GetFirstGpsTime() public method

public GetFirstGpsTime ( string fn ) : System.DateTime
fn string
return System.DateTime
Esempio n. 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);
        }
Esempio n. 2
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;
            updateDisplay();

            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-ss") + " " + 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());
            }

            // create ascii log
            BinaryLog.ConvertBin(logfile, logfile + ".log");

            //update the new filename
            logfile = logfile + ".log";

            // 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-ss") + ".log";
                try
                {
                    File.Move(logfile, newlogfilename);
                    // rename bin as well
                    File.Move(logfile.Replace(".log", ""), newlogfilename.Replace(".log", ".bin"));
                    logfile = newlogfilename;
                }
                catch  { CustomMessageBox.Show("Failed to rename file " + logfile + "\nto " + newlogfilename, "Error"); }
            }

            return(logfile);
        }
Esempio n. 3
0
        void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                while (comPort.BytesToRead > 0 && threadrun)
                {
                    updateDisplay();

                    string line = "";

                    comPort.ReadTimeout = 500;
                    try
                    {
                        line = comPort.ReadLine(); //readline(comPort);
                        if (!line.Contains("\n"))
                        {
                            line = line + "\n";
                        }
                    }
                    catch
                    {
                        line = comPort.ReadExisting();
                        //byte[] data = readline(comPort);
                        //line = Encoding.ASCII.GetString(data, 0, data.Length);
                    }

                    receivedbytes += line.Length;

                    //string line = Encoding.ASCII.GetString(data, 0, data.Length);

                    switch (status)
                    {
                    case serialstatus.Connecting:

                        if (line.Contains("ENTER") || line.Contains("GROUND START") || line.Contains("reset to FLY") || line.Contains("interactive setup") || line.Contains("CLI") || line.Contains("Ardu"))
                        {
                            try
                            {
                                //System.Threading.Thread.Sleep(200);
                                //comPort.Write("\n\n\n\n");
                            }
                            catch { }

                            System.Threading.Thread.Sleep(500);

                            // clear history
                            this.Invoke((System.Windows.Forms.MethodInvoker) delegate()
                            {
                                TXT_seriallog.Clear();
                            });

                            // comPort.Write("logs\r");
                            status = serialstatus.Done;
                        }
                        break;

                    case serialstatus.Closefile:
                        sw.Close();

                        DateTime logtime = DFLog.GetFirstGpsTime(logfile);

                        if (logtime != DateTime.MinValue)
                        {
                            string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm-ss") + ".log";
                            try
                            {
                                File.Move(logfile, newlogfilename);
                                logfile = newlogfilename;
                            }
                            catch (Exception ex) { log.Error(ex); CustomMessageBox.Show("Failed to rename file " + logfile + "\nto " + newlogfilename, Strings.ERROR); }
                        }

                        TextReader tr = new StreamReader(logfile);

                        //

                        this.Invoke((System.Windows.Forms.MethodInvoker) delegate()
                        {
                            TXT_seriallog.AppendText("Creating KML for " + logfile);
                        });

                        LogOutput lo = new LogOutput();

                        while (tr.Peek() != -1)
                        {
                            lo.processLine(tr.ReadLine());
                        }

                        tr.Close();

                        try
                        {
                            lo.writeKML(logfile + ".kml");
                        }
                        catch { }     // usualy invalid lat long error
                        status = serialstatus.Done;
                        comPort.DiscardInBuffer();
                        break;

                    case serialstatus.Createfile:
                        receivedbytes = 0;
                        Directory.CreateDirectory(MainV2.LogDir);
                        logfile = MainV2.LogDir + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + currentlog + ".log";
                        sw      = new StreamWriter(logfile);
                        status  = serialstatus.Waiting;
                        lock (thisLock)
                        {
                            this.Invoke((System.Windows.Forms.MethodInvoker) delegate()
                            {
                                TXT_seriallog.Clear();
                            });
                        }
                        //if (line.Contains("Dumping Log"))
                        {
                            status = serialstatus.Reading;
                        }
                        break;

                    case serialstatus.Done:
                        //
                        // if (line.Contains("start") && line.Contains("end"))
                    {
                        Regex regex2 = new Regex(@"^Log ([0-9]+)[,\s]", RegexOptions.IgnoreCase);
                        if (regex2.IsMatch(line))
                        {
                            MatchCollection matchs = regex2.Matches(line);
                            logcount = int.Parse(matchs[0].Groups[1].Value);
                            genchkcombo(logcount);
                            //status = serialstatus.Done;
                        }
                    }
                        if (line.Contains("No logs"))
                        {
                            status = serialstatus.Done;
                        }
                        break;

                    case serialstatus.Reading:
                        if (line.Contains("packets read") || line.Contains("Done") || line.Contains("logs enabled"))
                        {
                            status = serialstatus.Closefile;
                            Console.Write("CloseFile: " + line);
                            break;
                        }
                        sw.Write(line);
                        continue;

                    case serialstatus.Waiting:
                        if (line.Contains("Dumping Log") || line.Contains("GPS:") || line.Contains("NTUN:") || line.Contains("CTUN:") || line.Contains("PM:"))
                        {
                            status = serialstatus.Reading;
                            Console.Write("Reading: " + line);
                        }
                        break;
                    }
                    lock (thisLock)
                    {
                        this.BeginInvoke((MethodInvoker) delegate()
                        {
                            Console.Write(line);

                            TXT_seriallog.AppendText(line.Replace((char)0x0, ' '));

                            // auto scroll
                            if (TXT_seriallog.TextLength >= 10000)
                            {
                                TXT_seriallog.Text = TXT_seriallog.Text.Substring(TXT_seriallog.TextLength / 2);
                            }

                            TXT_seriallog.SelectionStart = TXT_seriallog.Text.Length;

                            TXT_seriallog.ScrollToCaret();

                            TXT_seriallog.Refresh();
                        });
                    }
                }

                //log.Info("exit while");
            }
            catch (Exception ex) { CustomMessageBox.Show("Error reading data" + ex.ToString()); }
        }