Exemplo n.º 1
1
        public static void SortLogs(string[] logs)
        {
            foreach (var logfile in logs)
            {
                FileInfo info = new FileInfo(logfile);

                if (info.Length <= 1024)
                {
                    try
                    {
                        string destdir = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar
                 + "SMALL" + Path.DirectorySeparatorChar;

                        if (!Directory.Exists(destdir))
                            Directory.CreateDirectory(destdir);

                        File.Move(logfile, destdir + Path.GetFileName(logfile));
                        File.Move(logfile.Replace(".tlog", ".rlog"), destdir + Path.GetFileName(logfile).Replace(".tlog", ".rlog"));
                    }
                    catch { }
                    continue;
                }

                MAVLinkInterface mine = new MAVLinkInterface();

                try
                {
                    using (mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read)))
                    {
                        mine.logreadmode = true;

                        byte[] hbpacket = mine.getHeartBeat();

                        if (hbpacket.Length == 0)
                            continue;

                        MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket);

                        mine.logreadmode = false;
                        mine.logplaybackfile.Close();

                        string destdir = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar
                            + mine.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                            + hbpacket[3] + Path.DirectorySeparatorChar;

                        if (!Directory.Exists(destdir))
                            Directory.CreateDirectory(destdir);

                        File.Move(logfile, destdir + Path.GetFileName(logfile));

                        try
                        {
                            File.Move(logfile.Replace(".tlog", ".rlog"), destdir + Path.GetFileName(logfile).Replace(".tlog", ".rlog"));
                        }
                        catch { }
                    }
                }
                catch { continue; }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes a tlog to get the offsets - creates dxf of data
        /// </summary>
        /// <param name="fn">Filename</param>
        /// <returns>Offsets</returns>
        public static double[] getOffsets(string fn, int throttleThreshold = 0)
        {
            // based off tridge's work
            string logfile = fn;

            // old method
            float minx = 0;
            float maxx = 0;
            float miny = 0;
            float maxy = 0;
            float minz = 0;
            float maxz = 0;

            // this is for a dxf
            Polyline3dVertex        vertex;
            List <Polyline3dVertex> vertexes = new List <Polyline3dVertex>();

            // data storage
            Tuple <float, float, float>         offset = new Tuple <float, float, float>(0, 0, 0);
            List <Tuple <float, float, float> > data   = new List <Tuple <float, float, float> >();

            Hashtable filter = new Hashtable();

            // track data to use
            bool useData = false;

            if (throttleThreshold <= 0)
            {
                useData = true;
            }

            log.Info("Start log: " + DateTime.Now);

            MAVLinkInterface mine = new MAVLinkInterface();

            try
            {
                mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read));
            }
            catch (Exception ex) { log.Debug(ex.ToString()); CustomMessageBox.Show("Log Can not be opened. Are you still connected?"); return(new double[] { 0 }); }

            mine.logreadmode = true;

            mine.MAV.packets.Initialize(); // clear

            // gather data
            while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length)
            {
                byte[] packetraw = mine.readPacket();

                var packet = mine.DebugPacket(packetraw, false);

                // this is for packets we dont know about
                if (packet == null)
                {
                    continue;
                }

                if (packet.GetType() == typeof(MAVLink.mavlink_vfr_hud_t))
                {
                    if (((MAVLink.mavlink_vfr_hud_t)packet).throttle >= throttleThreshold)
                    {
                        useData = true;
                    }
                    else
                    {
                        useData = false;
                    }
                }

                if (packet.GetType() == typeof(MAVLink.mavlink_sensor_offsets_t))
                {
                    offset = new Tuple <float, float, float>(
                        ((MAVLink.mavlink_sensor_offsets_t)packet).mag_ofs_x,
                        ((MAVLink.mavlink_sensor_offsets_t)packet).mag_ofs_y,
                        ((MAVLink.mavlink_sensor_offsets_t)packet).mag_ofs_z);
                }
                else if (packet.GetType() == typeof(MAVLink.mavlink_raw_imu_t) && useData)
                {
                    int div = 20;

                    // fox dxf
                    vertex = new Polyline3dVertex(new Vector3f(
                                                      ((MAVLink.mavlink_raw_imu_t)packet).xmag - offset.Item1,
                                                      ((MAVLink.mavlink_raw_imu_t)packet).ymag - offset.Item2,
                                                      ((MAVLink.mavlink_raw_imu_t)packet).zmag - offset.Item3)
                                                  );
                    vertexes.Add(vertex);


                    // for old method
                    setMinorMax(((MAVLink.mavlink_raw_imu_t)packet).xmag - offset.Item1, ref minx, ref maxx);
                    setMinorMax(((MAVLink.mavlink_raw_imu_t)packet).ymag - offset.Item2, ref miny, ref maxy);
                    setMinorMax(((MAVLink.mavlink_raw_imu_t)packet).zmag - offset.Item3, ref minz, ref maxz);

                    // for new lease sq
                    string item = (int)(((MAVLink.mavlink_raw_imu_t)packet).xmag / div) + "," +
                                  (int)(((MAVLink.mavlink_raw_imu_t)packet).ymag / div) + "," +
                                  (int)(((MAVLink.mavlink_raw_imu_t)packet).zmag / div);

                    if (filter.ContainsKey(item))
                    {
                        filter[item] = (int)filter[item] + 1;

                        if ((int)filter[item] > 3)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        filter[item] = 1;
                    }


                    data.Add(new Tuple <float, float, float>(
                                 ((MAVLink.mavlink_raw_imu_t)packet).xmag - offset.Item1,
                                 ((MAVLink.mavlink_raw_imu_t)packet).ymag - offset.Item2,
                                 ((MAVLink.mavlink_raw_imu_t)packet).zmag - offset.Item3));
                }
            }

            log.Info("Log Processed " + DateTime.Now);

            Console.WriteLine("Extracted " + data.Count + " data points");
            Console.WriteLine("Current offset: " + offset);

            mine.logreadmode = false;
            mine.logplaybackfile.Close();
            mine.logplaybackfile = null;

            if (data.Count < 10)
            {
                CustomMessageBox.Show("Log does not contain enough data");
                throw new Exception("Not Enough Data");
            }

            data.Sort(
                delegate(Tuple <float, float, float> d1, Tuple <float, float, float> d2)
            {
                // get distance from 0,0,0
                double ans1 = Math.Sqrt(d1.Item1 * d1.Item1 + d1.Item2 * d1.Item2 + d1.Item3 * d1.Item3);
                double ans2 = Math.Sqrt(d2.Item1 * d2.Item1 + d2.Item2 * d2.Item2 + d2.Item3 * d2.Item3);
                if (ans1 > ans2)
                {
                    return(1);
                }
                if (ans1 < ans2)
                {
                    return(-1);
                }
                return(0);
            }
                );

            data.RemoveRange(data.Count - (data.Count / 16), data.Count / 16);

            System.Console.WriteLine("Old Method {0} {1} {2}", -(maxx + minx) / 2, -(maxy + miny) / 2, -(maxz + minz) / 2);

            double[] x = LeastSq(data);

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

            doDXF(vertexes, x);

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

            return(x);
        }
