From a33808cb336fbfca84b31827befe07ffcffa7ff9 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 23 Feb 2016 16:30:30 -0800 Subject: [PATCH] Fix stats counting overflow. --- adsbus/packet.h | 2 +- adsbus/stats.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/adsbus/packet.h b/adsbus/packet.h index 07bd8a6..5c75e7f 100644 --- a/adsbus/packet.h +++ b/adsbus/packet.h @@ -10,7 +10,7 @@ struct packet { PACKET_TYPE_MODE_S_SHORT, PACKET_TYPE_MODE_S_LONG, } type; - #define NUM_TYPES 2 + #define NUM_TYPES 3 uint8_t payload[PACKET_DATA_LEN_MAX]; uint64_t mlat_timestamp; uint32_t rssi; diff --git a/adsbus/stats.c b/adsbus/stats.c index b0bce6e..eb49ee2 100644 --- a/adsbus/stats.c +++ b/adsbus/stats.c @@ -15,7 +15,7 @@ static struct stats_state { } stats_state = { 0 }; void stats_init() { - assert(clock_gettime(CLOCK_MONOTONIC, &stats_state.start) == 0); + assert(!clock_gettime(CLOCK_MONOTONIC_COARSE, &stats_state.start)); } void stats_serialize(struct packet *packet, struct buf *buf) { @@ -28,10 +28,13 @@ void stats_serialize(struct packet *packet, struct buf *buf) { } json_t *counts = json_object(); for (int i = 0; i < NUM_TYPES; i++) { + if (i == PACKET_TYPE_NONE) { + continue; + } json_object_set_new(counts, packet_type_names[i], json_integer(stats_state.type_count[i])); } struct timespec now; - assert(clock_gettime(CLOCK_MONOTONIC_COARSE, &now) == 0); + assert(!clock_gettime(CLOCK_MONOTONIC_COARSE, &now)); json_t *out = json_pack("{sIso}", "uptime_seconds", (json_int_t) (now.tv_sec - stats_state.start.tv_sec), "packet_counts", counts);