diff --git a/src/hk_param_sniffer.c b/src/hk_param_sniffer.c index b0e47b3..3960159 100644 --- a/src/hk_param_sniffer.c +++ b/src/hk_param_sniffer.c @@ -108,8 +108,8 @@ void hk_set_epoch(time_t epoch, uint16_t node, bool auto_sync) { char current_time_str[32]; strftime(current_time_str, sizeof(current_time_str), "%Y-%m-%d %H:%M:%S", gmtime(¤t_epoch)); - /* 1577833200: Jan 1st 2020 */ - if (epoch > current_epoch || epoch < 1577833200) { + /* 1577836800: Jan 1st 2020 */ + if (epoch > current_epoch || epoch < 1577836800) { char current_epoch_str[32]; strftime(current_epoch_str, sizeof(current_epoch_str), "%Y-%m-%d %H:%M:%S", gmtime(&epoch)); printf("At %s: Illegal EPOCH %lu (%s) received\n", current_time_str, current_epoch, current_epoch_str); @@ -238,6 +238,9 @@ bool hk_param_sniffer(csp_packet_t * packet) { if (timesync_nodes.node[i] == node && timesync_nodes.paramid[i] == param->id) { mpack_tag_t tag = mpack_peek_tag(&reader); local_epoch = tag.v.i - timestamp.tv_sec; + if (local_epoch == 0) { + local_epoch = tag.v.i; + } hk_set_epoch(local_epoch, packet->id.src, true); break; } @@ -251,7 +254,10 @@ bool hk_param_sniffer(csp_packet_t * packet) { continue; } - param->timestamp->tv_sec += local_epoch; + /* Only update if not receiving a UTC timestamp. 1577836800: Jan 1st 2020 */ + if (param->timestamp->tv_sec < 1577836800) { + param->timestamp->tv_sec += local_epoch; + } param_sniffer_log(NULL, &queue, param, offset, &reader, param->timestamp); } else { printf("HK: Found unknown param node %d id %d\n", node, id);