概述
1、接上模块通过USB连接,需要插上SIM卡,查看设备如下
root@ATK-IMX6U:~# ls /dev/ttyUSB*
/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/ttyUSB3
2、使能GPS信息输出
echo -e "AT+QGPS=1nr" > /dev/ttyUSB2
通过命令查看信息
root@ATK-IMX6U:~# cat /dev/ttyUSB1
没定位到的情况
$GPVTG,,T,,M,,N,,K,N*2C
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGGA,,,,,,0,,,,,,,,*66
$GPRMC,,V,,,,,,,,,,N*53
定位到的情况
$GPGSV,6,1,21,10,75,334,26,12,35,087,45,18,14,185,28,23,62,132,43*7D
$GPGSV,6,2,21,24,21,042,26,25,41,129,44,31,23,230,34,32,41,313,43*76
$GPGSV,6,3,21,15,02,090,,21,01,319,,33,,,34,38,,,34*72
$GPGSV,6,4,21,39,,,34,40,,,34,41,,,41,42,,,34*77
$GPGSV,6,5,21,45,,,41,46,,,34,48,,,34,50,,,41*73
$GPGSV,6,6,21,51,,,35*78
$GPGGA,090652.00,2813.804270,N,11256.758714,E,1,07,0.9,127.6,M,-14.0,M,,*48
$GPVTG,0.0,T,3.0,M,0.0,N,0.0,K,A*20
$GPRMC,090652.00,A,2813.804270,N,11256.758714,E,0.0,0.0,230921,3.0,W,A*2F
$GPGSA,A,3,10,12,18,23,24,25,32,,,,,,1.2,0.9,0.8*3A
GPS信息解析
gps.c
//
// Created by ihz on 2020/6/4.
//
#include "gps.h"
// 数据分割,可以分割两个连续的分隔符
static char* strsplit(char** stringp, const char* delim)
{
char* start = *stringp;
char* p;
p = (start != NULL) ? strpbrk(start, delim) : NULL;
if (p == NULL)
{
*stringp = NULL;
}
else
{
*p = '