Skip to content

Commit

Permalink
Activate ADS-L protocol feature for certain hardware platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed May 20, 2024
1 parent a899600 commit eb15836
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion software/firmware/source/SoftRF/src/platform/CC13XX.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/source/SoftRF/src/platform/ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/source/SoftRF/src/platform/ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/source/SoftRF/src/platform/RP2040.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/source/SoftRF/src/platform/RPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions software/firmware/source/SoftRF/src/platform/STM32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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") */
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/source/SoftRF/src/platform/nRF52.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 42 additions & 9 deletions software/firmware/source/SoftRF/src/protocol/radio/Legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ size_t legacy_encode(void *legacy_pkt, ufo_t *this_aircraft) {

#else
/*
* Volunteer contributors are welcome:
* https://pastebin.com/YB1ppAbt
*/

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down

0 comments on commit eb15836

Please sign in to comment.