diff --git a/software/firmware/source/SoftRF/src/platform/CC13XX.h b/software/firmware/source/SoftRF/src/platform/CC13XX.h index d0d82b41d..e8f9c1849 100644 --- a/software/firmware/source/SoftRF/src/platform/CC13XX.h +++ b/software/firmware/source/SoftRF/src/platform/CC13XX.h @@ -268,7 +268,7 @@ extern SCSerial scSerial; #define USE_OGN_ENCRYPTION -//#define ENABLE_ADSL +#define ENABLE_ADSL //#define EXCLUDE_GNSS_UBLOX #define EXCLUDE_GNSS_SONY diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.h b/software/firmware/source/SoftRF/src/platform/ESP32.h index 94b077b42..6ca8bf1fb 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.h +++ b/software/firmware/source/SoftRF/src/platform/ESP32.h @@ -343,7 +343,7 @@ struct rst_info { //#define USE_GDL90_MSL #define USE_OGN_ENCRYPTION #define ENABLE_PROL -//#define ENABLE_ADSL +#define ENABLE_ADSL //#define EXCLUDE_GNSS_UBLOX /* Neo-6/7/8, M10 */ #define ENABLE_UBLOX_RFS /* revert factory settings (when necessary) */ diff --git a/software/firmware/source/SoftRF/src/platform/ESP8266.h b/software/firmware/source/SoftRF/src/platform/ESP8266.h index 340c779b7..519fe0aec 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP8266.h +++ b/software/firmware/source/SoftRF/src/platform/ESP8266.h @@ -119,7 +119,7 @@ extern Adafruit_NeoPixel strip; #define EXCLUDE_BME680 /* Experimental */ -//#define ENABLE_ADSL +#define ENABLE_ADSL #define ENABLE_PROL #if defined(pgm_read_float_aligned) diff --git a/software/firmware/source/SoftRF/src/platform/RP2040.h b/software/firmware/source/SoftRF/src/platform/RP2040.h index 818a339a0..23532ae36 100644 --- a/software/firmware/source/SoftRF/src/platform/RP2040.h +++ b/software/firmware/source/SoftRF/src/platform/RP2040.h @@ -287,7 +287,7 @@ struct rst_info { //#define EXCLUDE_OLED_BARO_PAGE /* Experimental */ -//#define ENABLE_ADSL +#define ENABLE_ADSL #define ENABLE_PROL #if defined(USE_TINYUSB) //#define USE_USB_HOST diff --git a/software/firmware/source/SoftRF/src/platform/RPi.h b/software/firmware/source/SoftRF/src/platform/RPi.h index 2073409e0..d2b4bf453 100644 --- a/software/firmware/source/SoftRF/src/platform/RPi.h +++ b/software/firmware/source/SoftRF/src/platform/RPi.h @@ -135,7 +135,7 @@ extern const char *Hardware_Rev[]; //#define ENABLE_D1090_INPUT /* Experimental */ -//#define ENABLE_ADSL +#define ENABLE_ADSL //#define ENABLE_PROL //#define USE_OGN_RF_DRIVER diff --git a/software/firmware/source/SoftRF/src/platform/STM32.h b/software/firmware/source/SoftRF/src/platform/STM32.h index 329689b31..d6815be2d 100644 --- a/software/firmware/source/SoftRF/src/platform/STM32.h +++ b/software/firmware/source/SoftRF/src/platform/STM32.h @@ -176,7 +176,7 @@ typedef struct stm32_backup_struct { #define USE_TIME_SLOTS /* Experimental */ -//#define ENABLE_ADSL // + 2 kb +#define ENABLE_ADSL // + 2 kb #define ENABLE_PROL // + 18 kb /* Secondary target ("Blue pill") */ @@ -286,7 +286,7 @@ typedef struct stm32_backup_struct { #define USE_OGN_ENCRYPTION /* Experimental */ -//#define ENABLE_ADSL +#define ENABLE_ADSL #define ENABLE_PROL #elif defined(ARDUINO_WisDuo_RAK3172_Evaluation_Board) diff --git a/software/firmware/source/SoftRF/src/platform/nRF52.h b/software/firmware/source/SoftRF/src/platform/nRF52.h index 69109db5a..4730fc53a 100644 --- a/software/firmware/source/SoftRF/src/platform/nRF52.h +++ b/software/firmware/source/SoftRF/src/platform/nRF52.h @@ -315,7 +315,7 @@ struct rst_info { //#define EXCLUDE_NUS //#define EXCLUDE_IMU #define USE_OGN_ENCRYPTION -//#define ENABLE_ADSL +#define ENABLE_ADSL #define ENABLE_PROL #if !defined(ARDUINO_ARCH_MBED) #define USE_BLE_MIDI diff --git a/software/firmware/source/SoftRF/src/protocol/radio/Legacy.cpp b/software/firmware/source/SoftRF/src/protocol/radio/Legacy.cpp index c38e81ac8..eb1443a48 100644 --- a/software/firmware/source/SoftRF/src/protocol/radio/Legacy.cpp +++ b/software/firmware/source/SoftRF/src/protocol/radio/Legacy.cpp @@ -363,7 +363,6 @@ size_t legacy_encode(void *legacy_pkt, ufo_t *this_aircraft) { #else /* - * Volunteer contributors are welcome: * https://pastebin.com/YB1ppAbt */ @@ -426,6 +425,42 @@ static unsigned int enscale_unsigned(unsigned int value, return (value); } +static unsigned int enscale_signed( signed int value, + unsigned int mbits, + unsigned int ebits) +{ + unsigned int offset = (1 << mbits); + unsigned int signbit = (offset << ebits); + unsigned int max_val = signbit - 1; + unsigned int sign = 0; + + if (value < 0) { + value = -value; + sign = signbit; + } + + unsigned int rval; + if (value >= offset) { + unsigned int e = 0; + unsigned int m = offset + (unsigned int) value; + unsigned int mlimit = offset + offset - 1; + + while (m > mlimit) { + m >>= 1; + e += offset; + if (e > max_val) { + return (sign | max_val); + } + } + m -= offset; + rval = (sign | e | m); + } else { + rval = (sign | (unsigned int) value); + } + + return (rval); +} + bool legacy_decode(void *legacy_pkt, ufo_t *this_aircraft, ufo_t *fop) { const uint32_t xxtea_key[4] = LEGACY_KEY5; uint32_t key_v7[4]; @@ -574,18 +609,16 @@ size_t legacy_encode(void *legacy_pkt, ufo_t *this_aircraft) { pkt->hs = enscale_unsigned(speed10, 8, 2); /* 0 ... 3832 */ int16_t vs10 = (int16_t) roundf(vsf * 10.0f); - if (vs10 > 952) { vs10 = 952; } - if (vs10 < -952) { vs10 = -952; } - if (vs10 < 64 && vs10 > -64) { - pkt->vs = vs10; - } else { - pkt->vs = (vs10 < 0) ? -63 : 63; /* TODO */ - } + pkt->vs = this_aircraft->stealth ? 0 : enscale_signed(vs10, 6, 2); /* 0 ... 952 */ pkt->course = (int) (course * 2); pkt->airborne = ((int) speedf) >= legacy_GS_threshold[acft_type] ? 2 : 1; - /* TODO */ +/* + * TODO + * Volunteer contributors are welcome: + * https://pastebin.com/YB1ppAbt + */ pkt->_unk1 = 0; pkt->_unk2 = 0; pkt->_unk3 = 3; diff --git a/software/firmware/source/SoftRF/src/protocol/radio/Legacy.h b/software/firmware/source/SoftRF/src/protocol/radio/Legacy.h index afa2d48f5..08e819cff 100644 --- a/software/firmware/source/SoftRF/src/protocol/radio/Legacy.h +++ b/software/firmware/source/SoftRF/src/protocol/radio/Legacy.h @@ -187,7 +187,6 @@ typedef struct { /********************/ } __attribute__((packed)) legacy_v7_packet_t; - bool legacy_decode(void *, ufo_t *, ufo_t *); size_t legacy_encode(void *, ufo_t *);