ConvertBin() public static method

public static ConvertBin ( string inputfn, string outputfn, bool showui = true ) : void
inputfn string
outputfn string
showui bool
return void
コード例 #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;
            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);
        }
コード例 #2
0
        private void BUT_bintolog_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Binary Log|*.bin";

            ofd.ShowDialog();

            if (File.Exists(ofd.FileName))
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "log|*.log";

                DialogResult res = sfd.ShowDialog();

                if (res == System.Windows.Forms.DialogResult.OK)
                {
                    BinaryLog.ConvertBin(ofd.FileName, sfd.FileName);
                }
            }
        }
コード例 #3
0
        string GetLog(ushort no, string fileName)
        {
            log.Info("GetLog " + no);

            MainV2.comPort.Progress += comPort_Progress;

            status = SerialStatus.Reading;

            // used for log fn
            MAVLink.MAVLinkMessage hbpacket = MainV2.comPort.getHeartBeat();

            if (hbpacket != null)
            {
                log.Info("Got hbpacket length: " + hbpacket.Length);
            }

            // get df log from mav
            using (var ms = MainV2.comPort.GetLog(no))
            {
                if (ms != null)
                {
                    log.Info("Got Log length: " + ms.Length);
                }

                ms.Seek(0, SeekOrigin.Begin);

                status = SerialStatus.Done;

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

                logfile = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                          + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                          + hbpacket.sysid + Path.DirectorySeparatorChar + no + " " + MakeValidFileName(fileName) + ".bin";

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

                log.Info("about to write: " + logfile);
                // save memorystream to file
                using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(logfile)))
                {
                    byte[] buffer = new byte[256 * 1024];
                    while (ms.Position < ms.Length)
                    {
                        int read = ms.Read(buffer, 0, buffer.Length);
                        bw.Write(buffer, 0, read);
                    }
                }
            }

            log.Info("about to convertbin: " + logfile);

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

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

            // rename file if needed
            log.Info("about to GetFirstGpsTime: " + logfile);
            // get gps time of assci log
            DateTime logtime = new DFLog().GetFirstGpsTime(logfile);

            // rename log is we have a valid gps time
            if (logtime != DateTime.MinValue)
            {
                string newlogfilename = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                                        + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                                        + hbpacket.sysid + 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(Strings.ErrorRenameFile + " " + logfile + "\nto " + newlogfilename,
                                          Strings.ERROR);
                }
            }

            MainV2.comPort.Progress -= comPort_Progress;

            return(logfile);
        }
コード例 #4
0
        string GetLog(string no, string fileName)
        {
            log.Info("GetLog " + no);


            status = SerialStatus.Reading;

            logfile = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                      + MakeValidFileName(fileName) + ".bin";

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

            log.Info("about to write: " + logfile);
            // save memorystream to file


            SftpClient client = new SftpClient(_connectionInfo);

            client.Connect();

            using (var logstream = File.Open(logfile, FileMode.Create, FileAccess.Write))
            {
                client.DownloadFile(no, logstream, downloadCallback);
            }

            client.Disconnect();

            log.Info("about to convertbin: " + logfile);

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

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

            // rename file if needed
            log.Info("about to GetFirstGpsTime: " + logfile);
            // get gps time of assci log
            DateTime logtime = new DFLog().GetFirstGpsTime(logfile);

            // rename log is we have a valid gps time
            if (logtime != DateTime.MinValue)
            {
                string newlogfilename = Settings.Instance.LogDir + 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(Strings.ErrorRenameFile + " " + logfile + "\nto " + newlogfilename,
                                          Strings.ERROR);
                }
            }

            MainV2.comPort.Progress -= comPort_Progress;

            return(logfile);
        }
