public static void MapLogs(string[] logs) { foreach (var logfile in logs) { if (File.Exists(logfile + ".jpg")) { continue; } double minx = 99999; double maxx = -99999; double miny = 99999; double maxy = -99999; List <PointLatLngAlt> locs = new List <PointLatLngAlt>(); try { if (logfile.ToLower().EndsWith(".tlog")) { MAVLinkInterface mine = new MAVLinkInterface(); using (mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read))) { mine.logreadmode = true; CurrentState cs = new CurrentState(); while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length) { byte[] packet = mine.readPacket(); if (packet.Length < 5) { continue; } try { if (MainV2.speechEngine != null) { MainV2.speechEngine.SpeakAsyncCancelAll(); } } catch { } if (packet[5] == (byte)MAVLink.MAVLINK_MSG_ID.GLOBAL_POSITION_INT) { var loc = packet.ByteArrayToStructure <MAVLink.mavlink_global_position_int_t>(6); if (loc.lat == 0 || loc.lon == 0) { continue; } locs.Add(new PointLatLngAlt(loc.lat / 10000000.0f, loc.lon / 10000000.0f)); minx = Math.Min(minx, loc.lon / 10000000.0f); maxx = Math.Max(maxx, loc.lon / 10000000.0f); miny = Math.Min(miny, loc.lat / 10000000.0f); maxy = Math.Max(maxy, loc.lat / 10000000.0f); } } } } else if (logfile.ToLower().EndsWith(".bin") || logfile.ToLower().EndsWith(".log")) { bool bin = logfile.ToLower().EndsWith(".bin"); using (var st = File.OpenRead(logfile)) { using (StreamReader sr = new StreamReader(st)) { while (sr.BaseStream.Position < sr.BaseStream.Length) { string line = ""; if (bin) { line = BinaryLog.ReadMessage(sr.BaseStream); } else { line = sr.ReadLine(); } if (line.StartsWith("FMT")) { 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")]); if (lat == 0 || lon == 0) { continue; } locs.Add(new PointLatLngAlt(lat, lon)); minx = Math.Min(minx, lon); maxx = Math.Max(maxx, lon); miny = Math.Min(miny, lat); maxy = Math.Max(maxy, lat); } } } } } if (locs.Count > 10) { // add a bit of buffer var area = RectLatLng.FromLTRB(minx - 0.001, maxy + 0.001, maxx + 0.001, miny - 0.001); var map = GetMap(area); var grap = Graphics.FromImage(map); PointF lastpoint = new PointF(); foreach (var loc in locs) { PointF newpoint = GetPixel(area, loc, map.Size); if (!lastpoint.IsEmpty) { grap.DrawLine(Pens.Red, lastpoint, newpoint); } lastpoint = newpoint; } map.Save(logfile + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); map.Dispose(); map = null; } else { DoTextMap(logfile + ".jpg", "No gps data"); } } catch (Exception ex) { if (ex.ToString().Contains("Mavlink 0.9")) { DoTextMap(logfile + ".jpg", "Old log\nMavlink 0.9"); } continue; } } }
public void processLine(string line) { try { if (line.Length == 0) { return; } string[] items = line.Split(',', ':'); if (items[0].Contains("FMT")) { try { dflog.FMTLine(line); } catch { } } if (items[0].Contains("PARM")) { try { int nameindex = dflog.FindMessageOffset("PARM", "Name"); int valueindex = dflog.FindMessageOffset("PARM", "Value"); paramlist[items[nameindex].Trim()] = items[valueindex].Trim(); } catch { } } else if (items[0].Contains("CMD")) // "CMD", "QHHHfffffff","TimeUS,CTot,CNum,CId,Prm1,Prm2,Prm3,Prm4,Lat,Lng,Alt" }, \ { cmdraw.Add(line); int cidindex = dflog.FindMessageOffset("CMD", "CId"); if (int.Parse(items[cidindex]) <= (int)MAVLink.MAV_CMD.LAST) // wps { int cmdflatindex = dflog.FindMessageOffset("CMD", "Lat"); int cmdlngindex = dflog.FindMessageOffset("CMD", "Lng"); int cmdaltindex = dflog.FindMessageOffset("CMD", "Alt"); int cmdnumindex = dflog.FindMessageOffset("CMD", "CNum"); cmd.Add(new PointLatLngAlt( double.Parse(items[cmdflatindex], CultureInfo.InvariantCulture), double.Parse(items[cmdlngindex], CultureInfo.InvariantCulture), double.Parse(items[cmdaltindex], CultureInfo.InvariantCulture), items[cmdnumindex])); } } else if (items[0].Contains("MOD")) { positionindex++; while (modelist.Count < positionindex + 1) { modelist.Add(""); } int nameindex = dflog.FindMessageOffset("MODE", "Mode"); if (nameindex > 0) { modelist[positionindex] = items[nameindex]; } else { if (items.Length == 4) { modelist[positionindex] = (items[2]); } else { modelist[positionindex] = (items[1]); } } } 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) { return; } if (position[positionindex] == null) { position[positionindex] = new List <Point3D>(); } double alt = double.Parse(items[dflog.FindMessageOffset("GPS", "Alt")], CultureInfo.InvariantCulture); if (alt > 40000) { return; } double lng = double.Parse(items[dflog.FindMessageOffset("GPS", "Lng")], CultureInfo.InvariantCulture); double lat = double.Parse(items[dflog.FindMessageOffset("GPS", "Lat")], CultureInfo.InvariantCulture); if (lat < -90 || lat > 90) { return; } if (lng < -180 || lng > 180) { return; } position[positionindex].Add(new Point3D(lng, lat, alt)); oldlastpos = lastpos; lastpos = (position[positionindex][position[positionindex].Count - 1]); lastline = line; } else if (items[0].Contains("POS")) { if (dflog.logformat.ContainsKey("POS")) { 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))); } } else if (items[0].Contains("GRAW")) { gpsrawdata.Add(line); } else if (items[0].Contains("GRXH")) { gpsrawdata.Add(line); } else if (items[0].Contains("GRXS")) { gpsrawdata.Add(line); } else if (items[0].Contains("CTUN")) { ctunlast = items; } else if (items[0].Contains("NTUN")) { ntunlast = items; try { // line = "ATT:" + double.Parse(ctunlast[3], new System.Globalization.CultureInfo("en-US")) * 100 + "," + double.Parse(ctunlast[6], new System.Globalization.CultureInfo("en-US")) * 100 + "," + double.Parse(items[1], new System.Globalization.CultureInfo("en-US")) * 100; // items = line.Split(',', ':'); } catch { } } else if (items[0].Contains("ATT")) { try { if (lastpos.X != 0 && oldlastpos.X != lastpos.X && oldlastpos.Y != lastpos.Y) { Data dat = new Data(); try { dat.datetime = dflog.GetTimeGPS(lastline); } catch { } runmodel = new Model(); runmodel.Location.longitude = lastpos.X; runmodel.Location.latitude = lastpos.Y; runmodel.Location.altitude = lastpos.Z; oldlastpos = lastpos; runmodel.Orientation.roll = double.Parse(items[dflog.FindMessageOffset("ATT", "Roll")], CultureInfo.InvariantCulture) / -1; runmodel.Orientation.tilt = double.Parse(items[dflog.FindMessageOffset("ATT", "Pitch")], CultureInfo.InvariantCulture) / -1; runmodel.Orientation.heading = double.Parse(items[dflog.FindMessageOffset("ATT", "Yaw")], CultureInfo.InvariantCulture) / 1; dat.model = runmodel; dat.ctun = ctunlast; dat.ntun = ntunlast; flightdata.Add(dat); } } catch (Exception ex) { log.Error(ex); } } } catch (Exception) { // if items is to short or parse fails.. ignore } }
public static void MapLogs(string[] logs) { foreach (var logfile in logs) { if (File.Exists(logfile + ".jpg")) continue; double minx = 99999; double maxx = -99999; double miny = 99999; double maxy = -99999; List<PointLatLngAlt> locs = new List<PointLatLngAlt>(); try { if (logfile.ToLower().EndsWith(".tlog")) { using (MAVLinkInterface mine = new MAVLinkInterface()) using (mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { mine.logreadmode = true; CurrentState cs = new CurrentState(); while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length) { byte[] packet = mine.readPacket(); if (packet.Length < 5) continue; try { if (MainV2.speechEngine != null) MainV2.speechEngine.SpeakAsyncCancelAll(); } catch { } if (packet[5] == (byte)MAVLink.MAVLINK_MSG_ID.GLOBAL_POSITION_INT) { var loc = packet.ByteArrayToStructure<MAVLink.mavlink_global_position_int_t>(6); if (loc.lat == 0 || loc.lon == 0) continue; locs.Add(new PointLatLngAlt(loc.lat / 10000000.0f, loc.lon / 10000000.0f)); minx = Math.Min(minx, loc.lon / 10000000.0f); maxx = Math.Max(maxx, loc.lon / 10000000.0f); miny = Math.Min(miny, loc.lat / 10000000.0f); maxy = Math.Max(maxy, loc.lat / 10000000.0f); } } } } else if (logfile.ToLower().EndsWith(".bin") || logfile.ToLower().EndsWith(".log")) { bool bin = logfile.ToLower().EndsWith(".bin"); BinaryLog binlog = new BinaryLog(); DFLog dflog = new DFLog(); using (var st = File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (StreamReader sr = new StreamReader(st)) { while (sr.BaseStream.Position < sr.BaseStream.Length) { string line = ""; if (bin) { line = binlog.ReadMessage(sr.BaseStream); } else { line = sr.ReadLine(); } if (line.StartsWith("FMT")) { 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")]); if (lat == 0 || lon == 0) continue; locs.Add(new PointLatLngAlt(lat, lon)); minx = Math.Min(minx, lon); maxx = Math.Max(maxx, lon); miny = Math.Min(miny, lat); maxy = Math.Max(maxy, lat); } } } } } if (locs.Count > 10) { // add a bit of buffer var area = RectLatLng.FromLTRB(minx - 0.001, maxy + 0.001, maxx + 0.001, miny - 0.001); var map = GetMap(area); var grap = Graphics.FromImage(map); PointF lastpoint = new PointF(); foreach (var loc in locs) { PointF newpoint = GetPixel(area, loc, map.Size); if (!lastpoint.IsEmpty) grap.DrawLine(Pens.Red, lastpoint, newpoint); lastpoint = newpoint; } map.Save(logfile + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); map.Dispose(); map = null; } else { DoTextMap(logfile + ".jpg", "No gps data"); } } catch (Exception ex) { if (ex.ToString().Contains("Mavlink 0.9")) DoTextMap(logfile + ".jpg", "Old log\nMavlink 0.9"); continue; } } }
public void processLine(string line) { try { if (doevent.Second != DateTime.Now.Second) { Application.DoEvents(); doevent = DateTime.Now; } if (line.Length == 0) { return; } DateTime start = DateTime.Now; if (line.ToLower().Contains("ArduCopter")) { MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduCopter2; } if (line.ToLower().Contains("ArduPlane")) { MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduPlane; } if (line.ToLower().Contains("ArduRover")) { MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduRover; } line = line.Replace(", ", ","); line = line.Replace(": ", ":"); string[] items = line.Split(',', ':'); if (items[0].Contains("FMT")) { try { DFLog.FMTLine(line); } catch { } } else if (items[0].Contains("CMD")) { if (flightdata.Count == 0) { if (int.Parse(items[3]) <= (int)MAVLink.MAV_CMD.LAST) // wps { PointLatLngAlt temp = new PointLatLngAlt(double.Parse(items[7], new System.Globalization.CultureInfo("en-US")), double.Parse(items[8], new System.Globalization.CultureInfo("en-US")), double.Parse(items[6], new System.Globalization.CultureInfo("en-US")), items[2].ToString()); cmd.Add(temp); } } } else if (items[0].Contains("MOD")) { positionindex++; while (modelist.Count < positionindex + 1) { modelist.Add(""); } if (items.Length == 4) { modelist[positionindex] = (items[2]); } else { modelist[positionindex] = (items[1]); } } else if (items[0].Contains("GPS") && DFLog.logformat.ContainsKey("GPS")) { if (items[0].Contains("GPS2")) { return; } if (items[DFLog.FindMessageOffset("GPS", "Status")] != "3") { return; } if (position[positionindex] == null) { position[positionindex] = new List <Point3D>(); } // if (double.Parse(items[4], new System.Globalization.CultureInfo("en-US")) == 0) // return; // 7 agl // 8 asl... 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")], new System.Globalization.CultureInfo("en-US")), double.Parse(items[DFLog.FindMessageOffset("GPS", "Lat")], new System.Globalization.CultureInfo("en-US")), alt)); oldlastpos = lastpos; lastpos = (position[positionindex][position[positionindex].Count - 1]); lastline = line; } else if (items[0].Contains("GPS") && items[2] == "1" && items[4] != "0" && items[4] != "-1" && lastline != line) // check gps line and fixed status { MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduPlane; if (position[positionindex] == null) { position[positionindex] = new List <Point3D>(); } if (double.Parse(items[4], new System.Globalization.CultureInfo("en-US")) == 0) { return; } double alt = double.Parse(items[6], new System.Globalization.CultureInfo("en-US")); if (items.Length == 11 && items[6] == "0.0000") { alt = double.Parse(items[7], new System.Globalization.CultureInfo("en-US")); } if (items.Length == 11 && items[6] == "0") { alt = double.Parse(items[7], new System.Globalization.CultureInfo("en-US")); } position[positionindex].Add(new Point3D(double.Parse(items[5], new System.Globalization.CultureInfo("en-US")), double.Parse(items[4], new System.Globalization.CultureInfo("en-US")), alt)); oldlastpos = lastpos; lastpos = (position[positionindex][position[positionindex].Count - 1]); lastline = line; } else if (items[0].Contains("GPS") && items[4] != "0" && items[4] != "-1" && items.Length <= 9) // AC { MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduCopter2; if (position[positionindex] == null) { position[positionindex] = new List <Point3D>(); } if (double.Parse(items[4], new System.Globalization.CultureInfo("en-US")) == 0) { return; } double alt = double.Parse(items[5], new System.Globalization.CultureInfo("en-US")); position[positionindex].Add(new Point3D(double.Parse(items[4], new System.Globalization.CultureInfo("en-US")), double.Parse(items[3], new System.Globalization.CultureInfo("en-US")), alt)); oldlastpos = lastpos; lastpos = (position[positionindex][position[positionindex].Count - 1]); lastline = line; } else if ((items[0].Contains("GPS") && items[1] == "3" && items[6] != "0" && items[6] != "-1" && lastline != line && items.Length == 12) || (items[0].Contains("GPS") && items[1] == "3" && items[6] != "0" && items[6] != "-1" && lastline != line && items.Length == 14)) { if (position[positionindex] == null) { position[positionindex] = new List <Point3D>(); } // if (double.Parse(items[4], new System.Globalization.CultureInfo("en-US")) == 0) // return; // 8 agl // 9 asl... double alt = double.Parse(items[9], new System.Globalization.CultureInfo("en-US")); position[positionindex].Add(new Point3D(double.Parse(items[7], new System.Globalization.CultureInfo("en-US")), double.Parse(items[6], new System.Globalization.CultureInfo("en-US")), alt)); oldlastpos = lastpos; lastpos = (position[positionindex][position[positionindex].Count - 1]); lastline = line; } else if (items[0].Contains("GPS") && items[1] == "3" && items[4] != "0" && items[4] != "-1" && lastline != line && items.Length == 11) // check gps line and fixed status { if (position[positionindex] == null) { position[positionindex] = new List <Point3D>(); } // if (double.Parse(items[4], new System.Globalization.CultureInfo("en-US")) == 0) // return; // 7 agl // 8 asl... double alt = double.Parse(items[8], new System.Globalization.CultureInfo("en-US")); position[positionindex].Add(new Point3D(double.Parse(items[6], new System.Globalization.CultureInfo("en-US")), double.Parse(items[5], new System.Globalization.CultureInfo("en-US")), alt)); oldlastpos = lastpos; lastpos = (position[positionindex][position[positionindex].Count - 1]); lastline = line; } else if (items[0].Contains("GRAW")) { gpsrawdata.Add(line); } else if (items[0].Contains("CTUN")) { ctunlast = items; } else if (items[0].Contains("NTUN")) { ntunlast = items; try { // line = "ATT:" + double.Parse(ctunlast[3], new System.Globalization.CultureInfo("en-US")) * 100 + "," + double.Parse(ctunlast[6], new System.Globalization.CultureInfo("en-US")) * 100 + "," + double.Parse(items[1], new System.Globalization.CultureInfo("en-US")) * 100; // items = line.Split(',', ':'); } catch { } } else if (items[0].Contains("ATT")) { try { if (lastpos.X != 0 && oldlastpos.X != lastpos.X && oldlastpos.Y != lastpos.Y) { Data dat = new Data(); try { dat.datetime = DFLog.GetTimeGPS(lastline); } catch { } runmodel = new Model(); runmodel.Location.longitude = lastpos.X; runmodel.Location.latitude = lastpos.Y; runmodel.Location.altitude = lastpos.Z; oldlastpos = lastpos; runmodel.Orientation.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")], new System.Globalization.CultureInfo("en-US")) / -1; runmodel.Orientation.heading = double.Parse(items[DFLog.FindMessageOffset("ATT", "Yaw")], new System.Globalization.CultureInfo("en-US")) / 1; dat.model = runmodel; dat.ctun = ctunlast; dat.ntun = ntunlast; flightdata.Add(dat); } } catch (Exception ex) { log.Error(ex); } } if ((DateTime.Now - start).TotalMilliseconds > 5) { Console.WriteLine(line); } } catch (Exception) { // if items is to short or parse fails.. ignore } }
public static void MapLogs(string[] logs) { foreach (var logfile in logs) { if (File.Exists(logfile + ".jpg")) { continue; } double minx = 99999; double maxx = -99999; double miny = 99999; double maxy = -99999; Dictionary <int, List <PointLatLngAlt> > loc_list = new Dictionary <int, List <PointLatLngAlt> >(); try { if (logfile.ToLower().EndsWith(".tlog")) { using (MAVLinkInterface mine = new MAVLinkInterface()) using ( mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) ) { mine.logreadmode = true; while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length) { MAVLink.MAVLinkMessage packet = mine.readPacket(); if (packet.Length < 5) { continue; } try { if (MainV2.speechEngine != null) { MainV2.speechEngine.SpeakAsyncCancelAll(); } } catch { } if (packet.msgid == (byte)MAVLink.MAVLINK_MSG_ID.GLOBAL_POSITION_INT) { var loc = packet.ToStructure <MAVLink.mavlink_global_position_int_t>(); if (loc.lat == 0 || loc.lon == 0) { continue; } var id = MAVList.GetID(packet.sysid, packet.compid); if (!loc_list.ContainsKey(id)) { loc_list[id] = new List <PointLatLngAlt>(); } loc_list[id].Add(new PointLatLngAlt(loc.lat / 10000000.0f, loc.lon / 10000000.0f)); minx = Math.Min(minx, loc.lon / 10000000.0f); maxx = Math.Max(maxx, loc.lon / 10000000.0f); miny = Math.Min(miny, loc.lat / 10000000.0f); maxy = Math.Max(maxy, loc.lat / 10000000.0f); } } } } else if (logfile.ToLower().EndsWith(".bin") || logfile.ToLower().EndsWith(".log")) { bool bin = logfile.ToLower().EndsWith(".bin"); BinaryLog binlog = new BinaryLog(); DFLog dflog = new DFLog(); using (var st = File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (StreamReader sr = new StreamReader(st)) { loc_list[0] = new List <PointLatLngAlt>(); while (sr.BaseStream.Position < sr.BaseStream.Length) { string line = ""; if (bin) { line = binlog.ReadMessage(sr.BaseStream); } else { line = sr.ReadLine(); } if (line.StartsWith("FMT")) { 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")]); if (lat == 0 || lon == 0) { continue; } loc_list[0].Add(new PointLatLngAlt(lat, lon)); minx = Math.Min(minx, lon); maxx = Math.Max(maxx, lon); miny = Math.Min(miny, lat); maxy = Math.Max(maxy, lat); } } } } } if (loc_list.First().Value.Count > 10) { // add a bit of buffer var area = RectLatLng.FromLTRB(minx - 0.001, maxy + 0.001, maxx + 0.001, miny - 0.001); var map = GetMap(area); var grap = Graphics.FromImage(map); Color[] colours = { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet, Color.Pink }; int a = 0; foreach (var locs in loc_list.Values) { PointF lastpoint = new PointF(); var pen = new Pen(colours[a % (colours.Length - 1)]); foreach (var loc in locs) { PointF newpoint = GetPixel(area, loc, map.Size); if (!lastpoint.IsEmpty) { grap.DrawLine(pen, lastpoint, newpoint); } lastpoint = newpoint; } a++; } map.Save(logfile + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); map.Dispose(); map = null; } else { DoTextMap(logfile + ".jpg", "No gps data"); } } catch (Exception ex) { if (ex.ToString().Contains("Mavlink 0.9")) { DoTextMap(logfile + ".jpg", "Old log\nMavlink 0.9"); } continue; } } }
public static void MapLogs(string[] logs) { foreach (var logfile in logs) { if (File.Exists(logfile + ".jpg")) continue; double minx = 99999; double maxx = -99999; double miny = 99999; double maxy = -99999; bool sitl = false; Dictionary<int,List<PointLatLngAlt>> loc_list = new Dictionary<int, List<PointLatLngAlt>>(); try { if (logfile.ToLower().EndsWith(".tlog")) { using (MAVLinkInterface mine = new MAVLinkInterface()) using ( mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) ) { mine.logreadmode = true; mine.speechenabled = false; while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length) { MAVLink.MAVLinkMessage packet = mine.readPacket(); if (packet.Length < 5) continue; if (packet.msgid == (byte)MAVLink.MAVLINK_MSG_ID.SIM_STATE || packet.msgid == (byte)MAVLink.MAVLINK_MSG_ID.SIMSTATE) { sitl = true; } if (packet.msgid == (byte) MAVLink.MAVLINK_MSG_ID.GLOBAL_POSITION_INT) { var loc = packet.ToStructure<MAVLink.mavlink_global_position_int_t>(); if (loc.lat == 0 || loc.lon == 0) continue; var id = MAVList.GetID(packet.sysid, packet.compid); if (!loc_list.ContainsKey(id)) loc_list[id] = new List<PointLatLngAlt>(); loc_list[id].Add(new PointLatLngAlt(loc.lat/10000000.0f, loc.lon/10000000.0f)); minx = Math.Min(minx, loc.lon/10000000.0f); maxx = Math.Max(maxx, loc.lon/10000000.0f); miny = Math.Min(miny, loc.lat/10000000.0f); maxy = Math.Max(maxy, loc.lat/10000000.0f); } } } } else if (logfile.ToLower().EndsWith(".bin") || logfile.ToLower().EndsWith(".log")) { bool bin = logfile.ToLower().EndsWith(".bin"); BinaryLog binlog = new BinaryLog(); DFLog dflog = new DFLog(); using (var st = File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (StreamReader sr = new StreamReader(st)) { loc_list[0] = new List<PointLatLngAlt>(); while (sr.BaseStream.Position < sr.BaseStream.Length) { string line = ""; if (bin) { line = binlog.ReadMessage(sr.BaseStream); } else { line = sr.ReadLine(); } if (line.StartsWith("FMT")) { dflog.FMTLine(line); } else if (line.StartsWith("GPS")) { var item = dflog.GetDFItemFromLine(line, 0); if (!dflog.logformat.ContainsKey("GPS")) continue; var status = double.Parse(item.items[dflog.FindMessageOffset(item.msgtype, "Status")]); 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 || status < 3) continue; loc_list[0].Add(new PointLatLngAlt(lat, lon)); minx = Math.Min(minx, lon); maxx = Math.Max(maxx, lon); miny = Math.Min(miny, lat); maxy = Math.Max(maxy, lat); } } } } } if (loc_list.Count > 0 && loc_list.First().Value.Count > 10) { // add a bit of buffer var area = RectLatLng.FromLTRB(minx - 0.001, maxy + 0.001, maxx + 0.001, miny - 0.001); var map = GetMap(area); var grap = Graphics.FromImage(map); if (sitl) { AddTextToMap(grap, "SITL"); } Color[] colours = { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet, Color.Pink }; int a = 0; foreach (var locs in loc_list.Values) { PointF lastpoint = new PointF(); var pen = new Pen(colours[a%(colours.Length - 1)]); foreach (var loc in locs) { PointF newpoint = GetPixel(area, loc, map.Size); if (!lastpoint.IsEmpty) grap.DrawLine(pen, lastpoint, newpoint); lastpoint = newpoint; } a++; } map.Save(logfile + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); map.Dispose(); map = null; } else { DoTextMap(logfile + ".jpg", "No gps data"); } } catch (Exception ex) { if (ex.ToString().Contains("Mavlink 0.9")) DoTextMap(logfile + ".jpg", "Old log\nMavlink 0.9"); continue; } } }
private void PopulateDataTableFromUploadedFile(System.IO.Stream strm) { System.IO.StreamReader srdr = new System.IO.StreamReader(strm); String strLine = String.Empty; Int32 iLineCount = 0; DFLog.Clear(); do { strLine = srdr.ReadLine(); if (strLine == null) { break; } else if (strLine == "") { // continue; } if (0 == iLineCount++) { m_dtCSV = new DataTable("CSVTable"); } this.AddDataRowToTable(strLine, m_dtCSV); strLine = strLine.Replace(", ", ","); strLine = strLine.Replace(": ", ":"); string[] items = strLine.Split(',', ':'); // populate fw type if (items[0].Contains("SYSID_SW_TYPE")) { switch (items[1].ToString()) { case "10": MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduCopter2; break; case "7": MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.Ateryx; break; case "20": MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduRover; break; case "0": MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduPlane; break; } } if (items[0].Contains("FMT")) { try { DFLog.FMTLine(strLine); } catch { } } } while (true); }