From e387f1291da5993f4918e41760c0a09253a098e6 Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Tue, 8 May 2018 22:23:34 +0300 Subject: [PATCH] build-time address customization --- .../firmware/source/SoftRF/BluetoothHelper.cpp | 15 +++++---------- .../firmware/source/SoftRF/Platform_ESP32.cpp | 4 ++++ .../firmware/source/SoftRF/Platform_ESP8266.cpp | 4 ++++ .../firmware/source/SoftRF/Protocol_FANET.cpp | 2 +- .../firmware/source/SoftRF/Protocol_Legacy.cpp | 7 +++++++ software/firmware/source/SoftRF/WebHelper.cpp | 6 +++++- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/software/firmware/source/SoftRF/BluetoothHelper.cpp b/software/firmware/source/SoftRF/BluetoothHelper.cpp index 9707cffd7..d64a8790c 100644 --- a/software/firmware/source/SoftRF/BluetoothHelper.cpp +++ b/software/firmware/source/SoftRF/BluetoothHelper.cpp @@ -75,33 +75,28 @@ class MyCallbacks: public BLECharacteristicCallbacks { std::string rxValue = pCharacteristic->getValue(); if (rxValue.length() > 0) { -#if 0 - Serial.println("*********"); - Serial.print("Received Value: "); - for (int i = 0; i < rxValue.length(); i++) - Serial.print(rxValue[i]); - - Serial.println(); - Serial.println("*********"); -#else BLE_FIFO_RX->write(rxValue.c_str(), (BLE_FIFO_RX->room() > rxValue.length() ? rxValue.length() : BLE_FIFO_RX->room())); -#endif } } }; static void ESP32_Bluetooth_setup() { +#if !defined(SOFTRF_ADDRESS) union { uint8_t efuse_mac[6]; uint64_t chipmacid; }; chipmacid = ESP.getEfuseMac(); + BT_name += String((uint32_t) efuse_mac[5] | (efuse_mac[4] << 8) | \ (efuse_mac[3] << 16), HEX); +#else + BT_name += String(SOFTRF_ADDRESS & 0x00FFFFFFU, HEX); +#endif switch(settings->bluetooth) { diff --git a/software/firmware/source/SoftRF/Platform_ESP32.cpp b/software/firmware/source/SoftRF/Platform_ESP32.cpp index 114d51674..4ef856fbe 100644 --- a/software/firmware/source/SoftRF/Platform_ESP32.cpp +++ b/software/firmware/source/SoftRF/Platform_ESP32.cpp @@ -104,6 +104,7 @@ static void ESP32_setup() static uint32_t ESP32_getChipId() { +#if !defined(SOFTRF_ADDRESS) union { uint8_t efuse_mac[6]; uint64_t chipmacid; @@ -112,6 +113,9 @@ static uint32_t ESP32_getChipId() return (uint32_t) efuse_mac[5] | (efuse_mac[4] << 8) | \ (efuse_mac[3] << 16) | (efuse_mac[2] << 24); +#else + return (SOFTRF_ADDRESS & 0xFFFFFFFFU ); +#endif } static uint32_t ESP32_getFlashChipId() diff --git a/software/firmware/source/SoftRF/Platform_ESP8266.cpp b/software/firmware/source/SoftRF/Platform_ESP8266.cpp index 1ff91bb68..9f512e4a6 100644 --- a/software/firmware/source/SoftRF/Platform_ESP8266.cpp +++ b/software/firmware/source/SoftRF/Platform_ESP8266.cpp @@ -59,7 +59,11 @@ static void ESP8266_setup() static uint32_t ESP8266_getChipId() { +#if !defined(SOFTRF_ADDRESS) return ESP.getChipId(); +#else + return (SOFTRF_ADDRESS & 0xFFFFFFFFU ); +#endif } static uint32_t ESP8266_getFlashChipId() diff --git a/software/firmware/source/SoftRF/Protocol_FANET.cpp b/software/firmware/source/SoftRF/Protocol_FANET.cpp index ccc2c68d5..8a4b27603 100644 --- a/software/firmware/source/SoftRF/Protocol_FANET.cpp +++ b/software/firmware/source/SoftRF/Protocol_FANET.cpp @@ -341,7 +341,7 @@ size_t fanet_encode(void *fanet_pkt, ufo_t *this_aircraft) { pkt->heading = constrain((int)roundf(heading * 256.0f)/360.0f, 0, 255); - int turnr4 = constrain((int)roundf(turnrate * 4.0f), 0, 255); + int turnr4 = constrain((int)roundf(turnrate * 4.0f), -255, 255); if(abs(turnr4) > 63) { pkt->turn_scale = 1; pkt->turn_rate = ((turnr4 + (turnr4 >= 0 ? 2 : -2)) / 4); diff --git a/software/firmware/source/SoftRF/Protocol_Legacy.cpp b/software/firmware/source/SoftRF/Protocol_Legacy.cpp index d2e16d224..6fc10d073 100644 --- a/software/firmware/source/SoftRF/Protocol_Legacy.cpp +++ b/software/firmware/source/SoftRF/Protocol_Legacy.cpp @@ -201,7 +201,14 @@ size_t legacy_encode(void *legacy_pkt, ufo_t *this_aircraft) { unsigned int aircraft_type = this_aircraft->aircraft_type; pkt->addr = id & 0x00FFFFFF; + +#if !defined(SOFTRF_ADDRESS) pkt->addr_type = ADDR_TYPE_FLARM; +#else + pkt->addr_type = (pkt->addr == SOFTRF_ADDRESS ? + ADDR_TYPE_ICAO : ADDR_TYPE_FLARM); +#endif + pkt->parity = 0; pkt->vs = 0; pkt->vsmult = 0; diff --git a/software/firmware/source/SoftRF/WebHelper.cpp b/software/firmware/source/SoftRF/WebHelper.cpp index ce1fa486d..554e30121 100644 --- a/software/firmware/source/SoftRF/WebHelper.cpp +++ b/software/firmware/source/SoftRF/WebHelper.cpp @@ -379,7 +379,11 @@ void handleRoot() { \ \ "), - ThisAircraft.addr, SOFTRF_FIRMWARE_VERSION, + ThisAircraft.addr, SOFTRF_FIRMWARE_VERSION +#if defined(SOFTRF_ADDRESS) + "I" +#endif + , (SoC == NULL ? "NONE" : SoC->name), (rf_chip == NULL ? "NONE" : rf_chip->name), (baro_chip == NULL ? "NONE" : baro_chip->name),