mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-19 09:12:45 +00:00
Shrink devicestate for small mcus
This commit is contained in:
@@ -110,7 +110,10 @@ void NodeDB::resetRadioConfig()
|
||||
*/
|
||||
}
|
||||
|
||||
void NodeDB::installDefaultDeviceState() {
|
||||
void NodeDB::installDefaultDeviceState()
|
||||
{
|
||||
memset(&devicestate, 0, sizeof(devicestate));
|
||||
|
||||
// init our devicestate with valid flags so protobuf writing/reading will work
|
||||
devicestate.has_my_node = true;
|
||||
devicestate.has_radio = true;
|
||||
@@ -118,7 +121,7 @@ void NodeDB::installDefaultDeviceState() {
|
||||
devicestate.radio.has_channel_settings = true;
|
||||
devicestate.radio.has_preferences = true;
|
||||
devicestate.node_db_count = 0;
|
||||
devicestate.receive_queue_count = 0;
|
||||
devicestate.receive_queue_count = 0; // Not yet implemented FIXME
|
||||
|
||||
resetRadioConfig();
|
||||
|
||||
@@ -138,7 +141,7 @@ void NodeDB::installDefaultDeviceState() {
|
||||
pickNewNodeNum(); // Note: we will repick later, just in case the settings are corrupted, but we need a valid
|
||||
// owner.short_name now
|
||||
sprintf(owner.long_name, "Unknown %02x%02x", ourMacAddr[4], ourMacAddr[5]);
|
||||
sprintf(owner.short_name, "?%02X", myNodeInfo.my_node_num & 0xff);
|
||||
sprintf(owner.short_name, "?%02X", (unsigned)(myNodeInfo.my_node_num & 0xff));
|
||||
}
|
||||
|
||||
void NodeDB::init()
|
||||
@@ -226,14 +229,13 @@ void NodeDB::loadFromDisk()
|
||||
memset(&devicestate, 0, sizeof(devicestate));
|
||||
if (!pb_decode(&stream, DeviceState_fields, &devicestate)) {
|
||||
DEBUG_MSG("Error: can't decode protobuf %s\n", PB_GET_ERROR(&stream));
|
||||
installDefaultDeviceState(); // Our in RAM copy might now be corrupt
|
||||
installDefaultDeviceState(); // Our in RAM copy might now be corrupt
|
||||
// FIXME - report failure to phone
|
||||
} else {
|
||||
if (devicestate.version < DEVICESTATE_MIN_VER) {
|
||||
DEBUG_MSG("Warn: devicestate is old, discarding\n");
|
||||
installDefaultDeviceState();
|
||||
}
|
||||
else {
|
||||
installDefaultDeviceState();
|
||||
} else {
|
||||
DEBUG_MSG("Loaded saved preferences version %d\n", devicestate.version);
|
||||
}
|
||||
|
||||
@@ -245,8 +247,6 @@ void NodeDB::loadFromDisk()
|
||||
DEBUG_MSG("No saved preferences found\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#else
|
||||
DEBUG_MSG("ERROR: Filesystem not implemented\n");
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user