public object DebugPacket(MAVLinkMessage datin, ref string text, bool PrintToConsole, string delimeter = " ")
{
string textoutput = "";
try
{
if (datin.Length > 5)
{
textoutput =
string.Format(
"{0,2:X}{8}{1,2:X}{8}{2,2:X}{8}{3,2:X}{8}{4,2:X}{8}{5,2:X}{8}{6,2:X}{8}{7,6:X}{8}",
datin.header,
datin.payloadlength, datin.incompat_flags, datin.compat_flags, datin.seq, datin.sysid,
datin.compid, datin.msgid, delimeter);
object data = datin.data;
Type test = data.GetType();
if (PrintToConsole)
{
textoutput = textoutput + test.Name + delimeter;
foreach (var field in test.GetFields())
{
// field.Name has the field's name.
object fieldValue = field.GetValue(data); // Get value
if (field.FieldType.IsArray)
{
textoutput = textoutput + field.Name + delimeter;
if (fieldValue.GetType() == typeof (byte[]))
{
try
{
byte[] crap = (byte[]) fieldValue;
foreach (byte fiel in crap)
{
if (fiel == 0)
{
break;
}
else
{
textoutput = textoutput + (char) fiel;
}
}
}
catch
{
}
}
if (fieldValue.GetType() == typeof (short[]))
{
try
{
short[] crap = (short[]) fieldValue;
foreach (short fiel in crap)
{
if (fiel == 0)
{
break;
}
else
{
textoutput = textoutput + Convert.ToString(fiel, 16) + "|";
}
}
}
catch
{
}
}
textoutput = textoutput + delimeter;
}
else
{
textoutput = textoutput + field.Name + delimeter + fieldValue.ToString() + delimeter;
}
}
var sig = "";
if (datin.sig != null)
sig = Convert.ToBase64String(datin.sig);
textoutput = textoutput + delimeter + "sig " + sig + delimeter + "Len" + delimeter + datin.Length + "\r\n";
if (PrintToConsole)
Console.Write(textoutput);
if (text != null)
text = textoutput;
}
return data;
}
}
catch
{
textoutput = textoutput + "\r\n";
}
return null;
}