如何在 C# 中使用 NMEA 时间作为经过时间?

How to use NMEA time as elapsed time in c#?

在我的 windows 表单应用程序中,我使用 stopwatch 来计算事件之间的经过时间,但我想从 NMEA(GPRMC 语句)获取时间并将其用作经过时间。我该怎么做?

这是我的代码;

 Stopwatch watch=new Stopwatch();
    Textbox1.Text=gsaat.Substring(4,2);
    //gsaat is the UTC time part of the GPRMC;
     private void timer2_Tick(object sender, EventArgs e)
            {
     if ((Convert.ToDouble(textBox2.Text) >= Convert.ToDouble(label1.Text) && Convert.ToDouble(label1.Text) >= Convert.ToDouble(textBox1.Text)))
                        {
                             watch.Start();
                             var time = watch.Elapsed.TotalSeconds;
    //I want to use gsaat as elapsed time in here instead of stopwatch
  label2.Text = String.Format("{0:00.00}", time);
    }
    }

编辑;

在我的应用程序中,我正在使用 GNSS 模块进行加速测试。在应用程序中,我设置了速度边界条件 Textbox1Textbox2label1 表示汽车的当前速度,label2 表示汽车当前速度进入这些边界时经过的时间。例如;我设置了 Textbox1.text=10Textbox2.text=100 并且汽车开始加速,我想测量汽车从 10 加速到 100 之间的时间差。为此我使用了 stopwatch 但我遇到了一些问题。现在我想使用 UTC 时间来测量汽车速度为 10 和 100 之间的时间。我可以从 GPRMC 的句子中获取 UTC 时间并解析它 too.However 当汽车速度为10,当车速超过100时停止。

不是很清楚你要实现什么,只是猜测:

解析NMEA时间并将其保存为DateTime对象。然后做

var timeSpan = DateTime.UtcNow - nmeaTimestamp;

获取自传输时间戳以来的时间。

看看NMEA documentation这个时间戳的含义: UTC of position fix: 是发射站接近发射位置的时间。

如果您想在特定时间段后收到警报,请使用 Timer。它会在时间过去后引发事件。

编辑:选择接近速度 10 的数据包和接近速度 100 的数据包,解析时间戳并减去它们:

var accelerationTimeMilliseconds = (timestampAt100 - timestampAt10).ElapsedMilliseconds;