private static object GetFieldValue(string fieldName, UasMessage m) { PropertyInfo p = m.GetType().GetProperty(fieldName); if (p == null) { WL("MISSING FIELD: {0} on {1}", fieldName, m.GetType()); return(""); } object result = p.GetValue(m, null); if (result is char[]) { return(new String((char[])result)); } return(result); }
private void GetFieldValue(string fieldName, UasMessage m) { if (fieldName == "Roll") { PropertyInfo p = m.GetType().GetProperty(fieldName); Double degree = Convert.ToDouble(p.GetValue(m, null).ToString()) * (180 / Math.PI); lblRoll.Invoke((MethodInvoker)(() => lblRoll.Text = degree.ToString())); //lblRoll.Text= p.GetValue(m, null).ToString(); } else if (fieldName == "Pitch") { PropertyInfo p = m.GetType().GetProperty(fieldName); Double degree = Convert.ToDouble(p.GetValue(m, null).ToString()) * (180 / Math.PI); lblPitch.Invoke((MethodInvoker)(() => lblPitch.Text = degree.ToString())); //lblPitch.Text = p.GetValue(m, null).ToString(); } else if (fieldName == "Yaw") { PropertyInfo p = m.GetType().GetProperty(fieldName); Double degree = Convert.ToDouble(p.GetValue(m, null).ToString()) * (180 / Math.PI); lblYaw.Invoke((MethodInvoker)(() => lblYaw.Text = degree.ToString())); //lblYaw.Text = p.GetValue(m, null).ToString(); } //if (fieldName != "Rxerrors" && fieldName != "TimeBootMs" && fieldName != "TimeUsec"&& fieldName != "Chan1Raw" && fieldName != "Fixed" && fieldName != "Chan2Raw" && fieldName!= "VtolState" && fieldName!= "Chan3Raw" && fieldName!= "Rssi" && fieldName!="Q" && fieldName!= "Chan4Raw") //{ // PropertyInfo p = m.GetType().GetProperty(fieldName); // var resulti = p.GetValue(m,null); // object result = p.GetValue(m, null); //} //if (p == null) //{ // WL("MISSING FIELD: {0} on {1}", fieldName, m.GetType()); // return ""; //} //if (result is char[]) return new String((char[])result); //return result; }
private void PrintStandardMessage(UasMessage m) { if (m is UasAttitude) { DumpMsgMeta(m); return; } if (m is UasCommandAck) { WL("CmdACK: {0}", ((UasCommandAck)m).Result); } else if (m is UasMissionAck) { WL("MissionACK: {0}", ((UasMissionAck)m).Type); } else if (m is UasStatustext) { var sb = new StringBuilder(); foreach (char c in ((UasStatustext)m).Text) { if ('\0' == c) { break; } sb.Append(c); } WL("Statustext: {0}", sb.ToString()); } else if (m is UasPowerStatus) { WL("PowerStatus: {0}", ((UasPowerStatus)m).Vcc); } else if (m is UasHomePosition) { WL("**********HomePosition: {0}", ((UasHomePosition)m).X); } else if (m is UasHeartbeat) { var hb = (UasHeartbeat)m; WL("Heartbeat: {0} {1}", hb.Autopilot, hb.Type); } else if (m is UasLogEntry) { var log = (UasLogEntry)m; WL("UasLogEntry: {0} {1} {2}", log.Id, log.NumLogs, log.LastLogNum); } else if (m is UasMissionItem || m is UasMissionCount || m is UasMissionRequest || m is UasMissionCurrent || m is UasLogData) { var substring = m.GetType().ToString().Remove(0, 14);//remove prefix: "MavLinkNet.Uas" WL("MSG: {0}", substring); DumpMsgMeta(m); } else if (m is UasAutopilotVersion) { WL("MSG: UasAutopilotVersion"); DumpMsgMeta(m); } else if (m is UasParamValue) { WL("MSG: UasParamValue"); DumpMsgMeta(m); /* * var md = m.GetMetadata(); * var sb = new StringBuilder(); * foreach (var f in md.Fields) * { * sb.AppendLine(string.Format(" {0}: {1} ({2})", * f.Name, * GetFieldValue(f.Name, m), * f.Description)); * } * File.AppendAllText("UasParamValue.txt", sb.ToString()); */ } else { var substring = m.GetType().ToString().Remove(0, 14);//remove prefix: "MavLinkNet.Uas" WL("MSG: {0,-5} {1}", m.MessageId, substring); } }