Ejemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();

            timer        = new PrecisionTimer();
            timer.Period = 6000;
            timer.Tick  += new EventHandler(timer_Tick);

            initialPortSpeedCbx.SelectedIndex = 0;
            portNameCbx.Items.AddRange(SerialPort.GetPortNames());

            #region NMEA

            NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.UCN);
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UCN, "L", "x,x,c--c");

            #endregion

            if (portNameCbx.Items.Count > 0)
            {
                portNameCbx.SelectedIndex = 0;
                SetCtrlState(true);
            }
            else
            {
                SetCtrlState(false);
            }
        }
Ejemplo n.º 2
0
        public MainForm()
        {
            InitializeComponent();

            var portNames = SerialPort.GetPortNames();

            if (portNames.Length > 0)
            {
                #region Other

                buoyAddrCbx.Items.AddRange(Enum.GetNames(typeof(RedBASE_Addr)));
                BuoyAddr = RedBASE_Addr.REDBASE_ADDR_INVALID;

                #endregion

                #region NMEA

                NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.TNT);
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "0", "x");                    // ACK $PTNT0,errCode
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "4", "x,x");                  // LOC_DATA_GET $PTNT4,dataID,reserved
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "5", "x,x");                  // LOC_DATA_VAL $PTNT5,dataID,dataVal
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "!", "c--c,x,c--c,x,x,c--c"); // DEV_INFO $PTNT!,sys_moniker,sys_ver,dev_type,core_moniker,core_ver,dev_serial_num
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "7", "x");                    // SETTINGS_GET $PTNT7,reserved
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "8", "x,x");                  // SETTINGS_SET $PTNT8,buoyAddr,isInverted
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "9", "x,x");                  // SETTINGS_VAL $PTNT9,buoyAddr,isInverted

                #endregion

                #region timer

                timer          = new PrecisionTimer();
                timer.Period   = 1000;
                timer.Mode     = Mode.Periodic;
                timer.Tick    += new EventHandler(timer_Tick);
                timer.Started += new EventHandler(timer_Started);
                timer.Stopped += new EventHandler(timer_Stopped);

                #endregion

                #region port

                port = new NMEASerialPort(new SerialPortSettings("COM1", BaudRate.baudRate9600, Parity.None, DataBits.dataBits8, StopBits.One, Handshake.None));
                port.NewNMEAMessage += new EventHandler <NewNMEAMessageEventArgs>(port_NewNMEAMessage);
                port.PortError      += new EventHandler <SerialErrorReceivedEventArgs>(port_Error);
                port.IsRawModeOnly   = false;

                #endregion

                portNameCbx.Items.AddRange(portNames);
                portNameCbx.SelectedIndex = 0;

                State = AppState.PORT_CLOSED;
            }
            else
            {
                State = AppState.PORT_ABSENT;
            }
        }
Ejemplo n.º 3
0
        private void NMEAInit()
        {
            NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.TNT);

            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "0", "x,x");                   // ACK
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "1", "x,x");                   // FLD_SET
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "2", "x,x");                   // FLD_GET
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "3", "x,x");                   // FLD_VALUE
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "4", "x,x");                   // LOC_DATA_GET
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "5", "x,x.x");                 // LOC_DATA_VAL
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "6", "x,x");                   // LOC_ACT_INVOKE
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "!", "c--c,x,c--c,x,x,c--c");  // DEVICE_INFO
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "!!", "c--c,x,c--c,x,x,c--c"); // RED_NODE_DEVICE_INFO
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "H", "x,x");                   // GET_TRACK_ITEM
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "I", "x,x,x,x,x,x.x,x.x,x.x"); // TRACK_POINT_VAL
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "K", "x.x,x.x");               // SET_WAYPOINT
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "L", "x,x.x,x.x,x");           // WAYPOINT_VAL
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "P", "x,x.x");                 // SETVAL
        }
Ejemplo n.º 4
0
        private void NMEAInit()
        {
            NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.TNT);

            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "0", "x,x");                   // ACK
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "1", "x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "2", "x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "3", "x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "4", "xx,xx");                 // LOC_DATA_GET
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "5", "x,x.x");                 // LOC_DATA_VAL
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "6", "xx,xx");                 // LOC_ACT_INVOKE

            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "!", "c--c,x,c--c,x,x,c--c");  // DEVICE_INFO

            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "C", "x.x,x.x,x.x,x.x,x.x,x.x,x.x,x.x,x.x,x.x,x.x,x.x,x.x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "M", "x.x,x.x,x.x,x,x.x,x.x,x.x,x,x.x,x.x,x.x,x,x.x,x.x,x.x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "N", "x.x,x.x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "O", "x.x,x.x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "P", "xx,x.x");                // SETVAL
        }
