Skip to content

Commit

Permalink
[Legacy] maintain decoder compatibility with Air V6
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed May 14, 2024
1 parent 0ca5ab0 commit 69b3e96
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
33 changes: 21 additions & 12 deletions software/firmware/source/SoftRF/src/protocol/radio/Legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ void make_key(uint32_t key[4], uint32_t timestamp, uint32_t address) {
}
}

#if USE_AIR_V6

bool legacy_decode(void *legacy_pkt, ufo_t *this_aircraft, ufo_t *fop) {
static bool legacy_v6_decode(void *legacy_pkt, ufo_t *this_aircraft, ufo_t *fop) {

legacy_packet_t *pkt = (legacy_packet_t *) legacy_pkt;
legacy_v6_packet_t *pkt = (legacy_v6_packet_t *) legacy_pkt;

float ref_lat = this_aircraft->latitude;
float ref_lon = this_aircraft->longitude;
Expand All @@ -170,7 +168,7 @@ bool legacy_decode(void *legacy_pkt, ufo_t *this_aircraft, ufo_t *fop) {
make_key(key, timestamp, (pkt->addr << 8) & 0xffffff);
btea((uint32_t *) pkt + 1, -5, key);

for (ndx = 0; ndx < sizeof (legacy_packet_t); ndx++) {
for (ndx = 0; ndx < sizeof (legacy_v6_packet_t); ndx++) {
pkt_parity += parity(*(((unsigned char *) pkt) + ndx));
}
if (pkt_parity % 2) {
Expand Down Expand Up @@ -231,9 +229,16 @@ bool legacy_decode(void *legacy_pkt, ufo_t *this_aircraft, ufo_t *fop) {
return true;
}

#if USE_AIR_V6

bool legacy_decode(void *legacy_pkt, ufo_t *this_aircraft, ufo_t *fop) {

return legacy_v6_decode(legacy_pkt, this_aircraft, fop);
}

size_t legacy_encode(void *legacy_pkt, ufo_t *this_aircraft) {

legacy_packet_t *pkt = (legacy_packet_t *) legacy_pkt;
legacy_v6_packet_t *pkt = (legacy_v6_packet_t *) legacy_pkt;

int ndx;
uint8_t pkt_parity=0;
Expand Down Expand Up @@ -303,13 +308,13 @@ size_t legacy_encode(void *legacy_pkt, ufo_t *this_aircraft) {
pkt->ns[0] = ns; pkt->ns[1] = ns; pkt->ns[2] = ns; pkt->ns[3] = ns;
pkt->ew[0] = ew; pkt->ew[1] = ew; pkt->ew[2] = ew; pkt->ew[3] = ew;

pkt->_unk0 = 0;
pkt->type = 0;
pkt->_unk1 = 0;
pkt->_unk2 = 0;
pkt->_unk3 = 0;
// pkt->_unk4 = 0;

for (ndx = 0; ndx < sizeof (legacy_packet_t); ndx++) {
for (ndx = 0; ndx < sizeof (legacy_v6_packet_t); ndx++) {
pkt_parity += parity(*(((unsigned char *) pkt) + ndx));
}

Expand All @@ -325,7 +330,7 @@ size_t legacy_encode(void *legacy_pkt, ufo_t *this_aircraft) {
#endif
btea((uint32_t *) pkt + 1, 5, key);

return (sizeof(legacy_packet_t));
return (sizeof(legacy_v6_packet_t));
}

#elif USE_AIR_V7
Expand All @@ -336,7 +341,11 @@ size_t legacy_encode(void *legacy_pkt, ufo_t *this_aircraft) {

bool legacy_decode(void *legacy_pkt, ufo_t *this_aircraft, ufo_t *fop) {

legacy_packet_t *pkt = (legacy_packet_t *) legacy_pkt;
legacy_v7_packet_t *pkt = (legacy_v7_packet_t *) legacy_pkt;

if (pkt->type == 0) { /* Air V6 position */
return legacy_v6_decode(legacy_pkt, this_aircraft, fop);
}

/* TODO */

Expand All @@ -345,11 +354,11 @@ bool legacy_decode(void *legacy_pkt, ufo_t *this_aircraft, ufo_t *fop) {

size_t legacy_encode(void *legacy_pkt, ufo_t *this_aircraft) {

legacy_packet_t *pkt = (legacy_packet_t *) legacy_pkt;
legacy_v7_packet_t *pkt = (legacy_v7_packet_t *) legacy_pkt;

/* TODO */

return (sizeof(legacy_packet_t));
return (sizeof(legacy_v7_packet_t));
}

#else
Expand Down
23 changes: 12 additions & 11 deletions software/firmware/source/SoftRF/src/protocol/radio/Legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,12 @@ enum
TX_STATUS_ON
};

#if USE_AIR_V6

typedef struct {
/********************/
unsigned int addr:24;
unsigned int _unk0:4;
unsigned int type:4;
unsigned int addr_type:3;
unsigned int _unk1:1;
// unsigned int magic:8;
/********************/
int vs:10;
unsigned int _unk2:2;
Expand All @@ -159,23 +156,27 @@ typedef struct {
int8_t ns[4];
int8_t ew[4];
/********************/
} __attribute__((packed)) legacy_packet_t;
} __attribute__((packed)) legacy_v6_packet_t;

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

typedef struct {

/* TODO */
/********************/
unsigned int addr:24;
unsigned int type:4;
unsigned int addr_type:3;
unsigned int _unk1:1;
/********************/

/* TBD */
uint32_t stub[5];

} __attribute__((packed)) legacy_packet_t;
} __attribute__((packed)) legacy_v7_packet_t;

#else
#error "Unknown AIR protocol version"
#endif /* USE_AIR_Vx */

bool legacy_decode(void *, ufo_t *, ufo_t *);
size_t legacy_encode(void *, ufo_t *);
Expand Down

0 comments on commit 69b3e96

Please sign in to comment.