GPS receivers may not provide all possible data, some take more time
and some are irrelevant for some applications and are never sent by
some GPS receivers (eg. equipment found in maritime context doesn't
report elevation). Only populate attributes for which data is actually
available.
Signed-off-by: Daniel Golle <[email protected]>
blob_buf_init(&b, 0);
- if (!stamp.tv_sec) {
+ if (!stamp.tv_sec || !gps_fields) {
blobmsg_add_u8(&b, "signal", 0);
} else {
blobmsg_add_u32(&b, "age", now.tv_sec - stamp.tv_sec);
- blobmsg_add_string(&b, "latitude", latitude);
- blobmsg_add_string(&b, "longitude", longitude);
- blobmsg_add_string(&b, "elevation", elevation);
- blobmsg_add_string(&b, "course", course);
- blobmsg_add_string(&b, "speed", speed);
+ if (gps_fields & GPS_FIELD_LAT)
+ blobmsg_add_string(&b, "latitude", latitude);
+ if (gps_fields & GPS_FIELD_LON)
+ blobmsg_add_string(&b, "longitude", longitude);
+ if (gps_fields & GPS_FIELD_ALT)
+ blobmsg_add_string(&b, "elevation", elevation);
+ if (gps_fields & GPS_FIELD_COG)
+ blobmsg_add_string(&b, "course", course);
+ if (gps_fields & GPS_FIELD_SPD)
+ blobmsg_add_string(&b, "speed", speed);
}
ubus_send_reply(ctx, req, b.head);
static int nmea_bad_time;
char longitude[33] = { 0 }, latitude[33] = { 0 }, course[17] = { 0 }, speed[17] = { 0 }, elevation[17] = { 0 };
int gps_valid = 0;
+char gps_fields = 0;
static void
nmea_txt_cb(void)
snprintf(longitude, sizeof(longitude), "%f", lon);
DEBUG(3, "position: %s %s\n", latitude, longitude);
+ gps_fields |= GPS_FIELD_LAT | GPS_FIELD_LON;
+
gps_timestamp();
}
if (!gps_valid)
return;
strncpy(elevation, nmea_params[9].str, sizeof(elevation));
+ gps_fields |= GPS_FIELD_ALT;
DEBUG(4, "height: %s\n", elevation);
}
return;
strncpy(course, nmea_params[1].str, sizeof(course));
strncpy(speed, nmea_params[7].str, sizeof(speed));
+ gps_fields |= GPS_FIELD_COG | GPS_FIELD_SPD;
DEBUG(4, "course: %s\n", course);
DEBUG(4, "speed: %s\n", speed);
}
extern int nmea_open(char *dev, struct ustream_fd *s, speed_t speed);
extern void gps_timestamp(void);
extern unsigned int adjust_clock;
+extern char gps_fields;
+#define GPS_FIELD_LAT (1<<0)
+#define GPS_FIELD_LON (1<<1)
+#define GPS_FIELD_COG (1<<2)
+#define GPS_FIELD_SPD (1<<3)
+#define GPS_FIELD_ALT (1<<4)
#endif