From 13fa7c1628043032b82b6cc952a0a80f84c3cf7b Mon Sep 17 00:00:00 2001 From: Pedestrian <70135709+Pedestrian11@users.noreply.github.com> Date: Tue, 26 Apr 2022 17:43:32 +0800 Subject: [PATCH 01/31] TTGO_T_ECHO to use batteries, PIN_EINK_PWR_ON must be set to high --- src/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index afb162cee..7b9abd2ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -152,6 +152,13 @@ void setup() DEBUG_MSG("\n\n//\\ E S H T /\\ S T / C\n\n"); initDeepSleep(); + + #if defined(TTGO_T_ECHO) + DEBUG_MSG("\n\nTTGO_T_ECHO PIN_EINK_PWR_ON\n\n"); + pinMode(PIN_EINK_PWR_ON, OUTPUT); + digitalWrite(PIN_EINK_PWR_ON, HIGH); +#elif +#endif #ifdef VEXT_ENABLE pinMode(VEXT_ENABLE, OUTPUT); From 701707a01bdefd87ee85e828fdf02c69aac97767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 26 Apr 2022 13:00:11 +0200 Subject: [PATCH 02/31] - Bounds Check is working on big integers, don't throw away valid coordinates. - Set ublox chips back to NMEA mode if they have been configured wrongly before. --- src/GPSStatus.h | 8 +++---- src/configuration.h | 4 ++++ src/gps/GPS.cpp | 50 ++++++++++++++++++++++++++++++++++++++++ src/gps/NMEAGPS.cpp | 10 ++++++-- src/mesh/MeshService.cpp | 2 +- 5 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/GPSStatus.h b/src/GPSStatus.h index bcd371eb8..a15e385a8 100644 --- a/src/GPSStatus.h +++ b/src/GPSStatus.h @@ -63,7 +63,7 @@ class GPSStatus : public Status int32_t getLatitude() const { if (radioConfig.preferences.fixed_position){ -#if GPS_EXTRAVERBOSE +#ifdef GPS_EXTRAVERBOSE DEBUG_MSG("WARNING: Using fixed latitude\n"); #endif NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); @@ -75,7 +75,7 @@ class GPSStatus : public Status int32_t getLongitude() const { if (radioConfig.preferences.fixed_position){ -#if GPS_EXTRAVERBOSE +#ifdef GPS_EXTRAVERBOSE DEBUG_MSG("WARNING: Using fixed longitude\n"); #endif NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); @@ -87,7 +87,7 @@ class GPSStatus : public Status int32_t getAltitude() const { if (radioConfig.preferences.fixed_position){ -#if GPS_EXTRAVERBOSE +#ifdef GPS_EXTRAVERBOSE DEBUG_MSG("WARNING: Using fixed altitude\n"); #endif NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); @@ -105,7 +105,7 @@ class GPSStatus : public Status bool matches(const GPSStatus *newStatus) const { -#if GPS_EXTRAVERBOSE +#ifdef GPS_EXTRAVERBOSE DEBUG_MSG("GPSStatus.match() new pos@%x to old pos@%x\n", newStatus->p.pos_timestamp, p.pos_timestamp); #endif diff --git a/src/configuration.h b/src/configuration.h index 8f0d3cfa5..628cd0bf1 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -100,6 +100,10 @@ along with this program. If not, see . #define GPS_TX_PIN 12 #endif +#ifndef TTGO_T_ECHO +#define GPS_UBLOX +#endif + // ----------------------------------------------------------------------------- // LoRa SPI // ----------------------------------------------------------------------------- diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 57647472c..45e3eb1a1 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -54,6 +54,56 @@ bool GPS::setupGPS() _serial_gps->write("$PCAS11,3*1E\r\n"); delay(250); +#endif +#ifdef GPS_UBLOX + // Set the UART port to output NMEA only + byte _message_nmea[] = {0xB5, 0x62, 0x06, 0x00, 0x14, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xC0, 0x08, 0x00, 0x00, 0x80, 0x25, 0x00, 0x00, 0x07, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x91, 0xAF}; + _serial_gps->write(_message_nmea,sizeof(_message_nmea)); + delay(250); + + // disable GGL + byte _message_GGL[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, + 0xF0, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, + 0x05,0x3A}; + _serial_gps->write(_message_GGL,sizeof(_message_GGL)); + delay(250); + + // disable GSA + byte _message_GSA[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, + 0xF0, 0x02, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, + 0x06,0x41}; + _serial_gps->write(_message_GSA,sizeof(_message_GSA)); + delay(250); + + // disable GSV + byte _message_GSV[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, + 0xF0, 0x03, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, + 0x07,0x48}; + _serial_gps->write(_message_GSV,sizeof(_message_GSV)); + delay(250); + + // disable VTG + byte _message_VTG[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, + 0xF0, 0x05, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, + 0x09,0x56}; + _serial_gps->write(_message_VTG,sizeof(_message_VTG)); + delay(250); + + // enable RMC + byte _message_RMC[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, + 0xF0, 0x04, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x09,0x54}; + _serial_gps->write(_message_RMC,sizeof(_message_RMC)); + delay(250); + + // enable GGA + byte _message_GGA[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, + 0xF0, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x05, 0x38}; + _serial_gps->write(_message_GGA,sizeof(_message_GGA)); + delay(250); #endif } diff --git a/src/gps/NMEAGPS.cpp b/src/gps/NMEAGPS.cpp index 73031139a..7560c0b30 100644 --- a/src/gps/NMEAGPS.cpp +++ b/src/gps/NMEAGPS.cpp @@ -129,10 +129,16 @@ bool NMEAGPS::lookForLocation() auto loc = reader.location.value(); // Bail out EARLY to avoid overwriting previous good data (like #857) - if((toDegInt(loc.lat) == 0) || (toDegInt(loc.lat) > 90)) { + if (toDegInt(loc.lat) > 900000000) { +#ifdef GPS_EXTRAVERBOSE + DEBUG_MSG("Bail out EARLY on LAT %i\n",toDegInt(loc.lat)); +#endif return false; } - if((toDegInt(loc.lng) == 0) || (toDegInt(loc.lng) > 180)) { + if (toDegInt(loc.lng) > 1800000000) { +#ifdef GPS_EXTRAVERBOSE + DEBUG_MSG("Bail out EARLY on LNG %i\n",toDegInt(loc.lng)); +#endif return false; } diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 36d3b2251..fa1b2a90c 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -224,7 +224,7 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *newStatus) } else { // The GPS has lost lock, if we are fixed position we should just keep using // the old position -#if GPS_EXTRAVERBOSE +#ifdef GPS_EXTRAVERBOSE DEBUG_MSG("onGPSchanged() - lost validLocation\n"); #endif if (radioConfig.preferences.fixed_position) { From 3786b1ee159b63a8aa6b3fce99a14d90bb773d4c Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 26 Apr 2022 06:48:26 -0500 Subject: [PATCH 03/31] Reboot implementation for nrf devices (#1411) --- src/shutdown.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shutdown.h b/src/shutdown.h index 10c93bde2..ce1da1f36 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -6,10 +6,13 @@ void powerCommandsCheck() { + DEBUG_MSG("Rebooting\n"); + if (rebootAtMsec && millis() > rebootAtMsec) { #ifndef NO_ESP32 - DEBUG_MSG("Rebooting for update\n"); ESP.restart(); +#elif NRF52_SERIES + NVIC_SystemReset(); #else DEBUG_MSG("FIXME implement reboot for this platform"); #endif From 75e7bccdfb9b3ea9353bcd54bac456f96775b957 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 26 Apr 2022 06:49:05 -0500 Subject: [PATCH 04/31] Fix assert execution halt in nrf devices (#1410) --- src/nrf52/main-nrf52.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index 655170c36..90ab0113f 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -33,8 +33,8 @@ void __attribute__((noreturn)) __assert_func(const char *file, int line, const c { DEBUG_MSG("assert failed %s: %d, %s, test=%s\n", file, line, func, failedexpr); // debugger_break(); FIXME doesn't work, possibly not for segger - while (1) - ; // FIXME, reboot! + // Reboot cpu + NVIC_SystemReset(); } void getMacAddr(uint8_t *dmac) @@ -196,4 +196,4 @@ void clearBonds() { nrf52Bluetooth->setup(); } nrf52Bluetooth->clearBonds(); -} \ No newline at end of file +} From 76e48178c80aee6f759786c7632274d5deb643e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 26 Apr 2022 17:50:50 +0200 Subject: [PATCH 05/31] use a tiny software AES lib if user needs AES-256 --- src/nrf52/NRF52CryptoEngine.cpp | 16 ++- src/nrf52/aes-256/tiny-aes.cpp | 239 ++++++++++++++++++++++++++++++++ src/nrf52/aes-256/tiny-aes.h | 23 +++ 3 files changed, 275 insertions(+), 3 deletions(-) create mode 100644 src/nrf52/aes-256/tiny-aes.cpp create mode 100644 src/nrf52/aes-256/tiny-aes.h diff --git a/src/nrf52/NRF52CryptoEngine.cpp b/src/nrf52/NRF52CryptoEngine.cpp index 49f85a857..b508ed554 100644 --- a/src/nrf52/NRF52CryptoEngine.cpp +++ b/src/nrf52/NRF52CryptoEngine.cpp @@ -1,7 +1,7 @@ #include "configuration.h" #include "CryptoEngine.h" #include - +#include "aes-256/tiny-aes.h" class NRF52CryptoEngine : public CryptoEngine { public: @@ -18,7 +18,12 @@ class NRF52CryptoEngine : public CryptoEngine { // DEBUG_MSG("NRF52 encrypt!\n"); - if (key.length > 0) { + if (key.length > 16) { + AES_ctx ctx; + initNonce(fromNode, packetId); + AES_init_ctx_iv(&ctx, key.bytes, nonce); + AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes); + } else if (key.length > 0) { nRFCrypto.begin(); nRFCrypto_AES ctx; uint8_t myLen = ctx.blockLen(numBytes); @@ -36,7 +41,12 @@ class NRF52CryptoEngine : public CryptoEngine { // DEBUG_MSG("NRF52 decrypt!\n"); - if (key.length > 0) { + if (key.length > 16) { + AES_ctx ctx; + initNonce(fromNode, packetId); + AES_init_ctx_iv(&ctx, key.bytes, nonce); + AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes); + } else if (key.length > 0) { nRFCrypto.begin(); nRFCrypto_AES ctx; uint8_t myLen = ctx.blockLen(numBytes); diff --git a/src/nrf52/aes-256/tiny-aes.cpp b/src/nrf52/aes-256/tiny-aes.cpp new file mode 100644 index 000000000..48435ce7d --- /dev/null +++ b/src/nrf52/aes-256/tiny-aes.cpp @@ -0,0 +1,239 @@ +/* +AES-256 Software Implementation + +based on https://github.com/kokke/tiny-AES-C/ which is in public domain + +NOTE: String length must be evenly divisible by 16byte (str_len % 16 == 0) + You should pad the end of the string with zeros if this is not the case. + For AES192/256 the key size is proportionally larger. +*/ + +#include +#include "tiny-aes.h" + +#define Nb 4 +#define Nk 8 +#define Nr 14 + +typedef uint8_t state_t[4][4]; + +static const uint8_t sbox[256] = { + //0 1 2 3 4 5 6 7 8 9 A B C D E F + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; + +static const uint8_t Rcon[11] = { + 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 }; + +#define getSBoxValue(num) (sbox[(num)]) + +static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) +{ + unsigned i, j, k; + uint8_t tempa[4]; + + for (i = 0; i < Nk; ++i) + { + RoundKey[(i * 4) + 0] = Key[(i * 4) + 0]; + RoundKey[(i * 4) + 1] = Key[(i * 4) + 1]; + RoundKey[(i * 4) + 2] = Key[(i * 4) + 2]; + RoundKey[(i * 4) + 3] = Key[(i * 4) + 3]; + } + + for (i = Nk; i < Nb * (Nr + 1); ++i) + { + { + k = (i - 1) * 4; + tempa[0]=RoundKey[k + 0]; + tempa[1]=RoundKey[k + 1]; + tempa[2]=RoundKey[k + 2]; + tempa[3]=RoundKey[k + 3]; + + } + + if (i % Nk == 0) + { + const uint8_t u8tmp = tempa[0]; + tempa[0] = tempa[1]; + tempa[1] = tempa[2]; + tempa[2] = tempa[3]; + tempa[3] = u8tmp; + + tempa[0] = getSBoxValue(tempa[0]); + tempa[1] = getSBoxValue(tempa[1]); + tempa[2] = getSBoxValue(tempa[2]); + tempa[3] = getSBoxValue(tempa[3]); + + tempa[0] = tempa[0] ^ Rcon[i/Nk]; + } + + if (i % Nk == 4) + { + tempa[0] = getSBoxValue(tempa[0]); + tempa[1] = getSBoxValue(tempa[1]); + tempa[2] = getSBoxValue(tempa[2]); + tempa[3] = getSBoxValue(tempa[3]); + } + + j = i * 4; k=(i - Nk) * 4; + RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0]; + RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1]; + RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2]; + RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3]; + } +} + +void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key) +{ + KeyExpansion(ctx->RoundKey, key); +} +void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv) +{ + KeyExpansion(ctx->RoundKey, key); + memcpy (ctx->Iv, iv, AES_BLOCKLEN); +} +void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv) +{ + memcpy (ctx->Iv, iv, AES_BLOCKLEN); +} + +static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey) +{ + uint8_t i,j; + for (i = 0; i < 4; ++i) + { + for (j = 0; j < 4; ++j) + { + (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j]; + } + } +} + +static void SubBytes(state_t* state) +{ + uint8_t i, j; + for (i = 0; i < 4; ++i) + { + for (j = 0; j < 4; ++j) + { + (*state)[j][i] = getSBoxValue((*state)[j][i]); + } + } +} + +static void ShiftRows(state_t* state) +{ + uint8_t temp; + + temp = (*state)[0][1]; + (*state)[0][1] = (*state)[1][1]; + (*state)[1][1] = (*state)[2][1]; + (*state)[2][1] = (*state)[3][1]; + (*state)[3][1] = temp; + + temp = (*state)[0][2]; + (*state)[0][2] = (*state)[2][2]; + (*state)[2][2] = temp; + + temp = (*state)[1][2]; + (*state)[1][2] = (*state)[3][2]; + (*state)[3][2] = temp; + + temp = (*state)[0][3]; + (*state)[0][3] = (*state)[3][3]; + (*state)[3][3] = (*state)[2][3]; + (*state)[2][3] = (*state)[1][3]; + (*state)[1][3] = temp; +} + +static uint8_t xtime(uint8_t x) +{ + return ((x<<1) ^ (((x>>7) & 1) * 0x1b)); +} + +static void MixColumns(state_t* state) +{ + uint8_t i; + uint8_t Tmp, Tm, t; + for (i = 0; i < 4; ++i) + { + t = (*state)[i][0]; + Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ; + Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ; + Tm = (*state)[i][1] ^ (*state)[i][2] ; Tm = xtime(Tm); (*state)[i][1] ^= Tm ^ Tmp ; + Tm = (*state)[i][2] ^ (*state)[i][3] ; Tm = xtime(Tm); (*state)[i][2] ^= Tm ^ Tmp ; + Tm = (*state)[i][3] ^ t ; Tm = xtime(Tm); (*state)[i][3] ^= Tm ^ Tmp ; + } +} + +#define Multiply(x, y) \ + ( ((y & 1) * x) ^ \ + ((y>>1 & 1) * xtime(x)) ^ \ + ((y>>2 & 1) * xtime(xtime(x))) ^ \ + ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ \ + ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))) \ + + +static void Cipher(state_t* state, const uint8_t* RoundKey) +{ + uint8_t round = 0; + + AddRoundKey(0, state, RoundKey); + + for (round = 1; ; ++round) + { + SubBytes(state); + ShiftRows(state); + if (round == Nr) { + break; + } + MixColumns(state); + AddRoundKey(round, state, RoundKey); + } + AddRoundKey(Nr, state, RoundKey); +} + +void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length) +{ + uint8_t buffer[AES_BLOCKLEN]; + + size_t i; + int bi; + for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi) + { + if (bi == AES_BLOCKLEN) + { + + memcpy(buffer, ctx->Iv, AES_BLOCKLEN); + Cipher((state_t*)buffer,ctx->RoundKey); + + for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi) + { + if (ctx->Iv[bi] == 255) + { + ctx->Iv[bi] = 0; + continue; + } + ctx->Iv[bi] += 1; + break; + } + bi = 0; + } + + buf[i] = (buf[i] ^ buffer[bi]); + } +} diff --git a/src/nrf52/aes-256/tiny-aes.h b/src/nrf52/aes-256/tiny-aes.h new file mode 100644 index 000000000..eded2c77f --- /dev/null +++ b/src/nrf52/aes-256/tiny-aes.h @@ -0,0 +1,23 @@ +#ifndef _TINY_AES_H_ +#define _TINY_AES_H_ + +#include +#include + +#define AES_BLOCKLEN 16 // Block length in bytes - AES is 128b block only +// #define AES_KEYLEN 32 +#define AES_keyExpSize 240 + +struct AES_ctx +{ + uint8_t RoundKey[AES_keyExpSize]; + uint8_t Iv[AES_BLOCKLEN]; +}; + +void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key); +void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv); +void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv); + +void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length); + +#endif // _TINY_AES_H_ From 92185e763d2f858a7068178f9d4ef6fe8a192e11 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 26 Apr 2022 14:10:17 -0500 Subject: [PATCH 06/31] Bump version for another 1.3 release --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index d46454914..44643f1aa 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 1 minor = 3 -build = 8 +build = 9 From aaea2e74565f3cf6240abfaa0cb7e750cad805a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 26 Apr 2022 21:24:21 +0200 Subject: [PATCH 07/31] make cppcheck happy --- src/nrf52/aes-256/tiny-aes.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/nrf52/aes-256/tiny-aes.cpp b/src/nrf52/aes-256/tiny-aes.cpp index 48435ce7d..256ae55d8 100644 --- a/src/nrf52/aes-256/tiny-aes.cpp +++ b/src/nrf52/aes-256/tiny-aes.cpp @@ -43,10 +43,9 @@ static const uint8_t Rcon[11] = { static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) { - unsigned i, j, k; uint8_t tempa[4]; - for (i = 0; i < Nk; ++i) + for (unsigned i = 0; i < Nk; ++i) { RoundKey[(i * 4) + 0] = Key[(i * 4) + 0]; RoundKey[(i * 4) + 1] = Key[(i * 4) + 1]; @@ -57,7 +56,7 @@ static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) for (i = Nk; i < Nb * (Nr + 1); ++i) { { - k = (i - 1) * 4; + unsigned k = (i - 1) * 4; tempa[0]=RoundKey[k + 0]; tempa[1]=RoundKey[k + 1]; tempa[2]=RoundKey[k + 2]; @@ -89,7 +88,7 @@ static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) tempa[3] = getSBoxValue(tempa[3]); } - j = i * 4; k=(i - Nk) * 4; + unsigned j = i * 4; k=(i - Nk) * 4; RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0]; RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1]; RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2]; @@ -113,10 +112,9 @@ void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv) static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey) { - uint8_t i,j; - for (i = 0; i < 4; ++i) + for (uint8_t i = 0; i < 4; ++i) { - for (j = 0; j < 4; ++j) + for (uint8_t j = 0; j < 4; ++j) { (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j]; } @@ -125,10 +123,9 @@ static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey) static void SubBytes(state_t* state) { - uint8_t i, j; - for (i = 0; i < 4; ++i) + for (uint8_t i = 0; i < 4; ++i) { - for (j = 0; j < 4; ++j) + for (uint8_t j = 0; j < 4; ++j) { (*state)[j][i] = getSBoxValue((*state)[j][i]); } @@ -137,9 +134,7 @@ static void SubBytes(state_t* state) static void ShiftRows(state_t* state) { - uint8_t temp; - - temp = (*state)[0][1]; + uint8_t temp = (*state)[0][1]; (*state)[0][1] = (*state)[1][1]; (*state)[1][1] = (*state)[2][1]; (*state)[2][1] = (*state)[3][1]; @@ -167,13 +162,11 @@ static uint8_t xtime(uint8_t x) static void MixColumns(state_t* state) { - uint8_t i; - uint8_t Tmp, Tm, t; - for (i = 0; i < 4; ++i) + for (uint8_t i = 0; i < 4; ++i) { - t = (*state)[i][0]; - Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ; - Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ; + uint8_t t = (*state)[i][0]; + uint8_t Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ; + uint8_t Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ; Tm = (*state)[i][1] ^ (*state)[i][2] ; Tm = xtime(Tm); (*state)[i][1] ^= Tm ^ Tmp ; Tm = (*state)[i][2] ^ (*state)[i][3] ; Tm = xtime(Tm); (*state)[i][2] ^= Tm ^ Tmp ; Tm = (*state)[i][3] ^ t ; Tm = xtime(Tm); (*state)[i][3] ^= Tm ^ Tmp ; From 96f20287ff3113ed62bb47d52a57a2463364b6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 26 Apr 2022 21:30:14 +0200 Subject: [PATCH 08/31] fix scope error --- src/nrf52/aes-256/tiny-aes.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/nrf52/aes-256/tiny-aes.cpp b/src/nrf52/aes-256/tiny-aes.cpp index 256ae55d8..dc28a5249 100644 --- a/src/nrf52/aes-256/tiny-aes.cpp +++ b/src/nrf52/aes-256/tiny-aes.cpp @@ -53,16 +53,13 @@ static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) RoundKey[(i * 4) + 3] = Key[(i * 4) + 3]; } - for (i = Nk; i < Nb * (Nr + 1); ++i) + for (unsigned i = Nk; i < Nb * (Nr + 1); ++i) { - { - unsigned k = (i - 1) * 4; - tempa[0]=RoundKey[k + 0]; - tempa[1]=RoundKey[k + 1]; - tempa[2]=RoundKey[k + 2]; - tempa[3]=RoundKey[k + 3]; - - } + unsigned k = (i - 1) * 4; + tempa[0]=RoundKey[k + 0]; + tempa[1]=RoundKey[k + 1]; + tempa[2]=RoundKey[k + 2]; + tempa[3]=RoundKey[k + 3]; if (i % Nk == 0) { From 359b41d869c6e7ad5d073cbdf331c11ea82c8454 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 26 Apr 2022 19:40:24 -0500 Subject: [PATCH 09/31] Position fwd phone (#1413) * Correct factory reset code for NRF (from 1.2) * Changes from 1.2 * Update proto ref * Whoops Co-authored-by: Ben Meadors --- src/mesh/MeshService.cpp | 32 ++++++++++++++++++++------------ src/mesh/MeshService.h | 5 ++++- src/modules/PositionModule.cpp | 2 +- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index fa1b2a90c..6fe8cd38d 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -71,17 +71,7 @@ int MeshService::handleFromRadio(const MeshPacket *mp) printPacket("Forwarding to phone", mp); nodeDB.updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio - fromNum++; - - if (toPhoneQueue.numFree() == 0) { - DEBUG_MSG("NOTE: tophone queue is full, discarding oldest\n"); - MeshPacket *d = toPhoneQueue.dequeuePtr(0); - if (d) - releaseToPool(d); - } - - MeshPacket *copied = packetPool.allocCopy(*mp); - assert(toPhoneQueue.enqueue(copied, 0)); // FIXME, instead of failing for full queue, delete the oldest mssages + sendToPhone((MeshPacket *)mp); return 0; } @@ -161,12 +151,16 @@ bool MeshService::cancelSending(PacketId id) return router->cancelSending(nodeDB.getNodeNum(), id); } -void MeshService::sendToMesh(MeshPacket *p, RxSource src) +void MeshService::sendToMesh(MeshPacket *p, RxSource src, bool ccToPhone) { nodeDB.updateFrom(*p); // update our local DB for this packet (because phone might have sent position packets etc...) // Note: We might return !OK if our fifo was full, at that point the only option we have is to drop it router->sendLocal(p, src); + + if (ccToPhone) { + sendToPhone(p); + } } void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies) @@ -187,6 +181,20 @@ void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies) } } +void MeshService::sendToPhone(MeshPacket *p) { + if (toPhoneQueue.numFree() == 0) { + DEBUG_MSG("NOTE: tophone queue is full, discarding oldest\n"); + MeshPacket *d = toPhoneQueue.dequeuePtr(0); + if (d) + releaseToPool(d); + } + + MeshPacket *copied = packetPool.allocCopy(*p); + perhapsDecode(copied); + assert(toPhoneQueue.enqueue(copied, 0)); // FIXME, instead of failing for full queue, delete the oldest mssages + fromNum++; +} + NodeInfo *MeshService::refreshMyNodeInfo() { NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); diff --git a/src/mesh/MeshService.h b/src/mesh/MeshService.h index 3abae8efe..45559d3a2 100644 --- a/src/mesh/MeshService.h +++ b/src/mesh/MeshService.h @@ -75,7 +75,7 @@ class MeshService /// Send a packet into the mesh - note p must have been allocated from packetPool. We will return it to that pool after /// sending. This is the ONLY function you should use for sending messages into the mesh, because it also updates the nodedb /// cache - void sendToMesh(MeshPacket *p, RxSource src = RX_SRC_LOCAL); + void sendToMesh(MeshPacket *p, RxSource src = RX_SRC_LOCAL, bool ccToPhone = false); /** Attempt to cancel a previously sent packet from this _local_ node. Returns true if a packet was found we could cancel */ bool cancelSending(PacketId id); @@ -83,6 +83,9 @@ class MeshService /// Pull the latest power and time info into my nodeinfo NodeInfo *refreshMyNodeInfo(); + /// Send a packet to the phone + void sendToPhone(MeshPacket *p); + private: /// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh /// returns 0 to allow futher processing diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index da34ed69e..750920714 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -118,7 +118,7 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies) p->priority = MeshPacket_Priority_BACKGROUND; prevPacketId = p->id; - service.sendToMesh(p); + service.sendToMesh(p, RX_SRC_LOCAL, true); } int32_t PositionModule::runOnce() From a0f34a8d0a98d942c417e8b5cbeac9dd5c5a3fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 27 Apr 2022 11:00:26 +0200 Subject: [PATCH 10/31] Make Debug Log less spammy --- src/shutdown.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/shutdown.h b/src/shutdown.h index ce1da1f36..17ceb75dd 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -6,13 +6,12 @@ void powerCommandsCheck() { - DEBUG_MSG("Rebooting\n"); - if (rebootAtMsec && millis() > rebootAtMsec) { + DEBUG_MSG("Rebooting\n"); #ifndef NO_ESP32 ESP.restart(); #elif NRF52_SERIES - NVIC_SystemReset(); + NVIC_SystemReset(); #else DEBUG_MSG("FIXME implement reboot for this platform"); #endif From 3a9086dfc5831fe5e11dc1df596bbaf0306c3d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 27 Apr 2022 11:02:45 +0200 Subject: [PATCH 11/31] We may have RAK modules in Slot D pulling IO5 to Low permanently (like the RAK12002 RTC Module). React to assumed Long presses of the device button only 30 seconds after bootup to prevent a reboot loop. This is Particularly important for button-less RAK19003 Baseboard. --- src/ButtonThread.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 8a6603888..3a6f67a72 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -135,7 +135,7 @@ class ButtonThread : public concurrency::OSThread screen->adjustBrightness(); #endif // If user button is held down for 5 seconds, shutdown the device. - if (millis() - longPressTime > 5 * 1000) { + if ((millis() - longPressTime > 5 * 1000) && (longPressTime > 0)) { #ifdef TBEAM_V10 if (axp192_found == true) { setLed(false); @@ -144,7 +144,7 @@ class ButtonThread : public concurrency::OSThread #elif NRF52_SERIES // Do actual shutdown when button released, otherwise the button release // may wake the board immediatedly. - if (!shutdown_on_long_stop) { + if ((!shutdown_on_long_stop) && (millis() > 30 * 1000)) { screen->startShutdownScreen(); DEBUG_MSG("Shutdown from long press"); playBeep(); @@ -180,18 +180,22 @@ class ButtonThread : public concurrency::OSThread static void userButtonPressedLongStart() { - DEBUG_MSG("Long press start!\n"); - longPressTime = millis(); + if (millis() > 30 * 1000) { + DEBUG_MSG("Long press start!\n"); + longPressTime = millis(); + } } static void userButtonPressedLongStop() { - DEBUG_MSG("Long press stop!\n"); - longPressTime = 0; - if (shutdown_on_long_stop) { - playShutdownMelody(); - delay(3000); - power->shutdown(); + if (millis() > 30 * 1000){ + DEBUG_MSG("Long press stop!\n"); + longPressTime = 0; + if (shutdown_on_long_stop) { + playShutdownMelody(); + delay(3000); + power->shutdown(); + } } } }; From 9e97fac25206577c5404bcb4368b2c1a97e54c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 27 Apr 2022 11:05:08 +0200 Subject: [PATCH 12/31] - implement generic support for on-device battery powered RTC Modules. - implement support for I2C RV-3028 based RTC modules like the RAK12002 - pretty print some debug timestamps --- src/RedirectablePrint.cpp | 2 +- src/configuration.h | 4 +++ src/debug/i2cScan.h | 13 +++++++-- src/gps/NMEAGPS.cpp | 2 +- src/gps/RTC.cpp | 40 ++++++++++++++++++++++---- src/gps/RTC.h | 10 +++++-- src/graphics/Screen.cpp | 2 +- src/main.cpp | 3 ++ src/main.h | 1 + variants/rak4631/platformio.ini | 1 + variants/rak4631/variant.h | 3 ++ variants/rak4631_epaper/platformio.ini | 1 + variants/rak4631_epaper/variant.h | 3 ++ 13 files changed, 72 insertions(+), 13 deletions(-) diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index dc0f3b958..a2f048f8e 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -72,7 +72,7 @@ size_t RedirectablePrint::logDebug(const char *format, ...) // If we are the first message on a report, include the header if (!isContinuationMessage) { - uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityFromNet); + uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice); if (rtc_sec > 0) { long hms = rtc_sec % SEC_PER_DAY; // hms += tz.tz_dsttime * SEC_PER_HOUR; diff --git a/src/configuration.h b/src/configuration.h index 628cd0bf1..60cf7512b 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -25,6 +25,10 @@ along with this program. If not, see . #pragma once #include +#ifdef RV3028_RTC + #include "Melopero_RV3028.h" +#endif + // ----------------------------------------------------------------------------- // Version // ----------------------------------------------------------------------------- diff --git a/src/debug/i2cScan.h b/src/debug/i2cScan.h index 4279a5122..ae6384fbc 100644 --- a/src/debug/i2cScan.h +++ b/src/debug/i2cScan.h @@ -54,7 +54,16 @@ void scanI2Cdevice(void) DEBUG_MSG("unknown display found\n"); } } - +#ifdef RV3028_RTC + if (addr == RV3028_RTC){ + rtc_found = addr; + DEBUG_MSG("RV3028 RTC found\n"); + Melopero_RV3028 rtc; + rtc.initI2C(); + rtc.writeToRegister(0x35,0x07); // no Clkout + rtc.writeToRegister(0x37,0xB4); + } +#endif if (addr == CARDKB_ADDR) { cardkb_found = addr; DEBUG_MSG("m5 cardKB found\n"); @@ -81,7 +90,7 @@ void scanI2Cdevice(void) if (nDevices == 0) DEBUG_MSG("No I2C devices found\n"); else - DEBUG_MSG("done\n"); + DEBUG_MSG("%i I2C devices found\n",nDevices); } #else void scanI2Cdevice(void) {} diff --git a/src/gps/NMEAGPS.cpp b/src/gps/NMEAGPS.cpp index 7560c0b30..8a8181f3b 100644 --- a/src/gps/NMEAGPS.cpp +++ b/src/gps/NMEAGPS.cpp @@ -65,7 +65,7 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s t.tm_year = d.year() - 1900; t.tm_isdst = false; if (t.tm_mon > -1){ - DEBUG_MSG("NMEA GPS time %d-%d-%d %d:%d:%d\n", d.year(), d.month(), t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); + DEBUG_MSG("NMEA GPS time %02d-%02d-%02d %02d:%02d:%02d\n", d.year(), d.month(), t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); perhapsSetRTC(RTCQualityGPS, t); return true; } else diff --git a/src/gps/RTC.cpp b/src/gps/RTC.cpp index bc7e816cb..e717f97ba 100644 --- a/src/gps/RTC.cpp +++ b/src/gps/RTC.cpp @@ -1,5 +1,6 @@ #include "RTC.h" #include "configuration.h" +#include "main.h" #include #include @@ -18,14 +19,35 @@ static uint64_t zeroOffsetSecs; // GPS based time in secs since 1970 - only upda void readFromRTC() { struct timeval tv; /* btw settimeofday() is helpfull here too*/ - +#ifdef RV3028_RTC + if(rtc_found == RV3028_RTC) { + uint32_t now = millis(); + Melopero_RV3028 rtc; + rtc.initI2C(); + tm t; + t.tm_year = rtc.getYear() - 1900; + t.tm_mon = rtc.getMonth() - 1; + t.tm_mday = rtc.getDate(); + t.tm_hour = rtc.getHour(); + t.tm_min = rtc.getMinute(); + t.tm_sec = rtc.getSecond(); + tv.tv_sec = mktime(&t); + tv.tv_usec = 0; + DEBUG_MSG("Read RTC time from RV3028 as %ld\n", tv.tv_sec); + timeStartMsec = now; + zeroOffsetSecs = tv.tv_sec; + if (currentQuality == RTCQualityNone) { + currentQuality = RTCQualityDevice; + } + } +#else if (!gettimeofday(&tv, NULL)) { uint32_t now = millis(); - - DEBUG_MSG("Read RTC time as %ld (cur millis %u) quality=%d\n", tv.tv_sec, now, currentQuality); + DEBUG_MSG("Read RTC time as %ld\n", tv.tv_sec); timeStartMsec = now; zeroOffsetSecs = tv.tv_sec; } +#endif } /// If we haven't yet set our RTC this boot, set it from a GPS derived time @@ -55,12 +77,20 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv) zeroOffsetSecs = tv->tv_sec; // If this platform has a setable RTC, set it -#ifndef NO_ESP32 +#ifdef RV3028_RTC + if(rtc_found == RV3028_RTC) { + Melopero_RV3028 rtc; + rtc.initI2C(); + tm *t = localtime(&tv->tv_sec); + rtc.setTime(t->tm_year + 1900, t->tm_mon + 1, t->tm_wday, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); + DEBUG_MSG("RV3028_RTC setTime %02d-%02d-%02d %02d:%02d:%02d %ld\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv->tv_sec); + } +#elif !defined(NO_ESP32) settimeofday(tv, NULL); #endif // nrf52 doesn't have a readable RTC (yet - software not written) -#if defined(PORTDUINO) || !defined(NO_ESP32) +#if defined(PORTDUINO) || !defined(NO_ESP32) || defined(RV3028_RTC) readFromRTC(); #endif diff --git a/src/gps/RTC.h b/src/gps/RTC.h index 730d1914e..f2df3c757 100644 --- a/src/gps/RTC.h +++ b/src/gps/RTC.h @@ -5,17 +5,21 @@ #include enum RTCQuality { + /// We haven't had our RTC set yet RTCQualityNone = 0, + /// We got time from an onboard peripheral after boot. + RTCQualityDevice = 1, + /// Some other node gave us a time we can use - RTCQualityFromNet = 1, + RTCQualityFromNet = 2, /// Our time is based on NTP - RTCQualityNTP= 2, + RTCQualityNTP= 3, /// Our time is based on our own GPS - RTCQualityGPS = 3 + RTCQualityGPS = 4 }; RTCQuality getRTCQuality(); diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index edb3ebc45..136964006 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1557,7 +1557,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat else uptime += String(seconds) + "s "; - uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityFromNet); + uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice); if (rtc_sec > 0) { long hms = rtc_sec % SEC_PER_DAY; // hms += tz.tz_dsttime * SEC_PER_HOUR; diff --git a/src/main.cpp b/src/main.cpp index afb162cee..00963e224 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,6 +79,9 @@ uint8_t cardkb_found; // The I2C address of the Faces Keyboard (if found) uint8_t faceskb_found; +// The I2C address of the RTC Module (if found) +uint8_t rtc_found; + bool eink_found = true; uint32_t serialSinceMsec; diff --git a/src/main.h b/src/main.h index fc91f396a..de79435bb 100644 --- a/src/main.h +++ b/src/main.h @@ -9,6 +9,7 @@ extern uint8_t screen_found; extern uint8_t screen_model; extern uint8_t cardkb_found; extern uint8_t faceskb_found; +extern uint8_t rtc_found; extern bool eink_found; extern bool axp192_found; diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index 6e0563598..fd9fbcd89 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -6,6 +6,7 @@ build_flags = ${nrf52840_base.build_flags} -Ivariants/rak4631 -D RAK_4631 src_filter = ${nrf52_base.src_filter} +<../variants/rak4631> lib_deps = ${nrf52840_base.lib_deps} + melopero/Melopero RV3028@^1.1.0 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink \ No newline at end of file diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index c211ec4a1..bae5d957a 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -198,6 +198,9 @@ static const uint8_t SCK = PIN_SPI_SCK; #define GPS_RX_PIN PIN_SERIAL1_RX #define GPS_TX_PIN PIN_SERIAL1_TX +// RAK12002 RTC Module +#define RV3028_RTC (uint8_t) 0b1010010 + // Battery // The battery sense is hooked to pin A0 (5) #define BATTERY_PIN PIN_A0 diff --git a/variants/rak4631_epaper/platformio.ini b/variants/rak4631_epaper/platformio.ini index fc65ac2c8..55f799e25 100644 --- a/variants/rak4631_epaper/platformio.ini +++ b/variants/rak4631_epaper/platformio.ini @@ -7,6 +7,7 @@ src_filter = ${nrf52_base.src_filter} +<../variants/rak4631_epaper> lib_deps = ${nrf52840_base.lib_deps} https://github.com/ZinggJM/GxEPD2.git + melopero/Melopero RV3028@^1.1.0 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink \ No newline at end of file diff --git a/variants/rak4631_epaper/variant.h b/variants/rak4631_epaper/variant.h index 071c659e1..12f379d06 100644 --- a/variants/rak4631_epaper/variant.h +++ b/variants/rak4631_epaper/variant.h @@ -198,6 +198,9 @@ static const uint8_t SCK = PIN_SPI_SCK; #define GPS_RX_PIN PIN_SERIAL1_RX #define GPS_TX_PIN PIN_SERIAL1_TX +// RAK12002 RTC Module +#define RV3028_RTC (uint8_t) 0b1010010 + // Battery // The battery sense is hooked to pin A0 (5) #define BATTERY_PIN PIN_A0 From cc2a84afcd9b01640847b926aa42745724330479 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 27 Apr 2022 07:03:09 -0500 Subject: [PATCH 13/31] Bump version for release --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 44643f1aa..ed0a18ceb 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 1 minor = 3 -build = 9 +build = 10 From 629db8c71859101f5fc97ffebc5cff8111a348a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 27 Apr 2022 15:30:27 +0200 Subject: [PATCH 14/31] Fix build errors and add a bit of failsafe --- src/main.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7b9abd2ac..7328feb79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -152,12 +152,11 @@ void setup() DEBUG_MSG("\n\n//\\ E S H T /\\ S T / C\n\n"); initDeepSleep(); - - #if defined(TTGO_T_ECHO) - DEBUG_MSG("\n\nTTGO_T_ECHO PIN_EINK_PWR_ON\n\n"); + + // Testing this fix für erratic T-Echo boot behaviour +#if defined(TTGO_T_ECHO) && defined(PIN_EINK_PWR_ON) pinMode(PIN_EINK_PWR_ON, OUTPUT); digitalWrite(PIN_EINK_PWR_ON, HIGH); -#elif #endif #ifdef VEXT_ENABLE From 3a5f492106cd95bb736a7669608dffe5f90b3465 Mon Sep 17 00:00:00 2001 From: mkinney Date: Wed, 27 Apr 2022 10:20:10 -0700 Subject: [PATCH 15/31] add nano_g1 to build (#1417) --- bin/build-all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/build-all.sh b/bin/build-all.sh index 6ab69d3ef..809c9fcbe 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -5,7 +5,7 @@ set -e VERSION=`bin/buildinfo.py long` SHORT_VERSION=`bin/buildinfo.py short` -BOARDS_ESP32="rak11200 tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1" +BOARDS_ESP32="rak11200 tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1 nano-g1" #BOARDS_ESP32=tbeam # FIXME note nrf52840dk build is for some reason only generating a BIN file but not a HEX file nrf52840dk-geeksville is fine From 4df0e910b876e871f9d1fc7ff1c2327c8fbc76dc Mon Sep 17 00:00:00 2001 From: mkinney Date: Wed, 27 Apr 2022 10:23:20 -0700 Subject: [PATCH 16/31] Update main_matrix.yml add nano-g1 --- .github/workflows/main_matrix.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 18ecb22ed..8e7331a40 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -37,6 +37,7 @@ jobs: - board: rak4631 - board: rak4631_eink - board: t-echo + - board: nano-g1 runs-on: ubuntu-latest steps: @@ -91,6 +92,7 @@ jobs: - board: heltec-v2.1 - board: tbeam0.7 - board: meshtastic-diy-v1 + - board: nano-g1 runs-on: ubuntu-latest steps: From 516dff5b097756173af216b7e6488a8818da0973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 28 Apr 2022 08:18:03 +0200 Subject: [PATCH 17/31] RTC Module support for T-Echo and others with PCF8563 --- src/configuration.h | 3 +++ src/debug/i2cScan.h | 6 ++++++ src/gps/RTC.cpp | 30 ++++++++++++++++++++++++++++++ variants/t-echo/platformio.ini | 1 + variants/t-echo/variant.h | 3 +++ 5 files changed, 43 insertions(+) diff --git a/src/configuration.h b/src/configuration.h index 60cf7512b..3e1e680f1 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -28,6 +28,9 @@ along with this program. If not, see . #ifdef RV3028_RTC #include "Melopero_RV3028.h" #endif +#ifdef PCF8563_RTC + #include "pcf8563.h" +#endif // ----------------------------------------------------------------------------- // Version diff --git a/src/debug/i2cScan.h b/src/debug/i2cScan.h index ae6384fbc..4bfd2adf8 100644 --- a/src/debug/i2cScan.h +++ b/src/debug/i2cScan.h @@ -63,6 +63,12 @@ void scanI2Cdevice(void) rtc.writeToRegister(0x35,0x07); // no Clkout rtc.writeToRegister(0x37,0xB4); } +#endif +#ifdef PCF8563_RTC + if (addr == PCF8563_RTC){ + rtc_found = addr; + DEBUG_MSG("PCF8563 RTC found\n"); + } #endif if (addr == CARDKB_ADDR) { cardkb_found = addr; diff --git a/src/gps/RTC.cpp b/src/gps/RTC.cpp index e717f97ba..335dbe37d 100644 --- a/src/gps/RTC.cpp +++ b/src/gps/RTC.cpp @@ -40,6 +40,28 @@ void readFromRTC() currentQuality = RTCQualityDevice; } } +#elif defined(PCF8563_RTC) + if(rtc_found == PCF8563_RTC) { + uint32_t now = millis(); + PCF8563_Class rtc; + rtc.begin(); + auto tc = rtc.getDateTime(); + tm t; + t.tm_year = tc.year; + t.tm_mon = tc.month; + t.tm_mday = tc.day; + t.tm_hour = tc.hour; + t.tm_min = tc.minute; + t.tm_sec = tc.second; + tv.tv_sec = mktime(&t); + tv.tv_usec = 0; + DEBUG_MSG("Read RTC time from PCF8563 as %ld\n", tv.tv_sec); + timeStartMsec = now; + zeroOffsetSecs = tv.tv_sec; + if (currentQuality == RTCQualityNone) { + currentQuality = RTCQualityDevice; + } + } #else if (!gettimeofday(&tv, NULL)) { uint32_t now = millis(); @@ -85,6 +107,14 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv) rtc.setTime(t->tm_year + 1900, t->tm_mon + 1, t->tm_wday, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); DEBUG_MSG("RV3028_RTC setTime %02d-%02d-%02d %02d:%02d:%02d %ld\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv->tv_sec); } +#elif defined(PCF8563_RTC) + if(rtc_found == PCF8563_RTC) { + PCF8563_Class rtc; + rtc.begin(); + tm *t = localtime(&tv->tv_sec); + rtc.setDateTime(t->tm_year + 1900, t->tm_mon + 1, t->tm_wday, t->tm_hour, t->tm_min, t->tm_sec); + DEBUG_MSG("PCF8563_RTC setDateTime %02d-%02d-%02d %02d:%02d:%02d %ld\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv->tv_sec); + } #elif !defined(NO_ESP32) settimeofday(tv, NULL); #endif diff --git a/variants/t-echo/platformio.ini b/variants/t-echo/platformio.ini index 9714b0268..fca61584d 100644 --- a/variants/t-echo/platformio.ini +++ b/variants/t-echo/platformio.ini @@ -14,4 +14,5 @@ lib_deps = ${nrf52840_base.lib_deps} https://github.com/meshtastic/GxEPD2 adafruit/Adafruit BusIO + lewisxhe/PCF8563_Library@^0.0.1 ;upload_protocol = fs diff --git a/variants/t-echo/variant.h b/variants/t-echo/variant.h index 4f8946e95..094894c74 100644 --- a/variants/t-echo/variant.h +++ b/variants/t-echo/variant.h @@ -182,6 +182,9 @@ External serial flash WP25R1635FZUIL0 #define PIN_SERIAL1_RX PIN_GPS_TX #define PIN_SERIAL1_TX PIN_GPS_RX +// PCF8563 RTC Module +#define PCF8563_RTC 0x51 + /* * SPI Interfaces */ From 53cc090814a616083ca5983a18e07ca8599e88aa Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 29 Apr 2022 07:46:44 -0500 Subject: [PATCH 18/31] Move sx1262 fixes upstream (#1421) --- src/mesh/SX126xInterface.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index ac96aa70b..c051a193d 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -65,7 +65,7 @@ bool SX126xInterface::init() #ifdef SX126X_TXEN // lora.begin sets Dio2 as RF switch control, which is not true if we are manually controlling RX and TX if (res == ERR_NONE) - res = lora.setDio2AsRfSwitch(false); + res = lora.setDio2AsRfSwitch(true); #endif #if 0 @@ -194,6 +194,9 @@ void SX126xInterface::configHardwareForSend() #ifdef SX126X_TXEN // we have RXEN/TXEN control - turn on TX power / off RX power digitalWrite(SX126X_TXEN, HIGH); #endif +#ifdef SX126X_RXEN + digitalWrite(SX126X_RXEN, LOW); +#endif RadioLibInterface::configHardwareForSend(); } @@ -213,7 +216,10 @@ void SX126xInterface::startReceive() #ifdef SX126X_RXEN // we have RXEN/TXEN control - turn on RX power / off TX power digitalWrite(SX126X_RXEN, HIGH); #endif - +#ifdef SX126X_TXEN + digitalWrite(SX126X_TXEN, LOW); +#endif + // int err = lora.startReceive(); int err = lora.startReceiveDutyCycleAuto(); // We use a 32 bit preamble so this should save some power by letting radio sit in // standby mostly. @@ -283,4 +289,4 @@ bool SX126xInterface::sleep() #endif return true; -} \ No newline at end of file +} From 8e996e3e6390e16525fb7de0b97d6bc1e63a555d Mon Sep 17 00:00:00 2001 From: Mark Trevor Birss Date: Fri, 29 Apr 2022 21:23:17 +0200 Subject: [PATCH 19/31] Enable TXEN and RXEN for Waveshare LoRa Module (#1422) This change enables RXEN TXEN for the use of the Waveshare Core1262-868M Anti-Interference SX1262 LoRa Module, EU868 Band https://www.waveshare.com/core1262-868m.htm --- variants/Dongle_nRF52840-pca10059-v1/variant.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variants/Dongle_nRF52840-pca10059-v1/variant.h b/variants/Dongle_nRF52840-pca10059-v1/variant.h index 9e69a3e9e..32ab073e8 100644 --- a/variants/Dongle_nRF52840-pca10059-v1/variant.h +++ b/variants/Dongle_nRF52840-pca10059-v1/variant.h @@ -139,8 +139,8 @@ static const uint8_t SCK = PIN_SPI_SCK; #define SX126X_DIO1 (0 + 29) // DIO1 P0.29 #define SX126X_BUSY (0 + 2) // LORA_BUSY P0.02 #define SX126X_RESET (32 + 15) // LORA_RESET P1.15 -#define SX126X_TXEN (-1) // TXEN P1.13 NiceRF 868 dont use -#define SX126X_RXEN (-1) // RXEN P1.10 NiceRF 868 dont use +#define SX126X_TXEN (32 + 13) // TXEN P1.13 NiceRF 868 dont use +#define SX126X_RXEN (32 + 10) // RXEN P1.10 NiceRF 868 dont use #define SX126X_E22 #define PIN_GPS_EN (-1) From 98cd19ea0f0cf5b4bae976191753ac1dd7335a9a Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Sun, 1 May 2022 12:39:48 +1000 Subject: [PATCH 20/31] Config rework - Init getConfig --- proto | 2 +- src/mesh/generated/admin.pb.h | 29 +++++++++++++++++++++++++++++ src/modules/AdminModule.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/proto b/proto index a578453b3..de602f29b 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit a578453b3c17794b61fb6cf4470ecaac8287d6d2 +Subproject commit de602f29b743b5c46cd0205e50719ec7fd817543 diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index bd33f7b90..d1532c60c 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -12,6 +12,26 @@ #error Regenerate this file with the current version of nanopb generator. #endif +/* Enum definitions */ +typedef enum _AdminMessage_RadioConfigType { + AdminMessage_RadioConfigType_ALL = 0, + AdminMessage_RadioConfigType_CORE_ONLY = 1, + AdminMessage_RadioConfigType_MODULE_ONLY = 2, + AdminMessage_RadioConfigType_DEVICE_CONFIG = 3, + AdminMessage_RadioConfigType_GPS_CONFIG = 4, + AdminMessage_RadioConfigType_POWER_CONFIG = 5, + AdminMessage_RadioConfigType_WIFI_CONFIG = 6, + AdminMessage_RadioConfigType_DISPLAY_CONFIG = 7, + AdminMessage_RadioConfigType_LORA_CONFIG = 8, + AdminMessage_RadioConfigType_MODULE_MQTT_CONFIG = 9, + AdminMessage_RadioConfigType_MODULE_SERIAL_CONFIG = 10, + AdminMessage_RadioConfigType_MODULE_EXTNOTIF_CONFIG = 11, + AdminMessage_RadioConfigType_MODULE_STOREFORWARD_CONFIG = 12, + AdminMessage_RadioConfigType_MODULE_RANGETEST_CONFIG = 13, + AdminMessage_RadioConfigType_MODULE_ENVIRONMENTAL_CONFIG = 14, + AdminMessage_RadioConfigType_MODULE_CANNEDMSG_CONFIG = 15 +} AdminMessage_RadioConfigType; + /* Struct definitions */ /* This message is handled by the Admin module and is responsible for all settings/channel read/write operations. This message is used to do settings operations to both remote AND local nodes. @@ -29,6 +49,7 @@ typedef struct _AdminMessage { Channel get_channel_response; bool get_owner_request; User get_owner_response; + AdminMessage_RadioConfigType get_config_request; bool confirm_set_channel; bool confirm_set_radio; bool exit_simulator; @@ -50,6 +71,12 @@ typedef struct _AdminMessage { } AdminMessage; +/* Helper constants for enums */ +#define _AdminMessage_RadioConfigType_MIN AdminMessage_RadioConfigType_ALL +#define _AdminMessage_RadioConfigType_MAX AdminMessage_RadioConfigType_MODULE_CANNEDMSG_CONFIG +#define _AdminMessage_RadioConfigType_ARRAYSIZE ((AdminMessage_RadioConfigType)(AdminMessage_RadioConfigType_MODULE_CANNEDMSG_CONFIG+1)) + + #ifdef __cplusplus extern "C" { #endif @@ -68,6 +95,7 @@ extern "C" { #define AdminMessage_get_channel_response_tag 7 #define AdminMessage_get_owner_request_tag 8 #define AdminMessage_get_owner_response_tag 9 +#define AdminMessage_get_config_request_tag 10 #define AdminMessage_confirm_set_channel_tag 32 #define AdminMessage_confirm_set_radio_tag 33 #define AdminMessage_exit_simulator_tag 34 @@ -97,6 +125,7 @@ X(a, STATIC, ONEOF, UINT32, (variant,get_channel_request,get_channel_requ X(a, STATIC, ONEOF, MESSAGE, (variant,get_channel_response,get_channel_response), 7) \ X(a, STATIC, ONEOF, BOOL, (variant,get_owner_request,get_owner_request), 8) \ X(a, STATIC, ONEOF, MESSAGE, (variant,get_owner_response,get_owner_response), 9) \ +X(a, STATIC, ONEOF, UENUM, (variant,get_config_request,get_config_request), 10) \ X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_channel,confirm_set_channel), 32) \ X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_radio,confirm_set_radio), 33) \ X(a, STATIC, ONEOF, BOOL, (variant,exit_simulator,exit_simulator), 34) \ diff --git a/src/modules/AdminModule.h b/src/modules/AdminModule.h index dfe1e6c07..d80b215d2 100644 --- a/src/modules/AdminModule.h +++ b/src/modules/AdminModule.h @@ -26,6 +26,7 @@ class AdminModule : public ProtobufModule void handleGetChannel(const MeshPacket &req, uint32_t channelIndex); void handleGetRadio(const MeshPacket &req); + void handleGetConfig(const MeshPacket &req); void handleGetOwner(const MeshPacket &req); }; From 50326fbb6b9bcb7cc1f52e9034f6dad736161391 Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Sun, 1 May 2022 12:41:26 +1000 Subject: [PATCH 21/31] Config rework - Init getConfig --- src/modules/AdminModule.cpp | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 32f89da2f..4c75ae5cc 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -61,6 +61,79 @@ void AdminModule::handleGetRadio(const MeshPacket &req) } } +void AdminModule::handleGetConfig(const MeshPacket &req) +{ + // We create the reply here + AdminMessage r = AdminMessage_init_default; + r.get_radio_response = radioConfig; + + if (req.decoded.want_response) { + switch(r.get_config_request) { + case AdminMessage_RadioConfigType_ALL: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_ALL\n"); + break; + case AdminMessage_RadioConfigType_CORE_ONLY: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_CORE_ONLY\n"); + break; + case AdminMessage_RadioConfigType_MODULE_ONLY: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_ONLY\n"); + break; + case AdminMessage_RadioConfigType_DEVICE_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_DEVICE_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_GPS_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_GPS_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_POWER_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_POWER_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_WIFI_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_WIFI_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_DISPLAY_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_DISPLAY_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_LORA_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_LORA_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_MODULE_MQTT_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_MQTT_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_MODULE_SERIAL_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_SERIAL_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_MODULE_EXTNOTIF_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_EXTNOTIF_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_MODULE_STOREFORWARD_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_STOREFORWARD_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_MODULE_RANGETEST_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_RANGETEST_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_MODULE_ENVIRONMENTAL_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_ENVIRONMENTAL_CONFIG\n"); + break; + case AdminMessage_RadioConfigType_MODULE_CANNEDMSG_CONFIG: + DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_CANNEDMSG_CONFIG\n"); + break; + default: + break; + } + + // NOTE: The phone app needs to know the ls_secs & phone_timeout 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). + r.get_radio_response.preferences.ls_secs = getPref_ls_secs(); + r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs(); + // hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private and useful for users to know current provisioning) + hideSecret(r.get_radio_response.preferences.wifi_password); + + r.which_variant = AdminMessage_get_radio_response_tag; + myReply = allocDataProtobuf(r); + } +} + void AdminModule::handleGetOwner(const MeshPacket &req) { if (req.decoded.want_response) { @@ -113,6 +186,11 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r) handleGetRadio(mp); break; + case AdminMessage_get_config_request_tag: + DEBUG_MSG("Client is getting config\n"); + handleGetConfig(mp); + break; + case AdminMessage_get_owner_request_tag: DEBUG_MSG("Client is getting owner\n"); handleGetOwner(mp); From c0d40895f8515548472a4889bdd1293707b17ee7 Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Sun, 1 May 2022 16:12:48 +1000 Subject: [PATCH 22/31] Config rework - Init GetConfigResponse --- proto | 2 +- src/mesh/generated/admin.pb.h | 54 +++--- src/mesh/generated/config.pb.c | 54 ++++++ src/mesh/generated/config.pb.h | 308 +++++++++++++++++++++++++++++++++ src/modules/AdminModule.cpp | 89 ++++++---- 5 files changed, 446 insertions(+), 61 deletions(-) create mode 100644 src/mesh/generated/config.pb.c create mode 100644 src/mesh/generated/config.pb.h diff --git a/proto b/proto index de602f29b..6c790cef4 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit de602f29b743b5c46cd0205e50719ec7fd817543 +Subproject commit 6c790cef4c500f02773986726e48d45d4a218b5d diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index d1532c60c..13ec47ca2 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -7,30 +7,31 @@ #include "channel.pb.h" #include "mesh.pb.h" #include "radioconfig.pb.h" +#include "config.pb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. #endif /* Enum definitions */ -typedef enum _AdminMessage_RadioConfigType { - AdminMessage_RadioConfigType_ALL = 0, - AdminMessage_RadioConfigType_CORE_ONLY = 1, - AdminMessage_RadioConfigType_MODULE_ONLY = 2, - AdminMessage_RadioConfigType_DEVICE_CONFIG = 3, - AdminMessage_RadioConfigType_GPS_CONFIG = 4, - AdminMessage_RadioConfigType_POWER_CONFIG = 5, - AdminMessage_RadioConfigType_WIFI_CONFIG = 6, - AdminMessage_RadioConfigType_DISPLAY_CONFIG = 7, - AdminMessage_RadioConfigType_LORA_CONFIG = 8, - AdminMessage_RadioConfigType_MODULE_MQTT_CONFIG = 9, - AdminMessage_RadioConfigType_MODULE_SERIAL_CONFIG = 10, - AdminMessage_RadioConfigType_MODULE_EXTNOTIF_CONFIG = 11, - AdminMessage_RadioConfigType_MODULE_STOREFORWARD_CONFIG = 12, - AdminMessage_RadioConfigType_MODULE_RANGETEST_CONFIG = 13, - AdminMessage_RadioConfigType_MODULE_ENVIRONMENTAL_CONFIG = 14, - AdminMessage_RadioConfigType_MODULE_CANNEDMSG_CONFIG = 15 -} AdminMessage_RadioConfigType; +typedef enum _AdminMessage_ConfigType { + AdminMessage_ConfigType_ALL = 0, + AdminMessage_ConfigType_CORE_ONLY = 1, + AdminMessage_ConfigType_MODULE_ONLY = 2, + AdminMessage_ConfigType_DEVICE_CONFIG = 3, + AdminMessage_ConfigType_GPS_CONFIG = 4, + AdminMessage_ConfigType_POWER_CONFIG = 5, + AdminMessage_ConfigType_WIFI_CONFIG = 6, + AdminMessage_ConfigType_DISPLAY_CONFIG = 7, + AdminMessage_ConfigType_LORA_CONFIG = 8, + AdminMessage_ConfigType_MODULE_MQTT_CONFIG = 9, + AdminMessage_ConfigType_MODULE_SERIAL_CONFIG = 10, + AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG = 11, + AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG = 12, + AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG = 13, + AdminMessage_ConfigType_MODULE_ENVIRONMENTAL_CONFIG = 14, + AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG = 15 +} AdminMessage_ConfigType; /* Struct definitions */ /* This message is handled by the Admin module and is responsible for all settings/channel read/write operations. @@ -49,7 +50,8 @@ typedef struct _AdminMessage { Channel get_channel_response; bool get_owner_request; User get_owner_response; - AdminMessage_RadioConfigType get_config_request; + AdminMessage_ConfigType get_config_request; + Config get_config_response; bool confirm_set_channel; bool confirm_set_radio; bool exit_simulator; @@ -72,9 +74,9 @@ typedef struct _AdminMessage { /* Helper constants for enums */ -#define _AdminMessage_RadioConfigType_MIN AdminMessage_RadioConfigType_ALL -#define _AdminMessage_RadioConfigType_MAX AdminMessage_RadioConfigType_MODULE_CANNEDMSG_CONFIG -#define _AdminMessage_RadioConfigType_ARRAYSIZE ((AdminMessage_RadioConfigType)(AdminMessage_RadioConfigType_MODULE_CANNEDMSG_CONFIG+1)) +#define _AdminMessage_ConfigType_MIN AdminMessage_ConfigType_ALL +#define _AdminMessage_ConfigType_MAX AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG +#define _AdminMessage_ConfigType_ARRAYSIZE ((AdminMessage_ConfigType)(AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG+1)) #ifdef __cplusplus @@ -96,6 +98,7 @@ extern "C" { #define AdminMessage_get_owner_request_tag 8 #define AdminMessage_get_owner_response_tag 9 #define AdminMessage_get_config_request_tag 10 +#define AdminMessage_get_config_response_tag 11 #define AdminMessage_confirm_set_channel_tag 32 #define AdminMessage_confirm_set_radio_tag 33 #define AdminMessage_exit_simulator_tag 34 @@ -126,6 +129,7 @@ X(a, STATIC, ONEOF, MESSAGE, (variant,get_channel_response,get_channel_res X(a, STATIC, ONEOF, BOOL, (variant,get_owner_request,get_owner_request), 8) \ X(a, STATIC, ONEOF, MESSAGE, (variant,get_owner_response,get_owner_response), 9) \ X(a, STATIC, ONEOF, UENUM, (variant,get_config_request,get_config_request), 10) \ +X(a, STATIC, ONEOF, MESSAGE, (variant,get_config_response,get_config_response), 11) \ X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_channel,confirm_set_channel), 32) \ X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_radio,confirm_set_radio), 33) \ X(a, STATIC, ONEOF, BOOL, (variant,exit_simulator,exit_simulator), 34) \ @@ -151,6 +155,7 @@ X(a, STATIC, ONEOF, INT32, (variant,shutdown_seconds,shutdown_seconds), #define AdminMessage_variant_get_radio_response_MSGTYPE RadioConfig #define AdminMessage_variant_get_channel_response_MSGTYPE Channel #define AdminMessage_variant_get_owner_response_MSGTYPE User +#define AdminMessage_variant_get_config_response_MSGTYPE Config extern const pb_msgdesc_t AdminMessage_msg; @@ -158,7 +163,10 @@ extern const pb_msgdesc_t AdminMessage_msg; #define AdminMessage_fields &AdminMessage_msg /* Maximum encoded size of messages (where known) */ -#define AdminMessage_size 598 +#if defined(Config_size) +#define AdminMessage_size (0 + sizeof(union AdminMessage_variant_size_union)) +union AdminMessage_variant_size_union {char f0[598]; char f11[(6 + Config_size)];}; +#endif #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/config.pb.c b/src/mesh/generated/config.pb.c new file mode 100644 index 000000000..088dfd5d4 --- /dev/null +++ b/src/mesh/generated/config.pb.c @@ -0,0 +1,54 @@ +/* Automatically generated nanopb constant definitions */ +/* Generated by nanopb-0.4.5 */ + +#include "config.pb.h" +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +PB_BIND(Config, Config, AUTO) + + +PB_BIND(Config_DeviceConfig, Config_DeviceConfig, AUTO) + + +PB_BIND(Config_GpsConfig, Config_GpsConfig, AUTO) + + +PB_BIND(Config_PowerConfig, Config_PowerConfig, AUTO) + + +PB_BIND(Config_WiFiConfig, Config_WiFiConfig, AUTO) + + +PB_BIND(Config_DisplayConfig, Config_DisplayConfig, AUTO) + + +PB_BIND(Config_LoRaConfig, Config_LoRaConfig, AUTO) + + +PB_BIND(Config_ModuleConfig, Config_ModuleConfig, AUTO) + + +PB_BIND(Config_ModuleConfig_MQTTConfig, Config_ModuleConfig_MQTTConfig, AUTO) + + +PB_BIND(Config_ModuleConfig_SerialConfig, Config_ModuleConfig_SerialConfig, AUTO) + + +PB_BIND(Config_ModuleConfig_ExternalNotificationConfig, Config_ModuleConfig_ExternalNotificationConfig, AUTO) + + +PB_BIND(Config_ModuleConfig_StoreForwardConfig, Config_ModuleConfig_StoreForwardConfig, AUTO) + + +PB_BIND(Config_ModuleConfig_RangeTestConfig, Config_ModuleConfig_RangeTestConfig, AUTO) + + +PB_BIND(Config_ModuleConfig_TelemetryConfig, Config_ModuleConfig_TelemetryConfig, AUTO) + + +PB_BIND(Config_ModuleConfig_CannedMessageConfig, Config_ModuleConfig_CannedMessageConfig, AUTO) + + + diff --git a/src/mesh/generated/config.pb.h b/src/mesh/generated/config.pb.h new file mode 100644 index 000000000..cb7923d14 --- /dev/null +++ b/src/mesh/generated/config.pb.h @@ -0,0 +1,308 @@ +/* Automatically generated nanopb header */ +/* Generated by nanopb-0.4.5 */ + +#ifndef PB_CONFIG_PB_H_INCLUDED +#define PB_CONFIG_PB_H_INCLUDED +#include + +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +/* Struct definitions */ +typedef struct _Config_DeviceConfig { + char dummy_field; +} Config_DeviceConfig; + +typedef struct _Config_DisplayConfig { + char dummy_field; +} Config_DisplayConfig; + +typedef struct _Config_GpsConfig { + char dummy_field; +} Config_GpsConfig; + +typedef struct _Config_LoRaConfig { + char dummy_field; +} Config_LoRaConfig; + +typedef struct _Config_ModuleConfig_CannedMessageConfig { + char dummy_field; +} Config_ModuleConfig_CannedMessageConfig; + +typedef struct _Config_ModuleConfig_ExternalNotificationConfig { + char dummy_field; +} Config_ModuleConfig_ExternalNotificationConfig; + +typedef struct _Config_ModuleConfig_MQTTConfig { + char dummy_field; +} Config_ModuleConfig_MQTTConfig; + +typedef struct _Config_ModuleConfig_RangeTestConfig { + char dummy_field; +} Config_ModuleConfig_RangeTestConfig; + +typedef struct _Config_ModuleConfig_SerialConfig { + char dummy_field; +} Config_ModuleConfig_SerialConfig; + +typedef struct _Config_ModuleConfig_StoreForwardConfig { + char dummy_field; +} Config_ModuleConfig_StoreForwardConfig; + +typedef struct _Config_ModuleConfig_TelemetryConfig { + char dummy_field; +} Config_ModuleConfig_TelemetryConfig; + +typedef struct _Config_PowerConfig { + char dummy_field; +} Config_PowerConfig; + +typedef struct _Config_ModuleConfig { + pb_size_t which_payloadVariant; + union { + Config_ModuleConfig_MQTTConfig mqtt_config; + Config_ModuleConfig_SerialConfig serial_config; + Config_ModuleConfig_ExternalNotificationConfig external_notification_config; + Config_ModuleConfig_StoreForwardConfig store_forward_config; + Config_ModuleConfig_RangeTestConfig range_test_config; + Config_ModuleConfig_TelemetryConfig telemetry_config; + Config_ModuleConfig_CannedMessageConfig canned_message_config; + } payloadVariant; +} Config_ModuleConfig; + +typedef struct _Config_WiFiConfig { + pb_callback_t wifi_ssid; + pb_callback_t wifi_password; + bool wifi_ap_mode; +} Config_WiFiConfig; + +typedef struct _Config { + /* TODO: REPLACE */ + pb_size_t which_payloadVariant; + union { + Config_DeviceConfig device_config; + Config_GpsConfig gps_config; + Config_PowerConfig power_config; + Config_WiFiConfig wifi_config; + Config_DisplayConfig display_config; + Config_LoRaConfig lora_config; + Config_ModuleConfig module_config; + } payloadVariant; +} Config; + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Initializer values for message structs */ +#define Config_init_default {0, {Config_DeviceConfig_init_default}} +#define Config_DeviceConfig_init_default {0} +#define Config_GpsConfig_init_default {0} +#define Config_PowerConfig_init_default {0} +#define Config_WiFiConfig_init_default {{{NULL}, NULL}, {{NULL}, NULL}, 0} +#define Config_DisplayConfig_init_default {0} +#define Config_LoRaConfig_init_default {0} +#define Config_ModuleConfig_init_default {0, {Config_ModuleConfig_MQTTConfig_init_default}} +#define Config_ModuleConfig_MQTTConfig_init_default {0} +#define Config_ModuleConfig_SerialConfig_init_default {0} +#define Config_ModuleConfig_ExternalNotificationConfig_init_default {0} +#define Config_ModuleConfig_StoreForwardConfig_init_default {0} +#define Config_ModuleConfig_RangeTestConfig_init_default {0} +#define Config_ModuleConfig_TelemetryConfig_init_default {0} +#define Config_ModuleConfig_CannedMessageConfig_init_default {0} +#define Config_init_zero {0, {Config_DeviceConfig_init_zero}} +#define Config_DeviceConfig_init_zero {0} +#define Config_GpsConfig_init_zero {0} +#define Config_PowerConfig_init_zero {0} +#define Config_WiFiConfig_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, 0} +#define Config_DisplayConfig_init_zero {0} +#define Config_LoRaConfig_init_zero {0} +#define Config_ModuleConfig_init_zero {0, {Config_ModuleConfig_MQTTConfig_init_zero}} +#define Config_ModuleConfig_MQTTConfig_init_zero {0} +#define Config_ModuleConfig_SerialConfig_init_zero {0} +#define Config_ModuleConfig_ExternalNotificationConfig_init_zero {0} +#define Config_ModuleConfig_StoreForwardConfig_init_zero {0} +#define Config_ModuleConfig_RangeTestConfig_init_zero {0} +#define Config_ModuleConfig_TelemetryConfig_init_zero {0} +#define Config_ModuleConfig_CannedMessageConfig_init_zero {0} + +/* Field tags (for use in manual encoding/decoding) */ +#define Config_ModuleConfig_mqtt_config_tag 1 +#define Config_ModuleConfig_serial_config_tag 2 +#define Config_ModuleConfig_external_notification_config_tag 3 +#define Config_ModuleConfig_store_forward_config_tag 4 +#define Config_ModuleConfig_range_test_config_tag 5 +#define Config_ModuleConfig_telemetry_config_tag 6 +#define Config_ModuleConfig_canned_message_config_tag 7 +#define Config_WiFiConfig_wifi_ssid_tag 1 +#define Config_WiFiConfig_wifi_password_tag 2 +#define Config_WiFiConfig_wifi_ap_mode_tag 3 +#define Config_device_config_tag 1 +#define Config_gps_config_tag 2 +#define Config_power_config_tag 3 +#define Config_wifi_config_tag 4 +#define Config_display_config_tag 5 +#define Config_lora_config_tag 6 +#define Config_module_config_tag 7 + +/* Struct field encoding specification for nanopb */ +#define Config_FIELDLIST(X, a) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,device_config,payloadVariant.device_config), 1) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,gps_config,payloadVariant.gps_config), 2) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,power_config,payloadVariant.power_config), 3) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,wifi_config,payloadVariant.wifi_config), 4) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,display_config,payloadVariant.display_config), 5) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,lora_config,payloadVariant.lora_config), 6) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,module_config,payloadVariant.module_config), 7) +#define Config_CALLBACK NULL +#define Config_DEFAULT NULL +#define Config_payloadVariant_device_config_MSGTYPE Config_DeviceConfig +#define Config_payloadVariant_gps_config_MSGTYPE Config_GpsConfig +#define Config_payloadVariant_power_config_MSGTYPE Config_PowerConfig +#define Config_payloadVariant_wifi_config_MSGTYPE Config_WiFiConfig +#define Config_payloadVariant_display_config_MSGTYPE Config_DisplayConfig +#define Config_payloadVariant_lora_config_MSGTYPE Config_LoRaConfig +#define Config_payloadVariant_module_config_MSGTYPE Config_ModuleConfig + +#define Config_DeviceConfig_FIELDLIST(X, a) \ + +#define Config_DeviceConfig_CALLBACK NULL +#define Config_DeviceConfig_DEFAULT NULL + +#define Config_GpsConfig_FIELDLIST(X, a) \ + +#define Config_GpsConfig_CALLBACK NULL +#define Config_GpsConfig_DEFAULT NULL + +#define Config_PowerConfig_FIELDLIST(X, a) \ + +#define Config_PowerConfig_CALLBACK NULL +#define Config_PowerConfig_DEFAULT NULL + +#define Config_WiFiConfig_FIELDLIST(X, a) \ +X(a, CALLBACK, SINGULAR, STRING, wifi_ssid, 1) \ +X(a, CALLBACK, SINGULAR, STRING, wifi_password, 2) \ +X(a, STATIC, SINGULAR, BOOL, wifi_ap_mode, 3) +#define Config_WiFiConfig_CALLBACK pb_default_field_callback +#define Config_WiFiConfig_DEFAULT NULL + +#define Config_DisplayConfig_FIELDLIST(X, a) \ + +#define Config_DisplayConfig_CALLBACK NULL +#define Config_DisplayConfig_DEFAULT NULL + +#define Config_LoRaConfig_FIELDLIST(X, a) \ + +#define Config_LoRaConfig_CALLBACK NULL +#define Config_LoRaConfig_DEFAULT NULL + +#define Config_ModuleConfig_FIELDLIST(X, a) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,mqtt_config,payloadVariant.mqtt_config), 1) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,serial_config,payloadVariant.serial_config), 2) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,external_notification_config,payloadVariant.external_notification_config), 3) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,store_forward_config,payloadVariant.store_forward_config), 4) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,range_test_config,payloadVariant.range_test_config), 5) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,telemetry_config,payloadVariant.telemetry_config), 6) \ +X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,canned_message_config,payloadVariant.canned_message_config), 7) +#define Config_ModuleConfig_CALLBACK NULL +#define Config_ModuleConfig_DEFAULT NULL +#define Config_ModuleConfig_payloadVariant_mqtt_config_MSGTYPE Config_ModuleConfig_MQTTConfig +#define Config_ModuleConfig_payloadVariant_serial_config_MSGTYPE Config_ModuleConfig_SerialConfig +#define Config_ModuleConfig_payloadVariant_external_notification_config_MSGTYPE Config_ModuleConfig_ExternalNotificationConfig +#define Config_ModuleConfig_payloadVariant_store_forward_config_MSGTYPE Config_ModuleConfig_StoreForwardConfig +#define Config_ModuleConfig_payloadVariant_range_test_config_MSGTYPE Config_ModuleConfig_RangeTestConfig +#define Config_ModuleConfig_payloadVariant_telemetry_config_MSGTYPE Config_ModuleConfig_TelemetryConfig +#define Config_ModuleConfig_payloadVariant_canned_message_config_MSGTYPE Config_ModuleConfig_CannedMessageConfig + +#define Config_ModuleConfig_MQTTConfig_FIELDLIST(X, a) \ + +#define Config_ModuleConfig_MQTTConfig_CALLBACK NULL +#define Config_ModuleConfig_MQTTConfig_DEFAULT NULL + +#define Config_ModuleConfig_SerialConfig_FIELDLIST(X, a) \ + +#define Config_ModuleConfig_SerialConfig_CALLBACK NULL +#define Config_ModuleConfig_SerialConfig_DEFAULT NULL + +#define Config_ModuleConfig_ExternalNotificationConfig_FIELDLIST(X, a) \ + +#define Config_ModuleConfig_ExternalNotificationConfig_CALLBACK NULL +#define Config_ModuleConfig_ExternalNotificationConfig_DEFAULT NULL + +#define Config_ModuleConfig_StoreForwardConfig_FIELDLIST(X, a) \ + +#define Config_ModuleConfig_StoreForwardConfig_CALLBACK NULL +#define Config_ModuleConfig_StoreForwardConfig_DEFAULT NULL + +#define Config_ModuleConfig_RangeTestConfig_FIELDLIST(X, a) \ + +#define Config_ModuleConfig_RangeTestConfig_CALLBACK NULL +#define Config_ModuleConfig_RangeTestConfig_DEFAULT NULL + +#define Config_ModuleConfig_TelemetryConfig_FIELDLIST(X, a) \ + +#define Config_ModuleConfig_TelemetryConfig_CALLBACK NULL +#define Config_ModuleConfig_TelemetryConfig_DEFAULT NULL + +#define Config_ModuleConfig_CannedMessageConfig_FIELDLIST(X, a) \ + +#define Config_ModuleConfig_CannedMessageConfig_CALLBACK NULL +#define Config_ModuleConfig_CannedMessageConfig_DEFAULT NULL + +extern const pb_msgdesc_t Config_msg; +extern const pb_msgdesc_t Config_DeviceConfig_msg; +extern const pb_msgdesc_t Config_GpsConfig_msg; +extern const pb_msgdesc_t Config_PowerConfig_msg; +extern const pb_msgdesc_t Config_WiFiConfig_msg; +extern const pb_msgdesc_t Config_DisplayConfig_msg; +extern const pb_msgdesc_t Config_LoRaConfig_msg; +extern const pb_msgdesc_t Config_ModuleConfig_msg; +extern const pb_msgdesc_t Config_ModuleConfig_MQTTConfig_msg; +extern const pb_msgdesc_t Config_ModuleConfig_SerialConfig_msg; +extern const pb_msgdesc_t Config_ModuleConfig_ExternalNotificationConfig_msg; +extern const pb_msgdesc_t Config_ModuleConfig_StoreForwardConfig_msg; +extern const pb_msgdesc_t Config_ModuleConfig_RangeTestConfig_msg; +extern const pb_msgdesc_t Config_ModuleConfig_TelemetryConfig_msg; +extern const pb_msgdesc_t Config_ModuleConfig_CannedMessageConfig_msg; + +/* Defines for backwards compatibility with code written before nanopb-0.4.0 */ +#define Config_fields &Config_msg +#define Config_DeviceConfig_fields &Config_DeviceConfig_msg +#define Config_GpsConfig_fields &Config_GpsConfig_msg +#define Config_PowerConfig_fields &Config_PowerConfig_msg +#define Config_WiFiConfig_fields &Config_WiFiConfig_msg +#define Config_DisplayConfig_fields &Config_DisplayConfig_msg +#define Config_LoRaConfig_fields &Config_LoRaConfig_msg +#define Config_ModuleConfig_fields &Config_ModuleConfig_msg +#define Config_ModuleConfig_MQTTConfig_fields &Config_ModuleConfig_MQTTConfig_msg +#define Config_ModuleConfig_SerialConfig_fields &Config_ModuleConfig_SerialConfig_msg +#define Config_ModuleConfig_ExternalNotificationConfig_fields &Config_ModuleConfig_ExternalNotificationConfig_msg +#define Config_ModuleConfig_StoreForwardConfig_fields &Config_ModuleConfig_StoreForwardConfig_msg +#define Config_ModuleConfig_RangeTestConfig_fields &Config_ModuleConfig_RangeTestConfig_msg +#define Config_ModuleConfig_TelemetryConfig_fields &Config_ModuleConfig_TelemetryConfig_msg +#define Config_ModuleConfig_CannedMessageConfig_fields &Config_ModuleConfig_CannedMessageConfig_msg + +/* Maximum encoded size of messages (where known) */ +/* Config_size depends on runtime parameters */ +/* Config_WiFiConfig_size depends on runtime parameters */ +#define Config_DeviceConfig_size 0 +#define Config_DisplayConfig_size 0 +#define Config_GpsConfig_size 0 +#define Config_LoRaConfig_size 0 +#define Config_ModuleConfig_CannedMessageConfig_size 0 +#define Config_ModuleConfig_ExternalNotificationConfig_size 0 +#define Config_ModuleConfig_MQTTConfig_size 0 +#define Config_ModuleConfig_RangeTestConfig_size 0 +#define Config_ModuleConfig_SerialConfig_size 0 +#define Config_ModuleConfig_StoreForwardConfig_size 0 +#define Config_ModuleConfig_TelemetryConfig_size 0 +#define Config_ModuleConfig_size 2 +#define Config_PowerConfig_size 0 + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 4c75ae5cc..8b018092f 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -65,57 +65,72 @@ void AdminModule::handleGetConfig(const MeshPacket &req) { // We create the reply here AdminMessage r = AdminMessage_init_default; - r.get_radio_response = radioConfig; if (req.decoded.want_response) { switch(r.get_config_request) { - case AdminMessage_RadioConfigType_ALL: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_ALL\n"); + case AdminMessage_ConfigType_ALL: + DEBUG_MSG("Requesting AdminMessage_ConfigType_ALL\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_ALL; break; - case AdminMessage_RadioConfigType_CORE_ONLY: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_CORE_ONLY\n"); + case AdminMessage_ConfigType_CORE_ONLY: + DEBUG_MSG("Requesting AdminMessage_ConfigType_CORE_ONLY\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_CORE_ONLY; break; - case AdminMessage_RadioConfigType_MODULE_ONLY: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_ONLY\n"); + case AdminMessage_ConfigType_MODULE_ONLY: + DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_ONLY\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_ONLY; break; - case AdminMessage_RadioConfigType_DEVICE_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_DEVICE_CONFIG\n"); + case AdminMessage_ConfigType_DEVICE_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_DEVICE_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_DEVICE_CONFIG; break; - case AdminMessage_RadioConfigType_GPS_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_GPS_CONFIG\n"); + case AdminMessage_ConfigType_GPS_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_GPS_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_GPS_CONFIG; break; - case AdminMessage_RadioConfigType_POWER_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_POWER_CONFIG\n"); + case AdminMessage_ConfigType_POWER_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_POWER_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_POWER_CONFIG; break; - case AdminMessage_RadioConfigType_WIFI_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_WIFI_CONFIG\n"); + case AdminMessage_ConfigType_WIFI_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_WIFI_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_POWER_CONFIG; break; - case AdminMessage_RadioConfigType_DISPLAY_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_DISPLAY_CONFIG\n"); + case AdminMessage_ConfigType_DISPLAY_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_DISPLAY_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_DISPLAY_CONFIG; break; - case AdminMessage_RadioConfigType_LORA_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_LORA_CONFIG\n"); + case AdminMessage_ConfigType_LORA_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_LORA_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_LORA_CONFIG; break; - case AdminMessage_RadioConfigType_MODULE_MQTT_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_MQTT_CONFIG\n"); + case AdminMessage_ConfigType_MODULE_MQTT_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_MQTT_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_MQTT_CONFIG; break; - case AdminMessage_RadioConfigType_MODULE_SERIAL_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_SERIAL_CONFIG\n"); + case AdminMessage_ConfigType_MODULE_SERIAL_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_SERIAL_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_SERIAL_CONFIG; break; - case AdminMessage_RadioConfigType_MODULE_EXTNOTIF_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_EXTNOTIF_CONFIG\n"); + case AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG; break; - case AdminMessage_RadioConfigType_MODULE_STOREFORWARD_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_STOREFORWARD_CONFIG\n"); + case AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG; break; - case AdminMessage_RadioConfigType_MODULE_RANGETEST_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_RANGETEST_CONFIG\n"); + case AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG; break; - case AdminMessage_RadioConfigType_MODULE_ENVIRONMENTAL_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_ENVIRONMENTAL_CONFIG\n"); + case AdminMessage_ConfigType_MODULE_ENVIRONMENTAL_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_ENVIRONMENTAL_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_ENVIRONMENTAL_CONFIG; break; - case AdminMessage_RadioConfigType_MODULE_CANNEDMSG_CONFIG: - DEBUG_MSG("Requesting AdminMessage_RadioConfigType_MODULE_CANNEDMSG_CONFIG\n"); + case AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG; break; default: break; @@ -124,12 +139,12 @@ void AdminModule::handleGetConfig(const MeshPacket &req) // NOTE: The phone app needs to know the ls_secs & phone_timeout 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). - r.get_radio_response.preferences.ls_secs = getPref_ls_secs(); - r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs(); + // r.get_radio_response.preferences.ls_secs = getPref_ls_secs(); + // r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs(); // hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private and useful for users to know current provisioning) - hideSecret(r.get_radio_response.preferences.wifi_password); + // hideSecret(r.get_radio_response.preferences.wifi_password); - r.which_variant = AdminMessage_get_radio_response_tag; + r.which_variant = AdminMessage_get_config_response_tag; myReply = allocDataProtobuf(r); } } From cf64da21fbea6bc5e641829eef6efdfd9d13b556 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 1 May 2022 14:21:30 -0500 Subject: [PATCH 23/31] Move adc multiplier code into battery pin region to surpress warning --- src/Power.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 6c5301f15..e6fb9422d 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -100,12 +100,11 @@ class AnalogBatteryLevel : public HasBatteryLevel #ifndef ADC_MULTIPLIER #define ADC_MULTIPLIER 2.0 #endif - // Override variant or default ADC_MULTIPLIER if we have the override pref - float operativeAdcMultiplier = radioConfig.preferences.adc_multiplier_override > 0 ? - radioConfig.preferences.adc_multiplier_override : - ADC_MULTIPLIER; #ifdef BATTERY_PIN + // Override variant or default ADC_MULTIPLIER if we have the override pref + float operativeAdcMultiplier = radioConfig.preferences.adc_multiplier_override > 0 ? + radioConfig.preferences.adc_multiplier_override : ADC_MULTIPLIER; // Do not call analogRead() often. const uint32_t min_read_interval = 5000; if (millis() - last_read_time_ms > min_read_interval) { From 6a8724213efc0e8e5159b593162f963c67946f97 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 1 May 2022 14:22:04 -0500 Subject: [PATCH 24/31] Adafruit bus io is now required for sensor libs --- platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio.ini b/platformio.ini index bb051e5e2..5671ab513 100644 --- a/platformio.ini +++ b/platformio.ini @@ -70,6 +70,7 @@ src_filter = ${env.src_filter} - ; Common libs for environmental measurements (not included in native / portduino) [environmental] lib_deps = + adafruit/Adafruit BusIO@^1.11.4 adafruit/DHT sensor library@^1.4.1 adafruit/Adafruit Unified Sensor@^1.1.4 paulstoffregen/OneWire@^2.3.5 From 163774bb1f3380a95a09d55200fe19324bb89d41 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 1 May 2022 14:26:05 -0500 Subject: [PATCH 25/31] Moved refactored prefs --- proto | 2 +- src/mesh/NodeDB.cpp | 1 + src/mesh/NodeDB.h | 11 ++- src/mesh/generated/admin.pb.c | 1 + src/mesh/generated/admin.pb.h | 2 +- src/mesh/generated/config.pb.h | 62 ++++++++---- src/mesh/generated/radioconfig.pb.c | 1 - src/mesh/generated/radioconfig.pb.h | 66 +------------ src/mesh/generated/telemetry.pb.c | 1 + src/mesh/generated/telemetry.pb.h | 31 ++++++ src/modules/Telemetry/DeviceTelemetry.cpp | 3 +- src/modules/Telemetry/DeviceTelemetry.h | 2 + .../Telemetry/EnvironmentTelemetry.cpp | 97 +++++++++---------- src/modules/Telemetry/EnvironmentTelemetry.h | 2 + src/modules/Telemetry/Sensor/DHTSensor.cpp | 10 +- src/modules/Telemetry/Sensor/DallasSensor.cpp | 4 +- .../Telemetry/Sensor/TelemetrySensor.h | 3 +- 17 files changed, 156 insertions(+), 143 deletions(-) diff --git a/proto b/proto index 6c790cef4..d02d7131a 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 6c790cef4c500f02773986726e48d45d4a218b5d +Subproject commit d02d7131a20210a18f12a87a327753e1e34b4282 diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 660280fcb..c40849213 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -35,6 +35,7 @@ NodeDB nodeDB; EXT_RAM_ATTR DeviceState devicestate; MyNodeInfo &myNodeInfo = devicestate.my_node; RadioConfig radioConfig; +Config config; ChannelFile channelFile; /** The current change # for radio settings. Starts at 0 on boot and any time the radio settings diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 4cea56068..d7cc44e85 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -12,6 +12,7 @@ extern DeviceState devicestate; extern ChannelFile channelFile; extern MyNodeInfo &myNodeInfo; extern RadioConfig radioConfig; +extern Config config; extern User &owner; /// Given a node, return how many seconds in the past (vs now) that we last heard from it @@ -161,13 +162,17 @@ extern NodeDB nodeDB; #define IF_ROUTER(routerVal, normalVal) ((radioConfig.preferences.role == Role_Router) ? (routerVal) : (normalVal)) +#define default_broadcast_interval_secs IF_ROUTER(12 * 60 * 60, 15 * 60) + +inline uint32_t getIntervalOrDefaultMs(uint32_t interval) { + if (interval > 0) return interval * 1000; + return default_broadcast_interval_secs * 1000; +} + #define PREF_GET(name, defaultVal) \ inline uint32_t getPref_##name() { return radioConfig.preferences.name ? radioConfig.preferences.name : (defaultVal); } PREF_GET(position_broadcast_secs, IF_ROUTER(12 * 60 * 60, 15 * 60)) -// Defaulting Telemetry to the same as position interval for now -PREF_GET(telemetry_module_device_update_interval, IF_ROUTER(12 * 60 * 60, 15 * 60)) -PREF_GET(telemetry_module_environment_update_interval, IF_ROUTER(12 * 60 * 60, 15 * 60)) // Each time we wake into the DARK state allow 1 minute to send and receive BLE packets to the phone diff --git a/src/mesh/generated/admin.pb.c b/src/mesh/generated/admin.pb.c index 688cba334..aab68eb8f 100644 --- a/src/mesh/generated/admin.pb.c +++ b/src/mesh/generated/admin.pb.c @@ -10,3 +10,4 @@ PB_BIND(AdminMessage, AdminMessage, 2) + diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index 13ec47ca2..b6703c302 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -165,7 +165,7 @@ extern const pb_msgdesc_t AdminMessage_msg; /* Maximum encoded size of messages (where known) */ #if defined(Config_size) #define AdminMessage_size (0 + sizeof(union AdminMessage_variant_size_union)) -union AdminMessage_variant_size_union {char f0[598]; char f11[(6 + Config_size)];}; +union AdminMessage_variant_size_union {char f11[(6 + Config_size)]; char f0[551];}; #endif #ifdef __cplusplus diff --git a/src/mesh/generated/config.pb.h b/src/mesh/generated/config.pb.h index cb7923d14..a8e78161d 100644 --- a/src/mesh/generated/config.pb.h +++ b/src/mesh/generated/config.pb.h @@ -4,6 +4,7 @@ #ifndef PB_CONFIG_PB_H_INCLUDED #define PB_CONFIG_PB_H_INCLUDED #include +#include "telemetry.pb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. @@ -50,14 +51,28 @@ typedef struct _Config_ModuleConfig_StoreForwardConfig { char dummy_field; } Config_ModuleConfig_StoreForwardConfig; -typedef struct _Config_ModuleConfig_TelemetryConfig { - char dummy_field; -} Config_ModuleConfig_TelemetryConfig; - typedef struct _Config_PowerConfig { char dummy_field; } Config_PowerConfig; +typedef struct _Config_ModuleConfig_TelemetryConfig { + uint32_t device_update_interval; + uint32_t environment_update_interval; + bool environment_measurement_enabled; + bool environment_screen_enabled; + uint32_t environment_read_error_count_threshold; + uint32_t environment_recovery_interval; + bool environment_display_fahrenheit; + TelemetrySensorType environment_sensor_type; + uint32_t environment_sensor_pin; +} Config_ModuleConfig_TelemetryConfig; + +typedef struct _Config_WiFiConfig { + pb_callback_t wifi_ssid; + pb_callback_t wifi_password; + bool wifi_ap_mode; +} Config_WiFiConfig; + typedef struct _Config_ModuleConfig { pb_size_t which_payloadVariant; union { @@ -71,12 +86,6 @@ typedef struct _Config_ModuleConfig { } payloadVariant; } Config_ModuleConfig; -typedef struct _Config_WiFiConfig { - pb_callback_t wifi_ssid; - pb_callback_t wifi_password; - bool wifi_ap_mode; -} Config_WiFiConfig; - typedef struct _Config { /* TODO: REPLACE */ pb_size_t which_payloadVariant; @@ -110,7 +119,7 @@ extern "C" { #define Config_ModuleConfig_ExternalNotificationConfig_init_default {0} #define Config_ModuleConfig_StoreForwardConfig_init_default {0} #define Config_ModuleConfig_RangeTestConfig_init_default {0} -#define Config_ModuleConfig_TelemetryConfig_init_default {0} +#define Config_ModuleConfig_TelemetryConfig_init_default {0, 0, 0, 0, 0, 0, 0, _TelemetrySensorType_MIN, 0} #define Config_ModuleConfig_CannedMessageConfig_init_default {0} #define Config_init_zero {0, {Config_DeviceConfig_init_zero}} #define Config_DeviceConfig_init_zero {0} @@ -125,10 +134,22 @@ extern "C" { #define Config_ModuleConfig_ExternalNotificationConfig_init_zero {0} #define Config_ModuleConfig_StoreForwardConfig_init_zero {0} #define Config_ModuleConfig_RangeTestConfig_init_zero {0} -#define Config_ModuleConfig_TelemetryConfig_init_zero {0} +#define Config_ModuleConfig_TelemetryConfig_init_zero {0, 0, 0, 0, 0, 0, 0, _TelemetrySensorType_MIN, 0} #define Config_ModuleConfig_CannedMessageConfig_init_zero {0} /* Field tags (for use in manual encoding/decoding) */ +#define Config_ModuleConfig_TelemetryConfig_device_update_interval_tag 1 +#define Config_ModuleConfig_TelemetryConfig_environment_update_interval_tag 2 +#define Config_ModuleConfig_TelemetryConfig_environment_measurement_enabled_tag 3 +#define Config_ModuleConfig_TelemetryConfig_environment_screen_enabled_tag 4 +#define Config_ModuleConfig_TelemetryConfig_environment_read_error_count_threshold_tag 5 +#define Config_ModuleConfig_TelemetryConfig_environment_recovery_interval_tag 6 +#define Config_ModuleConfig_TelemetryConfig_environment_display_fahrenheit_tag 7 +#define Config_ModuleConfig_TelemetryConfig_environment_sensor_type_tag 8 +#define Config_ModuleConfig_TelemetryConfig_environment_sensor_pin_tag 9 +#define Config_WiFiConfig_wifi_ssid_tag 1 +#define Config_WiFiConfig_wifi_password_tag 2 +#define Config_WiFiConfig_wifi_ap_mode_tag 3 #define Config_ModuleConfig_mqtt_config_tag 1 #define Config_ModuleConfig_serial_config_tag 2 #define Config_ModuleConfig_external_notification_config_tag 3 @@ -136,9 +157,6 @@ extern "C" { #define Config_ModuleConfig_range_test_config_tag 5 #define Config_ModuleConfig_telemetry_config_tag 6 #define Config_ModuleConfig_canned_message_config_tag 7 -#define Config_WiFiConfig_wifi_ssid_tag 1 -#define Config_WiFiConfig_wifi_password_tag 2 -#define Config_WiFiConfig_wifi_ap_mode_tag 3 #define Config_device_config_tag 1 #define Config_gps_config_tag 2 #define Config_power_config_tag 3 @@ -242,7 +260,15 @@ X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,canned_message_config,payload #define Config_ModuleConfig_RangeTestConfig_DEFAULT NULL #define Config_ModuleConfig_TelemetryConfig_FIELDLIST(X, a) \ - +X(a, STATIC, SINGULAR, UINT32, device_update_interval, 1) \ +X(a, STATIC, SINGULAR, UINT32, environment_update_interval, 2) \ +X(a, STATIC, SINGULAR, BOOL, environment_measurement_enabled, 3) \ +X(a, STATIC, SINGULAR, BOOL, environment_screen_enabled, 4) \ +X(a, STATIC, SINGULAR, UINT32, environment_read_error_count_threshold, 5) \ +X(a, STATIC, SINGULAR, UINT32, environment_recovery_interval, 6) \ +X(a, STATIC, SINGULAR, BOOL, environment_display_fahrenheit, 7) \ +X(a, STATIC, SINGULAR, UENUM, environment_sensor_type, 8) \ +X(a, STATIC, SINGULAR, UINT32, environment_sensor_pin, 9) #define Config_ModuleConfig_TelemetryConfig_CALLBACK NULL #define Config_ModuleConfig_TelemetryConfig_DEFAULT NULL @@ -297,8 +323,8 @@ extern const pb_msgdesc_t Config_ModuleConfig_CannedMessageConfig_msg; #define Config_ModuleConfig_RangeTestConfig_size 0 #define Config_ModuleConfig_SerialConfig_size 0 #define Config_ModuleConfig_StoreForwardConfig_size 0 -#define Config_ModuleConfig_TelemetryConfig_size 0 -#define Config_ModuleConfig_size 2 +#define Config_ModuleConfig_TelemetryConfig_size 38 +#define Config_ModuleConfig_size 40 #define Config_PowerConfig_size 0 #ifdef __cplusplus diff --git a/src/mesh/generated/radioconfig.pb.c b/src/mesh/generated/radioconfig.pb.c index 47b4f3903..a5de74964 100644 --- a/src/mesh/generated/radioconfig.pb.c +++ b/src/mesh/generated/radioconfig.pb.c @@ -21,4 +21,3 @@ PB_BIND(RadioConfig_UserPreferences, RadioConfig_UserPreferences, 2) - diff --git a/src/mesh/generated/radioconfig.pb.h b/src/mesh/generated/radioconfig.pb.h index b6a50bb90..343c32450 100644 --- a/src/mesh/generated/radioconfig.pb.h +++ b/src/mesh/generated/radioconfig.pb.h @@ -237,31 +237,6 @@ typedef enum _RadioConfig_UserPreferences_Serial_Mode { RadioConfig_UserPreferences_Serial_Mode_MODE_PROTO = 2 } RadioConfig_UserPreferences_Serial_Mode; -/* Sets the charge control current of devices with a battery charger that can be - configured. This is passed into the axp power management chip like on the tbeam. */ -typedef enum _RadioConfig_UserPreferences_TelemetrySensorType { - /* TODO: REPLACE */ - RadioConfig_UserPreferences_TelemetrySensorType_None = 0, - /* TODO: REPLACE */ - RadioConfig_UserPreferences_TelemetrySensorType_DHT11 = 1, - /* TODO: REPLACE */ - RadioConfig_UserPreferences_TelemetrySensorType_DS18B20 = 2, - /* TODO: REPLACE */ - RadioConfig_UserPreferences_TelemetrySensorType_DHT12 = 3, - /* TODO: REPLACE */ - RadioConfig_UserPreferences_TelemetrySensorType_DHT21 = 4, - /* TODO: REPLACE */ - RadioConfig_UserPreferences_TelemetrySensorType_DHT22 = 5, - /* TODO: REPLACE */ - RadioConfig_UserPreferences_TelemetrySensorType_BME280 = 6, - /* TODO: REPLACE */ - RadioConfig_UserPreferences_TelemetrySensorType_BME680 = 7, - /* TODO: REPLACE */ - RadioConfig_UserPreferences_TelemetrySensorType_MCP9808 = 8, - /* TODO: REPLACE */ - RadioConfig_UserPreferences_TelemetrySensorType_SHTC3 = 9 -} RadioConfig_UserPreferences_TelemetrySensorType; - /* Struct definitions */ typedef struct _RadioConfig_UserPreferences { uint32_t position_broadcast_secs; @@ -314,14 +289,6 @@ typedef struct _RadioConfig_UserPreferences { uint32_t store_forward_module_records; uint32_t store_forward_module_history_return_max; uint32_t store_forward_module_history_return_window; - bool telemetry_module_environment_measurement_enabled; - bool telemetry_module_environment_screen_enabled; - uint32_t telemetry_module_environment_read_error_count_threshold; - uint32_t telemetry_module_device_update_interval; - uint32_t telemetry_module_environment_recovery_interval; - bool telemetry_module_environment_display_fahrenheit; - RadioConfig_UserPreferences_TelemetrySensorType telemetry_module_environment_sensor_type; - uint32_t telemetry_module_environment_sensor_pin; bool store_forward_module_enabled; bool store_forward_module_heartbeat; uint32_t position_flags; @@ -347,7 +314,6 @@ typedef struct _RadioConfig_UserPreferences { bool mqtt_encryption_enabled; float adc_multiplier_override; RadioConfig_UserPreferences_Serial_Baud serial_module_baud; - uint32_t telemetry_module_environment_update_interval; } RadioConfig_UserPreferences; /* The entire set of user settable/readable settings for our radio device. @@ -393,10 +359,6 @@ typedef struct _RadioConfig { #define _RadioConfig_UserPreferences_Serial_Mode_MAX RadioConfig_UserPreferences_Serial_Mode_MODE_PROTO #define _RadioConfig_UserPreferences_Serial_Mode_ARRAYSIZE ((RadioConfig_UserPreferences_Serial_Mode)(RadioConfig_UserPreferences_Serial_Mode_MODE_PROTO+1)) -#define _RadioConfig_UserPreferences_TelemetrySensorType_MIN RadioConfig_UserPreferences_TelemetrySensorType_None -#define _RadioConfig_UserPreferences_TelemetrySensorType_MAX RadioConfig_UserPreferences_TelemetrySensorType_SHTC3 -#define _RadioConfig_UserPreferences_TelemetrySensorType_ARRAYSIZE ((RadioConfig_UserPreferences_TelemetrySensorType)(RadioConfig_UserPreferences_TelemetrySensorType_SHTC3+1)) - #ifdef __cplusplus extern "C" { @@ -404,9 +366,9 @@ extern "C" { /* Initializer values for message structs */ #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default} -#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _Role_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_Serial_Mode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_TelemetrySensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, 0, "", 0, 0, 0, _RadioConfig_UserPreferences_Serial_Baud_MIN, 0} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _Role_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_Serial_Mode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, 0, "", 0, 0, 0, _RadioConfig_UserPreferences_Serial_Baud_MIN} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero} -#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _Role_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_Serial_Mode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_TelemetrySensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, 0, "", 0, 0, 0, _RadioConfig_UserPreferences_Serial_Baud_MIN, 0} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _Role_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_Serial_Mode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, 0, "", 0, 0, 0, _RadioConfig_UserPreferences_Serial_Baud_MIN} /* Field tags (for use in manual encoding/decoding) */ #define RadioConfig_UserPreferences_position_broadcast_secs_tag 1 @@ -458,14 +420,6 @@ extern "C" { #define RadioConfig_UserPreferences_store_forward_module_records_tag 137 #define RadioConfig_UserPreferences_store_forward_module_history_return_max_tag 138 #define RadioConfig_UserPreferences_store_forward_module_history_return_window_tag 139 -#define RadioConfig_UserPreferences_telemetry_module_environment_measurement_enabled_tag 140 -#define RadioConfig_UserPreferences_telemetry_module_environment_screen_enabled_tag 141 -#define RadioConfig_UserPreferences_telemetry_module_environment_read_error_count_threshold_tag 142 -#define RadioConfig_UserPreferences_telemetry_module_device_update_interval_tag 143 -#define RadioConfig_UserPreferences_telemetry_module_environment_recovery_interval_tag 144 -#define RadioConfig_UserPreferences_telemetry_module_environment_display_fahrenheit_tag 145 -#define RadioConfig_UserPreferences_telemetry_module_environment_sensor_type_tag 146 -#define RadioConfig_UserPreferences_telemetry_module_environment_sensor_pin_tag 147 #define RadioConfig_UserPreferences_store_forward_module_enabled_tag 148 #define RadioConfig_UserPreferences_store_forward_module_heartbeat_tag 149 #define RadioConfig_UserPreferences_position_flags_tag 150 @@ -491,7 +445,6 @@ extern "C" { #define RadioConfig_UserPreferences_mqtt_encryption_enabled_tag 174 #define RadioConfig_UserPreferences_adc_multiplier_override_tag 175 #define RadioConfig_UserPreferences_serial_module_baud_tag 176 -#define RadioConfig_UserPreferences_telemetry_module_environment_update_interval_tag 177 #define RadioConfig_preferences_tag 1 /* Struct field encoding specification for nanopb */ @@ -551,14 +504,6 @@ X(a, STATIC, SINGULAR, BOOL, range_test_module_save, 134) \ X(a, STATIC, SINGULAR, UINT32, store_forward_module_records, 137) \ X(a, STATIC, SINGULAR, UINT32, store_forward_module_history_return_max, 138) \ X(a, STATIC, SINGULAR, UINT32, store_forward_module_history_return_window, 139) \ -X(a, STATIC, SINGULAR, BOOL, telemetry_module_environment_measurement_enabled, 140) \ -X(a, STATIC, SINGULAR, BOOL, telemetry_module_environment_screen_enabled, 141) \ -X(a, STATIC, SINGULAR, UINT32, telemetry_module_environment_read_error_count_threshold, 142) \ -X(a, STATIC, SINGULAR, UINT32, telemetry_module_device_update_interval, 143) \ -X(a, STATIC, SINGULAR, UINT32, telemetry_module_environment_recovery_interval, 144) \ -X(a, STATIC, SINGULAR, BOOL, telemetry_module_environment_display_fahrenheit, 145) \ -X(a, STATIC, SINGULAR, UENUM, telemetry_module_environment_sensor_type, 146) \ -X(a, STATIC, SINGULAR, UINT32, telemetry_module_environment_sensor_pin, 147) \ X(a, STATIC, SINGULAR, BOOL, store_forward_module_enabled, 148) \ X(a, STATIC, SINGULAR, BOOL, store_forward_module_heartbeat, 149) \ X(a, STATIC, SINGULAR, UINT32, position_flags, 150) \ @@ -583,8 +528,7 @@ X(a, STATIC, SINGULAR, STRING, canned_message_module_allow_input_source, 171 X(a, STATIC, SINGULAR, BOOL, canned_message_module_send_bell, 173) \ X(a, STATIC, SINGULAR, BOOL, mqtt_encryption_enabled, 174) \ X(a, STATIC, SINGULAR, FLOAT, adc_multiplier_override, 175) \ -X(a, STATIC, SINGULAR, UENUM, serial_module_baud, 176) \ -X(a, STATIC, SINGULAR, UINT32, telemetry_module_environment_update_interval, 177) +X(a, STATIC, SINGULAR, UENUM, serial_module_baud, 176) #define RadioConfig_UserPreferences_CALLBACK NULL #define RadioConfig_UserPreferences_DEFAULT NULL @@ -596,8 +540,8 @@ extern const pb_msgdesc_t RadioConfig_UserPreferences_msg; #define RadioConfig_UserPreferences_fields &RadioConfig_UserPreferences_msg /* Maximum encoded size of messages (where known) */ -#define RadioConfig_UserPreferences_size 592 -#define RadioConfig_size 595 +#define RadioConfig_UserPreferences_size 545 +#define RadioConfig_size 548 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/telemetry.pb.c b/src/mesh/generated/telemetry.pb.c index 674a2f84d..a2d812cad 100644 --- a/src/mesh/generated/telemetry.pb.c +++ b/src/mesh/generated/telemetry.pb.c @@ -16,3 +16,4 @@ PB_BIND(Telemetry, Telemetry, AUTO) + diff --git a/src/mesh/generated/telemetry.pb.h b/src/mesh/generated/telemetry.pb.h index b3bf3df1d..6c9db655c 100644 --- a/src/mesh/generated/telemetry.pb.h +++ b/src/mesh/generated/telemetry.pb.h @@ -9,6 +9,31 @@ #error Regenerate this file with the current version of nanopb generator. #endif +/* Enum definitions */ +/* TODO: REPLACE */ +typedef enum _TelemetrySensorType { + /* No external telemetry sensor */ + TelemetrySensorType_NotSet = 0, + /* TODO: REPLACE */ + TelemetrySensorType_DHT11 = 1, + /* TODO: REPLACE */ + TelemetrySensorType_DS18B20 = 2, + /* TODO: REPLACE */ + TelemetrySensorType_DHT12 = 3, + /* TODO: REPLACE */ + TelemetrySensorType_DHT21 = 4, + /* TODO: REPLACE */ + TelemetrySensorType_DHT22 = 5, + /* TODO: REPLACE */ + TelemetrySensorType_BME280 = 6, + /* TODO: REPLACE */ + TelemetrySensorType_BME680 = 7, + /* TODO: REPLACE */ + TelemetrySensorType_MCP9808 = 8, + /* TODO: REPLACE */ + TelemetrySensorType_SHTC3 = 9 +} TelemetrySensorType; + /* Struct definitions */ /* Key native device metrics such as battery level */ typedef struct _DeviceMetrics { @@ -55,6 +80,12 @@ typedef struct _Telemetry { } Telemetry; +/* Helper constants for enums */ +#define _TelemetrySensorType_MIN TelemetrySensorType_NotSet +#define _TelemetrySensorType_MAX TelemetrySensorType_SHTC3 +#define _TelemetrySensorType_ARRAYSIZE ((TelemetrySensorType)(TelemetrySensorType_SHTC3+1)) + + #ifdef __cplusplus extern "C" { #endif diff --git a/src/modules/Telemetry/DeviceTelemetry.cpp b/src/modules/Telemetry/DeviceTelemetry.cpp index 4568521c3..9ba59f5a1 100644 --- a/src/modules/Telemetry/DeviceTelemetry.cpp +++ b/src/modules/Telemetry/DeviceTelemetry.cpp @@ -20,7 +20,8 @@ int32_t DeviceTelemetryModule::runOnce() } sendOurTelemetry(); // OSThread library. Multiply the preference value by 1000 to convert seconds to miliseconds - return (getPref_telemetry_module_device_update_interval() * 1000); + + return getIntervalOrDefaultMs(moduleConfig.device_update_interval); #endif } diff --git a/src/modules/Telemetry/DeviceTelemetry.h b/src/modules/Telemetry/DeviceTelemetry.h index c224a2c1d..07c781645 100644 --- a/src/modules/Telemetry/DeviceTelemetry.h +++ b/src/modules/Telemetry/DeviceTelemetry.h @@ -1,6 +1,7 @@ #pragma once #include "../mesh/generated/telemetry.pb.h" #include "ProtobufModule.h" +#include "NodeDB.h" #include #include @@ -27,6 +28,7 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu bool sendOurTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); private: + Config_ModuleConfig_TelemetryConfig moduleConfig = config.payloadVariant.module_config.payloadVariant.telemetry_config; bool firstTime = 1; const MeshPacket *lastMeasurementPacket; }; diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 0257fe311..2735f5ef1 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -50,17 +50,17 @@ int32_t EnvironmentTelemetryModule::runOnce() without having to configure it from the PythonAPI or WebUI. */ /* - radioConfig.preferences.telemetry_module_environment_measurement_enabled = 1; - radioConfig.preferences.telemetry_module_environment_screen_enabled = 1; - radioConfig.preferences.telemetry_module_environment_read_error_count_threshold = 5; - radioConfig.preferences.telemetry_module_environment_update_interval = 600; - radioConfig.preferences.telemetry_module_environment_recovery_interval = 60; - radioConfig.preferences.telemetry_module_environment_sensor_pin = 13; // If one-wire - radioConfig.preferences.telemetry_module_environment_sensor_type = RadioConfig_UserPreferences_TelemetrySensorType::RadioConfig_UserPreferences_TelemetrySensorType_BME280; + moduleConfig.environment_measurement_enabled = 1; + moduleConfig.environment_screen_enabled = 1; + moduleConfig.environment_read_error_count_threshold = 5; + moduleConfig.environment_update_interval = 600; + moduleConfig.environment_recovery_interval = 60; + moduleConfig.environment_sensor_pin = 13; // If one-wire + moduleConfig.environment_sensor_type = TelemetrySensorType::TelemetrySensorType_BME280; */ - if (!(radioConfig.preferences.telemetry_module_environment_measurement_enabled || - radioConfig.preferences.telemetry_module_environment_screen_enabled)) { + if (!(moduleConfig.environment_measurement_enabled || + moduleConfig.environment_screen_enabled)) { // If this module is not enabled, and the user doesn't want the display screen don't waste any OSThread time on it return (INT32_MAX); } @@ -69,24 +69,24 @@ int32_t EnvironmentTelemetryModule::runOnce() // This is the first time the OSThread library has called this function, so do some setup firstTime = 0; - if (radioConfig.preferences.telemetry_module_environment_measurement_enabled) { + if (moduleConfig.environment_measurement_enabled) { DEBUG_MSG("Environment Telemetry: Initializing\n"); // it's possible to have this module enabled, only for displaying values on the screen. // therefore, we should only enable the sensor loop if measurement is also enabled - switch (radioConfig.preferences.telemetry_module_environment_sensor_type) { + switch (moduleConfig.environment_sensor_type) { - case RadioConfig_UserPreferences_TelemetrySensorType_DHT11: - case RadioConfig_UserPreferences_TelemetrySensorType_DHT12: - case RadioConfig_UserPreferences_TelemetrySensorType_DHT21: - case RadioConfig_UserPreferences_TelemetrySensorType_DHT22: + case TelemetrySensorType_DHT11: + case TelemetrySensorType_DHT12: + case TelemetrySensorType_DHT21: + case TelemetrySensorType_DHT22: return dhtSensor.runOnce(); - case RadioConfig_UserPreferences_TelemetrySensorType_DS18B20: + case TelemetrySensorType_DS18B20: return dallasSensor.runOnce(); - case RadioConfig_UserPreferences_TelemetrySensorType_BME280: + case TelemetrySensorType_BME280: return bme280Sensor.runOnce(); - case RadioConfig_UserPreferences_TelemetrySensorType_BME680: + case TelemetrySensorType_BME680: return bme680Sensor.runOnce(); - case RadioConfig_UserPreferences_TelemetrySensorType_MCP9808: + case TelemetrySensorType_MCP9808: return mcp9808Sensor.runOnce(); default: DEBUG_MSG("Environment Telemetry: Invalid sensor type selected; Disabling module"); @@ -97,55 +97,54 @@ int32_t EnvironmentTelemetryModule::runOnce() return (INT32_MAX); } else { // if we somehow got to a second run of this module with measurement disabled, then just wait forever - if (!radioConfig.preferences.telemetry_module_environment_measurement_enabled) + if (!moduleConfig.environment_measurement_enabled) return (INT32_MAX); // this is not the first time OSThread library has called this function // so just do what we intend to do on the interval - if (sensor_read_error_count > radioConfig.preferences.telemetry_module_environment_read_error_count_threshold) { - if (radioConfig.preferences.telemetry_module_environment_recovery_interval > 0) { + if (sensor_read_error_count > moduleConfig.environment_read_error_count_threshold) { + if (moduleConfig.environment_recovery_interval > 0) { DEBUG_MSG("Environment Telemetry: TEMPORARILY DISABLED; The " "telemetry_module_environment_read_error_count_threshold has been exceed: %d. Will retry reads in " "%d seconds\n", - radioConfig.preferences.telemetry_module_environment_read_error_count_threshold, - radioConfig.preferences.telemetry_module_environment_recovery_interval); + moduleConfig.environment_read_error_count_threshold, + moduleConfig.environment_recovery_interval); sensor_read_error_count = 0; - return (radioConfig.preferences.telemetry_module_environment_recovery_interval * 1000); + return (moduleConfig.environment_recovery_interval * 1000); } DEBUG_MSG("Environment Telemetry: DISABLED; The telemetry_module_environment_read_error_count_threshold has " "been exceed: %d. Reads will not be retried until after device reset\n", - radioConfig.preferences.telemetry_module_environment_read_error_count_threshold); + moduleConfig.environment_read_error_count_threshold); return (INT32_MAX); } else if (sensor_read_error_count > 0) { DEBUG_MSG("Environment Telemetry: There have been %d sensor read failures. Will retry %d more times\n", sensor_read_error_count, sensor_read_error_count, sensor_read_error_count, - radioConfig.preferences.telemetry_module_environment_read_error_count_threshold - + moduleConfig.environment_read_error_count_threshold - sensor_read_error_count); } if (!sendOurTelemetry()) { // if we failed to read the sensor, then try again // as soon as we can according to the maximum polling frequency - switch (radioConfig.preferences.telemetry_module_environment_sensor_type) { - case RadioConfig_UserPreferences_TelemetrySensorType_DHT11: - case RadioConfig_UserPreferences_TelemetrySensorType_DHT12: - case RadioConfig_UserPreferences_TelemetrySensorType_DHT21: - case RadioConfig_UserPreferences_TelemetrySensorType_DHT22: + switch (moduleConfig.environment_sensor_type) { + case TelemetrySensorType_DHT11: + case TelemetrySensorType_DHT12: + case TelemetrySensorType_DHT21: + case TelemetrySensorType_DHT22: return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); - case RadioConfig_UserPreferences_TelemetrySensorType_DS18B20: + case TelemetrySensorType_DS18B20: return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); - case RadioConfig_UserPreferences_TelemetrySensorType_BME280: - case RadioConfig_UserPreferences_TelemetrySensorType_BME680: + case TelemetrySensorType_BME280: + case TelemetrySensorType_BME680: return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); - case RadioConfig_UserPreferences_TelemetrySensorType_MCP9808: + case TelemetrySensorType_MCP9808: return (MCP_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); default: return (DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); } } } - // OSThread library. Multiply the preference value by 1000 to convert seconds to miliseconds - return (getPref_telemetry_module_environment_update_interval() * 1000); + return getIntervalOrDefaultMs(moduleConfig.environment_update_interval); #endif } @@ -163,7 +162,7 @@ uint32_t GetTimeSinceMeshPacket(const MeshPacket *mp) bool EnvironmentTelemetryModule::wantUIFrame() { - return radioConfig.preferences.telemetry_module_environment_screen_enabled; + return moduleConfig.environment_screen_enabled; } float EnvironmentTelemetryModule::CelsiusToFahrenheit(float c) @@ -197,7 +196,7 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt display->setFont(FONT_SMALL); String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C"; - if (radioConfig.preferences.telemetry_module_environment_display_fahrenheit) { + if (moduleConfig.environment_display_fahrenheit) { last_temp = String(CelsiusToFahrenheit(lastMeasurement.variant.environment_metrics.temperature), 0) + "°F"; } display->drawString(x, y += fontHeight(FONT_MEDIUM) - 2, "From: " + String(lastSender) + "(" + String(agoSecs) + "s)"); @@ -243,25 +242,25 @@ bool EnvironmentTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies DEBUG_MSG("-----------------------------------------\n"); DEBUG_MSG("Environment Telemetry: Read data\n"); - switch (radioConfig.preferences.telemetry_module_environment_sensor_type) { - case RadioConfig_UserPreferences_TelemetrySensorType_DS18B20: + switch (moduleConfig.environment_sensor_type) { + case TelemetrySensorType_DS18B20: if (!dallasSensor.getMeasurement(&m)) sensor_read_error_count++; break; - case RadioConfig_UserPreferences_TelemetrySensorType_DHT11: - case RadioConfig_UserPreferences_TelemetrySensorType_DHT12: - case RadioConfig_UserPreferences_TelemetrySensorType_DHT21: - case RadioConfig_UserPreferences_TelemetrySensorType_DHT22: + case TelemetrySensorType_DHT11: + case TelemetrySensorType_DHT12: + case TelemetrySensorType_DHT21: + case TelemetrySensorType_DHT22: if (!dhtSensor.getMeasurement(&m)) sensor_read_error_count++; break; - case RadioConfig_UserPreferences_TelemetrySensorType_BME280: + case TelemetrySensorType_BME280: bme280Sensor.getMeasurement(&m); break; - case RadioConfig_UserPreferences_TelemetrySensorType_BME680: + case TelemetrySensorType_BME680: bme680Sensor.getMeasurement(&m); break; - case RadioConfig_UserPreferences_TelemetrySensorType_MCP9808: + case TelemetrySensorType_MCP9808: mcp9808Sensor.getMeasurement(&m); break; default: diff --git a/src/modules/Telemetry/EnvironmentTelemetry.h b/src/modules/Telemetry/EnvironmentTelemetry.h index c1cdc9994..48360312f 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.h +++ b/src/modules/Telemetry/EnvironmentTelemetry.h @@ -1,6 +1,7 @@ #pragma once #include "../mesh/generated/telemetry.pb.h" #include "ProtobufModule.h" +#include "NodeDB.h" #include #include @@ -28,6 +29,7 @@ class EnvironmentTelemetryModule : private concurrency::OSThread, public Protobu bool sendOurTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); private: + Config_ModuleConfig_TelemetryConfig moduleConfig = config.payloadVariant.module_config.payloadVariant.telemetry_config; float CelsiusToFahrenheit(float c); bool firstTime = 1; const MeshPacket *lastMeasurementPacket; diff --git a/src/modules/Telemetry/Sensor/DHTSensor.cpp b/src/modules/Telemetry/Sensor/DHTSensor.cpp index 063adced5..6711c4ce6 100644 --- a/src/modules/Telemetry/Sensor/DHTSensor.cpp +++ b/src/modules/Telemetry/Sensor/DHTSensor.cpp @@ -9,18 +9,18 @@ DHTSensor::DHTSensor() : TelemetrySensor {} { } int32_t DHTSensor::runOnce() { - if (RadioConfig_UserPreferences_TelemetrySensorType_DHT11 || - RadioConfig_UserPreferences_TelemetrySensorType_DHT12) { - dht = new DHT(radioConfig.preferences.telemetry_module_environment_sensor_pin, DHT11); + if (TelemetrySensorType_DHT11 || + TelemetrySensorType_DHT12) { + dht = new DHT(moduleConfig.environment_sensor_pin, DHT11); } else { - dht = new DHT(radioConfig.preferences.telemetry_module_environment_sensor_pin, DHT22); + dht = new DHT(moduleConfig.environment_sensor_pin, DHT22); } dht->begin(); dht->read(); DEBUG_MSG("Telemetry: Opened DHT11/DHT12 on pin: %d\n", - radioConfig.preferences.telemetry_module_environment_sensor_pin); + moduleConfig.environment_sensor_pin); return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); } diff --git a/src/modules/Telemetry/Sensor/DallasSensor.cpp b/src/modules/Telemetry/Sensor/DallasSensor.cpp index 1be369d79..f549a0af3 100644 --- a/src/modules/Telemetry/Sensor/DallasSensor.cpp +++ b/src/modules/Telemetry/Sensor/DallasSensor.cpp @@ -10,13 +10,13 @@ DallasSensor::DallasSensor() : TelemetrySensor {} { } int32_t DallasSensor::runOnce() { - oneWire = new OneWire(radioConfig.preferences.telemetry_module_environment_sensor_pin); + oneWire = new OneWire(moduleConfig.environment_sensor_pin); ds18b20 = new DS18B20(oneWire); ds18b20->begin(); ds18b20->setResolution(12); ds18b20->requestTemperatures(); DEBUG_MSG("Telemetry: Opened DS18B20 on pin: %d\n", - radioConfig.preferences.telemetry_module_environment_sensor_pin); + moduleConfig.environment_sensor_pin); return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); } diff --git a/src/modules/Telemetry/Sensor/TelemetrySensor.h b/src/modules/Telemetry/Sensor/TelemetrySensor.h index 327ef8aaa..746a05621 100644 --- a/src/modules/Telemetry/Sensor/TelemetrySensor.h +++ b/src/modules/Telemetry/Sensor/TelemetrySensor.h @@ -1,11 +1,12 @@ #pragma once #include "../mesh/generated/telemetry.pb.h" +#include "NodeDB.h" #define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000 class TelemetrySensor { protected: TelemetrySensor() { } - + Config_ModuleConfig_TelemetryConfig moduleConfig = config.payloadVariant.module_config.payloadVariant.telemetry_config; public: virtual int32_t runOnce() = 0; virtual bool getMeasurement(Telemetry *measurement) = 0; From 2ca029066204e626b2af5da4cffc37f1e0926b53 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 1 May 2022 15:35:01 -0500 Subject: [PATCH 26/31] Admin message implementation --- proto | 2 +- src/mesh/generated/admin.pb.h | 2 +- src/modules/AdminModule.cpp | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/proto b/proto index d02d7131a..a3c790850 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit d02d7131a20210a18f12a87a327753e1e34b4282 +Subproject commit a3c790850d536eb11d898bd40fd7d58977703fac diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index b6703c302..c4c2a716f 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -29,7 +29,7 @@ typedef enum _AdminMessage_ConfigType { AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG = 11, AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG = 12, AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG = 13, - AdminMessage_ConfigType_MODULE_ENVIRONMENTAL_CONFIG = 14, + AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG = 14, AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG = 15 } AdminMessage_ConfigType; diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 8b018092f..9d5e161c8 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -124,9 +124,12 @@ void AdminModule::handleGetConfig(const MeshPacket &req) DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG\n"); r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG; break; - case AdminMessage_ConfigType_MODULE_ENVIRONMENTAL_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_ENVIRONMENTAL_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_ENVIRONMENTAL_CONFIG; + case AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG: + DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG; + r.get_config_response.payloadVariant.module_config.which_payloadVariant = Config_ModuleConfig_telemetry_config_tag; + r.get_config_response.payloadVariant.module_config.payloadVariant.telemetry_config = + config.payloadVariant.module_config.payloadVariant.telemetry_config; break; case AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG: DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG\n"); From 1040b0988ae252e3b2f707e8a9634969fa37ecd5 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 1 May 2022 15:37:34 -0500 Subject: [PATCH 27/31] Removed unused members causing warnings --- src/esp32/ESP32Bluetooth.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/esp32/ESP32Bluetooth.cpp b/src/esp32/ESP32Bluetooth.cpp index 1816e7f6d..5ed46f119 100644 --- a/src/esp32/ESP32Bluetooth.cpp +++ b/src/esp32/ESP32Bluetooth.cpp @@ -23,9 +23,6 @@ // proccess at once // static uint8_t trBytes[_max(_max(_max(_max(ToRadio_size, RadioConfig_size), User_size), MyNodeInfo_size), FromRadio_size)]; static uint8_t fromRadioBytes[FromRadio_size]; -static uint8_t toRadioBytes[ToRadio_size]; - -static bool bleConnected; NimBLECharacteristic *FromNumCharacteristic; NimBLEServer *bleServer; From 3a1f20821edb8b9208e493a81febdb7094fdae19 Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Mon, 2 May 2022 08:35:31 +1000 Subject: [PATCH 28/31] Remove team and provision set_config --- proto | 2 +- src/mesh/generated/admin.pb.h | 8 ++- src/mesh/generated/deviceonly.pb.h | 2 +- src/mesh/generated/mesh.pb.h | 79 ++++++------------------------ src/modules/AdminModule.cpp | 5 -- 5 files changed, 24 insertions(+), 72 deletions(-) diff --git a/proto b/proto index a3c790850..8778b4190 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit a3c790850d536eb11d898bd40fd7d58977703fac +Subproject commit 8778b41906c4b1d0bd6053823f41cd4135160a8f diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index c4c2a716f..9491eb9e1 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -52,6 +52,7 @@ typedef struct _AdminMessage { User get_owner_response; AdminMessage_ConfigType get_config_request; Config get_config_response; + Config set_config; bool confirm_set_channel; bool confirm_set_radio; bool exit_simulator; @@ -99,6 +100,7 @@ extern "C" { #define AdminMessage_get_owner_response_tag 9 #define AdminMessage_get_config_request_tag 10 #define AdminMessage_get_config_response_tag 11 +#define AdminMessage_set_config_tag 12 #define AdminMessage_confirm_set_channel_tag 32 #define AdminMessage_confirm_set_radio_tag 33 #define AdminMessage_exit_simulator_tag 34 @@ -130,6 +132,7 @@ X(a, STATIC, ONEOF, BOOL, (variant,get_owner_request,get_owner_request) X(a, STATIC, ONEOF, MESSAGE, (variant,get_owner_response,get_owner_response), 9) \ X(a, STATIC, ONEOF, UENUM, (variant,get_config_request,get_config_request), 10) \ X(a, STATIC, ONEOF, MESSAGE, (variant,get_config_response,get_config_response), 11) \ +X(a, STATIC, ONEOF, MESSAGE, (variant,set_config,set_config), 12) \ X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_channel,confirm_set_channel), 32) \ X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_radio,confirm_set_radio), 33) \ X(a, STATIC, ONEOF, BOOL, (variant,exit_simulator,exit_simulator), 34) \ @@ -156,6 +159,7 @@ X(a, STATIC, ONEOF, INT32, (variant,shutdown_seconds,shutdown_seconds), #define AdminMessage_variant_get_channel_response_MSGTYPE Channel #define AdminMessage_variant_get_owner_response_MSGTYPE User #define AdminMessage_variant_get_config_response_MSGTYPE Config +#define AdminMessage_variant_set_config_MSGTYPE Config extern const pb_msgdesc_t AdminMessage_msg; @@ -163,9 +167,9 @@ extern const pb_msgdesc_t AdminMessage_msg; #define AdminMessage_fields &AdminMessage_msg /* Maximum encoded size of messages (where known) */ -#if defined(Config_size) +#if defined(Config_size) && defined(Config_size) #define AdminMessage_size (0 + sizeof(union AdminMessage_variant_size_union)) -union AdminMessage_variant_size_union {char f11[(6 + Config_size)]; char f0[551];}; +union AdminMessage_variant_size_union {char f0[551]; char f11[(6 + Config_size)]; char f12[(6 + Config_size)];}; #endif #ifdef __cplusplus diff --git a/src/mesh/generated/deviceonly.pb.h b/src/mesh/generated/deviceonly.pb.h index a8df04eae..d2d400f9f 100644 --- a/src/mesh/generated/deviceonly.pb.h +++ b/src/mesh/generated/deviceonly.pb.h @@ -159,7 +159,7 @@ extern const pb_msgdesc_t OEMStore_msg; /* Maximum encoded size of messages (where known) */ #define ChannelFile_size 832 -#define DeviceState_size 19327 +#define DeviceState_size 19197 #define OEMStore_size 2106 #ifdef __cplusplus diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index 8ce6fc803..e76eb83f7 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -69,41 +69,6 @@ typedef enum _HardwareModel { HardwareModel_PRIVATE_HW = 255 } HardwareModel; -/* The team colors are based on the names of "friendly teams" in ATAK: - https://github.com/deptofdefense/AndroidTacticalAssaultKit-CIV/blob/master/atak/ATAK/app/src/main/assets/filters/team_filters.xml */ -typedef enum _Team { - /* the default (unset) is "achromatic" (unaffiliated) */ - Team_CLEAR = 0, - /* TODO: REPLACE */ - Team_CYAN = 1, - /* TODO: REPLACE */ - Team_WHITE = 2, - /* TODO: REPLACE */ - Team_YELLOW = 3, - /* TODO: REPLACE */ - Team_ORANGE = 4, - /* TODO: REPLACE */ - Team_MAGENTA = 5, - /* TODO: REPLACE */ - Team_RED = 6, - /* TODO: REPLACE */ - Team_MAROON = 7, - /* TODO: REPLACE */ - Team_PURPLE = 8, - /* TODO: REPLACE */ - Team_DARK_BLUE = 9, - /* TODO: REPLACE */ - Team_BLUE = 10, - /* TODO: REPLACE */ - Team_TEAL = 11, - /* TODO: REPLACE */ - Team_GREEN = 12, - /* TODO: REPLACE */ - Team_DARK_GREEN = 13, - /* TODO: REPLACE */ - Team_BROWN = 14 -} Team; - /* Shared constants between device and phone */ typedef enum _Constants { /* First enum must be zero, and we are just using this enum to @@ -164,18 +129,17 @@ typedef enum _Position_LocSource { Position_LocSource_LOCSRC_GPS_EXTERNAL = 3 } Position_LocSource; -/* The team colors are based on the names of "friendly teams" in ATAK: - https://github.com/deptofdefense/AndroidTacticalAssaultKit-CIV/blob/master/atak/ATAK/app/src/main/assets/filters/team_filters.xml */ +/* Shared constants between device and phone */ typedef enum _Position_AltSource { - /* the default (unset) is "achromatic" (unaffiliated) */ + /* First enum must be zero, and we are just using this enum to + pass int constants between two very different environments */ Position_AltSource_ALTSRC_UNSPECIFIED = 0, - /* TODO: REPLACE */ + /* From mesh.options + note: this payload length is ONLY the bytes that are sent inside of the Data protobuf (excluding protobuf overhead). The 16 byte header is + outside of this envelope */ Position_AltSource_ALTSRC_MANUAL_ENTRY = 1, - /* TODO: REPLACE */ Position_AltSource_ALTSRC_GPS_INTERNAL = 2, - /* TODO: REPLACE */ Position_AltSource_ALTSRC_GPS_EXTERNAL = 3, - /* TODO: REPLACE */ Position_AltSource_ALTSRC_BAROMETRIC = 4 } Position_AltSource; @@ -232,14 +196,15 @@ typedef enum _MeshPacket_Priority { MeshPacket_Priority_MAX = 127 } MeshPacket_Priority; -/* The team colors are based on the names of "friendly teams" in ATAK: - https://github.com/deptofdefense/AndroidTacticalAssaultKit-CIV/blob/master/atak/ATAK/app/src/main/assets/filters/team_filters.xml */ +/* Shared constants between device and phone */ typedef enum _MeshPacket_Delayed { - /* the default (unset) is "achromatic" (unaffiliated) */ + /* First enum must be zero, and we are just using this enum to + pass int constants between two very different environments */ MeshPacket_Delayed_NO_DELAY = 0, - /* TODO: REPLACE */ + /* From mesh.options + note: this payload length is ONLY the bytes that are sent inside of the Data protobuf (excluding protobuf overhead). The 16 byte header is + outside of this envelope */ MeshPacket_Delayed_DELAYED_BROADCAST = 1, - /* TODO: REPLACE */ MeshPacket_Delayed_DELAYED_DIRECT = 2 } MeshPacket_Delayed; @@ -480,12 +445,6 @@ typedef struct _User { If this user is a licensed operator, set this flag. Also, "long_name" should be their licence number. */ bool is_licensed; - /* Participants in the same network can self-group into different teams. - Short-term this can be used to visually differentiate them on the map; - in the longer term it could also help users to semi-automatically - select or ignore messages according to team affiliation. - In total, 14 teams are defined (encoded in 4 bits) */ - Team team; /* Transmit power at antenna connector, in decibel-milliwatt An optional self-reported value useful in network planning, discovery and positioning - along with ant_gain_dbi and ant_azimuth below */ @@ -697,10 +656,6 @@ typedef struct _ToRadio { #define _HardwareModel_MAX HardwareModel_PRIVATE_HW #define _HardwareModel_ARRAYSIZE ((HardwareModel)(HardwareModel_PRIVATE_HW+1)) -#define _Team_MIN Team_CLEAR -#define _Team_MAX Team_BROWN -#define _Team_ARRAYSIZE ((Team)(Team_BROWN+1)) - #define _Constants_MIN Constants_Unused #define _Constants_MAX Constants_DATA_PAYLOAD_LEN #define _Constants_ARRAYSIZE ((Constants)(Constants_DATA_PAYLOAD_LEN+1)) @@ -740,7 +695,7 @@ extern "C" { /* Initializer values for message structs */ #define Position_init_default {0, 0, 0, 0, _Position_LocSource_MIN, _Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define User_init_default {"", "", "", {0}, _HardwareModel_MIN, 0, _Team_MIN, 0, 0, 0} +#define User_init_default {"", "", "", {0}, _HardwareModel_MIN, 0, 0, 0, 0} #define RouteDiscovery_init_default {0, {0, 0, 0, 0, 0, 0, 0, 0}} #define Routing_init_default {0, {RouteDiscovery_init_default}} #define Data_init_default {_PortNum_MIN, 0, {{0, {0}}}, 0, 0, 0, 0, 0, 0, false, Location_init_default} @@ -753,7 +708,7 @@ extern "C" { #define ToRadio_init_default {0, {MeshPacket_init_default}} #define ToRadio_PeerInfo_init_default {0, 0} #define Position_init_zero {0, 0, 0, 0, _Position_LocSource_MIN, _Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define User_init_zero {"", "", "", {0}, _HardwareModel_MIN, 0, _Team_MIN, 0, 0, 0} +#define User_init_zero {"", "", "", {0}, _HardwareModel_MIN, 0, 0, 0, 0} #define RouteDiscovery_init_zero {0, {0, 0, 0, 0, 0, 0, 0, 0}} #define Routing_init_zero {0, {RouteDiscovery_init_zero}} #define Data_init_zero {_PortNum_MIN, 0, {{0, {0}}}, 0, 0, 0, 0, 0, 0, false, Location_init_zero} @@ -824,7 +779,6 @@ extern "C" { #define User_macaddr_tag 4 #define User_hw_model_tag 6 #define User_is_licensed_tag 7 -#define User_team_tag 8 #define User_tx_power_dbm_tag 10 #define User_ant_gain_dbi_tag 11 #define User_ant_azimuth_tag 12 @@ -906,7 +860,6 @@ X(a, STATIC, SINGULAR, STRING, short_name, 3) \ X(a, STATIC, SINGULAR, FIXED_LENGTH_BYTES, macaddr, 4) \ X(a, STATIC, SINGULAR, UENUM, hw_model, 6) \ X(a, STATIC, SINGULAR, BOOL, is_licensed, 7) \ -X(a, STATIC, SINGULAR, UENUM, team, 8) \ X(a, STATIC, SINGULAR, UINT32, tx_power_dbm, 10) \ X(a, STATIC, SINGULAR, UINT32, ant_gain_dbi, 11) \ X(a, STATIC, SINGULAR, UINT32, ant_azimuth, 12) @@ -1078,13 +1031,13 @@ extern const pb_msgdesc_t ToRadio_PeerInfo_msg; #define LogRecord_size 81 #define MeshPacket_size 347 #define MyNodeInfo_size 210 -#define NodeInfo_size 283 +#define NodeInfo_size 281 #define Position_size 142 #define RouteDiscovery_size 40 #define Routing_size 42 #define ToRadio_PeerInfo_size 8 #define ToRadio_size 350 -#define User_size 97 +#define User_size 95 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 9d5e161c8..67215e790 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -277,11 +277,6 @@ void AdminModule::handleSetOwner(const User &o) owner.is_licensed = o.is_licensed; } - if ((!changed || o.team) && (owner.team != o.team)) { - changed = 1; - owner.team = o.team; - } - if (changed) // If nothing really changed, don't broadcast on the network or write to flash service.reloadOwner(); } From 8f038ced150d18b13e8e511982b67024139673b3 Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Mon, 2 May 2022 08:53:44 +1000 Subject: [PATCH 29/31] add handleSetConfig, remove team --- proto | 2 +- src/mesh/generated/admin.pb.h | 3 + src/modules/AdminModule.cpp | 238 +++++++++++++++++++++------------- src/modules/AdminModule.h | 1 + 4 files changed, 156 insertions(+), 88 deletions(-) diff --git a/proto b/proto index 8778b4190..cb7bf9ac2 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 8778b41906c4b1d0bd6053823f41cd4135160a8f +Subproject commit cb7bf9ac239b87c6a988feb0bb49c8a3e85dea0e diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index 9491eb9e1..da91fcd99 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -53,6 +53,7 @@ typedef struct _AdminMessage { AdminMessage_ConfigType get_config_request; Config get_config_response; Config set_config; + bool confirm_set_config; bool confirm_set_channel; bool confirm_set_radio; bool exit_simulator; @@ -101,6 +102,7 @@ extern "C" { #define AdminMessage_get_config_request_tag 10 #define AdminMessage_get_config_response_tag 11 #define AdminMessage_set_config_tag 12 +#define AdminMessage_confirm_set_config_tag 13 #define AdminMessage_confirm_set_channel_tag 32 #define AdminMessage_confirm_set_radio_tag 33 #define AdminMessage_exit_simulator_tag 34 @@ -133,6 +135,7 @@ X(a, STATIC, ONEOF, MESSAGE, (variant,get_owner_response,get_owner_respons X(a, STATIC, ONEOF, UENUM, (variant,get_config_request,get_config_request), 10) \ X(a, STATIC, ONEOF, MESSAGE, (variant,get_config_response,get_config_response), 11) \ X(a, STATIC, ONEOF, MESSAGE, (variant,set_config,set_config), 12) \ +X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_config,confirm_set_config), 13) \ X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_channel,confirm_set_channel), 32) \ X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_radio,confirm_set_radio), 33) \ X(a, STATIC, ONEOF, BOOL, (variant,exit_simulator,exit_simulator), 34) \ diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 67215e790..2f3f116d5 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -1,9 +1,9 @@ -#include "configuration.h" #include "AdminModule.h" #include "Channels.h" #include "MeshService.h" #include "NodeDB.h" #include "Router.h" +#include "configuration.h" #include "main.h" #ifdef PORTDUINO @@ -13,19 +13,22 @@ AdminModule *adminModule; /// A special reserved string to indicate strings we can not share with external nodes. We will use this 'reserved' word instead. -/// Also, to make setting work correctly, if someone tries to set a string to this reserved value we assume they don't really want a change. +/// Also, to make setting work correctly, if someone tries to set a string to this reserved value we assume they don't really want +/// a change. static const char *secretReserved = "sekrit"; /// If buf is !empty, change it to secret -static void hideSecret(char *buf) { - if(*buf) { +static void hideSecret(char *buf) +{ + if (*buf) { strcpy(buf, secretReserved); } } /// If buf is the reserved secret word, replace the buffer with currentVal -static void writeSecret(char *buf, const char *currentVal) { - if(strcmp(buf, secretReserved) == 0) { +static void writeSecret(char *buf, const char *currentVal) +{ + if (strcmp(buf, secretReserved) == 0) { strcpy(buf, currentVal); } } @@ -53,7 +56,8 @@ void AdminModule::handleGetRadio(const MeshPacket &req) // using to the app (so that even old phone apps work with new device loads). r.get_radio_response.preferences.ls_secs = getPref_ls_secs(); r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs(); - // hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private and useful for users to know current provisioning) + // hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private + // and useful for users to know current provisioning) hideSecret(r.get_radio_response.preferences.wifi_password); r.which_variant = AdminMessage_get_radio_response_tag; @@ -67,76 +71,76 @@ void AdminModule::handleGetConfig(const MeshPacket &req) AdminMessage r = AdminMessage_init_default; if (req.decoded.want_response) { - switch(r.get_config_request) { - case AdminMessage_ConfigType_ALL: - DEBUG_MSG("Requesting AdminMessage_ConfigType_ALL\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_ALL; - break; - case AdminMessage_ConfigType_CORE_ONLY: - DEBUG_MSG("Requesting AdminMessage_ConfigType_CORE_ONLY\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_CORE_ONLY; - break; - case AdminMessage_ConfigType_MODULE_ONLY: - DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_ONLY\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_ONLY; - break; - case AdminMessage_ConfigType_DEVICE_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_DEVICE_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_DEVICE_CONFIG; - break; - case AdminMessage_ConfigType_GPS_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_GPS_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_GPS_CONFIG; - break; - case AdminMessage_ConfigType_POWER_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_POWER_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_POWER_CONFIG; - break; - case AdminMessage_ConfigType_WIFI_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_WIFI_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_POWER_CONFIG; - break; - case AdminMessage_ConfigType_DISPLAY_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_DISPLAY_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_DISPLAY_CONFIG; - break; - case AdminMessage_ConfigType_LORA_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_LORA_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_LORA_CONFIG; - break; - case AdminMessage_ConfigType_MODULE_MQTT_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_MQTT_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_MQTT_CONFIG; - break; - case AdminMessage_ConfigType_MODULE_SERIAL_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_SERIAL_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_SERIAL_CONFIG; - break; - case AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG; - break; - case AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG; - break; - case AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG; - break; - case AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG; - r.get_config_response.payloadVariant.module_config.which_payloadVariant = Config_ModuleConfig_telemetry_config_tag; - r.get_config_response.payloadVariant.module_config.payloadVariant.telemetry_config = - config.payloadVariant.module_config.payloadVariant.telemetry_config; - break; - case AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG: - DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG\n"); - r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG; - break; - default: - break; + switch (r.get_config_request) { + case AdminMessage_ConfigType_ALL: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_ALL\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_ALL; + break; + case AdminMessage_ConfigType_CORE_ONLY: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_CORE_ONLY\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_CORE_ONLY; + break; + case AdminMessage_ConfigType_MODULE_ONLY: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_ONLY\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_ONLY; + break; + case AdminMessage_ConfigType_DEVICE_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_DEVICE_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_DEVICE_CONFIG; + break; + case AdminMessage_ConfigType_GPS_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_GPS_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_GPS_CONFIG; + break; + case AdminMessage_ConfigType_POWER_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_POWER_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_POWER_CONFIG; + break; + case AdminMessage_ConfigType_WIFI_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_WIFI_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_POWER_CONFIG; + break; + case AdminMessage_ConfigType_DISPLAY_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_DISPLAY_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_DISPLAY_CONFIG; + break; + case AdminMessage_ConfigType_LORA_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_LORA_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_LORA_CONFIG; + break; + case AdminMessage_ConfigType_MODULE_MQTT_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_MQTT_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_MQTT_CONFIG; + break; + case AdminMessage_ConfigType_MODULE_SERIAL_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_SERIAL_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_SERIAL_CONFIG; + break; + case AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG; + break; + case AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG; + break; + case AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG; + break; + case AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG; + r.get_config_response.payloadVariant.module_config.which_payloadVariant = Config_ModuleConfig_telemetry_config_tag; + r.get_config_response.payloadVariant.module_config.payloadVariant.telemetry_config = + config.payloadVariant.module_config.payloadVariant.telemetry_config; + break; + case AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG: + DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG\n"); + r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG; + break; + default: + break; } // NOTE: The phone app needs to know the ls_secs & phone_timeout value so it can properly expect sleep behavior. @@ -144,8 +148,8 @@ void AdminModule::handleGetConfig(const MeshPacket &req) // using to the app (so that even old phone apps work with new device loads). // r.get_radio_response.preferences.ls_secs = getPref_ls_secs(); // r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs(); - // hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private and useful for users to know current provisioning) - // hideSecret(r.get_radio_response.preferences.wifi_password); + // hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private + // and useful for users to know current provisioning) hideSecret(r.get_radio_response.preferences.wifi_password); r.which_variant = AdminMessage_get_config_response_tag; myReply = allocDataProtobuf(r); @@ -209,6 +213,11 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r) handleGetConfig(mp); break; + case AdminMessage_set_config_tag: + DEBUG_MSG("Client is setting the config\n"); + handleSetConfig(r->set_config); + break; + case AdminMessage_get_owner_request_tag: DEBUG_MSG("Client is getting owner\n"); handleGetOwner(mp); @@ -238,16 +247,11 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r) AdminMessage response = AdminMessage_init_default; AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &response); - if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) - { + if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) { myReply = allocDataProtobuf(response); - } - else if (mp.decoded.want_response) - { + } else if (mp.decoded.want_response) { DEBUG_MSG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_variant); - } - else if (handleResult != AdminMessageHandleResult::HANDLED) - { + } else if (handleResult != AdminMessageHandleResult::HANDLED) { // Probably a message sent by us or sent to our local node. FIXME, we should avoid scanning these messages DEBUG_MSG("Ignoring nonrelevant admin %d\n", r->which_variant); } @@ -303,6 +307,66 @@ void AdminModule::handleSetRadio(RadioConfig &r) service.reloadConfig(); } +void AdminModule::handleSetConfig(Config &c) +{ + switch (c.which_payloadVariant) { + case AdminMessage_ConfigType_ALL: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_ALL\n"); + break; + case AdminMessage_ConfigType_CORE_ONLY: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_CORE_ONLY\n"); + break; + case AdminMessage_ConfigType_MODULE_ONLY: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_ONLY\n"); + break; + case AdminMessage_ConfigType_DEVICE_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_DEVICE_CONFIG\n"); + break; + case AdminMessage_ConfigType_GPS_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_GPS_CONFIG\n"); + break; + case AdminMessage_ConfigType_POWER_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_POWER_CONFIG\n"); + break; + case AdminMessage_ConfigType_WIFI_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_WIFI_CONFIG\n"); + break; + case AdminMessage_ConfigType_DISPLAY_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_DISPLAY_CONFIG\n"); + break; + case AdminMessage_ConfigType_LORA_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_LORA_CONFIG\n"); + break; + case AdminMessage_ConfigType_MODULE_MQTT_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_MQTT_CONFIG\n"); + break; + case AdminMessage_ConfigType_MODULE_SERIAL_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_SERIAL_CONFIG\n"); + break; + case AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG\n"); + break; + case AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG\n"); + break; + case AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG\n"); + break; + case AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG\n"); + config.payloadVariant.module_config.payloadVariant.telemetry_config = + c.payloadVariant.module_config.payloadVariant.telemetry_config; + break; + case AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG: + DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG\n"); + break; + default: + break; + } + + service.reloadConfig(); +} + AdminModule::AdminModule() : ProtobufModule("Admin", PortNum_ADMIN_APP, AdminMessage_fields) { // restrict to the admin channel for rx diff --git a/src/modules/AdminModule.h b/src/modules/AdminModule.h index d80b215d2..ef71b54eb 100644 --- a/src/modules/AdminModule.h +++ b/src/modules/AdminModule.h @@ -23,6 +23,7 @@ class AdminModule : public ProtobufModule void handleSetOwner(const User &o); void handleSetChannel(const Channel &cc); void handleSetRadio(RadioConfig &r); + void handleSetConfig(Config &c); void handleGetChannel(const MeshPacket &req, uint32_t channelIndex); void handleGetRadio(const MeshPacket &req); From 7ae8601ba51f7c541ad259a34ea80dd585e9dfee Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Mon, 2 May 2022 10:24:28 +1000 Subject: [PATCH 30/31] fix warnings --- proto | 2 +- src/mesh/generated/admin.pb.h | 2 +- src/modules/AdminModule.cpp | 2 +- src/modules/AdminModule.h | 2 +- src/sleep.cpp | 42 +++++++++++++++++------------------ 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/proto b/proto index cb7bf9ac2..79d24080f 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit cb7bf9ac239b87c6a988feb0bb49c8a3e85dea0e +Subproject commit 79d24080ff83b0a54bc1619f07f41f17ffedfb99 diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index da91fcd99..f6e8ac5e5 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -5,9 +5,9 @@ #define PB_ADMIN_PB_H_INCLUDED #include #include "channel.pb.h" +#include "config.pb.h" #include "mesh.pb.h" #include "radioconfig.pb.h" -#include "config.pb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 2f3f116d5..8b78a2bb1 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -307,7 +307,7 @@ void AdminModule::handleSetRadio(RadioConfig &r) service.reloadConfig(); } -void AdminModule::handleSetConfig(Config &c) +void AdminModule::handleSetConfig(const Config &c) { switch (c.which_payloadVariant) { case AdminMessage_ConfigType_ALL: diff --git a/src/modules/AdminModule.h b/src/modules/AdminModule.h index ef71b54eb..d31d4269b 100644 --- a/src/modules/AdminModule.h +++ b/src/modules/AdminModule.h @@ -23,7 +23,7 @@ class AdminModule : public ProtobufModule void handleSetOwner(const User &o); void handleSetChannel(const Channel &cc); void handleSetRadio(RadioConfig &r); - void handleSetConfig(Config &c); + void handleSetConfig(const Config &c); void handleGetChannel(const MeshPacket &req, uint32_t channelIndex); void handleGetRadio(const MeshPacket &req); diff --git a/src/sleep.cpp b/src/sleep.cpp index fce4f02a3..849ec33a1 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -1,9 +1,9 @@ -#include "configuration.h" #include "sleep.h" #include "GPS.h" #include "MeshRadio.h" #include "MeshService.h" #include "NodeDB.h" +#include "configuration.h" #include "error.h" #include "main.h" #include "target_specific.h" @@ -11,10 +11,10 @@ #ifndef NO_ESP32 #include "esp32/pm.h" #include "esp_pm.h" +#include "mesh/http/WiFiAPClient.h" #include "rom/rtc.h" #include #include -#include "mesh/http/WiFiAPClient.h" #include "nimble/BluetoothUtil.h" @@ -51,25 +51,25 @@ void setCPUFast(bool on) #ifndef NO_ESP32 if (isWifiAvailable()) { - /* - * - * There's a newly introduced bug in the espressif framework where WiFi is - * unstable when the frequency is less than 240mhz. - * - * This mostly impacts WiFi AP mode but we'll bump the frequency for - * all WiFi use cases. - * (Added: Dec 23, 2021 by Jm Casler) - */ + /* + * + * There's a newly introduced bug in the espressif framework where WiFi is + * unstable when the frequency is less than 240mhz. + * + * This mostly impacts WiFi AP mode but we'll bump the frequency for + * all WiFi use cases. + * (Added: Dec 23, 2021 by Jm Casler) + */ DEBUG_MSG("Setting CPU to 240mhz because WiFi is in use.\n"); setCpuFrequencyMhz(240); return; } - // The Heltec LORA32 V1 runs at 26 MHz base frequency and doesn't react well to switching to 80 MHz... - #ifndef ARDUINO_HELTEC_WIFI_LORA_32 - setCpuFrequencyMhz(on ? 240 : 80); - #endif - +// The Heltec LORA32 V1 runs at 26 MHz base frequency and doesn't react well to switching to 80 MHz... +#ifndef ARDUINO_HELTEC_WIFI_LORA_32 + setCpuFrequencyMhz(on ? 240 : 80); +#endif + #endif } @@ -284,12 +284,12 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r */ void enableModemSleep() { - static esp_pm_config_esp32_t config; // filled with zeros because bss + static esp_pm_config_esp32_t esp32_config; // filled with zeros because bss - config.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; - config.min_freq_mhz = 20; // 10Mhz is minimum recommended - config.light_sleep_enable = false; - int rv = esp_pm_configure(&config); + esp32_config.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; + esp32_config.min_freq_mhz = 20; // 10Mhz is minimum recommended + esp32_config.light_sleep_enable = false; + int rv = esp_pm_configure(&esp32_config); DEBUG_MSG("Sleep request result %x\n", rv); } #endif From caac2ecb83b058194e9d7cf7f2aaa96706819573 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 1 May 2022 20:30:19 -0500 Subject: [PATCH 31/31] Compute config size and account for reloadconfig (#1428) * Compute config size and account for reloadconfig * Reload config and config_size --- src/mesh/NodeDB.cpp | 11 +++++++++++ src/mesh/NodeDB.h | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index c40849213..e9b88bf63 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -143,6 +143,11 @@ bool NodeDB::resetRadioConfig() return didFactoryReset; } +void NodeDB::installDefaultConfig() +{ + memset(&config, 0, sizeof(config)); +} + void NodeDB::installDefaultRadioConfig() { memset(&radioConfig, 0, sizeof(radioConfig)); @@ -281,6 +286,7 @@ void NodeDB::pickNewNodeNum() static const char *preffile = "/prefs/db.proto"; static const char *radiofile = "/prefs/radio.proto"; +static const char *configfile = "/prefs/config.proto"; static const char *channelfile = "/prefs/channels.proto"; /** Load a protobuf from a file, return true for success */ @@ -333,6 +339,10 @@ void NodeDB::loadFromDisk() installDefaultRadioConfig(); // Our in RAM copy might now be corrupt } + if (!loadProto(configfile, Config_size, sizeof(Config), Config_fields, &config)) { + installDefaultConfig(); // Our in RAM copy might now be corrupt + } + if (!loadProto(channelfile, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile)) { installDefaultChannels(); // Our in RAM copy might now be corrupt } @@ -391,6 +401,7 @@ void NodeDB::saveToDisk() #endif saveProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); saveProto(radiofile, RadioConfig_size, sizeof(RadioConfig), RadioConfig_fields, &radioConfig); + saveProto(configfile, Config_size, sizeof(Config), Config_fields, &config); saveChannelsToDisk(); } else { diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index d7cc44e85..793c4e73a 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -123,7 +123,7 @@ class NodeDB void loadFromDisk(); /// Reinit device state from scratch (not loading from disk) - void installDefaultDeviceState(), installDefaultRadioConfig(), installDefaultChannels(); + void installDefaultDeviceState(), installDefaultRadioConfig(), installDefaultChannels(), installDefaultConfig(); }; /** @@ -194,3 +194,5 @@ PREF_GET(min_wake_secs, 10) */ extern uint32_t radioGeneration; +// Config doesn't have a nanopb generated full size constant +#define Config_size (Config_DeviceConfig_size + Config_DisplayConfig_size + Config_GpsConfig_size + Config_LoRaConfig_size + Config_ModuleConfig_CannedMessageConfig_size + Config_ModuleConfig_ExternalNotificationConfig_size + Config_ModuleConfig_MQTTConfig_size + Config_ModuleConfig_RangeTestConfig_size + Config_ModuleConfig_SerialConfig_size + Config_ModuleConfig_StoreForwardConfig_size + Config_ModuleConfig_TelemetryConfig_size + Config_ModuleConfig_size + Config_PowerConfig_size) \ No newline at end of file