Reading from Serial port and dumping to log file

I Have a Garmin 18x LVC connected to serial port 2, I added the GPS to /etc/npd.conf and can read the time. But when I use the command cu I also get the GPS Coordinates:

Code:
/dev # cu -l /dev/cuau1 -s 4800
Connected
$GPGGA,210312,1234.4321,N,1234.4321,E,1,05,2.4,9.1,M,45.6,M,,*45
$GPGGA,210313,1234.4321,N,1234.4690,E,1,05,2.4,9.0,M,45.6,M,,*42

I would like to dump this information to a log file, so I can use it for other ends. I have no idea how to do this, can someone help me out?

Thankyou!

P.S. i did not realize that fans are popping up at my doorstep (Thanks to: ralphbsz), so i chaned the gps coordinates. He also mentioned that these GPS coordinates are very accurate, at least the Garmin is working. ;-)
 
The problem here is that the Garmin is connected to /dev/cuaXX, which will be opened by ntpd. Once it is open, it will look at the information it wants (the time), and throw the rest away. And while the device is open by ntpd, it can't be connected to gpxloggerd.

How to get around it? Tough question. One option would be: Write a tiny little daemon that reads one line from /dev/cuaXX, and immediately turns around and spits it out on two pipes (use named pipes for example). Then tell both gpxloggerd and ntpd to read from those pipes. Or go into the source code to ntpd, and add a line there: immediately after reading a line from the device, write it to somewhere (for example a log file, or a pipe, or something like that).

Or write a cron job, which starts and stops gpxloggerd and ntpd every hour (alternating), so only one each is running at each time. Since ntpd is typically required for good system health, one could switch back and forth between two ntpd configurations. Sounds difficult.
 
  • Thanks
Reactions: a6h
Actually i had to make a symbolic links, explained in this manual:

Getting time from GPS (without PPS)​


3.1 Configuring GPS and ntpd​


Windows administrators can install the ntpd port for Windows and follow the instructions in this article .

For Linux and FreeBSD, the instructions are the same:
  1. Connect the GPS receiver to the server's COM port (the USB adapter should also work).
  2. Create a symbolic link / dev / gpsX to the device (for example, I have / dev / cuau0 -> / dev / gps0).
  3. In ntp.conf add the line
    server 127.127.20.0 mode 0 prefer iburst minpoll 4 maxpoll 6

    Line 127.127.20. 0 means we are using a local time source, driver 20 (NMEA Generic), device / dev / gps 0 .

    If your device operates at a speed other than 4800 bps, you need to set the speed using the mode command: 0 - 4800 bps (by default, you can not specify), 16 - 9600, 32 - 19200, etc.
And i can dump while ntp is getting the info:
Code:
root@BSD06:/home/mrX # ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*GPS_NMEA(0)     .GPS.            0 l   51   64  377    0.000   +3.182   6.007
root@BSD06:/home/mrX #

So does this information make it more easy?
 
The link only moves the problem: You have one GPS device, which is readable on one serial port. You can use symbolic links to move that port to other places in the file system, in your case /dev/gps0. Only one program can read the data from that port. If the ntp daemon has read a line, that line is no longer available to the GPS location daemon. You need to create something that duplicates all the data.
 
Back
Top