GPS data parsing

Source: Internet
Author: User
Tags array com crc32

 

Instance download: http://download.csdn.net/detail/fcgksoso/3690014

Some time ago, I did some development work related to data parsing of GPS receivers, because I had to parse the positioning data of GPS receivers and read the motherboard description of a certain model of Novatel, if you have some knowledge about this, record it and make a memo.

 

Currently, satellites of different purposes are flying in the outer space of the earth. One of them is a satellite dedicated to positioning people on the earth, these satellites are composed of multiple satellite positioning systems that are always moving around the Earth. Currently, there are the following satellite positioning systems: GPS in the United States, GLONASS in Russia, and Galileo in Europe) and China's Beidou compass, which has not yet been put into normal use.

These positioning satellites are distributed over the earth according to certain trajectories, so that any point on the earth can receive satellite messages from them-that is, the data needed for positioning. These satellite texts contain some operation data of the satellite, which is compiled and modulated into a certain frequency of electromagnetic waves to broadcast to the Earth at a certain frequency. The Earth receives these satellite signals through a receiver, parses the data contained in the satellite, and uses the data to calculate based on a certain algorithm to obtain the exact location of the local ball.

 

The principle of satellite positioning is roughly as follows: the distance between the receiver and the satellite can be calculated through satellite data transmission, as long as there are more than three satellites at a distance, we can use the space circle intersection method to determine the coordinates of the spatial points in which the receiver is located, that is, the latitude and longitude of the Earth.

 

What the motherboard in the GPS receiver does is to receive and parse the satellite messages it receives, and then organize the data into a certain protocol format for output as needed.

These positioning data is organized in a certain format, such as the NMEA-0183 protocol format, which is an international standard navigation data standard protocol.

In addition, there are some protocol formats developed by the manufacturer of the GPS receiver motherboard, which will have a lot of pages to explain in detail their own data.

To obtain the expected data (such as longitude and latitude, time, Satellite Number, elevation angle, elevation angle, and signal-to-noise ratio) from the output data of the receiver ), the data format of the photo must be processed.

 

For example, the data in the nmea0183 protocol format is $ gpgga, 134658.00, 5106.9792, N, 11402.3003, W, 1.0, 1048.47, 16.27, M,-, M, 08, AAAA * 60.

It contains satellite time, latitude and longitude, elevation, and other information. This is clearly coded data, which is also meaningful to humans. Most of the data is received through serial transmission, read it from the serial port buffer and write the corresponding code to process it.

Take C # as an example:

1. Use the SerialPort class to receive and read data.

List <byte> combuffer = new list <byte> (4096); // Serial Data Processing Buffer int length = com. bytestoread; D = new byte [length]; // temporary serial data array COM. read (D, 0, length); combuffer. addrange (d); // Save the data in the temporary array to the data processing buffer.

2. perform data verification, such as XOR and CRC32.

For (INT I = 1; I <length; I ++) {checknum ^ = inbytes [I]; // from the last digit of the $ sign, the value is equal to or equal to the first digit of the * sign}

 

3. Use the econding. ascll. getstring () method to convert binary format to string format.

4. Use the spilt () method to cut the string and convert the corresponding data into Int or double data.

string[] datasplit = Encoding.ASCII.GetString(b, 0, b.Length).Split(new char[] { ',', '*' });
if (s[1] == "" || s[2] == "" || s[4] == "" || s[3] == "" || s[5] == "" || s[9] == "") return;this.gga.GGAtime = Convert.ToDouble(s[1]);this.gga.Latitude = Convert.ToDouble(s[2]);this.gga.LatNS = Convert.ToChar(s[3]);this.gga.Longtitude = Convert.ToDouble(s[4]);this.gga.LngEW = Convert.ToChar(s[5]);this.gga.Evelvation = Convert.ToSingle(s[9]);

This completes the resolution.

 

Common Data Formats of GPS Receivers-binary data, which is easier to parse than ascll data.

Take C # as an example:

1. Use the SerialPort class to receive and read data.

2. perform data verification, usually CRC32 Verification

                    for (int i = 0; i < length; i++)                    {                        checkNum = CRCTable[(checkNum ^ checkOutData[i]) & 0xFF] ^ (checkNum >> 8);                    }

 

3. Use bitconvert. toint32 () or other methods to obtain the data you want.

            this.Latitude = BitConverter.ToDouble(b, 36) * 100;            this.Longitude = BitConverter.ToDouble(b, 44) * 100;            this.Height = BitConverter.ToDouble(b, 52);            this.LatitudeDeviation = BitConverter.ToSingle(b, 68);            this.LongitudeDeviation = BitConverter.ToSingle(b, 72);            this.HeightDeviation = BitConverter.ToSingle(b, 76);

 

The motherboard manual will detail everything about the data.

 

Hexadecimal display of binary data:

Data header: aa44121c 01000240 20000000 1d1d0000 29160000 running 4c00 55525a80

Data body: 00000000 10000000 1b0450b3 f28e4940 16fa6bbe 7c825cc0 0060769f 449f9040 a62a82c1 3d000000
125acb3f cd9e983f db664040 00303030 00000000 00000000 0b0b0000 00060003

Verification Code: 42dc4c48

 

 

GPS data parsing is roughly like this.

I am just getting started. I wrote this article for the first time to cultivate good habits.

If it is helpful to you, you can support it. If there is something wrong or unclear, please kindly point it out. I'm glad to correct it. Thank you!

If you have any questions, you can write it down and try your best to answer your question ^_^.

 

More detailed reference: http://blog.csdn.net/wuyazhe/article/details/5598945

 

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.