Skip to content

Commit

Permalink
write gpsd.json when using gpsd_in
Browse files Browse the repository at this point in the history
for each message with lat / lon received from gpsd, the message is
written as is to gpsd.json
  • Loading branch information
wiedehopf committed May 23, 2024
1 parent 3dc36ea commit d10ae1c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions net_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -3577,6 +3577,12 @@ static int handle_gpsd(struct client *c, char *p, int remote, int64_t now, struc
fprintf(stderr, " gpsdebug: received from GPSD: \'%s\'\n", p);
}

struct char_buffer msg;
msg.alloc = strlen(p) + 128;
msg.buffer = cmalloc(msg.alloc);
sprintf(msg.buffer, "%s\n", p);
msg.len = strlen(msg.buffer);

// remove spaces in place
char *d = p;
char *s = p;
Expand All @@ -3592,7 +3598,7 @@ static int handle_gpsd(struct client *c, char *p, int remote, int64_t now, struc
if (Modes.debug_gps) {
fprintf(stderr, "gpsdebug: class \"TPV\" : ignoring message.\n");
}
return 0;
goto exit;
}
// filter all messages which don't have lat / lon
char *latp = strstr(p, "\"lat\":");
Expand All @@ -3602,7 +3608,7 @@ static int handle_gpsd(struct client *c, char *p, int remote, int64_t now, struc
if (Modes.debug_gps) {
fprintf(stderr, "gpsdebug: lat / lon not present: ignoring message.\n");
}
return 0;
goto exit;
}
latp += 6;
lonp += 6;
Expand Down Expand Up @@ -3637,13 +3643,13 @@ static int handle_gpsd(struct client *c, char *p, int remote, int64_t now, struc
if (Modes.debug_gps) {
fprintf(stderr, "gpsdebug: lat lon implausible, ignoring\n");
}
return 0;
goto exit;
}
if (fabs(lat) < 0.1 && fabs(lon) < 0.1) {
if (Modes.debug_gps) {
fprintf(stderr, "gpsdebug: lat lon implausible, ignoring\n");
}
return 0;
goto exit;
}

if (Modes.debug_gps) {
Expand All @@ -3659,8 +3665,13 @@ static int handle_gpsd(struct client *c, char *p, int remote, int64_t now, struc

if (Modes.json_dir) {
free(writeJsonToFile(Modes.json_dir, "receiver.json", generateReceiverJson()).buffer); // location changed
if (msg.len) {
writeJsonToFile(Modes.json_dir, "gpsd.json", msg);
}
}

exit:
free(msg.buffer);
return 0;
}

Expand Down

0 comments on commit d10ae1c

Please sign in to comment.