From a5326ad7faa8be26b81cf119c709963a2f6a4d8a Mon Sep 17 00:00:00 2001 From: cureton Date: Tue, 12 Mar 2024 23:12:45 +1100 Subject: [PATCH 1/2] Add enum for radio module types and update ConfigManager board table --- tinyGS/src/ConfigManager/ConfigManager.cpp | 50 +++++++++---------- tinyGS/src/Radio/Radio.cpp | 58 ++++++++++++---------- tinyGS/src/Radio/Radio.h | 11 ++++ 3 files changed, 67 insertions(+), 52 deletions(-) diff --git a/tinyGS/src/ConfigManager/ConfigManager.cpp b/tinyGS/src/ConfigManager/ConfigManager.cpp index 23963577..66b557fa 100644 --- a/tinyGS/src/ConfigManager/ConfigManager.cpp +++ b/tinyGS/src/ConfigManager/ConfigManager.cpp @@ -51,33 +51,33 @@ ConfigManager::ConfigManager() : IotWebConf2(thingName, &dnsServer, &server, initialApPassword, configVersion), server(80), gsConfigHtmlFormatProvider(*this), boards({ //OLED_add, OLED_SDA, OLED_SCL, OLED_RST, PROG_BUTTON, BOARD_LED, L_SX127X?, L_NSS, L_DI00, L_DI01, L_BUSSY, L_RST, L_MISO, L_MOSI, L_SCK, L_TCXO_V, RX_EN, TX_EN, BOARD #if CONFIG_IDF_TARGET_ESP32S3 - { 0x3c, 17, 18, 21, 0, 35, 6, 8, UNUSED, 14, 13, 12, 11, 10, 9, 1.6f, UNUSED, UNUSED, "150–960Mhz - HELTEC LORA32 V3 SX1262" }, // SX1262 - { 0x3c, 17, 18, UNUSED, 0, 35, 1, 8, 6, 14, UNUSED, 12, 11, 10, 9, 0.0f, UNUSED, UNUSED, "Custom ESP32-S3 433MHz SX1278" }, // SX1278 @g4lile0 + { 0x3c, 17, 18, 21, 0, 35, RADIO_SX1262, 8, UNUSED, 14, 13, 12, 11, 10, 9, 1.6f, UNUSED, UNUSED, "150–960Mhz - HELTEC LORA32 V3 SX1262" }, // SX1262 + { 0x3c, 17, 18, UNUSED, 0, 35, RADIO_SX1278, 8, 6, 14, UNUSED, 12, 11, 10, 9, 0.0f, UNUSED, UNUSED, "Custom ESP32-S3 433MHz SX1278" }, // SX1278 @g4lile0 #elif CONFIG_IDF_TARGET_ESP32C3 - { 0x3c, 0, 1, UNUSED, 20, 21, 6, 8, UNUSED, 3, 4, 5, 6, 7, 10, 1.6f, UNUSED, UNUSED, "433MHz HELTEC LORA32 HT-CT62 SX1262" }, // SX1262 @gargomoma - { 0x3c, 0, 1, UNUSED, 20, 21, 1, 8, 4, UNUSED, UNUSED, 5, 6, 7, 10, 0.0f, UNUSED, UNUSED, "Custom ESP32-C3 433MHz SX1278" }, // SX1278 @gargomoma + { 0x3c, 0, 1, UNUSED, 20, 21, RADIO_SX1262, 8, UNUSED, 3, 4, 5, 6, 7, 10, 1.6f, UNUSED, UNUSED, "433MHz HELTEC LORA32 HT-CT62 SX1262" }, // SX1262 @gargomoma + { 0x3c, 0, 1, UNUSED, 20, 21, RADIO_SX1278, 8, 4, UNUSED, UNUSED, 5, 6, 7, 10, 0.0f, UNUSED, UNUSED, "Custom ESP32-C3 433MHz SX1278" }, // SX1278 @gargomoma #else - { 0x3c, 4, 15, 16, 0, 25, 1, 18, 26, 12, UNUSED , 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz HELTEC WiFi LoRA 32 V1" }, // SX1278 @4m1g0 - { 0x3c, 4, 15, 16, 0, 25, 2, 18, 26, 12, UNUSED , 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "863-928MHz HELTEC WiFi LoRA 32 V1" }, // SX1276 - { 0x3c, 4, 15, 16, 0, 25, 1, 18, 26, 35, UNUSED , 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz HELTEC WiFi LoRA 32 V2" }, // SX1278 @4m1g0 - { 0x3c, 4, 15, 16, 0, 25, 2, 18, 26, 35, UNUSED , 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "863-928MHz HELTEC WiFi LoRA 32 V2" }, // SX1276 - { 0x3c, 4, 15, 16, 0, 2, 1, 18, 26, UNUSED, UNUSED , 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433Mhz TTGO LoRa 32 v1" }, // SX1278 @g4lile0 - { 0x3c, 4, 15, 16, 0, 2, 2, 18, 26, UNUSED, UNUSED , 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "868-915MHz TTGO LoRa 32 v1" }, // SX1276 - { 0x3c, 21, 22, UNUSED, 0, 22, 1, 18, 26, 33, UNUSED , 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz TTGO LoRA 32 v2" }, // SX1278 @TCRobotics - { 0x3c, 21, 22, 16, 0, 22, 2, 18, 26, 33, UNUSED , 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "868-915MHz TTGO LoRA 32 v2" }, // SX1276 - { 0x3c, 21, 22, 16, 39, 22, 1, 18, 26, 33, 32, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz T-BEAM + OLED" }, // SX1278 - { 0x3c, 21, 22, 16, 39, 22, 2, 18, 26, 33, 32, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "868-915MHz T-BEAM + OLED" }, // SX1276 - { 0x3c, 21, 22, 16, 0, 25, 5, 5, UNUSED, 27, 26, 14, 19, 23, 18, 0.0f, UNUSED, UNUSED, "Custom ESP32 Wroom + SX126x (Crystal)" }, // SX1268 @4m1g0, @lillefyr - { 0x3c, 21, 22, UNUSED, 0, 25, 5, 18, UNUSED, 33, 32, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "TTGO LoRa 32 V2 Modified with module SX126x (crystal)" }, // SX1268 @TCRobotics - { 0x3c, 21, 22, 16, 0, 25, 5, 5, UNUSED, 2, 13, 26, 19, 23, 18, 1.6f, UNUSED, UNUSED, "Custom ESP32 Wroom + SX126x DRF1268T (TCX0) (5, 2, 26, 13)" }, // SX1268 @sdey76 - { 0x3c, 21, 22, 16, 0, 25, 5, 5, UNUSED, 26, 12, 14, 19, 23, 18, 1.6f, UNUSED, UNUSED, "Custom ESP32 Wroom + SX126x DRF1268T (TCX0) (5, 26, 14, 12)" }, // SX1268 @imants - { 0x3c, 21, 22, UNUSED, 38, 22, 1, 18, 26, 33, UNUSED , 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz T-BEAM V1.0 + OLED" }, // SX1278 @fafu - { 0x3c, 21, 22, 16, 0, 2, 5, 5, UNUSED, 34, 32, 14, 19, 27, 18, 1.6f, UNUSED, UNUSED, "433MHz FOSSA 1W Ground Station" }, // SX1268 @jgromes - { 0x3c, 21, 22, 16, 0, 2, 2, 5, UNUSED, 34, 32, 14, 19, 27, 18, 1.6f, UNUSED, UNUSED, "868-915MHz FOSSA 1W Ground Station" }, //SX1276 @jgromes - { 0x3c, 21, 22, UNUSED, 0, 22, 8, 5, 26, 34, 32, 14, 19, 27, 18, 0.0f, UNUSED, UNUSED, "2.4GHz ESP32 + SX1280" }, //SX1280 @g4lile0 - { 0x3c, 21, 22, UNUSED, 38, 22, 2, 18, 26, 33, UNUSED , 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "868-915MHz T-BEAM V1.0 + OLED" }, // SX1276 @fafu - { 0x3c, 21, 22, UNUSED, 0, 25, 1, 18, 26, 33, UNUSED , 23, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz LILYGO T3_V1.6.1" }, // SX1278 - { 0x3c, 21, 22, UNUSED, 0, 25, 2, 18, 26, 33, UNUSED , 23, 19, 27, 5, 0.0f, UNUSED, UNUSED, "868-915MHz LILYGO T3_V1.6.1" }, // SX1276 + { 0x3c, 4, 15, 16, 0, 25, RADIO_SX1278, 18, 26, 12, UNUSED, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz HELTEC WiFi LoRA 32 V1" }, // SX1278 @4m1g0 + { 0x3c, 4, 15, 16, 0, 25, RADIO_SX1276, 18, 26, 12, UNUSED, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "863-928MHz HELTEC WiFi LoRA 32 V1" }, // SX1276 + { 0x3c, 4, 15, 16, 0, 25, RADIO_SX1278, 18, 26, 35, UNUSED, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz HELTEC WiFi LoRA 32 V2" }, // SX1278 @4m1g0 + { 0x3c, 4, 15, 16, 0, 25, RADIO_SX1276, 18, 26, 35, UNUSED, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "863-928MHz HELTEC WiFi LoRA 32 V2" }, // SX1276 + { 0x3c, 4, 15, 16, 0, 2, RADIO_SX1278, 18, 26, UNUSED, UNUSED, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433Mhz TTGO LoRa 32 v1" }, // SX1278 @g4lile0 + { 0x3c, 4, 15, 16, 0, 2, RADIO_SX1276, 18, 26, UNUSED, UNUSED, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "868-915MHz TTGO LoRa 32 v1" }, // SX1276 + { 0x3c, 21, 22, UNUSED, 0, 22, RADIO_SX1278, 18, 26, 33, UNUSED, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz TTGO LoRA 32 v2" }, // SX1278 @TCRobotics + { 0x3c, 21, 22, 16, 0, 22, RADIO_SX1276, 18, 26, 33, UNUSED, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "868-915MHz TTGO LoRA 32 v2" }, // SX1276 + { 0x3c, 21, 22, 16, 39, 22, RADIO_SX1278, 18, 26, 33, 32, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz T-BEAM + OLED" }, // SX1278 + { 0x3c, 21, 22, 16, 39, 22, RADIO_SX1276, 18, 26, 33, 32, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "868-915MHz T-BEAM + OLED" }, // SX1276 + { 0x3c, 21, 22, 16, 0, 25, RADIO_SX1268, 5, UNUSED, 27, 26, 14, 19, 23, 18, 0.0f, UNUSED, UNUSED, "Custom ESP32 Wroom + SX126x (Crystal)" }, // SX1268 @4m1g0, @lillefyr + { 0x3c, 21, 22, UNUSED, 0, 25, RADIO_SX1268, 18, UNUSED, 33, 32, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "TTGO LoRa 32 V2 Modified with module SX126x (crystal)" }, // SX1268 @TCRobotics + { 0x3c, 21, 22, 16, 0, 25, RADIO_SX1268, 5, UNUSED, 2, 13, 26, 19, 23, 18, 1.6f, UNUSED, UNUSED, "Custom ESP32 Wroom + SX126x DRF1268T (TCX0) (5, 2, 26, 13)" }, // SX1268 @sdey76 + { 0x3c, 21, 22, 16, 0, 25, RADIO_SX1268, 5, UNUSED, 26, 12, 14, 19, 23, 18, 1.6f, UNUSED, UNUSED, "Custom ESP32 Wroom + SX126x DRF1268T (TCX0) (5, 26, 14, 12)" }, // SX1268 @imants + { 0x3c, 21, 22, UNUSED, 38, 22, RADIO_SX1278, 18, 26, 33, UNUSED, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz T-BEAM V1.0 + OLED" }, // SX1278 @fafu + { 0x3c, 21, 22, 16, 0, 2, RADIO_SX1268, 5, UNUSED, 34, 32, 14, 19, 27, 18, 1.6f, UNUSED, UNUSED, "433MHz FOSSA 1W Ground Station" }, // SX1268 @jgromes + { 0x3c, 21, 22, 16, 0, 2, RADIO_SX1276, 5, UNUSED, 34, 32, 14, 19, 27, 18, 1.6f, UNUSED, UNUSED, "868-915MHz FOSSA 1W Ground Station" }, //SX1276 @jgromes + { 0x3c, 21, 22, UNUSED, 0, 22, RADIO_SX1280, 5, 26, 34, 32, 14, 19, 27, 18, 0.0f, UNUSED, UNUSED, "2.4GHz ESP32 + SX1280" }, //SX1280 @g4lile0 + { 0x3c, 21, 22, UNUSED, 38, 22, RADIO_SX1276, 18, 26, 33, UNUSED, 14, 19, 27, 5, 0.0f, UNUSED, UNUSED, "868-915MHz T-BEAM V1.0 + OLED" }, // SX1276 @fafu + { 0x3c, 21, 22, UNUSED, 0, 25, RADIO_SX1278, 18, 26, 33, UNUSED, 23, 19, 27, 5, 0.0f, UNUSED, UNUSED, "433MHz LILYGO T3_V1.6.1" }, // SX1278 + { 0x3c, 21, 22, UNUSED, 0, 25, RADIO_SX1276, 18, 26, 33, UNUSED, 23, 19, 27, 5, 0.0f, UNUSED, UNUSED, "868-915MHz LILYGO T3_V1.6.1" }, // SX1276 #endif }) { diff --git a/tinyGS/src/Radio/Radio.cpp b/tinyGS/src/Radio/Radio.cpp index 87adf087..7afe23fc 100644 --- a/tinyGS/src/Radio/Radio.cpp +++ b/tinyGS/src/Radio/Radio.cpp @@ -60,28 +60,29 @@ void Radio::init() spi.begin(board.L_SCK, board.L_MISO, board.L_MOSI, board.L_NSS); - if (board.L_radio == 1) - { - radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI00, board.L_RST, board.L_DI01, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); - } - else if (board.L_radio == 2) - { - radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI00, board.L_RST, board.L_DI01, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); - } - else if (board.L_radio == 5) - { - radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI01, board.L_RST, board.L_BUSSY, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); - } - else if (board.L_radio == 6) - { - radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI01, board.L_RST, board.L_BUSSY, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); - } - else if (board.L_radio == 8) - { - radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI01, board.L_RST, board.L_BUSSY, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); - } - else { - radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI01, board.L_RST, board.L_BUSSY, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); + switch (board.L_radio) { + case RADIO_SX1278: + radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI00, board.L_RST, board.L_DI01, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); + moduleNameString="SX1278"; + break; + case RADIO_SX1276: + radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI00, board.L_RST, board.L_DI01, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); + moduleNameString="SX1276"; + break; + case RADIO_SX1268: + radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI01, board.L_RST, board.L_BUSSY, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); + moduleNameString="SX1268"; + break; + case RADIO_SX1262: + radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI01, board.L_RST, board.L_BUSSY, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); + moduleNameString="SX1262"; + break; + case RADIO_SX1280: + radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI01, board.L_RST, board.L_BUSSY, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); + moduleNameString="SX1280"; + default: + radioHal = new RadioHal(new Module(board.L_NSS, board.L_DI01, board.L_RST, board.L_BUSSY, spi, SPISettings(2000000, MSBFIRST, SPI_MODE0))); + moduleNameString="default SX1268"; } if (board.RX_EN != UNUSED && board.TX_EN != UNUSED) @@ -134,7 +135,7 @@ int16_t Radio::begin() // attach the ISR to radio interrupt radioHal->setDio0Action(setFlag); // start listening for LoRa packets - Log::console(PSTR("[SX12x8] Starting to listen to %s"), m.satellite); + Log::console(PSTR("[%s] Starting to listen to %s"), moduleNameString, m.satellite); CHECK_ERROR(radioHal->startReceive()); status.modeminfo.currentRssi = radioHal->getRSSI(false,true); @@ -288,7 +289,10 @@ uint8_t Radio::listen() status.lastPacketInfo.frequencyerror = newPacketInfo.frequencyerror; // print RSSI (Received Signal Strength Indicator) - Log::console(PSTR("[SX12x8] RSSI:\t\t%f dBm\n[SX12x8] SNR:\t\t%f dB\n[SX12x8] Frequency error:\t%f Hz"), status.lastPacketInfo.rssi, status.lastPacketInfo.snr, status.lastPacketInfo.frequencyerror); + Log::console(PSTR("[%s] RSSI:\t\t%f dBm\n[%s] SNR:\t\t%f dB\n[%s] Frequency error:\t%f Hz"), + moduleNameString, status.lastPacketInfo.rssi, + moduleNameString, status.lastPacketInfo.snr, + moduleNameString, status.lastPacketInfo.frequencyerror); if (state == RADIOLIB_ERR_NONE && respLen > 0) { @@ -407,19 +411,19 @@ uint8_t Radio::listen() else if (state == RADIOLIB_ERR_CRC_MISMATCH) { // packet was received, but is malformed - Log::console(PSTR("[SX12x8] CRC error! Data cannot be retrieved")); + Log::console(PSTR("[%s] CRC error! Data cannot be retrieved"), moduleNameString); return 2; } else if (state == RADIOLIB_ERR_LORA_HEADER_DAMAGED) { // packet was received, but is malformed - Log::console(PSTR("[SX12x8] Damaged header! Data cannot be retrieved")); + Log::console(PSTR("[%S] Damaged header! Data cannot be retrieved"), moduleNameString); return 2; } else { // some other error occurred - Log::console(PSTR("[SX12x8] Failed, code %d"), state); + Log::console(PSTR("[%s] Failed, code %d"), moduleNameString, state); return 3; } } diff --git a/tinyGS/src/Radio/Radio.h b/tinyGS/src/Radio/Radio.h index e0b9d0e2..b1bda20f 100644 --- a/tinyGS/src/Radio/Radio.h +++ b/tinyGS/src/Radio/Radio.h @@ -30,6 +30,15 @@ extern Status status; + +enum RadioModelNum { + RADIO_SX1278 = 1, + RADIO_SX1276 = 2, + RADIO_SX1268 = 5, + RADIO_SX1262 = 6, + RADIO_SX1280 = 8 +}; + class Radio { public: static Radio& getInstance() @@ -45,6 +54,7 @@ class Radio { void startRx(); void currentRssi(); int16_t moduleSleep(); + const char* moduleName(); uint8_t listen(); bool isReady() { return status.radio_ready; } int16_t remote_freq(char* payload, size_t payload_len); @@ -79,6 +89,7 @@ class Radio { static void setFlag(); SPIClass spi; const char* TEST_STRING = "TinyGS-test "; // make sure this always start with "TinyGS-test"!!! + const char* moduleNameString = "Uninitalised"; double _atof(const char* buff, size_t length); int _atoi(const char* buff, size_t length); From 4e672fd99e0c9837ad0841da3030e8619f960c73 Mon Sep 17 00:00:00 2001 From: cureton Date: Tue, 12 Mar 2024 23:24:52 +1100 Subject: [PATCH 2/2] Remote unused fuction prototype --- tinyGS/src/Radio/Radio.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tinyGS/src/Radio/Radio.h b/tinyGS/src/Radio/Radio.h index b1bda20f..4312b250 100644 --- a/tinyGS/src/Radio/Radio.h +++ b/tinyGS/src/Radio/Radio.h @@ -54,7 +54,6 @@ class Radio { void startRx(); void currentRssi(); int16_t moduleSleep(); - const char* moduleName(); uint8_t listen(); bool isReady() { return status.radio_ready; } int16_t remote_freq(char* payload, size_t payload_len); @@ -95,4 +94,4 @@ class Radio { int _atoi(const char* buff, size_t length); }; -#endif \ No newline at end of file +#endif