fix channel prefs saving

1.2-legacy
geeksville 2020-02-12 13:31:09 -08:00
rodzic efa91f6767
commit d3ca56f91a
6 zmienionych plików z 33 dodań i 12 usunięć

Wyświetl plik

@ -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!

Wyświetl plik

@ -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()

Wyświetl plik

@ -41,10 +41,14 @@ MeshRadio::MeshRadio(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &_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);
}

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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 */