Ejemplo n.º 5
0
        public RWLT_Core(SerialPortSettings rwltPortSettings, double radialErrorThreshold, double simplexSize,
                         int courseEstimatorFIFOSize, int trkFilterFIFOSize)
        {
            #region parameters

            var basesIDs = Enum.GetValues(typeof(BaseIDs));
            foreach (BaseIDs baseID in basesIDs)
            {
                if (baseID != BaseIDs.BASE_INVALID)
                {
                    BaseBatVoltages.Add(baseID, new AgingValue <double>(4, 10, svoltageFormatter));
                    BaseMSRs.Add(baseID, new AgingValue <double>(4, 10, msrFormatter));
                }
            }

            HDOPState = new AgingValue <DOPState>(4, 10, x => x.ToString().ToUpperInvariant());
            TBAState  = new AgingValue <TBAQuality>(4, 10, x => x.ToString().Replace('_', ' ').ToUpperInvariant());

            TargetLatitude            = new AgingValue <double>(4, 10, latlonFormatter);
            TargetLongitude           = new AgingValue <double>(4, 10, latlonFormatter);
            TargetLocationRadialError = new AgingValue <double>(4, 10, rerrFormatter);
            TargetPressure            = new AgingValue <double>(6, 10, prsFormatter);
            TargetTemperature         = new AgingValue <double>(60, 120, tempFormatter);
            TargetBatVoltage          = new AgingValue <double>(30, 120, svoltageFormatter);
            TargetDepth = new AgingValue <double>(6, 10, dptdstFormatter);
            TargetAlarm = new AgingValue <PingerCodeIDs>(600, 6000, pAlmFormatter);

            DistanceToTarget       = new AgingValue <double>(4, 10, dptdstFormatter);
            ForwardAzimuthToTarget = new AgingValue <double>(4, 10, courseFormatter);
            ReverseAzimuthToTarget = new AgingValue <double>(4, 10, courseFormatter);

            TargetCourse = new AgingValue <double>(4, 10, courseFormatter);

            AUXLatitude  = new AgingValue <double>(4, 10, latlonFormatter);
            AUXLongitude = new AgingValue <double>(4, 10, latlonFormatter);
            AUXTrack     = new AgingValue <double>(4, 10, courseFormatter);
            AUXSpeed     = new AgingValue <double>(4, 10, speedFormatter);

            CEP   = new AgingValue <double>(4, 300, x => string.Format(CultureInfo.InvariantCulture, "{0:F03} m", x));
            DRMS  = new AgingValue <double>(4, 300, x => string.Format(CultureInfo.InvariantCulture, "{0:F03} m", x));
            DRMS2 = new AgingValue <double>(4, 300, x => string.Format(CultureInfo.InvariantCulture, "{0:F03} m", x));
            DRMS3 = new AgingValue <double>(4, 300, x => string.Format(CultureInfo.InvariantCulture, "{0:F03} m", x));

            #endregion

            #region trkFilter

            trkFilter = new TrackFilter(trkFilterFIFOSize);

            #endregion

            #region pCore

            pCore = new PCore2D <GeoPoint3DT>(radialErrorThreshold, simplexSize, Algorithms.WGS84Ellipsoid, courseEstimatorFIFOSize);
            pCore.RadialErrorExeedsThrehsoldEventHandler += new EventHandler(pCore_RadialErrorExeedsThresholdEventHandler);
            pCore.TargetLocationUpdatedExHandler         += new EventHandler <TargetLocationUpdatedExEventArgs>(pCore_TargetLocationUpdatedExEventHandler);
            pCore.BaseQualityUpdatedHandler += new EventHandler <BaseQualityUpdatedEventArgs>(pCore_BaseQualityUpdatedEventHandler);

            #endregion

            #region basesProcessor

            baseProcessor = new RWLT_BaseProcessor(4, 2.0);

            #endregion

            #region NMEA

            if (!nmeaSingleton)
            {
                NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.RWL);
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.RWL, "A", "x,x.x,x.x,x.x,x.x,x,x.x,x.x,x.x");
            }

            #endregion

            #region inPort

            inPort = new NMEASerialPort(rwltPortSettings);
            inPort.NewNMEAMessage += (o, e) =>
            {
                LogEvent.Rise(o, new LogEventArgs(LogLineType.INFO, string.Format("{0} (IN) >> {1}", inPort.PortName, e.Message)));
                NMEAListener.ProcessIncoming(0, e.Message);
            };

            inPort.PortError += (o, e) => LogEvent.Rise(o, new LogEventArgs(LogLineType.ERROR, string.Format("{0} (IN) >> {1}", inPort.PortName, e.EventType.ToString())));

            #endregion

            #region NMEAListener

            NMEAListener = new NMEAMultipleListener();
            NMEAListener.NMEAProprietaryUnsupportedSentenceParsed += new EventHandler <NMEAUnsupportedProprietaryEventArgs>(NMEAPSentenceReceived);
            NMEAListener.RMCSentenceReceived += new EventHandler <RMCMessageEventArgs>(GNSS_RMCSentenceReceived);

            #endregion

            #region timer

            timer        = new PrecisionTimer();
            timer.Period = 100;
            timer.Tick  += (o, e) =>
            {
                if (++systemUpdateTS > systemUpdateLimit)
                {
                    systemUpdateTS = 0;
                    SystemUpdateEvent.Rise(this, new EventArgs());
                }

                if (inPort.IsOpen && (++inPortTimeoutTS > inPortTimeoutLimit))
                {
                    inPortTimeoutTS = 0;
                    InPortTimeout   = true;
                    LogEvent.Rise(this, new LogEventArgs(LogLineType.ERROR, string.Format("{0} (IN) >> TIMEOUT", inPort.PortName)));
                }

                if (AUXGNSSUsed && auxGNSSPort.IsOpen && (++AUXGNSSTimeoutTS > AUXGNSSTimeoutLimit))
                {
                    AUXGNSSTimeoutTS = 0;
                    AUXGNSSTimeout   = true;
                    LogEvent.Rise(this, new LogEventArgs(LogLineType.ERROR, string.Format("{0} (AUX) >> TIMEOUT", auxGNSSPort.PortName)));
                }
            };

            timer.Start();

            #endregion

            statHelper = new List <GeoPoint>();
        }
Ejemplo n.º 6
0
        public uMCPNMEAPort(SerialPortSettings portSettings)
        {
            #region Parsers

            parsers = new Dictionary <string, parserDelegate>()
            {
                { "0", new parserDelegate(LACK_Parse) },
                { "2", new parserDelegate(RACK_Parse) },
                { "3", new parserDelegate(RPKT_Parse) },
                { "5", new parserDelegate(STAT_Parse) }
            };

            #endregion

            #region port

            port = new NMEASerialPort(portSettings);

            port.PortError      += (o, e) => { PortErrorEventHandler.Rise(this, e); };
            port.NewNMEAMessage += new EventHandler <NewNMEAMessageEventArgs>(port_MessageReceived);

            #endregion

            #region nmea

            if (!nmeaSingleton)
            {
                NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.MCP);
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "0", "c--c,x");
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "1", "x,x,x,x,x");
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "2", "h--h");
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "3", "h--h");
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "4", "h--h");
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "5", "x,x");

                //#define IC_D2H_LACK             '0'        // $PMCP0,sentenceID,errCode  - local command ACK
                //#define IC_H2D_STRT             '1'        // $PMCP1,senderID,targetID,selectDefState,selIntMs,toutIntMs - restart protocol with specified params
                //#define IC_D2H_RACK             '2'        // $PMCP2,h--h // sent packet acknowledged
                //#define IC_D2H_RPKT             '3'        // $PMCP3,h--h // packet received
                //#define IC_H2D_SPKT             '4'        // $PMCP4,h--h // send packet
                //#define IC_D2H_STAT             '5'        // $PMCP5,state,select // protocol state changed
            }

            #endregion

            #region timer

            timer        = new PrecisionTimer();
            timer.Period = 1000;
            timer.Mode   = Mode.OneShot;
            timer.Tick  += (o, e) => { PortTimeoutEventHandler.Rise(this, new EventArgs()); IsWaiting = false; };

            #endregion

            #region other

            dataToSend = new TSQueue <byte[]>(128, 128);
            dataToSend.ItemEnqueued += (o, e) => { if (!isWaiting)
                                                   {
                                                       OnPortFree();
                                                   }
            };

            #endregion
        }
