From d758b73346b61c4110535ec3766f3e184c1ac804 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Tue, 31 Dec 2024 17:21:42 +0000 Subject: [PATCH] support non-icao addresses in SBS input/output as in the json, non-icao addresses are prepended with ~ --- net_io.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/net_io.c b/net_io.c index c47ad9f2..c5e4c250 100644 --- a/net_io.c +++ b/net_io.c @@ -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]); @@ -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 @@ -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; @@ -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);