From 0146761850b6a6f1274a0beb827416ff4c4e55a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 15 Jun 2022 19:42:16 +0200 Subject: [PATCH 1/4] TEST - Push of LocalConfig --- src/mesh/PhoneAPI.cpp | 19 +++++++++++++++---- src/mesh/PhoneAPI.h | 9 +++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 033ef4906..f93c35895 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -112,7 +112,8 @@ bool PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) * * Our sending states progress in the following sequence (the client app ASSUMES THIS SEQUENCE, DO NOT CHANGE IT): * STATE_SEND_MY_INFO, // send our my info record - STATE_SEND_RADIO, + * STATE_SEND_GROUPS + STATE_SEND_CONFIG, STATE_SEND_NODEINFO, // states progress in this order as the device sends to to the client STATE_SEND_COMPLETE_ID, STATE_SEND_PACKETS // send packets or debug strings @@ -140,12 +141,23 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) myNodeInfo.has_gps = gps && gps->isConnected(); // Update with latest GPS connect info fromRadioScratch.which_payloadVariant = FromRadio_my_info_tag; fromRadioScratch.my_info = myNodeInfo; - state = STATE_SEND_NODEINFO; + state = STATE_SEND_CONFIG; service.refreshMyNodeInfo(); // Update my NodeInfo because the client will be asking for it soon. break; - case STATE_SEND_NODEINFO: { + case STATE_SEND_CONFIG: + fromRadioScratch.which_payloadVariant = FromRadio_config_tag; + fromRadioScratch.config = config; + + // NOTE: The phone app needs to know the ls_secs value so it can properly expect sleep behavior. + // So even if we internally use 0 to represent 'use default' we still need to send the value we are + // using to the app (so that even old phone apps work with new device loads). + fromRadioScratch.config.power.ls_secs = default_ls_secs; + state = STATE_SEND_NODEINFO; + break; + + case STATE_SEND_NODEINFO: const NodeInfo *info = nodeInfoForPhone; nodeInfoForPhone = NULL; // We just consumed a nodeinfo, will need a new one next time @@ -162,7 +174,6 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) return getFromRadio(buf); } break; - } case STATE_SEND_COMPLETE_ID: fromRadioScratch.which_payloadVariant = FromRadio_config_complete_id_tag; diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index ca926b096..f17ed26c0 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -20,13 +20,10 @@ class PhoneAPI : public Observer // FIXME, we shouldn't be inheriting from Observer, instead use CallbackObserver as a member { enum State { - STATE_UNUSED, // (no longer used) old default state - until Android apps are all updated, uses the old BLE API - STATE_SEND_NOTHING, // (Eventual) Initial state, don't send anything until the client starts asking for config - // (disconnected) + STATE_SEND_NOTHING, // Initial state, don't send anything until the client starts asking for config STATE_SEND_MY_INFO, // send our my info record - STATE_SEND_GROUPS, - // STATE_SEND_RADIO, // in 1.2 we now send this as a regular mesh packet - // STATE_SEND_OWNER, no need to send Owner specially, it is just part of the nodedb + STATE_SEND_GROUPS, // new in 1.3? + STATE_SEND_CONFIG, // Replacement for the old Radioconfig STATE_SEND_NODEINFO, // states progress in this order as the device sends to to the client STATE_SEND_COMPLETE_ID, STATE_SEND_PACKETS // send packets or debug strings From 7566ee1fea4477a089636ca2b0e78b84480223d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 15 Jun 2022 20:03:08 +0200 Subject: [PATCH 2/4] C++ is a weird language... --- src/mesh/PhoneAPI.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index f93c35895..84ff17d93 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -157,7 +157,7 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) state = STATE_SEND_NODEINFO; break; - case STATE_SEND_NODEINFO: + case STATE_SEND_NODEINFO: { const NodeInfo *info = nodeInfoForPhone; nodeInfoForPhone = NULL; // We just consumed a nodeinfo, will need a new one next time @@ -174,6 +174,7 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) return getFromRadio(buf); } break; + } case STATE_SEND_COMPLETE_ID: fromRadioScratch.which_payloadVariant = FromRadio_config_complete_id_tag; From 49e47f3e6d02a65c23eee66eefd279d782ad15a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 15 Jun 2022 21:50:33 +0200 Subject: [PATCH 3/4] Let's try this --- src/mesh/PhoneAPI.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 84ff17d93..406963951 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -232,6 +232,9 @@ bool PhoneAPI::available() case STATE_SEND_MY_INFO: return true; + + case STATE_SEND_CONFIG: + return true; case STATE_SEND_NODEINFO: if (!nodeInfoForPhone) @@ -281,4 +284,4 @@ int PhoneAPI::onNotify(uint32_t newValue) DEBUG_MSG("(Client not yet interested in packets)\n"); return 0; -} \ No newline at end of file +} From f63b876b71eb79991ff46d7877bccdbc1f135998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 16 Jun 2022 21:56:18 +0200 Subject: [PATCH 4/4] Send config chunks one by one --- src/mesh/PhoneAPI.cpp | 36 +++++++++++++++++++++++++++++++++--- src/mesh/PhoneAPI.h | 2 ++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 406963951..25569b18f 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -148,13 +148,43 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) case STATE_SEND_CONFIG: fromRadioScratch.which_payloadVariant = FromRadio_config_tag; - fromRadioScratch.config = config; + switch (config_state) { + case Config_device_tag: + fromRadioScratch.config.which_payloadVariant = Config_device_tag; + fromRadioScratch.config.payloadVariant.device = config.device; + break; + case Config_position_tag: + fromRadioScratch.config.which_payloadVariant = Config_position_tag; + fromRadioScratch.config.payloadVariant.position = config.position; + break; + case Config_power_tag: + fromRadioScratch.config.which_payloadVariant = Config_power_tag; + fromRadioScratch.config.payloadVariant.power = config.power; + fromRadioScratch.config.payloadVariant.power.ls_secs = default_ls_secs; + break; + case Config_wifi_tag: + fromRadioScratch.config.which_payloadVariant = Config_wifi_tag; + fromRadioScratch.config.payloadVariant.wifi = config.wifi; + break; + case Config_display_tag: + fromRadioScratch.config.which_payloadVariant = Config_display_tag; + fromRadioScratch.config.payloadVariant.display = config.display; + break; + case Config_lora_tag: + fromRadioScratch.config.which_payloadVariant = Config_lora_tag; + fromRadioScratch.config.payloadVariant.lora = config.lora; + break; + } // NOTE: The phone app needs to know the ls_secs value so it can properly expect sleep behavior. // So even if we internally use 0 to represent 'use default' we still need to send the value we are // using to the app (so that even old phone apps work with new device loads). - fromRadioScratch.config.power.ls_secs = default_ls_secs; - state = STATE_SEND_NODEINFO; + + config_state++; + // Advance when we have sent all of our config objects + if (config_state > Config_lora_tag) { + state = STATE_SEND_NODEINFO; + } break; case STATE_SEND_NODEINFO: { diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index f17ed26c0..3109a5e89 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -31,6 +31,8 @@ class PhoneAPI State state = STATE_SEND_NOTHING; + int8_t config_state = Config_device_tag; + /** * Each packet sent to the phone has an incrementing count */