Ejemplo n.º 7
0
        public MainForm()
        {
            InitializeComponent();

            #region Paths

            DateTime startTime = DateTime.Now;
            settingsFilePath = Path.ChangeExtension(Application.ExecutablePath, "settings");
            logPath          = Utils.GetDateDirTree(Application.ExecutablePath, "LOG", startTime);
            logFilePath      = Path.Combine(logPath, Utils.GetTimeFileName(startTime, "log"));

            if (!Directory.Exists(logPath))
            {
                Directory.CreateDirectory(logPath);
            }

            #endregion

            #region logger

            logger = new TSLogProvider(logFilePath);
            logger.WriteStart();

            #endregion

            #region settings

            bool settingsOk = false;
            settingsProvider = new SettingsProviderXML <SettingsContainer>();
            settingsProvider.isSwallowExceptions = false;

            try
            {
                settingsProvider.Load(settingsFilePath);
                logger.Write(settingsProvider.Data.ToString());
            }
            catch (Exception ex)
            {
                logger.Write(ex);
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (!settingsOk)
            {
                try
                {
                    settingsProvider.Save(settingsFilePath);
                }
                catch (Exception ex)
                {
                    logger.Write(ex);
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            #endregion

            #region UI

            testMessageTxb.Text = GenerateTestString();
            locDataIdCbx.Items.AddRange(Enum.GetNames(typeof(LOC_DATA_IDs)));
            locDataIdCbx.SelectedIndex = 0;

            List <string> subIDs = new List <string>();
            for (int i = 0; i < Utils.MAX_SUBSCRIBERS; i++)
            {
                subIDs.Add(i.ToString());
            }

            txChIdCbx.Items.AddRange(subIDs.ToArray());
            rxChIdCbx.Items.AddRange(subIDs.ToArray());

            txChId = 0;
            rxChId = 0;

            mainSplit.Enabled = false;

            #endregion

            #region port

            port = new NMEASerialPort(new SerialPortSettings(settingsProvider.Data.RedLINEPortName,
                                                             BaudRate.baudRate9600,
                                                             Parity.None,
                                                             DataBits.dataBits8,
                                                             StopBits.One,
                                                             Handshake.None));
            port.NewNMEAMessage  += new EventHandler <NewNMEAMessageEventArgs>(port_NewNMEAMessage);
            port.PortError       += new EventHandler <SerialErrorReceivedEventArgs>(port_Error);
            port.RawDataReceived += new EventHandler <RawDataReceivedEventArgs>(port_RawData);

            #endregion

            #region timer

            timer        = new PrecisionTimer();
            timer.Tick  += new EventHandler(timer_Tick);
            timer.Period = 1000;

            #endregion

            #region NMEA

            NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.TNT);

            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "!", "c--c,x,c--c,x,x,c--c"); // IC_D2H_DEV_INFO_VAL    $PTNT!,sys_moniker,sys_ver,dev_type,core_moniker,core_ver,dev_serial_num
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "0", "x");                    // IC_D2H_ACK             $PTNT0,errCode

            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "1", "x,x");                  // IC_H2D_FLD_GET         $PTNT1,fldID,reserved
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "2", "x,x");                  // IC_H2D_FLD_SET         $PTNT2,fldID,fldNewValue
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "3", "x,x");                  // IC_D2H_FLD_VAL         $PTNT3,fldID,fldValue

            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "4", "x,x");                  // IC_H2D_LOC_DATA_GET    $PTNT4,locDataID,reserved
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "5", "x,x.x");                // IC_D2H_LOC_DATA_VAL    $PTNT5,locDataID,locDataValue

            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "6", "x,x");                  // IC_H2D_ACT_INVOKE      $PTNT6,actionID,reserved

            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "7", "x,x,x,x");              // IC_H2D_SETTINGS_WRITE  $PTNT7,rxChID,txChID,isRTX,isRvrs
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "8", "x");                    // IC_H2D_SETTINGS_READ   $PTNT8,reserved
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "9", "x,x,x,x");              // IC_D2H_SETTINGS        $PTNT9,rxChID,txChID,isRTX,isRvrs

            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "P", "x,x.x");                // IC_H2D_SETVAL          $PTNTP,valueID,value

            #endregion
        }
