summaryrefslogtreecommitdiff
path: root/serial.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-02-13 15:41:41 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-02-13 15:41:41 +0000
commitbc8c850af6e96d616390f5d189cb12d12f188739 (patch)
treeb9cfdda104341d0b74b9a4cc08ed2531276e5eaa /serial.c
parentb168f262ebd7a26974b3ab89ee472257f55c17aa (diff)
downloadgpsd-bc8c850af6e96d616390f5d189cb12d12f188739.tar.gz
Integrated baud-rate hunting.
Diffstat (limited to 'serial.c')
-rw-r--r--serial.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/serial.c b/serial.c
index e3dc2c5d..bc150773 100644
--- a/serial.c
+++ b/serial.c
@@ -59,18 +59,18 @@ int gpsd_get_speed(struct termios* ttyctl)
static int rates[] = {4800, 9600, 19200, 38400};
#define NRATES sizeof(rates)/sizeof(rates[0])
-static int connect_at_speed(int ttyfd, struct termios *ttyctl, int speed)
+static int connect_at_speed(int ttyfd, struct gps_session_t *session, int speed)
{
- char buf[BUFSIZE], *sp;
+ char buf[BUFSIZE];
int n;
size_t maxreads;
- gpsd_set_speed(ttyctl, speed);
+ gpsd_set_speed(&session->ttyset, speed);
/*
* throw away stale NMEA data that may be sitting in the buffer
* from a previous session.
*/
- if (tcsetattr(ttyfd, TCSAFLUSH, ttyctl) != 0)
+ if (tcsetattr(ttyfd, TCSAFLUSH, &session->ttyset) != 0)
return 0;
/*
* for unknown reasons, the TCSAFLUSH above is not sufficient to
@@ -94,7 +94,10 @@ static int connect_at_speed(int ttyfd, struct termios *ttyctl, int speed)
return 0;
}
- return nmea_validate_buffer(buf, n);
+ if (session->device_type->validate_buffer)
+ return session->device_type->validate_buffer(buf, n);
+ else
+ return 1;
}
int gpsd_open(int device_speed, int stopbits, struct gps_session_t *session)
@@ -123,7 +126,7 @@ int gpsd_open(int device_speed, int stopbits, struct gps_session_t *session)
if (device_speed) {
gpsd_report(1, "setting speed %d, %d stopbits, no parity\n",
device_speed, stopbits);
- if (connect_at_speed(ttyfd, &session->ttyset, device_speed)) {
+ if (connect_at_speed(ttyfd, session, device_speed)) {
session->baudrate = device_speed;
return ttyfd;
}
@@ -131,7 +134,7 @@ int gpsd_open(int device_speed, int stopbits, struct gps_session_t *session)
for (ip = rates; ip < rates + sizeof(rates)/sizeof(rates[0]); ip++) {
gpsd_report(1, "hunting at speed %d, %d stopbits, no parity\n",
*ip, stopbits);
- if (connect_at_speed(ttyfd, &session->ttyset, *ip)) {
+ if (connect_at_speed(ttyfd, session, *ip)) {
session->baudrate = *ip;
return ttyfd;
}