From e39f39a63a649f8de6f06717302c37c493c8e4f0 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 19 Jun 2005 16:47:35 +0000 Subject: Avoid CPU cost for nonworking DCD change detection. --- libgpsd_core.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'libgpsd_core.c') diff --git a/libgpsd_core.c b/libgpsd_core.c index 2a10c312..4b9dc5b8 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -111,7 +111,7 @@ void gpsd_deactivate(struct gps_device_t *session) static void *gpsd_ppsmonitor(void *arg) { struct gps_device_t *session = (struct gps_device_t *)arg; - int cycle,duration, state = 0; + int cycle,duration, state = 0, laststate = -1, unchanged = 0; struct timeval tv; struct timeval pulse[2] = {{0,0},{0,0}}; @@ -124,8 +124,18 @@ static void *gpsd_ppsmonitor(void *arg) /*@ -ignoresigns */ state = (int)((state & TIOCM_CAR) != 0); - gpsd_report(5, "carrier-detect on %s changed to %d\n", - session->gpsdata.gps_device, state); + + if (state == laststate) { + if (++unchanged == 10) { + gpsd_report(1, "TIOCMIWAIT returns unchanged state, ppsmonitor terminates\n"); + break; + } + } else { + gpsd_report(5, "carrier-detect on %s changed to %d\n", + session->gpsdata.gps_device, state); + laststate = state; + unchanged = 0; + } /*@ +boolint @*/ if (session->gpsdata.fix.mode > MODE_NO_FIX) { -- cgit v1.2.1