From daebc372a996bd54002b737f6277c96787fa16ac Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Tue, 9 Jan 2018 17:07:47 +0000 Subject: [PATCH] Write a version header on faup1090 startup --- faup1090.c | 1 + net_io.c | 20 ++++++++++++++++++++ net_io.h | 2 ++ 3 files changed, 23 insertions(+) diff --git a/faup1090.c b/faup1090.c index e476a7e..425bc92 100644 --- a/faup1090.c +++ b/faup1090.c @@ -204,6 +204,7 @@ int main(int argc, char **argv) { // Set up output connection on stdout fatsv_output = makeFatsvOutputService(); createGenericClient(fatsv_output, STDOUT_FILENO); + writeFATSVHeader(); // Run it until we've lost either connection while (!Modes.exit && beast_input->connections && fatsv_output->connections) { diff --git a/net_io.c b/net_io.c index 1568022..c0700b8 100644 --- a/net_io.c +++ b/net_io.c @@ -1786,6 +1786,26 @@ __attribute__ ((format (printf,4,5))) static char *appendFATSV(char *p, char *en } #define TSV_MAX_PACKET_SIZE 400 +#define TSV_VERSION 2 + +void writeFATSVHeader() +{ + char *p = prepareWrite(&Modes.fatsv_out, TSV_MAX_PACKET_SIZE); + if (!p) + return; + + char *end = p + TSV_MAX_PACKET_SIZE; + + p = appendFATSV(p, end, "clock", "%" PRIu64, mstime() / 1000); + p = appendFATSV(p, end, "tsvVersion", "%u", TSV_VERSION); + --p; // remove last tab + p = safe_snprintf(p, end, "\n"); + + if (p <= end) + completeWrite(&Modes.fatsv_out, p); + else + fprintf(stderr, "fatsv: output too large (max %d, overran by %d)\n", TSV_MAX_PACKET_SIZE, (int) (p - end)); +} static void writeFATSVPositionUpdate(float lat, float lon, float alt) { diff --git a/net_io.h b/net_io.h index 2c39f6f..0dd3ea8 100644 --- a/net_io.h +++ b/net_io.h @@ -87,6 +87,8 @@ void modesInitNet(void); void modesQueueOutput(struct modesMessage *mm, struct aircraft *a); void modesNetPeriodicWork(void); +void writeFATSVHeader(); + // TODO: move these somewhere else char *generateAircraftJson(const char *url_path, int *len); char *generateStatsJson(const char *url_path, int *len);