Esempio n. 1
0
 // Overrides the ConvertTo method of TypeConverter.
 public override object ConvertTo(ITypeDescriptorContext context,
                                  CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string))
     {
         NMEASentence ns = value as NMEASentence;
         return(ns.Name + "," + ns.InPort.ToString() + "," + ns.OutPort1.ToString() + "," + ns.OutPort2.ToString() + "," + ns.OutPort3.ToString() + "," + ns.OutPort4.ToString());
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
Esempio n. 2
0
        void ProcessNMEASentence(NMEASentence sentence)
        {
            var standartSentence = sentence as NMEAStandartSentence;

            if (standartSentence == null)
            {
                return;
            }

            var sentenceId = standartSentence.SentenceId;

            // DEBUG
            Console.WriteLine("GPS: {0} {1}", standartSentence.TalkerId, sentenceId);

            if (_cmdProcessor.ContainsKey(sentenceId))
            {
                _cmdProcessor[sentenceId](standartSentence.Parameters);
            }
        }
Esempio n. 3
0
        private void port_MessageReceived(object sender, NewNMEAMessageEventArgs e)
        {
            NMEASentence sentence = null;
            bool         isParsed = false;

            try
            {
                sentence = NMEAParser.Parse(e.Message);
                isParsed = true;
            }
            catch (Exception ex)
            {
                /// TODO:
            }

            if (isParsed)
            {
                if (sentence is NMEAProprietarySentence)
                {
                    var pSentence = (sentence as NMEAProprietarySentence);
                    if (pSentence.Manufacturer == ManufacturerCodes.MCP)
                    {
                        if (parsers.ContainsKey(pSentence.SentenceIDString))
                        {
                            parsers[pSentence.SentenceIDString](pSentence.parameters);
                        }
                    }
                    else
                    {
                        /// TODO: skip unsupported manufacturer
                    }
                }
                else
                {
                    /// TODO: skip standard sentence
                }
            }
        }
Esempio n. 4
0
        public SetupWindow()
        {
            port1 = new ObservableString();
            port2 = new ObservableString();
            port3 = new ObservableString();
            port4 = new ObservableString();

            InitializeComponent();

            this.DataContext = this;

            if (Properties.Settings.Default.RouteSentence != null)
            {
                RouteSentence = Properties.Settings.Default.RouteSentence;
            }
            if (Properties.Settings.Default.NavSentence != null)
            {
                NavSentence = Properties.Settings.Default.NavSentence;
            }
            if (Properties.Settings.Default.DepthSentence != null)
            {
                DepthSentence = Properties.Settings.Default.DepthSentence;
            }
            if (Properties.Settings.Default.HeadingSentence != null)
            {
                HeadingSentence = Properties.Settings.Default.HeadingSentence;
            }
            if (Properties.Settings.Default.WaterTempSentence != null)
            {
                WaterTempSentence = Properties.Settings.Default.WaterTempSentence;
            }
            if (Properties.Settings.Default.HullSpeedSentence != null)
            {
                HullSpeedSentence = Properties.Settings.Default.HullSpeedSentence;
            }
            if (Properties.Settings.Default.AppWindSentence != null)
            {
                AppWindSentence = Properties.Settings.Default.AppWindSentence;
            }
            if (Properties.Settings.Default.TacktickPerformanceSentence != null)
            {
                TacktickPerformanceSentence = Properties.Settings.Default.TacktickPerformanceSentence;
            }

            RouteSentence.Name               = "Route"; RouteSentence.Comments = "RMB";
            NavSentence.Name                 = "Navigation"; NavSentence.Comments = "RMC";
            DepthSentence.Name               = "Depth"; DepthSentence.Comments = "DPT, DBT";
            HeadingSentence.Name             = "Heading"; HeadingSentence.Comments = "HDG, HDT";
            WaterTempSentence.Name           = "Water Temp"; WaterTempSentence.Comments = "MTW";
            HullSpeedSentence.Name           = "Hull Speed"; HullSpeedSentence.Comments = "VHW";
            AppWindSentence.Name             = "Apparent Wind"; AppWindSentence.Comments = "MWV";
            TacktickPerformanceSentence.Name = "Tacktick performance"; TacktickPerformanceSentence.Comments = "PTAK";

            NMEASentences.Add(RouteSentence);
            NMEASentences.Add(NavSentence);
            NMEASentences.Add(DepthSentence);
            NMEASentences.Add(HeadingSentence);
            NMEASentences.Add(WaterTempSentence);
            NMEASentences.Add(HullSpeedSentence);
            NMEASentences.Add(AppWindSentence);
            NMEASentences.Add(TacktickPerformanceSentence);


            foreach (string s in SerialPort.GetPortNames())
            {
                Combobox1.Items.Add(s);
                Combobox2.Items.Add(s);
                Combobox3.Items.Add(s);
                Combobox4.Items.Add(s);
            }

            Combobox1.Items.Add("None");
            Combobox2.Items.Add("None");
            Combobox3.Items.Add("None");
            Combobox4.Items.Add("None");

            if (Properties.Settings.Default.Port1 != "")
            {
                Combobox1.SelectedValue = Properties.Settings.Default.Port1;
            }
            else
            {
                Combobox1.SelectedIndex = 0;
            }
            if (Properties.Settings.Default.Port2 != "")
            {
                Combobox2.SelectedValue = Properties.Settings.Default.Port2;
            }
            else
            {
                Combobox2.SelectedIndex = 0;
            }
            if (Properties.Settings.Default.Port3 != "")
            {
                Combobox3.SelectedValue = Properties.Settings.Default.Port3;
            }
            else
            {
                Combobox3.SelectedIndex = 0;
            }
            if (Properties.Settings.Default.Port4 != "")
            {
                Combobox4.SelectedValue = Properties.Settings.Default.Port4;
            }
            else
            {
                Combobox4.SelectedIndex = 0;
            }

            if (Combobox1.SelectedValue != null)
            {
                port1.Value = Combobox1.SelectedValue.ToString();
            }
            if (Combobox2.SelectedValue != null)
            {
                port2.Value = Combobox2.SelectedValue.ToString();
            }
            if (Combobox3.SelectedValue != null)
            {
                port3.Value = Combobox3.SelectedValue.ToString();
            }
            if (Combobox4.SelectedValue != null)
            {
                port4.Value = Combobox4.SelectedValue.ToString();
            }

            dataGrid1.DataContext = NMEASentences;

            textBox1.Text = Properties.Settings.Default.MagVar.ToString();
        }
Esempio n. 5
0
        public override void ProcessIncoming(NMEASentence sentence)
        {
            if (sentence is NMEAStandartSentence)
            {
                NMEAStandartSentence nSentence = (sentence as NMEAStandartSentence);

                if (detected)
                {
                    ResetTimer();
                }

                if (nSentence.SentenceID == SentenceIdentifiers.HDT)
                {
                    if (!detected)
                    {
                        detected = true;
                    }

                    double hdn = O2D(nSentence.parameters[0]);
                    if (!double.IsNaN(hdn))
                    {
                        Heading = hdn;
                        HeadingUpdated.Rise(this, new EventArgs());
                    }
                }
                else if (nSentence.SentenceID == SentenceIdentifiers.RMC)
                {
                    if (!detected)
                    {
                        detected = true;
                    }

                    DateTime tStamp = nSentence.parameters[0] == null ? DateTime.MinValue : (DateTime)nSentence.parameters[0];

                    var      latitude         = O2D(nSentence.parameters[2]);
                    var      longitude        = O2D(nSentence.parameters[4]);
                    var      groundSpeed      = O2D(nSentence.parameters[6]);
                    var      courseOverGround = O2D(nSentence.parameters[7]);
                    DateTime dateTime         = nSentence.parameters[8] == null ? DateTime.MinValue : (DateTime)nSentence.parameters[8];

                    bool isValid = (nSentence.parameters[1].ToString() != "Invalid") &&
                                   (!double.IsNaN(latitude)) && latitude.IsValidLatDeg() &&
                                   (!double.IsNaN(longitude)) && longitude.IsValidLonDeg() &&
                                   (!double.IsNaN(groundSpeed)) &&
                                   (nSentence.parameters[11].ToString() != "N");

                    if (isValid)
                    {
                        dateTime    = dateTime.AddHours(tStamp.Hour);
                        dateTime    = dateTime.AddMinutes(tStamp.Minute);
                        dateTime    = dateTime.AddSeconds(tStamp.Second);
                        dateTime    = dateTime.AddMilliseconds(tStamp.Millisecond);
                        groundSpeed = 3.6 * NMEAParser.Bend2MpS(groundSpeed);

                        if (nSentence.parameters[3].ToString() == "S")
                        {
                            latitude = -latitude;
                        }
                        if (nSentence.parameters[5].ToString() == "W")
                        {
                            longitude = -longitude;
                        }

                        Latitude         = latitude;
                        Longitude        = longitude;
                        GroundSpeed      = groundSpeed;
                        CourseOverGround = courseOverGround;
                        GNSSTime         = dateTime;

                        LocationUpdated.Rise(this, new EventArgs());
                    }
                }
            }
        }
Esempio n. 6
0
 public UnknownSentenceEventArgs(NMEASentence sentence)
 {
     Sentence = sentence;
 }
Esempio n. 7
0
        private void port_NewNMEAMessageReceived(object sender, NewNMEAMessageEventArgs e)
        {
            bool         isParsed = false;
            NMEASentence result   = null;

            OnInfoEvent(string.Format(">> {0}", e.Message));

            try
            {
                result   = NMEAParser.Parse(e.Message);
                isParsed = true;
            }
            catch (Exception ex)
            {
                OnInfoEvent(string.Format("\"{0}\" caused \"{1}\", TargetSite: {2}", e.Message, ex.Message, ex.TargetSite));
            }

            if (isParsed)
            {
                if (result is NMEAProprietarySentence)
                {
                    NMEAProprietarySentence pResult = (result as NMEAProprietarySentence);

                    if (pResult.Manufacturer == ManufacturerCodes.UWV)
                    {
                        ICs sentenceID = uWAVE.ICsByMessageID(pResult.SentenceIDString);

                        if (sentenceID != ICs.IC_INVALID)
                        {
                            if (parsers.ContainsKey(sentenceID))
                            {
                                parsers[sentenceID](pResult.parameters);
                            }
                            else
                            {
                                // skip unsupported sentence
                                if (UnknownSentenceReceived != null)
                                {
                                    UnknownSentenceReceived.Rise(this, new UnknownSentenceEventArgs(result));
                                }
                                else
                                {
                                    OnInfoEvent(string.Format("WARNING: unsupported sentence identifier \"{0}\" (\"{1}\") in \"{2}\"", sentenceID, pResult.SentenceIDString, e.Message));
                                }
                            }
                        }
                        else
                        {
                            // skip unknown sentence ID
                            if (UnknownSentenceReceived != null)
                            {
                                UnknownSentenceReceived.Rise(this, new UnknownSentenceEventArgs(result));
                            }
                            else
                            {
                                OnInfoEvent(string.Format("WARNING: unsupported sentence identifier \"{0}\" in \"{1}\"", pResult.SentenceIDString, e.Message));
                            }
                        }
                    }
                    else
                    {
                        // skip unsupported manufacturer ID
                        if (UnknownSentenceReceived != null)
                        {
                            UnknownSentenceReceived.Rise(this, new UnknownSentenceEventArgs(result));
                        }
                        else
                        {
                            OnInfoEvent(string.Format("WARNING: unsupported manufacturer identifier \"{0}\" in \"{1}\"", pResult.SentenceIDString, e.Message));
                        }
                    }
                }
                else
                {
                    // skip standard sentence
                    if (UnknownSentenceReceived != null)
                    {
                        UnknownSentenceReceived.Rise(this, new UnknownSentenceEventArgs(result));
                    }
                    else
                    {
                        OnInfoEvent(string.Format("WARNING: unsupported standard sentence \"{0}\"", e.Message));
                    }
                }
            }
        }
Esempio n. 8
0
        private void DataReceivedEvent(object sender, SerialDataReceivedEventArgs e)
        {
            String inBuff;

            if (port.IsOpen)
            {
                inBuff = port.ReadExisting();
                if (inBuff != null)
                {
                    if (inBuff.StartsWith("$"))
                    {
                        inString = inBuff;
                    }
                    else
                    {
                        inString += inBuff;
                    }

                    if ((inString.StartsWith("$GPRMC") || inString.StartsWith("$GPGGA")) && inString.EndsWith("\r\n"))
                    {
                        try
                        {
                            NMEASentence sentence = NMEAParser.Parse(inString);
                            String       text     = "";
                            foreach (Object obj in sentence.parameters)
                            {
                                String outString;
                                if (obj == null)
                                {
                                    outString = "null";
                                }
                                else
                                {
                                    outString = obj.ToString();
                                }
                                text += outString + System.Environment.NewLine;
                            }

                            if (inString.StartsWith("$GPGGA"))
                            {
                                if (sentence.parameters[5].Equals("Fix not availible"))
                                {
                                    this.fix = false;
                                    this.setValue(-1f);
                                }
                                else
                                {
                                    this.fix = true;
                                }
                            }
                            else
                            {
                                if (fix)
                                {
                                    float f;
                                    float.TryParse(sentence.parameters[6].ToString(), out f);

                                    //Convert to m/s
                                    f = f * (463f / 900f);

                                    //Convert to km/h
                                    f = f * 3.6f;

                                    this.setValue(f);
                                    this.status = SensorStatus.CONNECTED;
                                }
                            }
                        }
                        catch (ArgumentException aex)
                        {
                            Console.WriteLine(inString, aex);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        private void inPort_NewNMEAMessage(object sender, NewNMEAMessageEventArgs e)
        {
            NMEASentence parsedSentence = null;
            bool         isParsed       = false;

            logger.Write(string.Format("{0} >> {1}", inPort.PortName, e.Message));

            try
            {
                parsedSentence = NMEAParser.Parse(e.Message);
                isParsed       = true;
            }
            catch (Exception ex)
            {
                ProcessException(ex, false);
            }

            if (isParsed && (parsedSentence is NMEAProprietarySentence))
            {
                NMEAProprietarySentence pResult = (parsedSentence as NMEAProprietarySentence);
                if ((pResult.Manufacturer == ManufacturerCodes.VLB) &&
                    (pResult.SentenceIDString == "L"))
                {
                    // $PVLBL,ownLat,ownLon,ownDepth,ownBatV,targetDataID,targetDataValue,propagationTime,MSR
                    double        ownLat  = doubleNullChecker(pResult.parameters[0]);
                    double        ownLon  = doubleNullChecker(pResult.parameters[1]);
                    double        ownDpt  = doubleNullChecker(pResult.parameters[2]);
                    double        ownBatV = doubleNullChecker(pResult.parameters[3]);
                    RC_CODES_Enum dataID  = (RC_CODES_Enum)Enum.ToObject(typeof(RC_CODES_Enum), intNullChecker(pResult.parameters[4]));
                    double        dataVal = doubleNullChecker(pResult.parameters[5]);
                    double        pTime   = doubleNullChecker(pResult.parameters[6]);
                    double        msr     = doubleNullChecker(pResult.parameters[7]);

                    if ((!double.IsNaN(ownLat)) && (!double.IsNaN(ownLon)))
                    {
                        ownLatitude.Value  = ownLat;
                        ownLongitude.Value = ownLon;

                        if (!is_g_updated)
                        {
                            g            = UCNLPhysics.PHX.PHX_GravityConstant_Calc(ownLat);
                            is_g_updated = true;
                            logger.Write(string.Format(CultureInfo.InvariantCulture, "Gravity constant updated: {0:F04} m/s^2", g));
                        }
                    }

                    if (!double.IsNaN(ownDpt))
                    {
                        ownDepth.Value = ownDpt;
                    }

                    if (!double.IsNaN(ownBatV))
                    {
                        ownBatteryVoltage.Value = ownBatV;
                    }

                    if (!double.IsNaN(pTime))
                    {
                        targetPTime.Value = pTime;
                    }

                    if (!double.IsNaN(msr))
                    {
                        targetMSR.Value = msr;
                    }

                    if (!double.IsNaN(dataVal))
                    {
                        if (dataID == RC_CODES_Enum.RC_DPT_GET)
                        {
                            targetDepth.Value = dataVal;
                        }
                        else if (dataID == RC_CODES_Enum.RC_TMP_GET)
                        {
                            targetTemperature.Value = dataVal;
                            TryUpdateSoundSpeed();
                        }
                        else if (dataID == RC_CODES_Enum.RC_BAT_V_GET)
                        {
                            targetBatVoltage.Value = dataVal;
                        }
                    }

                    if (!double.IsNaN(ownLat) && !double.IsNaN(ownLon) && !double.IsNaN(ownDpt))
                    {
                        if (!double.IsNaN(pTime) &&
                            targetDepth.IsInitializedAndNotObsolete)
                        {
                            vlblCore.TargetDepth = targetDepth.Value;
                            vlblCore.AddMeasurement(new VLBLTOAMeasurement(ownLat, ownLon, ownDpt, pTime * soundSpeedMps));

                            UpdateTrack("Measurements", new GeoPoint3D(ownLat, ownLon, ownDpt));
                        }
                        else
                        {
                            UpdateTrack("Rover", new GeoPoint3D(ownLat, ownLon, ownDpt));
                        }
                    }
                }
            }
        }
Esempio n. 10
0
 public abstract void ProcessIncoming(NMEASentence sentence);