Exemplo n.º 1
0
 private void FireNewMessage(NmeaMsg msg)
 {
     if (msg == null)
     {
         return;
     }
     if (NewMessage != null)
     {
         try
         {
             NewMessage(msg);
         }
         catch {}
     }
 }
Exemplo n.º 2
0
 public void Add(NmeaMsg msg)
 {
     if(msg == null)
     {
         return;
     }
     if (handlers == null)
     {
         handlers = new ArrayList();
     }
     for(int i = 0; i < handlers.Count; ++i)
     {
         NmeaMsg m = (NmeaMsg)handlers[i];
         if(m.id == msg.id)
         {
             // already there
             return;
         }
     }
     handlers.Add(msg);
 }
Exemplo n.º 3
0
 public void Add(NmeaMsg msg)
 {
     if (msg == null)
     {
         return;
     }
     if (handlers == null)
     {
         handlers = new ArrayList();
     }
     for (int i = 0; i < handlers.Count; ++i)
     {
         NmeaMsg m = (NmeaMsg)handlers[i];
         if (m.id == msg.id)
         {
             // already there
             return;
         }
     }
     handlers.Add(msg);
 }
Exemplo n.º 4
0
        private void ParseLine(string line)
        {
            if ((line == null) || (line.Length <= 0))
            {
                return;
            }
            NmeaMsg outMsg = null;

            try
            {
                int csIndex = line.LastIndexOf('*');
                if (csIndex <= 0)
                {
                    return;
                }
                csIndex++;
                if (csIndex >= line.Length)
                {
                    return;
                }
                string   cs       = line.Substring(csIndex, line.Length - csIndex);
                string   tempLine = line.Substring(0, csIndex - 1);
                string[] parts    = tempLine.ToUpper().Split(',');
                if (parts.Length <= 0)
                {
                    return;
                }
                if (!ValidateChecksum(tempLine, cs))
                {
                    return;
                }
                outMsg = handler.Parse(parts);
            }
            catch (Exception ex)
            {
                outMsg = new Error(line, ex);
            }
            FireNewMessage(outMsg);
        }
Exemplo n.º 5
0
 public NmeaMsg Parse(string[] nmea)
 {
     if ((nmea == null) || (nmea.Length <= 0))
     {
         return(null);
     }
     if (handlers == null)
     {
         return(null);
     }
     for (int i = 0; i < handlers.Count; ++i)
     {
         NmeaMsg m = (NmeaMsg)handlers[i];
         if (m.CanHandle(nmea))
         {
             NmeaMsg result = m.CreateEmpty();
             result.FromNMEA(nmea);
             return(result);
         }
     }
     return(null);
 }
Exemplo n.º 6
0
 void parser_NewMessage(NmeaMsg msg)
 {
     SendData(bgWnd.Hwnd, 0, msg.ToString());
     System.Diagnostics.Debug.WriteLine("### GPS sat data: '" + msg.ToString() + "'");
 }