Ejemplo n.º 8
0
        public uWAVEPort(string portName, BaudRate portBaudrate)
        {
            #region NMEA init

            if (!singleton)
            {
                NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.UWV);

                #region Common sentences

                // IC_D2H_ACK             $PUWV0,cmdID,errCode
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "0", "c--c,x");

                // IC_H2D_SETTINGS_WRITE  $PUWV1,rxChID,txChID,styPSU,isCmdMode,isACKOnTXFinished,gravityAcc
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "1", "x,x,x.x,x,x,x.x");

                #endregion

                #region Short code messages management sentences

                // IC_H2D_RC_REQUEST      $PUWV2,txChID,rxChID,rcCmdID
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "2", "x,x,x");

                // IC_D2H_RC_RESPONSE     $PUWV3,txChID,rcCmdID,propTime_seс,snr,[value],[azimuth]
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "3", "x,x,x.x,x.x,x.x,x.x");

                // IC_D2H_RC_TIMEOUT      $PUWV4,txChID,rcCmdID
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "4", "x,x");

                // IC_D2H_RC_ASYNC_IN     $PUWV5,rcCmdID,snr,[azimuth]
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "5", "x,x.x,x.x");

                #endregion

                #region Ambient data management sentences

                // IC_H2D_AMB_DTA_CFG     $PUWV6,isWriteInFlash,periodMs,isPrs,isTemp,isDpt,isBatV
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "6", "x,x,x,x,x,x");

                // IC_D2H_AMB_DTA         $PUWV7,prs_mBar,temp_C,dpt_m,batVoltage_V
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "7", "x.x,x.x,x.x,x.x");

                #endregion

                #region Device info

                // IC_H2D_DINFO_GET       $PUWV?,reserved
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "?", "x");

                // IC_D2H_DINFO $PUWV!,serial_number,sys_moniker,sys_version,core_moniker [release],core_version,acBaudrate,rxChID,txChID,totalCh,styPSU,isPTS,isCmdModeDefault
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "!", "c--c,c--c,x,c--c,x,x.x,x,x,x,x.x,x,x");

                #endregion

                #region Packet mode

                // IC_H2D_PT_SETTINGS_READ   $PUWVD,reserved
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "D", "x");

                // IC_D2H_PT_SETTINGS        $PUWVE,isPTMode,ptAddress
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "E", "x,x");

                // IC_H2H_PT_SETTINGS_WRITE  $PUWVF,isSaveInFlash,isPTMode,ptAddress
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "F", "x,x,x");

                // IC_H2D_PT_SEND            $PUWVG,tareget_ptAddress,[maxTries],data
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "G", "x,x,h--h");

                // IC_D2H_PT_FAILED          $PUWVH,tareget_ptAddress,triesTaken,data
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "H", "x,x,h--h");

                // IC_D2H_PT_DLVRD           $PUWVI,tareget_ptAddress,triesTaken,data
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "I", "x,x,h--h");

                // IC_D2H_PT_RCVD            $PUWVJ,sender_ptAddress,data
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "J", "x,h--h");

                #endregion

                #region LBL-related

                // IC_D2H_PT_HEARD          $PUWVK,b_id,b_lat,b_lon,b_toa_s,sender_pt_Address,dataPacket
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "K", "x,x.x,x.x,x.x,x,h--h");

                //IC_D2H_CM_HEARD           $PUWVL,b_id,b_lat,b_lon,b_toa_s,data_ID,dataValue,msr_dB
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "L", "x,x.x,x.x,x.x,x,x.x,x.x");

                #endregion

                singleton = true;
            }

            #endregion

            #region Parsers

            parsers = new Dictionary <ICs, parserDelegate>()
            {
                { ICs.IC_D2H_ACK, new parserDelegate(ACK_Parse) },
                { ICs.IC_D2H_AMB_DTA, new parserDelegate(AMB_DTA_Parse) },
                { ICs.IC_D2H_DINFO, new parserDelegate(DINFO_Parse) },
                { ICs.IC_D2H_RC_ASYNC_IN, new parserDelegate(RC_ASYNC_IN_Parse) },
                { ICs.IC_D2H_RC_RESPONSE, new parserDelegate(RC_RESPONSE_Parse) },
                { ICs.IC_D2H_RC_TIMEOUT, new parserDelegate(RC_TIMEOUT_Parse) },

                { ICs.IC_D2H_PT_SETTINGS, new parserDelegate(PT_SETTINGS_Parse) },
                { ICs.IC_D2H_PT_FAILED, new parserDelegate(PT_FAILED_Parse) },
                { ICs.IC_D2H_PT_DLVRD, new parserDelegate(PT_DLVRD_Parse) },
                { ICs.IC_D2H_PT_RCVD, new parserDelegate(PT_RCVD_Parse) },

                { ICs.IC_D2H_CM_HEARD, new parserDelegate(CM_HEARD) },
                { ICs.IC_D2H_PT_HEARD, new parserDelegate(PT_HEARD) },
            };

            #endregion

            #region port

            port = new NMEASerialPort(new SerialPortSettings(portName,
                                                             portBaudrate,
                                                             System.IO.Ports.Parity.None,
                                                             DataBits.dataBits8,
                                                             System.IO.Ports.StopBits.One,
                                                             System.IO.Ports.Handshake.None));

            port.NewNMEAMessage += new EventHandler <NewNMEAMessageEventArgs>(port_NewNMEAMessageReceived);
            port.PortError      += new EventHandler <SerialErrorReceivedEventArgs>(port_ErrorReceived);
            port.RawDataReceived = new EventHandler <RawDataReceivedEventArgs>(port_RawDataReceived);

            #endregion

            #region timer

            timer        = new PrecisionTimer();
            timer.Mode   = Mode.Periodic;
            timer.Period = 1000;
            timer.Tick  += new EventHandler(timer_Tick);

            #endregion

            #region Misc.

            InitDeviceInformation();

            #endregion
        }
