ReadLog() public method

public ReadLog ( Stream fn ) : List
fn Stream
return List
        public static double[] getOffsetsLog(string fn)
        {
            // this is for a dxf
            Polyline3dVertex vertex;
            List<Polyline3dVertex> vertexes = new List<Polyline3dVertex>();

            List<Tuple<float, float, float>> data = new List<Tuple<float, float, float>>();

            List<Tuple<float, float, float>> data2 = new List<Tuple<float, float, float>>();

            Log.DFLog dflog = new Log.DFLog();

            var logfile = dflog.ReadLog(fn);

            foreach (var line in logfile)
            {
                if (line.msgtype == "MAG" || line.msgtype == "MAG2")
                {
                    int indexmagx = dflog.FindMessageOffset(line.msgtype, "MagX");
                    int indexmagy = dflog.FindMessageOffset(line.msgtype, "MagY");
                    int indexmagz = dflog.FindMessageOffset(line.msgtype, "MagZ");

                    int indexoffsetx = dflog.FindMessageOffset(line.msgtype, "OfsX");
                    int indexoffsety = dflog.FindMessageOffset(line.msgtype, "OfsY");
                    int indexoffsetz = dflog.FindMessageOffset(line.msgtype, "OfsZ");

                    if (indexmagx != -1 && indexoffsetx != -1)
                    {
                        float magx = float.Parse(line.items[indexmagx]);
                        float magy = float.Parse(line.items[indexmagy]);
                        float magz = float.Parse(line.items[indexmagz]);

                        float offsetx = float.Parse(line.items[indexoffsetx]);
                        float offsety = float.Parse(line.items[indexoffsety]);
                        float offsetz = float.Parse(line.items[indexoffsetz]);

                        //offsetx = offsety = offsetz = 0;

                        if (line.msgtype == "MAG")
                        {
                            data.Add(new Tuple<float, float, float>(
                                magx - offsetx,
                                magy - offsety,
                                magz - offsetz));

                            // fox dxf
                            vertex = new Polyline3dVertex(new Vector3f(magx - offsetx,
                                magy - offsety,
                                magz - offsetz)
                                );
                            vertexes.Add(vertex);
                        }
                        else if (line.msgtype == "MAG2")
                        {
                            data2.Add(new Tuple<float, float, float>(
                                magx - offsetx,
                                magy - offsety,
                                magz - offsetz));
                        }
                    }
                }
            }

            double[] x = LeastSq(data);

            if (data2.Count > 0)
            {
                double[] x2 = LeastSq(data2);
            }

            log.Info("Least Sq Done " + DateTime.Now);

            doDXF(vertexes, x);

            Array.Resize<double>(ref x, 3);

            return x;
        }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Hashtable seenmessagetypes = new Hashtable();

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter           = "Log Files|*.log;*.bin";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            openFileDialog1.InitialDirectory = MainV2.LogDir;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Stream stream;

                    if (openFileDialog1.FileName.ToLower().EndsWith(".bin"))
                    {
                        log.Info("before " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0));
                        // extract log - converts to assci lines
                        var loglines = BinaryLog.ReadLog(openFileDialog1.FileName);
                        log.Info("loglines " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0));
                        GC.Collect();
                        log.Info("loglines2 " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0));
                        // create temp file
                        string tempfile = Path.GetTempFileName();
                        log.Info("temp file " + tempfile);
                        stream = File.Open(tempfile, FileMode.Create, FileAccess.ReadWrite, FileShare.Delete);
                        // save ascii lines to file
                        foreach (string line in loglines)
                        {
                            stream.Write(ASCIIEncoding.ASCII.GetBytes(line), 0, line.Length);
                        }
                        stream.Flush();
                        // back to stream start
                        stream.Seek(0, SeekOrigin.Begin);
                        loglines.Clear();
                        loglines = null;
                        // force memory reclaim after loglines clear
                        GC.Collect();
                        log.Info("loglines.clear " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0));
                    }
                    else
                    {
                        stream = File.Open(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    }

                    logdata = DFLog.ReadLog(stream);

                    this.Text = "Log Browser - " + Path.GetFileName(openFileDialog1.FileName);
                    log.Info("about to create DataTable " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0));
                    m_dtCSV = new DataTable();

                    log.Info("process to datagrid " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0));

                    bool largelog = logdata.Count > 500000 ? true : false;

                    foreach (var item in logdata)
                    {
                        if (item.items != null)
                        {
                            while (m_dtCSV.Columns.Count < (item.items.Length + typecoloum))
                            {
                                m_dtCSV.Columns.Add();
                            }

                            seenmessagetypes[item.msgtype] = "";

                            if (largelog)
                            {
                                continue;
                            }

                            DataRow dr = m_dtCSV.NewRow();

                            dr[0] = item.lineno;
                            dr[1] = item.time.ToString("yyyy-MM-dd HH:mm:ss.fff");

                            for (int a = 0; a < item.items.Length; a++)
                            {
                                dr[a + typecoloum] = item.items[a];
                            }

                            m_dtCSV.Rows.Add(dr);
                        }
                    }

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

                    //PopulateDataTableFromUploadedFile(stream);

                    stream.Close();

                    log.Info("set dgv datasourse " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0));

                    if (MainV2.MONO)
                    {
                        //if (m_dtCSV.Rows.Count > 5000)
                        // {
                        //     CustomMessageBox.Show("This log apears to be a large log, the grid view will be disabled.\nAll graphing will still work however", "Large Log");
                        //     dataGridView1.Visible = false;
                        // }
                        // else
                        {
                            BindingSource bs = new BindingSource();
                            bs.DataSource            = m_dtCSV;
                            dataGridView1.DataSource = bs;
                        }
                    }
                    else
                    {
                        dataGridView1.VirtualMode = true;
                        dataGridView1.RowCount    = logdata.Count;
                        dataGridView1.ColumnCount = m_dtCSV.Columns.Count;
                    }



                    dataGridView1.Columns[0].Visible = false;

                    log.Info("datasource set " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0));
                }
                catch (Exception ex) { CustomMessageBox.Show("Failed to read File: " + ex.ToString()); }

                foreach (DataGridViewColumn column in dataGridView1.Columns)
                {
                    column.SortMode = DataGridViewColumnSortMode.NotSortable;
                }


                CreateChart(zg1);

                ResetTreeView(seenmessagetypes);

                if (DFLog.logformat.Count == 0)
                {
                    CustomMessageBox.Show("Log Browse will not function correctly without FMT messages in your log.\nThese appear to be missing from your log.", "Error");
                    this.Close();
                    return;
                }
            }
            else
            {
                this.Close();
                return;
            }
        }
