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
#include <stdio.h>#include<string.h>intMain () {Chars[ +],*p; intcheck,sum,hour,min,sec; Do{scanf ("%s", s); if(s[0]=='$'&& s[1]=='G'&&s[2]=='P'&&s[3]=='R'&&s[4]=='M'&&s[5]=='C') { for(p=s+7; *p!=',';p + +);//find the location of the position, just started to lose the 19th place, the result is wrong, it is a big hole if(* (p+1)=='A') {p=s; Check=*(++p); for(p=p+1; *p!='*';p + +)//make a different or calculated{Check= check^ (*p); } P++; Sum=0; for(; *p!=' /';p + +)//convert 16 binary to 10 binary { if(*p>='0'&& *p<='9') {sum= sum* -+*p-'0'; }Else if(*p>='A'&& *p<='F') {sum= sum* -+*p-'A'+Ten; } } if(sum== (check%65536))//Recording Time{Hour= (s[7]-'0')*Ten+s[8]-'0'+8; if(hour>= -) hour=hour- -; Min= (s[9]-'0')*Ten+s[Ten]-'0'; SEC= (s[ One]-'0')*Ten+s[ A]-'0'; } } } } while(strcmp (s),"END")!=0); printf ("%02d:%02d:%02d\n", hour,min,sec); return 0;}
GPS data Processing Onge Teacher C Programming cap 10th Chapter programming problem