[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with program communicating to serial GPS


I'm having some strange issues when attempting to communicate to a NMEA
compat. gps over pccom0 on an old laptop.  I don't know if it _should_
work but I've tried simply catting /dev/tty00 expecting to see the NMEA
messages but it fails to work.  NMEA seems to only support 4800baud,
using `stty -f /dev/tty00 speed 4800` fails, returning only the text 9600.
I'm assuming it can't set the serial port to the correct baud.

I've been trying to use a C program (dstumbler) to communicate to the gps
with no success.  Funny thing though is that I've compiled gpsd (for use
with gpsdrive which does work on OpenBSD after removing all the damn
#ifdef linux shite), a C++ program and it works fine.  In fact, as root I
can even cat /dev/tty00 while gpsd is running at have the NMEA output
show up.

Is there something that needs modification in dstumbler's gps.c for proper
operation on OpenBSD?  I've included what I believe to be the working
speed setting portion of gpsd_main.cppp and the area of gps.c from
dstumbler that I think ?might? be having problems?  I'm at a loss to
explain why its not working but then I'm not really familiar enough with
serial devices or C to know.  This all in OpenBSD3.0 using pccom0.


Snip of gpsd_main.cpp

if(speedA==0 || 1!=system::sscanf(speedA,"%d",&speed)) speed= 4800;

void *gps= replay==0 ? system::openSerial(serial,speed) : 0;
if(gps==(void*)-1)  system::error(1,"fatal: Couldn't open serial port %s\n",serial);

Snip of gps.c from dstumbler:

 * open gps device for reading.. provide a fd and also fh for use with
gps_open(const char *device)
  int fd;

  if((fd = open(device, O_RDWR | O_SYNC)) < 0)
    alert("error: unable to open gps device: %s", strerror(errno));

    alert("error: specified gps device is not a tty: %s",

  if(tcgetattr(fd, &backup.ttyset) != 0)
    alert("error: unable to set attributes for gps device: %s",

  if(ioctl(fd, TIOCGETA, &ttyset) < 0)
    alert("error: unable to ioctl gps device: %s", strerror(errno));

  ttyset.c_ispeed = B4800;
  ttyset.c_ospeed = B4800;
  ttyset.c_cflag &= ~(PARENB | CRTSCTS);
  ttyset.c_cflag |= (CSIZE & CS8) | CREAD | CLOCAL;
  ttyset.c_iflag = ttyset.c_oflag = ttyset.c_lflag = (tcflag_t) 0;
  ttyset.c_lflag |= ICANON;

  if(ioctl(fd, TIOCSETAF, &ttyset) < 0)
    alert("error: unable to ioctl gps device: %s", strerror(errno));

  return fd;


Richard Lotz
GPG Key:     http://students.washington.edu/rlotz/key.txt
Fingerprint: 6BD7 C584 7DDC 43FD F0D4  87AB 5A8F 89D5 B3CC 9517

Visit your host, monkey.org