Esempio n. 3
0
        public static double[] getOffsetsLog(string fn)
        {
            // this is for a dxf
            Polyline3dVertex        vertex;
            List <Polyline3dVertex> vertexes = new List <Polyline3dVertex>();

            List <Tuple <float, float, float> > data = new List <Tuple <float, float, float> >();

            List <Tuple <float, float, float> > data2 = new List <Tuple <float, float, float> >();

            Log.DFLog dflog = new Log.DFLog();

            var logfile = dflog.ReadLog(fn);

            foreach (var line in logfile)
            {
                if (line.msgtype == "MAG" || line.msgtype == "MAG2")
                {
                    int indexmagx = dflog.FindMessageOffset(line.msgtype, "MagX");
                    int indexmagy = dflog.FindMessageOffset(line.msgtype, "MagY");
                    int indexmagz = dflog.FindMessageOffset(line.msgtype, "MagZ");

                    int indexoffsetx = dflog.FindMessageOffset(line.msgtype, "OfsX");
                    int indexoffsety = dflog.FindMessageOffset(line.msgtype, "OfsY");
                    int indexoffsetz = dflog.FindMessageOffset(line.msgtype, "OfsZ");

                    if (indexmagx != -1 && indexoffsetx != -1)
                    {
                        float magx = float.Parse(line.items[indexmagx]);
                        float magy = float.Parse(line.items[indexmagy]);
                        float magz = float.Parse(line.items[indexmagz]);

                        float offsetx = float.Parse(line.items[indexoffsetx]);
                        float offsety = float.Parse(line.items[indexoffsety]);
                        float offsetz = float.Parse(line.items[indexoffsetz]);

                        //offsetx = offsety = offsetz = 0;

                        if (line.msgtype == "MAG")
                        {
                            data.Add(new Tuple <float, float, float>(
                                         magx - offsetx,
                                         magy - offsety,
                                         magz - offsetz));

                            // fox dxf
                            vertex = new Polyline3dVertex(new Vector3f(magx - offsetx,
                                                                       magy - offsety,
                                                                       magz - offsetz)
                                                          );
                            vertexes.Add(vertex);
                        }
                        else if (line.msgtype == "MAG2")
                        {
                            data2.Add(new Tuple <float, float, float>(
                                          magx - offsetx,
                                          magy - offsety,
                                          magz - offsetz));
                        }
                    }
                }
            }

            double[] x = LeastSq(data);

            if (data2.Count > 0)
            {
                double[] x2 = LeastSq(data2);
            }

            log.Info("Least Sq Done " + DateTime.Now);

            doDXF(vertexes, x);

            Array.Resize <double>(ref x, 3);

            return(x);
        }
