string GetLabel(MessageField field, double y) { if (this.format.name == "vehicle_status") { if (field.name == "nav_state") { NavStates s = (NavStates)y; return(s.ToString()); } else if (field.name == "arming_state") { ArmingStates s = (ArmingStates)y; return(s.ToString()); } else if (field.name == "failure_detector_status") { FailureDetectorFlags s = (FailureDetectorFlags)y; return(s.ToString()); } } return(null); }
internal DataValue GetValue(MessageField field) { if (values == null) { ParseValues(); } double x = GetTimestamp(); double y = 0; object o = null; if (values.TryGetValue(field.name, out o)) { y = Convert.ToDouble(o); } return(new DataValue() { X = x, Y = y, UserData = this, Label = GetLabel(field, y) }); }
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); }
public IEnumerable <Flight> GetFlights() { MessageField field = new MessageField("uint8_t arming_state"); List <Flight> actualFlights = new List <Flight>(); Flight current = null; bool flying = false; Px4ULog log = null; int length = this.msgs.Count; for (int i = 0; i < length; i++) { var msg = this.msgs[i]; bool lastMessage = (i == length - 1); if (msg is MessageData md) { if (md.format.name == "vehicle_status") { var data = md.GetValue(field); if (data != null) { var s = (MessageData.ArmingStates)data.Y; if (s == MessageData.ArmingStates.ARMING_STATE_ARMED) { flying = true; } else { flying = false; } } } } if (flying) { if (current == null) { log = new Px4ULog() { file = this.file, formats = this.formats, logStartTimestamp = (long)msg.GetTimestamp(), msgs = new List <Message>(), schema = this.schema, startTime = GetTime(msg.GetTimestamp()), subscriptions = this.subscriptions, version = this.version }; current = new Flight() { Name = string.Format("Flight {0}", actualFlights.Count + 1), StartTime = log.startTime, Log = log }; } log.msgs.Add(msg); } if ((!flying || lastMessage) && current != null) { var now = GetTime(msg.GetTimestamp()); current.Duration = now - current.StartTime; actualFlights.Add(current); log = null; current = null; } } return(actualFlights); }
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); }