diff --git a/dump1090.c b/dump1090.c index 0039085..8c0ebc6 100644 --- a/dump1090.c +++ b/dump1090.c @@ -713,6 +713,7 @@ void backgroundTasks(void) { if ((Modes.json_dir || Modes.net_http_port) && now >= next_history) { char filebuf[PATH_MAX]; + int rewrite_receiver_json = (Modes.json_aircraft_history[HISTORY_SIZE-1].content == NULL); free(Modes.json_aircraft_history[Modes.json_aircraft_history_next].content); // might be NULL, that's OK. Modes.json_aircraft_history[Modes.json_aircraft_history_next].content = @@ -722,6 +723,10 @@ void backgroundTasks(void) { writeJsonToFile(filebuf, generateHistoryJson); Modes.json_aircraft_history_next = (Modes.json_aircraft_history_next+1) % HISTORY_SIZE; + + if (rewrite_receiver_json) + writeJsonToFile("receiver.json", generateReceiverJson); // number of history entries changed + next_history = now + HISTORY_INTERVAL; } } @@ -977,7 +982,7 @@ int main(int argc, char **argv) { } if (Modes.net) modesInitNet(); - writeJsonToFile("receiver.json", generateReceiverJson); // once only on startup + writeJsonToFile("receiver.json", generateReceiverJson); // once on startup // If the user specifies --net-only, just run in order to serve network // clients without reading data from the RTL device diff --git a/net_io.c b/net_io.c index f9bbc0f..d0719fe 100644 --- a/net_io.c +++ b/net_io.c @@ -737,14 +737,21 @@ char *generateAircraftJson(const char *url_path, int *len) { char *generateReceiverJson(const char *url_path, int *len) { char *buf = (char *) malloc(1024), *p = buf; + int history_size; (void)url_path; // unused + // work out number of valid history entries + if (Modes.json_aircraft_history[HISTORY_SIZE-1].content == NULL) + history_size = Modes.json_aircraft_history_next; + else + history_size = HISTORY_SIZE; + p += sprintf(p, "{ " \ "\"version\" : \"%s\", " "\"refresh\" : %d, " "\"history\" : %d", - MODES_DUMP1090_VERSION, Modes.json_interval * 1000, HISTORY_SIZE); + MODES_DUMP1090_VERSION, Modes.json_interval * 1000, history_size); if (Modes.json_location_accuracy && (Modes.fUserLat != 0.0 || Modes.fUserLon != 0.0)) { if (Modes.json_location_accuracy == 1) {