Exemplo n.º 3
0
        public static void SortLogs(string[] logs)
        {
            foreach (var logfile in logs)
            {
                FileInfo info = new FileInfo(logfile);

                // delete 0 size files
                if (info.Length == 0)
                {
                    try
                    {
                        File.Delete(logfile);
                    }
                    catch { }
                    continue;
                }

                // move small logs - most likerly invalid
                if (info.Length <= 1024)
                {
                    try
                    {
                        string destdir = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar
                 + "SMALL" + Path.DirectorySeparatorChar;

                        if (!Directory.Exists(destdir))
                            Directory.CreateDirectory(destdir);

                        log.Info("Move log small " + logfile + " to " + destdir + Path.GetFileName(logfile));

                        movefileusingmask(logfile, destdir);
                    }
                    catch { }
                    continue;
                }

                MAVLinkInterface mine = new MAVLinkInterface();

                try
                {
                    using (mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read)))
                    {
                        mine.logreadmode = true;

                        byte[] hbpacket = mine.getHeartBeat();

                        if (hbpacket.Length == 0)
                        {
                            mine.logreadmode = false;
                            mine.logplaybackfile.Close();

                            if (!Directory.Exists(Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD"))
                                Directory.CreateDirectory(Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD");

                            log.Info("Move log bad " + logfile + " to " + Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD" + Path.DirectorySeparatorChar + Path.GetFileName(logfile));

                            movefileusingmask(logfile, Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD" + Path.DirectorySeparatorChar);
                            continue;
                        }

                        MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket);

                        mine.logreadmode = false;
                        mine.logplaybackfile.Close();

                        string destdir = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar
                            + mine.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                            + hbpacket[3] + Path.DirectorySeparatorChar;

                        if (!Directory.Exists(destdir))
                            Directory.CreateDirectory(destdir);

                        movefileusingmask(logfile, destdir);
                    }
                }
                catch { continue; }
            }
        }
Exemplo n.º 4
0
        public static void SortLogs(string[] logs)
        {
            foreach (var logfile in logs)
            {
                FileInfo info = new FileInfo(logfile);

                // delete 0 size files
                if (info.Length == 0)
                {
                    try
                    {
                        File.Delete(logfile);
                    }
                    catch
                    {
                    }
                    continue;
                }

                // move small logs - most likerly invalid
                if (info.Length <= 1024)
                {
                    try
                    {
                        string destdir = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar
                                         + "SMALL" + Path.DirectorySeparatorChar;

                        if (!Directory.Exists(destdir))
                            Directory.CreateDirectory(destdir);

                        log.Info("Move log small " + logfile + " to " + destdir + Path.GetFileName(logfile));

                        movefileusingmask(logfile, destdir);
                    }
                    catch
                    {
                    }
                    continue;
                }

                try
                {
                    using (MAVLinkInterface mine = new MAVLinkInterface())
                    using (
                        mine.logplaybackfile =
                            new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read)))
                    {
                        mine.logreadmode = true;

                        var midpoint = mine.logplaybackfile.BaseStream.Length / 2;

                        mine.logplaybackfile.BaseStream.Seek(midpoint, SeekOrigin.Begin);

                        MAVLink.MAVLinkMessage hbpacket = mine.getHeartBeat();
                        MAVLink.MAVLinkMessage hbpacket1 = mine.getHeartBeat();
                        MAVLink.MAVLinkMessage hbpacket2 = mine.getHeartBeat();
                        MAVLink.MAVLinkMessage hbpacket3 = mine.getHeartBeat();

                        if (hbpacket.Length == 0 && hbpacket1.Length == 0 && hbpacket2.Length == 0 && hbpacket3.Length == 0)
                        {
                            mine.logreadmode = false;
                            mine.logplaybackfile.Close();

                            if (!Directory.Exists(Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD"))
                                Directory.CreateDirectory(Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar +
                                                          "BAD");

                            log.Info("Move log bad " + logfile + " to " + Path.GetDirectoryName(logfile) +
                                     Path.DirectorySeparatorChar + "BAD" + Path.DirectorySeparatorChar +
                                     Path.GetFileName(logfile));

                            movefileusingmask(logfile,
                                Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD" +
                                Path.DirectorySeparatorChar);
                            continue;
                        }

                        if (hbpacket.Length != 0)
                        {
                            MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t) mine.DebugPacket(hbpacket);
                        }

                        if (hbpacket1.Length != 0)
                        {
                            MAVLink.mavlink_heartbeat_t hb1 = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket1);
                        }

                        if (hbpacket2.Length != 0)
                        {
                            MAVLink.mavlink_heartbeat_t hb2 = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket2);
                        }

                        if (hbpacket3.Length != 0)
                        {
                            MAVLink.mavlink_heartbeat_t hb3 = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket3);
                        }

                        // find most appropriate
                        if (mine.MAVlist.Count > 1)
                        {
                            foreach (var mav in mine.MAVlist.GetMAVStates())
                            {
                                if (mav.aptype == MAVLink.MAV_TYPE.ANTENNA_TRACKER)
                                    continue;
                                if (mav.aptype == MAVLink.MAV_TYPE.GCS)
                                    continue;

                                mine.sysidcurrent = mav.sysid;
                                mine.compidcurrent = mav.compid;
                            }
                        }

                        mine.logreadmode = false;
                        mine.logplaybackfile.Close();

                        string destdir = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar
                                         + mine.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                                         + mine.MAV.sysid + Path.DirectorySeparatorChar;

                        if (!Directory.Exists(destdir))
                            Directory.CreateDirectory(destdir);

                        movefileusingmask(logfile, destdir);
                    }
                }
                catch
                {
                    continue;
                }
            }
        }
