Selaa lähdekoodia

* added CommonCLI::saveIdentity()

Scott Powell 11 kuukautta sitten
vanhempi
sitoutus
ee194a7b19

+ 14 - 0
examples/simple_repeater/main.cpp

@@ -732,6 +732,20 @@ public:
 
   mesh::LocalIdentity& getSelfId() override { return self_id; }
 
+  void saveIdentity(const mesh::LocalIdentity& new_id) override {
+    self_id = new_id;
+#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
+    IdentityStore store(*_fs, "");
+#elif defined(ESP32)
+    IdentityStore store(*_fs, "/identity");
+#elif defined(RP2040_PLATFORM)
+    IdentityStore store(*_fs, "/identity");
+#else
+    #error "need to define saveIdentity()"
+#endif
+    store.save("_main", self_id);
+  }
+
   void clearStats() override {
     radio_driver.resetStats();
     resetStats();

+ 14 - 0
examples/simple_room_server/main.cpp

@@ -865,6 +865,20 @@ public:
 
   mesh::LocalIdentity& getSelfId() override { return self_id; }
 
+  void saveIdentity(const mesh::LocalIdentity& new_id) override {
+    self_id = new_id;
+#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
+    IdentityStore store(*_fs, "");
+#elif defined(ESP32)
+    IdentityStore store(*_fs, "/identity");
+#elif defined(RP2040_PLATFORM)
+    IdentityStore store(*_fs, "/identity");
+#else
+    #error "need to define saveIdentity()"
+#endif
+    store.save("_main", self_id);
+  }
+
   void clearStats() override {
     radio_driver.resetStats();
     resetStats();

+ 14 - 0
examples/simple_sensor/SensorMesh.cpp

@@ -837,6 +837,20 @@ bool SensorMesh::formatFileSystem() {
 #endif
 }
 
+void SensorMesh::saveIdentity(const mesh::LocalIdentity& new_id) {
+  self_id = new_id;
+#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
+  IdentityStore store(*_fs, "");
+#elif defined(ESP32)
+  IdentityStore store(*_fs, "/identity");
+#elif defined(RP2040_PLATFORM)
+  IdentityStore store(*_fs, "/identity");
+#else
+  #error "need to define saveIdentity()"
+#endif
+  store.save("_main", self_id);
+}
+
 void SensorMesh::applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) {
   set_radio_at = futureMillis(2000);   // give CLI reply some time to be sent back, before applying temp radio params
   pending_freq = freq;

+ 1 - 0
examples/simple_sensor/SensorMesh.h

@@ -89,6 +89,7 @@ public:
     strcpy(reply, "not supported");
   }
   mesh::LocalIdentity& getSelfId() override { return self_id; }
+  void saveIdentity(const mesh::LocalIdentity& new_id) override;
   void clearStats() override { }
   void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override;
 

+ 3 - 1
src/helpers/CommonCLI.cpp

@@ -305,7 +305,9 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
         uint8_t prv_key[PRV_KEY_SIZE];
         bool success = mesh::Utils::fromHex(prv_key, PRV_KEY_SIZE, &config[8]);
         if (success) {
-          _callbacks->getSelfId().readFrom(prv_key, PRV_KEY_SIZE);
+          mesh::LocalIdentity new_id;
+          new_id.readFrom(prv_key, PRV_KEY_SIZE);
+          _callbacks->saveIdentity(new_id);
           strcpy(reply, "OK");
         } else {
           strcpy(reply, "Error, invalid key");

+ 1 - 0
src/helpers/CommonCLI.h

@@ -47,6 +47,7 @@ public:
     // no op by default
   };
   virtual mesh::LocalIdentity& getSelfId() = 0;
+  virtual void saveIdentity(const mesh::LocalIdentity& new_id) = 0;
   virtual void clearStats() = 0;
   virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0;
 };