LogItemSchema CreateSchemaItem(MessageSubscription sub, MessageFormat fmt) { LogItemSchema element = new LogItemSchema() { Name = fmt.name, Parent = schema, Id = sub.id }; foreach (var f in fmt.fields) { LogItemSchema column = new LogItemSchema() { Name = f.name, Parent = element, Type = f.typeName + (f.arraySize > 0 ? "[" + f.arraySize + "]" : ""), Id = sub.id }; if (f.type == FieldType.Struct) { // nested var child = CreateSchemaItem(sub, f.structType); column.ChildItems = child.ChildItems; } else if (f.arraySize > 0) { List <LogItemSchema> arrayItems = new List <LogItemSchema>(); // break out the elements of the array as separate items. for (int i = 0; i < f.arraySize; i++) { arrayItems.Add(new LogItemSchema() { Name = i.ToString(), Parent = column, Type = f.typeName, Id = sub.id }); } column.ChildItems = arrayItems; } if (element.ChildItems == null) { element.ChildItems = new List <Model.LogItemSchema>(); } element.ChildItems.Add(column); } return(element); }
public IEnumerable <LogEntry> GetRows(string typeName, DateTime startTime, TimeSpan duration) { if (typeName == "GPS") { // convert the ulog "vehicleglobal_position" to a GPS entry. MessageFormat format = null; if (formats.TryGetValue("vehicle_global_position", out format)) { foreach (var m in msgs) { if (m is MessageData) { MessageData data = (MessageData)m; if (data.format == format) { yield return(new vehicleglobal_position(data)); } } } } } }
LogItemSchema CreateSchemaItem(MessageSubscription sub, MessageFormat fmt) { LogItemSchema element = new LogItemSchema() { Name = fmt.name, Id = sub.id }; foreach (var f in fmt.fields) { LogItemSchema column = new LogItemSchema() { Name = f.name, Type = f.typeName + (f.arraySize > 0 ? "[" + f.arraySize + "]" : ""), Id = sub.id }; if (f.type == FieldType.Struct) { // nested var child = CreateSchemaItem(sub, f.structType); foreach (var item in child.CopyChildren()) { column.AddChild(item); } } else if (f.arraySize > 0) { column.IsArray = true; // break out the elements of the array as separate items. for (int i = 0; i < f.arraySize; i++) { column.AddChild(new LogItemSchema() { Name = i.ToString(), Type = f.typeName, Id = sub.id }); } } element.AddChild(column); } return(element); }
public MessageSubscription(int id, MessageFormat fmt, int multiId) { this.id = id; this.format = fmt; this.multiId = multiId; }
private object ReadField(BinaryReader reader, MessageField field) { object o = null; switch (field.type) { case FieldType.Float: o = reader.ReadSingle(); break; case FieldType.Double: o = reader.ReadDouble(); break; case FieldType.Int8: o = reader.ReadSByte(); break; case FieldType.Bool: o = (reader.ReadByte() == 0) ? false : true; break; case FieldType.UInt8: o = reader.ReadByte(); break; case FieldType.Int16: o = reader.ReadInt16(); break; case FieldType.UInt16: o = reader.ReadUInt16(); break; case FieldType.Int32: o = reader.ReadInt32(); break; case FieldType.UInt32: o = reader.ReadUInt32(); break; case FieldType.Int64: o = reader.ReadInt64(); break; case FieldType.UInt64: o = reader.ReadUInt64(); break; case FieldType.Char: o = (char)reader.ReadByte(); break; case FieldType.Struct: { MessageFormat f = field.structType; if (f == null) { throw new Exception(string.Format("Unexpected FieldType.Struct in field {0}", field.name)); } MessageData s = new MessageData(this.msgId, null, this.subscription); s.format = f; s.ReadValues(reader); o = s; } break; } return(o); }
internal MessageData GetNestedData(string fieldName) { if (values == null) { ParseValues(); } foreach (var field in format.fields) { if (field.name == fieldName) { object value = values[fieldName]; if (field.arraySize > 0) { if (nestedFormats == null) { nestedFormats = new Dictionary <string, MessageFormat>(); } MessageFormat format = null; if (!nestedFormats.TryGetValue(fieldName, out format)) { List <MessageField> fields = new List <MessageField>(); object tv; // we need to copy the timestamp down so the data renders with time sync. if (this.values.TryGetValue("timestamp", out tv)) { fields.Add(new MessageField("double timestamp")); } for (int i = 0; i < field.arraySize; i++) { var name = i.ToString(); fields.Add(new MessageField(MessageField.GetFieldTypeName(field.type) + " " + name)); } format = new MessageFormat(fieldName, fields); nestedFormats[fieldName] = format; } MessageData array = new MessageData(this.msgId, null, this.subscription); array.format = format; var values = new Dictionary <string, object>(); object ts = null; int offset = 0; // we need to copy the timestamp down so the data renders with time sync. if (this.values.TryGetValue("timestamp", out ts)) { values["timestamp"] = ts; offset++; } Array data = (Array)value; for (int i = 0; i < field.arraySize; i++) { string name = format.fields[i + offset].name; values[name] = data.GetValue(i); } array.values = values; return(array); } else if (value is MessageData) { return((MessageData)value); } else { throw new Exception(string.Format("Field {0} is not a struct", fieldName)); } } } return(null); }