Looking for a program that can communicate with a GPS reciever

Looking for a program that can communicate with a GPS reciever

Post by Jonas Kongslu » Mon, 01 Feb 1999 04:00:00



I have to delvelop a program that can communicate with a GPS reciever
through a RS-232 interface and save the output to a file.
The GPS reciever outputs pure ACSII text (in NMEA 0183 format) every
second, but I only need output every 5th minut.

Can anybody help me with some C++ source code that shows how I recieve
data from the RS-232 interface?

Thanks in advance.

--
Jonas Kongslund

Bell, Eric Temple: Euclid taught me that without assumptions there
is no proof. Therefore, in any argument, examine the assumptions.

 
 
 

Looking for a program that can communicate with a GPS reciever

Post by Mark Hah » Mon, 01 Feb 1999 04:00:00


Quote:> I have to delvelop a program that can communicate with a GPS reciever
> through a RS-232 interface and save the output to a file.
> The GPS reciever outputs pure ACSII text (in NMEA 0183 format) every
> second, but I only need output every 5th minut.
> Can anybody help me with some C++ source code that shows how I recieve
> data from the RS-232 interface?

following is some simple, portable code I wrote to drive my modem
a long time ago.  termios/open/select/read is so simple to use, I don't think
I'd bother prettying it up with classes...

#include <unistd.h>
#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>
#include <termios.h>

int
main() {
    int fdSer = open("/dev/ttyS0", O_RDWR);
    if (fdSer == -1) {
        perror("open of /dev/modem failed");
        return 1;
    }

    struct termios t;
    t.c_iflag = IGNBRK | INPCK;
    t.c_oflag = 0;
    t.c_cflag = CS8 | CREAD | CLOCAL | CSTOPB;
    t.c_lflag = 0;
    cfsetispeed(&t,B38400);
    cfsetospeed(&t,B38400);
    tcsetattr(fdSer,TCSANOW,&t);

    tcgetattr(0,&t);
    struct termios tOrg = t;
    t.c_iflag = 0;
    t.c_lflag = 0;
    t.c_cc[VTIME] = t.c_cc[VMIN] = 0;
    tcsetattr(0,TCSANOW,&t);

    while (1) {
        struct timeval timeout;
        timeout.tv_sec = 30;
        timeout.tv_usec = 0;

        fd_set readset;
        FD_ZERO(&readset);
        FD_SET(0,&readset);
        FD_SET(fdSer,&readset);

        if (select(fdSer+1,&readset,0,0,&timeout) == -1)
            continue;

        const unsigned bufSize = 256;
        unsigned char buf[bufSize];

        if (FD_ISSET(0,&readset)) {
            int c = read(0,buf,bufSize);
            if (c > 0) {
                static unsigned char prev = 0;
                if (prev == 0x1d && buf[0] == 'q')
                    break;
                prev = buf[0];
                write(fdSer,buf,c);
            }
        }
        if (FD_ISSET(fdSer,&readset)) {
            int c = read(fdSer,buf,bufSize);
            if (c > 0) {
                write(1,buf,c);
            }
        }
    }
    tcsetattr(0,TCSANOW,&tOrg);
    return 0;

Quote:}

--

                                              http://java.mcmaster.ca/~hahn