Skip to content

Commit 00fbe52

Browse files
Tune the GPS JSON status
1 parent c6b1293 commit 00fbe52

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

hc_http.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,19 @@ static const char *hc_http_status (const char *method, const char *uri,
7575
status_db->longitude, status_db->hemisphere[1]);
7676

7777
snprintf (buffer, sizeof(buffer),
78-
"{\"gps\":{\"fix\":%s,\"time\":\"%s\",\"date\":\"%s\""
79-
",\"latitude\":%s,\"longitude\":%s}}",
78+
"{\"gps\":{\"fix\":%s"
79+
",\"time\":[%c%c,%c%c,%c%c],\"date\":[%d,%c%c,%c%c]"
80+
",\"latitude\":%s,\"longitude\":%s,\"timestamp\":%zd.%03d}}",
8081
status_db->fix?"true":"false",
81-
status_db->time, status_db->date,
82-
latitude, longitude);
82+
status_db->time[0], status_db->time[1],
83+
status_db->time[2], status_db->time[3],
84+
status_db->time[4], status_db->time[5],
85+
2000 + (status_db->date[4]-'0')*10 + (status_db->date[5]-'0'),
86+
status_db->date[2], status_db->date[3],
87+
status_db->date[0], status_db->date[1],
88+
latitude, longitude,
89+
(size_t) (status_db->timestamp.tv_sec),
90+
status_db->timestamp.tv_usec/1000);
8391
echttp_content_type_json();
8492
return buffer;
8593
}

hc_nmea.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,9 @@ static void hc_nmea_record (const char *sentence,
315315
decoded->flags = 0;
316316
}
317317

318-
static void hc_nmea_mark (int flags) {
318+
static void hc_nmea_mark (int flags, const struct timeval *timestamp) {
319319
gpsHistory[gpsLatest].flags = flags;
320+
hc_nmea_status_db->timestamp = *timestamp;
320321
}
321322

322323
static void hc_nmea_store_position (char **fields) {
@@ -491,7 +492,7 @@ int hc_nmea_process (const struct timeval *received) {
491492

492493
flags |= hc_nmea_decode (gpsBuffer+start);
493494

494-
hc_nmea_mark (flags);
495+
hc_nmea_mark (flags, &bursttiming);
495496

496497
if (hc_nmea_ready(flags)) {
497498
struct timeval gmt;

hc_nmea.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef struct {
3636
char latitude[20];
3737
char longitude[20];
3838
char hemisphere[2];
39+
struct timeval timestamp;
3940
} hc_nmea_status;
4041

4142
void hc_nmea_convert (char *buffer, int size,

0 commit comments

Comments
 (0)