Skip to content

Commit

Permalink
Tune the amount of information returned in the web API
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fb-martin committed Dec 2, 2019
1 parent f605c14 commit 1af711e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
13 changes: 13 additions & 0 deletions hc_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
* void *hc_db_get (const char *name);
*
* Access the data for the specified table.
*
* int hc_db_get_space (void);
* int hc_db_get_used (void);
*
* Get information about shared memory usage.
*/

#include <sys/mman.h>
Expand Down Expand Up @@ -158,3 +163,11 @@ void *hc_db_get (const char *name) {
return 0;
}

int hc_db_get_space (void) {
return hc_db->size;
}

int hc_db_get_used (void) {
return hc_db->used;
}

3 changes: 3 additions & 0 deletions hc_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ int hc_db_get_count (const char *name);

void *hc_db_get (const char *name);

int hc_db_get_space (void);
int hc_db_get_used (void);

10 changes: 5 additions & 5 deletions hc_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ static const char *hc_http_status (const char *method, const char *uri,
",\"timestamp\":%zd.%03d}"
",\"learn\":{\"count\":%d,\"accumulator\":%d}"
",\"ntp\":{\"mode\":\"%c\",\"received\":%d,\"processed\":%d"
",\"broadcast\":%d}}",
",\"broadcast\":%d}"
",\"mem\":{\"space\":%d,\"used\":%d}}",
nmea_db->fix?"true":"false",
(unsigned int)nmea_db->fixtime,
nmea_db->gpstime,
Expand All @@ -162,7 +163,8 @@ static const char *hc_http_status (const char *method, const char *uri,
ntp_db->mode,
ntp_db->latest.received,
ntp_db->latest.client,
ntp_db->latest.broadcast);
ntp_db->latest.broadcast,
hc_db_get_space(), hc_db_get_used());

echttp_content_type_json();
return JsonBuffer;
Expand Down Expand Up @@ -254,11 +256,9 @@ static const char *hc_http_ntpclients (const char *method, const char *uri,
+ ((ntp_db->clients[i].local.tv_usec
- ntp_db->clients[i].origin.tv_usec) / 1000);
snprintf (buffer, sizeof(buffer),
"%s{\"address\":\"%s\",\"origin\":%d.%03d,\"local\":%d.%03d,\"delta\":%d}",
"%s{\"address\":\"%s\",\"timestamp\":%d.%03d,\"delta\":%d}",
prefix,
hc_broadcast_format(&(ntp_db->clients[i].address)),
ntp_db->clients[i].origin.tv_sec,
ntp_db->clients[i].origin.tv_usec / 1000,
ntp_db->clients[i].local.tv_sec,
ntp_db->clients[i].local.tv_usec / 1000, delta);
strcat (JsonBuffer, buffer);
Expand Down
2 changes: 1 addition & 1 deletion hc_ntp.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int hc_ntp_initialize (int argc, const char **argv);
void hc_ntp_process (const struct timeval *receive);
void hc_ntp_periodic (const struct timeval *now);

#define HC_NTP_DEPTH 60
#define HC_NTP_DEPTH 128
#define HC_NTP_POOL 4
#define HC_NTP_STATUS "NtpStatus"

Expand Down

0 comments on commit 1af711e

Please sign in to comment.