注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

dp: 生活的脚步,进步的点滴...

Cam、DSP、FPGA、PM、Life、More ...

 
 
 

日志

 
 

GPS 其实没啥  

2011-10-12 17:47:50|  分类: 专业 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

GPS只要处于工作状态就会源源不断地把接收并计算出的GPS导航定位信息通过串口传送进来,若要对GPS进行信息提取必须首先明确其帧结构,然后才能根据其结构完成对各定位信息的提取。
    NMEA0183协议是美国国家海洋电子协会(NationaIMarine Electronlcs Association)制定的GPS接口协议标准。NMEA0183定义了若干代表不同含义的语句,每个语句实际上是一个ASCII码串。这种码直观,易于识别和应用。在分析中,不需要了解NMEA0183通信协议的全部信息,仅需要从中挑选出需要的那部分定位数据,其余的信息忽略掉。

GPS数据格式:
GPS DOP and Active Satellites(GSA)当前卫星信息
$GPGSA,<1>,<2>,<3>,<3>,,,,,<3>,<3>,<3>,<4>,<5>,<6>,<7><CR><LF>
<1>模式:M = 手动, A = 自动。
<2>定位型式 1 = 未定位, 2 = 二维定位, 3 = 三维定位。
<3>PRN 数字:01 至 32 表天空使用中的卫星编号,最多可接收12 颗卫星信息。
<4> PDOP 位置精度因子(0.5~99.9)
<5> HDOP 水平精度因子(0.5~99.9)
<6> VDOP 垂直精度因子(0.5~99.9)
<7> Checksum.(检查位).


2 GPS Satellites in View(GSV)可见卫星信息
$GPGSV, <1>,<2>,<3>,<4>,<5>,<6>,<7>,?<4>,<5>,<6>,<7>,<8><CR><LF>
<1> GSV 语句的总数
<2> 本句GSV 的编号
<3> 可见卫星的总数,00 至 12。
<4> 卫星编号, 01 至 32。
<5>卫星仰角, 00 至 90 度。
<6>卫星方位角, 000 至 359 度。实际值。
<7>讯号噪声比(C/No), 00 至 99 dB;无表未接收到讯号。
<8>Checksum.(检查位).
第<4>,<5>,<6>,<7>项个别卫星会重复出现,每行最多有四颗卫星。其余卫星信息会于次一行出现,若未使用,这些字段会空白。

 

3 Global Positioning System Fix Data(GGA)GPS 定位信息
$GPGGA,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,M,<10>,M,<11>,<12>*hh<CR><LF>
<1> UTC 时间,hhmmss(时分秒)格式
<2> 纬度ddmm.mmmm(度分)格式(前面的0 也将被传输)
<3> 纬度半球N(北半球)或S(南半球)
<4> 经度dddmm.mmmm(度分)格式(前面的0 也将被传输)
<5> 经度半球E(东经)或W(西经)
<6> GPS 状态:0=未定位,1=非差分定位,2=差分定位,6=正在估算
<7> 正在使用解算位置的卫星数量(00~12)(前面的0 也将被传输)
<8> HDOP 水平精度因子(0.5~99.9)
<9> 海拔高度(-9999.9~99999.9)
<10> 地球椭球面相对大地水准面的高度
<11> 差分时间(从最近一次接收到差分信号开始的秒数,如果不是差分定位将为空)
<12> 差分站ID 号0000~1023(前面的0 也将被传输,如果不是差分定位将为空)

 

4 Recommended Minimum Specific GPS/TRANSIT Data(RMC)推荐定位信息
$GPRMC,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>,<12>*hh<CR><LF>
<1> UTC 时间,hhmmss(时分秒)格式
<2> 定位状态,A=有效定位,V=无效定位
<3> 纬度ddmm.mmmm(度分)格式(前面的0 也将被传输)
<4> 纬度半球N(北半球)或S(南半球)
<5> 经度dddmm.mmmm(度分)格式(前面的0 也将被传输)
<6> 经度半球E(东经)或W(西经)
<7> 地面速率(000.0~999.9 节,前面的0 也将被传输)
<8> 地面航向(000.0~359.9 度,以真北为参考基准,前面的0 也将被传输)
<9> UTC 日期,ddmmyy(日月年)格式
<10> 磁偏角(000.0~180.0 度,前面的0 也将被传输)
<11> 磁偏角方向,E(东)或W(西)
<12> 模式指示(仅NMEA0183 3.00 版本输出,A=自主定位,D=差分,E=估算,N=
数据无效)


