Read and parse the positioning information of GPRS/GNRMC
Frame Header |
UTC time |
Status |
Latitude |
North/South |
Longitude |
Dong Jing/XI Jing |
Speed |
$ Uplmc |
Hhmmss. sss |
A/V |
Ddmm. mmmm |
N/S |
Dddmm. mmmm |
E/W |
Section |
Azimuth |
UTC date |
Magnetic Slip Angle |
Magnetic slip direction |
Mode |
Verification |
Carriage return line feed |
Degrees |
Ddmmyy |
000-180 |
E/W |
A/D/E/N |
* Hh |
CR + LF |
Format: $ gprs mc, <1 >,< 2 >,< 3 >,< 4 >,< 5 >,< 6 >,< 7 >,< 8>, <9>, <10>, <11>, <12> * hh <CR> <LF>
$ Uplmc, 024813.640, A, 3158.4608, N, 11848.3737, E, 10.05, 324.27, 150706, A * 50
Description:
Field 0: $ uplmc, statement ID, indicating that the statement is the Minimum location information Recommended by Recommended Minimum Specific GPS/TRANSIT Data (RMC ).
Field 1: UTC time, hhmmss. sss format
Field 2: Status, A = positioning, V = uncertain
Field 3: latitude ddmm. mmmm, degree score format (add 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 score format (add 0 if the number of leading digits is insufficient)
Field 6: longitude E (eastern longitude) or W (Western longitude)
Field 7: speed, section, Knots (a section is also 1.852 km/hour)
Field 8: azimuth, degree (two-dimensional direction, equivalent to two-dimensional Compass)
Field 9: UTC date, in DDMMYY format
Field 10: Magnetic offset (180-) (0 if the number of leading digits is insufficient)
Field 11: Magnetic angle direction, E = east, W = West
Field 12: mode, A = automatic, D = difference, E = estimation, N = Invalid Data (3.0 protocol content)
Field 13: Check Value
/// <Summary> /// GPS information /// </summary> public class GPSInfo {public string longpolling; // Longitude public string Latitude; // Latitude public string Speed; // speed public string GPSStatus; // GPS status A = valid data; V = Invalid public string GPSTime; // gps time public string GPSHeading; // course} // <summary> // GPS/BD location information parsing // </summary> public static class GPSAnalysisClass {// <summary> /// open the Serial port // </summary> /// <param name = "_ Serial Port "> SerialPort </param> // <param name =" _ PortName "> PortName </param> // <param name =" _ BaudRate "> BaudRate </ param> // <returns> </returns> public static bool OpenSerialPort (SerialPort _ SerialPort, string _ PortName, int _ BaudRate) {bool Ret = false; try {_ SerialPort. close (); _ SerialPort. portName = _ PortName; _ SerialPort. baudRate = _ BaudRate; _ SerialPort. newLine = Environment. newLine; _ SerialPort. Open (); if (_ SerialPort. isOpen) Ret = true;} catch (Exception ex) {Console. writeLine (ex. message); Ret = false;} return Ret ;} /// <summary> /// GNRMC parse [Beidou] /// </summary> /// <param name = "_ RecString"> original string </param>/ // <returns> Beidou Positioning Information </returns> public static GPSInfo GNRMCAnalysis (string _ RecString) {GPSInfo gpsInfo = null; string [] strtemp = _ RecString. split ('\ n'); for (int I = 0; I <strtemp. L Ength; I ++) {string [] strtemp1 = strtemp [I]. split (','); if (strtemp1.Length> = 12) {if (strtemp1 [0] = "$ GNRMC") {gpsInfo = new GPSInfo (); gpsInfo. GPSStatus = strtemp1 [2]; gpsInfo. GPSHeading = strtemp1 [8]; gpsInfo. speed = strtemp1 [7] = ""? "": Convert. ToDouble (Convert. ToDouble (strtemp1 [7]) * 1.852). ToString ("0.0"); gpsInfo. Latitude = strtemp1 [3] = ""? "": GPSTransforming (strtemp1 [3]). ToString ("0.000000"); gpsInfo. longpolling = strtemp1 [5] = ""? "": GPSTransforming (strtemp1 [5]). ToString ("0.000000"); gpsInfo. GPSTime = strtemp1 [9] = ""? "": "20" + strtemp1 [9]. substring (4, 2) + "-" + strtemp1 [9]. substring (2, 2) + "-" + strtemp1 [9]. substring (0, 2) + "" + strtemp1 [1]. substring (0, 2) + ":" + strtemp1 [1]. substring (2, 2) + ":" + strtemp1 [1]. substring (4, 2) ;}} return gpsInfo ;} /// <summary> /// GPRS String Parsing [GPS] /// </summary> /// <param name = "_ RecString"> original string </param> /// <returns> GPS Positioning Information </returns> public static GPSInfo glasmcanalys Is (string _ RecString) {GPSInfo gpsInfo = null; if (! String. IsNullOrEmpty (_ RecString) {_ RecString = _ RecString. Contains ("\ r ")? _ RecString. substring (0, _ RecString. indexOf ("\ r"): _ RecString; string [] seg = _ RecString. split (','); if (seg. length> = 12) {gpsInfo = new GPSInfo (); gpsInfo. GPSStatus = seg [2]; // status gpsInfo. GPSHeading = seg [8]; // angle gpsInfo. speed = seg [7] = ""? "": (Convert. ToDouble (seg [7]) * 1.852). ToString ("0.0"); // speed gpsInfo. Latitude = seg [4] = ""? "": GPSTransforming (seg [3]). ToString ("0.000000"); gpsInfo. longpolling = seg [6] = ""? "": GPSTransforming (seg [5]). ToString ("0.000000"); gpsInfo. GPSTime = seg [9] = ""? "": String. format ("20 {0}-{1}-{2} {3 }:{ 4 }:{ 5}", seg [9]. substring (4), seg [9]. substring (2, 2), seg [9]. substring (0, 2), seg [1]. substring (0, 2), seg [1]. substring (2, 2), seg [1]. substring (4) ;}} return gpsInfo ;} /// <summary> /// the latitude and longitude of the decimal point in seconds format is converted to the latitude and longitude of the decimal point. /// </summary> /// <param name = "_ Value"> the latitude and longitude of the degree in seconds </param> // <returns> decimal longitude and latitude </returns> private static double GPSTransforming (string _ Value) {double Ret = 0.0; string [] TempStr = _ Value. split ('. '); string x = TempStr [0]. substring (0, TempStr [0]. length-2); string y = TempStr [0]. substring (TempStr [0]. length-2, 2); string z = TempStr [1]. substring (0, 4); Ret = Convert. toDouble (x) + Convert. toDouble (y)/60 + Convert. toDouble (z)/600000; return Ret ;}}