mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-23 17:13:38 +00:00
Merge pull request #159 from geeksville/master
hotfix release for reboot bug
This commit is contained in:
commit
5d874cd43b
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
export VERSION=0.6.7
|
export VERSION=0.6.8
|
@ -114,7 +114,6 @@ void NodeDB::init()
|
|||||||
devicestate.has_my_node = true;
|
devicestate.has_my_node = true;
|
||||||
devicestate.has_radio = true;
|
devicestate.has_radio = true;
|
||||||
devicestate.has_owner = true;
|
devicestate.has_owner = true;
|
||||||
devicestate.has_radio = false;
|
|
||||||
devicestate.radio.has_channel_settings = true;
|
devicestate.radio.has_channel_settings = true;
|
||||||
devicestate.radio.has_preferences = true;
|
devicestate.radio.has_preferences = true;
|
||||||
devicestate.node_db_count = 0;
|
devicestate.node_db_count = 0;
|
||||||
@ -137,16 +136,8 @@ void NodeDB::init()
|
|||||||
memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr));
|
memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr));
|
||||||
sprintf(owner.long_name, "Unknown %02x%02x", ourMacAddr[4], ourMacAddr[5]);
|
sprintf(owner.long_name, "Unknown %02x%02x", ourMacAddr[4], ourMacAddr[5]);
|
||||||
|
|
||||||
// Crummy guess at our nodenum
|
|
||||||
pickNewNodeNum();
|
|
||||||
|
|
||||||
sprintf(owner.short_name, "?%02X", myNodeInfo.my_node_num & 0xff);
|
sprintf(owner.short_name, "?%02X", myNodeInfo.my_node_num & 0xff);
|
||||||
|
|
||||||
// Include our owner in the node db under our nodenum
|
|
||||||
NodeInfo *info = getOrCreateNode(getNodeNum());
|
|
||||||
info->user = owner;
|
|
||||||
info->has_user = true;
|
|
||||||
|
|
||||||
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");
|
||||||
@ -157,6 +148,15 @@ void NodeDB::init()
|
|||||||
loadFromDisk();
|
loadFromDisk();
|
||||||
// saveToDisk();
|
// saveToDisk();
|
||||||
|
|
||||||
|
// Note! We do this after loading saved settings, so that if somehow an invalid nodenum was stored in preferences we won't
|
||||||
|
// keep using that nodenum forever. Crummy guess at our nodenum (but we will check against the nodedb to avoid conflicts)
|
||||||
|
pickNewNodeNum();
|
||||||
|
|
||||||
|
// Include our owner in the node db under our nodenum
|
||||||
|
NodeInfo *info = getOrCreateNode(getNodeNum());
|
||||||
|
info->user = owner;
|
||||||
|
info->has_user = true;
|
||||||
|
|
||||||
// We set these _after_ loading from disk - because they come from the build and are more trusted than
|
// We set these _after_ loading from disk - because they come from the build and are more trusted than
|
||||||
// what is stored in flash
|
// what is stored in flash
|
||||||
strncpy(myNodeInfo.region, optstr(HW_VERSION), sizeof(myNodeInfo.region));
|
strncpy(myNodeInfo.region, optstr(HW_VERSION), sizeof(myNodeInfo.region));
|
||||||
@ -176,9 +176,12 @@ void NodeDB::init()
|
|||||||
*/
|
*/
|
||||||
void NodeDB::pickNewNodeNum()
|
void NodeDB::pickNewNodeNum()
|
||||||
{
|
{
|
||||||
// Pick an initial nodenum based on the macaddr
|
NodeNum r = myNodeInfo.my_node_num;
|
||||||
NodeNum r = sizeof(NodeNum) == 1 ? ourMacAddr[5]
|
|
||||||
: ((ourMacAddr[2] << 24) | (ourMacAddr[3] << 16) | (ourMacAddr[4] << 8) | ourMacAddr[5]);
|
// If we don't have a nodenum at app - pick an initial nodenum based on the macaddr
|
||||||
|
if (r == 0)
|
||||||
|
r = sizeof(NodeNum) == 1 ? ourMacAddr[5]
|
||||||
|
: ((ourMacAddr[2] << 24) | (ourMacAddr[3] << 16) | (ourMacAddr[4] << 8) | ourMacAddr[5]);
|
||||||
|
|
||||||
if (r == NODENUM_BROADCAST || r < NUM_RESERVED)
|
if (r == NODENUM_BROADCAST || r < NUM_RESERVED)
|
||||||
r = NUM_RESERVED; // don't pick a reserved node number
|
r = NUM_RESERVED; // don't pick a reserved node number
|
||||||
@ -247,15 +250,18 @@ void NodeDB::saveToDisk()
|
|||||||
if (!pb_encode(&stream, DeviceState_fields, &devicestate)) {
|
if (!pb_encode(&stream, DeviceState_fields, &devicestate)) {
|
||||||
DEBUG_MSG("Error: can't write protobuf %s\n", PB_GET_ERROR(&stream));
|
DEBUG_MSG("Error: can't write protobuf %s\n", PB_GET_ERROR(&stream));
|
||||||
// FIXME - report failure to phone
|
// FIXME - report failure to phone
|
||||||
|
|
||||||
|
f.close();
|
||||||
|
} else {
|
||||||
|
// Success - replace the old file
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
// brief window of risk here ;-)
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
f.close();
|
|
||||||
|
|
||||||
// brief window of risk here ;-)
|
|
||||||
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 {
|
} else {
|
||||||
DEBUG_MSG("ERROR: can't write prefs\n"); // FIXME report to app
|
DEBUG_MSG("ERROR: can't write prefs\n"); // FIXME report to app
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user