Skip to content

Commit

Permalink
support non-icao addresses in SBS input/output
Browse files Browse the repository at this point in the history
as in the json, non-icao addresses are prepended with ~
  • Loading branch information
wiedehopf committed Dec 31, 2024
1 parent f9d7bdd commit d758b73
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions net_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -3077,10 +3077,15 @@ static int decodeSbsLine(struct client *c, char *line, int remote, int64_t now,

mm->sbsMsgType = atoi(t[2]);

if (!t[5] || strlen(t[5]) != 6) // icao must be 6 characters
if (!t[5] || strlen(t[5]) < 6 || strlen(t[5]) > 7) // icao must be 6 characters
goto basestation_invalid;

char *icao = t[5];
int non_icao = 0;
if (icao[0] == '~') {
icao++;
non_icao = 1;
}
unsigned char *chars = (unsigned char *) &(mm->addr);
for (int j = 0; j < 6; j += 2) {
int high = hexDigitVal(icao[j]);
Expand All @@ -3092,6 +3097,10 @@ static int decodeSbsLine(struct client *c, char *line, int remote, int64_t now,
chars[2 - j / 2] = (high << 4) | low;
}

if (non_icao) {
mm->addr |= MODES_NON_ICAO_ADDRESS;
}

//fprintf(stderr, "%x type %s: ", mm->addr, t[2]);
//fprintf(stderr, "%x: %d, %0.5f, %0.5f\n", mm->addr, mm->baro_alt, mm->decoded_lat, mm->decoded_lon);
//field 11, callsign
Expand Down Expand Up @@ -3250,10 +3259,6 @@ static void modesSendSBSOutput(struct modesMessage *mm, struct aircraft *a, stru
struct tm stTime_receive, stTime_now;
int msgType;

// For now, suppress non-ICAO addresses
if (mm->addr & MODES_NON_ICAO_ADDRESS)
return;

p = prepareWrite(writer, 200);
if (!p)
return;
Expand Down Expand Up @@ -3309,7 +3314,7 @@ static void modesSendSBSOutput(struct modesMessage *mm, struct aircraft *a, stru
}

// Fields 1 to 6 : SBS message type and ICAO address of the aircraft and some other stuff
p += sprintf(p, "MSG,%d,1,1,%06X,1,", msgType, mm->addr);
p += sprintf(p, "MSG,%d,1,1,%s%06X,1,", msgType, (a->addr & MODES_NON_ICAO_ADDRESS) ? "~" : "", a->addr & 0xFFFFFF);

// Find current system time
clock_gettime(CLOCK_REALTIME, &now);
Expand Down

0 comments on commit d758b73

Please sign in to comment.