Fix WisBlock GPS power policy and preserve shared peripherals
This commit is contained in:
1 parent
9079d6f47e
commit
368770656f
26 files changed
+1830
-107
No files matched your search
@@ -4,6 +4,9 @@
|
||||
#include <new>
|
||||
#include "DataStore.h"
|
||||
#include "PrefsStorageLayout.h"
|
||||
#if defined(RAK_4631)
|
||||
#include <helpers/PeripheralModePrefs.h>
|
||||
#endif
|
||||
#include <helpers/FileRead.h>
|
||||
#include <helpers/AdvertDataHelpers.h>
|
||||
#include <helpers/LazyPersistence.h>
|
||||
@@ -1104,6 +1107,9 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
loaded_prefs.usb_debug_enabled = 0;
|
||||
// Old images cannot opt in using an unrelated runtime preference value.
|
||||
loaded_prefs.lost_reply = 0;
|
||||
#if defined(RAK_4631)
|
||||
loaded_prefs.peripherals_shared = 0;
|
||||
#endif
|
||||
double loaded_lat = node_lat;
|
||||
double loaded_lon = node_lon;
|
||||
// The original image ended after ble_pin at byte 84. Later releases only
|
||||
@@ -1197,6 +1203,11 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if defined(RAK_4631)
|
||||
// Only the RAK4631 publishes this footer. Other targets retain their
|
||||
// exact existing image sizes, including the compact STM32 wire table.
|
||||
known_size = known_size || prefs_size == 236 + mesh::peripherals::FooterSize;
|
||||
#endif
|
||||
if (prefs_size < MIN_PREFS_SIZE || !known_size) {
|
||||
file.close();
|
||||
return false;
|
||||
@@ -1348,6 +1359,14 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
readOptionalField(&loaded_prefs.usb_debug_enabled,
|
||||
sizeof(loaded_prefs.usb_debug_enabled));
|
||||
readOptionalField(&loaded_prefs.lost_reply, sizeof(loaded_prefs.lost_reply));
|
||||
#if defined(RAK_4631)
|
||||
if (file.available() != 0) {
|
||||
uint8_t peripheral_footer[mesh::peripherals::FooterSize] = {};
|
||||
success = success && readField(peripheral_footer, sizeof(peripheral_footer))
|
||||
&& mesh::peripherals::decodeFooter(peripheral_footer,
|
||||
sizeof(peripheral_footer), loaded_prefs.peripherals_shared);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Any bytes left over form only part of a historically appended field.
|
||||
@@ -1543,6 +1562,11 @@ bool DataStore::savePrefs(const CompanionNodePrefs& _prefs, double node_lat, dou
|
||||
memcpy(tail + 6, &_prefs.gps_sync_interval_hours,
|
||||
sizeof(_prefs.gps_sync_interval_hours));
|
||||
success = success && writeField(tail, sizeof(tail));
|
||||
#if defined(RAK_4631)
|
||||
uint8_t peripheral_footer[mesh::peripherals::FooterSize];
|
||||
mesh::peripherals::encodeFooter(peripheral_footer, _prefs.peripherals_shared);
|
||||
success = success && writeField(peripheral_footer, sizeof(peripheral_footer));
|
||||
#endif
|
||||
|
||||
#if defined(STM32_PLATFORM)
|
||||
success = success && image_length == sizeof(image)
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#include <helpers/BatteryChargeCLI.h>
|
||||
#include <helpers/MorseCLI.h>
|
||||
#include <helpers/MorseLoopPolicy.h>
|
||||
#if defined(RAK_4631)
|
||||
#include <helpers/PeripheralModePrefs.h>
|
||||
#endif
|
||||
#include <helpers/ui/StartupScreen.h>
|
||||
#include "NotificationSettingsFile.h"
|
||||
#include "MyMesh.h"
|
||||
@@ -2758,6 +2761,9 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
|
||||
_prefs.gps_enabled = 0; // GPS disabled by default
|
||||
_prefs.gps_interval = 0; // Use the default 1-second fix-processing interval
|
||||
_prefs.gps_sync_interval_hours = 0; // Retain the board's default time-sync cadence
|
||||
#if defined(RAK_4631)
|
||||
_prefs.peripherals_shared = 0; // A genuinely fresh missing image is GPS-only.
|
||||
#endif
|
||||
_prefs.autoadd_config = DEFAULT_AUTOADD_CONFIG;
|
||||
_prefs.path_hash_mode = DEFAULT_PATH_HASH_MODE;
|
||||
#ifdef RADIO_FEM_TXGAIN
|
||||
@@ -2934,6 +2940,12 @@ void MyMesh::begin(bool has_display, bool radio_available,
|
||||
// load persisted prefs
|
||||
const bool prefs_ready =
|
||||
_store->loadPrefs(_prefs, sensors.node_lat, sensors.node_lon);
|
||||
#if defined(RAK_4631)
|
||||
// Only a verified image (or a fresh missing file) may permit GPS-only power.
|
||||
// A failed load never replaces a stored shared policy with an unsafe cut.
|
||||
if (!prefs_ready) _prefs.peripherals_shared = 1;
|
||||
sensors.configureSharedPeripheralMode(_prefs.peripherals_shared != 0);
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
// A volatile primary filesystem is the final recovery mode after the
|
||||
@@ -3654,6 +3666,19 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
|
||||
size_t reply_size) {
|
||||
if (!command || !reply || reply_size == 0) return false;
|
||||
while (*command == ' ') command++;
|
||||
#if defined(RAK_4631)
|
||||
// This helper is also reached only after normal remote-admin admission.
|
||||
if (mesh::peripherals::handleCommand(_prefs.peripherals_shared, command,
|
||||
reply, reply_size, sensors.supportsSharedPeripheralMode(),
|
||||
[this]() { return savePrefs(); })) return true;
|
||||
#else
|
||||
if (strcmp(command, "get peripherals.mode") == 0
|
||||
|| (strncmp(command, "set peripherals.mode", 20) == 0
|
||||
&& (command[20] == 0 || command[20] == ' ' || command[20] == '\t'))) {
|
||||
snprintf(reply, reply_size, "Error: unsupported");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (strcmp(command, "get public.key") == 0) {
|
||||
char public_key_hex[PUB_KEY_SIZE * 2 + 1];
|
||||
|
||||
@@ -117,6 +117,10 @@ public:
|
||||
uint8_t usb_debug_enabled = 0;
|
||||
// Appended opt-in private-message response: 0=off, 1=no, 2=yes.
|
||||
uint8_t lost_reply = 0;
|
||||
#if defined(RAK_4631)
|
||||
// A checked footer follows every existing on-flash field, never an insertion.
|
||||
uint8_t peripherals_shared = 0; // applied at boot, not on a live CLI save
|
||||
#endif
|
||||
|
||||
private:
|
||||
class RadioPrefs : public CommonRadioPrefs {
|
||||
@@ -255,10 +259,15 @@ public:
|
||||
// untouched, and leave a normally constructed snapshot's adapters local.
|
||||
bool copyPersistedValuesFrom(const CompanionNodePrefs& source) {
|
||||
if (&source == this) return true;
|
||||
#if defined(RAK_4631)
|
||||
const auto& last_value = peripherals_shared;
|
||||
#else
|
||||
const auto& last_value = lost_reply;
|
||||
#endif
|
||||
static_assert(sizeof(lost_reply) == sizeof(uint8_t),
|
||||
"The published lost reply preference is one byte");
|
||||
const uintptr_t first = reinterpret_cast<uintptr_t>(&airtime_factor);
|
||||
const uintptr_t last = reinterpret_cast<uintptr_t>(&lost_reply);
|
||||
const uintptr_t last = reinterpret_cast<uintptr_t>(&last_value);
|
||||
if (last < first
|
||||
|| last - first > sizeof(*this) - sizeof(lost_reply)) {
|
||||
return false;
|
||||
@@ -269,8 +278,13 @@ public:
|
||||
const uintptr_t object = reinterpret_cast<uintptr_t>(&values);
|
||||
const uintptr_t begin =
|
||||
reinterpret_cast<uintptr_t>(&values.airtime_factor);
|
||||
const uintptr_t end =
|
||||
reinterpret_cast<uintptr_t>(&values.lost_reply);
|
||||
const uintptr_t end = reinterpret_cast<uintptr_t>(
|
||||
#if defined(RAK_4631)
|
||||
&values.peripherals_shared
|
||||
#else
|
||||
&values.lost_reply
|
||||
#endif
|
||||
);
|
||||
const uintptr_t radio_begin = reinterpret_cast<uintptr_t>(&values.radio);
|
||||
const uintptr_t custom_begin = reinterpret_cast<uintptr_t>(&values.custom);
|
||||
// Subtractions happen only after the corresponding ordering checks.
|
||||
|
||||
Reference in new issue
Block a user