Esempio n. 4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            rowno = 1;

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter           = "Log Files|*.log;*.bin";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            openFileDialog1.InitialDirectory = MainV2.LogDir;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Stream stream;

                    if (openFileDialog1.FileName.ToLower().EndsWith(".bin"))
                    {
                        // extract log
                        List <string> loglines = BinaryLog.ReadLog(openFileDialog1.FileName);
                        // convert log to memory stream;
                        stream = new MemoryStream();
                        // create single string with entire log
                        foreach (string line in loglines)
                        {
                            stream.Write(ASCIIEncoding.ASCII.GetBytes(line), 0, line.Length);
                        }
                        // back to stream start
                        stream.Seek(0, SeekOrigin.Begin);
                    }
                    else
                    {
                        stream = File.Open(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    }

                    var logdata = DFLog.ReadLog(stream);

                    this.Text = "Log Browser - " + Path.GetFileName(openFileDialog1.FileName);
                    m_dtCSV   = new DataTable();

                    log.Info("process to datagrid");

                    foreach (var item in logdata)
                    {
                        if (item.items != null)
                        {
                            while (m_dtCSV.Columns.Count < (item.items.Length + typecoloum))
                            {
                                m_dtCSV.Columns.Add();
                            }

                            DataRow dr = m_dtCSV.NewRow();

                            dr[0] = item.lineno;
                            dr[1] = item.time.ToString("yyyy-MM-dd HH:mm:ss.fff");

                            for (int a = 0; a < item.items.Length; a++)
                            {
                                dr[a + typecoloum] = item.items[a];
                            }

                            m_dtCSV.Rows.Add(dr);
                        }
                    }

                    log.Info("Done");

                    //PopulateDataTableFromUploadedFile(stream);

                    stream.Close();

                    log.Info("set dgv datasourse");

                    dataGridView1.DataSource = m_dtCSV;

                    dataGridView1.Columns[0].Visible = false;

                    log.Info("datasource set");
                }
                catch (Exception ex) { CustomMessageBox.Show("Failed to read File: " + ex.ToString()); }

                foreach (DataGridViewColumn column in dataGridView1.Columns)
                {
                    column.SortMode = DataGridViewColumnSortMode.NotSortable;
                }

                log.Info("Get map");

                DrawMap();

                log.Info("map done");

                CreateChart(zg1);
            }
            else
            {
                this.Close();
                return;
            }
        }