Transfer from: Http://www.cnblogs.com/emouse/archive/2013/05/29/3105745.htmlGPS Module Introduction
The latest third-generation chip Sirfstar III (GSW 3.0/3.1), released in 2004 by the SIRF chip, has led to a peak in performance for civil GPS chips, with a much higher sensitivity than previous products. This chip improves sensitivity by using a 200,000-time/frequency-dependent device, with a cold boot/warm boot/Hot boot time of 42s/38s/8s, which can track up to 20 satellite channels simultaneously. is currently the most widely used in the market, at the same time cost-effective also very high chip, so in this design also use this chip as the core of the GPS module.
Data formats for GPS modules
The data processing of the GPS module is essentially the serial communication program design, but the output of the GPS module follows the fixed format, and the data from the module can be found by searching the string, and most of the commonly used GPS modules adopt the NMEA-0183 protocol. NMEA-0183 is the standard specification specified by National Marine Electronics Association, a standard for the development of communication standards between all navigational electronic instruments, including the format of transmission of data and the communication protocol for transmitting data.
The following is a normal set of GPS data
$GPGGA, 082006.000,3852.9276,n,11527.4283,e,1,08,1.0,20.6,m,,,, 0000*35
$GPRMC, 082006.000,a,3852.9276,n,11527.4283,e,0.00,0.0,261009,,*38
$GPVTG, 0.0,t,,m,0.00,n,0.0,k*50
The meanings of each group of data are analyzed separately below.
GPS fixed Data output statement ($GPGGA), which is the main data of a frame GPS positioning, is also the most widely used data. For ease of understanding, the following examples illustrate the meanings of the parts of the $gpgga statement.
Example: $GPGGA, 082006.000,3852.9276,n,11527.4283,e,1,08,1.0,20.6,m,,,, 0000*35
The standard format is:
$GPGGA, (1), (2), (3), (4), (5), (6), (7), (8), (9), M, (Ten), M, (one), () *hh (LF)
The meanings of the parts correspond to:
(1) Positioning UTC time: 08:20 06 seconds
(2) Latitude (format ddmm.mmmm: That is, DD degrees, mm.mmmm points);
(3) N/S (latitude or south latitude): Latitude 38 degrees 52.9276 minutes;
(4) Longitude (format dddmm.mmmm: That is, ddd degrees, mm.mmmm points);
(5) e/w (longitude or west longitude): East longitude 115 degrees 27.4283 minutes;
(6) Quality factor (0= no positioning, 1= real-time gps,2= differential GPS): 1= real-time GPS;
(7) Number of satellites available (0~8): Number of satellites to be used = 08;
(8) horizontal accuracy factor (1.0~99.9), horizontal precision factor =1.0;
(9) Antenna elevation (sea level, -9999.9~99999.9, Unit: m), antenna elevation =20.6m);
(10) Height of the earth ellipsoid relative to sea level ( -999.9~9999.9, Unit: m): none;
(11) Differential GPS data age, real-time GPS No: none;
(12) Differential reference station number (0000~1023), real-time GPS without: none;
* Sum check field; HH sum check number: (CR) (LF) carriage return, newline.
GPRMC (minimum GPS data format recommended)
$GPRMC, 082006.000,a,3852.9276,n,11527.4283,e,0.00,0.0,261009,,*38
$GPRMC, <1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10> <11><CR><LF>
(1) Standard location time (UTC) format: seconds seconds seconds (hhmmss.sss).
(2) position status, A = Data is available, V = data is unavailable.
(3) Latitude, format: Degree of Division. Sub-Division (DDMM.MMMM).
(4) Latitude-differentiated, Northern Hemisphere (N) or Southern Hemisphere (S).
(5) Longitude, format: Degree of Division, sub-division.
(6) Longitude distinction, East (E) hemisphere or west (W) hemisphere.
(7) Relative displacement speed, 0.0 to 1851.8 knots
(8) Relative displacement direction, 000.0 to 359.9 degrees. The actual value.
(9) Date, format: Sun and Moon Month (DDMMYY).
(10) Pole variable, 000.0 to 180.0.
(11) degrees.
(Checksum). (Check bit)
$GPVTG Ground Speed information
Example: $GPVTG, 0.0,t,,m,0.00,n,0.0,k*50
Field 0: $GPVTG, statement ID, indicating that the statement is track made good and Ground speed (VTG)
Surface speed Information
Field 1: Motion angle, 000-359, (0 if the number of leading digits is insufficient)
Field 2:t= True North reference frame
Field 3: Motion angle, 000-359, (0 if the number of leading digits is insufficient)
Field 4:m= Magnetic North Reference frame
Field 5: Horizontal Movement Speed (0.00) (0 if the number of leading digits is insufficient)
Field 6:n= section, knots
Field 7: Horizontal Movement Speed (0.00) (0 if the number of leading digits is insufficient)
Field 8:k= km/h, MPH
Field 9: Checksum value
Table 1 main parameters of GPS module
Main parameters of GPS module |
Gps Chipset |
SiRF Star III |
Operating frequency |
L1, 1575.42 MHz |
Coarse capture Code (C/A) Rate |
1.023 MHz Chip Rate |
Track the number of channels simultaneously |
20 |
Sensitivity |
-159 dBm |
Positioning accuracy |
5m (2-D RMS, wide-area differential system allowed) |
Minimum speed |
0.1 m/s |
Time Accuracy |
1μs (synchronized with GPS time) |
Default Coordinates |
1984 World Geodetic Coordinate system (WGS-84) |
Regain time |
0.1S (average) |
Hot start |
1S (average) |
Warm start |
38S (average) |
Cold start |
42S (average) |
Maximum operating altitude |
18km (60000feet) |
Biggest Movement rate |
515m/s (1000knots) |
Maximum acceleration |
4g |
Biggest Rush Degree |
20m/s3 |
Power supply voltage |
5v±0.5v |
Machine current |
Approx. 60mA, no more than 100mA |
Full board shape |
61mmx49mmx17mm |
Gps Chip profile |
27.9mmx20mmx2.9mm |
Baud rate |
9600bps |
Data output format |
SIRF binary format or NMEA 0183 GGA, GSA, GSV, RMC,VTG,GLL |
Data output level |
TTL and RS232 level |
Data Output interface |
20pin pin (TTL level) and DB9 female (RS232 level) |
Antenna type |
External active GPS antenna (3.3v/5v voltage selectable, Default is 3.3V) |
Backup battery |
CR1220 Lithium Battery, 3V, non-rechargeable |
Operating temperature |
40ºc to + 85ºc |
Application design of GPS module
The application design of the GPS module is mainly divided into two parts, the first part is the serial port setting in the data reading, the second part is the data analysis and the need data extraction.
As with other methods of device programming, under Linux, the operation and control of the serial port is done through the operation of the device files. Under Linux, the serial port device file is/DEV/TTYS0 or/DEV/TTYS1, etc. Therefore, to read and write the serial port, we first open the serial port, and then according to the configuration parameters of the GPS module to the serial port baud rate, check, flow control, etc., these parameters are set through the configuration of the Termios structure C_cflag implementation, the serial port configuration part of the function is as follows:
int gps::set_opt (int fd,int nspeed, int nBits, char nevent, int nstop) {struct Termios newtio,oldtio; if (tcgetattr (fd,&oldtio)! = 0) {perror ("Setupserial 1"); return-1; } bzero (&newtio, sizeof (Newtio)); Newtio.c_cflag |= clocal | Cread; Newtio.c_cflag &= ~csize; Switch (nBits) {case 7:newtio.c_cflag |= CS7; Break Case 8:newtio.c_cflag |= CS8; Break } switch (nevent) {case ' O '://Odd check newtio.c_cflag |= Parenb; Newtio.c_cflag |= parodd; Newtio.c_iflag |= (INPCK | Istrip); Break Case ' E '://Parity Newtio.c_iflag |= (INPCK | Istrip); Newtio.c_cflag |= Parenb; Newtio.c_cflag &= ~parodd; Break Case ' N '://No calibration newtio.c_cflag &= ~parenb; Break }switch (nspeed) {case 2400:cfsetispeed (&newtio, B2400); CfsetoSpeed (&newtio, B2400); Break Case 4800:cfsetispeed (&newtio, B4800); Cfsetospeed (&newtio, B4800); Break Case 9600:cfsetispeed (&newtio, B9600); Cfsetospeed (&newtio, B9600); Break Case 115200:cfsetispeed (&newtio, B115200); Cfsetospeed (&newtio, B115200); Break Default:cfsetispeed (&newtio, B9600); Cfsetospeed (&newtio, B9600); Break } if (nstop = = 1) {Newtio.c_cflag &= ~CSTOPB; } else if (nstop = = 2) {Newtio.c_cflag |= CSTOPB; } Newtio.c_cc[vtime] = 0; Newtio.c_cc[vmin] = 0; Tcflush (Fd,tciflush); if ((Tcsetattr (fd,tcsanow,&newtio))!=0) {qdebug () << "com set error" <<endl; return-1; } qdebug () << "Set done!" <<endl; return 0;}
In the processing of GPS data first put the window data into a string, and then through the judgment of the string data to extract the data content, the judgment is divided into two steps, first of all to determine what type of data, in the design of the program need to read $GPRMC and $gpgga two sets of data, so first judge the string Gps_ BUF[5] is C or a, because the data is separated by the symbol "," so that the data location is determined by finding ",". On the implementation will get the comma position function separately encapsulated call, the program is as follows:
Gets the comma position of the specified ordinal int gps::getcomma (int num,char *str) { int i,j=0; int Len=strlen (str); for (i=0;i<len;i++) { if (str[i]== ', ') { j + +; } if (j==num) return i+1; } return 0;}
Next, according to the data format, through the comma location, extract the data information, the program is as follows:
void Gps::gps_parse () {int tmp; char c; c = gps_buf[5]; if (c== ' C ') {//"GPRMC" Gps->d.hour = (gps_buf[7]-' 0 ') *10+ (gps_buf[8]-' 0 '); Gps->d.minute = (gps_buf[9]-' 0 ') *10+ (gps_buf[10]-' 0 '); Gps->d.second = (gps_buf[11]-' 0 ') *10+ (gps_buf[12]-' 0 '); TMP = Getcomma (9,GPS_BUF); Gps->d.day = (gps_buf[tmp+0]-' 0 ') *10+ (gps_buf[tmp+1]-' 0 '); Gps->d.month = (gps_buf[tmp+2]-' 0 ') *10+ (gps_buf[tmp+3]-' 0 '); Gps->d.year = (gps_buf[tmp+4]-' 0 ') *10+ (gps_buf[tmp+5]-' 0 ') +2000; Gps->status = Gps_buf[getcomma (2,gps_buf)]; Gps->latitude = Get_locate (Get_double_number (&gps_buf[getcomma (3,GPS_BUF))); Gps->ns = Gps_buf[getcomma (4,gps_buf)]; Gps->longitude= get_locate (Get_double_number (&gps_buf[getcomma (5,GPS_BUF))); Gps->ew = Gps_buf[getcomma (6,gps_buf)]; Gps->speed = Get_double_number (&gps_buf[getcomma (7,GPS_BUF)]); UTC2BTC (&Amp GPS->D); } if (c== ' A ') {//"$GPGGA" Gps->high = Get_double_number (&gps_buf[getcomma (9,GPS_BUF)]); }//converts the obtained text information to a double double Gps::get_double_number (char *s) {char buf[128]; int i; Double Rev; I=getcomma (1,s); strncpy (Buf,s,i); buf[i]=0; Rev=atof (BUF); return rev;} Double gps::get_locate (double temp) {int m; Double N; m= (int) temp/100; n= (temp-m*100)/60; N=n+m; return n;}
GPS data reading and processing