Example #1
0
        private void writeSettingsBtn_Click(object sender, EventArgs e)
        {
            // $PTNT7,rxChID,txChID,isRTX
            var cStr = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "7", new object[] { rxChId, txChId, Convert.ToInt32(isRetranslation), Convert.ToInt32(isReverse) });

            Send(cStr);
        }
Example #2
0
        private void readSettingsBtn_Click(object sender, EventArgs e)
        {
            // $PTNT8,0
            var cStr = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "8", new object[] { 0 });

            Send(cStr);
        }
Example #3
0
        private void locDataQueryBtn_Click(object sender, EventArgs e)
        {
            // $PTNT4,locDataID,reserved
            var cStr = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "4", new object[] { (int)locDataID, 0 });

            Send(cStr);
        }
Example #4
0
        public APLEmulator()
        {
            timer        = new PrecisionTimer();
            timer.Period = 10;
            timer.Mode   = Mode.Periodic;
            timer.Tick  += (o, e) =>
            {
                sec += 0.01;
                if (sec > data[idx][0])
                {
                    var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.APL, "A", new object[]
                    {
                        Convert.ToInt32(data[idx][1]),
                        data[idx][2],
                        data[idx][3],
                        data[idx][4],
                        1,
                        data[idx][5]
                    });
                    EmulatorOutputEvent.Rise(this, new NewNMEAMessageEventArgs(msg));
                    idx++;

                    if (idx >= data.Count)
                    {
                        sec = 0;
                        idx = 0;
                    }
                }
            };
        }
Example #5
0
        private void gtr_QueryRemote(int targetAddr, CDS_CMD cmd, int timeoutMs)
        {
            // $PTNTE,targetAddr,requestedCmd,timeoutMs
            var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "E", new object[] { targetAddr, (int)cmd, timeoutMs });

            gtr_requestID = cmd;
            gtr_TrySend(msg, string.Format("RedGTR << ? SUB #{0}, CMD {1}, TMO {2} ms", targetAddr, cmd, timeoutMs), true);
        }
Example #6
0
 public bool PacketMode_Send(byte target_ptAddress, byte maxTries, byte[] data)
 {
     if (data.Length <= uWAVE.PT_MAX_PACKET_SIZE)
     {
         var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.UWV, "G", new object[] { (int)target_ptAddress, (int)maxTries, data });
         return(TrySend(msg, ICs.IC_H2D_PT_SEND));
     }
     return(false);
 }
Example #7
0
 private void OnPortFree()
 {
     if (dataToSend.Count > 0)
     {
         var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.MCP, "4", new object[] { dataToSend.Dequeue() });
         port.SendData(msg);
         IsWaiting = true;
     }
 }
Example #8
0
        public void Start(byte SID, byte TID, bool selectDefaultState, int selIntMs, int toutIntMs)
        {
            if (!isWaiting)
            {
                var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.MCP, "1",
                                                              new object[] { SID, TID, Convert.ToInt32(selectDefaultState), selIntMs, toutIntMs });
                port.SendData(msg);

                isWaiting = true;
            }
        }
Example #9
0
        private void applyBuoyAddrBtn_Click(object sender, EventArgs e)
        {
            string message = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "8", new object[] { BuoyAddr, 0 });

            if (TrySend(message))
            {
                State = AppState.DEV_SETTINGS_APPLY_QUERIED;
            }
            else
            {
                State = AppState.PORT_ERROR;
            }
        }
Example #10
0
        public bool AMBDTAConfigQuery(bool isSaveToFlash, int periodMs, bool isPressure, bool isTemperature, bool isDepth, bool isVCC)
        {
            var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.UWV, "6", new object[]
            {
                Convert.ToInt32(isSaveToFlash),
                periodMs,
                Convert.ToInt32(isPressure),
                Convert.ToInt32(isTemperature),
                Convert.ToInt32(isDepth),
                Convert.ToInt32(isVCC)
            });

            return(TrySend(msg, ICs.IC_H2D_AMB_DTA_CFG));
        }
