From 3d88ba35dd8958e274199857644b406090094bbc Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 25 May 2018 12:33:30 -0700 Subject: [PATCH] TSCH: keep track of max/min observed drift and log it periodically --- os/net/mac/tsch/tsch-adaptive-timesync.c | 6 +++++- os/net/mac/tsch/tsch.c | 4 ++++ os/net/mac/tsch/tsch.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/os/net/mac/tsch/tsch-adaptive-timesync.c b/os/net/mac/tsch/tsch-adaptive-timesync.c index a23a4f1b0..6508a8752 100644 --- a/os/net/mac/tsch/tsch-adaptive-timesync.c +++ b/os/net/mac/tsch/tsch-adaptive-timesync.c @@ -109,7 +109,9 @@ timesync_learn_drift_ticks(uint32_t time_delta_asn, int32_t drift_ticks) TSCH_LOG_ADD(tsch_log_message, snprintf(log->message, sizeof(log->message), - "drift %ld", tsch_adaptive_timesync_get_drift_ppm())); + "drift %ld (min/max delta seen: %"PRId32"/%"PRId32")", + tsch_adaptive_timesync_get_drift_ppm(), + min_drift_seen, max_drift_seen)); } /*---------------------------------------------------------------------------*/ /* Either reset or update the neighbor's drift */ @@ -136,6 +138,8 @@ tsch_timesync_update(struct tsch_neighbor *n, uint16_t time_delta_asn, int32_t d compensated_ticks += drift_correction; } } + min_drift_seen = MIN(drift_correction, min_drift_seen); + max_drift_seen = MAX(drift_correction, max_drift_seen); } /*---------------------------------------------------------------------------*/ /* Error-accumulation free compensation algorithm */ diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index dea750120..45df20e6f 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -160,6 +160,8 @@ static struct ctimer keepalive_timer; unsigned long tx_count; unsigned long rx_count; unsigned long sync_count; +int32_t min_drift_seen; +int32_t max_drift_seen; /* TSCH processes and protothreads */ PT_THREAD(tsch_scan(struct pt *pt)); @@ -648,6 +650,8 @@ tsch_associate(const struct input_packet *input_eb, rtimer_clock_t timestamp) tx_count = 0; rx_count = 0; sync_count = 0; + min_drift_seen = 0; + max_drift_seen = 0; /* Start sending keep-alives now that tsch_is_associated is set */ tsch_schedule_keepalive(); diff --git a/os/net/mac/tsch/tsch.h b/os/net/mac/tsch/tsch.h index 93b6e0d88..88ebb4db6 100644 --- a/os/net/mac/tsch/tsch.h +++ b/os/net/mac/tsch/tsch.h @@ -175,6 +175,8 @@ extern rtimer_clock_t tsch_timing[tsch_ts_elements_count]; extern unsigned long tx_count; extern unsigned long rx_count; extern unsigned long sync_count; +extern int32_t min_drift_seen; +extern int32_t max_drift_seen; /* TSCH processes */ PROCESS_NAME(tsch_process);