MissionPlanner.Log.DFLog.GetFirstGpsTime C# (CSharp) Method

GetFirstGpsTime() public method

public GetFirstGpsTime ( string fn ) : System.DateTime
fn string
return System.DateTime
        public DateTime GetFirstGpsTime(string fn)
        {
            using (StreamReader sr = new StreamReader(fn))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();

                    if (line.StartsWith("FMT"))
                    {
                        FMTLine(line);
                    }
                    else if (line.StartsWith("GPS"))
                    {
                        DateTime answer = GetTimeGPS(line);
                        if (answer != DateTime.MinValue)
                            return answer;
                    }
                }
            }

            return DateTime.MinValue;
        }

Usage Example

Example #1
0
        string GetLog(ushort no)
        {
            MainV2.comPort.Progress += comPort_Progress;

            status = serialstatus.Reading;

            // get df log from mav
            var ms = MainV2.comPort.GetLog(no);

            status = serialstatus.Done;

            MainV2.comPort.Progress -= comPort_Progress;

            // set log fn
            byte[] hbpacket = MainV2.comPort.getHeartBeat();

            MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)MainV2.comPort.DebugPacket(hbpacket);

            logfile = MainV2.LogDir + Path.DirectorySeparatorChar
                      + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                      + hbpacket[3] + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm") + " " + no + ".bin";

            // make log dir
            Directory.CreateDirectory(Path.GetDirectoryName(logfile));

            // save memorystream to file
            using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(logfile)))
            {
                bw.Write(ms.ToArray());
            }

            // read binary log to assci log
            var temp1 = Log.BinaryLog.ReadLog(logfile);

            // delete binary log file
            //File.Delete(logfile);

            logfile = logfile + ".log";

            // write assci log
            File.WriteAllLines(logfile, temp1);

            // get gps time of assci log
            DateTime logtime = DFLog.GetFirstGpsTime(logfile);

            // rename log is we have a valid gps time
            if (logtime != DateTime.MinValue)
            {
                string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar
                                        + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                                        + hbpacket[3] + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm") + ".log";
                File.Move(logfile, newlogfilename);
                // rename bin as well
                File.Move(logfile.Replace(".log", ""), newlogfilename.Replace(".log", ".bin"));
                logfile = newlogfilename;
            }

            return(logfile);
        }
All Usage Examples Of MissionPlanner.Log.DFLog::GetFirstGpsTime