Example #11
0
        public bool SettingsWriteQuery(int txChID, int rxChID, double salinityPSU, bool isCmdMode, bool isACKOnTXFinished, double gravityAcc)
        {
            var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.UWV, "1", new object[]
            {
                txChID,
                rxChID,
                salinityPSU,
                Convert.ToInt32(isCmdMode),
                Convert.ToInt32(isACKOnTXFinished),
                gravityAcc
            });

            return(TrySend(msg, ICs.IC_H2D_SETTINGS_WRITE));
        }
Example #12
0
        public string QueryMirroredSet(bool isMirrored)
        {
            int fldVal;

            if (isMirrored)
            {
                fldVal = 1;
            }
            else
            {
                fldVal = 0;
            }
            return(NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "2", new object[] { (int)FieldIDs.FLD_IS_MIRROR_SCREEN, fldVal }));
        }
Example #13
0
        public bool RCRequestQuery(int txChID, int rxChID, RC_CODES_Enum cmdID)
        {
            if (!IsWaitingRemote)
            {
                var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.UWV, "2", new object[]
                {
                    txChID,
                    rxChID,
                    (int)cmdID
                });

                return(TrySend(msg, ICs.IC_H2D_RC_REQUEST));
            }
            else
            {
                OnInfoEvent("Unable to perform a remote request due to waiting for previous");
                return(false);
            }
        }
Example #14
0
        private bool RequestFWUpdate(bool isMedium)
        {
            InvokeWriteStateLbl("Querying");
            InvokeSwitchProgressBarMode(ProgressBarStyle.Marquee);
            InvokeWriteLogString("Querying firmware update...\r\n");
            bool result = false;
            var  cmdStr = NMEAParser.BuildProprietarySentence(ManufacturerCodes.UCN, "L", new object[] { (int)UCNL_SRV_CMD.FW_UPDATE_INVOKE, Convert.ToInt32(isMedium), "" });

            try
            {
                nmeaPort.SendData(cmdStr);
                timer.Start();
                InvokeWriteLogString(string.Format(">> {0}", cmdStr));
                result = true;
            }
            catch (Exception ex)
            {
                ProcessException(ex, false);
            }

            return(result);
        }
Example #15
0
        private bool RequestDevInfo()
        {
            InvokeWriteStateLbl("Querying");
            InvokeWriteLogString("Querying device info...\r\n");
            InvokeSwitchProgressBarMode(ProgressBarStyle.Marquee);
            bool result = false;
            var  cmdStr = NMEAParser.BuildProprietarySentence(ManufacturerCodes.UCN, "L", new object[] { (int)UCNL_SRV_CMD.DEV_INFO_GET, 0, "" });

            try
            {
                nmeaPort.SendData(cmdStr);
                result = true;
                timer.Start();
                InvokeWriteLogString(string.Format(">> {0}", cmdStr));
            }
            catch (Exception ex)
            {
                ProcessException(ex, false);
            }

            return(result);
        }
Example #16
0
        private bool CheckNextPort()
        {
            portSettings.PortName = portNames[curPortIdx];
            bool result = false;

            try
            {
                port = new NMEASerialPort(portSettings);
                port.NewNMEAMessage = new EventHandler <NewNMEAMessageEventArgs>(port_NewNMEAMessage);
                port.PortError      = new EventHandler <SerialErrorReceivedEventArgs>(port_PortError);
                port.Open();

                var queryStr = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "4", new object[] { (int)LocalDataIDs.LOC_DATA_DEVICE_INFO, 0 });
                port.SendData(queryStr);

                if (ConnectionEstablished != null)
                {
                    ConnectionEstablished(this, new EventArgs());
                }

                timer.Start();

                result = true;
            }
            catch (Exception ex)
            {
                if (port.IsOpen)
                {
                    port.Close();
                }

                UnsubscribePort();
                port.Dispose();
            }

            return(result);
        }
Example #17
0
 public string QueryLocDataGet(LocalDataIDs dataID)
 {
     return(NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "4", new object[] { (int)dataID, 0 }));
 }