Ejemplo n.º 9
0
        public MainForm()
        {
            InitializeComponent();

            this.Text = string.Format("{0}", Application.ProductName);

            #region file names & paths

            DateTime startTime = DateTime.Now;
            settingsFileName = Path.ChangeExtension(Application.ExecutablePath, "settings");
            logPath          = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "LOG");
            logFileName      = StrUtils.GetTimeDirTreeFileName(startTime, Application.ExecutablePath, "LOG", "log", true);
            snapshotsPath    = StrUtils.GetTimeDirTree(startTime, Application.ExecutablePath, "SNAPSHOTS", false);

            #endregion

            #region logger

            loggerTextAddedEventHandler = new EventHandler <TextAddedEventArgs>(logger_TextAdded);

            logger = new TSLogProvider(logFileName);
            logger.TextAddedEvent += loggerTextAddedEventHandler;
            logger.WriteStart();

            #endregion

            #region settings

            logger.Write("Loading settings...");
            settingsProvider = new SettingsProviderXML <SettingsContainer>();
            settingsProvider.isSwallowExceptions = false;

            try
            {
                settingsProvider.Load(settingsFileName);
            }
            catch (Exception ex)
            {
                ProcessException(ex, true);
            }

            logger.Write(settingsProvider.Data.ToString());

            gtr_RemoteTimeout_S = Convert.ToInt32((GTR.MIN_REM_TOUT_MS / 1000) + 2 * (double)settingsProvider.Data.MaxDistance / 1500) + 1;

            #endregion

            #region NMEA

            NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.TNT);
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "0", "x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "1", "x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "2", "x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "3", "x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "4", "x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "5", "x,x.x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "6", "x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "7", "x,x.x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "8", "x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "9", "x,x.x,x.x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "A", "x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "B", "x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "C", "x,x.x,x.x,x.x,x.x,x.x,x.x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "D", "x,x,x.x,x.x,x.x,x.x,x.x,x.x,x.x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "E", "x,x,x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "!", "c--c,x,c--c,x,x,c--c");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "O", "x.x,x.x");
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.TNT, "P", "x,x.x");

            /*
             #define IC_D2H_ACK              '0'        // $PTNT0,errCode
             #define IC_H2D_FLD_GET          '1'        // $PTNT1,fldID,reserved
             #define IC_H2D_FLD_SET          '2'        // $PTNT2,fldID,fldNewValue
             #define IC_D2H_FLD_VAL          '3'        // $PTNT3,fldID,fldValue
             #define IC_H2D_LOC_DATA_GET     '4'        // $PTNT4,locDataID,reserved
             #define IC_D2H_LOC_DATA_VAL     '5'        // $PTNT5,locDataID,locDataValue
             #define IC_H2D_ACT_INVOKE       '6'        // $PTNT6,actionID,reserved
             #define IC_H2D_LOC_DATA_SET     '7'        // $PTNT7,locDataID,locDataValue
             #define IC_H2D_REM_SEND         '8'        // $PTNT8,targetAddr,codeMsg
             #define IC_D2H_REM_RECEIVED     '9'        // $PTNT9,codeMsg,snrd,dpl
             #define IC_H2D_REM_PING         'A'        // $PTNTA,targetAddr,timeoutMs
             #define IC_D2H_REM_TOUT         'B'        // $PTNTB,targetAddr
             #define IC_D2H_REM_PONG         'C'        // $PTNTC,requestedAddr,snrd,dpl,pTime,[dst],[dpt],[tmp]
             #define IC_D2H_REM_PONGEX       'D'        // $PTNTD,requestedAddr,requestedCmd,receivedValue_decoded,snrd,dpl,pTime,[dst],[dpt],[tmp]
             #define IC_H2D_REM_PINGEX       'E'        // $PTNTE,targetAddr,requestedCmd,timeoutMs
             #define IC_D2H_DEV_INFO_VAL     '!'        // $PTNT!,sys_moniker,sys_ver,dev_type,core_moniker,core_ver,dev_serial_num
             #define IC_D2H_PRETMP_VAL       'O'        // $PTNTO,pressure_mbar,temp_deg_c
             #define IC_H2D_SETVAL           'P'        // $PTNTP,valueID,value
             */

            #endregion

            #region other

            gtrPortErrorEventHandler          = new EventHandler <SerialErrorReceivedEventArgs>(gtrPort_Error);
            gtrPortNewNMEAMessageEventHandler = new EventHandler <NewNMEAMessageEventArgs>(gtrPort_NewNMEAMessage);

            gtrPort = new NMEASerialPort(new SerialPortSettings(settingsProvider.Data.GTRPortName, BaudRate.baudRate9600,
                                                                System.IO.Ports.Parity.None, DataBits.dataBits8, System.IO.Ports.StopBits.One, System.IO.Ports.Handshake.None));

            gtrPort.IsRawModeOnly = false;

            timerTickHandler = new EventHandler(timer_Tick);

            timer        = new PrecisionTimer();
            timer.Mode   = Mode.Periodic;
            timer.Period = 1000;

            timer.Tick += timerTickHandler;
            timer.Start();


            if (settingsProvider.Data.IsGNSSEmulator)
            {
                gnssEmulatorPort = new NMEASerialPort(new SerialPortSettings(settingsProvider.Data.GNSSEmulatorPortName, BaudRate.baudRate9600,
                                                                             Parity.None, DataBits.dataBits8, StopBits.One, Handshake.None));
            }

            measurements = new Measurements(settingsProvider.Data.MeasurementsFIFOSize, settingsProvider.Data.BaseSize);

            bLatitude    = new AgingDouble("F06", "°");
            bLongitude   = new AgingDouble("F06", "°");
            bTemperature = new AgingDouble("F01", "°C");
            bDepth       = new AgingDouble("F03", " m");
            tTemperature = new AgingDouble("F01", "°C");
            tDepth       = new AgingDouble("F02", " m");

            tLatitude    = new AgingDouble("F06", "°");
            tLongitude   = new AgingDouble("F06", "°");
            tRadialError = new AgingDouble("F03", " m");

            tLocation = new List <GeoPoint3DWE>();
            bLocation = new List <GeoPoint>();

            tBestLocation             = new GeoPoint3DWE();
            tBestLocation.Latitude    = double.NaN;
            tBestLocation.Longitude   = double.NaN;
            tBestLocation.RadialError = double.NaN;

            marinePlot.InitTracks(settingsProvider.Data.MeasurementsFIFOSize);
            marinePlot.AddTrack("BOAT GNSS", Color.Blue, 2.0f, 2, settingsProvider.Data.MeasurementsFIFOSize, true);
            marinePlot.AddTrack("BASE", Color.Salmon, 2.0f, 8, settingsProvider.Data.BaseSize, false);
            marinePlot.AddTrack("MEASUREMENTS", Color.Green, 2.0f, 4, settingsProvider.Data.MeasurementsFIFOSize, false);
            marinePlot.AddTrack("TARGET", Color.Black, 2.0f, 4, settingsProvider.Data.MeasurementsFIFOSize, false);
            marinePlot.AddTrack("BEST", Color.Red, 2.0f, 8, 1, false);

            #endregion
        }
