From 9077192f5b0636e51769cb5a368cceb94bea4e82 Mon Sep 17 00:00:00 2001 From: Michael Oborne Date: Sat, 12 Sep 2015 07:50:46 +0800 Subject: [PATCH] DFLog: make threadsafe --- GeoRef/georefimage.cs | 42 ++++++++-------- Log/DFLog.cs | 28 +++++------ Log/LogBrowse.cs | 101 +++++++++++++++++++------------------- Log/LogDownload.cs | 2 +- Log/LogDownloadMavLink.cs | 2 +- Log/LogMap.cs | 17 ++++--- Log/LogOutput.cs | 70 +++++++++++++------------- MagCalib.cs | 16 +++--- Utilities/fftui.cs | 60 +++++++++++----------- 9 files changed, 174 insertions(+), 164 deletions(-) diff --git a/GeoRef/georefimage.cs b/GeoRef/georefimage.cs index 27875a3680..f16cb3b9f9 100644 --- a/GeoRef/georefimage.cs +++ b/GeoRef/georefimage.cs @@ -52,6 +52,8 @@ private enum PROCESSING_MODE private Label label28; private List JXL_StationIDs = new List(); + DFLog dflog = new DFLog(); + public Georefimage() { InitializeComponent(); @@ -233,25 +235,25 @@ private Dictionary readGPSMsgInLog(string fn) a++; string line = sr.ReadLine(); - var item = DFLog.GetDFItemFromLine(line, a); + var item = dflog.GetDFItemFromLine(line, a); // Look for GPS Messages. However GPS Messages do not have Roll, Pitch and Yaw // So we have to look for one ATT message after having read a GPS one if (item.msgtype == "GPS") { - if (!DFLog.logformat.ContainsKey("GPS")) + if (!dflog.logformat.ContainsKey("GPS")) continue; - int latindex = DFLog.FindMessageOffset("GPS", "Lat"); - int lngindex = DFLog.FindMessageOffset("GPS", "Lng"); - int altindex = DFLog.FindMessageOffset("GPS", "Alt"); - int raltindex = DFLog.FindMessageOffset("GPS", "RAlt"); + int latindex = dflog.FindMessageOffset("GPS", "Lat"); + int lngindex = dflog.FindMessageOffset("GPS", "Lng"); + int altindex = dflog.FindMessageOffset("GPS", "Alt"); + int raltindex = dflog.FindMessageOffset("GPS", "RAlt"); VehicleLocation location = new VehicleLocation(); try { - location.Time = DFLog.GetTimeGPS(line); + location.Time = dflog.GetTimeGPS(line); location.Lat = double.Parse(item.items[latindex], CultureInfo.InvariantCulture); location.Lon = double.Parse(item.items[lngindex], CultureInfo.InvariantCulture); location.RelAlt = double.Parse(item.items[raltindex], CultureInfo.InvariantCulture); @@ -275,9 +277,9 @@ private Dictionary readGPSMsgInLog(string fn) } else if (item.msgtype == "ATT") { - int Rindex = DFLog.FindMessageOffset("ATT", "Roll"); - int Pindex = DFLog.FindMessageOffset("ATT", "Pitch"); - int Yindex = DFLog.FindMessageOffset("ATT", "Yaw"); + int Rindex = dflog.FindMessageOffset("ATT", "Roll"); + int Pindex = dflog.FindMessageOffset("ATT", "Pitch"); + int Yindex = dflog.FindMessageOffset("ATT", "Yaw"); currentRoll = float.Parse(item.items[Rindex], CultureInfo.InvariantCulture); currentPitch = float.Parse(item.items[Pindex], CultureInfo.InvariantCulture); @@ -319,21 +321,21 @@ private Dictionary readCAMMsgInLog(string fn) a++; string line = sr.ReadLine(); - var item = DFLog.GetDFItemFromLine(line, a); + var item = dflog.GetDFItemFromLine(line, a); if (item.msgtype == "CAM") { - int latindex = DFLog.FindMessageOffset("CAM", "Lat"); - int lngindex = DFLog.FindMessageOffset("CAM", "Lng"); - int altindex = DFLog.FindMessageOffset("CAM", "Alt"); - int raltindex = DFLog.FindMessageOffset("CAM", "RelAlt"); + int latindex = dflog.FindMessageOffset("CAM", "Lat"); + int lngindex = dflog.FindMessageOffset("CAM", "Lng"); + int altindex = dflog.FindMessageOffset("CAM", "Alt"); + int raltindex = dflog.FindMessageOffset("CAM", "RelAlt"); - int rindex = DFLog.FindMessageOffset("CAM", "Roll"); - int pindex = DFLog.FindMessageOffset("CAM", "Pitch"); - int yindex = DFLog.FindMessageOffset("CAM", "Yaw"); + int rindex = dflog.FindMessageOffset("CAM", "Roll"); + int pindex = dflog.FindMessageOffset("CAM", "Pitch"); + int yindex = dflog.FindMessageOffset("CAM", "Yaw"); - int gtimeindex = DFLog.FindMessageOffset("CAM", "GPSTime"); - int gweekindex = DFLog.FindMessageOffset("CAM", "GPSWeek"); + int gtimeindex = dflog.FindMessageOffset("CAM", "GPSTime"); + int gweekindex = dflog.FindMessageOffset("CAM", "GPSWeek"); VehicleLocation p = new VehicleLocation(); diff --git a/Log/DFLog.cs b/Log/DFLog.cs index 4956722e77..15ddcf01b9 100644 --- a/Log/DFLog.cs +++ b/Log/DFLog.cs @@ -134,9 +134,9 @@ public enum events DATA_PARACHUTE_RELEASED = 51, } - public static Dictionary logformat = new Dictionary(); + public Dictionary logformat = new Dictionary(); - public static void Clear() + public void Clear() { logformat.Clear(); @@ -150,7 +150,7 @@ public static void Clear() gpsstarttime = DateTime.MinValue; } - public static DateTime GetFirstGpsTime(string fn) + public DateTime GetFirstGpsTime(string fn) { using (StreamReader sr = new StreamReader(fn)) { @@ -174,7 +174,7 @@ public static DateTime GetFirstGpsTime(string fn) return DateTime.MinValue; } - public static List ReadLog(string fn) + public List ReadLog(string fn) { List answer = new List(); @@ -187,15 +187,15 @@ public static List ReadLog(string fn) } // current gps time - static DateTime gpstime = DateTime.MinValue; + DateTime gpstime = DateTime.MinValue; // last time of message - static DateTime lasttime = DateTime.MinValue; + DateTime lasttime = DateTime.MinValue; // first valid gpstime - static DateTime gpsstarttime = DateTime.MinValue; + DateTime gpsstarttime = DateTime.MinValue; - static int msoffset = 0; + int msoffset = 0; - public static List ReadLog(Stream fn) + public List ReadLog(Stream fn) { Clear(); GC.Collect(); @@ -243,7 +243,7 @@ public static List ReadLog(Stream fn) return answer; } - public static DFItem GetDFItemFromLine(string line, int lineno) + public DFItem GetDFItemFromLine(string line, int lineno) { //line = line.Replace(",", ","); @@ -389,7 +389,7 @@ public static DFItem GetDFItemFromLine(string line, int lineno) return item; } - public static void FMTLine(string strLine) + public void FMTLine(string strLine) { try { @@ -413,7 +413,7 @@ public static void FMTLine(string strLine) //FMT, 130, 45, GPS, BIHBcLLeeEefI, Status,TimeMS,Week,NSats,HDop,Lat,Lng,RelAlt,Alt,Spd,GCrs,VZ,T //GPS, 3, 130040903, 1769, 10, 0.00, -35.3547178, 149.1696673, 885.52, 870.45, 24.56, 321.44, 2.450000, 127615 - public static DateTime GetTimeGPS(string gpsline) + public DateTime GetTimeGPS(string gpsline) { if (gpsline.StartsWith("GPS") && logformat.Count > 0) { @@ -456,7 +456,7 @@ public static DateTime GetTimeGPS(string gpsline) public static DateTime gpsTimeToTime(int week, double sec) { - int leap = 16; + int leap = 17; // not correct for leap seconds day days weeks seconds var basetime = new DateTime(1980, 1, 6, 0, 0, 0, DateTimeKind.Utc); @@ -466,7 +466,7 @@ public static DateTime gpsTimeToTime(int week, double sec) return basetime.ToLocalTime(); } - public static int FindMessageOffset(string linetype,string find) + public int FindMessageOffset(string linetype,string find) { if (logformat.ContainsKey(linetype)) return Log.DFLog.FindInArray(logformat[linetype].FieldNames, find); diff --git a/Log/LogBrowse.cs b/Log/LogBrowse.cs index 586a9395ca..245616dc99 100644 --- a/Log/LogBrowse.cs +++ b/Log/LogBrowse.cs @@ -23,7 +23,6 @@ public partial class LogBrowse : Form private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); DataTable m_dtCSV = new DataTable(); - //List logdata; CollectionBuffer logdata; Hashtable logdatafilter = new Hashtable(); Hashtable seenmessagetypes = new Hashtable(); @@ -40,6 +39,8 @@ public partial class LogBrowse : Form LineObj m_cursorLine = null; Hashtable dataModifierHash = new Hashtable(); + DFLog dflog = new DFLog(); + class DataModifer { private readonly bool isValid; @@ -292,8 +293,6 @@ private void LogBrowse_Load(object sender, EventArgs e) m_dtCSV.Clear(); - DFLog.Clear(); - if (logdata != null) logdata.Clear(); @@ -339,7 +338,7 @@ private void LogBrowse_Load(object sender, EventArgs e) log.Info("got log lines " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0)); - //logdata = DFLog.ReadLog(stream); + //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)); @@ -354,7 +353,7 @@ private void LogBrowse_Load(object sender, EventArgs e) foreach (var item2 in logdata) { b++; - var item = DFLog.GetDFItemFromLine(item2, b); + var item = dflog.GetDFItemFromLine(item2, b); if (item.items != null) { @@ -453,7 +452,7 @@ private void LogBrowse_Load(object sender, EventArgs e) ResetTreeView(seenmessagetypes); - if (DFLog.logformat.Count == 0) + if (dflog.logformat.Count == 0) { CustomMessageBox.Show(Strings.WarningLogBrowseFMTMissing, Strings.ERROR); this.Close(); @@ -489,7 +488,7 @@ private void ResetTreeView(Hashtable seenmessagetypes) treeView1.Nodes.Clear(); dataModifierHash = new Hashtable(); - var sorted = new SortedList(DFLog.logformat); + var sorted = new SortedList(dflog.logformat); foreach (DFLog.Label item in sorted.Values) { @@ -528,10 +527,10 @@ private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) string option = dataGridView1[typecoloum, e.RowIndex].EditedFormattedValue.ToString(); // new self describing log - if (DFLog.logformat.ContainsKey(option)) + if (dflog.logformat.ContainsKey(option)) { int a = typecoloum + 1; - foreach (string name in DFLog.logformat[option].FieldNames) + foreach (string name in dflog.logformat[option].FieldNames) { dataGridView1.Columns[a].HeaderText = name; a++; @@ -703,7 +702,7 @@ void graphit_clickprocess(bool left = true) return; } - if (!DFLog.logformat.ContainsKey(type)) + if (!dflog.logformat.ContainsKey(type)) { CustomMessageBox.Show(Strings.NoFMTMessage + type, Strings.ERROR); return; @@ -715,13 +714,13 @@ void graphit_clickprocess(bool left = true) return; } - if (DFLog.logformat[type].FieldNames.Length <= (col - typecoloum - 1)) + if (dflog.logformat[type].FieldNames.Length <= (col - typecoloum - 1)) { CustomMessageBox.Show(Strings.InvalidField, Strings.ERROR); return; } - string fieldname = DFLog.logformat[type].FieldNames[col - typecoloum - 1]; + string fieldname = dflog.logformat[type].FieldNames[col - typecoloum - 1]; GraphItem(type, fieldname, left); } @@ -754,13 +753,13 @@ void GraphItem(string type, string fieldname, bool left = true) } } - if (!DFLog.logformat.ContainsKey(type)) + if (!dflog.logformat.ContainsKey(type)) { CustomMessageBox.Show(Strings.NoFMTMessage + type + " - " + fieldname, Strings.ERROR); return; } - int col = DFLog.FindMessageOffset(type, fieldname); + int col = dflog.FindMessageOffset(type, fieldname); // field does not exist if (col == -1) @@ -791,7 +790,7 @@ void GraphItem(string type, string fieldname, bool left = true) continue; } - var item = DFLog.GetDFItemFromLine(item2, b); + var item = dflog.GetDFItemFromLine(item2, b); if (item.msgtype == type) { @@ -897,20 +896,20 @@ void DrawErrors() continue; } - var item = DFLog.GetDFItemFromLine(item2, b); + var item = dflog.GetDFItemFromLine(item2, b); if (item.msgtype == "ERR") { - if (!DFLog.logformat.ContainsKey("ERR")) + if (!dflog.logformat.ContainsKey("ERR")) return; - int index = DFLog.FindMessageOffset("ERR", "Subsys"); + int index = dflog.FindMessageOffset("ERR", "Subsys"); if (index == -1) { continue; } - int index2 = DFLog.FindMessageOffset("ERR", "ECode"); + int index2 = dflog.FindMessageOffset("ERR", "ECode"); if (index2 == -1) { continue; @@ -974,14 +973,14 @@ void DrawModes() continue; } - var item = DFLog.GetDFItemFromLine(item2, b); + var item = dflog.GetDFItemFromLine(item2, b); if (item.msgtype == "MODE") { - if (!DFLog.logformat.ContainsKey("MODE")) + if (!dflog.logformat.ContainsKey("MODE")) return; - int index = DFLog.FindMessageOffset("MODE", "Mode"); + int index = dflog.FindMessageOffset("MODE", "Mode"); if (index == -1) { continue; @@ -1048,15 +1047,15 @@ void DrawTime() continue; } - var item = DFLog.GetDFItemFromLine(item2, b); + var item = dflog.GetDFItemFromLine(item2, b); if (item.msgtype == "GPS") { - if (!DFLog.logformat.ContainsKey("GPS")) + if (!dflog.logformat.ContainsKey("GPS")) break; - int index = DFLog.FindMessageOffset("GPS", "TimeMS"); - int index2 = DFLog.FindMessageOffset("GPS", "TimeUS"); + int index = dflog.FindMessageOffset("GPS", "TimeMS"); + int index2 = dflog.FindMessageOffset("GPS", "TimeUS"); if (index == -1) { if (index2 == -1) @@ -1130,22 +1129,22 @@ void DrawMap() //zg1.GraphPane.GraphObjList.Clear(); //check if GPS data are available - if (!DFLog.logformat.ContainsKey("GPS")) + if (!dflog.logformat.ContainsKey("GPS")) return; - int latindex = DFLog.FindMessageOffset("GPS", "Lat"); + int latindex = dflog.FindMessageOffset("GPS", "Lat"); if (latindex == -1) { return; } - int lngindex2 = DFLog.FindMessageOffset("GPS", "Lng"); + int lngindex2 = dflog.FindMessageOffset("GPS", "Lng"); if (lngindex2 == -1) { return; } - int statusindex3 = DFLog.FindMessageOffset("GPS", "Status"); + int statusindex3 = dflog.FindMessageOffset("GPS", "Status"); if (statusindex3 == -1) { return; @@ -1155,11 +1154,11 @@ void DrawMap() int poslngindex = -1; int posaltindex = -1; // check for POS message - if (DFLog.logformat.ContainsKey("POS")) + if (dflog.logformat.ContainsKey("POS")) { - poslatindex = DFLog.FindMessageOffset("POS", "Lat"); - poslngindex = DFLog.FindMessageOffset("POS", "Lng"); - posaltindex = DFLog.FindMessageOffset("POS", "Alt"); + poslatindex = dflog.FindMessageOffset("POS", "Lat"); + poslngindex = dflog.FindMessageOffset("POS", "Lng"); + posaltindex = dflog.FindMessageOffset("POS", "Alt"); } int i = 0; @@ -1177,7 +1176,7 @@ void DrawMap() continue; } - var item = DFLog.GetDFItemFromLine(item2, b); + var item = dflog.GetDFItemFromLine(item2, b); if (item.msgtype == "GPS") { @@ -1274,22 +1273,22 @@ void DrawMap() { if (item.msgtype == "GPS") { - if (!DFLog.logformat.ContainsKey("GPS")) + if (!dflog.logformat.ContainsKey("GPS")) return null; - int index = DFLog.FindMessageOffset("GPS", "Lat"); + int index = dflog.FindMessageOffset("GPS", "Lat"); if (index == -1) { return null; } - int index2 = DFLog.FindMessageOffset("GPS", "Lng"); + int index2 = dflog.FindMessageOffset("GPS", "Lng"); if (index2 == -1) { return null; } - int index3 = DFLog.FindMessageOffset("GPS", "Status"); + int index3 = dflog.FindMessageOffset("GPS", "Status"); if (index3 == -1) { return null; @@ -1316,16 +1315,16 @@ void DrawMap() if (item.msgtype == "POS") { - if (!DFLog.logformat.ContainsKey("POS")) + if (!dflog.logformat.ContainsKey("POS")) return null; - int index = DFLog.FindMessageOffset("POS", "Lat"); + int index = dflog.FindMessageOffset("POS", "Lat"); if (index == -1) { return null; } - int index2 = DFLog.FindMessageOffset("POS", "Lng"); + int index2 = dflog.FindMessageOffset("POS", "Lng"); if (index2 == -1) { return null; @@ -1405,7 +1404,7 @@ private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCel foreach (var item2 in logdata) { b++; - var item = DFLog.GetDFItemFromLine(item2, b); + var item = dflog.GetDFItemFromLine(item2, b); if (item.msgtype == null) continue; @@ -1438,7 +1437,7 @@ private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCel foreach (var item2 in logdata) { b++; - var item = DFLog.GetDFItemFromLine(item2, b); + var item = dflog.GetDFItemFromLine(item2, b); if (item.msgtype == opt.SelectedItem) { @@ -1728,7 +1727,7 @@ private void dataGridView1_CellValueNeeded(object sender, DataGridViewCellValueE { var item2 = logdata[e.RowIndex]; - var item = DFLog.GetDFItemFromLine(item2, e.RowIndex); + var item = dflog.GetDFItemFromLine(item2, e.RowIndex); if (logdatafilter.Count > 0) { @@ -1799,10 +1798,10 @@ bool GetTimeFromRow(int lineNumber, out int millis) bool ret = false; millis = 0; - if (!DFLog.logformat.ContainsKey("IMU")) + if (!dflog.logformat.ContainsKey("IMU")) return ret; - int index = DFLog.FindMessageOffset("IMU", "TimeMS"); + int index = dflog.FindMessageOffset("IMU", "TimeMS"); if (index < 0) return ret; @@ -1845,12 +1844,12 @@ bool GetGPSFromRow(int lineNumber, out PointLatLng pt) bool ret = false; pt = new PointLatLng(); - if (!DFLog.logformat.ContainsKey("GPS")) + if (!dflog.logformat.ContainsKey("GPS")) return ret; - int index = DFLog.FindMessageOffset("GPS", "Lat"); - int index2 = DFLog.FindMessageOffset("GPS", "Lng"); - int index3 = DFLog.FindMessageOffset("GPS", "Status"); + int index = dflog.FindMessageOffset("GPS", "Lat"); + int index2 = dflog.FindMessageOffset("GPS", "Lng"); + int index3 = dflog.FindMessageOffset("GPS", "Status"); if ((index < 0) || (index2 < 0) || (index3 < 0)) return ret; diff --git a/Log/LogDownload.cs b/Log/LogDownload.cs index 7800fa4ba7..aef021fdf1 100644 --- a/Log/LogDownload.cs +++ b/Log/LogDownload.cs @@ -271,7 +271,7 @@ void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e) case serialstatus.Closefile: sw.Close(); - DateTime logtime = DFLog.GetFirstGpsTime(logfile); + DateTime logtime = new DFLog().GetFirstGpsTime(logfile); if (logtime != DateTime.MinValue) { diff --git a/Log/LogDownloadMavLink.cs b/Log/LogDownloadMavLink.cs index c7315979c7..7e53a5d841 100644 --- a/Log/LogDownloadMavLink.cs +++ b/Log/LogDownloadMavLink.cs @@ -180,7 +180,7 @@ string GetLog(ushort no) logfile = logfile + ".log"; // get gps time of assci log - DateTime logtime = DFLog.GetFirstGpsTime(logfile); + DateTime logtime = new DFLog().GetFirstGpsTime(logfile); // rename log is we have a valid gps time if (logtime != DateTime.MinValue) diff --git a/Log/LogMap.cs b/Log/LogMap.cs index 0c97372cbb..79a66654e9 100644 --- a/Log/LogMap.cs +++ b/Log/LogMap.cs @@ -73,7 +73,8 @@ public static void MapLogs(string[] logs) { bool bin = logfile.ToLower().EndsWith(".bin"); - BinaryLog binlog = new BinaryLog(); + BinaryLog binlog = new BinaryLog(); + DFLog dflog = new DFLog(); using (var st = File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { @@ -93,15 +94,15 @@ public static void MapLogs(string[] logs) } if (line.StartsWith("FMT")) - { - DFLog.FMTLine(line); + { + dflog.FMTLine(line); } else if (line.StartsWith("GPS")) - { - var item = DFLog.GetDFItemFromLine(line, 0); - - var lat = double.Parse(item.items[DFLog.FindMessageOffset(item.msgtype, "Lat")]); - var lon = double.Parse(item.items[DFLog.FindMessageOffset(item.msgtype, "Lng")]); + { + var item = dflog.GetDFItemFromLine(line, 0); + + var lat = double.Parse(item.items[dflog.FindMessageOffset(item.msgtype, "Lat")]); + var lon = double.Parse(item.items[dflog.FindMessageOffset(item.msgtype, "Lng")]); if (lat == 0 || lon == 0) continue; diff --git a/Log/LogOutput.cs b/Log/LogOutput.cs index 6c16cf40a6..9a4b9ff558 100644 --- a/Log/LogOutput.cs +++ b/Log/LogOutput.cs @@ -40,6 +40,8 @@ public class LogOutput private DateTime doevent = DateTime.Now; + DFLog dflog = new DFLog(); + public struct Data { public Model model; @@ -89,7 +91,7 @@ public void processLine(string line) { try { - DFLog.FMTLine(line); + dflog.FMTLine(line); } catch { } } @@ -120,12 +122,12 @@ public void processLine(string line) modelist[positionindex] = (items[1]); } } - else if (items[0].Contains("GPS") && DFLog.logformat.ContainsKey("GPS")) + else if (items[0].Contains("GPS") && dflog.logformat.ContainsKey("GPS")) { if (items[0].Contains("GPS2")) return; - if (int.Parse(items[DFLog.FindMessageOffset("GPS", "Status")]) < 3) + if (int.Parse(items[dflog.FindMessageOffset("GPS", "Status")]) < 3) return; if (position[positionindex] == null) @@ -136,11 +138,11 @@ public void processLine(string line) // 7 agl // 8 asl... - double alt = double.Parse(items[DFLog.FindMessageOffset("GPS", "Alt")], new System.Globalization.CultureInfo("en-US")); + double alt = double.Parse(items[dflog.FindMessageOffset("GPS", "Alt")], new System.Globalization.CultureInfo("en-US")); - position[positionindex].Add(new Point3D(double.Parse(items[DFLog.FindMessageOffset("GPS", "Lng")], + position[positionindex].Add(new Point3D(double.Parse(items[dflog.FindMessageOffset("GPS", "Lng")], new System.Globalization.CultureInfo("en-US")), - double.Parse(items[DFLog.FindMessageOffset("GPS", "Lat")], + double.Parse(items[dflog.FindMessageOffset("GPS", "Lat")], new System.Globalization.CultureInfo("en-US")), alt)); oldlastpos = lastpos; lastpos = (position[positionindex][position[positionindex].Count - 1]); @@ -224,11 +226,11 @@ public void processLine(string line) } else if (items[0].Contains("POS")) { - if (DFLog.logformat.ContainsKey("POS")) + if (dflog.logformat.ContainsKey("POS")) { - int poslatindex = DFLog.FindMessageOffset("POS", "Lat"); - int poslngindex = DFLog.FindMessageOffset("POS", "Lng"); - int posaltindex = DFLog.FindMessageOffset("POS", "Alt"); + int poslatindex = dflog.FindMessageOffset("POS", "Lat"); + int poslngindex = dflog.FindMessageOffset("POS", "Lng"); + int posaltindex = dflog.FindMessageOffset("POS", "Alt"); PosLatLngAlts.Add(new PointLatLngAlt(double.Parse(items[poslatindex], CultureInfo.InvariantCulture), double.Parse(items[poslngindex], CultureInfo.InvariantCulture), double.Parse(items[posaltindex], CultureInfo.InvariantCulture))); } @@ -271,7 +273,7 @@ public void processLine(string line) try { - dat.datetime = DFLog.GetTimeGPS(lastline); + dat.datetime = dflog.GetTimeGPS(lastline); } catch { @@ -286,13 +288,13 @@ public void processLine(string line) oldlastpos = lastpos; runmodel.Orientation.roll = - double.Parse(items[DFLog.FindMessageOffset("ATT", "Roll")], + double.Parse(items[dflog.FindMessageOffset("ATT", "Roll")], new System.Globalization.CultureInfo("en-US"))/-1; runmodel.Orientation.tilt = - double.Parse(items[DFLog.FindMessageOffset("ATT", "Pitch")], + double.Parse(items[dflog.FindMessageOffset("ATT", "Pitch")], new System.Globalization.CultureInfo("en-US"))/-1; runmodel.Orientation.heading = - double.Parse(items[DFLog.FindMessageOffset("ATT", "Yaw")], + double.Parse(items[dflog.FindMessageOffset("ATT", "Yaw")], new System.Globalization.CultureInfo("en-US"))/1; dat.model = runmodel; @@ -565,36 +567,36 @@ 6 GLONASS if (items[0].StartsWith("GRAW")) { - weekms = double.Parse(items[DFLog.FindMessageOffset("GRAW", "WkMS")]); - week = int.Parse(items[DFLog.FindMessageOffset("GRAW", "Week")]); - NSats = double.Parse(items[DFLog.FindMessageOffset("GRAW", "numSV")]); - sv = double.Parse(items[DFLog.FindMessageOffset("GRAW", "sv")]); - cpMes = double.Parse(items[DFLog.FindMessageOffset("GRAW", "cpMes")]); - prMes = double.Parse(items[DFLog.FindMessageOffset("GRAW", "prMes")]); - doMes = double.Parse(items[DFLog.FindMessageOffset("GRAW", "doMes")]); - mesQI = double.Parse(items[DFLog.FindMessageOffset("GRAW", "mesQI")]); - cno = double.Parse(items[DFLog.FindMessageOffset("GRAW", "cno")]); - lli = double.Parse(items[DFLog.FindMessageOffset("GRAW", "lli")]); + weekms = double.Parse(items[dflog.FindMessageOffset("GRAW", "WkMS")]); + week = int.Parse(items[dflog.FindMessageOffset("GRAW", "Week")]); + NSats = double.Parse(items[dflog.FindMessageOffset("GRAW", "numSV")]); + sv = double.Parse(items[dflog.FindMessageOffset("GRAW", "sv")]); + cpMes = double.Parse(items[dflog.FindMessageOffset("GRAW", "cpMes")]); + prMes = double.Parse(items[dflog.FindMessageOffset("GRAW", "prMes")]); + doMes = double.Parse(items[dflog.FindMessageOffset("GRAW", "doMes")]); + mesQI = double.Parse(items[dflog.FindMessageOffset("GRAW", "mesQI")]); + cno = double.Parse(items[dflog.FindMessageOffset("GRAW", "cno")]); + lli = double.Parse(items[dflog.FindMessageOffset("GRAW", "lli")]); if (sv > 32) gnss = 1; } else if (items[0].StartsWith("GRXH")) { - weekms = double.Parse(items[DFLog.FindMessageOffset("GRXH", "rcvTime")]) * 1000.0; - week = int.Parse(items[DFLog.FindMessageOffset("GRXH", "week")]); - NSats = double.Parse(items[DFLog.FindMessageOffset("GRXH", "numMeas")]); + weekms = double.Parse(items[dflog.FindMessageOffset("GRXH", "rcvTime")]) * 1000.0; + week = int.Parse(items[dflog.FindMessageOffset("GRXH", "week")]); + NSats = double.Parse(items[dflog.FindMessageOffset("GRXH", "numMeas")]); continue; } else if (items[0].StartsWith("GRXS")) { - sv = double.Parse(items[DFLog.FindMessageOffset("GRXS", "sv")]); - cpMes = double.Parse(items[DFLog.FindMessageOffset("GRXS", "cpMes")]); - prMes = double.Parse(items[DFLog.FindMessageOffset("GRXS", "prMes")]); - doMes = double.Parse(items[DFLog.FindMessageOffset("GRXS", "doMes")]); - gnss = int.Parse(items[DFLog.FindMessageOffset("GRXS", "gnss")]); - cno = double.Parse(items[DFLog.FindMessageOffset("GRXS", "cno")]); - double locktime = double.Parse(items[DFLog.FindMessageOffset("GRXS", "lock")]); + sv = double.Parse(items[dflog.FindMessageOffset("GRXS", "sv")]); + cpMes = double.Parse(items[dflog.FindMessageOffset("GRXS", "cpMes")]); + prMes = double.Parse(items[dflog.FindMessageOffset("GRXS", "prMes")]); + doMes = double.Parse(items[dflog.FindMessageOffset("GRXS", "doMes")]); + gnss = int.Parse(items[dflog.FindMessageOffset("GRXS", "gnss")]); + cno = double.Parse(items[dflog.FindMessageOffset("GRXS", "cno")]); + double locktime = double.Parse(items[dflog.FindMessageOffset("GRXS", "lock")]); lli = 0; // OK or not known } diff --git a/MagCalib.cs b/MagCalib.cs index e8ddf6bd69..ca02b4a656 100644 --- a/MagCalib.cs +++ b/MagCalib.cs @@ -586,19 +586,21 @@ public static double[] getOffsetsLog(string fn) List> data2 = new List>(); - var logfile = Log.DFLog.ReadLog(fn); + 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 = Log.DFLog.FindMessageOffset(line.msgtype, "MagX"); - int indexmagy = Log.DFLog.FindMessageOffset(line.msgtype, "MagY"); - int indexmagz = Log.DFLog.FindMessageOffset(line.msgtype, "MagZ"); + int indexmagx = dflog.FindMessageOffset(line.msgtype, "MagX"); + int indexmagy = dflog.FindMessageOffset(line.msgtype, "MagY"); + int indexmagz = dflog.FindMessageOffset(line.msgtype, "MagZ"); - int indexoffsetx = Log.DFLog.FindMessageOffset(line.msgtype, "OfsX"); - int indexoffsety = Log.DFLog.FindMessageOffset(line.msgtype, "OfsY"); - int indexoffsetz = Log.DFLog.FindMessageOffset(line.msgtype, "OfsZ"); + 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) { diff --git a/Utilities/fftui.cs b/Utilities/fftui.cs index e58c0f1136..ea54cb122a 100644 --- a/Utilities/fftui.cs +++ b/Utilities/fftui.cs @@ -164,18 +164,20 @@ private void myButton1_Click(object sender, EventArgs e) double lasttime = 0; double timedelta = 0; double[] freqt = null; - double samplerate = 0; + double samplerate = 0; + + Log.DFLog dflog = new Log.DFLog(); while (!file.EndOfStream) - { - var item = Log.DFLog.GetDFItemFromLine(file.ReadLine(), 0); + { + var item = dflog.GetDFItemFromLine(file.ReadLine(), 0); if (item.msgtype == "ACC1") - { - int offsetAX = Log.DFLog.FindMessageOffset("ACC1", "AccX"); - int offsetAY = Log.DFLog.FindMessageOffset("ACC1", "AccY"); - int offsetAZ = Log.DFLog.FindMessageOffset("ACC1", "AccZ"); - int offsetTime = Log.DFLog.FindMessageOffset("ACC1", "TimeUS"); + { + int offsetAX = dflog.FindMessageOffset("ACC1", "AccX"); + int offsetAY = dflog.FindMessageOffset("ACC1", "AccY"); + int offsetAZ = dflog.FindMessageOffset("ACC1", "AccZ"); + int offsetTime = dflog.FindMessageOffset("ACC1", "TimeUS"); double time = double.Parse(item.items[offsetTime]) / 1000.0; @@ -194,11 +196,11 @@ private void myButton1_Click(object sender, EventArgs e) lasttime = time; } else if (item.msgtype == "GYR1") - { - int offsetGX = Log.DFLog.FindMessageOffset("GYR1", "GyrX"); - int offsetGY = Log.DFLog.FindMessageOffset("GYR1", "GyrY"); - int offsetGZ = Log.DFLog.FindMessageOffset("GYR1", "GyrZ"); - int offsetTime = Log.DFLog.FindMessageOffset("ACC1", "TimeUS"); + { + int offsetGX = dflog.FindMessageOffset("GYR1", "GyrX"); + int offsetGY = dflog.FindMessageOffset("GYR1", "GyrY"); + int offsetGZ = dflog.FindMessageOffset("GYR1", "GyrZ"); + int offsetTime = dflog.FindMessageOffset("ACC1", "TimeUS"); double time = double.Parse(item.items[offsetTime]) / 1000.0; @@ -321,11 +323,13 @@ private void BUT_log2_Click(object sender, EventArgs e) // 3 imus * 2 sets of measurements(gyr/acc) datastate[] alldata = new datastate[3 * 2]; for (int a = 0; a < alldata.Length; a++) - alldata[a] = new datastate(); + alldata[a] = new datastate(); + + Log.DFLog dflog = new Log.DFLog(); while (!file.EndOfStream) - { - var item = Log.DFLog.GetDFItemFromLine(file.ReadLine(), 0); + { + var item = dflog.GetDFItemFromLine(file.ReadLine(), 0); if (item.msgtype == null) { @@ -335,12 +339,12 @@ private void BUT_log2_Click(object sender, EventArgs e) if (item.msgtype.StartsWith("ACC")) { int sensorno = int.Parse(item.msgtype.Substring(3)) - 1 + 3; - alldata[sensorno].type = item.msgtype; - - int offsetAX = Log.DFLog.FindMessageOffset(item.msgtype, "AccX"); - int offsetAY = Log.DFLog.FindMessageOffset(item.msgtype, "AccY"); - int offsetAZ = Log.DFLog.FindMessageOffset(item.msgtype, "AccZ"); - int offsetTime = Log.DFLog.FindMessageOffset(item.msgtype, "TimeUS"); + alldata[sensorno].type = item.msgtype; + + int offsetAX = dflog.FindMessageOffset(item.msgtype, "AccX"); + int offsetAY = dflog.FindMessageOffset(item.msgtype, "AccY"); + int offsetAZ = dflog.FindMessageOffset(item.msgtype, "AccZ"); + int offsetTime = dflog.FindMessageOffset(item.msgtype, "TimeUS"); double time = double.Parse(item.items[offsetTime]) / 1000.0; @@ -356,12 +360,12 @@ private void BUT_log2_Click(object sender, EventArgs e) else if (item.msgtype.StartsWith("GYR")) { int sensorno = int.Parse(item.msgtype.Substring(3)) - 1; - alldata[sensorno].type = item.msgtype; - - int offsetGX = Log.DFLog.FindMessageOffset(item.msgtype, "GyrX"); - int offsetGY = Log.DFLog.FindMessageOffset(item.msgtype, "GyrY"); - int offsetGZ = Log.DFLog.FindMessageOffset(item.msgtype, "GyrZ"); - int offsetTime = Log.DFLog.FindMessageOffset(item.msgtype, "TimeUS"); + alldata[sensorno].type = item.msgtype; + + int offsetGX = dflog.FindMessageOffset(item.msgtype, "GyrX"); + int offsetGY = dflog.FindMessageOffset(item.msgtype, "GyrY"); + int offsetGZ = dflog.FindMessageOffset(item.msgtype, "GyrZ"); + int offsetTime = dflog.FindMessageOffset(item.msgtype, "TimeUS"); double time = double.Parse(item.items[offsetTime]) / 1000.0;