Example #18
0
        private void gtr_DeviceInfoQuery()
        {
            var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "4", new object[] { (int)LocData.LOC_DATA_DEVICE_INFO, 0 });

            gtr_TrySend(msg, "Device info query", false);
        }
Example #19
0
        private void OnAppStateChanged(AppState state)
        {
            switch (state)
            {
            case AppState.PORT_ABSENT:
            {
                portNameCbx.Enabled      = false;
                openClosePortBtn.Enabled = false;
                deviceInfoGroup.Enabled  = false;
                buoyAddressGroup.Enabled = false;
                statusLbl.Text           = "No ports available";
                break;
            }

            case AppState.PORT_OPENED:
            {
                portNameCbx.Enabled      = false;
                openClosePortBtn.Text    = "Close";
                deviceInfoGroup.Enabled  = false;
                buoyAddressGroup.Enabled = false;
                statusLbl.Text           = "Port opened";

                var message = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "4", new object[] { LOC_DATA_INFO.LOC_DATA_DEVICE_INFO, 0 });
                if (!TrySend(message))
                {
                    State = AppState.PORT_CLOSED;
                }
                else
                {
                    State = AppState.DEV_INFO_QUERIED;
                }

                break;
            }

            case AppState.PORT_ERROR:
            {
                if (timer.IsRunning)
                {
                    timer.Stop();
                }

                statusLbl.Text = "Port error";
                break;
            }

            case AppState.PORT_CLOSED:
            {
                if (timer.IsRunning)
                {
                    timer.Stop();
                }

                portNameCbx.Enabled      = true;
                openClosePortBtn.Text    = "Open";
                openClosePortBtn.Enabled = true;
                deviceInfoGroup.Enabled  = false;
                buoyAddressGroup.Enabled = false;

                statusLbl.Text = "Port closed";
                break;
            }

            case AppState.DEV_INFO_QUERIED:
            {
                statusLbl.Text = "Device info queried...";
                timer.Start();
                break;
            }

            case AppState.DEV_INFO_RECEIVED:
            {
                if (timer.IsRunning)
                {
                    timer.Stop();
                }

                deviceInfoGroup.Enabled = true;
                statusLbl.Text          = "Device info received";

                string message = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "7", new object[] { 0 });

                if (TrySend(message))
                {
                    State = AppState.DEV_SETTINGS_QUERIED;
                    timer.Start();
                }
                else
                {
                    State = AppState.PORT_ERROR;
                }

                break;
            }

            case AppState.DEV_TIMEOUT:
            {
                statusLbl.Text = "Device timeout";
                break;
            }

            case AppState.WRONG_DEVICE:
            {
                if (timer.IsRunning)
                {
                    timer.Stop();
                }

                buoyAddressGroup.Enabled = false;
                statusLbl.Text           = "Connected device is not a RedBASE";
                break;
            }

            case AppState.DEV_SETTINGS_QUERIED:
            {
                statusLbl.Text = "Settings queried...";
                break;
            }

            case AppState.DEV_SETTINGS_RECEIVED:
            {
                if (timer.IsRunning)
                {
                    timer.Stop();
                }

                buoyAddressGroup.Enabled = true;
                statusLbl.Text           = "Settings received";
                break;
            }

            case AppState.DEV_SETTINGS_APPLY_QUERIED:
            {
                statusLbl.Text = "Settings apply queried...";
                timer.Start();
                break;
            }

            case AppState.DEV_SETTINGS_UPDATED:
            {
                if (timer.IsRunning)
                {
                    timer.Stop();
                }

                statusLbl.Text = "Settings updated";
                break;
            }

            default:
            {
                break;
            }
            }
        }
Example #20
0
 public string QueryFlashWrite()
 {
     return(NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "6", new object[] { (int)InvokeIDs.LOC_INVOKE_FLASH_WRITE, 0 }));
 }
