GPS nmea 输出,仅保存最后一条记录到外部文件 linux

GPS nmea 输出,仅保存最后一条记录到外部文件 linux

我正在为我的车载自组织网络项目使用 globalsat G-STAR IV GPS。在此,来自 GPS 的 nmea 输出每 1 秒更新一次。我想知道是否有办法只保存外部文件中的最后一行,并在 GPS 发送数据信号时不断覆盖该外部文件中的行。

我的 GPS 的 nmea 输出示例如下。

$GPGSV,3,1,10,21,55,052,18,22,54,297,13,18,53,011,22,15,18,042,18*75
$GPGSV,3,2,10,14,43,184,,27,33,314,,29,21,152,,16,17,263,*7D
$GPGSV,3,3,10,24,10,092,,19,06,322,*79
$GPRMC,095827.000,A,2335.2440,N,05809.8432,E,0.55,103.38,091114,,,A*66
$GPGGA,095828.000,2335.2443,N,05809.8433,E,1,04,5.2,89.5,M,-34.7,M,,0000*46
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095828.000,A,2335.2443,N,05809.8433,E,1.21,102.44,091114,,,A*63
$GPGGA,095829.000,2335.2446,N,05809.8434,E,1,04,5.2,89.5,M,-34.7,M,,0000*45
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095829.000,A,2335.2446,N,05809.8434,E,0.92,102.44,091114,,,A*69
$GPGGA,095830.000,2335.2448,N,05809.8437,E,1,04,5.2,89.5,M,-34.7,M,,0000*40
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095830.000,A,2335.2448,N,05809.8437,E,1.25,102.12,091114,,,A*62
$GPGGA,095831.000,2335.2450,N,05809.8441,E,1,04,5.2,89.5,M,-34.7,M,,0000*49
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095831.000,A,2335.2450,N,05809.8441,E,1.47,101.80,091114,,,A*67
$GPGGA,095832.000,2335.2455,N,05809.8446,E,1,04,5.2,89.5,M,-34.7,M,,0000*48
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPGSV,3,1,10,21,55,052,18,22,54,297,14,18,53,011,22,15,18,042,18*72
$GPGSV,3,2,10,14,43,184,,27,33,314,,29,21,152,,16,17,263,*7D
$GPGSV,3,3,10,24,10,092,,19,06,322,*79
$GPRMC,095832.000,A,2335.2455,N,05809.8446,E,2.36,100.07,091114,,,A*6D
$GPGGA,095833.000,2335.2459,N,05809.8450,E,1,04,5.2,89.5,M,-34.7,M,,0000*42
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095833.000,A,2335.2459,N,05809.8450,E,1.98,98.52,091114,,,A*50
$GPGGA,095834.000,2335.2458,N,05809.8454,E,1,04,5.2,89.5,M,-34.7,M,,0000*40
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095834.000,A,2335.2458,N,05809.8454,E,1.19,98.50,091114,,,A*59
$GPGGA,095835.000,2335.2450,N,05809.8457,E,1,04,5.2,89.6,M,-34.7,M,,0000*49
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C

我目前正在通过 linux 命令中的终端将此输出保存到外部文件:

ima@ubuntu12:~$ sudo cat /dev/ttyUSB0 | tee gpsoutput.tr 

我也尝试过sudo cat /dev/ttyUSB0 | tee >(tail -n 1 > gpsout.tr)但它并没有动态更新。

但是,我需要一种方法来将来自 GPS 的最后一行保存到该外部文件中。也就是说,它会不断覆盖文件并替换为来自 GPS 的最新行。请帮忙。谢谢

答案1

这个怎么样:

watch -n 1 "tail -n 1 /dev/ttyUSB0 > gpsout.tr"

相关内容