From aa95124d481ff16eb98ba18ddd3aaf03076d3ae4 Mon Sep 17 00:00:00 2001
From: Alessandro Rubini <rubini@gnudd.com>
Date: Thu, 15 Oct 2015 11:44:08 +0200
Subject: [PATCH] gui: print a new status screen whenever the wr servo runs

The gui is timely: it refreshes every that many seconds, but I'd
better see a change immediated when it happens.  This commit
introduces monitoring of the wr-servo update count, so if anything
changed an information scree is dumped.

This is different from stats (two commits ago), because we want to
refresh timely in any case, so the user sees the thing is active.

You can verify the effect of the commit after "refresh 4": timely
refresh is now slower than servo updated and you'll see how gui
updates are synced with the ptp protocol.

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
---
 monitor/monitor_ppsi.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/monitor/monitor_ppsi.c b/monitor/monitor_ppsi.c
index 950c1df0f..7b667bb36 100644
--- a/monitor/monitor_ppsi.c
+++ b/monitor/monitor_ppsi.c
@@ -74,7 +74,8 @@ static int wrc_mon_status(void)
 
 void wrc_mon_gui(void)
 {
-	static uint32_t last;
+	static uint32_t last_jiffies;
+	static uint32_t last_servo_count;
 	struct hal_port_state state;
 	int tx, rx;
 	int aux_stat;
@@ -87,12 +88,14 @@ void wrc_mon_gui(void)
 			&((struct wr_data *)ppi->ext_data)->servo_state;
 	int64_t crtt;
 	int64_t total_asymmetry;
-	if (!last)
-		last = timer_get_tics() - 1 -  wrc_ui_refperiod;
-	if (time_before(timer_get_tics(), last + wrc_ui_refperiod))
-		return;
 
-	last = timer_get_tics();
+	if (!last_jiffies)
+		last_jiffies = timer_get_tics() - 1 -  wrc_ui_refperiod;
+	if (time_before(timer_get_tics(), last_jiffies + wrc_ui_refperiod)
+		&& last_servo_count == s->update_count)
+		return;
+	last_jiffies = timer_get_tics();
+	last_servo_count = s->update_count;
 
 	term_clear();
 
-- 
GitLab