5 Track Made Good and Ground Speed(VTG)地面速度信息
$GPVTG,<1>,T,<2>,M,<3>,N,<4>,K,<5>*hh<CR><LF>
<1> 以真北为参考基准的地面航向(000~359 度,前面的0 也将被传输)
<2> 以磁北为参考基准的地面航向(000~359 度,前面的0 也将被传输)
<3> 地面速率(000.0~999.9 节,前面的0 也将被传输)
<4> 地面速率(0000.0~1851.8 公里/小时,前面的0 也将被传输)
<5> 模式指示(仅NMEA0183 3.00 版本输出,A=自主定位,D=差分,E=估算,N=数
据无效)__

 


 GPS接收的数据Log:

$GPRMC,073550.000,A,3959.2134,N,11619.6676,E,1.19,180.54,180310,,*00
$GPGGA,073551.000,3959.2129,N,11619.6675,E,1,05,3.7,49.2,M,-6.5,M,,0000*7B
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073551.000,A,3959.2129,N,11619.6675,E,0.95,178.90,180310,,*04
$GPGGA,073552.000,3959.2120,N,11619.6674,E,1,05,3.7,49.0,M,-6.5,M,,0000*72
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073552.000,A,3959.2120,N,11619.6674,E,0.96,178.68,180310,,*0B
$GPGGA,073553.000,3959.2122,N,11619.6674,E,1,05,3.7,49.0,M,-6.5,M,,0000*71
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073553.000,A,3959.2122,N,11619.6674,E,0.27,156.04,180310,,*04
$GPGGA,073554.000,3959.2121,N,11619.6674,E,1,05,3.7,48.9,M,-6.5,M,,0000*7D
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPGSV,3,1,12,18,87,063,24,26,69,341,43,09,62,058,41,27,53,051,39*7F
$GPGSV,3,2,12,22,52,310,45,24,45,272,,31,38,208,,15,34,199,*7E
$GPGSV,3,3,12,21,32,203,,14,08,263,,30,04,168,,10,03,125,*7F
$GPRMC,073554.000,A,3959.2121,N,11619.6674,E,0.69,173.63,180310,,*0C
$GPGGA,073555.000,3959.2115,N,11619.6673,E,1,05,3.7,48.8,M,-6.5,M,,0000*7D
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073555.000,A,3959.2115,N,11619.6673,E,1.00,179.14,180310,,*09
$GPGGA,073556.000,3959.2115,N,11619.6674,E,1,05,3.7,48.7,M,-6.5,M,,0000*76
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073556.000,A,3959.2115,N,11619.6674,E,0.72,174.63,180310,,*04
$GPGGA,073557.000,3959.2118,N,11619.6674,E,1,05,3.7,48.7,M,-6.5,M,,0000*7A
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073557.000,A,3959.2118,N,11619.6674,E,0.30,157.08,180310,,*02
$GPGGA,073558.000,3959.2129,N,11619.6676,E,1,05,3.7,48.8,M,-6.5,M,,0000*7A
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073558.000,A,3959.2129,N,11619.6676,E,0.35,35.31,180310,,*37
$GPGGA,073559.000,3959.2143,N,11619.6678,E,1,05,3.7,48.9,M,-6.5,M,,0000*78
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPGSV,3,1,12,18,87,063,24,26,69,341,43,09,62,058,41,27,53,051,39*7F
$GPGSV,3,2,12,22,52,310,45,24,45,272,,31,38,208,,15,34,199,*7E
$GPGSV,3,3,12,21,32,203,,14,08,263,,30,04,168,,10,03,125,*7F
$GPRMC,073559.000,A,3959.2143,N,11619.6678,E,0.43,30.56,180310,,*31
$GPGGA,073600.000,3959.2149,N,11619.6680,E,1,05,3.7,49.0,M,-6.5,M,,0000*72
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073600.000,A,3959.2149,N,11619.6680,E,0.17,119.93,180310,,*01
$GPGGA,073601.000,3959.2159,N,11619.6681,E,1,05,3.7,49.1,M,-6.5,M,,0000*72
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073601.000,A,3959.2159,N,11619.6681,E,0.16,75.84,180310,,*3C
$GPGGA,073602.000,3959.2165,N,11619.6682,E,1,05,3.7,49.2,M,-6.5,M,,0000*7E
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073602.000,A,3959.2165,N,11619.6682,E,0.18,70.13,180310,,*36
$GPGGA,073603.000,3959.2166,N,11619.6682,E,1,05,3.7,49.2,M,-6.5,M,,0000*7C
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073603.000,A,3959.2166,N,11619.6682,E,0.21,141.70,180310,,*08
$GPGGA,073604.000,3959.2153,N,11619.6680,E,1,05,3.7,49.0,M,-6.5,M,,0000*7D
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPGSV,3,1,12,18,87,063,24,26,69,341,43,09,62,058,41,27,53,051,39*7F
$GPGSV,3,2,12,22,52,310,45,24,45,272,,31,38,208,,15,34,199,*7E
$GPGSV,3,3,12,21,32,203,,14,08,263,,30,04,168,,10,03,125,*7F
$GPRMC,073604.000,A,3959.2153,N,11619.6680,E,0.84,177.27,180310,,*03
$GPGGA,073605.000,3959.2140,N,11619.6678,E,1,05,3.7,48.8,M,-6.5,M,,0000*70
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073605.000,A,3959.2140,N,11619.6678,E,1.39,181.38,180310,,*07
$GPGGA,073606.000,3959.2135,N,11619.6677,E,1,05,3.7,48.7,M,-6.5,M,,0000*71
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073606.000,A,3959.2135,N,11619.6677,E,0.75,176.70,180310,,*04
$GPGGA,073607.000,3959.2123,N,11619.6675,E,1,05,3.7,48.5,M,-6.5,M,,0000*77
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073607.000,A,3959.2123,N,11619.6675,E,0.74,176.95,180310,,*0A
$GPGGA,073608.000,3959.2132,N,11619.6677,E,1,05,3.7,48.6,M,-6.5,M,,0000*79
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPRMC,073608.000,A,3959.2132,N,11619.6677,E,0.18,61.27,180310,,*33
$GPGGA,073609.000,3959.2134,N,11619.6677,E,1,05,3.7,48.7,M,-6.5,M,,0000*7F
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.9,3.7,1.0*3C
$GPGSV,3,1,12,18,87,063,23,26,69,341,42,09,62,058,41,27,53,051,39*79
$GPGSV,3,2,12,22,52,310,45,24,45,272,,31,38,208,,15,34,199,*7E
$GPGSV,3,3,12,21,32,203,,14,08,263,,30,04,168,,10,03,125,*7F
$GPRMC,073609.000,A,3959.2134,N,11619.6677,E,0.28,153.30,180310,,*01
$GPGGA,073610.000,3959.2143,N,11619.6679,E,1,05,3.7,48.8,M,-6.5,M,,0000*76
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.8,3.7,1.0*3D
$GPRMC,073610.000,A,3959.2143,N,11619.6679,E,0.21,54.47,180310,,*38
$GPGGA,073611.000,3959.2149,N,11619.6680,E,1,05,3.7,48.9,M,-6.5,M,,0000*7A
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.8,3.7,1.0*3D
$GPRMC,073611.000,A,3959.2149,N,11619.6680,E,0.21,52.48,180310,,*3C
$GPGGA,073612.000,3959.2159,N,11619.6681,E,1,05,3.7,49.1,M,-6.5,M,,0000*70
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.8,3.7,1.0*3D
$GPRMC,073612.000,A,3959.2159,N,11619.6681,E,0.31,35.71,180310,,*35
$GPGGA,073613.000,3959.2165,N,11619.6682,E,1,05,3.7,49.2,M,-6.5,M,,0000*7E
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.8,3.7,1.0*3D
$GPRMC,073613.000,A,3959.2165,N,11619.6682,E,0.53,23.22,180310,,*3D
$GPGGA,073614.000,3959.2175,N,11619.6684,E,1,05,3.7,49.4,M,-6.5,M,,0000*78
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.8,3.7,1.0*3D
$GPGSV,3,1,12,18,87,067,23,26,69,341,42,09,61,057,40,27,53,051,39*70
$GPGSV,3,2,12,22,52,310,46,24,45,271,,31,38,208,,15,34,199,*7E
$GPGSV,3,3,12,21,32,202,,14,08,263,,30,07,164,,10,03,125,*71
$GPRMC,073614.000,A,3959.2175,N,11619.6684,E,0.99,16.51,180310,,*39
$GPGGA,073615.000,3959.2170,N,11619.6683,E,1,05,3.7,49.3,M,-6.5,M,,0000*7C
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.8,3.7,1.0*3D
$GPRMC,073615.000,A,3959.2170,N,11619.6683,E,0.16,96.19,180310,,*39
$GPGGA,073616.000,3959.2179,N,11619.6685,E,1,05,3.7,49.5,M,-6.5,M,,0000*76
$GPGSA,A,3,09,22,26,27,18,,,,,,,,3.8,3.7,1.0*3D
$GPRMC,073616.000,A,3959.2179,N,11619.6685,E,0.32,160.55,180310,,*03
$PSRFTXT,Version:GSW3.2.4_3.1.00.12-SDK003P1.00a
$PSRFTXT,Version2:F-GPS-03-0701231
$PSRFTXT,WAAS Disable
$PSRFTXT,TOW:  372971
$PSRFTXT,WK:   1575 

 

 