Exemplo n.º 7
0
 private void FireNewMessage(NmeaMsg msg)
 {
     if (msg == null) return;
     if (NewMessage != null)
     {
         try
         {
             NewMessage(msg);
         }
         catch{}
     }
 }
 private void HandleNewMessage(NmeaMsg msg)
 {
     Field f = null;
     bool newPosition = (msg.id == cycleStartMsgType);
     switch(msg.id)
     {
         case NmeaMsg.MsgType.GGA:
             f = (Field)msg.Fields[GGA.FieldIds.PositionFixIndicator];
             if ((f != null) && f.HasValue)
             {
                 position.positionFixIndicator = f.GetInt(position.positionFixIndicator);
             }
             f = (Field)msg.Fields[GGA.FieldIds.X];
             if((f != null) && f.HasValue)
             {
                 position.x = f.GetDouble(position.x);
             }
             f = (Field)msg.Fields[GGA.FieldIds.Y];
             if ((f != null) && f.HasValue)
             {
                 position.y = f.GetDouble(position.y);
             }
             f = (Field)msg.Fields[GGA.FieldIds.Utc];
             if ((f != null) && f.HasValue)
             {
                 position.time = f.GetTime(position.time);
             }
             f = (Field)msg.Fields[GGA.FieldIds.Satelites];
             if ((f != null) && f.HasValue)
             {
                 position.satelites = f.GetInt(position.satelites);
             }
             f = (Field)msg.Fields[GGA.FieldIds.Hdop];
             if ((f != null) && f.HasValue)
             {
                 position.hdop = f.GetInt(position.hdop);
             }
             break;
         case NmeaMsg.MsgType.RMC:
             f = (Field)msg.Fields[RMC.FieldIds.Status];
             if ((f != null) && f.HasValue)
             {
                 char status = f.GetChar((char)0);
                 if(status == 'A') // read data only if valid
                 {
                     f = (Field)msg.Fields[RMC.FieldIds.X];
                     if ((f != null) && f.HasValue)
                     {
                         position.x = f.GetDouble(position.x);
                     }
                     f = (Field)msg.Fields[RMC.FieldIds.Y];
                     if ((f != null) && f.HasValue)
                     {
                         position.y = f.GetDouble(position.y);
                     }
                     f = (Field)msg.Fields[RMC.FieldIds.Utc];
                     if ((f != null) && f.HasValue)
                     {
                         position.time = f.GetTime(position.time);
                     }
                     f = (Field)msg.Fields[RMC.FieldIds.Date];
                     if ((f != null) && f.HasValue)
                     {
                         position.date = f.GetDate(position.date);
                     }
                     f = (Field)msg.Fields[RMC.FieldIds.Speed];
                     if ((f != null) && f.HasValue)
                     {
                         position.speed = f.GetDouble(position.speed);
                     }
                     f = (Field)msg.Fields[RMC.FieldIds.Course];
                     if ((f != null) && f.HasValue)
                     {
                         position.course = f.GetDouble(position.course);
                     }
                 }
             }
             break;
     }
     if(newPosition)
     {
         this.FireNewPosition();
     }
 }
        private void HandleNewMessage(NmeaMsg msg)
        {
            Field f           = null;
            bool  newPosition = (msg.id == cycleStartMsgType);

            switch (msg.id)
            {
            case NmeaMsg.MsgType.GGA:
                f = (Field)msg.Fields[GGA.FieldIds.PositionFixIndicator];
                if ((f != null) && f.HasValue)
                {
                    position.positionFixIndicator = f.GetInt(position.positionFixIndicator);
                }
                f = (Field)msg.Fields[GGA.FieldIds.X];
                if ((f != null) && f.HasValue)
                {
                    position.x = f.GetDouble(position.x);
                }
                f = (Field)msg.Fields[GGA.FieldIds.Y];
                if ((f != null) && f.HasValue)
                {
                    position.y = f.GetDouble(position.y);
                }
                f = (Field)msg.Fields[GGA.FieldIds.Utc];
                if ((f != null) && f.HasValue)
                {
                    position.time = f.GetTime(position.time);
                }
                f = (Field)msg.Fields[GGA.FieldIds.Satelites];
                if ((f != null) && f.HasValue)
                {
                    position.satelites = f.GetInt(position.satelites);
                }
                f = (Field)msg.Fields[GGA.FieldIds.Hdop];
                if ((f != null) && f.HasValue)
                {
                    position.hdop = f.GetInt(position.hdop);
                }
                break;

            case NmeaMsg.MsgType.RMC:
                f = (Field)msg.Fields[RMC.FieldIds.Status];
                if ((f != null) && f.HasValue)
                {
                    char status = f.GetChar((char)0);
                    if (status == 'A')    // read data only if valid
                    {
                        f = (Field)msg.Fields[RMC.FieldIds.X];
                        if ((f != null) && f.HasValue)
                        {
                            position.x = f.GetDouble(position.x);
                        }
                        f = (Field)msg.Fields[RMC.FieldIds.Y];
                        if ((f != null) && f.HasValue)
                        {
                            position.y = f.GetDouble(position.y);
                        }
                        f = (Field)msg.Fields[RMC.FieldIds.Utc];
                        if ((f != null) && f.HasValue)
                        {
                            position.time = f.GetTime(position.time);
                        }
                        f = (Field)msg.Fields[RMC.FieldIds.Date];
                        if ((f != null) && f.HasValue)
                        {
                            position.date = f.GetDate(position.date);
                        }
                        f = (Field)msg.Fields[RMC.FieldIds.Speed];
                        if ((f != null) && f.HasValue)
                        {
                            position.speed = f.GetDouble(position.speed);
                        }
                        f = (Field)msg.Fields[RMC.FieldIds.Course];
                        if ((f != null) && f.HasValue)
                        {
                            position.course = f.GetDouble(position.course);
                        }
                    }
                }
                break;
            }
            if (newPosition)
            {
                this.FireNewPosition();
            }
        }