GPS decoding is actually very simple. Generally, if the GPS module is powered on, it will not stop sending packets. You can check the next few packets to understand it.
For more information, see the NMEA protocol. Most useful packages are strings starting with $ uplmc.
Replace the UTC time plus 8 with the UTC time in the UTC time zone, and then replace the latitude and longitude speed, the height, and other turtles in the zone with memcpy!
For more information, see the following code.
Void gps_info_out ()
{
While (receivedata_temp.find (0x0d )! =-1) & (receivedata_temp.find (0x0a )! =-1 ))
{
Bool up_jw = 1; // whether to refresh the longitude and latitude
Bool up_date = 1; // whether to refresh the date
Int startlf = receivedata_temp.find (0x0a );
Int endcr = receivedata_temp.find (0x0d );
If (startlf> endcr)
Endcr = receivedata_temp.find (0x0d, startlf );
Cstring MSG = receivedata_temp.mid (startlf + 1, endCR-startLF-1 );
Receivedata_temp.delete (0, endcr + 1 );
If (msg. Left (6). Compare (_ T ("$ uplmc "))! = 0) // determine the header
{
Continue;
}
MSG. Delete (0, MSG. Find (',') + 1 );
Wchar_t * ptime = msg. getbuffer (msg. getlength () + 1 );
Int hour, Min, SEC;
Wchar_t hour_t [3];
Wchar_t min_t [3];
Wchar_t sec_t [3];
Wchar_t year_t [3];
Wchar_t mon_t [3];
Wchar_t day_t [3];
Wchar_t T2 [10];
Memset (temp, 0, 9 );
Memcpy (hour_t, ptime, 4 );
Memcpy (min_t, ptime + 2, 4 );
Memcpy (sec_t, ptime + 4, 4 );
Hour = _ wtoi (hour_t );
Min = _ wtoi (min_t );
SEC = _ wtoi (sec_t );
MSG. releasebuffer ();
MSG. Delete (0, MSG. Find (',') + 1 );
If (msg. getat (0 )! = 'A') // determines whether the data is valid. A is valid.
{
Continue;
}
MSG. Delete (0, MSG. Find (',') + 1 );
Cstring longpolling = MSG. Left (2 );
// Longpolling + = "'";
Cstring longituded = msg. mid (2, 6 );
Double longituded1;
_ Atlsimplefloatparse (longpolling, longituded1 );
Double longituded2;
_ Atlsimplefloatparse (longituded, longituded2 );
Longituded2 = longituded2/60;
Longituded1 + = longituded2;
Longituded2 = longituded1 * 3600000;
Long longitudedl = (long) longituded2;
Memcpy (gps_lg, (char *) & longitudedl, 4 );
Changehl (gps_lg, 4 );
// Longpolling + = ".";
MSG. Delete (0, MSG. Find (',') + 1 );
// If (msg. getat (0) = 'n ')
// Longpolling. insert (0, _ T ("N "));
// If (msg. getat (0) ='s ')
// Longpolling. insert (0, _ T ("S "));
MSG. Delete (0, MSG. Find (',') + 1 );
Cstring latitude = MSG. Left (3 );
Cstring latituded = msg. mid (3,6 );
Double latituded1;
_ Atlsimplefloatparse (latitude, latituded1 );
Double latituded2;
_ Atlsimplefloatparse (latituded, latituded2 );
Latituded2 = latituded2/60;
Latituded1 + = latituded2;
Latituded2 = latituded1 * 3600000;
Long latitudedl = (long) latituded2;
Memcpy (gps_la, (char *) & latitudedl, 4 );
Changehl (gps_la, 4 );
// Latitude + = ".";
MSG. Delete (0, MSG. Find (',') + 1 );
// If (msg. getat (0) = 'E ')
// Latitude. insert (0, _ T ("e "));
// If (msg. getat (0) = 'W ')
// Latitude. insert (0, _ T ("W "));
MSG. Delete (0, MSG. Find (',') + 1 );
Cstring strspeed = msg. mid (0, MSG. Find (','));
Double dspeed = _ tcstod (strspeed, null) * 1.852;
Int fspeed = (INT) dspeed;
Memcpy (gps_spd, (char *) & fspeed, 1 );
MSG. Delete (0, MSG. Find (',') + 1 );
Cstring strdirection = msg. mid (0, MSG. Find (','));
Double dDirection = _ tcstod (strdirection, null );
Memcpy (gps_dir, (char *) & dDirection, 1 );
MSG. Delete (0, MSG. Find (',') + 1 );
Wchar_t * pdate = msg. getbuffer (msg. getlength () + 1 );
Int day, Mon, year;
Memset (temp, 0, 9 );
Memcpy (year_t, pdate, 4 );
Memcpy (mon_t, pdate + 2, 4 );
Memcpy (day_t, pdate + 4, 4 );
Day = _ wtoi (year_t );
MON = _ wtoi (mon_t );
Year = _ wtoi (day_t );
If (Year> 40) & (year <97) // judge whether the date is normal
Continue;
Year + = 2000;
Hour + = 8;
If (hour> 23)
{
Day ++;
If (MON = 1 | MON = 3 | MON = 5 | MON = 7 | MON = 8 | MON = 10) & day> 31)
{
Mon ++;
Day = 1;
}
Else if (MON = 12 & day> 31)
{
Year ++;
MON = 1;
Day = 1;
}
Else if (MON = 2)
{
If (year = 2012 | year = 2016 | year = 2020 | year = 2024 | year = 2028)
{
If (day> 29)
{
Mon ++;
Day = 1;
}
}
Else
{
If (day> 28)
{
Mon ++;
Day = 1;
}
}
}
Else if (day> 30 & (MON = 4 | MON = 6 | MON = 9 | MON = 11 ))
{
Mon ++;
Day = 1;
}
}
Hour = hour % 24;
Memcpy (gps_utc, (char *) & year, 2 );
Char tt;
Tt = gps_utc [0];
Gps_utc [0] = gps_utc [1];
Gps_utc [1] = tt;
Memcpy (gps_utc + 2), (char *) & Mon, 1 );
Memcpy (gps_utc + 3), (char *) & Day, 1 );
Memcpy (gps_utc + 4), (char *) & hour, 1 );
Memcpy (gps_utc + 5), (char *) & min, 1 );
Memcpy (gps_utc + 6), (char *) & sec, 1 );
// The latitude is the east longitude e113 '55. 619
M_pos.format (_ T ("% s, % s"), longpolling, latitude );
Gps_state = 1;
MSG. releasebuffer ();
}
}