Pseudo TTY Devices for GPS Emulation

Looking for a possibility to emulate some GPS data for testing some balloon tracking software I found the nice tcl application called gpsfeed+ [1]. That is very useful for feeding simulated GPS data into a device using a serial port. My usecase is testing software with GPS data on the computer itself. The way to go is to use pseudo TTY devices that is a piece of software pipe that you can put data in on the one end and read of from the other end.

For creating such a TTY pipe on my Ubuntu Trusty I used socat to create a bidrectional pipe. It creates two devices that can be used to write GPS raw data from gpsfeed+ to and read from the other end. Here I used it to simluate an attached GPS receiver to dl-fldigi in order to test the tracker. The pseudo TTY pipe can be set up as follows:

user@host:~$ socat -d -d pty,raw,echo=0 pty,raw,echo=0
2015/12/11 00:27:47 socat[9076] N PTY is /dev/pts/28
2015/12/11 00:27:47 socat[9076] N PTY is /dev/pts/29
2015/12/11 00:27:47 socat[9076] N starting data transfer loop with FDs [3,3] and [5,5]

After that you have two devices. You can attach gpsfeed+ to /dev/pts/28 for example and dl-fldigi to /dev/pts/29. After configuring this dl-fldigi can read the simluated GPS data from /dev/pts/29. The siumlated GPS position is shown in the preferences window on the right. By default gpsdeed+ emulates some circles around a configured GPS position. Here we are drawing some circles around Athens in Greece.

Emulating GPS circles around Athens
Emulating GPS circles around Athens

Playing a pre-recorded Track

Another option is to let gpsfeed+ play a GPS track that way previously recorded with a handheld GPS device. In my case I have some tracks that were exported from a Garmin GPS device. Apparently that is not NMEA raw data as gpsfeed+ expects. But there is another nice piece of software called gpsbabel. That can be used to convert GPS data from any known format to almost every other format. Here I converted a .gdb file to NMEA raw data:

user@host:~$ gpsbabel -i gdb -f 2014_07_12.gdb -o nmea -F gps_raw.nmea

The converted file needs some rework because the time fild is obviously a little different from what is expected. And the other reason is that there is no information about satellite fixes in the file. That causes some program to ignore the GPS data.

$GPGGA,185244.000,5128.810,N,00714.360,E,0,00,0.0,118.860,M,0.0,M,,*65
$GPGGA,185250.000,5128.837,N,00714.318,E,0,00,0.0,118.379,M,0.0,M,,*69
$GPGGA,185256.000,5128.842,N,00714.275,E,0,00,0.0,120.302,M,0.0,M,,*60

This can be edited with some sed magic. For example:

user@host:~$ sed -i -e 's/E,0,00,/E,2,10,/' -e 's/\.000,/,/' gps_raw.nmea
$GPGGA,185244,5128.810,N,00714.360,E,2,10,0.0,118.860,M,0.0,M,,*65
$GPGGA,185250,5128.837,N,00714.318,E,2,10,0.0,118.379,M,0.0,M,,*69
$GPGGA,185256,5128.842,N,00714.275,E,2,10,0.0,120.302,M,0.0,M,,*60

The resulting file can be opened in gpsfeed+ and replayed. The result is shown in the following image.

Replaying a recorded GPS track
Replaying a recorded GPS track

References

[1] http://gpsfeed.sourceforge.net/