mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-09-21 02:26:37 +00:00
loadPrefsInt()'s "sentinel mismatch" block had accumulated ~62 lines of one-shot backfills tied to specific old NodePrefs::SCHEMA_SENTINEL values (favourites/map home-page bits, split bot-command toggles, trail_units_idx, bot_trigger_ch seed, scope mask/index zeroing). Reduce it to just the sentinel read + mismatch log line -- an upgrade from a version old enough to hit any of these now lands on today's plain defaults for that field instead of a silently-seeded value, same outcome a fresh device already gets. The ongoing per-field range clamps (defensive against any corrupt or out-of-range byte, not version-specific) are untouched. Same treatment for DataStore::loadScopeList()'s one-time synthesis of a scope-list entry from the old single default_scope_name/key field: removed, along with the scope_migrated_legacy plumbing in MyMesh::begin() that only ran once that migration had just fired. loadScopeList() drops its now- unused NodePrefs parameter and bool return. Also trimmed ~25 per-field comments that over-specified which exact old sentinel produced which stray byte, down to what the clamp actually defends against -- except where the hex value explained a genuinely non-obvious byte-aliasing interaction, which stays. One comment (scope mask/index) was flagged and rewritten because it described the very zeroing logic this change removes. Drive-by: two comments still said Settings > Sound > "Msg wake" -- it's been under Settings > Display for a while, per the enum's section grouping in SettingsScreen.h. Verified: sim_companion_radio and WioTrackerL1_companion_solo_dual build clean, RAM/Flash usage unchanged (pure logic removal, no schema/layout change). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
76 lines
3.3 KiB
C++
76 lines
3.3 KiB
C++
#pragma once
|
|
|
|
#include <helpers/IdentityStore.h>
|
|
#include <helpers/ContactInfo.h>
|
|
#include <helpers/ChannelDetails.h>
|
|
#include "NodePrefs.h"
|
|
#include "ScopeList.h"
|
|
|
|
class DataStoreHost {
|
|
public:
|
|
virtual bool onContactLoaded(const ContactInfo& contact) =0;
|
|
virtual bool getContactForSave(uint32_t idx, ContactInfo& contact) =0;
|
|
virtual bool onChannelLoaded(uint8_t channel_idx, const ChannelDetails& ch) =0;
|
|
virtual bool getChannelForSave(uint8_t channel_idx, ChannelDetails& ch) =0;
|
|
};
|
|
|
|
class DataStore {
|
|
FILESYSTEM* _fs;
|
|
FILESYSTEM* _fsExtra;
|
|
mesh::RTCClock* _clock;
|
|
IdentityStore identity_store;
|
|
|
|
void loadPrefsInt(const char *filename, NodePrefs& prefs, double& node_lat, double& node_lon);
|
|
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
|
void checkAdvBlobFile();
|
|
#endif
|
|
|
|
public:
|
|
DataStore(FILESYSTEM& fs, mesh::RTCClock& clock);
|
|
DataStore(FILESYSTEM& fs, FILESYSTEM& fsExtra, mesh::RTCClock& clock);
|
|
void begin();
|
|
bool formatFileSystem();
|
|
FILESYSTEM* getPrimaryFS() const { return _fs; }
|
|
FILESYSTEM* getSecondaryFS() const { return _fsExtra; }
|
|
bool loadMainIdentity(mesh::LocalIdentity &identity);
|
|
bool saveMainIdentity(const mesh::LocalIdentity &identity);
|
|
void loadPrefs(NodePrefs& prefs, double& node_lat, double& node_lon);
|
|
void savePrefs(const NodePrefs& prefs, double node_lat, double node_lon);
|
|
void loadContacts(DataStoreHost* host);
|
|
void saveContacts(DataStoreHost* host, bool (*filter)(const ContactInfo& c) = NULL);
|
|
// Returns true if a channels file (current or legacy) existed and was
|
|
// loaded -- false only on a genuinely fresh device with neither file, so
|
|
// the caller knows whether it's safe to seed default channels (see
|
|
// MyMesh::begin()'s addChannel("Public", ...) -- seeding unconditionally
|
|
// would resurrect a channel the user had deliberately deleted, since a
|
|
// deleted slot is simply absent from the file, not written as empty).
|
|
bool loadChannels(DataStoreHost* host);
|
|
void saveChannels(DataStoreHost* host);
|
|
// /scopes1: the shared named-scope list (see ScopeList.h). A device with no
|
|
// file yet just starts with the default-constructed ScopeList (empty,
|
|
// default_idx 0 == "*").
|
|
void loadScopeList(ScopeList& list);
|
|
void saveScopeList(const ScopeList& list);
|
|
void migrateToSecondaryFS();
|
|
uint8_t getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]);
|
|
bool putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len);
|
|
bool deleteBlobByKey(const uint8_t key[], int key_len);
|
|
File openRead(const char* filename);
|
|
File openRead(FILESYSTEM* fs, const char* filename);
|
|
File openWrite(const char* filename);
|
|
// Atomically replace final_path with a fully-written temp file (see
|
|
// openWrite()). Use for small custom records that want the same crash-safety
|
|
// as contacts/channels: write everything to a .tmp, then commit. Returns
|
|
// false if the swap fails (the previous good file is left untouched).
|
|
bool commitFile(const char* tmp_path, const char* final_path);
|
|
bool removeFile(const char* filename);
|
|
bool removeFile(FILESYSTEM* fs, const char* filename);
|
|
uint32_t getStorageUsedKb() const;
|
|
uint32_t getStorageTotalKb() const;
|
|
void saveRTCTime();
|
|
void restoreRTCTime();
|
|
|
|
private:
|
|
FILESYSTEM* _getContactsChannelsFS() const { if (_fsExtra) return _fsExtra; return _fs;};
|
|
};
|