Exemplo n.º 5
0
        public static void ScanAccel()
        {
            string[] files = Directory.GetFiles(MainV2.LogDir, "*.tlog", SearchOption.AllDirectories);

            List<string> badfiles = new List<string>();

            foreach (var file in files)
            {
                bool board = false;

                Console.WriteLine(file);

                MAVLinkInterface mavi = new MAVLinkInterface();
                using (mavi.logplaybackfile = new BinaryReader(File.OpenRead(file)))
                {
                    mavi.logreadmode = true;

                    try
                    {

                        while (mavi.logplaybackfile.BaseStream.Position < mavi.logplaybackfile.BaseStream.Length)
                        {

                            byte[] packet = mavi.readPacket();

                            if (packet.Length == 0)
                                break;

                            var objectds = mavi.DebugPacket(packet, false);

                            if (objectds is MAVLink.mavlink_param_value_t)
                            {
                                MAVLink.mavlink_param_value_t param = (MAVLink.mavlink_param_value_t)objectds;

                                if (ASCIIEncoding.ASCII.GetString(param.param_id).Contains("INS_PRODUCT_ID"))
                                {
                                    if (param.param_value == 0 || param.param_value == 5)
                                    {
                                        board = true;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }

                            if (objectds is MAVLink.mavlink_raw_imu_t)
                            {
                                MAVLink.mavlink_raw_imu_t rawimu = (MAVLink.mavlink_raw_imu_t)objectds;

                                if (board && Math.Abs(rawimu.xacc) > 2000 && Math.Abs(rawimu.yacc) > 2000 && Math.Abs(rawimu.zacc) > 2000)
                                {
                                    //CustomMessageBox.Show("Bad Log " + file);
                                    badfiles.Add(file);
                                    break;
                                }
                            }
                        }
                    }
                    catch { }
                }
            }

            if (badfiles.Count > 0)
            {
                FileStream fs = File.Open(MainV2.LogDir + Path.DirectorySeparatorChar + "SearchResults.zip", FileMode.Create);
                ZipOutputStream zipStream = new ZipOutputStream(fs);
                zipStream.SetLevel(9); //0-9, 9 being the highest level of compression
                zipStream.UseZip64 = UseZip64.Off; // older zipfile

                foreach (var file in badfiles)
                {
                    // entry 2
                    string entryName = ZipEntry.CleanName(Path.GetFileName(file)); // Removes drive from name and fixes slash direction
                    ZipEntry newEntry = new ZipEntry(entryName);
                    newEntry.DateTime = DateTime.Now;

                    zipStream.PutNextEntry(newEntry);

                    // Zip the file in buffered chunks
                    // the "using" will close the stream even if an exception occurs
                    byte[] buffer = new byte[4096];
                    using (FileStream streamReader = File.OpenRead(file))
                    {
                        StreamUtils.Copy(streamReader, zipStream, buffer);
                    }
                    zipStream.CloseEntry();
                }

                zipStream.IsStreamOwner = true;	// Makes the Close also Close the underlying stream
                zipStream.Close();

                CustomMessageBox.Show("Added " + badfiles.Count + " logs to " + MainV2.LogDir + Path.DirectorySeparatorChar + "SearchResults.zip\n Please send this file to Craig Elder <*****@*****.**>");
            }
            else
            {
                CustomMessageBox.Show("No Bad Logs Found");
            }
        }
Exemplo n.º 6
0
        public static void ScanAccel()
        {
            string[] files = Directory.GetFiles(MainV2.LogDir, "*.tlog", SearchOption.AllDirectories);

            List <string> badfiles = new List <string>();

            foreach (var file in files)
            {
                bool board = false;

                Console.WriteLine(file);

                using (MAVLinkInterface mavi = new MAVLinkInterface())
                    using (mavi.logplaybackfile = new BinaryReader(File.OpenRead(file)))
                    {
                        mavi.logreadmode = true;

                        try
                        {
                            while (mavi.logplaybackfile.BaseStream.Position < mavi.logplaybackfile.BaseStream.Length)
                            {
                                byte[] packet = mavi.readPacket();

                                if (packet.Length == 0)
                                {
                                    break;
                                }

                                var objectds = mavi.DebugPacket(packet, false);

                                if (objectds is MAVLink.mavlink_param_value_t)
                                {
                                    MAVLink.mavlink_param_value_t param = (MAVLink.mavlink_param_value_t)objectds;

                                    if (ASCIIEncoding.ASCII.GetString(param.param_id).Contains("INS_PRODUCT_ID"))
                                    {
                                        if (param.param_value == 0 || param.param_value == 5)
                                        {
                                            board = true;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }

                                if (objectds is MAVLink.mavlink_raw_imu_t)
                                {
                                    MAVLink.mavlink_raw_imu_t rawimu = (MAVLink.mavlink_raw_imu_t)objectds;

                                    if (board && Math.Abs(rawimu.xacc) > 2000 && Math.Abs(rawimu.yacc) > 2000 &&
                                        Math.Abs(rawimu.zacc) > 2000)
                                    {
                                        //CustomMessageBox.Show("Bad Log " + file);
                                        badfiles.Add(file);
                                        break;
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
            }

            if (badfiles.Count > 0)
            {
                FileStream fs = File.Open(MainV2.LogDir + Path.DirectorySeparatorChar + "SearchResults.zip",
                                          FileMode.Create);
                ZipOutputStream zipStream = new ZipOutputStream(fs);
                zipStream.SetLevel(9);             //0-9, 9 being the highest level of compression
                zipStream.UseZip64 = UseZip64.Off; // older zipfile


                foreach (var file in badfiles)
                {
                    // entry 2
                    string entryName = ZipEntry.CleanName(Path.GetFileName(file));
                    // Removes drive from name and fixes slash direction
                    ZipEntry newEntry = new ZipEntry(entryName);
                    newEntry.DateTime = DateTime.Now;

                    zipStream.PutNextEntry(newEntry);

                    // Zip the file in buffered chunks
                    // the "using" will close the stream even if an exception occurs
                    byte[] buffer = new byte[4096];
                    using (FileStream streamReader = File.OpenRead(file))
                    {
                        StreamUtils.Copy(streamReader, zipStream, buffer);
                    }
                    zipStream.CloseEntry();
                }

                zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream
                zipStream.Close();

                CustomMessageBox.Show("Added " + badfiles.Count + " logs to " + MainV2.LogDir +
                                      Path.DirectorySeparatorChar +
                                      "SearchResults.zip\n Please send this file to Craig Elder <*****@*****.**>");
            }
            else
            {
                CustomMessageBox.Show("No Bad Logs Found");
            }
        }
Exemplo n.º 7
0
        public static void SortLogs(string[] logs)
        {
            foreach (var logfile in logs)
            {
                FileInfo info = new FileInfo(logfile);

                if (info.Length == 0)
                {
                    try
                    {
                        File.Delete(logfile);
                    }
                    catch { }
                    continue;
                }

                if (info.Length <= 1024)
                {
                    try
                    {
                        string destdir = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar
                                         + "SMALL" + Path.DirectorySeparatorChar;

                        if (!Directory.Exists(destdir))
                        {
                            Directory.CreateDirectory(destdir);
                        }

                        File.Move(logfile, destdir + Path.GetFileName(logfile));
                        File.Move(logfile.Replace(".tlog", ".rlog"), destdir + Path.GetFileName(logfile).Replace(".tlog", ".rlog"));
                    }
                    catch { }
                    continue;
                }

                MAVLinkInterface mine = new MAVLinkInterface();

                try
                {
                    using (mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read)))
                    {
                        mine.logreadmode = true;

                        byte[] hbpacket = mine.getHeartBeat();

                        if (hbpacket.Length == 0)
                        {
                            mine.logreadmode = false;
                            mine.logplaybackfile.Close();

                            if (!Directory.Exists(Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD"))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD");
                            }

                            File.Move(logfile, Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD" + Path.DirectorySeparatorChar + Path.GetFileName(logfile));
                            continue;
                        }

                        MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket);

                        mine.logreadmode = false;
                        mine.logplaybackfile.Close();

                        string destdir = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar
                                         + mine.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                                         + hbpacket[3] + Path.DirectorySeparatorChar;

                        if (!Directory.Exists(destdir))
                        {
                            Directory.CreateDirectory(destdir);
                        }

                        File.Move(logfile, destdir + Path.GetFileName(logfile));

                        try
                        {
                            File.Move(logfile.Replace(".tlog", ".rlog"), destdir + Path.GetFileName(logfile).Replace(".tlog", ".rlog"));
                        }
                        catch { }
                    }
                }
                catch { continue; }
            }
        }
Exemplo n.º 8
0
        public static void SortLogs(string[] logs, string masterdestdir = "")
        {
            foreach (var logfile in logs)
            {
                if (masterdestdir == "")
                {
                    masterdestdir = Path.GetDirectoryName(logfile);
                }

                issitl = false;

                FileInfo info = new FileInfo(logfile);

                // delete 0 size files
                if (info.Length == 0)
                {
                    try
                    {
                        File.Delete(logfile);
                    }
                    catch
                    {
                    }
                    continue;
                }

                // move small logs - most likerly invalid
                if (info.Length <= 1024)
                {
                    try
                    {
                        string destdir = masterdestdir + Path.DirectorySeparatorChar
                                         + "SMALL" + Path.DirectorySeparatorChar;

                        if (!Directory.Exists(destdir))
                        {
                            Directory.CreateDirectory(destdir);
                        }

                        log.Info("Move log small " + logfile + " to " + destdir + Path.GetFileName(logfile));

                        movefileusingmask(logfile, destdir);
                    }
                    catch
                    {
                    }
                    continue;
                }

                try
                {
                    using (MAVLinkInterface mine = new MAVLinkInterface())
                        using (
                            mine.logplaybackfile =
                                new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read)))
                        {
                            mine.logreadmode   = true;
                            mine.speechenabled = false;

                            var midpoint = mine.logplaybackfile.BaseStream.Length / 2;

                            mine.logplaybackfile.BaseStream.Seek(midpoint, SeekOrigin.Begin);

                            // used for sitl detection
                            mine.SubscribeToPacketType(MAVLink.MAVLINK_MSG_ID.SIMSTATE, sitldetection);
                            mine.SubscribeToPacketType(MAVLink.MAVLINK_MSG_ID.SIM_STATE, sitldetection);

                            MAVLink.MAVLinkMessage hbpacket  = mine.getHeartBeat();
                            MAVLink.MAVLinkMessage hbpacket1 = mine.getHeartBeat();
                            MAVLink.MAVLinkMessage hbpacket2 = mine.getHeartBeat();
                            MAVLink.MAVLinkMessage hbpacket3 = mine.getHeartBeat();

                            if (hbpacket.Length == 0 && hbpacket1.Length == 0 && hbpacket2.Length == 0 && hbpacket3.Length == 0)
                            {
                                mine.logreadmode = false;
                                mine.logplaybackfile.Close();

                                if (!Directory.Exists(masterdestdir + Path.DirectorySeparatorChar + "BAD"))
                                {
                                    Directory.CreateDirectory(masterdestdir + Path.DirectorySeparatorChar +
                                                              "BAD");
                                }

                                log.Info("Move log bad " + logfile + " to " + masterdestdir +
                                         Path.DirectorySeparatorChar + "BAD" + Path.DirectorySeparatorChar +
                                         Path.GetFileName(logfile));

                                movefileusingmask(logfile,
                                                  masterdestdir + Path.DirectorySeparatorChar + "BAD" +
                                                  Path.DirectorySeparatorChar);
                                continue;
                            }

                            if (hbpacket.Length != 0)
                            {
                                MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket);
                            }

                            if (hbpacket1.Length != 0)
                            {
                                MAVLink.mavlink_heartbeat_t hb1 = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket1);
                            }

                            if (hbpacket2.Length != 0)
                            {
                                MAVLink.mavlink_heartbeat_t hb2 = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket2);
                            }

                            if (hbpacket3.Length != 0)
                            {
                                MAVLink.mavlink_heartbeat_t hb3 = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket3);
                            }

                            // find most appropriate
                            if (mine.MAVlist.Count > 1)
                            {
                                foreach (var mav in mine.MAVlist)
                                {
                                    if (mav.aptype == MAVLink.MAV_TYPE.ANTENNA_TRACKER)
                                    {
                                        continue;
                                    }
                                    if (mav.aptype == MAVLink.MAV_TYPE.GCS)
                                    {
                                        continue;
                                    }

                                    mine.sysidcurrent  = mav.sysid;
                                    mine.compidcurrent = mav.compid;
                                }
                            }

                            mine.logreadmode = false;
                            mine.logplaybackfile.Close();

                            string destdir = masterdestdir + Path.DirectorySeparatorChar
                                             + mine.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                                             + mine.MAV.sysid + Path.DirectorySeparatorChar;

                            if (issitl)
                            {
                                destdir = masterdestdir + Path.DirectorySeparatorChar
                                          + "SITL" + Path.DirectorySeparatorChar
                                          + mine.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                                          + mine.MAV.sysid + Path.DirectorySeparatorChar;
                            }

                            if (!Directory.Exists(destdir))
                            {
                                Directory.CreateDirectory(destdir);
                            }

                            movefileusingmask(logfile, destdir);
                        }
                }
                catch
                {
                    continue;
                }
            }
        }
Exemplo n.º 9
0
        public static void SortLogs(string[] logs)
        {
            foreach (var logfile in logs)
            {
                FileInfo info = new FileInfo(logfile);

                // delete 0 size files
                if (info.Length == 0)
                {
                    try
                    {
                        File.Delete(logfile);
                    }
                    catch { }
                    continue;
                }

                // move small logs - most likerly invalid
                if (info.Length <= 1024)
                {
                    try
                    {
                        string destdir = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar
                                         + "SMALL" + Path.DirectorySeparatorChar;

                        if (!Directory.Exists(destdir))
                        {
                            Directory.CreateDirectory(destdir);
                        }

                        log.Info("Move log small " + logfile + " to " + destdir + Path.GetFileName(logfile));

                        movefileusingmask(logfile, destdir);
                    }
                    catch { }
                    continue;
                }

                try
                {
                    using (MAVLinkInterface mine = new MAVLinkInterface())
                        using (mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read)))
                        {
                            mine.logreadmode = true;

                            byte[] hbpacket = mine.getHeartBeat();

                            if (hbpacket.Length == 0)
                            {
                                mine.logreadmode = false;
                                mine.logplaybackfile.Close();

                                if (!Directory.Exists(Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD"))
                                {
                                    Directory.CreateDirectory(Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD");
                                }

                                log.Info("Move log bad " + logfile + " to " + Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD" + Path.DirectorySeparatorChar + Path.GetFileName(logfile));

                                movefileusingmask(logfile, Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + "BAD" + Path.DirectorySeparatorChar);
                                continue;
                            }

                            MAVLink.mavlink_heartbeat_t hb = (MAVLink.mavlink_heartbeat_t)mine.DebugPacket(hbpacket);

                            mine.logreadmode = false;
                            mine.logplaybackfile.Close();

                            string destdir = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar
                                             + mine.MAV.aptype.ToString() + Path.DirectorySeparatorChar
                                             + hbpacket[3] + Path.DirectorySeparatorChar;

                            if (!Directory.Exists(destdir))
                            {
                                Directory.CreateDirectory(destdir);
                            }

                            movefileusingmask(logfile, destdir);
                        }
                }
                catch { continue; }
            }
        }