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

489 views Asked by At

In my windows form application I use stopwatch to calculate elapsed time between events but I want to get time from NMEA(GPRMC sentence) and want to use it as elapsed time. How can I do this?

Here is my code;

 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);
    }
    }

EDIT;

In my application I am making a acceleration test by using GNSS module. In application I am setting a boundary conditions for velocity Textbox1 and Textbox2 and label1 represents current velocity of the car and label2 represents elapsed time when car's current velocity enter these boundaries .For example; I set Textbox1.text=10 and Textbox2.text=100 and car started to accelerate and I want to measure time difference between car is accclerating from 10 to 100. To do this I used stopwatch but I faced some problems. Now I want to use UTC time to measure time between car's velocity is 10 and 100. I can get UTC time from sentences of the GPRMC and I parsed it too.However I can't make start it from zero when car's velocity is 10 and stopped it when car velocity passed 100.

1

There are 1 answers

0
Tom Schardt On BEST ANSWER

Not really clear what you want to achieve, but a guess:

Parse the NMEA time and save it as DateTime object. Then do

var timeSpan = DateTime.UtcNow - nmeaTimestamp;

to get the time since the transmitted timestamp.

Have a look at NMEA documentation for the meaning of this timestamp: UTC of position fix: It is the time when the transmitting station was close to the transmitted position.

If you want to be alarmed after a particular timespan use a Timer. It will raise an event when the time has elapsed.

EDIT: Pick a packet close to velocity 10 and a packet close to velocity 100, parse the timestamps and subtract them:

var accelerationTimeMilliseconds = (timestampAt100 - timestampAt10).ElapsedMilliseconds;