Introduction to the design of NetEase cloud Classroom-C language _ Seventh week: pointer and string _2GPS data processing

Source: Internet
Author: User
Tags uppercase letter

2GPS Data Processing (6 points)

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. In addition, if you need to, you can use SSCANF (s, "%d", &i) from the string s to get its expressed integer number to I.

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 Main ()5 {6     Charstr[ -] =" /";7     CharStr1[] ="END";8     CharStr2[] ="$GPRMC";9 Ten     intJiaoyan1, jiaoyan3; One     Charjiaoyan2[3]; A     intJiaoyan4; -  -     intI, J, Len; the  -     inthh, MM, SS; -  -      Do +     { -Gets (str);/*Input String*/ +  A         if(strncmp (str, STR2,6) ==0)/*if the first 6 bits of the string are $GPRMC*/ at         { -              for(Jiaoyan1 = str[1], I =2; Str[i]! ='*'; i++) - /*tip: The function of the ^ operator is XOR. The result of a value after 65536 is taken after the number of characters between $ and * (the first character and the second character XOR, the result then the third character Xor, and so on)*/ -             { -Jiaoyan1 = jiaoyan1^Str[i]; -             } in  -JIAOYAN3 = jiaoyan1%65536; to  +len = strlen (str);/*finding the length of a string*/ -  the              for(i = len-2, j =0; J <3; i++, J + +)/*Remove the value of the two hexadecimal digits after the **/ *             { $JIAOYAN2[J] =Str[i];Panax Notoginseng             } -  theSSCANF (Jiaoyan2,"%x", &jiaoyan4); +             /*%x enters the integer number in hexadecimal format, and if you want, you can use SSCANF (s, "%d", &i) from the string s to get the integer number that it expresses to me. */ A  the             if(jiaoyan3 = = Jiaoyan4)/*If the checksum is correct*/ +             { -SSCANF (str,"$GPRMC,%2d%2d%2d", &hh, &AMP;MM, &ss); $                 /*In addition, if you need to, you can use SSCANF (s, "%d", &i) from the string s to get its expressed integer number to I. */ $             } -         } -} while(strcmp (str, str1)! =0);/*Loop, when the input string is not end, continue looping*/ the  -HH = hh +8;/*Beijing Time*/Wuyi  the     if(HH >= -)/*if more than 24 hours*/ -     { WuHH = hh- -; -     } About  $printf"%02d:%02d:%02d", hh, MM, ss);/*0 in front of less than two bits*/ -}

Introduction to the design of NetEase cloud Classroom-C language _ Seventh week: pointer and string _2GPS 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.