diff --git a/src/MeshBluetoothService.cpp b/src/MeshBluetoothService.cpp index ced1a7878..73b687608 100644 --- a/src/MeshBluetoothService.cpp +++ b/src/MeshBluetoothService.cpp @@ -79,6 +79,38 @@ public: } }; +// wrap our protobuf version with something that forces the service to reload the config +class RadioCharacteristic : public ProtobufCharacteristic +{ +public: + RadioCharacteristic() + : ProtobufCharacteristic("b56786c8-839a-44a1-b98e-a1724c4a0262", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ, RadioConfig_fields, &radioConfig) + { + } + + void onWrite(BLECharacteristic *c) + { + ProtobufCharacteristic::onWrite(c); + service.reloadConfig(); + } +}; + +// wrap our protobuf version with something that forces the service to reload the owner +class OwnerCharacteristic : public ProtobufCharacteristic +{ +public: + OwnerCharacteristic() + : ProtobufCharacteristic("6ff1d8b6-e2de-41e3-8c0b-8fa384f64eb6", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ, User_fields, &owner) + { + } + + void onWrite(BLECharacteristic *c) + { + ProtobufCharacteristic::onWrite(c); + service.reloadOwner(); + } +}; + static BLECharacteristic meshFromRadioCharacteristic("8ba2bcc2-ee02-4a55-a531-c525c5e454d5", BLECharacteristic::PROPERTY_READ), meshToRadioCharacteristic("f75c76d2-129e-4dad-a1dd-7866124401e7", BLECharacteristic::PROPERTY_WRITE), @@ -87,9 +119,11 @@ static BLECharacteristic static NodeInfoCharacteristic meshNodeInfoCharacteristic; static ProtobufCharacteristic - meshMyNodeCharacteristic("ea9f3f82-8dc4-4733-9452-1f6da28892a2", BLECharacteristic::PROPERTY_READ, MyNodeInfo_fields, &myNodeInfo), - meshRadioCharacteristic("b56786c8-839a-44a1-b98e-a1724c4a0262", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ, RadioConfig_fields, &radioConfig), - meshOwnerCharacteristic("6ff1d8b6-e2de-41e3-8c0b-8fa384f64eb6", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ, User_fields, &owner); + meshMyNodeCharacteristic("ea9f3f82-8dc4-4733-9452-1f6da28892a2", BLECharacteristic::PROPERTY_READ, MyNodeInfo_fields, &myNodeInfo); + +static OwnerCharacteristic meshOwnerCharacteristic; + +static RadioCharacteristic meshRadioCharacteristic; /** * Tell any bluetooth clients that the number of rx packets has changed diff --git a/src/MeshRadio.h b/src/MeshRadio.h index 8a02b793a..6f706737a 100644 --- a/src/MeshRadio.h +++ b/src/MeshRadio.h @@ -36,6 +36,9 @@ public: /// for received packets it will call the rx handler void loop(); + /// The radioConfig object just changed, call this to force the hw to change to the new settings + void reloadConfig() { Serial.println("FIXME add reloadConfig"); } + private: RH_RF95 rf95; // the raw radio interface RHMesh manager; diff --git a/src/MeshService.h b/src/MeshService.h index ab7d8661e..f274f1e3f 100644 --- a/src/MeshService.h +++ b/src/MeshService.h @@ -50,6 +50,12 @@ public: /// Given a ToRadio buffer (from bluetooth) parse it and properly handle it (setup radio, owner or send packet into the mesh) void handleToRadio(std::string s); + /// The radioConfig object just changed, call this to force the hw to change to the new settings + void reloadConfig() { radio.reloadConfig(); } + + /// The owner User record just got updated, update our node DB and broadcast the info into the mesh + void reloadOwner() { Serial.println("FIXME implement reloadOwner"); } + private: /// Send a packet into the mesh - note p is read only and should be copied into a pool based MeshPacket before