Example #21
0
        public bool PacketMode_SettingsWrite(bool isSaveInFlash, bool isPTMode, byte ptAddress)
        {
            var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.UWV, "F", new object[] { Convert.ToInt32(isSaveInFlash), Convert.ToInt32(isPTMode), (int)ptAddress });

            return(TrySend(msg, ICs.IC_H2H_PT_SETTINGS_WRITE));
        }
Example #22
0
        private void timer_Tick(object sender, EventArgs e)
        {
            #region randomize basepoints

            double dst = timeSlice * targetSpeed;
            targetLocation = MoveGeoPoint(targetLocation, dst, targetCourse);
            targetCourse   = targetCourse * 0.99 + 0.01 * rnd.NextDouble() * Math.PI * 2.0;
            targetSpeed    = Math.Abs(targetSpeed * 0.9 + 0.1 * rnd.NextDouble() * 2 - 1);

            targetDpt  = Math.Abs(targetDpt + rnd.NextDouble() * 0.5 - 0.25);
            targetTemp = Math.Abs(targetTemp + rnd.NextDouble() * 0.1 - 0.05);
            targetBat  = Math.Abs(targetBat + rnd.NextDouble() * 0.1 - 0.05);

            dst         = timeSlice * auxSpeed;
            auxLocation = MoveGeoPoint(auxLocation, dst, auxCourse);
            auxCourse   = auxCourse * 0.99 + 0.01 * rnd.NextDouble() * Math.PI * 2.0;
            auxSpeed    = Math.Abs(auxSpeed * 0.9 + 0.1 * rnd.NextDouble() * 2 - 1);

            foreach (BaseIDs baseID in baseIDs)
            {
                if (baseID != BaseIDs.BASE_INVALID)
                {
                    dst = timeSlice * baseSpeeds[baseID];
                    baseLocations[baseID] = MoveGeoPoint(baseLocations[baseID], dst, baseCourses[baseID]);
                    baseCourses[baseID]   = baseCourses[baseID] * 0.9 + 0.1 * rnd.NextDouble() * Math.PI * 2.0;
                    baseSpeeds[baseID]    = Math.Abs(baseSpeeds[baseID] * 0.9 + 0.1 * rnd.NextDouble() * 0.5 - 0.25);

                    baseBats[baseID] = baseBats[baseID] + rnd.NextDouble() * 0.1;
                }
            }

            #endregion

            if (++targetPeriod == 2)
            {
                targetPeriod = 0;

                double dst_p      = 0;
                double ddpt       = 0;
                double fwd_az_rad = 0;
                double rev_az_rad = 0;
                int    its        = 0;
                foreach (BaseIDs baseID in baseIDs)
                {
                    if (baseID != BaseIDs.BASE_INVALID)
                    {
                        Algorithms.VincentyInverse(targetLocation.Latitude, targetLocation.Longitude,
                                                   baseLocations[baseID].Latitude, baseLocations[baseID].Longitude,
                                                   Algorithms.WGS84Ellipsoid,
                                                   Algorithms.VNC_DEF_EPSILON,
                                                   Algorithms.VNC_DEF_IT_LIMIT,
                                                   out dst_p,
                                                   out fwd_az_rad,
                                                   out rev_az_rad,
                                                   out its);

                        ddpt         = RWLT.DEFAULT_BASE_DPT_M - targetDpt;
                        TOAs[baseID] = Math.Sqrt(ddpt * ddpt + dst_p * dst_p) / SoundSpeed;
                    }
                }

                #region emulate LBLAs

                PingerDataIDs dataID = dataIDs[dataIDIdx];
                dataIDIdx = (dataIDIdx + 1) % dataIDs.Length;
                double data = 0.0;

                if (dataID == PingerDataIDs.DID_BAT)
                {
                    data = targetBat;
                }
                else if (dataID == PingerDataIDs.DID_TMP)
                {
                    data = targetTemp;
                }
                else if (dataID == PingerDataIDs.DID_PRS)
                {
                    data = PHX.Pressure_by_depth_calc(targetDpt, PHX.PHX_ATM_PRESSURE_MBAR, PHX.PHX_FWTR_DENSITY_KGM3, PHX.PHX_GRAVITY_ACC_MPS2);
                }
                else
                {
                    data = (int)dataID;
                }

                // IC_D2H_LBLA $PRWLA,bID,baseLat,baseLon,[baseDpt],baseBat,pingerDataID,pingerData,TOAsecond,MSR_dB
                foreach (BaseIDs baseID in baseIDs)
                {
                    if ((baseID != BaseIDs.BASE_INVALID)) //&& (baseID != BaseIDs.BASE_2))
                    {
                        NewEmuStringEvent.Rise(this, new EmuStringEventArgs(
                                                   NMEAParser.BuildProprietarySentence(ManufacturerCodes.RWL, "A",
                                                                                       new object[]
                        {
                            (int)baseID,
                            Algorithms.Rad2Deg(baseLocations[baseID].Latitude),
                            Algorithms.Rad2Deg(baseLocations[baseID].Longitude),
                            RWLT.DEFAULT_BASE_DPT_M,
                            baseBats[baseID],
                            dataID,
                            data,
                            TOAs[baseID],
                            77.7777     // it's an emulation
                        })));
                    }
                }

                #endregion
            }

            #region emulate AUX GNSS

            string latCardinal, lonCardinal;

            double auxLat = Algorithms.Rad2Deg(auxLocation.Latitude);
            double auxLon = Algorithms.Rad2Deg(auxLocation.Longitude);

            if (auxLat > 0)
            {
                latCardinal = "North";
            }
            else
            {
                latCardinal = "South";
            }
            if (auxLon > 0)
            {
                lonCardinal = "East";
            }
            else
            {
                lonCardinal = "West";
            }

            /*
             * NewEmuStringEvent.Rise(this,
             *  new EmuStringEventArgs(
             *      NMEAParser.BuildSentence(TalkerIdentifiers.GN, SentenceIdentifiers.RMC, new object[]
             * {
             *  DateTime.Now,
             *  "Valid",
             *  Math.Abs(auxLat), latCardinal,
             *  Math.Abs(auxLon), lonCardinal,
             *  auxSpeed * 3.6, // speed
             *  Algorithms.Rad2Deg(auxCourse), // track true
             *  DateTime.Now,
             *  null, // magnetic variation
             *  null, // magnetic variation direction
             *  "A",
             * })));
             */

            #endregion
        }
