From 5729d66a9ead2ff7a7620882a82607180fee4824 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Mon, 2 Jun 2025 15:25:55 +1000 Subject: [PATCH] * companion: some further refactors after the MyMesh refactor --- examples/companion_radio/MyMesh.cpp | 33 +++++++++++++++++++++++++++-- examples/companion_radio/MyMesh.h | 33 ----------------------------- examples/companion_radio/UITask.cpp | 18 +++++++--------- examples/companion_radio/UITask.h | 3 +-- examples/companion_radio/main.cpp | 2 +- 5 files changed, 41 insertions(+), 48 deletions(-) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index e53022f6..b0905bb6 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -68,6 +68,37 @@ #define RESP_CODE_SIGNATURE 20 #define RESP_CODE_CUSTOM_VARS 21 +#define SEND_TIMEOUT_BASE_MILLIS 500 +#define FLOOD_SEND_TIMEOUT_FACTOR 16.0f +#define DIRECT_SEND_PERHOP_FACTOR 6.0f +#define DIRECT_SEND_PERHOP_EXTRA_MILLIS 250 +#define LAZY_CONTACTS_WRITE_DELAY 5000 + +#define PUBLIC_GROUP_PSK "izOH6cXN6mrJ5e26oRXNcg==" + +// these are _pushed_ to client app at any time +#define PUSH_CODE_ADVERT 0x80 +#define PUSH_CODE_PATH_UPDATED 0x81 +#define PUSH_CODE_SEND_CONFIRMED 0x82 +#define PUSH_CODE_MSG_WAITING 0x83 +#define PUSH_CODE_RAW_DATA 0x84 +#define PUSH_CODE_LOGIN_SUCCESS 0x85 +#define PUSH_CODE_LOGIN_FAIL 0x86 +#define PUSH_CODE_STATUS_RESPONSE 0x87 +#define PUSH_CODE_LOG_RX_DATA 0x88 +#define PUSH_CODE_TRACE_DATA 0x89 +#define PUSH_CODE_NEW_ADVERT 0x8A +#define PUSH_CODE_TELEMETRY_RESPONSE 0x8B + +#define ERR_CODE_UNSUPPORTED_CMD 1 +#define ERR_CODE_NOT_FOUND 2 +#define ERR_CODE_TABLE_FULL 3 +#define ERR_CODE_BAD_STATE 4 +#define ERR_CODE_FILE_IO_ERROR 5 +#define ERR_CODE_ILLEGAL_ARG 6 + +#define MAX_SIGN_DATA_LEN (8 * 1024) // 8K + #ifdef DISPLAY_CLASS #include "UITask.h" #endif @@ -1527,10 +1558,8 @@ bool MyMesh::advert() { auto pkt = createSelfAdvert(_prefs.node_name, sensors.node_lat, sensors.node_lon); if (pkt) { sendZeroHop(pkt); - writeOKFrame(); return true; } else { - writeErrFrame(ERR_CODE_TABLE_FULL); return false; } } \ No newline at end of file diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index 574b9878..9d7da0df 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -70,43 +70,12 @@ #include -#define SEND_TIMEOUT_BASE_MILLIS 500 -#define FLOOD_SEND_TIMEOUT_FACTOR 16.0f -#define DIRECT_SEND_PERHOP_FACTOR 6.0f -#define DIRECT_SEND_PERHOP_EXTRA_MILLIS 250 -#define LAZY_CONTACTS_WRITE_DELAY 5000 - -#define PUBLIC_GROUP_PSK "izOH6cXN6mrJ5e26oRXNcg==" - -// these are _pushed_ to client app at any time -#define PUSH_CODE_ADVERT 0x80 -#define PUSH_CODE_PATH_UPDATED 0x81 -#define PUSH_CODE_SEND_CONFIRMED 0x82 -#define PUSH_CODE_MSG_WAITING 0x83 -#define PUSH_CODE_RAW_DATA 0x84 -#define PUSH_CODE_LOGIN_SUCCESS 0x85 -#define PUSH_CODE_LOGIN_FAIL 0x86 -#define PUSH_CODE_STATUS_RESPONSE 0x87 -#define PUSH_CODE_LOG_RX_DATA 0x88 -#define PUSH_CODE_TRACE_DATA 0x89 -#define PUSH_CODE_NEW_ADVERT 0x8A -#define PUSH_CODE_TELEMETRY_RESPONSE 0x8B - -#define ERR_CODE_UNSUPPORTED_CMD 1 -#define ERR_CODE_NOT_FOUND 2 -#define ERR_CODE_TABLE_FULL 3 -#define ERR_CODE_BAD_STATE 4 -#define ERR_CODE_FILE_IO_ERROR 5 -#define ERR_CODE_ILLEGAL_ARG 6 - /* -------------------------------------------------------------------------------------- */ #define REQ_TYPE_GET_STATUS 0x01 // same as _GET_STATS #define REQ_TYPE_KEEP_ALIVE 0x02 #define REQ_TYPE_GET_TELEMETRY_DATA 0x03 -#define MAX_SIGN_DATA_LEN (8 * 1024) // 8K - class MyMesh : public BaseChatMesh { public: MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables); @@ -213,8 +182,6 @@ private: int next_ack_idx; }; -extern StdRNG fast_rng; -extern SimpleMeshTables tables; extern MyMesh the_mesh; #ifdef DISPLAY_CLASS extern UITask ui_task; diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index eabfd8f7..00263e5e 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -34,26 +34,25 @@ static const uint8_t meshcore_logo [] PROGMEM = { 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8, }; -void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs, const char* build_date, const char* firmware_version, uint32_t pin_code) { +void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) { _display = display; _auto_off = millis() + AUTO_OFF_MILLIS; clearMsgPreview(); _node_prefs = node_prefs; - _pin_code = pin_code; if (_display != NULL) { _display->turnOn(); } // strip off dash and commit hash by changing dash to null terminator // e.g: v1.2.3-abcdef -> v1.2.3 - char *version = strdup(firmware_version); + char *version = strdup(FIRMWARE_VERSION); char *dash = strchr(version, '-'); - if(dash){ + if (dash) { *dash = 0; } // v1.2.3 (1 Jan 2025) - sprintf(_version_info, "%s (%s)", version, build_date); + sprintf(_version_info, "%s (%s)", version, FIRMWARE_BUILD_DATE); #ifdef PIN_BUZZER buzzer.begin(); @@ -216,11 +215,11 @@ void UITask::renderCurrScreen() { _display->print(tmp); // BT pin - if (!_connected && _pin_code != 0) { + if (!_connected && the_mesh.getBLEPin() != 0) { _display->setColor(DisplayDriver::RED); _display->setTextSize(2); _display->setCursor(0, 43); - sprintf(tmp, "Pin:%d", _pin_code); + sprintf(tmp, "Pin:%d", the_mesh.getBLEPin()); _display->print(tmp); _display->setColor(DisplayDriver::GREEN); } else { @@ -343,10 +342,9 @@ void UITask::handleButtonShortPress() { void UITask::handleButtonDoublePress() { MESH_DEBUG_PRINTLN("UITask: double press triggered, sending advert"); // ADVERT - if(the_mesh.advert()) { + if (the_mesh.advert()) { MESH_DEBUG_PRINTLN("Advert sent!"); - } - else { + } else { MESH_DEBUG_PRINTLN("Advert failed!"); } } diff --git a/examples/companion_radio/UITask.h b/examples/companion_radio/UITask.h index acf5237e..6914e9ec 100644 --- a/examples/companion_radio/UITask.h +++ b/examples/companion_radio/UITask.h @@ -29,7 +29,6 @@ class UITask { #endif unsigned long _next_refresh, _auto_off; bool _connected; - uint32_t _pin_code; NodePrefs* _node_prefs; char _version_info[32]; char _origin[62]; @@ -61,7 +60,7 @@ public: _next_refresh = 0; _connected = false; } - void begin(DisplayDriver* display, NodePrefs* node_prefs, const char* build_date, const char* firmware_version, uint32_t pin_code); + void begin(DisplayDriver* display, NodePrefs* node_prefs); void setHasConnection(bool connected) { _connected = connected; } bool hasDisplay() const { return _display != NULL; } diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 8c822a5c..a276a2b5 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -181,7 +181,7 @@ void setup() { sensors.begin(); #ifdef DISPLAY_CLASS - ui_task.begin(disp, the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION, the_mesh.getBLEPin()); + ui_task.begin(disp, the_mesh.getNodePrefs()); // still want to pass this in as dependency, as prefs might be moved #endif }