From ef80c2638c1a1bc3239bd655712dbca585edbb01 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 16 Oct 2024 16:15:29 +0100 Subject: [PATCH 01/14] Fix BLE service duplication bug on nRF52 --- Bluetooth.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Bluetooth.h b/Bluetooth.h index ee3964e..60cf86a 100644 --- a/Bluetooth.h +++ b/Bluetooth.h @@ -32,6 +32,7 @@ BLEUart SerialBT; BLEDis bledis; BLEBas blebas; + bool SerialBT_init = false; #endif #define BT_PAIRING_TIMEOUT 35000 @@ -502,10 +503,14 @@ void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) { // start device information service bledis.begin(); - SerialBT.bufferTXD(true); // enable buffering + // Guard to ensure SerialBT service is not duplicated through BT being power cycled + if (!SerialBT_init) { + SerialBT.bufferTXD(true); // enable buffering - SerialBT.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM); // enable encryption for BLE serial - SerialBT.begin(); + SerialBT.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM); // enable encryption for BLE serial + SerialBT.begin(); + SerialBT_init = true; + } blebas.begin(); From a76a01b25fc980bee2910d421ce4279d20026f34 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 16 Oct 2024 16:17:47 +0100 Subject: [PATCH 02/14] Bump version to 1.75 --- Config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config.h b/Config.h index bfa07ff..1f0d6a9 100644 --- a/Config.h +++ b/Config.h @@ -20,7 +20,7 @@ #define CONFIG_H #define MAJ_VERS 0x01 - #define MIN_VERS 0x4e + #define MIN_VERS 0x4a #define MODE_HOST 0x11 #define MODE_TNC 0x12 From 89e37323cc370337d86dcce7eaa288b6799caae8 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 16 Oct 2024 16:25:40 +0100 Subject: [PATCH 03/14] Ensure instant startup on openCom XL --- RNode_Firmware_CE.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RNode_Firmware_CE.ino b/RNode_Firmware_CE.ino index 721260a..4b39cd6 100644 --- a/RNode_Firmware_CE.ino +++ b/RNode_Firmware_CE.ino @@ -135,7 +135,7 @@ void setup() { led_init(); #endif - #if BOARD_MODEL != BOARD_RAK4631 && BOARD_MODEL != BOARD_RNODE_NG_22 && BOARD_MODEL != BOARD_TBEAM_S_V1 && BOARD_MODEL != BOARD_T3S3 && BOARD_MODEL != BOARD_TECHO + #if BOARD_MODEL != BOARD_RAK4631 && BOARD_MODEL != BOARD_RNODE_NG_22 && BOARD_MODEL != BOARD_TBEAM_S_V1 && BOARD_MODEL != BOARD_T3S3 && BOARD_MODEL != BOARD_TECHO && BOARD_MODEL != BOARD_OPENCOM_XL // Some boards need to wait until the hardware UART is set up before booting // the full firmware. In the case of the RAK4631/TECHO, the line below will wait // until a serial connection is actually established with a master. Thus, it From 2930e89a3da40cffde082962e0b20e917e0e3957 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 16 Oct 2024 16:28:42 +0100 Subject: [PATCH 04/14] Add openCom XL board definition --- Boards.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Boards.h b/Boards.h index ac5474d..f5937c7 100644 --- a/Boards.h +++ b/Boards.h @@ -108,6 +108,7 @@ #define MODEL_14 0x14 // RAK4631, 868/915 MHz with WisBlock SX1280 module (LIBSYS002) #define PRODUCT_OPENCOM_XL 0x20 // openCom XL - sold by Liberated Embedded Systems + #define BOARD_OPENCOM_XL 0x52 #define MODEL_21 0x21 // openCom XL, 868/915 MHz #define BOARD_E22_ESP32 0x44 // Custom Ebyte E22 board design for meshtastic, source: From c18ec1629f2c81e01bc1c2314c9a580cbcfcd4df Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 16 Oct 2024 16:29:59 +0100 Subject: [PATCH 05/14] Update openCom XL makefile targets --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2fa721b..ba954fd 100644 --- a/Makefile +++ b/Makefile @@ -145,7 +145,7 @@ firmware-rak4631_sx1280: arduino-cli compile --fqbn rakwireless:nrf52:WisCoreRAK4631Board $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x51\" \"-DBOARD_VARIANT=0x14\"" firmware-opencom-xl: - arduino-cli compile --fqbn rakwireless:nrf52:WisCoreRAK4631Board $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x51\" \"-DBOARD_VARIANT=0x21\"" + arduino-cli compile --fqbn rakwireless:nrf52:WisCoreRAK4631Board $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x52\" \"-DBOARD_VARIANT=0x21\"" upload-tbeam: @@ -459,6 +459,6 @@ release-rak4631_sx1280: adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application build/rnode_firmware_rak4631_sx1280.hex Release/rnode_firmware_rak4631_sx1280.zip release-opencom-xl: - arduino-cli compile --fqbn rakwireless:nrf52:WisCoreRAK4631Board $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x51\" \"-DBOARD_VARIANT=0x21\"" + arduino-cli compile --fqbn rakwireless:nrf52:WisCoreRAK4631Board $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x52\" \"-DBOARD_VARIANT=0x21\"" cp build/rakwireless.nrf52.WisCoreRAK4631Board/RNode_Firmware_CE.ino.hex build/rnode_firmware_opencom_xl.hex adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application build/rnode_firmware_opencom_xl.hex Release/rnode_firmware_opencom_xl.zip From 6cb176796fe43a670652e0ab3c63c432d03f9c90 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 16 Oct 2024 16:59:45 +0100 Subject: [PATCH 06/14] Fix - correct version to 1.75 --- Config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config.h b/Config.h index 1f0d6a9..77cb0a4 100644 --- a/Config.h +++ b/Config.h @@ -20,7 +20,7 @@ #define CONFIG_H #define MAJ_VERS 0x01 - #define MIN_VERS 0x4a + #define MIN_VERS 0x4b #define MODE_HOST 0x11 #define MODE_TNC 0x12 From 17ff4b049626d35365c544643a2c84bec7e8c1ed Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 16 Oct 2024 21:23:33 +0100 Subject: [PATCH 07/14] Update T3S3 SX1280 PA model code, again --- Boards.h | 4 ++-- Makefile | 2 +- Radio.cpp | 2 +- Utilities.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Boards.h b/Boards.h index f5937c7..2f62a4c 100644 --- a/Boards.h +++ b/Boards.h @@ -82,7 +82,7 @@ #define MODEL_A1 0xA1 // T3S3 SX1262 868/915 MHz #define MODEL_AB 0xAB // T3S3 SX1276 868/915 MHz #define MODEL_A5 0xA5 // T3S3 SX1278 433 MHz - #define MODEL_AB 0xAB // T3S3 SX1280 2.4 GHz w/ PA + #define MODEL_AC 0xAC // T3S3 SX1280 2.4 GHz w/ PA #define PRODUCT_TECHO 0x15 // LilyGO T-Echo devices #define BOARD_TECHO 0x43 @@ -727,7 +727,7 @@ -1 // pin_tcxo_enable } }; - #elif BOARD_VARIANT == MODEL_AB // SX1280 with PA + #elif BOARD_VARIANT == MODEL_AC // SX1280 with PA const uint8_t interfaces[INTERFACE_COUNT] = {SX1280}; const bool interface_cfg[INTERFACE_COUNT][3] = { // SX1280 diff --git a/Makefile b/Makefile index ba954fd..e362222 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,7 @@ firmware-t3s3_sx126x: arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DBOARD_VARIANT=0xA1\"" firmware-t3s3_sx1280_pa: - arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DBOARD_VARIANT=0xAB\"" + arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DBOARD_VARIANT=0xAC\"" firmware-e22_esp32: arduino-cli compile --fqbn esp32:esp32:esp32 $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x44\" \"-DEXTERNAL_LEDS=true\"" diff --git a/Radio.cpp b/Radio.cpp index 03b8e70..852263c 100644 --- a/Radio.cpp +++ b/Radio.cpp @@ -2347,7 +2347,7 @@ void sx128x::setTxPower(int level, int outputPin) { executeOpcode(OP_TX_PARAMS_8X, tx_buf, 2); - #elif BOARD_VARIANT == MODEL_AB + #elif BOARD_VARIANT == MODEL_AC // T3S3 SX1280 PA if (level > 20) { level = 20; diff --git a/Utilities.h b/Utilities.h index bcde9b3..d9a34be 100644 --- a/Utilities.h +++ b/Utilities.h @@ -1048,7 +1048,7 @@ void setTXPower(RadioInterface* radio, int txp) { if (model == MODEL_A8) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_A9) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_AA) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); - if (model == MODEL_AB) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); + if (model == MODEL_AC) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_B3) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_B4) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); From 18780131d8b77ba7c645c245d0f223a3cf84ee23 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 16 Oct 2024 21:24:18 +0100 Subject: [PATCH 08/14] Fix openCom XL compilation --- Display.h | 10 +++++----- Power.h | 4 ++-- RNode_Firmware_CE.ino | 2 +- Radio.cpp | 4 ++-- Utilities.h | 6 ++++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Display.h b/Display.h index 4bfaf56..ba27ea4 100644 --- a/Display.h +++ b/Display.h @@ -94,7 +94,7 @@ void busyCallback(const void* p) { #define SCL_OLED 17 #define SDA_OLED 18 #endif -#elif BOARD_MODEL == BOARD_RAK4631 +#elif BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL #if DISPLAY == OLED // RAK1921/SSD1306 #define DISP_RST -1 @@ -135,7 +135,7 @@ void busyCallback(const void* p) { #include "Graphics.h" -#if BOARD_MODEL == BOARD_RAK4631 +#if BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL #if DISPLAY == EINK_BW GxEPD2_BW display(DISPLAY_MODEL(pin_disp_cs, pin_disp_dc, pin_disp_reset, pin_disp_busy)); float disp_target_fps = 0.2; @@ -316,7 +316,7 @@ bool display_init() { // waiting for the display to update, it will poll the serial buffer to // check for any commands from the host. display.epd2.setBusyCallback(busyCallback); - #elif BOARD_MODEL == BOARD_RAK4631 + #elif BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL #if DISPLAY == OLED #elif DISPLAY == EINK_BW || DISPLAY == EINK_3C pinMode(pin_disp_en, INPUT_PULLUP); @@ -386,7 +386,7 @@ bool display_init() { #elif BOARD_MODEL == BOARD_HELTEC32_V2 disp_mode = DISP_MODE_PORTRAIT; display.setRotation(1); - #elif BOARD_MODEL == BOARD_RAK4631 + #elif BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL #if DISPLAY == OLED #elif DISPLAY == EINK_BW || DISPLAY == EINK_3C disp_mode = DISP_MODE_PORTRAIT; @@ -397,7 +397,7 @@ bool display_init() { #elif BOARD_MODEL == BOARD_HELTEC32_V3 disp_mode = DISP_MODE_PORTRAIT; display.setRotation(1); - #elif BOARD_MODEL == BOARD_RAK4631 + #elif BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL disp_mode = DISP_MODE_LANDSCAPE; display.setRotation(0); #elif BOARD_MODEL == BOARD_TDECK diff --git a/Power.h b/Power.h index 0aec818..80d6e11 100644 --- a/Power.h +++ b/Power.h @@ -62,7 +62,7 @@ bool bat_voltage_dropping = false; float bat_delay_v = 0; float bat_state_change_v = 0; -#elif BOARD_MODEL == BOARD_RAK4631 +#elif BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL #include "nrfx_power.h" #define BAT_C_SAMPLES 7 #define BAT_D_SAMPLES 2 @@ -291,7 +291,7 @@ void measure_battery() { battery_ready = false; } - #elif BOARD_MODEL == BOARD_RAK4631 + #elif BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL battery_installed = true; battery_indeterminate = false; diff --git a/RNode_Firmware_CE.ino b/RNode_Firmware_CE.ino index 4b39cd6..143bff9 100644 --- a/RNode_Firmware_CE.ino +++ b/RNode_Firmware_CE.ino @@ -19,7 +19,7 @@ #if MCU_VARIANT == MCU_NRF52 #define INTERFACE_SPI - #if BOARD_MODEL == BOARD_RAK4631 + #if BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL // Required because on RAK4631, non-default SPI pins must be initialised when class is declared. SPIClass interface_spi[1] = { // SX1262 diff --git a/Radio.cpp b/Radio.cpp index 852263c..f1d7b04 100644 --- a/Radio.cpp +++ b/Radio.cpp @@ -740,7 +740,7 @@ void sx126x::sleep() void sx126x::enableTCXO() { if (_tcxo) { - #if BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_HELTEC32_V3 + #if BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL || BOARD_MODEL == BOARD_HELTEC32_V3 uint8_t buf[4] = {MODE_TCXO_3_3V_6X, 0x00, 0x00, 0xFF}; #elif BOARD_MODEL == BOARD_TBEAM uint8_t buf[4] = {MODE_TCXO_1_8V_6X, 0x00, 0x00, 0xFF}; @@ -2240,7 +2240,7 @@ void sx128x::disableTCXO() { void sx128x::setTxPower(int level, int outputPin) { uint8_t tx_buf[2]; - #if BOARD_VARIANT == MODEL_13 + #if BOARD_VARIANT == MODEL_13 || BOARD_VARIANT == MODEL_21 // RAK4631 with WisBlock SX1280 module (LIBSYS002) if (level > 27) { level = 27; diff --git a/Utilities.h b/Utilities.h index d9a34be..8a0eb9d 100644 --- a/Utilities.h +++ b/Utilities.h @@ -236,7 +236,7 @@ uint8_t boot_vector = 0x00; void led_tx_off() { digitalWrite(pin_led_tx, LOW); } #endif #elif MCU_VARIANT == MCU_NRF52 - #if BOARD_MODEL == BOARD_RAK4631 + #if BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL void led_rx_on() { digitalWrite(pin_led_rx, HIGH); } void led_rx_off() { digitalWrite(pin_led_rx, LOW); } void led_tx_on() { digitalWrite(pin_led_tx, HIGH); } @@ -1427,7 +1427,9 @@ bool eeprom_model_valid() { #elif BOARD_MODEL == BOARD_HELTEC32_V3 if (model == MODEL_C5 || model == MODEL_CA) { #elif BOARD_MODEL == BOARD_RAK4631 - if (model == MODEL_11 || model == MODEL_12 || model == MODEL_13 || model == MODEL_14 || model == MODEL_21) { + if (model == MODEL_11 || model == MODEL_12 || model == MODEL_13 || model == MODEL_14) { + #elif BOARD_MODEL == BOARD_OPENCOM_XL + if (model == MODEL_21) { #elif BOARD_MODEL == BOARD_HUZZAH32 if (model == MODEL_FF) { #elif BOARD_MODEL == BOARD_HMBRW From c4104ce0c7363a782dfcef3f16c63b47952d289d Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 16 Oct 2024 21:49:45 +0100 Subject: [PATCH 09/14] Add openCom XL upload target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e362222..4c0ba5a 100644 --- a/Makefile +++ b/Makefile @@ -243,7 +243,7 @@ upload-featheresp32: @sleep 3 python ./Release/esptool/esptool.py --port $(or $(port), /dev/ttyUSB0) $(COMMON_UPLOAD_FLAGS) ./Release/console_image.bin -upload-rak4631: +upload-opencom-xl upload-rak4631: arduino-cli upload -p $(or $(port), /dev/ttyACM0) --fqbn rakwireless:nrf52:WisCoreRAK4631Board unzip -o build/rakwireless.nrf52.WisCoreRAK4631Board/RNode_Firmware_CE.ino.zip -d build/rakwireless.nrf52.WisCoreRAK4631Board rnodeconf $(or $(port), /dev/ttyACM0) --firmware-hash $$(sha256sum ./build/rakwireless.nrf52.WisCoreRAK4631Board/RNode_Firmware_CE.ino.bin | grep -o '^\S*') From bf38bbf7b1929823c6351abf99cff1b782c413ad Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Tue, 22 Oct 2024 11:55:58 +0100 Subject: [PATCH 10/14] Correct version to 1.74 --- Config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config.h b/Config.h index 77cb0a4..1f0d6a9 100644 --- a/Config.h +++ b/Config.h @@ -20,7 +20,7 @@ #define CONFIG_H #define MAJ_VERS 0x01 - #define MIN_VERS 0x4b + #define MIN_VERS 0x4a #define MODE_HOST 0x11 #define MODE_TNC 0x12 From a4081fd79c546de6e56f21d024672cafd8a6eea6 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Tue, 22 Oct 2024 14:07:23 +0100 Subject: [PATCH 11/14] Fix edge case of potential packet duplication --- Radio.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Radio.cpp b/Radio.cpp index f1d7b04..964edae 100644 --- a/Radio.cpp +++ b/Radio.cpp @@ -110,6 +110,7 @@ void ISR_VECT onDio0Rise() { // Therefore, the modem is set into receive mode each time a packet is received. interface_obj[i]->receive(); } + break; } } taskEXIT_CRITICAL_FROM_ISR(int_status); From 8207c62d733034b1b6cfcfb90603e3c9fc741d1b Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Tue, 22 Oct 2024 18:02:46 +0100 Subject: [PATCH 12/14] Change read_len to array to combat multiple interface edge case --- Config.h | 2 +- RNode_Firmware_CE.ino | 44 ++++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Config.h b/Config.h index 1f0d6a9..41646ec 100644 --- a/Config.h +++ b/Config.h @@ -90,7 +90,7 @@ uint8_t last_rssi_raw = 0x00; uint8_t last_snr_raw = 0x80; uint8_t seq[INTERFACE_COUNT]; - uint16_t read_len = 0; + uint16_t read_len[INTERFACE_COUNT]; bool serial_in_frame = false; diff --git a/RNode_Firmware_CE.ino b/RNode_Firmware_CE.ino index 143bff9..961d293 100644 --- a/RNode_Firmware_CE.ino +++ b/RNode_Firmware_CE.ino @@ -168,6 +168,7 @@ void setup() { memset(packet_lengths_buf, 0, sizeof(packet_starts_buf)); memset(seq, 0xFF, sizeof(seq)); + memset(read_len, 0, sizeof(read_len)); modem_packet_queue = xQueueCreate(MODEM_QUEUE_SIZE, sizeof(modem_packet_t*)); @@ -355,7 +356,7 @@ inline void kiss_write_packet(int index) { // Add index of interface the packet came from serial_write(cmd_byte); - for (uint16_t i = 0; i < read_len; i++) { + for (uint16_t i = 0; i < read_len[index]; i++) { #if MCU_VARIANT == MCU_NRF52 portENTER_CRITICAL(); uint8_t byte = pbuf[i]; @@ -370,7 +371,7 @@ inline void kiss_write_packet(int index) { } serial_write(FEND); - read_len = 0; + read_len[index] = 0; #if MCU_VARIANT == MCU_ESP32 && HAS_BLE bt_flush(); @@ -378,14 +379,15 @@ inline void kiss_write_packet(int index) { } inline void getPacketData(RadioInterface* radio, uint16_t len) { + uint8_t index = radio->getIndex(); #if MCU_VARIANT != MCU_NRF52 - while (len-- && read_len < MTU) { - pbuf[read_len++] = radio->read(); + while (len-- && read_len[index] < MTU) { + pbuf[read_len[index]++] = radio->read(); } #else BaseType_t int_mask = taskENTER_CRITICAL_FROM_ISR(); - while (len-- && read_len < MTU) { - pbuf[read_len++] = radio->read(); + while (len-- && read_len[index] < MTU) { + pbuf[read_len[index]++] = radio->read(); } taskEXIT_CRITICAL_FROM_ISR(int_mask); #endif @@ -394,7 +396,7 @@ inline void getPacketData(RadioInterface* radio, uint16_t len) { inline bool queue_packet(RadioInterface* radio, uint8_t index) { // Allocate packet struct, but abort if there // is not enough memory available. - modem_packet_t *modem_packet = (modem_packet_t*)malloc(sizeof(modem_packet_t) + read_len); + modem_packet_t *modem_packet = (modem_packet_t*)malloc(sizeof(modem_packet_t) + read_len[index]); if(!modem_packet) { memory_low = true; return false; } // Get packet RSSI and SNR @@ -408,8 +410,8 @@ inline bool queue_packet(RadioInterface* radio, uint8_t index) { // Send packet to event queue, but free the // allocated memory again if the queue is // unable to receive the packet. - modem_packet->len = read_len; - memcpy(modem_packet->data, pbuf, read_len); + modem_packet->len = read_len[index]; + memcpy(modem_packet->data, pbuf, read_len[index]); if (!modem_packet_queue || xQueueSendFromISR(modem_packet_queue, &modem_packet, NULL) != pdPASS) { free(modem_packet); return false; @@ -437,9 +439,9 @@ void ISR_VECT receive_callback(uint8_t index, int packet_size) { // packet, so we set the seq variable // and add the data to the buffer #if MCU_VARIANT == MCU_NRF52 - int_mask = taskENTER_CRITICAL_FROM_ISR(); read_len = 0; taskEXIT_CRITICAL_FROM_ISR(int_mask); + int_mask = taskENTER_CRITICAL_FROM_ISR(); read_len[index] = 0; taskEXIT_CRITICAL_FROM_ISR(int_mask); #else - read_len = 0; + read_len[index] = 0; #endif seq[index] = sequence; @@ -462,9 +464,9 @@ void ISR_VECT receive_callback(uint8_t index, int packet_size) { // that we are seeing the first part of // a new split packet. #if MCU_VARIANT == MCU_NRF52 - int_mask = taskENTER_CRITICAL_FROM_ISR(); read_len = 0; taskEXIT_CRITICAL_FROM_ISR(int_mask); + int_mask = taskENTER_CRITICAL_FROM_ISR(); read_len[index] = 0; taskEXIT_CRITICAL_FROM_ISR(int_mask); #else - read_len = 0; + read_len[index] = 0; #endif seq[index] = sequence; @@ -479,9 +481,9 @@ void ISR_VECT receive_callback(uint8_t index, int packet_size) { // If we already had part of a split // packet in the buffer, we clear it. #if MCU_VARIANT == MCU_NRF52 - int_mask = taskENTER_CRITICAL_FROM_ISR(); read_len = 0; taskEXIT_CRITICAL_FROM_ISR(int_mask); + int_mask = taskENTER_CRITICAL_FROM_ISR(); read_len[index] = 0; taskEXIT_CRITICAL_FROM_ISR(int_mask); #else - read_len = 0; + read_len[index] = 0; #endif seq[index] = SEQ_UNSET; } @@ -493,7 +495,7 @@ void ISR_VECT receive_callback(uint8_t index, int packet_size) { } else { // In promiscuous mode, raw packets are // output directly to the host - read_len = 0; + read_len[index] = 0; getPacketData(selected_radio, packet_size); @@ -1318,10 +1320,10 @@ void loop() { #if MCU_VARIANT == MCU_ESP32 modem_packet_t *modem_packet = NULL; if(modem_packet_queue && xQueueReceive(modem_packet_queue, &modem_packet, 0) == pdTRUE && modem_packet) { - read_len = modem_packet->len; + packet_interface = modem_packet->interface; + read_len[packet_interface] = modem_packet->len; last_rssi = modem_packet->rssi; last_snr_raw = modem_packet->snr_raw; - packet_interface = modem_packet->interface; memcpy(&pbuf, modem_packet->data, modem_packet->len); free(modem_packet); modem_packet = NULL; @@ -1334,11 +1336,11 @@ void loop() { #elif MCU_VARIANT == MCU_NRF52 modem_packet_t *modem_packet = NULL; if(modem_packet_queue && xQueueReceive(modem_packet_queue, &modem_packet, 0) == pdTRUE && modem_packet) { - memcpy(&pbuf, modem_packet->data, modem_packet->len); - read_len = modem_packet->len; + packet_interface = modem_packet->interface; + read_len[packet_interface] = modem_packet->len; last_rssi = modem_packet->rssi; last_snr_raw = modem_packet->snr_raw; - packet_interface = modem_packet->interface; + memcpy(&pbuf, modem_packet->data, modem_packet->len); free(modem_packet); modem_packet = NULL; From 58fdc627225fb3e8c27f037c04d220c7765585d6 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 23 Oct 2024 08:35:11 +0100 Subject: [PATCH 13/14] Enlarge BLE transmission buffer to support split packets --- Bluetooth.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Bluetooth.h b/Bluetooth.h index 60cf86a..57bae7c 100644 --- a/Bluetooth.h +++ b/Bluetooth.h @@ -29,7 +29,8 @@ #elif MCU_VARIANT == MCU_NRF52 #include #include - BLEUart SerialBT; + #define BLE_MTU 512+3 + BLEUart SerialBT(BLE_MTU); BLEDis bledis; BLEBas blebas; bool SerialBT_init = false; @@ -436,7 +437,7 @@ char bt_devname[11]; cable_state = CABLE_STATE_DISCONNECTED; BLEConnection* conn = Bluefruit.Connection(conn_handle); conn->requestPHY(BLE_GAP_PHY_2MBPS); - conn->requestMtuExchange(512+3); + conn->requestMtuExchange(BLE_MTU); conn->requestDataLengthUpdate(); } From 629abbc3c06cfb4c367c6233626c118e9beded80 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 23 Oct 2024 11:15:39 +0100 Subject: [PATCH 14/14] openCom XL - Adjust TX power PA curve --- Radio.cpp | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Radio.cpp b/Radio.cpp index 964edae..5693b52 100644 --- a/Radio.cpp +++ b/Radio.cpp @@ -2258,74 +2258,74 @@ void sx128x::setTxPower(int level, int outputPin) { reg_value = -18; break; case 1: - reg_value = -17; - break; - case 2: reg_value = -16; break; - case 3: + case 2: reg_value = -15; break; - case 4: + case 3: reg_value = -14; break; - case 5: + case 4: reg_value = -13; break; - case 6: + case 5: reg_value = -12; break; - case 7: - reg_value = -10; + case 6: + reg_value = -11; break; - case 8: + case 7: reg_value = -9; break; - case 9: + case 8: reg_value = -8; break; - case 10: + case 9: reg_value = -7; break; - case 11: + case 10: reg_value = -6; break; - case 12: + case 11: reg_value = -5; break; - case 13: + case 12: reg_value = -4; break; - case 14: + case 13: reg_value = -3; break; - case 15: + case 14: reg_value = -2; break; - case 16: + case 15: reg_value = -1; break; - case 17: + case 16: reg_value = 0; break; - case 18: + case 17: reg_value = 1; break; - case 19: + case 18: reg_value = 2; break; - case 20: + case 19: reg_value = 3; break; - case 21: + case 20: reg_value = 4; break; - case 22: + case 21: reg_value = 5; break; - case 23: + case 22: reg_value = 6; break; + case 23: + reg_value = 7; + break; case 24: reg_value = 8; break;