コード例 #5
0
        public static void ProcessLog(string fn)
        {
            StreamReader sr;

            if (fn.ToLower().EndsWith(".bin"))
            {
                string tmpfile = Path.GetTempFileName();
                BinaryLog.ConvertBin(fn, tmpfile);
                sr = new StreamReader(tmpfile);
            }
            else
            {
                sr = new StreamReader(fn);
            }

            // store all the arrays
            List <MLArray> mlList = new List <MLArray>();
            // store data to putinto the arrays
            Dictionary <string, DoubleList> data = new Dictionary <string, DoubleList>();
            // store line item lengths
            Hashtable len = new Hashtable();
            // store whats we have seen in the log
            Hashtable seen = new Hashtable();
            // store the params seen
            SortedDictionary <string, double> param = new SortedDictionary <string, double>();

            // keep track of line no
            int a = 0;

            log.Info("ProcessLog start " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0));

            while (!sr.EndOfStream)
            {
                var line = sr.ReadLine();

                a++;
                if (a % 100 == 0)
                {
                    Console.Write(a + "\r");
                }

                string strLine = line.Replace(", ", ",");
                strLine = strLine.Replace(": ", ":");

                string[] items = strLine.Split(',', ':');

                // process the fmt messages
                if (line.StartsWith("FMT"))
                {
                    // +1 for line no
                    string[] names = new string[items.Length - 5 + 1];
                    names[0] = "LineNo";
                    Array.ConstrainedCopy(items, 5, names, 1, names.Length - 1);

                    MLArray format = CreateCellArray(items[3] + "_label", names);

                    if (items[3] == "PARM")
                    {
                    }
                    else
                    {
                        mlList.Add(format);
                    }

                    len[items[3]] = names.Length;
                } // process param messages
                else if (line.StartsWith("PARM"))
                {
                    try
                    {
                        param[items[2]] = double.Parse(items[3], CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                    }
                } // everyting else is generic
                else
                {
                    // make sure the line is long enough
                    if (items.Length < 2)
                    {
                        continue;
                    }
                    // check we have a valid fmt message for this message type
                    if (!len.ContainsKey(items[0]))
                    {
                        continue;
                    }
                    // check the fmt length matchs what the log has
                    if (items.Length != (int)len[items[0]])
                    {
                        continue;
                    }

                    // make it as being seen
                    seen[items[0]] = 1;

                    double[] dbarray = new double[items.Length];

                    // set line no
                    dbarray[0] = a;

                    for (int n = 1; n < items.Length; n++)
                    {
                        double dbl = 0;

                        double.TryParse(items[n], NumberStyles.Any, CultureInfo.InvariantCulture, out dbl);

                        dbarray[n] = dbl;
                    }

                    if (!data.ContainsKey(items[0]))
                    {
                        data[items[0]] = new DoubleList();
                    }

                    data[items[0]].Add(dbarray);
                }

                // split at x records
                if (a % 2000000 == 0)
                {
                    GC.Collect();
                    DoWrite(fn + "-" + a, data, param, mlList, seen);
                    mlList.Clear();
                    data.Clear();
                    param.Clear();
                    seen.Clear();
                    GC.Collect();
                }
            }

            DoWrite(fn + "-" + a, data, param, mlList, seen);

            sr.Close();
        }
コード例 #6
0
        string GetLog(ushort no, string fileName)
        {
            log.Info("GetLog " + no);

            MainV2.comPort.Progress += comPort_Progress;

            status = SerialStatus.Reading;

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

            if (hbpacket != null)
            {
                log.Info("Got hbpacket length: " + hbpacket.Length);
            }

            // get df log from mav
            using (var ms = MainV2.comPort.GetLog(no))
            {
                if (ms != null)
                {
                    log.Info("Got Log length: " + ms.Length);
                }

                ms.Seek(0, SeekOrigin.Begin);

                status = SerialStatus.Done;

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

                logfile = Settings.Instance.LogDir + Path.DirectorySeparatorChar
                          + MainV2.comPort.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                          + hbpacket[3] + Path.DirectorySeparatorChar + no + " " + MakeValidFileName(fileName) + ".bin";

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

                log.Info("about to write: " + logfile);
                // save memorystream to file
                using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(logfile)))
                {
                    byte[] buffer = new byte[256 * 1024];
                    while (ms.Position < ms.Length)
                    {
                        int read = ms.Read(buffer, 0, buffer.Length);
                        bw.Write(buffer, 0, read);
                    }
                }
            }

            log.Info("about to convertbin: " + logfile);

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

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

            MainV2.comPort.Progress -= comPort_Progress;

            return(logfile);
        }