mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 22:52:07 +00:00
Don't use a (huge - 16KB) scratch buffer for device state loading
This commit is contained in:
parent
656faf4ce9
commit
99dac51b9d
@ -110,8 +110,7 @@ void NodeDB::resetRadioConfig()
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeDB::init()
|
void NodeDB::installDefaultDeviceState() {
|
||||||
{
|
|
||||||
// init our devicestate with valid flags so protobuf writing/reading will work
|
// init our devicestate with valid flags so protobuf writing/reading will work
|
||||||
devicestate.has_my_node = true;
|
devicestate.has_my_node = true;
|
||||||
devicestate.has_radio = true;
|
devicestate.has_radio = true;
|
||||||
@ -140,11 +139,16 @@ void NodeDB::init()
|
|||||||
// owner.short_name now
|
// owner.short_name now
|
||||||
sprintf(owner.long_name, "Unknown %02x%02x", ourMacAddr[4], ourMacAddr[5]);
|
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", myNodeInfo.my_node_num & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeDB::init()
|
||||||
|
{
|
||||||
|
installDefaultDeviceState();
|
||||||
|
|
||||||
if (!FSBegin()) // FIXME - do this in main?
|
if (!FSBegin()) // FIXME - do this in main?
|
||||||
{
|
{
|
||||||
DEBUG_MSG("ERROR filesystem mount Failed\n");
|
DEBUG_MSG("ERROR filesystem mount Failed\n");
|
||||||
// FIXME - report failure to phone
|
assert(0); // FIXME - report failure to phone
|
||||||
}
|
}
|
||||||
|
|
||||||
// saveToDisk();
|
// saveToDisk();
|
||||||
@ -210,7 +214,7 @@ const char *preftmp = "/db.proto.tmp";
|
|||||||
void NodeDB::loadFromDisk()
|
void NodeDB::loadFromDisk()
|
||||||
{
|
{
|
||||||
#ifdef FS
|
#ifdef FS
|
||||||
static DeviceState scratch;
|
// static DeviceState scratch; We no longer read into a tempbuf because this structure is 15KB of valuable RAM
|
||||||
|
|
||||||
auto f = FS.open(preffile);
|
auto f = FS.open(preffile);
|
||||||
if (f) {
|
if (f) {
|
||||||
@ -219,16 +223,18 @@ void NodeDB::loadFromDisk()
|
|||||||
|
|
||||||
// DEBUG_MSG("Preload channel name=%s\n", channelSettings.name);
|
// DEBUG_MSG("Preload channel name=%s\n", channelSettings.name);
|
||||||
|
|
||||||
memset(&scratch, 0, sizeof(scratch));
|
memset(&devicestate, 0, sizeof(devicestate));
|
||||||
if (!pb_decode(&stream, DeviceState_fields, &scratch)) {
|
if (!pb_decode(&stream, DeviceState_fields, &devicestate)) {
|
||||||
DEBUG_MSG("Error: can't decode protobuf %s\n", PB_GET_ERROR(&stream));
|
DEBUG_MSG("Error: can't decode protobuf %s\n", PB_GET_ERROR(&stream));
|
||||||
|
installDefaultDeviceState(); // Our in RAM copy might now be corrupt
|
||||||
// FIXME - report failure to phone
|
// FIXME - report failure to phone
|
||||||
} else {
|
} else {
|
||||||
if (scratch.version < DEVICESTATE_MIN_VER)
|
if (devicestate.version < DEVICESTATE_MIN_VER) {
|
||||||
DEBUG_MSG("Warn: devicestate is old, discarding\n");
|
DEBUG_MSG("Warn: devicestate is old, discarding\n");
|
||||||
|
installDefaultDeviceState();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
DEBUG_MSG("Loaded saved preferences version %d\n", scratch.version);
|
DEBUG_MSG("Loaded saved preferences version %d\n", devicestate.version);
|
||||||
devicestate = scratch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG_MSG("Postload channel name=%s\n", channelSettings.name);
|
// DEBUG_MSG("Postload channel name=%s\n", channelSettings.name);
|
||||||
@ -238,6 +244,9 @@ void NodeDB::loadFromDisk()
|
|||||||
} else {
|
} else {
|
||||||
DEBUG_MSG("No saved preferences found\n");
|
DEBUG_MSG("No saved preferences found\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
DEBUG_MSG("ERROR: Filesystem not implemented\n");
|
DEBUG_MSG("ERROR: Filesystem not implemented\n");
|
||||||
#endif
|
#endif
|
||||||
|
@ -93,6 +93,9 @@ class NodeDB
|
|||||||
|
|
||||||
/// read our db from flash
|
/// read our db from flash
|
||||||
void loadFromDisk();
|
void loadFromDisk();
|
||||||
|
|
||||||
|
/// Reinit device state from scratch (not loading from disk)
|
||||||
|
void installDefaultDeviceState();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user