summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-01-26 21:13:09 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-01-27 07:34:25 -0500
commit3dde68036e7d76d659debedb25d1745af4095b73 (patch)
tree1658580e096c3f2103bdb8c045b943759c2106d0
parentb9211a0a482a72c4d88248dd7c99a59df2c54906 (diff)
downloadgpsd-3dde68036e7d76d659debedb25d1745af4095b73.tar.gz
Improved adaptive-delay logic. Don't insert them if CAN devices are in play.
All regression tests pass.
-rw-r--r--driver_nmea2000.c6
-rw-r--r--gpsd.c30
2 files changed, 18 insertions, 18 deletions
diff --git a/driver_nmea2000.c b/driver_nmea2000.c
index e2bc0fa1..1d25158b 100644
--- a/driver_nmea2000.c
+++ b/driver_nmea2000.c
@@ -1644,15 +1644,9 @@ int nmea2000_open(struct gps_device_t *session)
}
}
- /*
- * For device-classification purposes, pretend this is a fast pseudo-tty.
- * What we mainly want out of this is to disable the adaptive-delay logic,
- * which causes loss of CAN packets.
- */
session->gpsdata.dev.parity = 'n';
session->gpsdata.dev.baudrate = 250000;
session->gpsdata.dev.stopbits = 0;
- session->sourcetype = source_pty;
return session->gpsdata.gps_fd;
}
#endif /* of ifndef S_SPLINT_S */
diff --git a/gpsd.c b/gpsd.c
index efaa8d09..04441201 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -1783,9 +1783,9 @@ static void adaptive_delay(void)
/* sleep a calculated time only if we have a buggy select() */
{
struct gps_device_t *devp;
- unsigned int numdevices;
+ unsigned int mightbuzz;
+ bool buzzlock;
useconds_t delay;
- bool nonpty = false;
if (context.inbytesavg <= SLEEP_THRESHOLD)
context.selectbug = true;
@@ -1799,27 +1799,33 @@ static void adaptive_delay(void)
if (context.inbyteswpos != (unsigned char)WINDOW_AVG_SIZE)
return;
- /* count the number of devices which would be polled */
- numdevices = 0;
+ /* count the number of devices which might buzz */
+ mightbuzz = 0;
+ buzzlock = false;
for (devp = devices; devp < devices + MAX_DEVICES; devp++)
if (allocated_device(devp) && devp->gpsdata.gps_fd > 0) {
- if (devp->sourcetype != source_pty && devp->sourcetype != source_udp)
- nonpty = true;
- numdevices++;
+ if (devp->sourcetype==source_rs232 && devp->sourcetype==source_usb)
+ mightbuzz++;
+ /*
+ * Some fast devices will lose packets if delays
+ */
+ if (devp->sourcetype == source_can)
+ buzzlock = true;
}
/*
- * Avoid containing and delaying if we're running inside a test harness.
- * Without this check the regression tests fail.
+ * Because ptys are not counted, we avoid delay insertion if we're
+ * running inside a test harness. Without this check the
+ * regression tests fail.
*/
- if (nonpty && numdevices > 0) {
+ if (mightbuzz > 0 && !buzzlock) {
/*
* SLEEP_FACTOR is a magic number derived by observation.
* Sleep no more than 0.5secs including all the devices.
*/
delay = (useconds_t)(SLEEP_FACTOR/context.inbytesavg);
- if (delay > (useconds_t) (500000UL/numdevices) )
- delay = (useconds_t) (500000UL/numdevices);
+ if (delay > (useconds_t) (500000UL/mightbuzz) )
+ delay = (useconds_t) (500000UL/mightbuzz);
gpsd_report(&context.errout, LOG_WARN,
"select() bug found, sleeping for %u usec\n",delay);