Example #23
0
 public string QueryZeroDepthAdjust()
 {
     return(NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "6", new object[] { (int)InvokeIDs.LOC_INVOKE_DPT_ZERO_ADJUST, 0 }));
 }
Example #24
0
 public string QueryDeviceInfo()
 {
     return(NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "4", new object[] { (int)LocalDataIDs.LOC_DATA_DEVICE_INFO, 0 }));
 }
Example #25
0
 public string QueryBatteryCharge()
 {
     return(NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "4", new object[] { (int)LocalDataIDs.LOC_DATA_BAT_CHARGE, 0 }));
 }
Example #26
0
        public bool PacketMode_AbortSend()
        {
            var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.UWV, "G", new object[] { null, null, null });

            return(TrySend(msg, ICs.IC_H2D_PT_SEND));
        }
Example #27
0
 public string QueryLocDataSet(LocalDataIDs dataID, double value)
 {
     return(NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "P", new object[] { (int)dataID, value }));
 }
Example #28
0
        public bool DeviceInfoQuery()
        {
            var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.UWV, "?", new object[] { 0 });

            return(TrySend(msg, ICs.IC_H2D_DINFO_GET));
        }
Example #29
0
        public bool PacketMode_SettingQuery()
        {
            var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.UWV, "D", new object[] { 0 });

            return(TrySend(msg, ICs.IC_H2D_PT_SETTINGS_READ));
        }
Example #30
0
        private void gtr_QuerySalinitySet(double salinity)
        {
            var msg = NMEAParser.BuildProprietarySentence(ManufacturerCodes.TNT, "7", new object[] { (int)LocData.LOC_DATA_SALINITY, salinity });

            gtr_TrySend(msg, string.Format("Salinity set = {0:F01}", salinity), false);
        }