Ejemplo n.º 10
0
        public uWAVEPort(string portName, BaudRate portBaudrate)
        {
            #region NMEA init

            if (!singleton)
            {
                NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.UWV);

                // IC_D2H_ACK             $PUWV0,cmdID,errCode
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "0", "c--c,x");

                // IC_H2D_SETTINGS_WRITE  $PUWV1,rxChID,txChID,styPSU,isCmdMode,isACKOnTXFinished,gravityAcc
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "1", "x,x,x.x,x,x,x.x");

                // IC_H2D_RC_REQUEST      $PUWV2,txChID,rxChID,rcCmdID
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "2", "x,x,x");

                // IC_D2H_RC_RESPONSE     $PUWV3,txChID,rcCmdID,propTime_seс,snr,[value],[azimuth]
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "3", "x,x,x.x,x.x,x.x,x.x");

                // IC_D2H_RC_TIMEOUT      $PUWV4,txChID,rcCmdID
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "4", "x,x");

                // IC_D2H_RC_ASYNC_IN     $PUWV5,rcCmdID,snr,[azimuth]
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "5", "x,x.x,x.x");

                // IC_H2D_AMB_DTA_CFG     $PUWV6,isWriteInFlash,periodMs,isPrs,isTemp,isDpt,isBatV
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "6", "x,x,x,x,x,x");

                // IC_D2H_AMB_DTA         $PUWV7,prs_mBar,temp_C,dpt_m,batVoltage_V
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "7", "x.x,x.x,x.x,x.x");

                // IC_D2H_LBLA            $PUWVA,baseID,baseLat,baseLon,baseDpt,baseBat,pingerData,TOAsecond
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "A", "x,x.x,x.x,x.x,x.x,x,x.x");

                // IC_H2D_DINFO_GET       $PUWV?,reserved
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "?", "x");

                // IC_D2H_DINFO $PUWV!,serial_number,sys_moniker,sys_version,core_moniker [release],core_version,acBaudrate,rxChID,txChID,totalCh,styPSU,isPTS,isCmdModeDefault
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.UWV, "!", "c--c,c--c,x,c--c,x,x.x,x,x,x,x.x,x,x");


                singleton = true;
            }

            #endregion

            #region Parsers

            parsers = new Dictionary <ICs, parserDelegate>()
            {
                { ICs.IC_D2H_ACK, new parserDelegate(ACK_Parse) },
                { ICs.IC_D2H_AMB_DTA, new parserDelegate(AMB_DTA_Parse) },
                { ICs.IC_D2H_DINFO, new parserDelegate(DINFO_Parse) },
                { ICs.IC_D2H_RC_ASYNC_IN, new parserDelegate(RC_ASYNC_IN_Parse) },
                { ICs.IC_D2H_RC_RESPONSE, new parserDelegate(RC_RESPONSE_Parse) },
                { ICs.IC_D2H_RC_TIMEOUT, new parserDelegate(RC_TIMEOUT_Parse) },
                { ICs.IC_D2H_LBLA, new parserDelegate(RC_LBLA_Parse) }
            };

            #endregion

            #region port

            port = new NMEASerialPort(new SerialPortSettings(portName,
                                                             portBaudrate,
                                                             System.IO.Ports.Parity.None,
                                                             DataBits.dataBits8,
                                                             System.IO.Ports.StopBits.One,
                                                             System.IO.Ports.Handshake.None));

            port.NewNMEAMessage += new EventHandler <NewNMEAMessageEventArgs>(port_NewNMEAMessageReceived);
            port.PortError      += new EventHandler <SerialErrorReceivedEventArgs>(port_ErrorReceived);
            port.RawDataReceived = new EventHandler <RawDataReceivedEventArgs>(port_RawDataReceived);

            #endregion

            #region timer

            timer        = new PrecisionTimer();
            timer.Mode   = Mode.Periodic;
            timer.Period = 1000;
            timer.Tick  += new EventHandler(timer_Tick);

            #endregion

            #region Misc.

            InitDeviceInformation();

            #endregion
        }
Ejemplo n.º 11
0
        public MainForm()
        {
            InitializeComponent();

            #region filenames

            DateTime startTime = DateTime.Now;
            settingsFileName = Path.ChangeExtension(Application.ExecutablePath, "settings");
            loggerFileName   = StrUtils.GetTimeDirTreeFileName(startTime, Application.ExecutablePath, "LOG", "log", true);
            snapshotsPath    = StrUtils.GetTimeDirTree(startTime, Application.ExecutablePath, "SNAPSHOTS", false);

            #endregion

            #region logger

            logger = new TSLogProvider(loggerFileName);
            logger.WriteStart();
            logger.TextAddedEvent += (o, e) =>
            {
                if (geoPlotCartesian.InvokeRequired)
                {
                    geoPlotCartesian.Invoke((MethodInvoker) delegate
                    {
                        geoPlotCartesian.AppendHistoryLine(e.Text);
                        geoPlotCartesian.Invalidate();
                    });
                }
                else
                {
                    geoPlotCartesian.AppendHistoryLine(e.Text);
                    geoPlotCartesian.Invalidate();
                }
            };

            #endregion

            #region settingsProvider

            settingsProvider = new SimpeSettingsProviderXML <SettingsContainer>();
            settingsProvider.isSwallowExceptions = false;

            try
            {
                settingsProvider.Load(settingsFileName);
            }
            catch (Exception ex)
            {
                ProcessException(ex, true);
            }

            settingsProvider.isSwallowExceptions = true;

            logger.Write(settingsProvider.Data.ToString());

            #endregion

            #region NMEA

            NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.VLB);
            NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.VLB, "L", "x.x,x.x,x.x,x.x,x,x.x,x.x,x.x");

            #endregion

            #region agingValues

            targetLatitude    = new AgingValue <double>(3, 20, (x) => string.Format(CultureInfo.InvariantCulture, "LAT: {0:F06}°", x));
            targetLongitude   = new AgingValue <double>(3, 20, (x) => string.Format(CultureInfo.InvariantCulture, "LON: {0:F06}°", x));
            targetRadialError = new AgingValue <double>(3, 300, (x) => string.Format(CultureInfo.InvariantCulture, "RER: {0:F03} m", x));
            targetTemperature = new AgingValue <double>(3, 600, (x) => string.Format(CultureInfo.InvariantCulture, "TMP: {0:F01} °C", x));
            targetDepth       = new AgingValue <double>(3, 60, (x) => string.Format(CultureInfo.InvariantCulture, "DPT: {0:F03} m", x));
            targetBatVoltage  = new AgingValue <double>(3, 300, (x) => string.Format(CultureInfo.InvariantCulture, "BAT: {0:F01} V", x));
            targetMSR         = new AgingValue <double>(3, 20, (x) => string.Format(CultureInfo.InvariantCulture, "MSR: {0:F01} dB", x));
            targetPTime       = new AgingValue <double>(3, 20, (x) => string.Format(CultureInfo.InvariantCulture, "TIM: {0:F04} sec", x));

            ownLatitude       = new AgingValue <double>(3, 20, (x) => string.Format(CultureInfo.InvariantCulture, "LAT: {0:F06}°", x));
            ownLongitude      = new AgingValue <double>(3, 20, (x) => string.Format(CultureInfo.InvariantCulture, "LON: {0:F06}°", x));
            ownDepth          = new AgingValue <double>(3, 20, (x) => string.Format(CultureInfo.InvariantCulture, "DPT: {0:F03} m", x));
            ownBatteryVoltage = new AgingValue <double>(3, 20, (x) => string.Format(CultureInfo.InvariantCulture, "BAT: {0:F01} V", x));

            #endregion

            #region geoPlotCartesian

            geoPlotCartesian.AddTrack("Rover", Color.Gray, 2, 2, settingsProvider.Data.MeasurementsFIFOSize, true);
            geoPlotCartesian.AddTrack("Measurements", Color.Blue, 2, 2, settingsProvider.Data.MeasurementsFIFOSize, true);
            geoPlotCartesian.AddTrack("Reference point", Color.Magenta, 4, 4, 1, false);
            geoPlotCartesian.AddTrack("Base", Color.Green, 4, 4, settingsProvider.Data.BaseSize, false);
            geoPlotCartesian.AddTrack("Target", Color.Red, 6, 6, settingsProvider.Data.TargetLocationFIFOSize, true);

            #endregion

            #region vlblCore

            vlblCore = new VLBLCore <VLBLTOAMeasurement>(settingsProvider.Data.MeasurementsFIFOSize,
                                                         settingsProvider.Data.BaseSize,
                                                         settingsProvider.Data.RadialErrorThreshold,
                                                         settingsProvider.Data.SimplexSize,
                                                         UCNLNav.Algorithms.WGS84Ellipsoid);

            vlblCore.BaseUpdatedEventHandler           += (o, e) => { UpdateTrack("Base", e.BasePoints); };
            vlblCore.ReferencePointUpdatedEventHandler += (o, e) => { UpdateTrack("Reference point", vlblCore.ReferencePoint); };

            vlblCore.TargetPositionUpdatedEventHandler += (o, e) =>
            {
                UpdateTrack("Target", e.TargetPosition);

                if (InvokeRequired)
                {
                    Invoke((MethodInvoker) delegate
                    {
                        targetLatitude.Value    = e.TargetPosition.Latitude;
                        targetLongitude.Value   = e.TargetPosition.Longitude;
                        targetRadialError.Value = e.RadialError;
                    });
                }
                else
                {
                    targetLatitude.Value    = e.TargetPosition.Latitude;
                    targetLongitude.Value   = e.TargetPosition.Longitude;
                    targetRadialError.Value = e.RadialError;
                }
            };

            #endregion

            #region tracks

            tracks = new Dictionary <string, List <GeoPoint3D> >();

            #endregion

            #region InPort

            inPort = new NMEASerialPort(new SerialPortSettings(settingsProvider.Data.InPortName, settingsProvider.Data.InPortBaudrate,
                                                               System.IO.Ports.Parity.None,
                                                               DataBits.dataBits8,
                                                               System.IO.Ports.StopBits.One,
                                                               System.IO.Ports.Handshake.None));

            inPort.NewNMEAMessage += new EventHandler <NewNMEAMessageEventArgs>(inPort_NewNMEAMessage);

            #endregion

            #region OutPort

            if (settingsProvider.Data.IsUseOutPort)
            {
                outPort = new SerialPort(settingsProvider.Data.OutPortName, (int)settingsProvider.Data.OutPortBaudrate);
            }

            #endregion

            #region timer

            timer        = new PrecisionTimer();
            timer.Period = 1000;
            timer.Mode   = Mode.Periodic;
            timer.Tick  += new EventHandler(timer_Tick);
            timer.Start();

            #endregion
        }
