Skip to content

Commit

Permalink
write gpsd_in altitude to receiver.json
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed May 18, 2024
1 parent 2d8defe commit 4e00217
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions json_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,11 @@ struct char_buffer generateReceiverJson() {
"\"lon\": %.6f",
Modes.fUserLat, Modes.fUserLon); // exact location
}
if (Modes.fUserAlt > -1e6) {
p = safe_snprintf(p, end,
", \"alt_m_amsl\": %.0f",
Modes.fUserAlt);
}
}

p = safe_snprintf(p, end, ", \"jaeroTimeout\": %.1f", ((double) Modes.trackExpireJaero) / (60 * SECONDS));
Expand Down
19 changes: 18 additions & 1 deletion net_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -3589,6 +3589,7 @@ static int handle_gpsd(struct client *c, char *p, int remote, int64_t now, struc
// filter all messages which don't have lat / lon
char *latp = strstr(p, "\"lat\":");
char *lonp = strstr(p, "\"lon\":");
char *altp = strstr(p, "\"alt\":");
if (!latp || !lonp) {
if (Modes.debug_gps) {
fprintf(stderr, "gpsdebug: lat / lon not present: ignoring message.\n");
Expand All @@ -3600,13 +3601,26 @@ static int handle_gpsd(struct client *c, char *p, int remote, int64_t now, struc

char *saveptr = NULL;
strtok_r(latp, ",", &saveptr);
saveptr = NULL;
strtok_r(lonp, ",", &saveptr);

double lat = strtod(latp, NULL);
double lon = strtod(lonp, NULL);

double alt_m = -2e6;
if (altp) {
altp += 6;
saveptr = NULL;
strtok_r(altp, ",", &saveptr);
alt_m = strtod(altp, NULL);
}

if (Modes.debug_gps) {
fprintf(stderr, "gpsdebug: parsed lat,lon: %11.6f,%11.6f\n", lat, lon);
if (alt_m > -1e6) {
fprintf(stderr, "gpsdebug: parsed lat,lon: %11.6f,%11.6f (alt: %.0f m)\n", lat, lon, alt_m);
} else {
fprintf(stderr, "gpsdebug: parsed lat,lon: %11.6f,%11.6f (no alt)\n", lat, lon);
}
}
//fprintf(stderr, "%11.6f %11.6f\n", lat, lon);

Expand All @@ -3630,6 +3644,9 @@ static int handle_gpsd(struct client *c, char *p, int remote, int64_t now, struc

Modes.fUserLat = lat;
Modes.fUserLon = lon;
if (alt_m > -1e6) {
Modes.fUserAlt = alt_m;
}
Modes.userLocationValid = 1;

if (Modes.json_dir) {
Expand Down
2 changes: 2 additions & 0 deletions readsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ static void configSetDefaults(void) {
Modes.acasFD2 = -1; // set to -1 so it's clear we don't have that fd
Modes.sbsOverrideSquawk = -1;

Modes.fUserAlt = -2e6;

Modes.enable_zstd = 1;

Modes.currentTask = "unset";
Expand Down
1 change: 1 addition & 0 deletions readsb.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ struct _Modes
int32_t net_output_flush_interval_beast_reduce; // Maximum interval (in milliseconds) between outputwrites
double fUserLat; // Users receiver/antenna lat/lon needed for initial surface location
double fUserLon; // Users receiver/antenna lat/lon needed for initial surface location
double fUserAlt; // receiver altitude AMSL in meters
double maxRange; // Absolute maximum decoding range, in *metres*
char *latString;
char *lonString;
Expand Down

0 comments on commit 4e00217

Please sign in to comment.