コード例 #1
0
        private void WriteOutData(double bLat, double bLon, double bDpt, double rErr, double cource, bool isValid, double wTemp)
        {
            string latCardinal, lonCardinal;

            string RMCvString;

            if (isValid)
            {
                RMCvString = "Valid";
            }
            else
            {
                RMCvString = "Invalid";
            }

            if (bLat > 0)
            {
                latCardinal = "North";
            }
            else
            {
                latCardinal = "South";
            }

            if (bLon > 0)
            {
                lonCardinal = "East";
            }
            else
            {
                lonCardinal = "West";
            }

            StringBuilder emuString = new StringBuilder();

            #region RMC

            emuString.Append(NMEAParser.BuildSentence(TalkerIdentifiers.GP,
                                                      SentenceIdentifiers.RMC,
                                                      new object[]
            {
                GetTimeStamp(),
                RMCvString,
                doubleNullCheckerR(Math.Abs(bLat)), latCardinal,
                doubleNullCheckerR(Math.Abs(bLon)), lonCardinal,
                null,                       // speed
                doubleNullCheckerR(cource), // track true
                GetTimeStamp(),
                null,                       // magnetic variation
                null,                       // magnetic variation direction
                "A",
            }));

            #endregion

            #region GGA

            if (bLat > 0)
            {
                latCardinal = "N";
            }
            else
            {
                latCardinal = "S";
            }

            if (bLon > 0)
            {
                lonCardinal = "E";
            }
            else
            {
                lonCardinal = "W";
            }

            emuString.Append(NMEAParser.BuildSentence(TalkerIdentifiers.GP,
                                                      SentenceIdentifiers.GGA,
                                                      new object[]
            {
                GetTimeStamp(),
                doubleNullCheckerR(Math.Abs(bLat)), latCardinal,
                doubleNullCheckerR(Math.Abs(bLon)), lonCardinal,
                "GPS fix",
                4,
                doubleNullCheckerR(rErr),
                doubleNullCheckerR(-bDpt),
                "M",
                null,
                "M",
                null,
                null
            }));

            #endregion

            #region MTW

            if (!double.IsNaN(wTemp))
            {
                emuString.Append(NMEAParser.BuildSentence(TalkerIdentifiers.GP, SentenceIdentifiers.MTW, new object[]
                {
                    doubleNullCheckerR(wTemp),
                    "C"
                }));
            }

            #endregion

            var emuStr = emuString.ToString();

            try
            {
                var bytes = Encoding.ASCII.GetBytes(emuStr);
                outPort.Write(bytes, 0, bytes.Length);

                LogEvent.Rise(this, new LogEventArgs(LogLineType.INFO, string.Format("{0} (OUT) << {1}", outPort.PortName, emuStr)));
            }
            catch (Exception ex)
            {
                LogEvent.Rise(this, new LogEventArgs(LogLineType.ERROR, ex));
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: ucnl/RedGTR_VLBL
        private void SendEMU(double tLat, double tLon, double tdpt, double tRErr)
        {
            // "hhmmss.ss,A=Valid|V=Invalid,llll.ll,N=North|S=South,yyyyy.yy,E=East|W=West,x.x,x.x,ddmmyy,x.x,a,a" },
            // $GPRMC,105552.000,A,4831.4568,N,04430.2342,E,0.17,180.99,230518,,,A*6F

            string latCardinal;

            if (tLat > 0)
            {
                latCardinal = "North";
            }
            else
            {
                latCardinal = "South";
            }

            string lonCardinal;

            if (tLon > 0)
            {
                lonCardinal = "East";
            }
            else
            {
                lonCardinal = "West";
            }

            StringBuilder sb = new StringBuilder();

            sb.Append(NMEAParser.BuildSentence(TalkerIdentifiers.GN, SentenceIdentifiers.RMC, new object[]
            {
                DateTime.Now,
                "Valid",
                tLat, latCardinal,
                tLon, lonCardinal,
                null, // speed knots
                null, // track true
                DateTime.Now,
                null, // magnetic variation
                null, // magnetic variation direction
                "A",
            }));

            // "hhmmss.ss,llll.ll,a,yyyyy.yy,a,0=Fix not availible|1=GPS fix|2=DGPS fix,xx,x.x,x.x,M,x.x,M,x.x,xxxx" },
            sb.Append(NMEAParser.BuildSentence(TalkerIdentifiers.GN, SentenceIdentifiers.GGA, new object[]
            {
                DateTime.Now,
                tLat, latCardinal[0],
                tLon, lonCardinal[0],
                "GPS fix",
                settingsProvider.Data.BaseSize,
                tRErr,
                -tdpt,
                "M",
                null,
                "M",
                null,
                null
            }));

            try
            {
                gnssEmulatorPort.SendData(sb.ToString());
            }
            catch (Exception ex)
            {
                ProcessException(ex, false);
            }
        }