Ejemplo n.º 1
0
        private void CreateSchema(PX4BinaryLog log)
        {
            LogItemSchema schema = new LogItemSchema()
            {
                Name = "Px4DataLog", Type = "Root"
            };

            foreach (var fmt in log.GetFormats())
            {
                LogItemSchema element = new LogItemSchema()
                {
                    Name = fmt.Name
                };

                int i = 0;
                foreach (var c in fmt.Columns)
                {
                    LogItemSchema column = new LogItemSchema()
                    {
                        Name = c
                    };
                    if (i < fmt.FormatString.Length)
                    {
                        column.Type = GetTypeName(fmt.FormatString[i]);
                    }
                    i++;
                    element.AddChild(column);
                }
                schema.AddChild(element);
            }

            this.schema = schema;
        }
Ejemplo n.º 2
0
        private void CreateSchema(PX4BinaryLog log)
        {
            LogItemSchema schema = new LogItemSchema()
            {
                Name = "Px4DataLog", Type = "Root", ChildItems = new List <Model.LogItemSchema>()
            };

            foreach (var fmt in log.GetFormats())
            {
                LogItemSchema element = new LogItemSchema()
                {
                    Name = fmt.Name, Parent = schema
                };

                int i = 0;
                foreach (var c in fmt.Columns)
                {
                    LogItemSchema column = new LogItemSchema()
                    {
                        Name = c, Parent = element
                    };
                    if (i < fmt.FormatString.Length)
                    {
                        column.Type = GetTypeName(fmt.FormatString[i]);
                    }
                    i++;
                    if (element.ChildItems == null)
                    {
                        element.ChildItems = new List <Model.LogItemSchema>();
                    }
                    element.ChildItems.Add(column);
                }
                schema.ChildItems.Add(element);
            }

            this.schema = schema;
        }
Ejemplo n.º 3
0
        public async Task Load(string file, ProgressUtility progress)
        {
            this.file = file;
            string ext = System.IO.Path.GetExtension(file).ToLowerInvariant();

            if (ext == ".bin")
            {
                this.logType = LogType.binFile;
            }
            else if (ext == ".px4log")
            {
                this.logType = LogType.px4logFile;
            }

            bool hasStartTime = false;

            this.startTime = DateTime.MinValue;

            List <LogEntry> rows = new List <LogEntry>();

            await Task.Run(() =>
            {
                using (Stream s = File.OpenRead(file))
                {
                    BinaryReader reader     = new BinaryReader(s);
                    PX4BinaryLog log        = new PX4BinaryLog(this.logType);
                    log.GenerateParser      = false;
                    DateTime?gpsStartTime   = null;
                    ulong gpsAbsoluteOffset = 0;
                    ulong logStartTime      = 0;

                    while (s.Position < s.Length)
                    {
                        progress.ShowProgress(0, s.Length, s.Position);

                        LogEntry row = log.ReadMessageObjects(s) as LogEntry;
                        if (row == null)
                        {
                            // has no system clock value yet, so skip it.
                            continue;
                        }

                        if (!hasStartTime && log.CurrentTime != 0)
                        {
                            hasStartTime   = true;
                            logStartTime   = log.CurrentTime;
                            this.startTime = GetTime(log.CurrentTime);
                        }
                        if (!gpsStartTime.HasValue && row.Name == "GPS")
                        {
                            ulong time = row.GetField <ulong>("GPSTime");
                            if (time > 0)
                            {
                                // ok, we got a real GPS time
                                gpsStartTime = GetTime(time);
                                // backtrack and fix up initial rows.
                                if (hasStartTime)
                                {
                                    // compute offset from PX4 boot time (which is the log.CurrentTime) and the absolute GPS real time clock
                                    // so we can add this offset to PX4 log.CurrentTime so all our times from here on out are in real time.
                                    gpsStartTime = gpsStartTime.Value.AddMilliseconds((double)logStartTime - (double)log.CurrentTime);
                                }
                                ulong linuxEpochMicroseconds = ((ulong)(gpsStartTime.Value.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalMilliseconds * 1000);
                                gpsAbsoluteOffset            = linuxEpochMicroseconds - logStartTime;
                                this.startTime = gpsStartTime.Value;
                                // and fix existing log entries
                                foreach (LogEntry e in rows)
                                {
                                    // add GPS absolute offset to the timestamp.
                                    e.Timestamp += gpsAbsoluteOffset;
                                }
                                hasStartTime = true;
                            }
                        }

                        if (gpsStartTime.HasValue)
                        {
                            // add GPS absolute offset to the timestamp.
                            row.Timestamp += gpsAbsoluteOffset;
                        }

                        rows.Add(row);

                        if (row.Format.Name == "PARM")
                        {
                            string name = row.GetField <string>("Name");
                            float value = row.GetField <float>("Value");
                            Debug.WriteLine("{0}={1}", name, value);
                        }
                    }
                    if (log.CurrentTime != 0)
                    {
                        DateTime endTime = GetTime(log.CurrentTime + gpsAbsoluteOffset);
                        this.duration    = endTime - startTime;
                        Debug.WriteLine("StartTime={0}, EndTime={1}, Duration={2}", startTime.ToString(), endTime.ToString(), duration.ToString());
                    }

                    CreateSchema(log);
                }
            });

            this.data = rows;
        }