예제 #1
0
        public override void processEvents()
        {
            // removing a sentence possibly store in the queue
            int qlen = SentenceQueue.Count();

            if (qlen > 0)
            {
                string sentence = SentenceQueue[qlen - 1];
                SentenceQueue.RemoveAt(qlen - 1);
                // decode the GPRMC sentence
                string[] tokens = parseNMEASentence(sentence);
                if (tokens[0] == "$GPRMC")
                {
                    decodeGPRMCTokens(tokens,
                                      out LatitudeAsDecimal,
                                      out LatDegrees,
                                      out LatMinutes,
                                      out LongitudeAsDecimal,
                                      out LongDegrees,
                                      out LongMinutes,
                                      out SpeedOverGround,
                                      out CourseOverGround,
                                      out UTCDateTime);
                }


                // ************** time retrieved and stored **********
            }
        }
        public override void processEvents()
        {
            // removing a sentence possibly store in the queue
            int qlen = SentenceQueue.Count();
            if (qlen > 0)
            {
                string sentence = SentenceQueue[qlen - 1];
                SentenceQueue.RemoveAt(qlen - 1);
                //Console.WriteLine(sentence);
                List<string> args = parseNMEASentence(string2Bytes(sentence));
                if (args[0] == "GPRMC")
                { // GPRMC sentence
                    // Field 1: UTC Time
                    string thetime = args[1]; // first argument should be the time in hhmmss.sss format
                    if (thetime.Length >=6)
                    {
                        LastUTCHour = (thetime[0] - '0') * 10 + thetime[1] - '0';
                        LastUTCMinute = (thetime[2] - '0') * 10 + thetime[3] - '0';
                        LastUTCSecond = (thetime[4] - '0') * 10 + thetime[5] - '0';
                        if (thetime.Length >=8) LasUTCMillisecond = (thetime[7] - '0') * 10 + thetime[8] - '0';
                    }
                    // Field 2: Valid Data (A - valid, V - invalid)
                    
                    MRCStatus = args[2][0] == 'A' ? true : false;
                    if (MRCStatus)
                    {
                        // Field 3-4: Latitude in format ddmm.mmmm and latitude hemisphere (N/S)
                        string latitude = args[3];
                        LatDegrees = (latitude[0] - '0') * 10 + latitude[1] - '0';
                        LatMinutes = (latitude[2] - '0') * 10 + latitude[3] - '0';
                        LatDeciminutes = (latitude[5] - '0') * 1000 + (latitude[6] - '0') * 100 + (latitude[7] - '0') * 10 + latitude[8] - '0';

                        LatDegrees *= (args[4][0] == 'N') ? 1 : -1;

                        // Field 5 - 6: Longitude in format dddmm.mmmm and longitude hemisphere (E/W)
                        string longitude = args[5];
                        LongDegrees = (longitude[0] - '0') * 100 + (longitude[1] - '0') * 10 + longitude[2] - '0';
                        LongMinutes = (longitude[3] - '0') * 10 + longitude[4] - '0';
                        LongDeciminutes = (longitude[6] - '0') * 1000 + (longitude[7] - '0') * 100 + (longitude[8] - '0') * 10 + longitude[9] - '0';

                        LongDegrees *= args[6][0] == 'E' ? 1 : -1;
                    }
                    else
                    {
                        LatDegrees = LatMinutes = 0;
                        LongDegrees = LongMinutes = LongDeciminutes = 0;
                    }

                    //Field 7: Speed over ground
                    if (MRCStatus)
                    {
                        string speed = args[7];
                        if (speed.Length > 0)
                            SpeedOverGround = Convert.ToDouble(speed);
                        else
                            SpeedOverGround = -1;
                        // Field 8: course over ground
                        string course = args[8];
                        if (course.Length > 0)
                            CourseOverGround = Convert.ToDouble(course);
                        else
                            CourseOverGround = -1;

                        // Field 9: Date
                        string thedate = args[9];
                        int day, month, year;

                        day = (thedate[0] - '0') * 10 + thedate[1] - '0';
                        month = (thedate[2] - '0') * 10 + thedate[3] - '0';
                        year = (thedate[4] - '0') * 10 + thedate[5] - '0';

                        UTCDateTime = new DateTime(2000 + year, month, day, LastUTCHour, LastUTCMinute, LastUTCSecond);
                    }
                    else
                    {
                        SpeedOverGround = -1;
                        CourseOverGround = -1;
                        UTCDateTime = DateTime.Today;
                    }

                    // Field 10 - 11: Magnetic Variation (E/W)
                    /* if (MRCStatus)
                    {
                        string magvar = args[10];
                        if (magvar.Length > 0)
                        {
                            MagVariation = Convert.ToDouble(magvar);

                            MagVariation *= args[11][0] == 'E' ? 1 : -1;
                        } els
                    }
                    else MagVariation = -1; */

                }
                    
                    // ************** time retrieved and stored **********
            }
        }