gps信息

 

 

   为了给用户简明清晰的定位和导航信息,我们必须将GPS数据进行转换,再显示出来。
   比如,在我的地图定位中,地图坐标(0,0)的点即为GPS的(3136.4227 ,11994.8942),单个像素纬度/经度(0.03211387*0.05595)。

   GPS信息转换为地图坐标满足

  (GPS经纬度–原点经纬度)/ 单个像素经纬度

还有第三方地图库的支持

地图  


 串口测试用c实现:

 

          #include <stdlib.h>   
  1. #include <stdio.h>   
  2. #include <unistd.h>   
  3. #include <termios.h>   
  4. #include <errno.h>   
  5. #include <sys/stat.h>   
  6. #include <sys/types.h>   
  7. #include <string.h>   
  8. #include <fcntl.h>   
  9.   
  10.   
  11. #define COM_OPEN "/dev/ttyS0"   
  12. #define BUFFER_SIZE 100   
  13.   
  14. int set_com_config(int fd,int baud_rate,int data_bits,char parity,int stop_bits)  
  15. {  
  16.     struct termios new_cfg,old_cfg;  
  17.     int speed;  
  18.     if(tcgetattr(fd,&old_cfg))  
  19.     {  
  20.         perror("tcgetattr err!/n");  
  21.         return -1;  
  22.     }  
  23.   
  24.     new_cfg = old_cfg;  
  25.     cfmakeraw(&new_cfg);//set to raw 方式   
  26.   
  27.     new_cfg.c_cflag &= ~CSIZE;  
  28.       
  29.     switch (baud_rate)  
  30.     {  
  31.         case 2400:  
  32.             speed = B2400;  
  33.             break;  
  34.         case 4800:  
  35.             speed = B4800;  
  36.             break;  
  37.         case 9600:  
  38.             speed = B9600;  
  39.             break;  
  40.         case 19200:  
  41.             speed = B19200;  
  42.             break;  
  43.         case 38400:  
  44.             speed = B38400;  
  45.             break;  
  46.         default:  
  47.             case 115200:  
  48.             {  
  49.                 speed = B115200;  
  50.             }  
  51.             break;  
  52.               
  53.     }  
  54.       
  55.     cfsetispeed(&new_cfg,speed);  
  56.     cfsetospeed(&new_cfg,speed);  
  57.   
  58.     switch (data_bits)  
  59.     {  
  60.         default:  
  61.         case 8:  
  62.         {  
  63.             new_cfg.c_cflag |= CS8;  
  64.         }  
  65.         break;  
  66.           
  67.         case 7:  
  68.         {  
  69.             new_cfg.c_cflag |= CS7;  
  70.         }  
  71.         break;  
  72.     }  
  73.   
  74.     switch (parity)  
  75.     {  
  76.         default:  
  77.         case 'n':  
  78.         case 'N':  
  79.         {  
  80.             new_cfg.c_cflag &= ~PARENB;  
  81.             new_cfg.c_iflag &= ~INPCK;  
  82.         }  
  83.         break;  
  84.   
  85.         case 'o':  
  86.         case 'O':  
  87.         {  
  88.             new_cfg.c_cflag |=(PARODD |PARENB);  
  89.             new_cfg.c_iflag |=INPCK;              
  90.         }  
  91.         break;  
  92.   
  93.         case 'e':  
  94.         case 'E':  
  95.         {  
  96.             new_cfg.c_cflag |= PARENB;  
  97.             new_cfg.c_cflag &= ~PARODD;  
  98.             new_cfg.c_iflag |= INPCK;  
  99.         }  
  100.         break;  
  101.   
  102.         case 's':  
  103.         case 'S':  
  104.         {  
  105.             new_cfg.c_cflag &= ~PARENB;  
  106.             new_cfg.c_cflag &= ~CSTOPB;  
  107.         }  
  108.         break;        
  109.     }  
  110.   
  111.     switch (stop_bits)  
  112.     {  
  113.         default:  
  114.         case 1:  
  115.             new_cfg.c_cflag &= ~CSTOPB;  
  116.             break;  
  117.         case 2:  
  118.             new_cfg.c_cflag  |=CSTOPB;  
  119.             break;  
  120.     }  
  121.   
  122.     new_cfg.c_cc[VTIME] = 0;  
  123.     new_cfg.c_cc[VMIN] = 1;  
  124.       
  125.     tcflush(fd,TCIFLUSH);  
  126.     if((tcsetattr(fd,TCSANOW,&new_cfg)) != 0)  
  127.     {  
  128.         perror("tcsetattr err!/n");  
  129.         return -1;  
  130.     }  
  131.   
  132.     return 0;  
  133. }  
  134.   
  135. int open_port(int com_port)  
  136. {  
  137.     int fd;  
  138.     fd = open (COM_OPEN,O_RDWR|O_NOCTTY|O_NDELAY);  
  139.     if(fd<0)  
  140.     {  
  141.         perror("open serial port err!/n");  
  142.         return -1;  
  143.     }  
  144.       
  145.     if(fcntl(fd, F_SETFL, 0)<0)  
  146.     {  
  147.         perror("fcntl  err!/n");  
  148.         return -1;  
  149.     }  
  150.   
  151.     if(isatty(fd) ==0)  
  152.     {  
  153.         perror("this is not a terminal device!/n");  
  154.         return -1;  
  155.     }  
  156.   
  157.     return fd;  
  158.           
  159. }  
  160.   
  161. int main()  
  162. {  
  163.       
  164.     int fd;  
  165.     int speed;  
  166.     char buff[BUFFER_SIZE];  
  167.   
  168.     struct termios new_cfg,old_cfg;  
  169.       
  170.     fd = open (COM_OPEN,O_RDWR|O_NOCTTY|O_NDELAY);//|O_NOCTTY|O_NDELAY   
  171.     if(fd<0)  
  172.     {  
  173.         perror("open serial port err!/n");  
  174.         return -1;  
  175.     }else  
  176.     {  
  177.         printf("open serial port !/n");  
  178.     }  
  179.       
  180.     if (set_com_config(fd, 4800, 8, 'N', 1)<0)  
  181.     {  
  182.         perror("set_com_config/n");  
  183.         return -1;  
  184.     }  
  185.     while(1)  
  186.     {  
  187.         memset(buff,0, BUFFER_SIZE*sizeof(char));  
  188.         if(read(fd,buff,BUFFER_SIZE)>0)  
  189.         {  
  190.             printf("the received words are :%s/n",buff);  
  191.         }  
  192.         sleep(1);  
  193.     }  
  194.     return 0;  
  195. }  

    刚刚捣腾完GPS,因为网上的资料七零八碎的,好不容易才折腾清楚,在这简单做个总结。

  评论这张
 
阅读(728)| 评论(0)
推荐

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016