C Language Programming exercises GPS data processing

Source: Internet
Author: User
Tags uppercase letter

Topic content:

The NMEA-0183 protocol is designed to establish a unified BTCM (Maritime Radio Technical Committee) standard in different GPS (Global Positioning System) navigation equipment, by the National Oceanic Electronics Association (nmea-the Nation Marine Electronics Associa-tion) set up a communication protocol. GPS receiver According to the standard specification of the NMEA-0183 protocol, the location, speed and other information through the serial port to the PC, PDA and other equipment.

NMEA-0183 protocol is the standard protocol that GPS receivers should abide by, and also the most widely used protocol in GPS receivers, most common GPS receivers, GPS data processing software, navigation software comply with or at least compatible with this protocol.

The NMEA-0183 protocol defines a lot of statements, but the most commonly used or most compatible statements are $gpgga, $GPGSA, $GPGSV, $GPRMC, $GPVTG, $GPGLL, and so on.

Where the $GPRMC statement is formatted as follows:

$GPRMC, 024813.640,a,3158.4608,n,11848.3737,e,10.05,324.27,150706,,, a*50

Here the entire statement is a line of text, the line with a comma "," separate the fields, the size of each field (length) is different, the example here is only a possibility, and do not think the size of the field as the above example.

Field 0: $GPRMC, statement ID, indicating that the statement recommends minimum location information for recommended Minimum specific gps/transit Data (RMC)

Field 1:UTC time, hhmmss.sss format

Field 2: status, a= positioning, v= not positioned

Field 3: Latitude ddmm.mmmm, Degree fractal format (0 if the number of leading digits is insufficient)

Field 4: Latitude N (north latitude) or S (South latitude)

Field 5: Longitude dddmm.mmmm, Degree format (0 if the number of leading digits is insufficient)

Field 6: Latitude E (longitude) or W (West)

Field 7: Speed, section, knots

Field 8: Bearing angle, Degree

Field 9:UTC date, ddmmyy format

Field 10: Declination, (000-180) degrees (0 if the number of leading digits is insufficient)

Field 11: Declination direction, e= East w= West

Field 16: Checksum value

Here, "*" is the checksum identifier, followed by a checksum of two digits, representing the hexadecimal value of the XOR value of all characters between "$" and "*", excluding both characters. The checksum of the above clause is hexadecimal 50, which is the decimal 80.

Tip: The function of the ^ operator is XOR. The result of a value of 65536 after the remainder of the values of the number of characters between $ and * (the first character and the second character XOR, the result again and the third character Xor, and so on) should be equal to the value of the two hexadecimal digits after the *, otherwise the statement has an error in the transmission. Note that this hexadecimal value will appear in the uppercase letter of the a-f.

Now your program reads into a series of GPS outputs, which contain $GPRMC and other statements. At the end of the data, there is a single line of

END

Represents the end of the data.

Your program is going to find the $GPRMC statement, calculate the checksum, find out where the checksum is correct, and the field 2 represents the statement that has been positioned, from which the time is calculated and converted into Beijing time. The data will contain multiple $GPRMC statements, with the time of the last statement obtained as the result output.

Your program is bound to read a valid $GPRMC statement.

Input format:

Multiple GPS statements, each ending with a carriage return line. The last line is the end three uppercase letters.

Output format:

6-digit time, expressed as:

Hh:mm:ss

Where HH is a two-digit hour, less than two bits when the front of the 0;mm is a two-digit minute, less than two bits when the front 0;ss is two digits of the second, less than two bits in front of 0.

Input Sample:

$GPRMC, 024813.640,a,3158.4608,n,11848.3737,e,10.05,324.27,150706,,, a*50

END

Sample output:

10:48:13

time limit: 500ms memory limit: 32000kb
1#include <stdio.h>2#include <string.h>3 4 intMain ()5 {6     Chara[ +] ="$GPRMC, 024813.640,a,3158.4608,n,11848.3737,e,10.05,324.27,150706,,, a*50",*p;7     intHour, Min, sec;8     intcheck, value;9      Do {Ten          One gets (a); Ap =A; -  -         if(STRNCMP (A,"$GPRMC",6) ==0&& strncmp (STRCHR (A +6,','),", A",2) ) {//you must pay attention to a positioning here . theCheck = * (+ +p); -              for(p = p +1; *p! ='*'; p++ ) { -Check = Check ^ *p; -             } +Check = check%65536; -  +Value =0; A              for(p = p +1; *p! =' /'; p++)//hexadecimal --and decimal at             { -                 if('A'<= *p && *p <='F' ) -Value = value * -+ *p-'A'+Ten; -                 Else -Value = value * -+ *p-'0'; -             } in  -             if(check) = =value) to             { +Hour = (a[7]-'0')*Ten+ (a[8]-'0')+8; -                 if(Hour > -) thehour-= -; *Min = (a[9]-'0')*Ten+ (a[Ten]-'0'); $SEC = (a[ One]-'0')*Ten+ (a[ A]-'0');Panax Notoginseng             } -         } the  +} while(strcmp (A,"END") !=0 ); A      theprintf"%02d:%02d:%02d\n", Hour, Min, sec); +  -     return 0; $}

C Language Programming exercises GPS data processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.