diff --git a/TODO.md b/TODO.md index 68f446f4..3b73c78e 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,7 @@ # High priority -* after reboot, channel number is getting reset to zero! fix! +* send user and location events much less often +* send location (or if not available user) when the user wakes the device from display sleep (both for testing and to improve user experience) * have node info screen show real info (including time since last contact, distance and heading) * make debug info screen show real data (including battery level & charging) * make real implementation of getNumOnlineNodes @@ -125,3 +126,4 @@ until the phone pulls those packets. Ever so often power on bluetooth just so w * finish power measurements (GPS on during sleep vs LCD on during sleep vs LORA on during sleep) and est battery life * make screen sleep behavior work * make screen advance only when a new node update arrives, a new text arrives or the user presses a button, turn off screen after a while +* after reboot, channel number is getting reset to zero! fix! diff --git a/src/GPS.cpp b/src/GPS.cpp index 2e610747..cbe95976 100644 --- a/src/GPS.cpp +++ b/src/GPS.cpp @@ -45,7 +45,7 @@ void GPS::loop() } uint64_t GPS::getTime() { - return (millis() - timeStartMsec) * 1000LL + zeroOffset; + return ((uint64_t) millis() - timeStartMsec) + zeroOffset; } void GPS::doTask() diff --git a/src/MeshRadio.cpp b/src/MeshRadio.cpp index 01191ff1..46ecbef1 100644 --- a/src/MeshRadio.cpp +++ b/src/MeshRadio.cpp @@ -41,10 +41,14 @@ MeshRadio::MeshRadio(MemoryPool &_pool, PointerQueue &_r channelSettings.channel_num = DEFAULT_CHANNEL_NUM; memcpy(&channelSettings.psk, &defaultpsk, sizeof(channelSettings.psk)); strcpy(channelSettings.name, "Default"); + // Can't print strings this early - serial not setup yet + // DEBUG_MSG("Set meshradio defaults name=%s\n", channelSettings.name); } bool MeshRadio::init() { + DEBUG_MSG("Starting meshradio init...\n"); + #ifdef RESET_GPIO pinMode(RESET_GPIO, OUTPUT); // Deassert reset digitalWrite(RESET_GPIO, HIGH); @@ -101,7 +105,7 @@ void MeshRadio::reloadConfig() // FIXME - can we do this? It seems to be in the Heltec board. rf95.setTxPower(channelSettings.tx_power, false); - DEBUG_MSG("Set radio: config=%u, ch=%d, txpower=%d\n", channelSettings.modem_config, channelSettings.channel_num, channelSettings.tx_power); + DEBUG_MSG("Set radio: name=%s. config=%u, ch=%d, txpower=%d\n", channelSettings.name, channelSettings.modem_config, channelSettings.channel_num, channelSettings.tx_power); } diff --git a/src/NodeDB.cpp b/src/NodeDB.cpp index 4ceaba56..5f5147d8 100644 --- a/src/NodeDB.cpp +++ b/src/NodeDB.cpp @@ -43,6 +43,9 @@ void NodeDB::init() devicestate.has_my_node = true; devicestate.has_radio = true; devicestate.has_owner = true; + devicestate.has_radio = true; + devicestate.radio.has_channel_settings = true; + devicestate.radio.has_preferences = true; devicestate.node_db_count = 0; devicestate.receive_queue_count = 0; @@ -116,6 +119,8 @@ void NodeDB::loadFromDisk() DEBUG_MSG("Loading saved preferences\n"); pb_istream_t stream = {&readcb, &f, DeviceState_size}; + //DEBUG_MSG("Preload channel name=%s\n", channelSettings.name); + memset(&scratch, 0, sizeof(scratch)); if (!pb_decode(&stream, DeviceState_fields, &scratch)) { @@ -127,7 +132,11 @@ void NodeDB::loadFromDisk() if (scratch.version < DeviceState_Version_Minimum) DEBUG_MSG("Warn: devicestate is old, discarding\n"); else + { devicestate = scratch; + } + + //DEBUG_MSG("Postload channel name=%s\n", channelSettings.name); } f.close(); @@ -144,7 +153,10 @@ void NodeDB::saveToDisk() if (f) { DEBUG_MSG("Writing preferences\n"); - pb_ostream_t stream = {&writecb, &f, DeviceState_size, 0}; + + pb_ostream_t stream = {&writecb, &f, SIZE_MAX, 0}; + + //DEBUG_MSG("Presave channel name=%s\n", channelSettings.name); devicestate.version = DeviceState_Version_Current; if (!pb_encode(&stream, DeviceState_fields, &devicestate)) @@ -156,8 +168,10 @@ void NodeDB::saveToDisk() f.close(); // brief window of risk here ;-) - FS.remove(preffile); - FS.rename(preftmp, preffile); + if (!FS.remove(preffile)) + DEBUG_MSG("Warning: Can't remove old pref file\n"); + if (!FS.rename(preftmp, preffile)) + DEBUG_MSG("Error: can't rename new pref file\n"); } else { @@ -187,13 +201,13 @@ uint32_t sinceLastSeen(const NodeInfo *n) #define NUM_ONLINE_SECS (60 * 2) // 2 hrs to consider someone offline -size_t NodeDB::getNumOnlineNodes() -{ +size_t NodeDB::getNumOnlineNodes() +{ size_t numseen = 0; // FIXME this implementation is kinda expensive - for(int i = 0; i < *numNodes; i++) - if(sinceLastSeen(&nodes[i]) < NUM_ONLINE_SECS) + for (int i = 0; i < *numNodes; i++) + if (sinceLastSeen(&nodes[i]) < NUM_ONLINE_SECS) numseen++; return numseen; diff --git a/src/mesh-pb-constants.cpp b/src/mesh-pb-constants.cpp index 8bc5e8a4..45a203b6 100644 --- a/src/mesh-pb-constants.cpp +++ b/src/mesh-pb-constants.cpp @@ -66,5 +66,6 @@ bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count) bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count) { File *file = (File*) stream->state; + //DEBUG_MSG("writing %d bytes to protobuf file\n", count); return file->write(buf, count) == count; } diff --git a/src/mesh.pb.h b/src/mesh.pb.h index 9a92854c..3e45d46d 100644 --- a/src/mesh.pb.h +++ b/src/mesh.pb.h @@ -34,8 +34,8 @@ typedef enum _ChannelSettings_ModemConfig { typedef enum _DeviceState_Version { DeviceState_Version_Unset = 0, - DeviceState_Version_Minimum = 7, - DeviceState_Version_Current = 7 + DeviceState_Version_Minimum = 10, + DeviceState_Version_Current = 10 } DeviceState_Version; /* Struct definitions */