Experimental json changes

This commit is contained in:
Oliver Jowett 2014-11-23 16:02:11 +00:00
parent bff92c4ad7
commit 6910a4bf4d
4 changed files with 66 additions and 3 deletions

View file

@ -82,6 +82,7 @@ void modesInitConfig(void) {
Modes.interactive_display_ttl = MODES_INTERACTIVE_DISPLAY_TTL;
Modes.fUserLat = MODES_USER_LATITUDE_DFLT;
Modes.fUserLon = MODES_USER_LONGITUDE_DFLT;
Modes.json_interval = 1;
}
//
//=========================================================================
@ -436,6 +437,8 @@ void showHelp(void) {
"--debug <flags> Debug mode (verbose), see README for details\n"
"--quiet Disable output to stdout. Use for daemon applications\n"
"--ppm <error> Set receiver error in parts per million (default 0)\n"
"--write-json <dir> Periodically write json output to <dir> (for serving by a separate webserver)\n"
"--write-json-every <t> Write json output every t seconds (default 1)\n"
"--help Show this help\n"
"\n"
"Debug mode flags: d = Log frames decoded with errors\n"
@ -571,6 +574,7 @@ static void display_stats(void) {
//
void backgroundTasks(void) {
static time_t next_stats;
static time_t next_json;
if (Modes.net) {
modesReadFromClients();
@ -594,6 +598,14 @@ void backgroundTasks(void) {
next_stats = now + Modes.stats;
}
}
if (Modes.json_path && Modes.json_interval > 0) {
time_t now = time(NULL);
if (now > next_json) {
modesWriteJson(Modes.json_path);
next_json = now + Modes.json_interval;
}
}
}
//
//=========================================================================
@ -778,6 +790,15 @@ int main(int argc, char **argv) {
} else if (!strcmp(argv[j],"--interactive-rtl1090")) {
Modes.interactive = 1;
Modes.interactive_rtl1090 = 1;
#ifndef _WIN32
} else if (!strcmp(argv[j], "--write-json") && more) {
++j;
Modes.json_path = malloc(strlen(argv[j]) + 11);
strcpy(Modes.json_path, argv[j]);
strcat(Modes.json_path, "/aircraft.json");
} else if (!strcmp(argv[j], "--write-json-every") && more) {
Modes.json_interval = atoi(argv[++j]);
#endif
} else {
fprintf(stderr,
"Unknown or not enough arguments for option '%s'.\n\n",