json: optional JSON version output, global or local define

pull/37/head
Zilog80 2021-01-31 20:28:34 +01:00
rodzic 004d1a3663
commit 048080374e
12 zmienionych plików z 192 dodań i 5 usunięć

Wyświetl plik

@ -11,6 +11,17 @@
#include <complex.h>
#include <math.h>
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
typedef unsigned char ui8_t;
static int option_verbose = 0,
@ -325,6 +336,7 @@ static void printGPX() {
static void printJSON() {
// UTC or GPS time ?
char *ver_jsn = NULL;
char json_sonde_id[] = "C50-xxxx\0\0\0\0\0\0\0";
if (gpx.sn) {
sprintf(json_sonde_id, "C50-%u", gpx.sn);
@ -340,6 +352,10 @@ static void printJSON() {
if (gpx.jsn_freq > 0) {
printf(", \"freq\": %d", gpx.jsn_freq);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') printf(", \"version\": \"%s\"", ver_jsn);
printf(" }\n");
//printf("\n");
}

Wyświetl plik

@ -20,6 +20,16 @@
#include <io.h>
#endif
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
#include "demod_mod.h"
@ -781,6 +791,7 @@ static void print_gpx(gpx_t *gpx) {
if (gpx->option.jsn && jsonout && gpx->sek < 60.0)
{
char *ver_jsn = NULL;
unsigned long sec_gps = 0;
int week = 0;
int tow = 0;
@ -814,6 +825,10 @@ static void print_gpx(gpx_t *gpx) {
if (gpx->jsn_freq > 0) {
printf(", \"freq\": %d", gpx->jsn_freq);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') printf(", \"version\": \"%s\"", ver_jsn);
printf(" }\n");
printf("\n");
}

Wyświetl plik

@ -20,6 +20,17 @@
#include <io.h>
#endif
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
//typedef unsigned char ui8_t;
//typedef unsigned short ui16_t;
//typedef unsigned int ui32_t;
@ -431,6 +442,7 @@ static int print_position(gpx_t *gpx, int len, int ecc_frm, int ecc_gps) {
// prnGPS,prnTPU
if (gpx->option.jsn && frm_ok && (gpx->status&0x30)==0x30) {
char *ver_jsn = NULL;
unsigned long count_day = (unsigned long)(gpx->std*3600 + gpx->min*60 + gpx->sek+0.5); // (gpx->timems/1e3+0.5) has gaps
fprintf(stdout, "{ \"type\": \"%s\"", "IMET5");
fprintf(stdout, ", \"frame\": %lu", count_day);
@ -448,6 +460,10 @@ static int print_position(gpx_t *gpx, int len, int ecc_frm, int ecc_gps) {
if (gpx->jsn_freq > 0) {
fprintf(stdout, ", \"freq\": %d", gpx->jsn_freq);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') fprintf(stdout, ", \"version\": \"%s\"", ver_jsn);
fprintf(stdout, " }\n");
fprintf(stdout, "\n");
}

Wyświetl plik

@ -35,6 +35,16 @@
#include <io.h>
#endif
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
//typedef unsigned char ui8_t;
//typedef unsigned short ui16_t;
@ -752,6 +762,7 @@ static void print_frame(gpx_t *gpx, int crc_err, int len) {
// Print JSON output required by auto_rx.
if (crc_err==0) { // CRC-OK
// UTC oder GPS?
char *ver_jsn = NULL;
char sntyp[] = "LMS6-";
if (gpx->typ == 10) sntyp[3] = 'X';
printf("{ \"type\": \"%s\"", "LMS");
@ -764,6 +775,10 @@ static void print_frame(gpx_t *gpx, int crc_err, int len) {
if (gpx->jsn_freq > 0) {
printf(", \"freq\": %d", gpx->jsn_freq);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') printf(", \"version\": \"%s\"", ver_jsn);
printf(" }\n");
printf("\n");
}

Wyświetl plik

@ -20,6 +20,16 @@
#include <io.h>
#endif
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
#include "demod_mod.h"
@ -955,6 +965,7 @@ static int print_pos(gpx_t *gpx, int csOK) {
if (gpx->option.jsn) {
// Print out telemetry data as JSON
if (csOK) {
char *ver_jsn = NULL;
int j;
char sn_id[4+12] = "M10-";
ui8_t aprs_id[4];
@ -1012,6 +1023,10 @@ static int print_pos(gpx_t *gpx, int csOK) {
if (gpx->jsn_freq > 0) {
fprintf(stdout, ", \"freq\": %d", gpx->jsn_freq);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') fprintf(stdout, ", \"version\": \"%s\"", ver_jsn);
fprintf(stdout, " }\n");
fprintf(stdout, "\n");
}

Wyświetl plik

@ -27,6 +27,16 @@
#include <io.h>
#endif
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
#include "demod_mod.h"
@ -635,6 +645,7 @@ static int print_pos(gpx_t *gpx, int bcOK, int csOK) {
if (gpx->option.jsn) {
// Print out telemetry data as JSON
if (csOK) {
char *ver_jsn = NULL;
int j;
char sn_id[4+12] = "M20-";
double sec_gps0 = (double)gpx->week*SECONDS_IN_WEEK + gpx->tow_ms/1e3;
@ -652,6 +663,10 @@ static int print_pos(gpx_t *gpx, int bcOK, int csOK) {
if (gpx->jsn_freq > 0) {
fprintf(stdout, ", \"freq\": %d", gpx->jsn_freq);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') fprintf(stdout, ", \"version\": \"%s\"", ver_jsn);
fprintf(stdout, " }\n");
fprintf(stdout, "\n");
}

Wyświetl plik

@ -102,6 +102,17 @@ e.g. -b --br 2398
#include <io.h>
#endif
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
//typedef unsigned char ui8_t;
//typedef unsigned short ui16_t;
//typedef unsigned int ui32_t;
@ -911,6 +922,7 @@ int main(int argc, char **argv) {
printf("\n");
if (option_jsn && err_frm==0 && gps_err==0) {
char *ver_jsn = NULL;
char id_str[] = "xxxxxx\0\0\0\0\0\0";
if (gpx.sn > 0 && gpx.sn < 1e9) {
sprintf(id_str, "%.0f", gpx.sn);
@ -922,6 +934,10 @@ int main(int argc, char **argv) {
if (gpx.jsn_freq > 0) { // not gpx.fq, because gpx.sn not in every frame
printf(", \"freq\": %d", gpx.jsn_freq);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') printf(", \"version\": \"%s\"", ver_jsn);
printf(" }\n");
printf("\n");
}

Wyświetl plik

@ -25,6 +25,17 @@
#include <io.h>
#endif
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
//typedef unsigned char ui8_t;
//typedef unsigned short ui16_t;
//typedef unsigned int ui32_t;
@ -1801,6 +1812,7 @@ static int print_position(gpx_t *gpx, int ec) {
// Print out telemetry data as JSON
if ((!err && !err1 && !err3) || (!err && encrypted)) { // frame-nb/id && gps-time && gps-position (crc-)ok; 3 CRCs, RS not needed
// eigentlich GPS, d.h. UTC = GPS - 18sec (ab 1.1.2017)
char *ver_jsn = NULL;
fprintf(stdout, "{ \"type\": \"%s\"", "RS41");
fprintf(stdout, ", \"frame\": %d, \"id\": \"%s\", \"datetime\": \"%04d-%02d-%02dT%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f, \"vel_h\": %.5f, \"heading\": %.5f, \"vel_v\": %.5f, \"sats\": %d, \"bt\": %d, \"batt\": %.2f",
gpx->frnr, gpx->id, gpx->jahr, gpx->monat, gpx->tag, gpx->std, gpx->min, gpx->sek, gpx->lat, gpx->lon, gpx->alt, gpx->vH, gpx->vD, gpx->vV, gpx->numSV, gpx->conf_cd, gpx->batt );
@ -1833,6 +1845,10 @@ static int print_position(gpx_t *gpx, int ec) {
if (gpx->freq > 0) fq_kHz = gpx->freq;
fprintf(stdout, ", \"freq\": %d", fq_kHz);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') fprintf(stdout, ", \"version\": \"%s\"", ver_jsn);
fprintf(stdout, " }\n");
fprintf(stdout, "\n");
}

Wyświetl plik

@ -25,6 +25,16 @@
#include <io.h>
#endif
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
//typedef unsigned char ui8_t;
//typedef unsigned short ui16_t;
@ -1178,6 +1188,7 @@ static int print_position(gpx_t *gpx, int ec) { // GPS-Hoehe ueber Ellipsoid
// Print out telemetry data as JSON //even if we don't have a valid GPS lock
if ((gpx->crc & (crc_FRAME | crc_GPS))==0 && (gpx->gps.almanac || gpx->gps.ephem)) //(!err1 && !err3)
{ // eigentlich GPS, d.h. UTC = GPS - UTC_OFS (UTC_OFS=18sec ab 1.1.2017)
char *ver_jsn = NULL;
fprintf(stdout, "\n");
fprintf(stdout, "{ \"type\": \"%s\"", "RS92");
fprintf(stdout, ", \"frame\": %d, \"id\": \"%s\", \"datetime\": \"%04d-%02d-%02dT%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f, \"vel_h\": %.5f, \"heading\": %.5f, \"vel_v\": %.5f",
@ -1190,6 +1201,10 @@ static int print_position(gpx_t *gpx, int ec) { // GPS-Hoehe ueber Ellipsoid
//if (gpx->freq > 0) fq_kHz = gpx->freq; // L-band: option.ngp ?
fprintf(stdout, ", \"freq\": %d", fq_kHz);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') fprintf(stdout, ", \"version\": \"%s\"", ver_jsn);
fprintf(stdout, " }\n");
}
}

Wyświetl plik

@ -0,0 +1,18 @@
#ifndef VERSION_JSN_H
#define VERSION_JSN_H
/*
compile options
(a) -DVERSION_JSN [-I<inc_dir>] (set global)
(b) -DVER_JSN_STR=\"0.0.2\" (set local)
*/
// e.g. global option (a)
// #define VER_JSN_STR "0.0.1"
#define VER_JSN_STR ""
#endif /* VERSION_JSN_H */

Wyświetl plik

@ -10,6 +10,17 @@
#include <complex.h>
#include <math.h>
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
typedef unsigned char ui8_t;
int option_verbose = 0, // ausfuehrliche Anzeige
@ -429,15 +440,19 @@ int print_frame(int len) {
if (option_json) {
if (gpx.gps_valid && gpx.ptu_valid) // frameNb part of PTU-pck
{
char *ver_jsn = NULL;
fprintf(stdout, "{ \"type\": \"%s\"", "IMET");
fprintf(stdout, ", \"frame\": %d, \"id\": \"iMet\", \"datetime\": \"%02d:%02d:%02dZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %d, \"sats\": %d, \"temp\": %.2f, \"humidity\": %.2f, \"pressure\": %.2f, \"batt\": %.1f",
gpx.frame, gpx.hour, gpx.min, gpx.sec, gpx.lat, gpx.lon, gpx.alt, gpx.sats, gpx.temp, gpx.humidity, gpx.pressure, gpx.batt);
if (gpx.jsn_freq > 0) {
fprintf(stdout, ", \"freq\": %d", gpx.jsn_freq);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') fprintf(stdout, ", \"version\": \"%s\"", ver_jsn);
fprintf(stdout, " }\n");
}
if (gpx.jsn_freq > 0) {
fprintf(stdout, ", \"freq\": %d", gpx.jsn_freq);
}
fprintf(stdout, " }\n");
}
if (out) fprintf(stdout, "\n");

Wyświetl plik

@ -9,6 +9,16 @@
#include <string.h>
#include <math.h>
// optional JSON "version"
// (a) set global
// gcc -DVERSION_JSN [-I<inc_dir>] ...
#ifdef VERSION_JSN
#include "version_jsn.h"
#endif
// or
// (b) set local compiler option, e.g.
// gcc -DVER_JSN_STR=\"0.0.2\" ...
typedef unsigned char ui8_t;
typedef unsigned short ui16_t;
@ -639,6 +649,7 @@ void print_frame(int len) {
if (crc_err==0 && (gpx.id & 0xFFFF0000)) { // CRC-OK and FullID
if (gpx.prev_frnr != gpx.frnr) { //|| gpx.id != _id0
// UTC oder GPS?
char *ver_jsn = NULL;
printf("{ \"type\": \"%s\"", "LMS");
printf(", \"frame\": %d, \"id\": \"LMS6-%d\", \"datetime\": \"%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f, \"vel_h\": %.5f, \"heading\": %.5f, \"vel_v\": %.5f",
gpx.frnr, gpx.id, gpx.std, gpx.min, gpx.sek, gpx.lat, gpx.lon, gpx.alt, gpx.vH, gpx.vD, gpx.vV );
@ -646,6 +657,10 @@ void print_frame(int len) {
if (gpx.jsn_freq > 0) {
printf(", \"freq\": %d", gpx.jsn_freq);
}
#ifdef VER_JSN_STR
ver_jsn = VER_JSN_STR;
#endif
if (ver_jsn && *ver_jsn != '\0') printf(", \"version\": \"%s\"", ver_jsn);
printf(" }\n");
printf("\n");
gpx.prev_frnr = gpx.frnr;