[prev in list] [next in list] [prev in thread] [next in thread]
List: gpsd-dev
Subject: [Gpsd-dev] Better test diff for serial.c
From: gpsd-dev () lists ! berlios ! de (Eric S ! Raymond)
Date: 2006-06-14 13:58:23
Message-ID: 200606141358.k5EDwNar017718 () golux ! thyrsus ! com
[Download RAW message or body]
This is especially for Til to try:
--- serial.c (revision 3335)
+++ serial.c (working copy)
@@ -50,7 +51,7 @@
void gpsd_set_speed(struct gps_device_t *session,
speed_t speed, unsigned char parity, unsigned int stopbits)
{
- speed_t rate;
+ speed_t rate, oldrate = cfgetispeed(&session->ttyset);
if (speed < 300)
rate = B0;
@@ -73,7 +74,7 @@
else
rate = B115200;
- if (rate!=cfgetispeed(&session->ttyset) || (unsigned \
int)parity!=session->gpsdata.parity || stopbits!=session->gpsdata.stopbits) { + if \
(rate!=oldrate || (unsigned int)parity!=session->gpsdata.parity || \
stopbits!=session->gpsdata.stopbits) {
/*@ignore@*/
(void)cfsetispeed(&session->ttyset, rate);
@@ -145,10 +146,19 @@
* flush followed by a 200-millisecond delay followed by flush has
* been found to work reliably on the pl2303. It is also known
* from testing that a 100-millisec delay is too short, allowing
- * occasional failure to lock.
+ * occasional failure to lock. A straight delay of 500 milliseconds
+ * without a following flush also seems to work; we don't know
+ * whether the second flush is doing something real to the state of
+ * the system or merely acting as an additional delay.
+ *
+ * The formula below tries to compute flush time for a device with
+ * a 96-byte fifo like the pl2303. 10 is the actual number of bits
+ * in an 8N1 serial frame. At 4800bps this yields 200000. For
+ * higher speeds the delay will be less.
*/
+#define min(x, y) ((x) < (y) ? (x) : (y))
(void)tcflush(session->gpsdata.gps_fd, TCIOFLUSH);
- (void)usleep(200000);
+ (void)usleep((1e6 / min(rate, oldrate)) * 10 * 96);
(void)tcflush(session->gpsdata.gps_fd, TCIOFLUSH);
}
gpsd_report(1, "speed %d, %d%c%d\n", speed, 9-stopbits, parity, stopbits);
--
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
"Boys who own legal firearms have much lower rates of delinquency and
drug use and are even slightly less delinquent than nonowners of guns."
-- U.S. Department of Justice, National Institute of
Justice, Office of Juvenile Justice and Delinquency Prevention,
NCJ-143454, "Urban Delinquency and Substance Abuse," August 1995.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic