From eb09fe01d7e630daa689aa7ecb2d253b2bc19aa4 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Wed, 26 Sep 2012 08:42:19 +0200 Subject: [PATCH] phc2sys: refactor and rationalize the output messages. Signed-off-by: Richard Cochran --- phc2sys.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/phc2sys.c b/phc2sys.c index 81eaeef..1e406ba 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -126,14 +126,18 @@ struct servo { static struct servo servo; +static void show_servo(FILE *fp, const char *label, int64_t offset, uint64_t ts) +{ + fprintf(fp, "%s %9lld s%d %lld.%09llu drift %.2f\n", label, offset, + servo.state, ts / NS_PER_SEC, ts % NS_PER_SEC, servo.drift); + fflush(fp); +} + static void do_servo(struct servo *srv, clockid_t dst, int64_t offset, uint64_t ts, double kp, double ki) { double ki_term, ppb; - printf("s%d %lld.%09llu drift %.2f\n", - srv->state, ts / NS_PER_SEC, ts % NS_PER_SEC, srv->drift); - switch (srv->state) { case SAMPLE_0: clock_ppb(dst, 0.0); @@ -206,8 +210,8 @@ static int do_pps_loop(char *pps_device, double kp, double ki, clockid_t dst) if (!read_pps(fd, &pps_offset, &pps_ts)) { continue; } - printf("pps %9lld ", pps_offset); do_servo(&servo, dst, pps_offset, pps_ts, kp, ki); + show_servo(stdout, "pps", pps_offset, pps_ts); } close(fd); return 0; @@ -294,8 +298,8 @@ int main(int argc, char *argv[]) if (!read_phc(src, dst, phc_readings, &phc_offset, &phc_ts)) { continue; } - printf("phc %9lld ", phc_offset); do_servo(&servo, dst, phc_offset, phc_ts, kp, ki); + show_servo(stdout, "phc", phc_offset, phc_ts); } return 0; }