mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-10 15:12:06 +00:00
Calculate CRC32 of Protobuf and compare before save.
This commit is contained in:
parent
063c4904ff
commit
54816231e9
@ -51,6 +51,7 @@ lib_deps =
|
|||||||
https://github.com/meshtastic/TinyGPSPlus.git#2f0d0528d737000043e949f4c3bdfb623cf0b902
|
https://github.com/meshtastic/TinyGPSPlus.git#2f0d0528d737000043e949f4c3bdfb623cf0b902
|
||||||
https://github.com/meshtastic/ArduinoThread.git#72921ac222eed6f526ba1682023cee290d9aa1b3
|
https://github.com/meshtastic/ArduinoThread.git#72921ac222eed6f526ba1682023cee290d9aa1b3
|
||||||
nanopb/Nanopb@^0.4.6
|
nanopb/Nanopb@^0.4.6
|
||||||
|
erriez/ErriezCRC32@^1.0.1
|
||||||
|
|
||||||
; Used for the code analysis in PIO Home / Inspect
|
; Used for the code analysis in PIO Home / Inspect
|
||||||
check_tool = cppcheck
|
check_tool = cppcheck
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "mesh-pb-constants.h"
|
#include "mesh-pb-constants.h"
|
||||||
#include <pb_decode.h>
|
#include <pb_decode.h>
|
||||||
#include <pb_encode.h>
|
#include <pb_encode.h>
|
||||||
|
#include <ErriezCRC32.h>
|
||||||
|
|
||||||
#ifdef ARCH_ESP32
|
#ifdef ARCH_ESP32
|
||||||
#include "mesh/http/WiFiAPClient.h"
|
#include "mesh/http/WiFiAPClient.h"
|
||||||
@ -268,6 +269,12 @@ void NodeDB::init()
|
|||||||
DEBUG_MSG("Initializing NodeDB\n");
|
DEBUG_MSG("Initializing NodeDB\n");
|
||||||
loadFromDisk();
|
loadFromDisk();
|
||||||
|
|
||||||
|
uint32_t devicestateCRC = crc32Buffer(&devicestate, sizeof(devicestate));
|
||||||
|
uint32_t configCRC = crc32Buffer(&config, sizeof(config));
|
||||||
|
uint32_t channelFileCRC = crc32Buffer(&channelFile, sizeof(channelFile));
|
||||||
|
|
||||||
|
int saveWhat = 0;
|
||||||
|
|
||||||
myNodeInfo.max_channels = MAX_NUM_CHANNELS; // tell others the max # of channels we can understand
|
myNodeInfo.max_channels = MAX_NUM_CHANNELS; // tell others the max # of channels we can understand
|
||||||
|
|
||||||
myNodeInfo.error_code = CriticalErrorCode_NONE; // For the error code, only show values from this boot (discard value from flash)
|
myNodeInfo.error_code = CriticalErrorCode_NONE; // For the error code, only show values from this boot (discard value from flash)
|
||||||
@ -305,7 +312,15 @@ void NodeDB::init()
|
|||||||
|
|
||||||
resetRadioConfig(); // If bogus settings got saved, then fix them
|
resetRadioConfig(); // If bogus settings got saved, then fix them
|
||||||
DEBUG_MSG("region=%d, NODENUM=0x%x, dbsize=%d\n", config.lora.region, myNodeInfo.my_node_num, *numNodes);
|
DEBUG_MSG("region=%d, NODENUM=0x%x, dbsize=%d\n", config.lora.region, myNodeInfo.my_node_num, *numNodes);
|
||||||
saveToDisk(SEGMENT_DEVICESTATE | SEGMENT_CONFIG | SEGMENT_CHANNELS);
|
|
||||||
|
if (devicestateCRC != crc32Buffer(&devicestate, sizeof(devicestate)))
|
||||||
|
saveWhat |= SEGMENT_DEVICESTATE;
|
||||||
|
if (configCRC != crc32Buffer(&config, sizeof(config)))
|
||||||
|
saveWhat |= SEGMENT_CONFIG;
|
||||||
|
if (channelFileCRC != crc32Buffer(&channelFile, sizeof(channelFile)))
|
||||||
|
saveWhat |= SEGMENT_CHANNELS;
|
||||||
|
|
||||||
|
saveToDisk(saveWhat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We reserve a few nodenums for future use
|
// We reserve a few nodenums for future use
|
||||||
@ -480,11 +495,11 @@ void NodeDB::saveToDisk(int saveWhat)
|
|||||||
#ifdef FSCom
|
#ifdef FSCom
|
||||||
FSCom.mkdir("/prefs");
|
FSCom.mkdir("/prefs");
|
||||||
#endif
|
#endif
|
||||||
if (saveWhat && SEGMENT_DEVICESTATE) {
|
if (saveWhat & SEGMENT_DEVICESTATE) {
|
||||||
saveDeviceStateToDisk();
|
saveDeviceStateToDisk();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saveWhat && SEGMENT_CONFIG) {
|
if (saveWhat & SEGMENT_CONFIG) {
|
||||||
config.has_device = true;
|
config.has_device = true;
|
||||||
config.has_display = true;
|
config.has_display = true;
|
||||||
config.has_lora = true;
|
config.has_lora = true;
|
||||||
@ -495,7 +510,7 @@ void NodeDB::saveToDisk(int saveWhat)
|
|||||||
saveProto(configFileName, LocalConfig_size, sizeof(config), LocalConfig_fields, &config);
|
saveProto(configFileName, LocalConfig_size, sizeof(config), LocalConfig_fields, &config);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saveWhat && SEGMENT_MODULECONFIG) {
|
if (saveWhat & SEGMENT_MODULECONFIG) {
|
||||||
moduleConfig.has_canned_message = true;
|
moduleConfig.has_canned_message = true;
|
||||||
moduleConfig.has_external_notification = true;
|
moduleConfig.has_external_notification = true;
|
||||||
moduleConfig.has_mqtt = true;
|
moduleConfig.has_mqtt = true;
|
||||||
@ -506,7 +521,7 @@ void NodeDB::saveToDisk(int saveWhat)
|
|||||||
saveProto(moduleConfigFileName, LocalModuleConfig_size, sizeof(moduleConfig), LocalModuleConfig_fields, &moduleConfig);
|
saveProto(moduleConfigFileName, LocalModuleConfig_size, sizeof(moduleConfig), LocalModuleConfig_fields, &moduleConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saveWhat && SEGMENT_CHANNELS) {
|
if (saveWhat & SEGMENT_CHANNELS) {
|
||||||
saveChannelsToDisk();
|
saveChannelsToDisk();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user