Ejemplo n.º 12
0
        public APLLBLCore(Dictionary <string, SerialPortSettings> inPortSettings,
                          double radialErrorThreshold, double simplexSize, int courseEstimatorFifoSize, int trackFilterSize)
        {
            #region misc. initialization

            primaryGNSSFixRMC = new AgingValue <RMCMessageEventArgs>(2, 10,
                                                                     x => string.Format(CultureInfo.InvariantCulture, "LAT: {0:F06}°\r\nLON: {1:F06}°\r\nSPD: {2:F01} m/s (3:F01 km/h)\r\nTRK: {4:F01}°",
                                                                                        x.Latitude, x.Longitude, x.SpeedKmh / 3.6, x.SpeedKmh, x.TrackTrue));

            meanWaterTemperatureC = new AgingValue <double>(10, 30, x => string.Format(CultureInfo.InvariantCulture, "MTW: {0:F01} °C", x));

            targetFix = new AgingValue <GeoPoint3DETm>(3, 60,
                                                       x => string.Format(CultureInfo.InvariantCulture, "LAT: {0:F06}°\r\nLON: {1:F06}°\r\nRER: {2:F03} m",
                                                                          x.Latitude, x.Longitude, x.RadialError));

            targetFixFlt = new AgingValue <GeoPoint3DETm>(3, 60,
                                                          x => string.Format(CultureInfo.InvariantCulture, "LAT: {0:F06}°\r\nLON: {1:F06}°",
                                                                             x.Latitude, x.Longitude));

            targetCourse           = new AgingValue <double>(4, 8, x => string.Format(CultureInfo.InvariantCulture, "CRS: {0:F01}°", x));
            distanceToTarget       = new AgingValue <double>(4, 8, x => string.Format(CultureInfo.InvariantCulture, "D2T: {0:F01} m", x));
            forwardAzimuthToTarget = new AgingValue <double>(4, 8, x => string.Format(CultureInfo.InvariantCulture, "FAZ: {0:F01}°", x));
            reverseAzimuthToTarget = new AgingValue <double>(4, 8, x => string.Format(CultureInfo.InvariantCulture, "RAZ: {0:F01}°", x));

            BaseBatStates = new Dictionary <BaseIDs, AgingValue <bool> >();
            BaseBatStates.Add(BaseIDs.BASE_1, new AgingValue <bool>(30, 60, x => !x ? string.Format("{0} BAT LOW!", BaseIDs.BASE_1) : string.Empty));
            BaseBatStates.Add(BaseIDs.BASE_2, new AgingValue <bool>(30, 60, x => !x ? string.Format("{0} BAT LOW!", BaseIDs.BASE_1) : string.Empty));
            BaseBatStates.Add(BaseIDs.BASE_3, new AgingValue <bool>(30, 60, x => !x ? string.Format("{0} BAT LOW!", BaseIDs.BASE_1) : string.Empty));
            BaseBatStates.Add(BaseIDs.BASE_4, new AgingValue <bool>(30, 60, x => !x ? string.Format("{0} BAT LOW!", BaseIDs.BASE_1) : string.Empty));

            dopState   = new AgingValue <DOPState>(4, 10, x => x.ToString().Replace('_', ' ').ToUpperInvariant());
            tbaQuality = new AgingValue <TBAQuality>(4, 10, x => x.ToString().Replace('_', ' ').ToUpperInvariant());

            #endregion

            #region pCore

            trkFilter = new TrackFilter(trackFilterSize);

            pCore = new PCore2D <GeoPoint3DT>(radialErrorThreshold, simplexSize, Algorithms.WGS84Ellipsoid, courseEstimatorFifoSize);
            pCore.RadialErrorExeedsThrehsoldEventHandler += (o, e) => InfoEventHandler.Rise(this, new LogEventArgs(LogLineType.INFO, "WAYU Pinger location failed: radial error exeeds threshold"));
            pCore.TargetLocationUpdatedExHandler         += (o, e) =>
            {
                targetFix.Value    = new GeoPoint3DETm(e.Location.Latitude, e.Location.Longitude, e.Location.Depth, e.Location.RadialError, e.TimeStamp);
                targetCourse.Value = e.Course;

                var fltTrk = trkFilter.Filter(e.Location.Latitude, e.Location.Longitude);
                targetFixFlt.Value = new GeoPoint3DETm(fltTrk.Latitude, fltTrk.Longitude, e.Location.Depth, e.Location.RadialError, e.TimeStamp);

                if (primaryGNSSFixRMC.IsInitializedAndNotObsolete)
                {
                    UpdateTargetRelativeData();
                }

                InfoEventHandler.Rise(this, new LogEventArgs(LogLineType.INFO,
                                                             string.Format(CultureInfo.InvariantCulture, "WAYU Pinger located: {0}, Course: {1:F01}°",
                                                                           targetFixFlt, e.Course)));

                TrackUpdateHandler.Rise(this,
                                        new TrackUpdateEventArgs("WAYU (RAW)", targetFix.Value, e.Course));

                TrackUpdateHandler.Rise(this,
                                        new TrackUpdateEventArgs("WAYU (FLT)", targetFixFlt.Value, e.Course));

                if ((outPort != null) &&
                    (outPort.IsOpen))
                {
                    WriteOutData(targetFixFlt.Value.Latitude, targetFixFlt.Value.Longitude, 0.0, targetFix.Value.RadialError,
                                 targetCourse.Value, targetFix.Value.RadialError <= pCore.RadialErrorThreshold);
                }

                SystemUpdate();
            };

            pCore.BaseQualityUpdatedHandler += (o, e) =>
            {
                dopState.Value   = e.DopState;
                tbaQuality.Value = e.TBAState;
            };

            #endregion

            #region basesProcessor

            basesProcessor = new APLBaseProcessor(4, 2.0);

            #endregion

            #region NMEA

            if (!nmeaSingleton)
            {
                NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.APL);
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.APL, "A", "x,x.x,x.x,x.x,x,x.x");
                nmeaSingleton = true;
            }

            #endregion

            #region Port dictionaries

            portDescrByHash = new Dictionary <int, string>();
            portNameByHash  = new Dictionary <int, string>();
            portHashByDescr = new Dictionary <string, int>();
            portTimoutFlags = new Dictionary <int, bool>();
            portTSByHash    = new Dictionary <int, int>();

            portDescrByHash.Add(emuID, emuIDstr);
            portNameByHash.Add(emuID, emuIDstr);
            portHashByDescr.Add(emuIDstr, emuID);

            #endregion

            #region nmeaListener

            nmeaListener = new NMEAMultipleListener();
            nmeaListener.LogEventHandler             += (o, e) => InfoEventHandler.Rise(o, e);
            nmeaListener.NMEAIncomingMessageReceived += (o, e) => InfoEventHandler.Rise(o,
                                                                                        new LogEventArgs(LogLineType.INFO,
                                                                                                         string.Format("{0} ({1}) >> {2}", portNameByHash[e.SourceID], portDescrByHash[e.SourceID], e.Message)));

            nmeaListener.RMCSentenceReceived += new EventHandler <RMCMessageEventArgs>(nmeaListener_RMCSentenceReceivedHandler);
            nmeaListener.MTWSentenceReceived += new EventHandler <MTWMessageEventArgs>(nmeaListener_MTWSentenceReceivedHandler);
            nmeaListener.NMEAProprietaryUnsupportedSentenceParsed += new EventHandler <NMEAUnsupportedProprietaryEventArgs>(nmeaListener_NMEAUnsupportedProprietaryReceivedHander);

            #endregion

            #region inPorts

            List <SerialPortSettings> portsList = new List <SerialPortSettings>();

            foreach (var inPort in inPortSettings)
            {
                int portHash = inPort.Value.PortName.GetHashCode();
                portDescrByHash.Add(portHash, inPort.Key);
                portNameByHash.Add(portHash, inPort.Value.PortName);
                portHashByDescr.Add(inPort.Key, portHash);

                portTimoutFlags.Add(portHash, false);
                portTSByHash.Add(portHash, 0);
                portsList.Add(inPort.Value);
            }

            inPorts = new SerialPortsPool(portsList.ToArray());
            inPorts.DataReceived += (o, e) =>
            {
                int portKey = e.PortName.GetHashCode();
                portTSByHash[portKey] = 0;
                if (portTimoutFlags[portKey])
                {
                    portTimoutFlags[portKey] = false;
                    PortStateChangedHandler.Rise(this, new EventArgs());
                }

                nmeaListener.ProcessIncoming(portKey, e.Data);
            };
            inPorts.ErrorReceived += (o, e) => InfoEventHandler.Rise(o,
                                                                     new LogEventArgs(LogLineType.ERROR,
                                                                                      string.Format("{0} ({1}) >> {2}", e.PortName, portDescrByHash[e.PortName.GetHashCode()], e.EventType.ToString())));

            #endregion

            #region timer

            timer        = new PrecisionTimer();
            timer.Mode   = Mode.Periodic;
            timer.Period = 100;

            timer.Tick += (o, e) =>
            {
                if (IsOpen)
                {
                    int[] keys = new int[portTSByHash.Count];
                    portTSByHash.Keys.CopyTo(keys, 0);
                    for (int i = 0; i < keys.Length; i++)
                    {
                        portTSByHash[keys[i]] += timerPeriodMS;
                        if (portTSByHash[keys[i]] > portsTimeoutMS)
                        {
                            portTSByHash[keys[i]] = 0;
                            if (!portTimoutFlags[keys[i]])
                            {
                                portTimoutFlags[keys[i]] = true;
                                PortStateChangedHandler.Rise(this, new EventArgs());
                            }
                        }
                    }
                }

                systemUpdateTS += timerPeriodMS;
                if (systemUpdateTS > systemUpdateTimeoutMS)
                {
                    SystemUpdate();
                }
            };

            timer.Start();

            #endregion
        }