// Useful for conversion from mavlink types to our log format. internal void SetField(string name, object value) { if (cache == null) { cache = new Dictionary <string, LogField>(); } cache[name] = new LogField() { Name = name, Value = value, Parent = this }; }
/// <summary> /// Return a data value, and try and timestamp in the x-coordinate /// </summary> /// <param name="field"></param> /// <returns></returns> public virtual DataValue GetDataValue(string field) { LogField result = null; if (cache == null) { cache = new Dictionary <string, Model.LogField>(); // crack the blob ParseFields(); } if (!cache.TryGetValue(field, out result)) { return(null); } if (result != null) { DataValue dv = new DataValue() { X = Timestamp, Y = 0 }; try { if (result.Value is double) { dv.Y = (double)result.Value; } if (result.Value is string) { double y = 0; double.TryParse((string)result.Value, out y); dv.Y = y; } } catch { } if (result.Value is string) { dv.Label = (string)result.Value; } else { dv.Label = GetLabel(result); } return(dv); } return(null); }
public T GetField <T>(string name) { LogField result = null; if (cache == null) { cache = new Dictionary <string, Model.LogField>(); // crack the blob ParseFields(); } if (cache.TryGetValue(name, out result)) { Type t = typeof(T); if (t == typeof(sbyte)) // b { object d = Convert.ToSByte(result.Value); return((T)d); } else if (t == typeof(byte)) // B { object d = Convert.ToByte(result.Value); return((T)d); } else if (t == typeof(Int16)) // h { object d = Convert.ToInt16(result.Value); return((T)d); } else if (t == typeof(UInt16)) // H { object d = Convert.ToUInt16(result.Value); return((T)d); } else if (t == typeof(Int32)) // i { object d = Convert.ToInt32(result.Value); return((T)d); } else if (t == typeof(UInt32)) // I { object d = Convert.ToUInt32(result.Value); return((T)d); } else if (t == typeof(Int64)) // q { object d = Convert.ToInt64(result.Value); return((T)d); } else if (t == typeof(UInt64)) // Q { try { object d = Convert.ToUInt64(result.Value); return((T)d); } catch { } } else if (t == typeof(float)) // f { object d = Convert.ToSingle(result.Value); return((T)d); } else if (t == typeof(double)) // d { object d = Convert.ToDouble(result.Value); return((T)d); } else if (t == typeof(string)) // n, N, Z { object d = Convert.ToString(result.Value); return((T)d); } } return(default(T)); }