diff --git a/Tools/ArdupilotMegaPlanner/3DRRadio/ChangeLog.txt b/Tools/ArdupilotMegaPlanner/3DRRadio/ChangeLog.txt index c1fe230149..a98d7181f0 100644 --- a/Tools/ArdupilotMegaPlanner/3DRRadio/ChangeLog.txt +++ b/Tools/ArdupilotMegaPlanner/3DRRadio/ChangeLog.txt @@ -1,4 +1,6 @@ -0.5 - add terminal +0.7 - fix typos - log rssi screen to log as well +0.6 - add terminal logging to file, fix remote radio config +0.5 - add terminal 0.4 - adjust erase timeout - to prevent lost bootloader sync error. 0.3 - add RFD900 support 0.2 - change packet size to 32 bytes diff --git a/Tools/ArdupilotMegaPlanner/3DRRadio/Config.Designer.cs b/Tools/ArdupilotMegaPlanner/3DRRadio/Config.Designer.cs index 227e2647b3..57e029c25c 100644 --- a/Tools/ArdupilotMegaPlanner/3DRRadio/Config.Designer.cs +++ b/Tools/ArdupilotMegaPlanner/3DRRadio/Config.Designer.cs @@ -41,10 +41,10 @@ this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.terminalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.rssiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.projectPageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.rssiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); @@ -108,8 +108,8 @@ // // groupBox2 // - this.groupBox2.Controls.Add(this.panel1); resources.ApplyResources(this.groupBox2, "groupBox2"); + this.groupBox2.Controls.Add(this.panel1); this.groupBox2.Name = "groupBox2"; this.groupBox2.TabStop = false; // @@ -142,6 +142,12 @@ resources.ApplyResources(this.terminalToolStripMenuItem, "terminalToolStripMenuItem"); this.terminalToolStripMenuItem.Click += new System.EventHandler(this.terminalToolStripMenuItem_Click); // + // rssiToolStripMenuItem + // + this.rssiToolStripMenuItem.Name = "rssiToolStripMenuItem"; + resources.ApplyResources(this.rssiToolStripMenuItem, "rssiToolStripMenuItem"); + this.rssiToolStripMenuItem.Click += new System.EventHandler(this.rssiToolStripMenuItem_Click); + // // aboutToolStripMenuItem // this.aboutToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -162,12 +168,6 @@ resources.ApplyResources(this.projectPageToolStripMenuItem, "projectPageToolStripMenuItem"); this.projectPageToolStripMenuItem.Click += new System.EventHandler(this.projectPageToolStripMenuItem_Click); // - // rssiToolStripMenuItem - // - this.rssiToolStripMenuItem.Name = "rssiToolStripMenuItem"; - resources.ApplyResources(this.rssiToolStripMenuItem, "rssiToolStripMenuItem"); - this.rssiToolStripMenuItem.Click += new System.EventHandler(this.rssiToolStripMenuItem_Click); - // // Config // resources.ApplyResources(this, "$this"); @@ -178,7 +178,6 @@ this.Controls.Add(this.pictureBox1); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; - this.MaximizeBox = false; this.Name = "Config"; this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); diff --git a/Tools/ArdupilotMegaPlanner/3DRRadio/Config.resx b/Tools/ArdupilotMegaPlanner/3DRRadio/Config.resx index 0f00cd14fc..07de3c487c 100644 --- a/Tools/ArdupilotMegaPlanner/3DRRadio/Config.resx +++ b/Tools/ArdupilotMegaPlanner/3DRRadio/Config.resx @@ -326,6 +326,9 @@ 1 + + Top, Bottom, Left, Right + 12, 108 @@ -393,10 +396,10 @@ Terminal - 39, 20 + 41, 20 - Rssi + RSSI 140, 22 @@ -1585,7 +1588,7 @@ - 3DRRadio Config 0.5 + 3DRRadio Config 0.7 settingsToolStripMenuItem @@ -1599,6 +1602,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + rssiToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + aboutToolStripMenuItem @@ -1617,12 +1626,6 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - rssiToolStripMenuItem - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Config diff --git a/Tools/ArdupilotMegaPlanner/3DRRadio/Properties/AssemblyInfo.cs b/Tools/ArdupilotMegaPlanner/3DRRadio/Properties/AssemblyInfo.cs index 097219d9f7..4ebc553f2c 100644 --- a/Tools/ArdupilotMegaPlanner/3DRRadio/Properties/AssemblyInfo.cs +++ b/Tools/ArdupilotMegaPlanner/3DRRadio/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.*")] -[assembly: AssemblyFileVersion("0.5.0.0")] +[assembly: AssemblyVersion("0.0.*")] +[assembly: AssemblyFileVersion("0.0.0.0")] diff --git a/Tools/ArdupilotMegaPlanner/3DRRadio/Rssi.cs b/Tools/ArdupilotMegaPlanner/3DRRadio/Rssi.cs index 13e5110dfb..d6dab41710 100644 --- a/Tools/ArdupilotMegaPlanner/3DRRadio/Rssi.cs +++ b/Tools/ArdupilotMegaPlanner/3DRRadio/Rssi.cs @@ -9,6 +9,7 @@ using System.Windows.Forms; using ZedGraph; using ArdupilotMega; using System.Text.RegularExpressions; +using System.IO; namespace _3DRRadio { @@ -26,10 +27,15 @@ namespace _3DRRadio { InitializeComponent(); - zedGraphControl1.GraphPane.AddCurve("Rssi Local",plotdatarssil,Color.Red,SymbolType.None); - zedGraphControl1.GraphPane.AddCurve("Rssi Remote", plotdatarssir, Color.Green, SymbolType.None); - zedGraphControl1.GraphPane.AddCurve("Noice Local", plotdatanoicel, Color.Blue, SymbolType.None); - zedGraphControl1.GraphPane.AddCurve("Noice Remote", plotdatanoicer, Color.Orange, SymbolType.None); + zedGraphControl1.GraphPane.AddCurve("RSSI Local",plotdatarssil,Color.Red,SymbolType.None); + zedGraphControl1.GraphPane.AddCurve("RSSI Remote", plotdatarssir, Color.Green, SymbolType.None); + zedGraphControl1.GraphPane.AddCurve("Noise Local", plotdatanoicel, Color.Blue, SymbolType.None); + zedGraphControl1.GraphPane.AddCurve("Noise Remote", plotdatanoicer, Color.Orange, SymbolType.None); + + zedGraphControl1.GraphPane.Title.Text = "RSSI"; + + if (Terminal.sw == null) + Terminal.sw = new StreamWriter("Terminal-" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".txt"); } private void BUT_connect_Click(object sender, EventArgs e) @@ -112,6 +118,12 @@ L/R RSSI: 12/0 L/R noise: 16/0 pkts: 0 txe=0 rxe=0 stx=0 srx=0 ecc=0/0 temp=61 // Force a redraw zedGraphControl1.Invalidate(); + + if (Terminal.sw != null) + { + Terminal.sw.Write(line); + Terminal.sw.Flush(); + } } } diff --git a/Tools/ArdupilotMegaPlanner/3DRRadio/Terminal.cs b/Tools/ArdupilotMegaPlanner/3DRRadio/Terminal.cs index 7c23e789c9..1dac56fa0d 100644 --- a/Tools/ArdupilotMegaPlanner/3DRRadio/Terminal.cs +++ b/Tools/ArdupilotMegaPlanner/3DRRadio/Terminal.cs @@ -9,6 +9,7 @@ using System.Windows.Forms; using System.IO.Ports; using ArdupilotMega; using ArdupilotMega.Comms; +using System.IO; namespace _3DRRadio { @@ -18,10 +19,14 @@ namespace _3DRRadio Object thisLock = new Object(); public static bool threadrun = false; StringBuilder cmd = new StringBuilder(); + internal static StreamWriter sw; public Terminal() { InitializeComponent(); + + if (sw == null) + sw = new StreamWriter("Terminal-" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".txt"); } void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e) @@ -35,6 +40,12 @@ namespace _3DRRadio string data = comPort.ReadExisting(); //Console.Write(data); + if (sw != null) + { + sw.Write(data); + sw.Flush(); + } + addText(data); } } @@ -113,6 +124,13 @@ namespace _3DRRadio comPort.DtrEnable = false; + try + { + //if (sw != null) + // sw.Close(); + } + catch { } + if (threadrun == false) { comPort.Close(); @@ -174,11 +192,19 @@ namespace _3DRRadio string temp = cmd.ToString(); if (cmd.ToString() == "+++") + { comPort.Write(Encoding.ASCII.GetBytes(cmd.ToString()), 0, cmd.Length); + } else { comPort.Write(Encoding.ASCII.GetBytes(cmd.ToString() + "\r"), 0, cmd.Length + 1); } + + if (sw != null) + { + sw.WriteLine(cmd.ToString()); + sw.Flush(); + } } catch { CustomMessageBox.Show("Error writing to com port"); } } diff --git a/Tools/ArdupilotMegaPlanner/ArdupilotMega.csproj b/Tools/ArdupilotMegaPlanner/ArdupilotMega.csproj index d42963ffc4..71c8ec678b 100644 --- a/Tools/ArdupilotMegaPlanner/ArdupilotMega.csproj +++ b/Tools/ArdupilotMegaPlanner/ArdupilotMega.csproj @@ -231,6 +231,12 @@ + + + Component + + + UserControl @@ -265,6 +271,7 @@ ConfigArdurover.cs + @@ -406,12 +413,6 @@ Camera.cs - - - Component - - - UserControl @@ -468,7 +469,7 @@ JoystickSetup.cs - + Component @@ -537,14 +538,14 @@ Component - + Form ElevationProfile.cs - + Component diff --git a/Tools/ArdupilotMegaPlanner/ArdupilotMega.csproj.user b/Tools/ArdupilotMegaPlanner/ArdupilotMega.csproj.user index e53d971127..496c214467 100644 --- a/Tools/ArdupilotMegaPlanner/ArdupilotMega.csproj.user +++ b/Tools/ArdupilotMegaPlanner/ArdupilotMega.csproj.user @@ -11,6 +11,6 @@ - C:\Users\hog\Desktop\DIYDrones\myquad\greatmaps_e1bb830a18a3\Demo.WindowsForms\bin\Debug\;C:\Users\hog\Documents\Visual Studio 2010\Projects\ArdupilotMega\ArdupilotMega\Lib\;C:\Users\hog\Desktop\DIYDrones\myquad\sharpkml\SharpKml\bin\Release\;C:\Users\hog\Desktop\DIYDrones\myquad\MetaDataExtractorCSharp240d\bin\Release\ + C:\Users\hog\Desktop\DIYDrones\myquad\greatmaps_e1bb830a18a3\Demo.WindowsForms\bin\Debug\;C:\Users\hog\Desktop\DIYDrones\myquad\sharpkml\SharpKml\bin\Release\;C:\Users\hog\Desktop\DIYDrones\myquad\MetaDataExtractorCSharp240d\bin\Release\;C:\Users\hog\Documents\Visual Studio 2010\Projects\ArdupilotMega\ArdupilotMega\Lib\ \ No newline at end of file diff --git a/Tools/ArdupilotMegaPlanner/Common.cs b/Tools/ArdupilotMegaPlanner/Common.cs index a5a62fa53e..1d87d21b81 100644 --- a/Tools/ArdupilotMegaPlanner/Common.cs +++ b/Tools/ArdupilotMegaPlanner/Common.cs @@ -203,7 +203,7 @@ namespace ArdupilotMega float alpha = ((desired_lead_dist * (float)m2pixelwidth) / MainV2.cs.radius) * rad2deg; - if (MainV2.cs.radius < 0) + if (MainV2.cs.radius < -1) { // fixme @@ -215,7 +215,7 @@ namespace ArdupilotMega } - else + else if (MainV2.cs.radius > 1) { // correct @@ -295,6 +295,9 @@ namespace ArdupilotMega public string Tag = ""; public Color color = Color.White; + const float rad2deg = (float)(180 / Math.PI); + const float deg2rad = (float)(1.0 / rad2deg); + public PointLatLngAlt(double lat, double lng, double alt, string tag) { this.Lat = lat; @@ -378,7 +381,24 @@ namespace ArdupilotMega double num6 = num3 - d; double num7 = Math.Pow(Math.Sin(num6 / 2.0), 2.0) + ((Math.Cos(d) * Math.Cos(num3)) * Math.Pow(Math.Sin(num5 / 2.0), 2.0)); double num8 = 2.0 * Math.Atan2(Math.Sqrt(num7), Math.Sqrt(1.0 - num7)); - return (6378.137 * num8) * 1000; // M + return (6371 * num8) * 1000.0; // M + } + + public double GetDistance2(PointLatLngAlt p2) + { + //http://www.movable-type.co.uk/scripts/latlong.html + var R = 6371; // 6371 km + var dLat = (p2.Lat - Lat) * deg2rad; + var dLon = (p2.Lng - Lng) * deg2rad; + var lat1 = Lat * deg2rad; + var lat2 = p2.Lat * deg2rad; + + var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + + Math.Sin(dLon / 2) * Math.Sin(dLon / 2) * Math.Cos(lat1) * Math.Cos(lat2); + var c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); + var d = R * c * 1000.0; // M + + return d; } } @@ -587,188 +607,6 @@ namespace ArdupilotMega //Console.ReadLine(); } - #if MAVLINK10 - - public static bool translateMode(string modein, ref MAVLink.mavlink_set_mode_t mode) - { - //MAVLink.mavlink_set_mode_t mode = new MAVLink.mavlink_set_mode_t(); - mode.target_system = MainV2.comPort.sysid; - - try - { - if (Common.getModes() == typeof(Common.apmmodes)) - { - switch (EnumTranslator.GetValue(modein)) - { - case (int)Common.apmmodes.MANUAL: - case (int)Common.apmmodes.CIRCLE: - case (int)Common.apmmodes.STABILIZE: - case (int)Common.apmmodes.AUTO: - case (int)Common.apmmodes.RTL: - case (int)Common.apmmodes.LOITER: - case (int)Common.apmmodes.FLY_BY_WIRE_A: - case (int)Common.apmmodes.FLY_BY_WIRE_B: - mode.base_mode = (byte)MAVLink.MAV_MODE_FLAG.CUSTOM_MODE_ENABLED; - mode.custom_mode = (uint)EnumTranslator.GetValue(modein); - break; - default: - MessageBox.Show("No Mode Changed " + modein); - return false; - } - } - else if (Common.getModes() == typeof(Common.ac2modes)) - { - switch (EnumTranslator.GetValue(modein)) - { - case (int)Common.ac2modes.STABILIZE: - case (int)Common.ac2modes.AUTO: - case (int)Common.ac2modes.RTL: - case (int)Common.ac2modes.LOITER: - case (int)Common.ac2modes.ACRO: - case (int)Common.ac2modes.ALT_HOLD: - case (int)Common.ac2modes.CIRCLE: - case (int)Common.ac2modes.POSITION: - mode.base_mode = (byte)MAVLink.MAV_MODE_FLAG.CUSTOM_MODE_ENABLED; - mode.custom_mode = (uint)EnumTranslator.GetValue(modein); - break; - default: - MessageBox.Show("No Mode Changed " + modein); - return false; - } - } - } - catch { System.Windows.Forms.MessageBox.Show("Failed to find Mode"); return false; } - - return true; - } - -#else - public static bool translateMode(string modein, ref MAVLink.mavlink_set_nav_mode_t navmode, ref MAVLink.mavlink_set_mode_t mode) - { - - //MAVLink.mavlink_set_nav_mode_t navmode = new MAVLink.mavlink_set_nav_mode_t(); - navmode.target = MainV2.comPort.sysid; - navmode.nav_mode = 255; - - //MAVLink.mavlink_set_mode_t mode = new MAVLink.mavlink_set_mode_t(); - mode.target = MainV2.comPort.sysid; - - try - { - if (Common.getModes() == typeof(Common.apmmodes)) - { - switch (EnumTranslator.GetValue(modein)) - { - case (int)Common.apmmodes.MANUAL: - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_MANUAL; - break; - case (int)Common.apmmodes.GUIDED: - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_GUIDED; - break; - case (int)Common.apmmodes.STABILIZE: - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST1; - break; - // AUTO MODES - case (int)Common.apmmodes.AUTO: - navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_WAYPOINT; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; - break; - case (int)Common.apmmodes.RTL: - navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_RETURNING; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; - break; - case (int)Common.apmmodes.LOITER: - navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_LOITER; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; - break; - // FBW - case (int)Common.apmmodes.FLY_BY_WIRE_A: - navmode.nav_mode = (byte)1; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST2; - break; - case (int)Common.apmmodes.FLY_BY_WIRE_B: - navmode.nav_mode = (byte)2; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST2; - break; - default: - CustomMessageBox.Show("No Mode Changed " + modein); - return false; - } - } - else if (Common.getModes() == typeof(Common.aprovermodes)) - { - switch (EnumTranslator.GetValue(modein)) - { - case (int)Common.aprovermodes.MANUAL: - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_MANUAL; - break; - case (int)Common.aprovermodes.GUIDED: - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_GUIDED; - break; - case (int)Common.aprovermodes.LEARNING: - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST1; - break; - // AUTO MODES - case (int)Common.aprovermodes.AUTO: - navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_WAYPOINT; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; - break; - case (int)Common.aprovermodes.RTL: - navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_RETURNING; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; - break; - case (int)Common.aprovermodes.LOITER: - navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_LOITER; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; - break; - // FBW - case (int)Common.aprovermodes.FLY_BY_WIRE_A: - navmode.nav_mode = (byte)1; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST2; - break; - case (int)Common.aprovermodes.FLY_BY_WIRE_B: - navmode.nav_mode = (byte)2; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST2; - break; - default: - CustomMessageBox.Show("No Mode Changed " + modein); - return false; - } - } - else if (Common.getModes() == typeof(Common.ac2modes)) - { - switch (EnumTranslator.GetValue(modein)) - { - case (int)Common.ac2modes.GUIDED: - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_GUIDED; - break; - case (int)Common.ac2modes.STABILIZE: - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_MANUAL; - break; - // AUTO MODES - case (int)Common.ac2modes.AUTO: - navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_WAYPOINT; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; - break; - case (int)Common.ac2modes.RTL: - navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_RETURNING; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; - break; - case (int)Common.ac2modes.LOITER: - navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_LOITER; - mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; - break; - default: - CustomMessageBox.Show("No Mode Changed " + modein); - return false; - } - } - } - catch { System.Windows.Forms.CustomMessageBox.Show("Failed to find Mode"); return false; } - - return true; - } - #endif diff --git a/Tools/ArdupilotMegaPlanner/Controls/BackstageView/BackstageView.cs b/Tools/ArdupilotMegaPlanner/Controls/BackstageView/BackstageView.cs index effe9d5f59..0f9e0591b1 100644 --- a/Tools/ArdupilotMegaPlanner/Controls/BackstageView/BackstageView.cs +++ b/Tools/ArdupilotMegaPlanner/Controls/BackstageView/BackstageView.cs @@ -191,6 +191,50 @@ namespace ArdupilotMega.Controls.BackstageView pnlMenu.Controls.Add(lnkButton); lnkButton.Click += this.ButtonClick; + lnkButton.DoubleClick += lnkButton_DoubleClick; + } + + void lnkButton_DoubleClick(object sender, EventArgs e) + { + var backstageViewButton = ((BackstageViewButton)sender); + var associatedPage = backstageViewButton.Tag as BackstageViewPage; + + Form popoutForm = new Form(); + popoutForm.FormClosing += popoutForm_FormClosing; + + int maxright = 0, maxdown = 0; + + foreach (Control ctl in associatedPage.Page.Controls) + { + maxright = Math.Max(ctl.Right, maxright); + maxdown = Math.Max(ctl.Bottom, maxdown); + } + + // set the height to 0, so we can derive the header height in the next step + popoutForm.Height = 0; + + popoutForm.Size = new System.Drawing.Size(maxright + 20, maxdown + 20 + popoutForm.Height); + popoutForm.Controls.Add(associatedPage.Page); + popoutForm.Tag = associatedPage; + + popoutForm.Text = associatedPage.LinkText; + + popoutForm.BackColor = this.BackColor; + popoutForm.ForeColor = this.ForeColor; + + popoutForm.Show(this); + } + + void popoutForm_FormClosing(object sender, FormClosingEventArgs e) + { + // get the page back + var temp = ((Form)sender).Tag as BackstageViewPage; + // add back to where it belongs + this.pnlPages.Controls.Add(temp.Page); + + // clear the controls, so we dont dispose the good control + ((Form)sender).Controls.Clear(); + } @@ -239,7 +283,7 @@ namespace ArdupilotMega.Controls.BackstageView LinkText = linkText; } - public BackStageViewContentPanel Page { get; private set; } + public BackStageViewContentPanel Page { get; set; } public string LinkText { get; set; } } } diff --git a/Tools/ArdupilotMegaPlanner/Controls/BackstageView/BackstageViewButton.cs b/Tools/ArdupilotMegaPlanner/Controls/BackstageView/BackstageViewButton.cs index ab6544584a..b0a2292594 100644 --- a/Tools/ArdupilotMegaPlanner/Controls/BackstageView/BackstageViewButton.cs +++ b/Tools/ArdupilotMegaPlanner/Controls/BackstageView/BackstageViewButton.cs @@ -135,6 +135,7 @@ namespace ArdupilotMega.Controls.BackstageView this.Invalidate(); } + /* // This IS necessary for transparency - windows only..... remove it protected override CreateParams CreateParams diff --git a/Tools/ArdupilotMegaPlanner/Controls/ConnectionStats.cs b/Tools/ArdupilotMegaPlanner/Controls/ConnectionStats.cs index cea41e0209..a9f455a6ec 100644 --- a/Tools/ArdupilotMegaPlanner/Controls/ConnectionStats.cs +++ b/Tools/ArdupilotMegaPlanner/Controls/ConnectionStats.cs @@ -11,10 +11,11 @@ namespace ArdupilotMega.Controls { public partial class ConnectionStats : UserControl { - private readonly MAVLink _mavlink; + private readonly IMAVLink _mavlink; private CompositeDisposable _subscriptionsDisposable; - public ConnectionStats(MAVLink comPort) : this() + public ConnectionStats(IMAVLink comPort) + : this() { _mavlink = comPort; diff --git a/Tools/ArdupilotMegaPlanner/Controls/HUD.cs b/Tools/ArdupilotMegaPlanner/Controls/HUD.cs index bb39392093..7fbc01176c 100644 --- a/Tools/ArdupilotMegaPlanner/Controls/HUD.cs +++ b/Tools/ArdupilotMegaPlanner/Controls/HUD.cs @@ -967,18 +967,34 @@ namespace ArdupilotMega.Controls { drawstring(graphicsObject, "N".PadLeft(2), font, fontsize + 4, whiteBrush, headbg.Left - 5 + space * (a - start) - fontoffset, headbg.Bottom - 24 - (int)(fontoffset * 1.7)); } + else if (disp == 45) + { + drawstring(graphicsObject, "NE".PadLeft(2), font, fontsize + 4, whiteBrush, headbg.Left - 5 + space * (a - start) - fontoffset, headbg.Bottom - 24 - (int)(fontoffset * 1.7)); + } else if (disp == 90) { drawstring(graphicsObject, "E".PadLeft(2), font, fontsize + 4, whiteBrush, headbg.Left - 5 + space * (a - start) - fontoffset, headbg.Bottom - 24 - (int)(fontoffset * 1.7)); } + else if (disp == 135) + { + drawstring(graphicsObject, "SE".PadLeft(2), font, fontsize + 4, whiteBrush, headbg.Left - 5 + space * (a - start) - fontoffset, headbg.Bottom - 24 - (int)(fontoffset * 1.7)); + } else if (disp == 180) { drawstring(graphicsObject, "S".PadLeft(2), font, fontsize + 4, whiteBrush, headbg.Left - 5 + space * (a - start) - fontoffset, headbg.Bottom - 24 - (int)(fontoffset * 1.7)); } + else if (disp == 225) + { + drawstring(graphicsObject, "SW".PadLeft(2), font, fontsize + 4, whiteBrush, headbg.Left - 5 + space * (a - start) - fontoffset, headbg.Bottom - 24 - (int)(fontoffset * 1.7)); + } else if (disp == 270) { drawstring(graphicsObject, "W".PadLeft(2), font, fontsize + 4, whiteBrush, headbg.Left - 5 + space * (a - start) - fontoffset, headbg.Bottom - 24 - (int)(fontoffset * 1.7)); } + else if (disp == 315) + { + drawstring(graphicsObject, "NW".PadLeft(2), font, fontsize + 4, whiteBrush, headbg.Left - 5 + space * (a - start) - fontoffset, headbg.Bottom - 24 - (int)(fontoffset * 1.7)); + } else { drawstring(graphicsObject, (disp % 360).ToString().PadLeft(3), font, fontsize, whiteBrush, headbg.Left - 5 + space * (a - start) - fontoffset, headbg.Bottom - 24 - (int)(fontoffset * 1.7)); diff --git a/Tools/ArdupilotMegaPlanner/CurrentState.cs b/Tools/ArdupilotMegaPlanner/CurrentState.cs index bdbac3a758..5effdfcd8a 100644 --- a/Tools/ArdupilotMegaPlanner/CurrentState.cs +++ b/Tools/ArdupilotMegaPlanner/CurrentState.cs @@ -220,6 +220,9 @@ namespace ArdupilotMega { float dist = DistToMAV; + if (dist < 5) + return 0; + float altdiff = (float)(alt - HomeLocation.Alt); float angle = (float)Math.Atan(altdiff / dist) * rad2deg; @@ -245,6 +248,9 @@ namespace ArdupilotMega //bearing = bearing - 180;//absolut return direction //if (bearing < 0) bearing += 360;//normalization + if (DistToMAV < 5) + return 0; + return (float)bearing; } } @@ -339,7 +345,7 @@ namespace ArdupilotMega UpdateCurrentSettings(bs, false, MainV2.comPort); } */ - public void UpdateCurrentSettings(System.Windows.Forms.BindingSource bs, bool updatenow, MAVLink mavinterface) + public void UpdateCurrentSettings(System.Windows.Forms.BindingSource bs, bool updatenow, IMAVLink mavinterface) { if (DateTime.Now > lastupdate.AddMilliseconds(19) || updatenow) // 50 hz { diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.Designer.cs b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.Designer.cs index 2b823b0fe0..88faabb310 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.Designer.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.Designer.cs @@ -127,6 +127,7 @@ this.label91 = new System.Windows.Forms.Label(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.BUT_writePIDS = new ArdupilotMega.Controls.MyButton(); + this.BUT_rerequestparams = new ArdupilotMega.Controls.MyButton(); ((System.ComponentModel.ISupportInitialize)(this.TUNE_LOW)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.TUNE_HIGH)).BeginInit(); this.groupBox5.SuspendLayout(); @@ -793,10 +794,18 @@ this.BUT_writePIDS.UseVisualStyleBackColor = true; this.BUT_writePIDS.Click += new System.EventHandler(this.BUT_writePIDS_Click); // + // BUT_rerequestparams + // + resources.ApplyResources(this.BUT_rerequestparams, "BUT_rerequestparams"); + this.BUT_rerequestparams.Name = "BUT_rerequestparams"; + this.BUT_rerequestparams.UseVisualStyleBackColor = true; + this.BUT_rerequestparams.Click += new System.EventHandler(this.BUT_rerequestparams_Click); + // // ConfigArducopter // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.BUT_rerequestparams); this.Controls.Add(this.BUT_writePIDS); this.Controls.Add(this.myLabel3); this.Controls.Add(this.TUNE_LOW); @@ -974,5 +983,6 @@ private System.Windows.Forms.Label label91; private System.Windows.Forms.ToolTip toolTip1; private Controls.MyButton BUT_writePIDS; + private Controls.MyButton BUT_rerequestparams; } } diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.cs b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.cs index 5c4ffe974b..0f64de4203 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.cs @@ -374,6 +374,33 @@ namespace ArdupilotMega.GCSViews.ConfigurationView } } } + + /// + /// Handles the Click event of the BUT_rerequestparams control. + /// + /// The source of the event. + /// The instance containing the event data. + protected void BUT_rerequestparams_Click(object sender, EventArgs e) + { + if (!MainV2.comPort.BaseStream.IsOpen) + return; + + ((Control)sender).Enabled = false; + + try + { + MainV2.comPort.getParamList(); + } + catch (Exception ex) + { + CustomMessageBox.Show("Error: getting param list " + ex.ToString()); + } + + + ((Control)sender).Enabled = true; + + this.DoLoad(new EventArgs()); + } } diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.resx b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.resx index 79660de141..81c07eaaa4 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.resx +++ b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArducopter.resx @@ -135,13 +135,13 @@ myLabel3 - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4498.24834, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null $this - 1 + 2 575, 305 @@ -162,7 +162,7 @@ $this - 2 + 3 665, 305 @@ -183,7 +183,7 @@ $this - 3 + 4 540, 277 @@ -201,13 +201,13 @@ myLabel2 - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4498.24834, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null $this - 4 + 5 CH6_NONE @@ -294,7 +294,7 @@ $this - 5 + 6 540, 329 @@ -312,13 +312,13 @@ myLabel1 - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4498.24834, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null $this - 6 + 7 Do Nothing @@ -363,7 +363,7 @@ $this - 7 + 8 80, 60 @@ -580,7 +580,7 @@ $this - 8 + 9 True @@ -610,7 +610,7 @@ $this - 9 + 10 80, 60 @@ -874,7 +874,7 @@ $this - 10 + 11 80, 13 @@ -946,7 +946,7 @@ $this - 11 + 12 80, 63 @@ -1114,7 +1114,7 @@ $this - 12 + 13 80, 61 @@ -1282,7 +1282,7 @@ $this - 13 + 14 80, 63 @@ -1450,7 +1450,7 @@ $this - 14 + 15 80, 88 @@ -1666,7 +1666,7 @@ $this - 15 + 16 80, 63 @@ -1834,7 +1834,7 @@ $this - 16 + 17 80, 60 @@ -2050,7 +2050,7 @@ $this - 17 + 18 80, 60 @@ -2266,7 +2266,7 @@ $this - 18 + 19 80, 60 @@ -2482,19 +2482,16 @@ $this - 19 + 20 17, 17 - - Top, Right - NoControl - 305, 383 + 255, 383 103, 19 @@ -2509,12 +2506,42 @@ BUT_writePIDS - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4498.24834, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null $this + 1 + + + NoControl + + + 364, 383 + + + 0, 15, 0, 0 + + + 103, 19 + + + 74 + + + Refresh Params + + + BUT_rerequestparams + + + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null + + + $this + + 0 @@ -2527,7 +2554,7 @@ True - 728, 529 + 728, 411 toolTip1 @@ -2539,6 +2566,6 @@ ConfigArducopter - ArdupilotMega.Controls.BackstageView.BackStageViewContentPanel, ArdupilotMegaPlanner, Version=1.1.4498.24834, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.BackstageView.BackStageViewContentPanel, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null \ No newline at end of file diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.Designer.cs b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.Designer.cs index 9712d788f3..0fd14d9cc3 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.Designer.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.Designer.cs @@ -132,6 +132,7 @@ this.label52 = new System.Windows.Forms.Label(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.BUT_writePIDS = new ArdupilotMega.Controls.MyButton(); + this.BUT_rerequestparams = new ArdupilotMega.Controls.MyButton(); this.groupBox3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.THR_FS_VALUE)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.THR_MAX)).BeginInit(); @@ -797,10 +798,18 @@ this.BUT_writePIDS.UseVisualStyleBackColor = true; this.BUT_writePIDS.Click += new System.EventHandler(this.BUT_writePIDS_Click); // + // BUT_rerequestparams + // + resources.ApplyResources(this.BUT_rerequestparams, "BUT_rerequestparams"); + this.BUT_rerequestparams.Name = "BUT_rerequestparams"; + this.BUT_rerequestparams.UseVisualStyleBackColor = true; + this.BUT_rerequestparams.Click += new System.EventHandler(this.BUT_rerequestparams_Click); + // // ConfigArduplane // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.BUT_rerequestparams); this.Controls.Add(this.BUT_writePIDS); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox1); @@ -980,5 +989,6 @@ private System.Windows.Forms.Label label52; private System.Windows.Forms.ToolTip toolTip1; private Controls.MyButton BUT_writePIDS; + private Controls.MyButton BUT_rerequestparams; } } diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.cs b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.cs index 32dda5b074..575b7e9cb6 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.cs @@ -294,5 +294,32 @@ namespace ArdupilotMega.GCSViews.ConfigurationView } } + /// + /// Handles the Click event of the BUT_rerequestparams control. + /// + /// The source of the event. + /// The instance containing the event data. + protected void BUT_rerequestparams_Click(object sender, EventArgs e) + { + if (!MainV2.comPort.BaseStream.IsOpen) + return; + + ((Control)sender).Enabled = false; + + try + { + MainV2.comPort.getParamList(); + } + catch (Exception ex) + { + CustomMessageBox.Show("Error: getting param list " + ex.ToString()); + } + + + ((Control)sender).Enabled = true; + + this.DoLoad(new EventArgs()); + } + } } diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.resx b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.resx index 771898ca2c..97fe1d611c 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.resx +++ b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArduplane.resx @@ -237,7 +237,7 @@ $this - 1 + 2 111, 82 @@ -550,7 +550,7 @@ $this - 2 + 3 111, 82 @@ -838,7 +838,7 @@ $this - 3 + 4 111, 59 @@ -1054,7 +1054,7 @@ $this - 4 + 5 111, 36 @@ -1246,7 +1246,7 @@ $this - 5 + 6 111, 13 @@ -1510,7 +1510,7 @@ $this - 6 + 7 111, 82 @@ -1822,7 +1822,7 @@ $this - 7 + 8 111, 82 @@ -2134,7 +2134,7 @@ $this - 8 + 9 111, 82 @@ -2446,7 +2446,7 @@ $this - 9 + 10 111, 82 @@ -2758,7 +2758,7 @@ $this - 10 + 11 111, 82 @@ -3070,7 +3070,7 @@ $this - 11 + 12 111, 82 @@ -3382,7 +3382,7 @@ $this - 12 + 13 111, 82 @@ -3586,7 +3586,7 @@ NoControl - 261, 437 + 204, 437 103, 19 @@ -3601,12 +3601,42 @@ BUT_writePIDS - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4498.24834, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null $this + 1 + + + NoControl + + + 313, 437 + + + 0, 15, 0, 0 + + + 103, 19 + + + 75 + + + Refresh Params + + + BUT_rerequestparams + + + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null + + + $this + + 0 @@ -3628,6 +3658,6 @@ ConfigArduplane - ArdupilotMega.Controls.BackstageView.BackStageViewContentPanel, ArdupilotMegaPlanner, Version=1.1.4498.24834, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.BackstageView.BackStageViewContentPanel, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null \ No newline at end of file diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.Designer.cs b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.Designer.cs index 230b45dc36..1c6752f03a 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.Designer.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.Designer.cs @@ -80,6 +80,7 @@ this.label64 = new System.Windows.Forms.Label(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.BUT_writePIDS = new ArdupilotMega.Controls.MyButton(); + this.BUT_rerequestparams = new ArdupilotMega.Controls.MyButton(); this.groupBox3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.THR_FS_VALUE)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.THR_MAX)).BeginInit(); @@ -404,10 +405,18 @@ this.BUT_writePIDS.UseVisualStyleBackColor = true; this.BUT_writePIDS.Click += new System.EventHandler(this.BUT_writePIDS_Click); // + // BUT_rerequestparams + // + resources.ApplyResources(this.BUT_rerequestparams, "BUT_rerequestparams"); + this.BUT_rerequestparams.Name = "BUT_rerequestparams"; + this.BUT_rerequestparams.UseVisualStyleBackColor = true; + this.BUT_rerequestparams.Click += new System.EventHandler(this.BUT_rerequestparams_Click); + // // ConfigArdurover // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.BUT_rerequestparams); this.Controls.Add(this.BUT_writePIDS); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox1); @@ -500,5 +509,6 @@ private System.Windows.Forms.Label label64; private System.Windows.Forms.ToolTip toolTip1; private Controls.MyButton BUT_writePIDS; + private Controls.MyButton BUT_rerequestparams; } } diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.cs b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.cs index b84474d7b1..12feeefa1a 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.cs @@ -294,5 +294,32 @@ namespace ArdupilotMega.GCSViews.ConfigurationView } } + /// + /// Handles the Click event of the BUT_rerequestparams control. + /// + /// The source of the event. + /// The instance containing the event data. + protected void BUT_rerequestparams_Click(object sender, EventArgs e) + { + if (!MainV2.comPort.BaseStream.IsOpen) + return; + + ((Control)sender).Enabled = false; + + try + { + MainV2.comPort.getParamList(); + } + catch (Exception ex) + { + CustomMessageBox.Show("Error: getting param list " + ex.ToString()); + } + + + ((Control)sender).Enabled = true; + + this.DoLoad(new EventArgs()); + } + } } diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.resx b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.resx index 7d553eb832..a42e29cbf7 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.resx +++ b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/ConfigArdurover.resx @@ -237,7 +237,7 @@ $this - 1 + 2 111, 82 @@ -550,7 +550,7 @@ $this - 2 + 3 111, 82 @@ -838,7 +838,7 @@ $this - 3 + 4 111, 59 @@ -1054,7 +1054,7 @@ $this - 4 + 5 111, 36 @@ -1270,7 +1270,7 @@ $this - 5 + 6 111, 82 @@ -1582,7 +1582,7 @@ $this - 6 + 7 111, 82 @@ -1783,7 +1783,7 @@ NoControl - 261, 437 + 205, 437 103, 19 @@ -1798,12 +1798,42 @@ BUT_writePIDS - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4517.34195, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null $this + 1 + + + NoControl + + + 314, 437 + + + 0, 15, 0, 0 + + + 103, 19 + + + 75 + + + Refresh Params + + + BUT_rerequestparams + + + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null + + + $this + + 0 @@ -1825,6 +1855,6 @@ ConfigArdurover - ArdupilotMega.Controls.BackstageView.BackStageViewContentPanel, ArdupilotMegaPlanner, Version=1.1.4517.34195, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.BackstageView.BackStageViewContentPanel, ArdupilotMegaPlanner, Version=1.1.4523.24267, Culture=neutral, PublicKeyToken=null \ No newline at end of file diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/Setup.cs b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/Setup.cs index 95c92cdd96..21091c68ed 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/Setup.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/ConfigurationView/Setup.cs @@ -36,7 +36,7 @@ namespace ArdupilotMega.GCSViews.ConfigurationView configpanel.LoadXML("ArduCopterConfig.xml"); this.backstageView.AddPage(new BackstageView.BackstageViewPage(configpanel, "ArduCopter Pids")); - this.backstageView.AddPage(new BackstageView.BackstageViewPage(new ConfigArducopter(), "OLD ArduCopter Config")); + this.backstageView.AddPage(new BackstageView.BackstageViewPage(new ConfigArducopter(), "ArduCopter Config")); } /****************************** ArduCopter **************************/ else if (MainV2.cs.firmware == MainV2.Firmwares.ArduCopter2) @@ -47,7 +47,7 @@ namespace ArdupilotMega.GCSViews.ConfigurationView configpanel.LoadXML("ArduCopterConfig.xml"); this.backstageView.AddPage(new BackstageView.BackstageViewPage(configpanel, "ArduCopter Pids")); - this.backstageView.AddPage(new BackstageView.BackstageViewPage(new ConfigArducopter(), "OLD ArduCopter Config")); + this.backstageView.AddPage(new BackstageView.BackstageViewPage(new ConfigArducopter(), "ArduCopter Config")); } /****************************** ArduPlane **************************/ else if (MainV2.cs.firmware == MainV2.Firmwares.ArduPlane) @@ -79,7 +79,7 @@ namespace ArdupilotMega.GCSViews.ConfigurationView if (!MainV2.comPort.BaseStream.IsOpen) { - CustomMessageBox.Show("Please connect (click Connect Button) before using setup!!"); + Common.MessageShowAgain("Config Connect", "Please connect (click Connect Button) before using setup!!"); } } diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.Designer.cs b/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.Designer.cs index cd1a09ae84..183eecaafe 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.Designer.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.Designer.cs @@ -44,8 +44,9 @@ this.Gspeed = new AGaugeApp.AGauge(); this.tabStatus = new System.Windows.Forms.TabPage(); this.tabTLogs = new System.Windows.Forms.TabPage(); + this.lbl_playbackspeed = new ArdupilotMega.Controls.MyLabel(); this.lbl_logpercent = new ArdupilotMega.Controls.MyLabel(); - this.NUM_playbackspeed = new System.Windows.Forms.NumericUpDown(); + this.NUM_playbackspeed = new ArdupilotMega.Controls.MyTrackBar(); this.BUT_log2kml = new ArdupilotMega.Controls.MyButton(); this.tracklog = new System.Windows.Forms.TrackBar(); this.BUT_playlog = new ArdupilotMega.Controls.MyButton(); @@ -852,6 +853,7 @@ // // tabTLogs // + this.tabTLogs.Controls.Add(this.lbl_playbackspeed); this.tabTLogs.Controls.Add(this.lbl_logpercent); this.tabTLogs.Controls.Add(this.NUM_playbackspeed); this.tabTLogs.Controls.Add(this.BUT_log2kml); @@ -862,6 +864,12 @@ this.tabTLogs.Name = "tabTLogs"; this.tabTLogs.UseVisualStyleBackColor = true; // + // lbl_playbackspeed + // + resources.ApplyResources(this.lbl_playbackspeed, "lbl_playbackspeed"); + this.lbl_playbackspeed.Name = "lbl_playbackspeed"; + this.lbl_playbackspeed.resize = false; + // // lbl_logpercent // resources.ApplyResources(this.lbl_logpercent, "lbl_logpercent"); @@ -870,30 +878,14 @@ // // NUM_playbackspeed // - this.NUM_playbackspeed.DecimalPlaces = 1; - this.NUM_playbackspeed.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); resources.ApplyResources(this.NUM_playbackspeed, "NUM_playbackspeed"); - this.NUM_playbackspeed.Maximum = new decimal(new int[] { - 10, - 0, - 0, - 0}); - this.NUM_playbackspeed.Minimum = new decimal(new int[] { - 1, - 0, - 0, - 65536}); + this.NUM_playbackspeed.LargeChange = 1; + this.NUM_playbackspeed.Maximum = 10D; + this.NUM_playbackspeed.Minimum = 0.01D; this.NUM_playbackspeed.Name = "NUM_playbackspeed"; this.toolTip1.SetToolTip(this.NUM_playbackspeed, resources.GetString("NUM_playbackspeed.ToolTip")); - this.NUM_playbackspeed.Value = new decimal(new int[] { - 1, - 0, - 0, - 0}); + this.NUM_playbackspeed.Value = 1D; + this.NUM_playbackspeed.Scroll += new System.EventHandler(this.NUM_playbackspeed_Scroll); // // BUT_log2kml // @@ -1225,7 +1217,7 @@ private ArdupilotMega.Controls.MyLabel lbl_winddir; private ArdupilotMega.Controls.MyButton BUT_joystick; private System.Windows.Forms.ToolTip toolTip1; - private System.Windows.Forms.NumericUpDown NUM_playbackspeed; + private ArdupilotMega.Controls.MyTrackBar NUM_playbackspeed; private System.Windows.Forms.ContextMenuStrip contextMenuStrip2; private System.Windows.Forms.ToolStripMenuItem recordHudToAVIToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem stopRecordToolStripMenuItem; @@ -1236,5 +1228,6 @@ private ArdupilotMega.Controls.MyLabel lbl_hdop; private ArdupilotMega.Controls.MyLabel lbl_sats; private Controls.HSI Gheading; + private Controls.MyLabel lbl_playbackspeed; } } \ No newline at end of file diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.cs b/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.cs index 695059accb..f80e4dfc76 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.cs @@ -24,7 +24,7 @@ namespace ArdupilotMega.GCSViews { partial class FlightData : MyUserControl { - ArdupilotMega.MAVLink comPort = MainV2.comPort; + ArdupilotMega.IMAVLink comPort = MainV2.comPort; public static int threadrun = 0; StreamWriter swlog; int tickStart = 0; @@ -77,7 +77,7 @@ namespace ArdupilotMega.GCSViews public static GMapControl mymap = null; bool playingLog = false; - + double LogPlayBackSpeed = 1.0; public static PointLatLngAlt GuidedModeWP = new PointLatLngAlt(); @@ -126,7 +126,7 @@ namespace ArdupilotMega.GCSViews List list = new List(); - //foreach (object obj in Enum.GetValues(typeof(MAVLink.MAV_ACTION))) + //foreach (object obj in Enum.GetValues(typeof(MAVLink09.MAV_ACTION))) #if MAVLINK10 { list.Add("LOITER_UNLIM"); @@ -280,7 +280,7 @@ namespace ArdupilotMega.GCSViews { //System.Threading.Thread.Sleep(1000); - //comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.RAW_CONTROLLER, 0); // request servoout + //comPort.requestDatastream((byte)ArdupilotMega.MAVLink09.MAV_DATA_STREAM.RAW_CONTROLLER, 0); // request servoout comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.EXTENDED_STATUS, MainV2.cs.ratestatus); // mode comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.POSITION, MainV2.cs.rateposition); // request gps comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.EXTRA1, MainV2.cs.rateattitude); // request attitude @@ -319,20 +319,7 @@ namespace ArdupilotMega.GCSViews updatePlayPauseButton(true); - switch (comPort.aptype) - { - case MAVLink.MAV_TYPE.MAV_FIXED_WING: - MainV2.cs.firmware = MainV2.Firmwares.ArduPlane; - break; - case MAVLink.MAV_TYPE.MAV_QUADROTOR: - MainV2.cs.firmware = MainV2.Firmwares.ArduCopter2; - break; - case MAVLink.MAV_TYPE.MAV_GROUND: - MainV2.cs.firmware = MainV2.Firmwares.ArduRover; - break; - default: - break; - } + MainV2.comPort.setAPType(); if (comPort.BaseStream.IsOpen) { @@ -356,9 +343,11 @@ namespace ArdupilotMega.GCSViews act = 0; int ts = 0; + if (LogPlayBackSpeed == 0) + LogPlayBackSpeed = 0.01; try { - ts = (int)(act / (double)NUM_playbackspeed.Value); + ts = (int) Math.Min((act / LogPlayBackSpeed),1000); } catch { } if (ts > 0) @@ -509,7 +498,6 @@ namespace ArdupilotMega.GCSViews { PointLatLng currentloc = new PointLatLng(MainV2.cs.lat, MainV2.cs.lng); - if (MainV2.cs.firmware == MainV2.Firmwares.ArduPlane) { routes.Markers.Add(new GMapMarkerPlane(currentloc, MainV2.cs.yaw, MainV2.cs.groundcourse, MainV2.cs.nav_bearing, MainV2.cs.target_bearing, gMapControl1)); @@ -864,11 +852,11 @@ namespace ArdupilotMega.GCSViews { ((Button)sender).Enabled = false; - //comPort.doAction(MAVLink.MAV_ACTION.MAV_ACTION_RETURN); // set nav from + //comPort.doAction(MAVLink09.MAV_ACTION.MAV_ACTION_RETURN); // set nav from //System.Threading.Thread.Sleep(100); comPort.setWPCurrent(1); // set nav to //System.Threading.Thread.Sleep(100); - //comPort.doAction(MAVLink.MAV_ACTION.MAV_ACTION_SET_AUTO); // set auto + //comPort.doAction(MAVLink09.MAV_ACTION.MAV_ACTION_SET_AUTO); // set auto } catch { CustomMessageBox.Show("The command failed to execute"); } ((Button)sender).Enabled = true; @@ -1139,7 +1127,33 @@ namespace ArdupilotMega.GCSViews private void tabPage1_Resize(object sender, EventArgs e) { - int mywidth; + int mywidth, myheight; + + float scale = tabGauges.Width / (float)tabGauges.Height; + + if (scale > 0.5 && scale < 1.9) + {// square + Gvspeed.Visible = true; + + if (tabGauges.Height < tabGauges.Width) + myheight = tabGauges.Height / 2; + else + myheight = tabGauges.Width / 2; + + Gvspeed.Height = myheight; + Gspeed.Height = myheight; + Galt.Height = myheight; + Gheading.Height = myheight; + + Gvspeed.Location = new Point(0, 0); + Gspeed.Location = new Point(Gvspeed.Right, 0); + + + Galt.Location = new Point(0, Gspeed.Bottom); + Gheading.Location = new Point(Galt.Right, Gspeed.Bottom); + + return; + } if (tabGauges.Width < 500) { @@ -1448,7 +1462,7 @@ namespace ArdupilotMega.GCSViews aviwriter = null; } - void setupPropertyInfo(ref System.Reflection.PropertyInfo input, string name, object source) + bool setupPropertyInfo(ref System.Reflection.PropertyInfo input, string name, object source) { Type test = source.GetType(); @@ -1457,11 +1471,11 @@ namespace ArdupilotMega.GCSViews if (field.Name == name) { input = field; - return; + return true; } } - + return false; } private void zg1_DoubleClick(object sender, EventArgs e) @@ -1575,53 +1589,53 @@ namespace ArdupilotMega.GCSViews { if (list1item == null) { - setupPropertyInfo(ref list1item, ((CheckBox)sender).Name, MainV2.cs); - list1curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list1, Color.Red, SymbolType.None); + if (setupPropertyInfo(ref list1item, ((CheckBox)sender).Name, MainV2.cs)) + list1curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list1, Color.Red, SymbolType.None); } else if (list2item == null) { - setupPropertyInfo(ref list2item, ((CheckBox)sender).Name, MainV2.cs); - list2curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list2, Color.Blue, SymbolType.None); + if (setupPropertyInfo(ref list2item, ((CheckBox)sender).Name, MainV2.cs)) + list2curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list2, Color.Blue, SymbolType.None); } else if (list3item == null) { - setupPropertyInfo(ref list3item, ((CheckBox)sender).Name, MainV2.cs); - list3curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list3, Color.Green, SymbolType.None); + if (setupPropertyInfo(ref list3item, ((CheckBox)sender).Name, MainV2.cs)) + list3curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list3, Color.Green, SymbolType.None); } else if (list4item == null) { - setupPropertyInfo(ref list4item, ((CheckBox)sender).Name, MainV2.cs); - list4curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list4, Color.Orange, SymbolType.None); + if (setupPropertyInfo(ref list4item, ((CheckBox)sender).Name, MainV2.cs)) + list4curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list4, Color.Orange, SymbolType.None); } else if (list5item == null) { - setupPropertyInfo(ref list5item, ((CheckBox)sender).Name, MainV2.cs); - list5curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list5, Color.Yellow, SymbolType.None); + if (setupPropertyInfo(ref list5item, ((CheckBox)sender).Name, MainV2.cs)) + list5curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list5, Color.Yellow, SymbolType.None); } else if (list6item == null) { - setupPropertyInfo(ref list6item, ((CheckBox)sender).Name, MainV2.cs); - list6curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list6, Color.Magenta, SymbolType.None); + if (setupPropertyInfo(ref list6item, ((CheckBox)sender).Name, MainV2.cs)) + list6curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list6, Color.Magenta, SymbolType.None); } else if (list7item == null) { - setupPropertyInfo(ref list7item, ((CheckBox)sender).Name, MainV2.cs); - list7curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list7, Color.Purple, SymbolType.None); + if (setupPropertyInfo(ref list7item, ((CheckBox)sender).Name, MainV2.cs)) + list7curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list7, Color.Purple, SymbolType.None); } else if (list8item == null) { - setupPropertyInfo(ref list8item, ((CheckBox)sender).Name, MainV2.cs); - list8curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list8, Color.LimeGreen, SymbolType.None); + if (setupPropertyInfo(ref list8item, ((CheckBox)sender).Name, MainV2.cs)) + list8curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list8, Color.LimeGreen, SymbolType.None); } else if (list9item == null) { - setupPropertyInfo(ref list9item, ((CheckBox)sender).Name, MainV2.cs); - list9curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list9, Color.Cyan, SymbolType.None); + if (setupPropertyInfo(ref list9item, ((CheckBox)sender).Name, MainV2.cs)) + list9curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list9, Color.Cyan, SymbolType.None); } else if (list10item == null) { - setupPropertyInfo(ref list10item, ((CheckBox)sender).Name, MainV2.cs); - list10curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list10, Color.Violet, SymbolType.None); + if (setupPropertyInfo(ref list10item, ((CheckBox)sender).Name, MainV2.cs)) + list10curve = zg1.GraphPane.AddCurve(((CheckBox)sender).Name, list10, Color.Violet, SymbolType.None); } else { @@ -1843,5 +1857,11 @@ print 'Roll complete' { MainV2.config["CHK_autopan"] = CHK_autopan.Checked.ToString(); } + + private void NUM_playbackspeed_Scroll(object sender, EventArgs e) + { + LogPlayBackSpeed = NUM_playbackspeed.Value; + lbl_playbackspeed.Text = "x " + LogPlayBackSpeed; + } } } \ No newline at end of file diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.resx b/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.resx index c6bf7abc1f..52768e3a33 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.resx +++ b/Tools/ArdupilotMegaPlanner/GCSViews/FlightData.resx @@ -208,7 +208,7 @@ hud1 - ArdupilotMega.Controls.HUD, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.HUD, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null SubMainLeft.Panel1 @@ -247,7 +247,7 @@ BUT_script - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -280,7 +280,7 @@ BUT_joystick - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -310,7 +310,7 @@ BUT_quickmanual - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -340,7 +340,7 @@ BUT_quickrtl - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -370,7 +370,7 @@ BUT_quickauto - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -424,7 +424,7 @@ BUT_setwp - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -475,7 +475,7 @@ BUT_setmode - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -505,7 +505,7 @@ BUT_clear_track - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -556,7 +556,7 @@ BUT_Homealt - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -586,7 +586,7 @@ BUT_RAWSensor - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -616,7 +616,7 @@ BUTrestartmission - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -646,7 +646,7 @@ BUTactiondo - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabActions @@ -700,7 +700,7 @@ Gvspeed - AGaugeApp.AGauge, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + AGaugeApp.AGauge, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabGauges @@ -730,7 +730,7 @@ Gheading - ArdupilotMega.Controls.HSI, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.HSI, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabGauges @@ -760,7 +760,7 @@ Galt - AGaugeApp.AGauge, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + AGaugeApp.AGauge, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabGauges @@ -793,7 +793,7 @@ Gspeed - AGaugeApp.AGauge, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + AGaugeApp.AGauge, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabGauges @@ -858,6 +858,33 @@ 2 + + Top, Right + + + 353, 54 + + + 51, 20 + + + 79 + + + x 1.0 + + + lbl_playbackspeed + + + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null + + + tabTLogs + + + 0 + Top, Right @@ -877,19 +904,22 @@ lbl_logpercent - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabTLogs - 0 + 1 + + + Top, Bottom, Left, Right - 178, 35 + 178, 40 - 54, 20 + 169, 45 77 @@ -901,13 +931,13 @@ NUM_playbackspeed - System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + ArdupilotMega.Controls.MyTrackBar, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabTLogs - 1 + 2 NoControl @@ -928,13 +958,13 @@ BUT_log2kml - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabTLogs - 2 + 3 Top, Left, Right @@ -961,7 +991,7 @@ tabTLogs - 3 + 4 NoControl @@ -982,13 +1012,13 @@ BUT_playlog - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabTLogs - 4 + 5 NoControl @@ -1009,13 +1039,13 @@ BUT_loadtelem - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null tabTLogs - 5 + 6 4, 22 @@ -1198,7 +1228,7 @@ lbl_hdop - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null splitContainer1.Panel2 @@ -1231,7 +1261,7 @@ lbl_sats - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null splitContainer1.Panel2 @@ -1261,7 +1291,7 @@ lbl_winddir - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null splitContainer1.Panel2 @@ -1291,7 +1321,7 @@ lbl_windvel - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null splitContainer1.Panel2 @@ -1463,7 +1493,7 @@ gMapControl1 - ArdupilotMega.Controls.myGMAP, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.myGMAP, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null splitContainer1.Panel2 @@ -1526,7 +1556,7 @@ TXT_lat - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null panel1 @@ -1583,7 +1613,7 @@ label1 - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null panel1 @@ -1613,7 +1643,7 @@ TXT_long - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null panel1 @@ -1643,7 +1673,7 @@ TXT_alt - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null panel1 @@ -1844,7 +1874,7 @@ label6 - ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyLabel, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null $this @@ -1922,6 +1952,6 @@ FlightData - System.Windows.Forms.MyUserControl, ArdupilotMegaPlanner, Version=1.1.4519.33801, Culture=neutral, PublicKeyToken=null + System.Windows.Forms.MyUserControl, ArdupilotMegaPlanner, Version=1.1.4523.23191, Culture=neutral, PublicKeyToken=null \ No newline at end of file diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/FlightPlanner.cs b/Tools/ArdupilotMegaPlanner/GCSViews/FlightPlanner.cs index 67782599e2..6e8f15b418 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/FlightPlanner.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/FlightPlanner.cs @@ -1221,7 +1221,7 @@ namespace ArdupilotMega.GCSViews try { - MAVLink port = MainV2.comPort; + IMAVLink port = MainV2.comPort; if (!port.BaseStream.IsOpen) { @@ -1330,7 +1330,7 @@ namespace ArdupilotMega.GCSViews { try { - MAVLink port = MainV2.comPort; + IMAVLink port = MainV2.comPort; if (!port.BaseStream.IsOpen) { @@ -2491,6 +2491,12 @@ namespace ArdupilotMega.GCSViews CustomMessageBox.Show("Right click the map to draw a polygon", "Area", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } + + // ensure points/latlong are current + MainMap.Zoom = (int)MainMap.Zoom; + + MainMap.Refresh(); + GMapPolygon area = drawnpolygon; area.Points.Add(area.Points[0]); // make a full loop RectLatLng arearect = getPolyMinMax(area); @@ -2541,7 +2547,7 @@ namespace ArdupilotMega.GCSViews //Commands.Rows.Clear(); #endif // get x y components - double x1 = Math.Cos((double.Parse(angle)) * deg2rad); + double x1 = Math.Cos((double.Parse(angle)) * deg2rad); // needs to mod for long scale double y1 = Math.Sin((double.Parse(angle)) * deg2rad); // get x y step amount in lat lng from m diff --git a/Tools/ArdupilotMegaPlanner/GCSViews/Simulation.cs b/Tools/ArdupilotMegaPlanner/GCSViews/Simulation.cs index 07871632a6..11ce2b36c6 100644 --- a/Tools/ArdupilotMegaPlanner/GCSViews/Simulation.cs +++ b/Tools/ArdupilotMegaPlanner/GCSViews/Simulation.cs @@ -22,7 +22,7 @@ namespace ArdupilotMega.GCSViews public partial class Simulation : MyUserControl { private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - MAVLink comPort = MainV2.comPort; + IMAVLink comPort = MainV2.comPort; UdpClient XplanesSEND; UdpClient MavLink; Socket SimulatorRECV; @@ -721,7 +721,7 @@ namespace ArdupilotMega.GCSViews /// Packet /// Length /// Com Port - private void RECVprocess(byte[] data, int receviedbytes, ArdupilotMega.MAVLink comPort) + private void RECVprocess(byte[] data, int receviedbytes, ArdupilotMega.IMAVLink comPort) { #if MAVLINK10 ArdupilotMega.MAVLink.mavlink_hil_state_t hilstate = new ArdupilotMega.MAVLink.mavlink_hil_state_t(); diff --git a/Tools/ArdupilotMegaPlanner/MainV2.cs b/Tools/ArdupilotMegaPlanner/MainV2.cs index 3ae41c1b5e..ce6366d45e 100644 --- a/Tools/ArdupilotMegaPlanner/MainV2.cs +++ b/Tools/ArdupilotMegaPlanner/MainV2.cs @@ -44,7 +44,7 @@ namespace ArdupilotMega /// /// Main Comport interface /// - public static MAVLink comPort = new MAVLink(); + public static IMAVLink comPort = new MAVLink(); /// /// Comport name /// @@ -1310,7 +1310,10 @@ namespace ArdupilotMega try { - CheckForUpdate(); + if (System.Diagnostics.Debugger.IsAttached) + { + CheckForUpdate(); + } } catch (Exception ex) { @@ -1518,6 +1521,23 @@ namespace ArdupilotMega kml.AddFeature(pmplane); + SharpKml.Dom.CoordinateCollection coords = new SharpKml.Dom.CoordinateCollection(); + + foreach (var point in GCSViews.FlightPlanner.pointlist) + { + if (point != null) + coords.Add(new SharpKml.Base.Vector(point.Lat, point.Lng, point.Alt)); + + } + + SharpKml.Dom.LineString ls = new SharpKml.Dom.LineString(); + ls.AltitudeMode = SharpKml.Dom.AltitudeMode.RelativeToGround; + ls.Coordinates = coords; + + SharpKml.Dom.Placemark pm = new SharpKml.Dom.Placemark() { Geometry = ls }; + + kml.AddFeature(pm); + SharpKml.Base.Serializer serializer = new SharpKml.Base.Serializer(); serializer.Serialize(kml); @@ -1677,19 +1697,20 @@ namespace ArdupilotMega { process.StartInfo.FileName = exePath + Path.DirectorySeparatorChar + "Updater.exe"; process.StartInfo.Arguments = ""; - try + } + + try + { + foreach (string newupdater in Directory.GetFiles(exePath, "Updater.exe*.new")) { - foreach (string newupdater in Directory.GetFiles(exePath, "Updater.exe*.new")) - { - File.Copy(newupdater, newupdater.Remove(newupdater.Length - 4), true); - File.Delete(newupdater); - } - } - catch (Exception ex) - { - log.Error("Exception during update", ex); + File.Copy(newupdater, newupdater.Remove(newupdater.Length - 4), true); + File.Delete(newupdater); } } + catch (Exception ex) + { + log.Error("Exception during update", ex); + } if (frmProgressReporter != null) frmProgressReporter.UpdateProgressAndStatus(-1, "Starting Updater"); log.Info("Starting new process: " + process.StartInfo.FileName + " with " + process.StartInfo.Arguments); @@ -1750,7 +1771,7 @@ namespace ArdupilotMega //dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. - bool shouldGetFile = false; + bool updateFound = false; if (File.Exists(path)) { @@ -1785,19 +1806,19 @@ namespace ArdupilotMega if (LocalVersion != WebVersion) { - shouldGetFile = true; + updateFound = true; } } else { - shouldGetFile = true; + updateFound = true; log.Info("File does not exist: Getting " + path); // get it } response.Close(); - if (shouldGetFile) + if (updateFound) { var dr = CustomMessageBox.Show("Update Found\n\nDo you wish to update now?", "Update Now", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) @@ -2173,7 +2194,7 @@ namespace ArdupilotMega // write MainV2.comPort.doCommand(MAVLink.MAV_CMD.PREFLIGHT_STORAGE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); //read - ///////MainV2.comPort.doCommand(MAVLink.MAV_CMD.PREFLIGHT_STORAGE, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); + ///////MainV2.comPort.doCommand(MAVLink09.MAV_CMD.PREFLIGHT_STORAGE, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); #else MainV2.comPort.doAction(MAVLink.MAV_ACTION.MAV_ACTION_STORAGE_WRITE); #endif diff --git a/Tools/ArdupilotMegaPlanner/Mavlink/IMAVLink.cs b/Tools/ArdupilotMegaPlanner/Mavlink/IMAVLink.cs new file mode 100644 index 0000000000..eaad344f82 --- /dev/null +++ b/Tools/ArdupilotMegaPlanner/Mavlink/IMAVLink.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Subjects; +using System.Text; +using System.Runtime.InteropServices; +using System.Collections; // hashs +using System.Diagnostics; // stopwatch +using System.Reflection; +using System.Reflection.Emit; +using System.IO; +using System.Drawing; +using System.Threading; +using ArdupilotMega.Controls; +using System.ComponentModel; +using log4net; +using ArdupilotMega.Comms; +using ArdupilotMega.Utilities; +namespace ArdupilotMega +{ + public interface IMAVLink + { + // there is too much message intergration in the main code, so i dont think i will pursue this any further + // if it an't broke dont fix it - mav09 and mav10 are compile time defined + // i will probly revert this change at some point, unless someone else has a good idea. + + // Fields + + byte[][] packets { get; set; } + + + double[] packetspersecond { get; set; } + + Hashtable param { get; set; } + + BinaryWriter rawlogfile { get; set; } + + + + byte sysid { get; set; } + Subject WhenPacketLost { get; set; } + Subject WhenPacketReceived { get; set; } + PointLatLngAlt[] wps { get; set; } + + + ArdupilotMega.MAVLink.MAV_TYPE aptype { get; set; } + ICommsSerial BaseStream { get; set; } + int bps { get; set; } + + + DateTime bpstime { get; set; } + byte compid { get; set; } + + bool debugmavlink { get; set; } + + + DateTime lastlogread { get; set; } + DateTime lastvalidpacket { get; set; } + + BinaryWriter logfile { get; set; } + BinaryReader logplaybackfile { get; set; } + bool logreadmode { get; set; } + + // Events + + event EventHandler ParamListChanged; + + // Methods + + + void Close(); + object DebugPacket(byte[] datin); + object DebugPacket(byte[] datin, bool PrintToConsole); + object DebugPacket(byte[] datin, ref string text); + object DebugPacket(byte[] datin, ref string text, bool PrintToConsole, string delimeter = " "); + + // mav 09 + bool doAction(object actionid); + // mac 10 + bool doCommand(ArdupilotMega.MAVLink.MAV_CMD actionid, float p1, float p2, float p3, float p4, float p5, float p6, float p7); + + void setAPType(); + + + PointLatLngAlt getFencePoint(int no, ref int total); + + void getParamList(); + + Locationwp getWP(ushort index); + byte getWPCount(); + + + // static void modifyParamForDisplay(bool fromapm, string paramname, ref float value); + void Open(); + void Open(bool getparams); + + + + byte[] readPacket(); + void requestDatastream(byte id, byte hzrate); + void sendPacket(object indata); + bool setFencePoint(byte index, PointLatLngAlt plla, byte fencepointcount); + void setMode(string modein); + void setMountConfigure(ArdupilotMega.MAVLink.MAV_MOUNT_MODE mountmode, bool stabroll, bool stabpitch, bool stabyaw); + void setMountControl(double pa, double pb, double pc, bool islatlng); + bool setParam(string paramname, float value); + void setWP(Locationwp loc, ushort index, ArdupilotMega.MAVLink.MAV_FRAME frame, byte current); + void setWPACK(); + bool setWPCurrent(ushort index); + void setWPTotal(ushort wp_total); + void stopall(bool forget); + bool Write(string line); + + // Properties + + IObservable BytesReceived { get; } + IObservable BytesSent { get; } + + } +} \ No newline at end of file diff --git a/Tools/ArdupilotMegaPlanner/Mavlink/MAVLink.cs b/Tools/ArdupilotMegaPlanner/Mavlink/MAVLink.cs new file mode 100644 index 0000000000..597b3dc3f9 --- /dev/null +++ b/Tools/ArdupilotMegaPlanner/Mavlink/MAVLink.cs @@ -0,0 +1,2832 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Subjects; +using System.Text; +using System.Runtime.InteropServices; +using System.Collections; // hashs +using System.Diagnostics; // stopwatch +using System.Reflection; +using System.Reflection.Emit; +using System.IO; +using System.Drawing; +using System.Threading; +using ArdupilotMega.Controls; +using System.ComponentModel; +using log4net; +using ArdupilotMega.Comms; +using ArdupilotMega.Utilities; +using System.Windows.Forms; + +namespace ArdupilotMega +{ + public partial class MAVLink: IMAVLink + { + private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + public ICommsSerial BaseStream { get; set; } + public event EventHandler ParamListChanged; + + private const double CONNECT_TIMEOUT_SECONDS = 30; + + /// + /// progress form to handle connect and param requests + /// + ProgressReporterDialogue frmProgressReporter; + + /// + /// used for outbound packet sending + /// + byte packetcount = 0; + /// + /// mavlink remote sysid + /// + public byte sysid { get; set; } + /// + /// mavlink remove compid + /// + public byte compid { get; set; } + /// + /// storage for whole paramater list + /// + public Hashtable param { get; set; } + /// + /// storage of a previous packet recevied of a specific type + /// + public byte[][] packets { get; set; } + /// + /// used to calc packets per second on any single message type - used for stream rate comparaison + /// + public double[] packetspersecond { get; set; } + /// + /// time last seen a packet of a type + /// + DateTime[] packetspersecondbuild = new DateTime[256]; + + + private readonly Subject _bytesReceivedSubj = new Subject(); + private readonly Subject _bytesSentSubj = new Subject(); + + /// + /// Observable of the count of bytes received, notified when the bytes themselves are received + /// + public IObservable BytesReceived { get { return _bytesReceivedSubj; } } + + /// + /// Observable of the count of bytes sent, notified when the bytes themselves are received + /// + public IObservable BytesSent { get { return _bytesSentSubj; } } + + /// + /// Observable of the count of packets skipped (on reception), + /// calculated from periods where received packet sequence is not + /// contiguous + /// + public Subject WhenPacketLost { get; set; } + + public Subject WhenPacketReceived { get; set; } + + /// + /// used as a serial port write lock + /// + object objlock = new object(); + /// + /// used for a readlock on readpacket + /// + object readlock = new object(); + /// + /// used for tlog file lock + /// + object logwritelock = new object(); + /// + /// time seen of last mavlink packet + /// + public DateTime lastvalidpacket { get; set; } + /// + /// old log support + /// + bool oldlogformat = false; + + /// + /// mavlink version + /// + byte mavlinkversion = 0; + /// + /// mavlink ap type + /// + public MAV_TYPE aptype { get; set; } + /// + /// used as a snapshot of what is loaded on the ap atm. - derived from the stream + /// + public PointLatLngAlt[] wps { get; set; } + /// + /// turns on console packet display + /// + public bool debugmavlink { get; set; } + /// + /// enabled read from file mode + /// + public bool logreadmode { get; set; } + public DateTime lastlogread { get; set; } + public BinaryReader logplaybackfile { get; set; } + public BinaryWriter logfile { get; set; } + public BinaryWriter rawlogfile { get; set; } + + int bps1 = 0; + int bps2 = 0; + public int bps { get; set; } + public DateTime bpstime { get; set; } + int recvpacketcount = 0; + + float synclost; + float packetslost = 0; + float packetsnotlost = 0; + DateTime packetlosttimer = DateTime.Now; + + public MAVLink() + { + // init fields + this.BaseStream = new SerialPort(); + this.packetcount = 0; + this.sysid = 0; + this.compid = 0; + this.param = new Hashtable(); + this.packets = new byte[0x100][]; + this.packetspersecond = new double[0x100]; + this.packetspersecondbuild = new DateTime[0x100]; + this._bytesReceivedSubj = new Subject(); + this._bytesSentSubj = new Subject(); + this.WhenPacketLost = new Subject(); + this.WhenPacketReceived = new Subject(); + this.objlock = new object(); + this.readlock = new object(); + this.logwritelock = new object(); + this.lastvalidpacket = DateTime.Now; + this.oldlogformat = false; + this.mavlinkversion = 0; + this.aptype = 0; + this.wps = new PointLatLngAlt[200]; + this.debugmavlink = false; + this.logreadmode = false; + this.lastlogread = DateTime.MinValue; + this.logplaybackfile = null; + this.logfile = null; + this.rawlogfile = null; + this.bps1 = 0; + this.bps2 = 0; + this.bps = 0; + this.bpstime = DateTime.Now; + this.recvpacketcount = 0; + this.packetslost = 0f; + this.packetsnotlost = 0f; + this.packetlosttimer = DateTime.Now; + this.lastbad = new byte[2]; + + } + + public void Close() + { + BaseStream.Close(); + } + + public void Open() + { + Open(false); + } + + public void Open(bool getparams) + { + if (BaseStream.IsOpen) + return; + + frmProgressReporter = new ProgressReporterDialogue + { + StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen, + Text = "Connecting Mavlink" + }; + + if (getparams) + { + frmProgressReporter.DoWork += FrmProgressReporterDoWorkAndParams; + } + else + { + frmProgressReporter.DoWork += FrmProgressReporterDoWorkNOParams; + } + frmProgressReporter.UpdateProgressAndStatus(-1, "Mavlink Connecting..."); + ThemeManager.ApplyThemeTo(frmProgressReporter); + + frmProgressReporter.RunBackgroundOperationAsync(); + } + + void FrmProgressReporterDoWorkAndParams(object sender, ProgressWorkerEventArgs e) + { + OpenBg(true, e); + } + + void FrmProgressReporterDoWorkNOParams(object sender, ProgressWorkerEventArgs e) + { + OpenBg(false, e); + } + + private void OpenBg(bool getparams, ProgressWorkerEventArgs progressWorkerEventArgs) + { + frmProgressReporter.UpdateProgressAndStatus(-1, "Mavlink Connecting..."); + + // reset + sysid = 0; + compid = 0; + param = new Hashtable(); + packets.Initialize(); + + try + { + MainV2.giveComport = true; + + BaseStream.ReadBufferSize = 4 * 1024; + + lock (objlock) // so we dont have random traffic + { + log.Info("Open port with " + BaseStream.PortName + " " + BaseStream.BaudRate); + + BaseStream.Open(); + + BaseStream.DiscardInBuffer(); + + Thread.Sleep(1000); + } + + byte[] buffer = new byte[0]; + byte[] buffer1 = new byte[0]; + + DateTime start = DateTime.Now; + DateTime deadline = start.AddSeconds(CONNECT_TIMEOUT_SECONDS); + + var countDown = new System.Timers.Timer { Interval = 1000, AutoReset = false }; + countDown.Elapsed += (sender, e) => + { + int secondsRemaining = (deadline - e.SignalTime).Seconds; + //if (Progress != null) + // Progress(-1, string.Format("Trying to connect.\nTimeout in {0}", secondsRemaining)); + frmProgressReporter.UpdateProgressAndStatus(-1, string.Format("Trying to connect.\nTimeout in {0}", secondsRemaining)); + if (secondsRemaining > 0) countDown.Start(); + }; + countDown.Start(); + + int count = 0; + + while (true) + { + if (progressWorkerEventArgs.CancelRequested) + { + progressWorkerEventArgs.CancelAcknowledged = true; + countDown.Stop(); + if (BaseStream.IsOpen) + BaseStream.Close(); + MainV2.giveComport = false; + return; + } + + // incase we are in setup mode + BaseStream.WriteLine("planner\rgcs\r"); + + log.Info(DateTime.Now.Millisecond + " Start connect loop "); + + if (lastbad[0] == '!' && lastbad[1] == 'G' || lastbad[0] == 'G' && lastbad[1] == '!') // waiting for gps lock + { + //if (Progress != null) + // Progress(-1, "Waiting for GPS detection.."); + frmProgressReporter.UpdateProgressAndStatus(-1, "Waiting for GPS detection.."); + deadline = deadline.AddSeconds(5); // each round is 1.1 seconds + } + + if (DateTime.Now > deadline) + { + //if (Progress != null) + // Progress(-1, "No Heatbeat Packets"); + this.Close(); + progressWorkerEventArgs.ErrorMessage = "No Heatbeat Packets Received"; + throw new Exception("No Mavlink Heartbeat Packets where read from this port - Verify Baud Rate and setup\nAPM Planner waits for 2 valid heartbeat packets before connecting"); + } + + System.Threading.Thread.Sleep(1); + + // incase we are in setup mode + BaseStream.WriteLine("planner\rgcs\r"); + + // can see 2 heartbeat packets at any time, and will connect - was one after the other + + if (buffer.Length == 0) + buffer = getHeartBeat(); + + // incase we are in setup mode + BaseStream.WriteLine("planner\rgcs\r"); + + System.Threading.Thread.Sleep(1); + + if (buffer1.Length == 0) + buffer1 = getHeartBeat(); + + try + { + log.Debug("MAv Data: len " + buffer.Length + " btr " + BaseStream.BytesToRead); + } + catch { } + + count++; + + if (buffer.Length > 5 && buffer1.Length > 5 && buffer[3] == buffer1[3] && buffer[4] == buffer1[4]) + { + mavlink_heartbeat_t hb = buffer.ByteArrayToStructure(6); + + mavlinkversion = hb.mavlink_version; + aptype = (MAV_TYPE)hb.type; + + sysid = buffer[3]; + compid = buffer[4]; + recvpacketcount = buffer[2]; + log.InfoFormat("ID sys {0} comp {1} ver{2}", sysid, compid, mavlinkversion); + break; + } + + } + + countDown.Stop(); + + // if (Progress != null) + // Progress(-1, "Getting Params.. (sysid " + sysid + " compid " + compid + ") "); + frmProgressReporter.UpdateProgressAndStatus(0, "Getting Params.. (sysid " + sysid + " compid " + compid + ") "); + + if (getparams) + getParamListBG(); + + if (frmProgressReporter.doWorkArgs.CancelAcknowledged == true) + { + MainV2.giveComport = false; + if (BaseStream.IsOpen) + BaseStream.Close(); + return; + } + } + catch (Exception e) + { + try + { + BaseStream.Close(); + } + catch { } + MainV2.giveComport = false; + // if (Progress != null) + // Progress(-1, "Connect Failed\n" + e.Message); + if (string.IsNullOrEmpty(progressWorkerEventArgs.ErrorMessage)) + progressWorkerEventArgs.ErrorMessage = "Connect Failed"; + throw e; + } + //frmProgressReporter.Close(); + MainV2.giveComport = false; + frmProgressReporter.UpdateProgressAndStatus(100, "Done."); + log.Info("Done open " + sysid + " " + compid); + packetslost = 0; + synclost = 0; + } + + byte[] getHeartBeat() + { + DateTime start = DateTime.Now; + while (true) + { + byte[] buffer = readPacket(); + if (buffer.Length > 5) + { + //log.Info("getHB packet received: " + buffer.Length + " btr " + BaseStream.BytesToRead + " type " + buffer[5] ); + if (buffer[5] == MAVLINK_MSG_ID_HEARTBEAT) + { + return buffer; + } + } + if (DateTime.Now > start.AddMilliseconds(2200)) // was 1200 , now 2.2 sec + return new byte[0]; + } + } + + public void sendPacket(object indata) + { + bool validPacket = false; + byte a = 0; + foreach (Type ty in MAVLINK_MESSAGE_INFO) + { + if (ty == indata.GetType()) + { + validPacket = true; + generatePacket(a, indata); + return; + } + a++; + } + if (!validPacket) + { + log.Info("Mavlink : NOT VALID PACKET sendPacket() " + indata.GetType().ToString()); + } + } + + /// + /// Generate a Mavlink Packet and write to serial + /// + /// type number + /// struct of data + void generatePacket(byte messageType, object indata) + { + byte[] data; + + if (mavlinkversion == 3) + { + data = MavlinkUtil.StructureToByteArray(indata); + } + else + { + data = MavlinkUtil.StructureToByteArrayBigEndian(indata); + } + + //Console.WriteLine(DateTime.Now + " PC Doing req "+ messageType + " " + this.BytesToRead); + byte[] packet = new byte[data.Length + 6 + 2]; + + if (mavlinkversion == 3) + { + packet[0] = 254; + } + else if (mavlinkversion == 2) + { + packet[0] = (byte)'U'; + } + packet[1] = (byte)data.Length; + packet[2] = packetcount; + packet[3] = 255; // this is always 255 - MYGCS +#if MAVLINK10 + packet[4] = (byte)MAV_COMPONENT.MAV_COMP_ID_MISSIONPLANNER; +#else + packet[4] = (byte)MAV_COMPONENT.MAV_COMP_ID_WAYPOINTPLANNER; +#endif + packet[5] = messageType; + + int i = 6; + foreach (byte b in data) + { + packet[i] = b; + i++; + } + + ushort checksum = MavlinkCRC.crc_calculate(packet, packet[1] + 6); + + if (mavlinkversion == 3) + { + checksum = MavlinkCRC.crc_accumulate(MAVLINK_MESSAGE_CRCS[messageType], checksum); + } + + byte ck_a = (byte)(checksum & 0xFF); ///< High byte + byte ck_b = (byte)(checksum >> 8); ///< Low byte + + packet[i] = ck_a; + i += 1; + packet[i] = ck_b; + i += 1; + + if (BaseStream.IsOpen) + { + lock (objlock) + { + BaseStream.Write(packet, 0, i); + } + _bytesSentSubj.OnNext(i); + } + + try + { + if (logfile != null && logfile.BaseStream.CanWrite) + { + lock (logwritelock) + { + byte[] datearray = BitConverter.GetBytes((UInt64)((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds * 1000)); //ASCIIEncoding.ASCII.GetBytes(DateTime.Now.ToBinary() + ":"); + Array.Reverse(datearray); + logfile.Write(datearray, 0, datearray.Length); + logfile.Write(packet, 0, i); + logfile.Flush(); + } + } + + } + catch { } + + if (messageType == ArdupilotMega.MAVLink.MAVLINK_MSG_ID_REQUEST_DATA_STREAM) + { + try + { + BinaryWriter bw = new BinaryWriter(File.OpenWrite("serialsent.raw")); + bw.Seek(0, SeekOrigin.End); + bw.Write(packet, 0, i); + bw.Write((byte)'\n'); + bw.Close(); + } + catch { } // been getting errors from this. people must have it open twice. + } + + packetcount++; + + + + //System.Threading.Thread.Sleep(1); + } + + public bool Write(string line) + { + lock (objlock) + { + BaseStream.Write(line); + } + _bytesSentSubj.OnNext(line.Length); + return true; + } + + /// + /// Set parameter on apm + /// + /// name as a string + /// + public bool setParam(string paramname, float value) + { + if (!param.ContainsKey(paramname)) + { + log.Info("Param doesnt exist " + paramname); + return false; + } + + if ((float)param[paramname] == value) + { + log.Debug("setParam " + paramname + " not modified"); + return true; + } + + MainV2.giveComport = true; + + mavlink_param_set_t req = new mavlink_param_set_t(); + req.target_system = sysid; + req.target_component = compid; + + byte[] temp = ASCIIEncoding.ASCII.GetBytes(paramname); + + modifyParamForDisplay(false, paramname, ref value); +#if MAVLINK10 + Array.Resize(ref temp, 16); +#else + Array.Resize(ref temp, 15); +#endif + req.param_id = temp; + req.param_value = (value); + + generatePacket(MAVLINK_MSG_ID_PARAM_SET, req); + + log.InfoFormat("setParam '{0}' = '{1}' sysid {2} compid {3}", paramname, req.param_value, sysid, compid); + + DateTime start = DateTime.Now; + int retrys = 3; + + while (true) + { + if (!(start.AddMilliseconds(500) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("setParam Retry " + retrys); + generatePacket(MAVLINK_MSG_ID_PARAM_SET, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - setParam " + paramname); + } + + byte[] buffer = readPacket(); + if (buffer.Length > 5) + { + if (buffer[5] == MAVLINK_MSG_ID_PARAM_VALUE) + { + mavlink_param_value_t par = buffer.ByteArrayToStructure(6); + + string st = System.Text.ASCIIEncoding.ASCII.GetString(par.param_id); + + int pos = st.IndexOf('\0'); + + if (pos != -1) + { + st = st.Substring(0, pos); + } + + if (st != paramname) + { + log.InfoFormat("MAVLINK bad param responce - {0} vs {1}", paramname, st); + continue; + } + + modifyParamForDisplay(true, st, ref par.param_value); + + param[st] = (par.param_value); + + MainV2.giveComport = false; + //System.Threading.Thread.Sleep(100);//(int)(8.5 * 5)); // 8.5ms per byte + return true; + } + } + } + } + /* + public Bitmap getImage() + { + MemoryStream ms = new MemoryStream(); + + } + */ + public void getParamList() + { + frmProgressReporter = new ProgressReporterDialogue + { + StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen, + Text = "Getting Params" + }; + + frmProgressReporter.DoWork += FrmProgressReporterGetParams; + frmProgressReporter.UpdateProgressAndStatus(-1, "Getting Params..."); + ThemeManager.ApplyThemeTo(frmProgressReporter); + + frmProgressReporter.RunBackgroundOperationAsync(); + + if (ParamListChanged != null) + { + ParamListChanged(this, null); + } + } + + void FrmProgressReporterGetParams(object sender, ProgressWorkerEventArgs e) + { + Hashtable old = new Hashtable(param); + getParamListBG(); + if (frmProgressReporter.doWorkArgs.CancelRequested) + { + param = old; + } + } + + /// + /// Get param list from apm + /// + /// + private Hashtable getParamListBG() + { + MainV2.giveComport = true; + List got = new List(); + + // clear old + param = new Hashtable(); + + int retrys = 6; + int param_count = 0; + int param_total = 5; + + goagain: + + mavlink_param_request_list_t req = new mavlink_param_request_list_t(); + req.target_system = sysid; + req.target_component = compid; + + generatePacket(MAVLINK_MSG_ID_PARAM_REQUEST_LIST, req); + + DateTime start = DateTime.Now; + DateTime restart = DateTime.Now; + + do + { + + if (frmProgressReporter.doWorkArgs.CancelRequested) + { + frmProgressReporter.doWorkArgs.CancelAcknowledged = true; + MainV2.giveComport = false; + frmProgressReporter.doWorkArgs.ErrorMessage = "User Canceled"; + return param; + } + + // 4 seconds between valid packets + if (!(start.AddMilliseconds(4000) > DateTime.Now)) + { + if (retrys > 0) + { + log.InfoFormat("getParamList Retry {0} sys {1} comp {2}", retrys, sysid, compid); + generatePacket(MAVLINK_MSG_ID_PARAM_REQUEST_LIST, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - getParamList " + got.Count + " " + param_total + "\n\nYour serial link isn't fast enough\n"); + } + + byte[] buffer = readPacket(); + if (buffer.Length > 5) + { + //stopwatch.Reset(); + //stopwatch.Start(); + if (buffer[5] == MAVLINK_MSG_ID_PARAM_VALUE) + { + restart = DateTime.Now; + start = DateTime.Now; + + mavlink_param_value_t par = buffer.ByteArrayToStructure(6); + + // set new target + param_total = (par.param_count); + + + string paramID = System.Text.ASCIIEncoding.ASCII.GetString(par.param_id); + + int pos = paramID.IndexOf('\0'); + if (pos != -1) + { + paramID = paramID.Substring(0, pos); + } + + // check if we already have it + if (got.Contains(par.param_index)) + { + log.Info("Already got " + (par.param_index) + " '" + paramID + "'"); + this.frmProgressReporter.UpdateProgressAndStatus((got.Count * 100) / param_total, "Already Got param " + paramID); + continue; + } + + log.Info(DateTime.Now.Millisecond + " got param " + (par.param_index) + " of " + (par.param_count) + " name: " + paramID); + + modifyParamForDisplay(true, paramID, ref par.param_value); + param[paramID] = (par.param_value); + param_count++; + got.Add(par.param_index); + + // if (Progress != null) + // Progress((param.Count * 100) / param_total, "Got param " + paramID); + this.frmProgressReporter.UpdateProgressAndStatus((got.Count * 100) / param_total, "Got param " + paramID); + + // we have them all - lets escape eq total = 176 index = 0-175 + if (par.param_index == (param_total -1)) + break; + } + else + { + //Console.WriteLine(DateTime.Now + " PC paramlist " + buffer[5] + " want " + MAVLINK_MSG_ID_PARAM_VALUE + " btr " + BaseStream.BytesToRead); + } + //stopwatch.Stop(); + //Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed); + } + } while (got.Count < param_total); + + if (got.Count != param_total) + { + if (retrys > 0) + { + this.frmProgressReporter.UpdateProgressAndStatus((got.Count * 100) / param_total, "Getting missed params"); + retrys--; + goto goagain; + } + throw new Exception("Missing Params"); + } + MainV2.giveComport = false; + return param; + } + + public static void modifyParamForDisplay(bool fromapm, string paramname, ref float value) + { + if (paramname.ToUpper().EndsWith("_IMAX") || paramname.ToUpper().EndsWith("ALT_HOLD_RTL") || paramname.ToUpper().EndsWith("TRIM_ARSPD_CM") + || paramname.ToUpper().EndsWith("XTRK_ANGLE_CD") || paramname.ToUpper().EndsWith("LIM_PITCH_MAX") || paramname.ToUpper().EndsWith("LIM_PITCH_MIN") + || paramname.ToUpper().EndsWith("LIM_ROLL_CD") || paramname.ToUpper().EndsWith("PITCH_MAX") || paramname.ToUpper().EndsWith("WP_SPEED_MAX")) + { + if (paramname.ToUpper().EndsWith("THR_HOLD_IMAX")) + { + return; + } + + if (fromapm) + { + value /= 100.0f; + } + else + { + value *= 100.0f; + } + } + else if (paramname.ToUpper().StartsWith("TUNE_")) + { + if (fromapm) + { + value /= 1000.0f; + } + else + { + value *= 1000.0f; + } + } + } + + /// + /// Stops all requested data packets. + /// + public void stopall(bool forget) + { + mavlink_request_data_stream_t req = new mavlink_request_data_stream_t(); + req.target_system = sysid; + req.target_component = compid; + + req.req_message_rate = 10; + req.start_stop = 0; // stop + req.req_stream_id = 0; // all + + // no error on bad + try + { + generatePacket(MAVLINK_MSG_ID_REQUEST_DATA_STREAM, req); + System.Threading.Thread.Sleep(20); + generatePacket(MAVLINK_MSG_ID_REQUEST_DATA_STREAM, req); + System.Threading.Thread.Sleep(20); + generatePacket(MAVLINK_MSG_ID_REQUEST_DATA_STREAM, req); + log.Info("Stopall Done"); + + } + catch { } + } + + public void setWPACK() + { +#if MAVLINK10 + MAVLink.mavlink_mission_ack_t req = new MAVLink.mavlink_mission_ack_t(); + req.target_system = sysid; + req.target_component = compid; + req.type = 0; + + generatePacket(MAVLINK_MSG_ID_MISSION_ACK, req); +#else + MAVLink.mavlink_waypoint_ack_t req = new MAVLink.mavlink_waypoint_ack_t(); + req.target_system = sysid; + req.target_component = compid; + req.type = 0; + + generatePacket(MAVLINK_MSG_ID_WAYPOINT_ACK, req); +#endif + } + + public bool setWPCurrent(ushort index) + { +#if MAVLINK10 + MainV2.giveComport = true; + byte[] buffer; + + mavlink_mission_set_current_t req = new mavlink_mission_set_current_t(); + + req.target_system = sysid; + req.target_component = compid; + req.seq = index; + + generatePacket(MAVLINK_MSG_ID_MISSION_SET_CURRENT, req); + + DateTime start = DateTime.Now; + int retrys = 5; + + while (true) + { + if (!(start.AddMilliseconds(2000) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("setWPCurrent Retry " + retrys); + generatePacket(MAVLINK_MSG_ID_MISSION_SET_CURRENT, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - setWPCurrent"); + } + + buffer = readPacket(); + if (buffer.Length > 5) + { + if (buffer[5] == MAVLINK_MSG_ID_MISSION_CURRENT) + { + MainV2.giveComport = false; + return true; + } + } + } + } + + [Obsolete("Mavlink 09", true)] + public bool doAction(object actionid) + { + // mavlink 09 + throw new NotImplementedException(); + } + + public bool doCommand(MAV_CMD actionid, float p1, float p2, float p3, float p4, float p5, float p6, float p7) + { + + MainV2.giveComport = true; + byte[] buffer; + + mavlink_command_long_t req = new mavlink_command_long_t(); + + req.target_system = sysid; + req.target_component = compid; + + req.command = (ushort)actionid; + + req.param1 = p1; + req.param2 = p2; + req.param3 = p3; + req.param4 = p4; + req.param5 = p5; + req.param6 = p6; + req.param7 = p7; + + generatePacket(MAVLINK_MSG_ID_COMMAND_LONG, req); + + DateTime start = DateTime.Now; + int retrys = 3; + + int timeout = 2000; + + // imu calib take a little while + if (actionid == MAV_CMD.PREFLIGHT_CALIBRATION) + { + retrys = 1; + timeout = 6000; + } + + while (true) + { + if (!(start.AddMilliseconds(timeout) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("doAction Retry " + retrys); + generatePacket(MAVLINK_MSG_ID_COMMAND_LONG, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - doAction"); + } + + buffer = readPacket(); + if (buffer.Length > 5) + { + if (buffer[5] == MAVLINK_MSG_ID_COMMAND_ACK) + { + + + var ack = buffer.ByteArrayToStructure(6); + + + if (ack.result == (byte)MAV_RESULT.ACCEPTED) + { + MainV2.giveComport = false; + return true; + } + else + { + MainV2.giveComport = false; + return false; + } + } + } + } +#else + MainV2.giveComport = true; + byte[] buffer; + + mavlink_waypoint_set_current_t req = new mavlink_waypoint_set_current_t(); + + req.target_system = sysid; + req.target_component = compid; + req.seq = index; + + generatePacket(MAVLINK_MSG_ID_WAYPOINT_SET_CURRENT, req); + + DateTime start = DateTime.Now; + int retrys = 5; + + while (true) + { + if (!(start.AddMilliseconds(2000) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("setWPCurrent Retry " + retrys); + generatePacket(MAVLINK_MSG_ID_WAYPOINT_SET_CURRENT, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - setWPCurrent"); + } + + buffer = readPacket(); + if (buffer.Length > 5) + { + if (buffer[5] == MAVLINK_MSG_ID_WAYPOINT_CURRENT) + { + MainV2.giveComport = false; + return true; + } + } + } + } + + public bool doCommand(ArdupilotMega.MAVLink.MAV_CMD actionid, float p1, float p2, float p3, float p4, float p5, float p6, float p7) + { + // mavlink 10 + throw new NotImplementedException(); + } + + public bool doAction(object actionidin) + { + MAV_ACTION actionid = (MAV_ACTION)actionidin; + + MainV2.giveComport = true; + byte[] buffer; + + mavlink_action_t req = new mavlink_action_t(); + + req.target = sysid; + req.target_component = compid; + + req.action = (byte)actionid; + + generatePacket(MAVLINK_MSG_ID_ACTION, req); + + DateTime start = DateTime.Now; + int retrys = 3; + + int timeout = 2000; + + // imu calib take a little while + if (actionid == MAV_ACTION.MAV_ACTION_CALIBRATE_ACC || + actionid == MAV_ACTION.MAV_ACTION_CALIBRATE_GYRO || + actionid == MAV_ACTION.MAV_ACTION_CALIBRATE_MAG || + actionid == MAV_ACTION.MAV_ACTION_CALIBRATE_PRESSURE || + actionid == MAV_ACTION.MAV_ACTION_REBOOT) + { + retrys = 1; + timeout = 20000; + } + + while (true) + { + if (!(start.AddMilliseconds(timeout) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("doAction Retry " + retrys); + generatePacket(MAVLINK_MSG_ID_ACTION, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - doAction"); + } + + buffer = readPacket(); + if (buffer.Length > 5) + { + if (buffer[5] == MAVLINK_MSG_ID_ACTION_ACK) + { + if (buffer[7] == 1) + { + MainV2.giveComport = false; + return true; + } + else + { + MainV2.giveComport = false; + return false; + } + } + } + } + +#endif + } + + public void requestDatastream(byte id, byte hzrate) + { + + double pps = 0; + + switch (id) + { + case (byte)MAVLink.MAV_DATA_STREAM.ALL: + + break; + case (byte)MAVLink.MAV_DATA_STREAM.EXTENDED_STATUS: + if (packetspersecondbuild[MAVLINK_MSG_ID_SYS_STATUS] < DateTime.Now.AddSeconds(-2)) + break; + pps = packetspersecond[MAVLINK_MSG_ID_SYS_STATUS]; + if (hzratecheck(pps, hzrate)) + { + return; + } + break; + case (byte)MAVLink.MAV_DATA_STREAM.EXTRA1: + if (packetspersecondbuild[MAVLINK_MSG_ID_ATTITUDE] < DateTime.Now.AddSeconds(-2)) + break; + pps = packetspersecond[MAVLINK_MSG_ID_ATTITUDE]; + if (hzratecheck(pps, hzrate)) + { + return; + } + break; + case (byte)MAVLink.MAV_DATA_STREAM.EXTRA2: + if (packetspersecondbuild[MAVLINK_MSG_ID_VFR_HUD] < DateTime.Now.AddSeconds(-2)) + break; + pps = packetspersecond[MAVLINK_MSG_ID_VFR_HUD]; + if (hzratecheck(pps, hzrate)) + { + return; + } + break; + case (byte)MAVLink.MAV_DATA_STREAM.EXTRA3: + if (packetspersecondbuild[MAVLINK_MSG_ID_AHRS] < DateTime.Now.AddSeconds(-2)) + break; + pps = packetspersecond[MAVLINK_MSG_ID_AHRS]; + if (hzratecheck(pps, hzrate)) + { + return; + } + break; + case (byte)MAVLink.MAV_DATA_STREAM.POSITION: + if (packetspersecondbuild[MAVLINK_MSG_ID_GLOBAL_POSITION_INT] < DateTime.Now.AddSeconds(-2)) + break; + pps = packetspersecond[MAVLINK_MSG_ID_GLOBAL_POSITION_INT]; + if (hzratecheck(pps, hzrate)) + { + return; + } + break; + case (byte)MAVLink.MAV_DATA_STREAM.RAW_CONTROLLER: + if (packetspersecondbuild[MAVLINK_MSG_ID_RC_CHANNELS_SCALED] < DateTime.Now.AddSeconds(-2)) + break; + pps = packetspersecond[MAVLINK_MSG_ID_RC_CHANNELS_SCALED]; + if (hzratecheck(pps, hzrate)) + { + return; + } + break; + case (byte)MAVLink.MAV_DATA_STREAM.RAW_SENSORS: + if (packetspersecondbuild[MAVLINK_MSG_ID_RAW_IMU] < DateTime.Now.AddSeconds(-2)) + break; + pps = packetspersecond[MAVLINK_MSG_ID_RAW_IMU]; + if (hzratecheck(pps, hzrate)) + { + return; + } + break; + case (byte)MAVLink.MAV_DATA_STREAM.RC_CHANNELS: + if (packetspersecondbuild[MAVLINK_MSG_ID_RC_CHANNELS_RAW] < DateTime.Now.AddSeconds(-2)) + break; + pps = packetspersecond[MAVLINK_MSG_ID_RC_CHANNELS_RAW]; + if (hzratecheck(pps, hzrate)) + { + return; + } + break; + } + + //packetspersecond[temp[5]]; + + if (pps == 0 && hzrate == 0) + { + return; + } + + + log.InfoFormat("Request stream {0} at {1} hz", Enum.Parse(typeof(MAV_DATA_STREAM), id.ToString()), hzrate); + getDatastream(id, hzrate); + } + + // returns true for ok + bool hzratecheck(double pps, int hzrate) + { + + if (hzrate == 0 && pps == 0) + { + return true; + } + else if (hzrate == 1 && pps >= 0.5 && pps <= 2) + { + return true; + } + else if (hzrate == 3 && pps >= 2 && hzrate < 5) + { + return true; + } + else if (hzrate == 10 && pps > 5 && hzrate < 15) + { + return true; + } + else if (hzrate > 15 && pps > 15) + { + return true; + } + + return false; + + } + + void getDatastream(byte id, byte hzrate) + { + mavlink_request_data_stream_t req = new mavlink_request_data_stream_t(); + req.target_system = sysid; + req.target_component = compid; + + req.req_message_rate = hzrate; + req.start_stop = 1; // start + req.req_stream_id = id; // id + + // send each one twice. + generatePacket(MAVLINK_MSG_ID_REQUEST_DATA_STREAM, req); + generatePacket(MAVLINK_MSG_ID_REQUEST_DATA_STREAM, req); + } + + /// + /// Returns WP count + /// + /// + public byte getWPCount() + { + MainV2.giveComport = true; + byte[] buffer; +#if MAVLINK10 + mavlink_mission_request_list_t req = new mavlink_mission_request_list_t(); + + req.target_system = sysid; + req.target_component = compid; + + // request list + generatePacket(MAVLINK_MSG_ID_MISSION_REQUEST_LIST, req); + + DateTime start = DateTime.Now; + int retrys = 6; + + while (true) + { + if (!(start.AddMilliseconds(500) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("getWPCount Retry " + retrys + " - giv com " + MainV2.giveComport); + generatePacket(MAVLINK_MSG_ID_MISSION_REQUEST_LIST, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + //return (byte)int.Parse(param["WP_TOTAL"].ToString()); + throw new Exception("Timeout on read - getWPCount"); + } + + buffer = readPacket(); + if (buffer.Length > 5) + { + if (buffer[5] == MAVLINK_MSG_ID_MISSION_COUNT) + { + + + + var count = buffer.ByteArrayToStructure(6); + + + log.Info("wpcount: " + count.count); + MainV2.giveComport = false; + return (byte)count.count; // should be ushort, but apm has limited wp count < byte + } + else + { + log.Info(DateTime.Now + " PC wpcount " + buffer[5] + " need " + MAVLINK_MSG_ID_MISSION_COUNT + " " + this.BaseStream.BytesToRead); + } + } + } +#else + + mavlink_waypoint_request_list_t req = new mavlink_waypoint_request_list_t(); + + req.target_system = sysid; + req.target_component = compid; + + // request list + generatePacket(MAVLINK_MSG_ID_WAYPOINT_REQUEST_LIST, req); + + DateTime start = DateTime.Now; + int retrys = 6; + + while (true) + { + if (!(start.AddMilliseconds(500) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("getWPCount Retry " + retrys + " - giv com " + MainV2.giveComport); + generatePacket(MAVLINK_MSG_ID_WAYPOINT_REQUEST_LIST, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + //return (byte)int.Parse(param["WP_TOTAL"].ToString()); + throw new Exception("Timeout on read - getWPCount"); + } + + buffer = readPacket(); + if (buffer.Length > 5) + { + if (buffer[5] == MAVLINK_MSG_ID_WAYPOINT_COUNT) + { + + log.Info("wpcount: " + buffer[9]); + MainV2.giveComport = false; + return buffer[9]; // should be ushort, but apm has limited wp count < byte + } + else + { + log.Info(DateTime.Now + " PC wpcount " + buffer[5] + " need " + MAVLINK_MSG_ID_WAYPOINT_COUNT + " " + this.BaseStream.BytesToRead); + } + } + } + +#endif + } + /// + /// Gets specfied WP + /// + /// + /// WP + public Locationwp getWP(ushort index) + { + MainV2.giveComport = true; + Locationwp loc = new Locationwp(); +#if MAVLINK10 + mavlink_mission_request_t req = new mavlink_mission_request_t(); + + req.target_system = sysid; + req.target_component = compid; + + req.seq = index; + + //Console.WriteLine("getwp req "+ DateTime.Now.Millisecond); + + // request + generatePacket(MAVLINK_MSG_ID_MISSION_REQUEST, req); + + DateTime start = DateTime.Now; + int retrys = 5; + + while (true) + { + if (!(start.AddMilliseconds(800) > DateTime.Now)) // apm times out after 1000ms + { + if (retrys > 0) + { + log.Info("getWP Retry " + retrys); + generatePacket(MAVLINK_MSG_ID_MISSION_REQUEST, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - getWP"); + } + //Console.WriteLine("getwp read " + DateTime.Now.Millisecond); + byte[] buffer = readPacket(); + //Console.WriteLine("getwp readend " + DateTime.Now.Millisecond); + if (buffer.Length > 5) + { + if (buffer[5] == MAVLINK_MSG_ID_MISSION_ITEM) + { + //Console.WriteLine("getwp ans " + DateTime.Now.Millisecond); + + + //Array.Copy(buffer, 6, buffer, 0, buffer.Length - 6); + + var wp = buffer.ByteArrayToStructure(6); + + +#else + + mavlink_waypoint_request_t req = new mavlink_waypoint_request_t(); + + req.target_system = sysid; + req.target_component = compid; + + req.seq = index; + + //Console.WriteLine("getwp req "+ DateTime.Now.Millisecond); + + // request + generatePacket(MAVLINK_MSG_ID_WAYPOINT_REQUEST, req); + + DateTime start = DateTime.Now; + int retrys = 5; + + while (true) + { + if (!(start.AddMilliseconds(800) > DateTime.Now)) // apm times out after 1000ms + { + if (retrys > 0) + { + log.Info("getWP Retry " + retrys); + generatePacket(MAVLINK_MSG_ID_WAYPOINT_REQUEST, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - getWP"); + } + //Console.WriteLine("getwp read " + DateTime.Now.Millisecond); + byte[] buffer = readPacket(); + //Console.WriteLine("getwp readend " + DateTime.Now.Millisecond); + if (buffer.Length > 5) + { + if (buffer[5] == MAVLINK_MSG_ID_WAYPOINT) + { + //Console.WriteLine("getwp ans " + DateTime.Now.Millisecond); + mavlink_waypoint_t wp = buffer.ByteArrayToStructure(6); + +#endif + + loc.options = (byte)(wp.frame & 0x1); + loc.id = (byte)(wp.command); + loc.p1 = (wp.param1); + loc.p2 = (wp.param2); + loc.p3 = (wp.param3); + loc.p4 = (wp.param4); + + loc.alt = ((wp.z)); + loc.lat = ((wp.x)); + loc.lng = ((wp.y)); + /* + if (MainV2.cs.firmware == MainV2.Firmwares.ArduPlane) + { + switch (loc.id) + { // Switch to map APM command fields inot MAVLink command fields + case (byte)MAV_CMD.LOITER_TURNS: + case (byte)MAV_CMD.TAKEOFF: + case (byte)MAV_CMD.DO_SET_HOME: + //case (byte)MAV_CMD.DO_SET_ROI: + loc.alt = (float)((wp.z)); + loc.lat = (float)((wp.x)); + loc.lng = (float)((wp.y)); + loc.p1 = (float)wp.param1; + break; + + case (byte)MAV_CMD.CONDITION_CHANGE_ALT: + loc.lat = (int)wp.param1; + loc.p1 = 0; + break; + + case (byte)MAV_CMD.LOITER_TIME: + if (MainV2.APMFirmware == MainV2.Firmwares.ArduPlane) + { + loc.p1 = (byte)(wp.param1 / 10); // APM loiter time is in ten second increments + } + else + { + loc.p1 = (byte)wp.param1; + } + break; + + case (byte)MAV_CMD.CONDITION_DELAY: + case (byte)MAV_CMD.CONDITION_DISTANCE: + loc.lat = (int)wp.param1; + break; + + case (byte)MAV_CMD.DO_JUMP: + loc.lat = (int)wp.param2; + loc.p1 = (byte)wp.param1; + break; + + case (byte)MAV_CMD.DO_REPEAT_SERVO: + loc.lng = (int)wp.param4; + goto case (byte)MAV_CMD.DO_CHANGE_SPEED; + case (byte)MAV_CMD.DO_REPEAT_RELAY: + case (byte)MAV_CMD.DO_CHANGE_SPEED: + loc.lat = (int)wp.param3; + loc.alt = (int)wp.param2; + loc.p1 = (byte)wp.param1; + break; + + case (byte)MAV_CMD.DO_SET_PARAMETER: + case (byte)MAV_CMD.DO_SET_RELAY: + case (byte)MAV_CMD.DO_SET_SERVO: + loc.alt = (int)wp.param2; + loc.p1 = (byte)wp.param1; + break; + + case (byte)MAV_CMD.WAYPOINT: + loc.p1 = (byte)wp.param1; + break; + } + } + */ + log.InfoFormat("getWP {0} {1} {2} {3} {4} opt {5}", loc.id, loc.p1, loc.alt, loc.lat, loc.lng, loc.options); + + break; + } + else + { + log.Info(DateTime.Now + " PC getwp " + buffer[5]); + } + } + } + MainV2.giveComport = false; + return loc; + } + + public object DebugPacket(byte[] datin) + { + string text = ""; + return DebugPacket(datin, ref text, true); + } + + public object DebugPacket(byte[] datin, bool PrintToConsole) + { + string text = ""; + return DebugPacket(datin, ref text, PrintToConsole); + } + + public object DebugPacket(byte[] datin, ref string text) + { + return DebugPacket(datin, ref text, true); + } + + /// + /// Print entire decoded packet to console + /// + /// packet byte array + /// struct of data + public object DebugPacket(byte[] datin, ref string text, bool PrintToConsole, string delimeter = " ") + { + string textoutput; + try + { + if (datin.Length > 5) + { + byte header = datin[0]; + byte length = datin[1]; + byte seq = datin[2]; + byte sysid = datin[3]; + byte compid = datin[4]; + byte messid = datin[5]; + + textoutput = string.Format("{0:X}{6}{1:X}{6}{2:X}{6}{3:X}{6}{4:X}{6}{5:X}{6}", header, length, seq, sysid, compid, messid, delimeter); + + object data = Activator.CreateInstance(MAVLINK_MESSAGE_INFO[messid]); + + MavlinkUtil.ByteArrayToStructure(datin, ref data, 6); + + 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; + byte[] crap = (byte[])fieldValue; + foreach (byte fiel in crap) + { + if (fiel == 0) + { + break; + } + else + { + textoutput = textoutput + (char)fiel; + } + } + textoutput = textoutput + delimeter; + } + else + { + textoutput = textoutput + field.Name + delimeter + fieldValue.ToString() + delimeter; + } + } + textoutput = textoutput + delimeter + "Len" + delimeter + datin.Length + "\r\n"; + if (PrintToConsole) + Console.Write(textoutput); + + if (text != null) + text = textoutput; + } + + return data; + } + } + catch { } + + return null; + } + + /// + /// Sets wp total count + /// + /// + public void setWPTotal(ushort wp_total) + { +#if MAVLINK10 + MainV2.giveComport = true; + mavlink_mission_count_t req = new mavlink_mission_count_t(); + + req.target_system = sysid; + req.target_component = compid; // MAVLINK_MSG_ID_MISSION_COUNT + + req.count = wp_total; + + generatePacket(MAVLINK_MSG_ID_MISSION_COUNT, req); + + DateTime start = DateTime.Now; + int retrys = 3; + + while (true) + { + if (!(start.AddMilliseconds(700) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("setWPTotal Retry " + retrys); + generatePacket(MAVLINK_MSG_ID_MISSION_COUNT, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - setWPTotal"); + } + byte[] buffer = readPacket(); + if (buffer.Length > 9) + { + if (buffer[5] == MAVLINK_MSG_ID_MISSION_REQUEST) + { + + + + var request = buffer.ByteArrayToStructure(6); + + if (request.seq == 0) + { + if (param["WP_TOTAL"] != null) + param["WP_TOTAL"] = (float)wp_total - 1; + if (param["CMD_TOTAL"] != null) + param["CMD_TOTAL"] = (float)wp_total - 1; + MainV2.giveComport = false; + return; + } + } + else + { + //Console.WriteLine(DateTime.Now + " PC getwp " + buffer[5]); + } + } + } +#else + MainV2.giveComport = true; + mavlink_waypoint_count_t req = new mavlink_waypoint_count_t(); + + req.target_system = sysid; + req.target_component = compid; // MAVLINK_MSG_ID_WAYPOINT_COUNT + + req.count = wp_total; + + generatePacket(MAVLINK_MSG_ID_WAYPOINT_COUNT, req); + + DateTime start = DateTime.Now; + int retrys = 3; + + while (true) + { + if (!(start.AddMilliseconds(700) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("setWPTotal Retry " + retrys); + generatePacket(MAVLINK_MSG_ID_WAYPOINT_COUNT, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - setWPTotal"); + } + byte[] buffer = readPacket(); + if (buffer.Length > 9) + { + if (buffer[5] == MAVLINK_MSG_ID_WAYPOINT_REQUEST) + { + mavlink_waypoint_request_t request = buffer.ByteArrayToStructure(6); + + if (request.seq == 0) + { + if (param["WP_TOTAL"] != null) + param["WP_TOTAL"] = (float)wp_total - 1; + if (param["CMD_TOTAL"] != null) + param["CMD_TOTAL"] = (float)wp_total - 1; + MainV2.giveComport = false; + return; + } + } + else + { + //Console.WriteLine(DateTime.Now + " PC getwp " + buffer[5]); + } + } + } + +#endif + } + + /// + /// Save wp to eeprom + /// + /// location struct + /// wp no + /// global or relative + /// 0 = no , 2 = guided mode + public void setWP(Locationwp loc, ushort index, MAV_FRAME frame, byte current) + { + MainV2.giveComport = true; +#if MAVLINK10 + mavlink_mission_item_t req = new mavlink_mission_item_t(); +#else + mavlink_waypoint_t req = new mavlink_waypoint_t(); +#endif + + req.target_system = sysid; + req.target_component = compid; // MAVLINK_MSG_ID_MISSION_ITEM + + req.command = loc.id; + req.param1 = loc.p1; + + req.current = current; + + req.frame = (byte)frame; + req.y = (float)(loc.lng); + req.x = (float)(loc.lat); + req.z = (float)(loc.alt); + + req.param1 = loc.p1; + req.param2 = loc.p2; + req.param3 = loc.p3; + req.param4 = loc.p4; + /* + if (MainV2.cs.firmware == MainV2.Firmwares.ArduPlane) + { + switch (loc.id) + { // Switch to map APM command fields inot MAVLink command fields + case (byte)MAV_CMD.LOITER_TURNS: + case (byte)MAV_CMD.TAKEOFF: + req.param1 = loc.p1; + break; + case (byte)MAV_CMD.DO_SET_HOME: + req.param1 = loc.p1; + break; + + case (byte)MAV_CMD.CONDITION_CHANGE_ALT: + req.param1 = loc.lat; + req.x = 0; + req.y = 0; + break; + + case (byte)MAV_CMD.LOITER_TIME: + req.param1 = loc.p1 * 10; // APM loiter time is in ten second increments + break; + + case (byte)MAV_CMD.CONDITION_DELAY: + case (byte)MAV_CMD.CONDITION_DISTANCE: + req.param1 = loc.lat; + break; + + case (byte)MAV_CMD.DO_JUMP: + req.param2 = loc.lat; + req.param1 = loc.p1; + break; + + case (byte)MAV_CMD.DO_REPEAT_SERVO: + req.param4 = loc.lng; + goto case (byte)MAV_CMD.DO_CHANGE_SPEED; + case (byte)MAV_CMD.DO_REPEAT_RELAY: + case (byte)MAV_CMD.DO_CHANGE_SPEED: + req.param3 = loc.lat; + req.param2 = loc.alt; + req.param1 = loc.p1; + break; + + case (byte)MAV_CMD.DO_SET_PARAMETER: + case (byte)MAV_CMD.DO_SET_RELAY: + case (byte)MAV_CMD.DO_SET_SERVO: + req.param2 = loc.alt; + req.param1 = loc.p1; + break; + } + } + */ + req.seq = index; + + log.InfoFormat("setWP {6} frame {0} cmd {1} p1 {2} x {3} y {4} z {5}", req.frame, req.command, req.param1, req.x, req.y, req.z, index); + + // request +#if MAVLINK10 + generatePacket(MAVLINK_MSG_ID_MISSION_ITEM, req); +#else + generatePacket(MAVLINK_MSG_ID_WAYPOINT, req); +#endif + + DateTime start = DateTime.Now; + int retrys = 6; + + while (true) + { + if (!(start.AddMilliseconds(500) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("setWP Retry " + retrys); +#if MAVLINK10 + generatePacket(MAVLINK_MSG_ID_MISSION_ITEM, req); +#else + generatePacket(MAVLINK_MSG_ID_WAYPOINT, req); +#endif + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - setWP"); + } + byte[] buffer = readPacket(); + if (buffer.Length > 5) + { +#if MAVLINK10 + if (buffer[5] == MAVLINK_MSG_ID_MISSION_ACK) + { + + + var ans = buffer.ByteArrayToStructure(6); + + + log.Info("set wp " + index + " ACK 47 : " + buffer[5] + " ans " + Enum.Parse(typeof(MAV_MISSION_RESULT), ans.type.ToString())); + break; + } + else if (buffer[5] == MAVLINK_MSG_ID_MISSION_REQUEST) + { + var ans = buffer.ByteArrayToStructure(6); + + + + + if (ans.seq == (index + 1)) + { + log.Info("set wp doing " + index + " req " + ans.seq + " REQ 40 : " + buffer[5]); + MainV2.giveComport = false; + break; + } + else + { + log.InfoFormat("set wp fail doing " + index + " req " + ans.seq + " ACK 47 or REQ 40 : " + buffer[5] + " seq {0} ts {1} tc {2}", req.seq, req.target_system, req.target_component); + //break; + } + } + else + { + //Console.WriteLine(DateTime.Now + " PC setwp " + buffer[5]); + } +#else + if (buffer[5] == MAVLINK_MSG_ID_WAYPOINT_ACK) + { //mavlink_waypoint_request_t + log.Info("set wp " + index + " ACK 47 : " + buffer[5]); + break; + } + else if (buffer[5] == MAVLINK_MSG_ID_WAYPOINT_REQUEST) + { + mavlink_waypoint_request_t ans = buffer.ByteArrayToStructure(6); + + if (ans.seq == (index + 1)) + { + log.Info("set wp doing " + index + " req " + ans.seq + " REQ 40 : " + buffer[5]); + MainV2.giveComport = false; + break; + } + else + { + log.InfoFormat("set wp fail doing " + index + " req " + ans.seq + " ACK 47 or REQ 40 : " + buffer[5] + " seq {0} ts {1} tc {2}", req.seq, req.target_system, req.target_component); + //break; + } + } + else + { + //Console.WriteLine(DateTime.Now + " PC setwp " + buffer[5]); + } +#endif + } + } + } + + public void setMountConfigure(MAV_MOUNT_MODE mountmode, bool stabroll, bool stabpitch, bool stabyaw) + { + mavlink_mount_configure_t req = new mavlink_mount_configure_t(); + + req.target_system = sysid; + req.target_component = compid; + req.mount_mode = (byte)mountmode; + req.stab_pitch = (stabpitch == true) ? (byte)1 : (byte)0; + req.stab_roll = (stabroll == true) ? (byte)1 : (byte)0; + req.stab_yaw = (stabyaw == true) ? (byte)1 : (byte)0; + + generatePacket(MAVLINK_MSG_ID_MOUNT_CONFIGURE, req); + System.Threading.Thread.Sleep(20); + generatePacket(MAVLINK_MSG_ID_MOUNT_CONFIGURE, req); + } + + public void setMountControl(double pa, double pb, double pc, bool islatlng) + { + mavlink_mount_control_t req = new mavlink_mount_control_t(); + + req.target_system = sysid; + req.target_component = compid; + if (!islatlng) + { + req.input_a = (int)pa; + req.input_b = (int)pb; + req.input_c = (int)pc; + } + else + { + req.input_a = (int)(pa * 10000000.0); + req.input_b = (int)(pb * 10000000.0); + req.input_c = (int)(pc * 100.0); + } + + generatePacket(MAVLINK_MSG_ID_MOUNT_CONTROL, req); + System.Threading.Thread.Sleep(20); + generatePacket(MAVLINK_MSG_ID_MOUNT_CONTROL, req); + } + + public void setMode(string modein) + { +#if MAVLINK10 + try + { + MAVLink.mavlink_set_mode_t mode = new MAVLink.mavlink_set_mode_t(); + + if (translateMode(modein, ref mode)) + { + generatePacket((byte)MAVLink.MAVLINK_MSG_ID_SET_MODE, mode); + System.Threading.Thread.Sleep(10); + generatePacket((byte)MAVLink.MAVLINK_MSG_ID_SET_MODE, mode); + } + } + catch { System.Windows.Forms.MessageBox.Show("Failed to change Modes"); } +#else + try + { + MAVLink.mavlink_set_nav_mode_t navmode = new MAVLink.mavlink_set_nav_mode_t(); + + MAVLink.mavlink_set_mode_t mode = new MAVLink.mavlink_set_mode_t(); + + if (translateMode(modein, ref navmode, ref mode)) + { + generatePacket((byte)MAVLink.MAVLINK_MSG_ID_SET_NAV_MODE, navmode); + System.Threading.Thread.Sleep(10); + generatePacket((byte)MAVLink.MAVLINK_MSG_ID_SET_MODE, mode); + System.Threading.Thread.Sleep(10); + generatePacket((byte)MAVLink.MAVLINK_MSG_ID_SET_NAV_MODE, navmode); + System.Threading.Thread.Sleep(10); + generatePacket((byte)MAVLink.MAVLINK_MSG_ID_SET_MODE, mode); + } + } + catch { System.Windows.Forms.CustomMessageBox.Show("Failed to change Modes"); } + +#endif + } + + /// + /// used for last bad serial characters + /// + byte[] lastbad = new byte[2]; + + /// + /// Serial Reader to read mavlink packets. POLL method + /// + /// + public byte[] readPacket() + { + byte[] temp = new byte[300]; + int count = 0; + int length = 0; + int readcount = 0; + lastbad = new byte[2]; + + BaseStream.ReadTimeout = 1200; // 1200 ms between chars - the gps detection requires this. + + DateTime start = DateTime.Now; + + try + { + // test fabs idea - http://diydrones.com/profiles/blogs/flying-with-joystick?commentId=705844%3AComment%3A818712&xg_source=msg_com_blogpost + if (BaseStream.IsOpen && BaseStream.BytesToWrite > 0) + { + // slow down execution. else 100% cpu + Thread.Sleep(1); + return new byte[0]; + } + } + catch (Exception ex) { log.Info(ex.ToString()); } + + lock (readlock) + { + + while (BaseStream.IsOpen || logreadmode) + { + try + { + if (readcount > 300) + { + log.Info("MAVLink readpacket No valid mavlink packets"); + break; + } + readcount++; + if (logreadmode) + { + try + { + if (logplaybackfile.BaseStream.Position == 0) + { + if (logplaybackfile.PeekChar() == '-') + { + oldlogformat = true; + } + else + { + oldlogformat = false; + } + } + } + catch { oldlogformat = false; } + + if (oldlogformat) + { + temp = readlogPacket(); //old style log + } + else + { + temp = readlogPacketMavlink(); + } + } + else + { + MainV2.cs.datetime = DateTime.Now; + + DateTime to = DateTime.Now.AddMilliseconds(BaseStream.ReadTimeout); + + while (BaseStream.BytesToRead <= 0) + { + if (DateTime.Now > to) + { + log.InfoFormat("MAVLINK: S wait time out btr {0} len {1}", BaseStream.BytesToRead, length); + throw new Exception("Timeout"); + } + System.Threading.Thread.Sleep(1); + } + if (BaseStream.IsOpen) + { + temp[count] = (byte)BaseStream.ReadByte(); + if (rawlogfile != null && rawlogfile.BaseStream.CanWrite) + rawlogfile.Write(temp[count]); + } + } + } + catch (Exception e) { log.Info("MAVLink readpacket read error: " + e.ToString()); break; } + + // check if looks like a mavlink packet and check for exclusions and write to console + if (temp[0] != 254 && temp[0] != 'U' || lastbad[0] == 'I' && lastbad[1] == 'M' || lastbad[1] == 'G' || lastbad[1] == 'A') // out of sync "AUTO" "GUIDED" "IMU" + { + if (temp[0] >= 0x20 && temp[0] <= 127 || temp[0] == '\n' || temp[0] == '\r') + { + TCPConsole.Write(temp[0]); + Console.Write((char)temp[0]); + } + _bytesReceivedSubj.OnNext(1); + count = 0; + lastbad[0] = lastbad[1]; + lastbad[1] = temp[0]; + temp[1] = 0; + continue; + } + // reset count on valid packet + readcount = 0; + + + if (temp[0] == 'U' || temp[0] == 254) + { + length = temp[1] + 6 + 2 - 2; // data + header + checksum - U - length + if (count >= 5 || logreadmode) + { + if (sysid != 0) + { + if (sysid != temp[3] || compid != temp[4]) + { + if (temp[3] == '3' && temp[4] == 'D') + { + // this is a 3dr radio rssi packet + } + else + { + log.InfoFormat("Mavlink Bad Packet (not addressed to this MAV) got {0} {1} vs {2} {3}", temp[3], temp[4], sysid, compid); + return new byte[0]; + } + } + } + + try + { + if (logreadmode) + { + + } + else + { + DateTime to = DateTime.Now.AddMilliseconds(BaseStream.ReadTimeout); + + while (BaseStream.BytesToRead < (length - 4)) + { + if (DateTime.Now > to) + { + log.InfoFormat("MAVLINK: L wait time out btr {0} len {1}", BaseStream.BytesToRead, length); + break; + } + //Console.WriteLine("data " + 0 + " " + length + " aval " + BaseStream.BytesToRead); + } + if (BaseStream.IsOpen) + { + int read = BaseStream.Read(temp, 6, length - 4); + if (rawlogfile != null && rawlogfile.BaseStream.CanWrite) + { + // write only what we read, temp is the whole packet, so 6-end + rawlogfile.Write(temp, 6, read); + rawlogfile.BaseStream.Flush(); + } + } + } + //Console.WriteLine("data " + read + " " + length + " aval " + this.BytesToRead); + count = length + 2; + } + catch { break; } + break; + } + } + + count++; + if (count == 299) + break; + } + }// end readlock + + Array.Resize(ref temp, count); + + _bytesReceivedSubj.OnNext(temp.Length); + + if (packetlosttimer.AddSeconds(5) < DateTime.Now) + { + packetlosttimer = DateTime.Now; + packetslost = (packetslost * 0.8f); + packetsnotlost = (packetsnotlost * 0.8f); + } + + MainV2.cs.linkqualitygcs = (ushort)((packetsnotlost / (packetsnotlost + packetslost)) * 100.0); + + if (bpstime.Second != DateTime.Now.Second && !logreadmode) + { + Console.Write("bps {0} loss {1} left {2} mem {3} \n", bps1, synclost, BaseStream.BytesToRead, System.GC.GetTotalMemory(false) / 1024 / 1024.0); + bps2 = bps1; // prev sec + bps1 = 0; // current sec + bpstime = DateTime.Now; + } + + bps1 += temp.Length; + + bps = (bps1 + bps2) / 2; + + if (temp.Length >= 5 && temp[3] == 255 && logreadmode) // gcs packet + { + getWPsfromstream(ref temp); + return temp;// new byte[0]; + } + + ushort crc = MavlinkCRC.crc_calculate(temp, temp.Length - 2); + + if (temp.Length > 5 && temp[0] == 254) + { + crc = MavlinkCRC.crc_accumulate(MAVLINK_MESSAGE_CRCS[temp[5]], crc); + } + + if (temp.Length > 5 && temp[1] != MAVLINK_MESSAGE_LENGTHS[temp[5]]) + { + if (MAVLINK_MESSAGE_LENGTHS[temp[5]] == 0) // pass for unknown packets + { + + } + else + { + log.InfoFormat("Mavlink Bad Packet (Len Fail) len {0} pkno {1}", temp.Length, temp[5]); +#if MAVLINK10 + if (temp.Length == 11 && temp[0] == 'U' && temp[5] == 0){ + string message ="Mavlink 0.9 Heartbeat, Please upgrade your AP, This planner is for Mavlink 1.0\n\n"; + System.Windows.Forms.CustomMessageBox.Show(message); + throw new Exception(message); + } +#else + if (temp.Length == 17 && temp[0] == 254 && temp[5] == 0) + { + string message = "Mavlink 1.0 Heartbeat, Please Upgrade your Mission Planner, This planner is for Mavlink 0.9\n\n"; + System.Windows.Forms.CustomMessageBox.Show(message); + throw new Exception(message); + } +#endif + return new byte[0]; + } + } + + if (temp.Length < 5 || temp[temp.Length - 1] != (crc >> 8) || temp[temp.Length - 2] != (crc & 0xff)) + { + int packetno = -1; + if (temp.Length > 5) + { + packetno = temp[5]; + } + log.InfoFormat("Mavlink Bad Packet (crc fail) len {0} crc {1} pkno {2}", temp.Length, crc, packetno); + return new byte[0]; + } + + try + { + if ((temp[0] == 'U' || temp[0] == 254) && temp.Length >= temp[1]) + { + if (temp[3] == '3' && temp[4] == 'D') + { + + } + else + { + byte packetSeqNo = temp[2]; + int expectedPacketSeqNo = ((recvpacketcount + 1) % 0x100); + + if (packetSeqNo != expectedPacketSeqNo) + { + synclost++; // actualy sync loss's + int numLost = 0; + + if (packetSeqNo < ((recvpacketcount + 1))) // recvpacketcount = 255 then 10 < 256 = true if was % 0x100 this would fail + { + numLost = 0x100 - expectedPacketSeqNo + packetSeqNo; + } + else + { + numLost = packetSeqNo - recvpacketcount; + } + packetslost += numLost; + WhenPacketLost.OnNext(numLost); + + log.InfoFormat("lost {0} pkts {1}", packetSeqNo, (int)packetslost); + } + + packetsnotlost++; + + recvpacketcount = packetSeqNo; + WhenPacketReceived.OnNext(1); + // Console.WriteLine(DateTime.Now.Millisecond); + } + + //MAVLINK_MSG_ID_GPS_STATUS + //if (temp[5] == MAVLINK_MSG_ID_GPS_STATUS) + + // Console.Write(temp[5] + " " + DateTime.Now.Millisecond + " " + packetspersecond[temp[5]] + " " + (DateTime.Now - packetspersecondbuild[temp[5]]).TotalMilliseconds + " \n"); + + if (double.IsInfinity(packetspersecond[temp[5]])) + packetspersecond[temp[5]] = 0; + + packetspersecond[temp[5]] = (((1000 / ((DateTime.Now - packetspersecondbuild[temp[5]]).TotalMilliseconds) + packetspersecond[temp[5]]) / 2)); + + packetspersecondbuild[temp[5]] = DateTime.Now; + + //Console.WriteLine("Packet {0}",temp[5]); + // store packet history + lock (objlock) + { + packets[temp[5]] = temp; + } + + if (debugmavlink) + DebugPacket(temp); + + if (temp[5] == MAVLink.MAVLINK_MSG_ID_STATUSTEXT) // status text + { + string logdata = Encoding.ASCII.GetString(temp, 7, temp.Length - 7); + int ind = logdata.IndexOf('\0'); + if (ind != -1) + logdata = logdata.Substring(0, ind); + log.Info(DateTime.Now + " " + logdata); + + if (MainV2.speechEngine != null && MainV2.config["speechenable"] != null && MainV2.config["speechenable"].ToString() == "True") + { + //MainV2.talk.SpeakAsync(logdata); + } + + } + + getWPsfromstream(ref temp); + + try + { + if (logfile != null && logfile.BaseStream.CanWrite) + { + lock (logwritelock) + { + byte[] datearray = BitConverter.GetBytes((UInt64)((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds * 1000)); //ASCIIEncoding.ASCII.GetBytes(DateTime.Now.ToBinary() + ":"); + Array.Reverse(datearray); + logfile.Write(datearray, 0, datearray.Length); + logfile.Write(temp, 0, temp.Length); + logfile.Flush(); + } + } + + } + catch { } + } + } + catch { } + + lastvalidpacket = DateTime.Now; + + // Console.Write((DateTime.Now - start).TotalMilliseconds.ToString("00.000") + "\t" + temp.Length + " \r"); + + return temp; + } + + /// + /// Used to extract mission from log file + /// + /// packet + void getWPsfromstream(ref byte[] buffer) + { +#if MAVLINK10 + if (buffer[5] == MAVLINK_MSG_ID_MISSION_COUNT) + { + // clear old + wps = new PointLatLngAlt[wps.Length]; + } + + if (buffer[5] == MAVLink.MAVLINK_MSG_ID_MISSION_ITEM) + { + mavlink_mission_item_t wp = buffer.ByteArrayToStructure(6); +#else + + if (buffer[5] == MAVLINK_MSG_ID_WAYPOINT_COUNT) + { + // clear old + wps = new PointLatLngAlt[wps.Length]; + } + + if (buffer[5] == MAVLink.MAVLINK_MSG_ID_WAYPOINT) + { + mavlink_waypoint_t wp = buffer.ByteArrayToStructure(6); + +#endif + wps[wp.seq] = new PointLatLngAlt(wp.x, wp.y, wp.z, wp.seq.ToString()); + } + } + + public PointLatLngAlt getFencePoint(int no, ref int total) + { + byte[] buffer; + + MainV2.giveComport = true; + + PointLatLngAlt plla = new PointLatLngAlt(); + mavlink_fence_fetch_point_t req = new mavlink_fence_fetch_point_t(); + + req.idx = (byte)no; + req.target_component = compid; + req.target_system = sysid; + + // request point + generatePacket(MAVLINK_MSG_ID_FENCE_FETCH_POINT, req); + + DateTime start = DateTime.Now; + int retrys = 3; + + while (true) + { + if (!(start.AddMilliseconds(500) > DateTime.Now)) + { + if (retrys > 0) + { + log.Info("getFencePoint Retry " + retrys + " - giv com " + MainV2.giveComport); + generatePacket(MAVLINK_MSG_ID_FENCE_FETCH_POINT, req); + start = DateTime.Now; + retrys--; + continue; + } + MainV2.giveComport = false; + throw new Exception("Timeout on read - getFencePoint"); + } + + buffer = readPacket(); + if (buffer.Length > 5) + { + if (buffer[5] == MAVLINK_MSG_ID_FENCE_POINT) + { + MainV2.giveComport = false; + + mavlink_fence_point_t fp = buffer.ByteArrayToStructure(6); + + plla.Lat = fp.lat; + plla.Lng = fp.lng; + plla.Tag = fp.idx.ToString(); + + total = fp.count; + + return plla; + } + } + } + } + + public bool setFencePoint(byte index, PointLatLngAlt plla, byte fencepointcount) + { + mavlink_fence_point_t fp = new mavlink_fence_point_t(); + + fp.idx = index; + fp.count = fencepointcount; + fp.lat = (float)plla.Lat; + fp.lng = (float)plla.Lng; + fp.target_component = compid; + fp.target_system = sysid; + + int retry = 3; + + while (retry > 0) + { + generatePacket(MAVLINK_MSG_ID_FENCE_POINT, fp); + int counttemp = 0; + PointLatLngAlt newfp = getFencePoint(fp.idx, ref counttemp); + + if (newfp.Lat == plla.Lat && newfp.Lng == fp.lng) + return true; + retry--; + } + + return false; + } + + byte[] readlogPacket() + { + byte[] temp = new byte[300]; + + sysid = 0; + + int a = 0; + while (a < temp.Length && logplaybackfile.BaseStream.Position != logplaybackfile.BaseStream.Length) + { + temp[a] = (byte)logplaybackfile.BaseStream.ReadByte(); + //Console.Write((char)temp[a]); + if (temp[a] == ':') + { + break; + } + a++; + if (temp[0] != '-') + { + a = 0; + } + } + + //Console.Write('\n'); + + //Encoding.ASCII.GetString(temp, 0, a); + string datestring = Encoding.ASCII.GetString(temp, 0, a); + //Console.WriteLine(datestring); + long date = Int64.Parse(datestring); + DateTime date1 = DateTime.FromBinary(date); + + lastlogread = date1; + + int length = 5; + a = 0; + while (a < length) + { + temp[a] = (byte)logplaybackfile.BaseStream.ReadByte(); + if (a == 1) + { + length = temp[1] + 6 + 2 + 1; + } + a++; + } + + return temp; + } + + byte[] readlogPacketMavlink() + { + byte[] temp = new byte[300]; + + sysid = 0; + + //byte[] datearray = BitConverter.GetBytes((ulong)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds); + + byte[] datearray = new byte[8]; + + logplaybackfile.BaseStream.Read(datearray, 0, datearray.Length); + + Array.Reverse(datearray); + + DateTime date1 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + + UInt64 dateint = BitConverter.ToUInt64(datearray, 0); + + date1 = date1.AddMilliseconds(dateint / 1000); + + lastlogread = date1.ToLocalTime(); + + MainV2.cs.datetime = lastlogread; + + int length = 5; + int a = 0; + while (a < length) + { + temp[a] = (byte)logplaybackfile.ReadByte(); + if (temp[0] != 'U' && temp[0] != 254) + { + log.InfoFormat("lost sync byte {0} pos {1}", temp[0], logplaybackfile.BaseStream.Position); + a = 0; + continue; + } + if (a == 1) + { + length = temp[1] + 6 + 2; // 6 header + 2 checksum + } + a++; + } + + // set ap type for log file playback + if (temp[5] == 0) { + mavlink_heartbeat_t hb = temp.ByteArrayToStructure(6); + + mavlinkversion = hb.mavlink_version; + aptype = (MAV_TYPE)hb.type; + } + + return temp; + } + + +#if MAVLINK10 + + public static bool translateMode(string modein, ref MAVLink.mavlink_set_mode_t mode) + { + //MAVLink09.mavlink_set_mode_t mode = new MAVLink09.mavlink_set_mode_t(); + mode.target_system = MainV2.comPort.sysid; + + try + { + if (Common.getModes() == typeof(Common.apmmodes)) + { + switch (EnumTranslator.GetValue(modein)) + { + case (int)Common.apmmodes.MANUAL: + case (int)Common.apmmodes.CIRCLE: + case (int)Common.apmmodes.STABILIZE: + case (int)Common.apmmodes.AUTO: + case (int)Common.apmmodes.RTL: + case (int)Common.apmmodes.LOITER: + case (int)Common.apmmodes.FLY_BY_WIRE_A: + case (int)Common.apmmodes.FLY_BY_WIRE_B: + mode.base_mode = (byte)MAVLink.MAV_MODE_FLAG.CUSTOM_MODE_ENABLED; + mode.custom_mode = (uint)EnumTranslator.GetValue(modein); + break; + default: + MessageBox.Show("No Mode Changed " + modein); + return false; + } + } + else if (Common.getModes() == typeof(Common.ac2modes)) + { + switch (EnumTranslator.GetValue(modein)) + { + case (int)Common.ac2modes.STABILIZE: + case (int)Common.ac2modes.AUTO: + case (int)Common.ac2modes.RTL: + case (int)Common.ac2modes.LOITER: + case (int)Common.ac2modes.ACRO: + case (int)Common.ac2modes.ALT_HOLD: + case (int)Common.ac2modes.CIRCLE: + case (int)Common.ac2modes.POSITION: + mode.base_mode = (byte)MAVLink.MAV_MODE_FLAG.CUSTOM_MODE_ENABLED; + mode.custom_mode = (uint)EnumTranslator.GetValue(modein); + break; + default: + MessageBox.Show("No Mode Changed " + modein); + return false; + } + } + } + catch { System.Windows.Forms.MessageBox.Show("Failed to find Mode"); return false; } + + return true; + } + +#else + public static bool translateMode(string modein, ref MAVLink.mavlink_set_nav_mode_t navmode, ref MAVLink.mavlink_set_mode_t mode) + { + + //MAVLink.mavlink_set_nav_mode_t navmode = new MAVLink.mavlink_set_nav_mode_t(); + navmode.target = MainV2.comPort.sysid; + navmode.nav_mode = 255; + + //MAVLink.mavlink_set_mode_t mode = new MAVLink.mavlink_set_mode_t(); + mode.target = MainV2.comPort.sysid; + + try + { + if (Common.getModes() == typeof(Common.apmmodes)) + { + switch (EnumTranslator.GetValue(modein)) + { + case (int)Common.apmmodes.MANUAL: + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_MANUAL; + break; + case (int)Common.apmmodes.GUIDED: + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_GUIDED; + break; + case (int)Common.apmmodes.STABILIZE: + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST1; + break; + // AUTO MODES + case (int)Common.apmmodes.AUTO: + navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_WAYPOINT; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; + break; + case (int)Common.apmmodes.RTL: + navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_RETURNING; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; + break; + case (int)Common.apmmodes.LOITER: + navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_LOITER; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; + break; + // FBW + case (int)Common.apmmodes.FLY_BY_WIRE_A: + navmode.nav_mode = (byte)1; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST2; + break; + case (int)Common.apmmodes.FLY_BY_WIRE_B: + navmode.nav_mode = (byte)2; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST2; + break; + default: + CustomMessageBox.Show("No Mode Changed " + modein); + return false; + } + } + else if (Common.getModes() == typeof(Common.aprovermodes)) + { + switch (EnumTranslator.GetValue(modein)) + { + case (int)Common.aprovermodes.MANUAL: + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_MANUAL; + break; + case (int)Common.aprovermodes.GUIDED: + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_GUIDED; + break; + case (int)Common.aprovermodes.LEARNING: + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST1; + break; + // AUTO MODES + case (int)Common.aprovermodes.AUTO: + navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_WAYPOINT; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; + break; + case (int)Common.aprovermodes.RTL: + navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_RETURNING; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; + break; + case (int)Common.aprovermodes.LOITER: + navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_LOITER; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; + break; + // FBW + case (int)Common.aprovermodes.FLY_BY_WIRE_A: + navmode.nav_mode = (byte)1; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST2; + break; + case (int)Common.aprovermodes.FLY_BY_WIRE_B: + navmode.nav_mode = (byte)2; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_TEST2; + break; + default: + CustomMessageBox.Show("No Mode Changed " + modein); + return false; + } + } + else if (Common.getModes() == typeof(Common.ac2modes)) + { + switch (EnumTranslator.GetValue(modein)) + { + case (int)Common.ac2modes.GUIDED: + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_GUIDED; + break; + case (int)Common.ac2modes.STABILIZE: + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_MANUAL; + break; + // AUTO MODES + case (int)Common.ac2modes.AUTO: + navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_WAYPOINT; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; + break; + case (int)Common.ac2modes.RTL: + navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_RETURNING; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; + break; + case (int)Common.ac2modes.LOITER: + navmode.nav_mode = (byte)MAVLink.MAV_NAV.MAV_NAV_LOITER; + mode.mode = (byte)MAVLink.MAV_MODE.MAV_MODE_AUTO; + break; + default: + CustomMessageBox.Show("No Mode Changed " + modein); + return false; + } + } + } + catch { System.Windows.Forms.CustomMessageBox.Show("Failed to find Mode"); return false; } + + return true; + } +#endif + +#if MAVLINK10 + public void setAPType() + { + switch (aptype) + { + case MAVLink.MAV_TYPE.FIXED_WING: + MainV2.cs.firmware = MainV2.Firmwares.ArduPlane; + break; + case MAVLink.MAV_TYPE.QUADROTOR: + MainV2.cs.firmware = MainV2.Firmwares.ArduCopter2; + break; + case MAVLink.MAV_TYPE.GROUND_ROVER: + MainV2.cs.firmware = MainV2.Firmwares.ArduRover; + break; + default: + break; + } + } +#else + public void setAPType() + { + switch (aptype) + { + case MAVLink.MAV_TYPE.MAV_FIXED_WING: + MainV2.cs.firmware = MainV2.Firmwares.ArduPlane; + break; + case MAVLink.MAV_TYPE.MAV_QUADROTOR: + MainV2.cs.firmware = MainV2.Firmwares.ArduCopter2; + break; + case MAVLink.MAV_TYPE.MAV_GROUND: + MainV2.cs.firmware = MainV2.Firmwares.ArduRover; + break; + default: + break; + } + } +#endif + } +} \ No newline at end of file diff --git a/Tools/ArdupilotMegaPlanner/Mavlink/MAVLinkTypes.cs b/Tools/ArdupilotMegaPlanner/Mavlink/MAVLinkTypes.cs new file mode 100644 index 0000000000..eb64c40fa6 --- /dev/null +++ b/Tools/ArdupilotMegaPlanner/Mavlink/MAVLinkTypes.cs @@ -0,0 +1,2376 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace ArdupilotMega +{ +#if MAVLINK10 + partial class MAVLink + { + public const string MAVLINK_BUILD_DATE = "Sun Apr 8 12:29:46 2012"; + public const string MAVLINK_WIRE_PROTOCOL_VERSION = "1.0"; + public const int MAVLINK_MAX_DIALECT_PAYLOAD_SIZE = 42; + + public const int MAVLINK_LITTLE_ENDIAN = 1; + public const int MAVLINK_BIG_ENDIAN = 0; + + public const byte MAVLINK_STX = 254; + + public const byte MAVLINK_ENDIAN = MAVLINK_LITTLE_ENDIAN; + + public const bool MAVLINK_ALIGNED_FIELDS = (1 == 1); + + public const byte MAVLINK_CRC_EXTRA = 1; + + public const bool MAVLINK_NEED_BYTE_SWAP = (MAVLINK_ENDIAN == MAVLINK_LITTLE_ENDIAN); + + public byte[] MAVLINK_MESSAGE_LENGTHS = new byte[] {9, 31, 12, 0, 14, 28, 3, 32, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 20, 2, 25, 23, 30, 101, 22, 26, 16, 14, 28, 32, 28, 28, 22, 22, 21, 6, 6, 37, 4, 4, 2, 2, 4, 2, 2, 3, 13, 12, 19, 17, 15, 15, 27, 25, 18, 18, 20, 20, 0, 0, 26, 0, 36, 0, 6, 4, 0, 21, 18, 0, 0, 0, 20, 0, 33, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 56, 42, 33, 0, 0, 0, 0, 0, 0, 0, 18, 32, 32, 20, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 8, 4, 12, 15, 13, 6, 15, 14, 0, 12, 3, 8, 28, 36, 3, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 30, 18, 18, 51, 9, 3}; + + public byte[] MAVLINK_MESSAGE_CRCS = new byte[] {50, 124, 137, 0, 237, 217, 104, 119, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0, 214, 159, 220, 168, 24, 23, 170, 144, 67, 115, 39, 246, 185, 104, 237, 244, 222, 212, 9, 254, 230, 28, 28, 132, 221, 232, 11, 153, 41, 39, 214, 223, 141, 33, 15, 3, 100, 24, 239, 238, 0, 0, 183, 0, 130, 0, 148, 21, 0, 52, 124, 0, 0, 0, 20, 0, 152, 143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 183, 63, 54, 0, 0, 0, 0, 0, 0, 0, 19, 102, 158, 208, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 134, 219, 208, 188, 84, 22, 19, 21, 134, 0, 78, 68, 189, 127, 42, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 204, 49, 170, 44, 83, 46, 247}; + + public Type[] MAVLINK_MESSAGE_INFO = new Type[] {typeof( mavlink_heartbeat_t ), typeof( mavlink_sys_status_t ), typeof( mavlink_system_time_t ), null, typeof( mavlink_ping_t ), typeof( mavlink_change_operator_control_t ), typeof( mavlink_change_operator_control_ack_t ), typeof( mavlink_auth_key_t ), null, null, null, typeof( mavlink_set_mode_t ), null, null, null, null, null, null, null, null, typeof( mavlink_param_request_read_t ), typeof( mavlink_param_request_list_t ), typeof( mavlink_param_value_t ), typeof( mavlink_param_set_t ), typeof( mavlink_gps_raw_int_t ), typeof( mavlink_gps_status_t ), typeof( mavlink_scaled_imu_t ), typeof( mavlink_raw_imu_t ), typeof( mavlink_raw_pressure_t ), typeof( mavlink_scaled_pressure_t ), typeof( mavlink_attitude_t ), typeof( mavlink_attitude_quaternion_t ), typeof( mavlink_local_position_ned_t ), typeof( mavlink_global_position_int_t ), typeof( mavlink_rc_channels_scaled_t ), typeof( mavlink_rc_channels_raw_t ), typeof( mavlink_servo_output_raw_t ), typeof( mavlink_mission_request_partial_list_t ), typeof( mavlink_mission_write_partial_list_t ), typeof( mavlink_mission_item_t ), typeof( mavlink_mission_request_t ), typeof( mavlink_mission_set_current_t ), typeof( mavlink_mission_current_t ), typeof( mavlink_mission_request_list_t ), typeof( mavlink_mission_count_t ), typeof( mavlink_mission_clear_all_t ), typeof( mavlink_mission_item_reached_t ), typeof( mavlink_mission_ack_t ), typeof( mavlink_set_gps_global_origin_t ), typeof( mavlink_gps_global_origin_t ), typeof( mavlink_set_local_position_setpoint_t ), typeof( mavlink_local_position_setpoint_t ), typeof( mavlink_global_position_setpoint_int_t ), typeof( mavlink_set_global_position_setpoint_int_t ), typeof( mavlink_safety_set_allowed_area_t ), typeof( mavlink_safety_allowed_area_t ), typeof( mavlink_set_roll_pitch_yaw_thrust_t ), typeof( mavlink_set_roll_pitch_yaw_speed_thrust_t ), typeof( mavlink_roll_pitch_yaw_thrust_setpoint_t ), typeof( mavlink_roll_pitch_yaw_speed_thrust_setpoint_t ), null, null, typeof( mavlink_nav_controller_output_t ), null, typeof( mavlink_state_correction_t ), null, typeof( mavlink_request_data_stream_t ), typeof( mavlink_data_stream_t ), null, typeof( mavlink_manual_control_t ), typeof( mavlink_rc_channels_override_t ), null, null, null, typeof( mavlink_vfr_hud_t ), null, typeof( mavlink_command_long_t ), typeof( mavlink_command_ack_t ), null, null, null, null, null, null, null, null, null, null, null, null, typeof( mavlink_hil_state_t ), typeof( mavlink_hil_controls_t ), typeof( mavlink_hil_rc_inputs_raw_t ), null, null, null, null, null, null, null, typeof( mavlink_optical_flow_t ), typeof( mavlink_global_vision_position_estimate_t ), typeof( mavlink_vision_position_estimate_t ), typeof( mavlink_vision_speed_estimate_t ), typeof( mavlink_vicon_position_estimate_t ), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, typeof( mavlink_sensor_offsets_t ), typeof( mavlink_set_mag_offsets_t ), typeof( mavlink_meminfo_t ), typeof( mavlink_ap_adc_t ), typeof( mavlink_digicam_configure_t ), typeof( mavlink_digicam_control_t ), typeof( mavlink_mount_configure_t ), typeof( mavlink_mount_control_t ), typeof( mavlink_mount_status_t ), null, typeof( mavlink_fence_point_t ), typeof( mavlink_fence_fetch_point_t ), typeof( mavlink_fence_status_t ), typeof( mavlink_ahrs_t ), typeof( mavlink_simstate_t ), typeof( mavlink_hwstatus_t ), typeof( mavlink_radio_t ), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, typeof( mavlink_memory_vect_t ), typeof( mavlink_debug_vect_t ), typeof( mavlink_named_value_float_t ), typeof( mavlink_named_value_int_t ), typeof( mavlink_statustext_t ), typeof( mavlink_debug_t ), typeof( mavlink_extended_message_t )}; + + public const byte MAVLINK_VERSION = 2; + + + /** @brief Enumeration of possible mount operation modes */ + public enum MAV_MOUNT_MODE + { + /// Load and keep safe position (Roll,Pitch,Yaw) from EEPROM and stop stabilization | + RETRACT=0, + /// Load and keep neutral position (Roll,Pitch,Yaw) from EEPROM. | + NEUTRAL=1, + /// Load neutral position and start MAVLink Roll,Pitch,Yaw control with stabilization | + MAVLINK_TARGETING=2, + /// Load neutral position and start RC Roll,Pitch,Yaw control with stabilization | + RC_TARGETING=3, + /// Load neutral position and start to point to Lat,Lon,Alt | + GPS_POINT=4, + /// | + ENUM_END=5, + + }; + + /** @brief */ + public enum MAV_CMD + { + /// Navigate to MISSION. |Hold time in decimal seconds. (ignored by fixed wing, time to stay at MISSION for rotary wing)| Acceptance radius in meters (if the sphere with this radius is hit, the MISSION counts as reached)| 0 to pass through the WP, if > 0 radius in meters to pass by WP. Positive value for clockwise orbit, negative value for counter-clockwise orbit. Allows trajectory control.| Desired yaw angle at MISSION (rotary wing)| Latitude| Longitude| Altitude| + WAYPOINT=16, + /// Loiter around this MISSION an unlimited amount of time |Empty| Empty| Radius around MISSION, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| + LOITER_UNLIM=17, + /// Loiter around this MISSION for X turns |Turns| Empty| Radius around MISSION, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| + LOITER_TURNS=18, + /// Loiter around this MISSION for X seconds |Seconds (decimal)| Empty| Radius around MISSION, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| + LOITER_TIME=19, + /// Return to launch location |Empty| Empty| Empty| Empty| Empty| Empty| Empty| + RETURN_TO_LAUNCH=20, + /// Land at location |Empty| Empty| Empty| Desired yaw angle.| Latitude| Longitude| Altitude| + LAND=21, + /// Takeoff from ground / hand |Minimum pitch (if airspeed sensor present), desired pitch without sensor| Empty| Empty| Yaw angle (if magnetometer present), ignored without magnetometer| Latitude| Longitude| Altitude| + TAKEOFF=22, + /// Sets the region of interest (ROI) for a sensor set or the vehicle itself. This can then be used by the vehicles control system to control the vehicle attitude and the attitude of various sensors such as cameras. |Region of intereset mode. (see MAV_ROI enum)| MISSION index/ target ID. (see MAV_ROI enum)| ROI index (allows a vehicle to manage multiple ROI's)| Empty| x the location of the fixed ROI (see MAV_FRAME)| y| z| + ROI=80, + /// Control autonomous path planning on the MAV. |0: Disable local obstacle avoidance / local path planning (without resetting map), 1: Enable local path planning, 2: Enable and reset local path planning| 0: Disable full path planning (without resetting map), 1: Enable, 2: Enable and reset map/occupancy grid, 3: Enable and reset planned route, but not occupancy grid| Empty| Yaw angle at goal, in compass degrees, [0..360]| Latitude/X of goal| Longitude/Y of goal| Altitude/Z of goal| + PATHPLANNING=81, + /// NOP - This command is only used to mark the upper limit of the NAV/ACTION commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| + LAST=95, + /// Delay mission state machine. |Delay in seconds (decimal)| Empty| Empty| Empty| Empty| Empty| Empty| + CONDITION_DELAY=112, + /// Ascend/descend at rate. Delay mission state machine until desired altitude reached. |Descent / Ascend rate (m/s)| Empty| Empty| Empty| Empty| Empty| Finish Altitude| + CONDITION_CHANGE_ALT=113, + /// Delay mission state machine until within desired distance of next NAV point. |Distance (meters)| Empty| Empty| Empty| Empty| Empty| Empty| + CONDITION_DISTANCE=114, + /// Reach a certain target angle. |target angle: [0-360], 0 is north| speed during yaw change:[deg per second]| direction: negative: counter clockwise, positive: clockwise [-1,1]| relative offset or absolute angle: [ 1,0]| Empty| Empty| Empty| + CONDITION_YAW=115, + /// NOP - This command is only used to mark the upper limit of the CONDITION commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| + CONDITION_LAST=159, + /// Set system mode. |Mode, as defined by ENUM MAV_MODE| Empty| Empty| Empty| Empty| Empty| Empty| + DO_SET_MODE=176, + /// Jump to the desired command in the mission list. Repeat this action only the specified number of times |Sequence number| Repeat count| Empty| Empty| Empty| Empty| Empty| + DO_JUMP=177, + /// Change speed and/or throttle set points. |Speed type (0=Airspeed, 1=Ground Speed)| Speed (m/s, -1 indicates no change)| Throttle ( Percent, -1 indicates no change)| Empty| Empty| Empty| Empty| + DO_CHANGE_SPEED=178, + /// Changes the home location either to the current location or a specified location. |Use current (1=use current location, 0=use specified location)| Empty| Empty| Empty| Latitude| Longitude| Altitude| + DO_SET_HOME=179, + /// Set a system parameter. Caution! Use of this command requires knowledge of the numeric enumeration value of the parameter. |Parameter number| Parameter value| Empty| Empty| Empty| Empty| Empty| + DO_SET_PARAMETER=180, + /// Set a relay to a condition. |Relay number| Setting (1=on, 0=off, others possible depending on system hardware)| Empty| Empty| Empty| Empty| Empty| + DO_SET_RELAY=181, + /// Cycle a relay on and off for a desired number of cyles with a desired period. |Relay number| Cycle count| Cycle time (seconds, decimal)| Empty| Empty| Empty| Empty| + DO_REPEAT_RELAY=182, + /// Set a servo to a desired PWM value. |Servo number| PWM (microseconds, 1000 to 2000 typical)| Empty| Empty| Empty| Empty| Empty| + DO_SET_SERVO=183, + /// Cycle a between its nominal setting and a desired PWM for a desired number of cycles with a desired period. |Servo number| PWM (microseconds, 1000 to 2000 typical)| Cycle count| Cycle time (seconds)| Empty| Empty| Empty| + DO_REPEAT_SERVO=184, + /// Control onboard camera system. |Camera ID (-1 for all)| Transmission: 0: disabled, 1: enabled compressed, 2: enabled raw| Transmission mode: 0: video stream, >0: single images every n seconds (decimal)| Recording: 0: disabled, 1: enabled compressed, 2: enabled raw| Empty| Empty| Empty| + DO_CONTROL_VIDEO=200, + /// Mission command to configure an on-board camera controller system. |Modes: P, TV, AV, M, Etc| Shutter speed: Divisor number for one second| Aperture: F stop number| ISO number e.g. 80, 100, 200, Etc| Exposure type enumerator| Command Identity| Main engine cut-off time before camera trigger in seconds/10 (0 means no cut-off)| + DO_DIGICAM_CONFIGURE=202, + /// Mission command to control an on-board camera controller system. |Session control e.g. show/hide lens| Zoom's absolute position| Zooming step value to offset zoom from the current position| Focus Locking, Unlocking or Re-locking| Shooting Command| Command Identity| Empty| + DO_DIGICAM_CONTROL=203, + /// Mission command to configure a camera or antenna mount |Mount operation mode (see MAV_MOUNT_MODE enum)| stabilize roll? (1 = yes, 0 = no)| stabilize pitch? (1 = yes, 0 = no)| stabilize yaw? (1 = yes, 0 = no)| Empty| Empty| Empty| + DO_MOUNT_CONFIGURE=204, + /// Mission command to control a camera or antenna mount |pitch(deg*100) or lat, depending on mount mode.| roll(deg*100) or lon depending on mount mode| yaw(deg*100) or alt (in cm) depending on mount mode| Empty| Empty| Empty| Empty| + DO_MOUNT_CONTROL=205, + /// NOP - This command is only used to mark the upper limit of the DO commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| + DO_LAST=240, + /// Trigger calibration. This command will be only accepted if in pre-flight mode. |Gyro calibration: 0: no, 1: yes| Magnetometer calibration: 0: no, 1: yes| Ground pressure: 0: no, 1: yes| Radio calibration: 0: no, 1: yes| Empty| Empty| Empty| + PREFLIGHT_CALIBRATION=241, + /// Set sensor offsets. This command will be only accepted if in pre-flight mode. |Sensor to adjust the offsets for: 0: gyros, 1: accelerometer, 2: magnetometer, 3: barometer, 4: optical flow| X axis offset (or generic dimension 1), in the sensor's raw units| Y axis offset (or generic dimension 2), in the sensor's raw units| Z axis offset (or generic dimension 3), in the sensor's raw units| Generic dimension 4, in the sensor's raw units| Generic dimension 5, in the sensor's raw units| Generic dimension 6, in the sensor's raw units| + PREFLIGHT_SET_SENSOR_OFFSETS=242, + /// Request storage of different parameter values and logs. This command will be only accepted if in pre-flight mode. |Parameter storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Mission storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Reserved| Reserved| Empty| Empty| Empty| + PREFLIGHT_STORAGE=245, + /// Request the reboot or shutdown of system components. |0: Do nothing for autopilot, 1: Reboot autopilot, 2: Shutdown autopilot.| 0: Do nothing for onboard computer, 1: Reboot onboard computer, 2: Shutdown onboard computer.| Reserved| Reserved| Empty| Empty| Empty| + PREFLIGHT_REBOOT_SHUTDOWN=246, + /// Hold / continue the current action |MAV_GOTO_DO_HOLD: hold MAV_GOTO_DO_CONTINUE: continue with next item in mission plan| MAV_GOTO_HOLD_AT_CURRENT_POSITION: Hold at current position MAV_GOTO_HOLD_AT_SPECIFIED_POSITION: hold at specified position| MAV_FRAME coordinate frame of hold point| Desired yaw angle in degrees| Latitude / X position| Longitude / Y position| Altitude / Z position| + OVERRIDE_GOTO=252, + /// start running a mission |first_item: the first mission item to run| last_item: the last mission item to run (after this item is run, the mission ends)| + MISSION_START=300, + /// | + ENUM_END=301, + + }; + + /** @brief */ + public enum FENCE_ACTION + { + /// Disable fenced mode | + NONE=0, + /// Switched to guided mode to return point (fence point 0) | + GUIDED=1, + /// | + ENUM_END=2, + + }; + + /** @brief */ + public enum FENCE_BREACH + { + /// No last fence breach | + NONE=0, + /// Breached minimum altitude | + MINALT=1, + /// Breached minimum altitude | + MAXALT=2, + /// Breached fence boundary | + BOUNDARY=3, + /// | + ENUM_END=4, + + }; + + + + /** @brief Micro air vehicle / autopilot classes. This identifies the individual model. */ + public enum MAV_AUTOPILOT + { + /// Generic autopilot, full support for everything | + GENERIC=0, + /// PIXHAWK autopilot, http://pixhawk.ethz.ch | + PIXHAWK=1, + /// SLUGS autopilot, http://slugsuav.soe.ucsc.edu | + SLUGS=2, + /// ArduPilotMega / ArduCopter, http://diydrones.com | + ARDUPILOTMEGA=3, + /// OpenPilot, http://openpilot.org | + OPENPILOT=4, + /// Generic autopilot only supporting simple waypoints | + GENERIC_WAYPOINTS_ONLY=5, + /// Generic autopilot supporting waypoints and other simple navigation commands | + GENERIC_WAYPOINTS_AND_SIMPLE_NAVIGATION_ONLY=6, + /// Generic autopilot supporting the full mission command set | + GENERIC_MISSION_FULL=7, + /// No valid autopilot, e.g. a GCS or other MAVLink component | + INVALID=8, + /// PPZ UAV - http://nongnu.org/paparazzi | + PPZ=9, + /// UAV Dev Board | + UDB=10, + /// FlexiPilot | + FP=11, + /// | + ENUM_END=12, + + }; + + /** @brief These flags encode the MAV mode. */ + public enum MAV_MODE_FLAG + { + /// 0b00000001 Reserved for future use. | + CUSTOM_MODE_ENABLED=1, + /// 0b00000010 system has a test mode enabled. This flag is intended for temporary system tests and should not be used for stable implementations. | + TEST_ENABLED=2, + /// 0b00000100 autonomous mode enabled, system finds its own goal positions. Guided flag can be set or not, depends on the actual implementation. | + AUTO_ENABLED=4, + /// 0b00001000 guided mode enabled, system flies MISSIONs / mission items. | + GUIDED_ENABLED=8, + /// 0b00010000 system stabilizes electronically its attitude (and optionally position). It needs however further control inputs to move around. | + STABILIZE_ENABLED=16, + /// 0b00100000 hardware in the loop simulation. All motors / actuators are blocked, but internal software is full operational. | + HIL_ENABLED=32, + /// 0b01000000 remote control input is enabled. | + MANUAL_INPUT_ENABLED=64, + /// 0b10000000 MAV safety set to armed. Motors are enabled / running / can start. Ready to fly. | + SAFETY_ARMED=128, + /// | + ENUM_END=129, + + }; + + /** @brief These values encode the bit positions of the decode position. These values can be used to read the value of a flag bit by combining the base_mode variable with AND with the flag position value. The result will be either 0 or 1, depending on if the flag is set or not. */ + public enum MAV_MODE_FLAG_DECODE_POSITION + { + /// Eighth bit: 00000001 | + CUSTOM_MODE=1, + /// Seventh bit: 00000010 | + TEST=2, + /// Sixt bit: 00000100 | + AUTO=4, + /// Fifth bit: 00001000 | + GUIDED=8, + /// Fourth bit: 00010000 | + STABILIZE=16, + /// Third bit: 00100000 | + HIL=32, + /// Second bit: 01000000 | + MANUAL=64, + /// First bit: 10000000 | + SAFETY=128, + /// | + ENUM_END=129, + + }; + + /** @brief Override command, pauses current mission execution and moves immediately to a position */ + public enum MAV_GOTO + { + /// Hold at the current position. | + DO_HOLD=0, + /// Continue with the next item in mission execution. | + DO_CONTINUE=1, + /// Hold at the current position of the system | + HOLD_AT_CURRENT_POSITION=2, + /// Hold at the position specified in the parameters of the DO_HOLD action | + HOLD_AT_SPECIFIED_POSITION=3, + /// | + ENUM_END=4, + + }; + + /** @brief These defines are predefined OR-combined mode flags. There is no need to use values from this enum, but it simplifies the use of the mode flags. Note that manual input is enabled in all modes as a safety override. */ + public enum MAV_MODE + { + /// System is not ready to fly, booting, calibrating, etc. No flag is set. | + PREFLIGHT=0, + /// System is allowed to be active, under manual (RC) control, no stabilization | + MANUAL_DISARMED=64, + /// UNDEFINED mode. This solely depends on the autopilot - use with caution, intended for developers only. | + TEST_DISARMED=66, + /// System is allowed to be active, under assisted RC control. | + STABILIZE_DISARMED=80, + /// System is allowed to be active, under autonomous control, manual setpoint | + GUIDED_DISARMED=88, + /// System is allowed to be active, under autonomous control and navigation (the trajectory is decided onboard and not pre-programmed by MISSIONs) | + AUTO_DISARMED=92, + /// System is allowed to be active, under manual (RC) control, no stabilization | + MANUAL_ARMED=192, + /// UNDEFINED mode. This solely depends on the autopilot - use with caution, intended for developers only. | + TEST_ARMED=194, + /// System is allowed to be active, under assisted RC control. | + STABILIZE_ARMED=208, + /// System is allowed to be active, under autonomous control, manual setpoint | + GUIDED_ARMED=216, + /// System is allowed to be active, under autonomous control and navigation (the trajectory is decided onboard and not pre-programmed by MISSIONs) | + AUTO_ARMED=220, + /// | + ENUM_END=221, + + }; + + /** @brief */ + public enum MAV_STATE + { + /// Uninitialized system, state is unknown. | + UNINIT=0, + /// System is booting up. | + BOOT=1, + /// System is calibrating and not flight-ready. | + CALIBRATING=2, + /// System is grounded and on standby. It can be launched any time. | + STANDBY=3, + /// System is active and might be already airborne. Motors are engaged. | + ACTIVE=4, + /// System is in a non-normal flight mode. It can however still navigate. | + CRITICAL=5, + /// System is in a non-normal flight mode. It lost control over parts or over the whole airframe. It is in mayday and going down. | + EMERGENCY=6, + /// System just initialized its power-down sequence, will shut down now. | + POWEROFF=7, + /// | + ENUM_END=8, + + }; + + /** @brief */ + public enum MAV_TYPE + { + /// Generic micro air vehicle. | + GENERIC=0, + /// Fixed wing aircraft. | + FIXED_WING=1, + /// Quadrotor | + QUADROTOR=2, + /// Coaxial helicopter | + COAXIAL=3, + /// Normal helicopter with tail rotor. | + HELICOPTER=4, + /// Ground installation | + ANTENNA_TRACKER=5, + /// Operator control unit / ground control station | + GCS=6, + /// Airship, controlled | + AIRSHIP=7, + /// Free balloon, uncontrolled | + FREE_BALLOON=8, + /// Rocket | + ROCKET=9, + /// Ground rover | + GROUND_ROVER=10, + /// Surface vessel, boat, ship | + SURFACE_BOAT=11, + /// Submarine | + SUBMARINE=12, + /// Hexarotor | + HEXAROTOR=13, + /// Octorotor | + OCTOROTOR=14, + /// Octorotor | + TRICOPTER=15, + /// Flapping wing | + FLAPPING_WING=16, + /// | + ENUM_END=17, + + }; + + /** @brief */ + public enum MAV_COMPONENT + { + /// | + MAV_COMP_ID_ALL=0, + /// | + MAV_COMP_ID_CAMERA=100, + /// | + MAV_COMP_ID_SERVO1=140, + /// | + MAV_COMP_ID_SERVO2=141, + /// | + MAV_COMP_ID_SERVO3=142, + /// | + MAV_COMP_ID_SERVO4=143, + /// | + MAV_COMP_ID_SERVO5=144, + /// | + MAV_COMP_ID_SERVO6=145, + /// | + MAV_COMP_ID_SERVO7=146, + /// | + MAV_COMP_ID_SERVO8=147, + /// | + MAV_COMP_ID_SERVO9=148, + /// | + MAV_COMP_ID_SERVO10=149, + /// | + MAV_COMP_ID_SERVO11=150, + /// | + MAV_COMP_ID_SERVO12=151, + /// | + MAV_COMP_ID_SERVO13=152, + /// | + MAV_COMP_ID_SERVO14=153, + /// | + MAV_COMP_ID_MAPPER=180, + /// | + MAV_COMP_ID_MISSIONPLANNER=190, + /// | + MAV_COMP_ID_PATHPLANNER=195, + /// | + MAV_COMP_ID_IMU=200, + /// | + MAV_COMP_ID_IMU_2=201, + /// | + MAV_COMP_ID_IMU_3=202, + /// | + MAV_COMP_ID_GPS=220, + /// | + MAV_COMP_ID_UDP_BRIDGE=240, + /// | + MAV_COMP_ID_UART_BRIDGE=241, + /// | + MAV_COMP_ID_SYSTEM_CONTROL=250, + /// | + ENUM_END=251, + + }; + + /** @brief */ + public enum MAV_FRAME + { + /// Global coordinate frame, WGS84 coordinate system. First value / x: latitude, second value / y: longitude, third value / z: positive altitude over mean sea level (MSL) | + GLOBAL=0, + /// Local coordinate frame, Z-up (x: north, y: east, z: down). | + LOCAL_NED=1, + /// NOT a coordinate frame, indicates a mission command. | + MISSION=2, + /// Global coordinate frame, WGS84 coordinate system, relative altitude over ground with respect to the home position. First value / x: latitude, second value / y: longitude, third value / z: positive altitude with 0 being at the altitude of the home location. | + GLOBAL_RELATIVE_ALT=3, + /// Local coordinate frame, Z-down (x: east, y: north, z: up) | + LOCAL_ENU=4, + /// | + ENUM_END=5, + + }; + + /** @brief */ + public enum MAVLINK_DATA_STREAM_TYPE + { + /// | + MAVLINK_DATA_STREAM_IMG_JPEG=1, + /// | + MAVLINK_DATA_STREAM_IMG_BMP=2, + /// | + MAVLINK_DATA_STREAM_IMG_RAW8U=3, + /// | + MAVLINK_DATA_STREAM_IMG_RAW32U=4, + /// | + MAVLINK_DATA_STREAM_IMG_PGM=5, + /// | + MAVLINK_DATA_STREAM_IMG_PNG=6, + /// | + ENUM_END=7, + + }; + + /** @brief Data stream IDs. A data stream is not a fixed set of messages, but rather a recommendation to the autopilot software. Individual autopilots may or may not obey the recommended messages. */ + public enum MAV_DATA_STREAM + { + /// Enable all data streams | + ALL=0, + /// Enable IMU_RAW, GPS_RAW, GPS_STATUS packets. | + RAW_SENSORS=1, + /// Enable GPS_STATUS, CONTROL_STATUS, AUX_STATUS | + EXTENDED_STATUS=2, + /// Enable RC_CHANNELS_SCALED, RC_CHANNELS_RAW, SERVO_OUTPUT_RAW | + RC_CHANNELS=3, + /// Enable ATTITUDE_CONTROLLER_OUTPUT, POSITION_CONTROLLER_OUTPUT, NAV_CONTROLLER_OUTPUT. | + RAW_CONTROLLER=4, + /// Enable LOCAL_POSITION, GLOBAL_POSITION/GLOBAL_POSITION_INT messages. | + POSITION=6, + /// Dependent on the autopilot | + EXTRA1=10, + /// Dependent on the autopilot | + EXTRA2=11, + /// Dependent on the autopilot | + EXTRA3=12, + /// | + ENUM_END=13, + + }; + + /** @brief The ROI (region of interest) for the vehicle. This can be be used by the vehicle for camera/vehicle attitude alignment (see MAV_CMD_NAV_ROI). */ + public enum MAV_ROI + { + /// No region of interest. | + NONE=0, + /// Point toward next MISSION. | + WPNEXT=1, + /// Point toward given MISSION. | + WPINDEX=2, + /// Point toward fixed location. | + LOCATION=3, + /// Point toward of given id. | + TARGET=4, + /// | + ENUM_END=5, + + }; + + /** @brief ACK / NACK / ERROR values as a result of MAV_CMDs and for mission item transmission. */ + public enum MAV_CMD_ACK + { + /// Command / mission item is ok. | + OK=1, + /// Generic error message if none of the other reasons fails or if no detailed error reporting is implemented. | + ERR_FAIL=2, + /// The system is refusing to accept this command from this source / communication partner. | + ERR_ACCESS_DENIED=3, + /// Command or mission item is not supported, other commands would be accepted. | + ERR_NOT_SUPPORTED=4, + /// The coordinate frame of this command / mission item is not supported. | + ERR_COORDINATE_FRAME_NOT_SUPPORTED=5, + /// The coordinate frame of this command is ok, but he coordinate values exceed the safety limits of this system. This is a generic error, please use the more specific error messages below if possible. | + ERR_COORDINATES_OUT_OF_RANGE=6, + /// The X or latitude value is out of range. | + ERR_X_LAT_OUT_OF_RANGE=7, + /// The Y or longitude value is out of range. | + ERR_Y_LON_OUT_OF_RANGE=8, + /// The Z or altitude value is out of range. | + ERR_Z_ALT_OUT_OF_RANGE=9, + /// | + ENUM_END=10, + + }; + + /** @brief type of a mavlink parameter */ + public enum MAV_VAR + { + /// 32 bit float | + FLOAT=0, + /// 8 bit unsigned integer | + UINT8=1, + /// 8 bit signed integer | + INT8=2, + /// 16 bit unsigned integer | + UINT16=3, + /// 16 bit signed integer | + INT16=4, + /// 32 bit unsigned integer | + UINT32=5, + /// 32 bit signed integer | + INT32=6, + /// | + ENUM_END=7, + + }; + + /** @brief result from a mavlink command */ + public enum MAV_RESULT + { + /// Command ACCEPTED and EXECUTED | + ACCEPTED=0, + /// Command TEMPORARY REJECTED/DENIED | + TEMPORARILY_REJECTED=1, + /// Command PERMANENTLY DENIED | + DENIED=2, + /// Command UNKNOWN/UNSUPPORTED | + UNSUPPORTED=3, + /// Command executed, but failed | + FAILED=4, + /// | + ENUM_END=5, + + }; + + /** @brief result in a mavlink mission ack */ + public enum MAV_MISSION_RESULT + { + /// mission accepted OK | + MAV_MISSION_ACCEPTED=0, + /// generic error / not accepting mission commands at all right now | + MAV_MISSION_ERROR=1, + /// coordinate frame is not supported | + MAV_MISSION_UNSUPPORTED_FRAME=2, + /// command is not supported | + MAV_MISSION_UNSUPPORTED=3, + /// mission item exceeds storage space | + MAV_MISSION_NO_SPACE=4, + /// one of the parameters has an invalid value | + MAV_MISSION_INVALID=5, + /// param1 has an invalid value | + MAV_MISSION_INVALID_PARAM1=6, + /// param2 has an invalid value | + MAV_MISSION_INVALID_PARAM2=7, + /// param3 has an invalid value | + MAV_MISSION_INVALID_PARAM3=8, + /// param4 has an invalid value | + MAV_MISSION_INVALID_PARAM4=9, + /// x/param5 has an invalid value | + MAV_MISSION_INVALID_PARAM5_X=10, + /// y/param6 has an invalid value | + MAV_MISSION_INVALID_PARAM6_Y=11, + /// param7 has an invalid value | + MAV_MISSION_INVALID_PARAM7=12, + /// received waypoint out of sequence | + MAV_MISSION_INVALID_SEQUENCE=13, + /// not accepting any mission commands from this communication partner | + MAV_MISSION_DENIED=14, + /// | + ENUM_END=15, + + }; + + + public const byte MAVLINK_MSG_ID_SENSOR_OFFSETS = 150; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=42)] + public struct mavlink_sensor_offsets_t + { + /// magnetic declination (radians) + public Single mag_declination; + /// raw pressure from barometer + public Int32 raw_press; + /// raw temperature from barometer + public Int32 raw_temp; + /// gyro X calibration + public Single gyro_cal_x; + /// gyro Y calibration + public Single gyro_cal_y; + /// gyro Z calibration + public Single gyro_cal_z; + /// accel X calibration + public Single accel_cal_x; + /// accel Y calibration + public Single accel_cal_y; + /// accel Z calibration + public Single accel_cal_z; + /// magnetometer X offset + public Int16 mag_ofs_x; + /// magnetometer Y offset + public Int16 mag_ofs_y; + /// magnetometer Z offset + public Int16 mag_ofs_z; + + }; + + + public const byte MAVLINK_MSG_ID_SET_MAG_OFFSETS = 151; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=8)] + public struct mavlink_set_mag_offsets_t + { + /// magnetometer X offset + public Int16 mag_ofs_x; + /// magnetometer Y offset + public Int16 mag_ofs_y; + /// magnetometer Z offset + public Int16 mag_ofs_z; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_MEMINFO = 152; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=4)] + public struct mavlink_meminfo_t + { + /// heap top + public UInt16 brkval; + /// free memory + public UInt16 freemem; + + }; + + + public const byte MAVLINK_MSG_ID_AP_ADC = 153; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=12)] + public struct mavlink_ap_adc_t + { + /// ADC output 1 + public UInt16 adc1; + /// ADC output 2 + public UInt16 adc2; + /// ADC output 3 + public UInt16 adc3; + /// ADC output 4 + public UInt16 adc4; + /// ADC output 5 + public UInt16 adc5; + /// ADC output 6 + public UInt16 adc6; + + }; + + + public const byte MAVLINK_MSG_ID_DIGICAM_CONFIGURE = 154; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=15)] + public struct mavlink_digicam_configure_t + { + /// Correspondent value to given extra_param + public Single extra_value; + /// Divisor number //e.g. 1000 means 1/1000 (0 means ignore) + public UInt16 shutter_speed; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Mode enumeration from 1 to N //P, TV, AV, M, Etc (0 means ignore) + public byte mode; + /// F stop number x 10 //e.g. 28 means 2.8 (0 means ignore) + public byte aperture; + /// ISO enumeration from 1 to N //e.g. 80, 100, 200, Etc (0 means ignore) + public byte iso; + /// Exposure type enumeration from 1 to N (0 means ignore) + public byte exposure_type; + /// Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once + public byte command_id; + /// Main engine cut-off time before camera trigger in seconds/10 (0 means no cut-off) + public byte engine_cut_off; + /// Extra parameters enumeration (0 means ignore) + public byte extra_param; + + }; + + + public const byte MAVLINK_MSG_ID_DIGICAM_CONTROL = 155; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=13)] + public struct mavlink_digicam_control_t + { + /// Correspondent value to given extra_param + public Single extra_value; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// 0: stop, 1: start or keep it up //Session control e.g. show/hide lens + public byte session; + /// 1 to N //Zoom's absolute position (0 means ignore) + public byte zoom_pos; + /// -100 to 100 //Zooming step value to offset zoom from the current position + public byte zoom_step; + /// 0: unlock focus or keep unlocked, 1: lock focus or keep locked, 3: re-lock focus + public byte focus_lock; + /// 0: ignore, 1: shot or start filming + public byte shot; + /// Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once + public byte command_id; + /// Extra parameters enumeration (0 means ignore) + public byte extra_param; + + }; + + + public const byte MAVLINK_MSG_ID_MOUNT_CONFIGURE = 156; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=6)] + public struct mavlink_mount_configure_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// mount operating mode (see MAV_MOUNT_MODE enum) + public byte mount_mode; + /// (1 = yes, 0 = no) + public byte stab_roll; + /// (1 = yes, 0 = no) + public byte stab_pitch; + /// (1 = yes, 0 = no) + public byte stab_yaw; + + }; + + + public const byte MAVLINK_MSG_ID_MOUNT_CONTROL = 157; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=15)] + public struct mavlink_mount_control_t + { + /// pitch(deg*100) or lat, depending on mount mode + public Int32 input_a; + /// roll(deg*100) or lon depending on mount mode + public Int32 input_b; + /// yaw(deg*100) or alt (in cm) depending on mount mode + public Int32 input_c; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// if "1" it will save current trimmed position on EEPROM (just valid for NEUTRAL and LANDING) + public byte save_position; + + }; + + + public const byte MAVLINK_MSG_ID_MOUNT_STATUS = 158; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=14)] + public struct mavlink_mount_status_t + { + /// pitch(deg*100) or lat, depending on mount mode + public Int32 pointing_a; + /// roll(deg*100) or lon depending on mount mode + public Int32 pointing_b; + /// yaw(deg*100) or alt (in cm) depending on mount mode + public Int32 pointing_c; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_FENCE_POINT = 160; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=12)] + public struct mavlink_fence_point_t + { + /// Latitude of point + public Single lat; + /// Longitude of point + public Single lng; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// point index (first point is 1, 0 is for return point) + public byte idx; + /// total number of points (for sanity checking) + public byte count; + + }; + + + public const byte MAVLINK_MSG_ID_FENCE_FETCH_POINT = 161; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_fence_fetch_point_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// point index (first point is 1, 0 is for return point) + public byte idx; + + }; + + + public const byte MAVLINK_MSG_ID_FENCE_STATUS = 162; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=8)] + public struct mavlink_fence_status_t + { + /// time of last breach in milliseconds since boot + public UInt32 breach_time; + /// number of fence breaches + public UInt16 breach_count; + /// 0 if currently inside fence, 1 if outside + public byte breach_status; + /// last breach type (see FENCE_BREACH_* enum) + public byte breach_type; + + }; + + + public const byte MAVLINK_MSG_ID_AHRS = 163; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=28)] + public struct mavlink_ahrs_t + { + /// X gyro drift estimate rad/s + public Single omegaIx; + /// Y gyro drift estimate rad/s + public Single omegaIy; + /// Z gyro drift estimate rad/s + public Single omegaIz; + /// average accel_weight + public Single accel_weight; + /// average renormalisation value + public Single renorm_val; + /// average error_roll_pitch value + public Single error_rp; + /// average error_yaw value + public Single error_yaw; + + }; + + + public const byte MAVLINK_MSG_ID_SIMSTATE = 164; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=36)] + public struct mavlink_simstate_t + { + /// Roll angle (rad) + public Single roll; + /// Pitch angle (rad) + public Single pitch; + /// Yaw angle (rad) + public Single yaw; + /// X acceleration m/s/s + public Single xacc; + /// Y acceleration m/s/s + public Single yacc; + /// Z acceleration m/s/s + public Single zacc; + /// Angular speed around X axis rad/s + public Single xgyro; + /// Angular speed around Y axis rad/s + public Single ygyro; + /// Angular speed around Z axis rad/s + public Single zgyro; + + }; + + + public const byte MAVLINK_MSG_ID_HWSTATUS = 165; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_hwstatus_t + { + /// board voltage (mV) + public UInt16 Vcc; + /// I2C error count + public byte I2Cerr; + + }; + + + public const byte MAVLINK_MSG_ID_RADIO = 166; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=9)] + public struct mavlink_radio_t + { + /// receive errors + public UInt16 rxerrors; + /// count of error corrected packets + public UInt16 fixedp; + /// local signal strength + public byte rssi; + /// remote signal strength + public byte remrssi; + /// how full the tx buffer is as a percentage + public byte txbuf; + /// background noise level + public byte noise; + /// remote background noise level + public byte remnoise; + + }; + + + public const byte MAVLINK_MSG_ID_HEARTBEAT = 0; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=9)] + public struct mavlink_heartbeat_t + { + /// Navigation mode bitfield, see MAV_AUTOPILOT_CUSTOM_MODE ENUM for some examples. This field is autopilot-specific. + public UInt32 custom_mode; + /// Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) + public byte type; + /// Autopilot type / class. defined in MAV_CLASS ENUM + public byte autopilot; + /// System mode bitfield, see MAV_MODE_FLAGS ENUM in mavlink/include/mavlink_types.h + public byte base_mode; + /// System status flag, see MAV_STATUS ENUM + public byte system_status; + /// MAVLink version + public byte mavlink_version; + + }; + + + public const byte MAVLINK_MSG_ID_SYS_STATUS = 1; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=31)] + public struct mavlink_sys_status_t + { + /// Bitmask showing which onboard controllers and sensors are present. Value of 0: not present. Value of 1: present. Indices: 0: 3D gyro, 1: 3D acc, 2: 3D mag, 3: absolute pressure, 4: differential pressure, 5: GPS, 6: optical flow, 7: computer vision position, 8: laser based position, 9: external ground-truth (Vicon or Leica). Controllers: 10: 3D angular rate control 11: attitude stabilization, 12: yaw position, 13: z/altitude control, 14: x/y position control, 15: motor outputs / control + public UInt32 onboard_control_sensors_present; + /// Bitmask showing which onboard controllers and sensors are enabled: Value of 0: not enabled. Value of 1: enabled. Indices: 0: 3D gyro, 1: 3D acc, 2: 3D mag, 3: absolute pressure, 4: differential pressure, 5: GPS, 6: optical flow, 7: computer vision position, 8: laser based position, 9: external ground-truth (Vicon or Leica). Controllers: 10: 3D angular rate control 11: attitude stabilization, 12: yaw position, 13: z/altitude control, 14: x/y position control, 15: motor outputs / control + public UInt32 onboard_control_sensors_enabled; + /// Bitmask showing which onboard controllers and sensors are operational or have an error: Value of 0: not enabled. Value of 1: enabled. Indices: 0: 3D gyro, 1: 3D acc, 2: 3D mag, 3: absolute pressure, 4: differential pressure, 5: GPS, 6: optical flow, 7: computer vision position, 8: laser based position, 9: external ground-truth (Vicon or Leica). Controllers: 10: 3D angular rate control 11: attitude stabilization, 12: yaw position, 13: z/altitude control, 14: x/y position control, 15: motor outputs / control + public UInt32 onboard_control_sensors_health; + /// Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000 + public UInt16 load; + /// Battery voltage, in millivolts (1 = 1 millivolt) + public UInt16 voltage_battery; + /// Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current + public Int16 current_battery; + /// Communication drops in percent, (0%: 0, 100%: 10'000), (UART, I2C, SPI, CAN), dropped packets on all links (packets that were corrupted on reception on the MAV) + public UInt16 drop_rate_comm; + /// Communication errors (UART, I2C, SPI, CAN), dropped packets on all links (packets that were corrupted on reception on the MAV) + public UInt16 errors_comm; + /// Autopilot-specific errors + public UInt16 errors_count1; + /// Autopilot-specific errors + public UInt16 errors_count2; + /// Autopilot-specific errors + public UInt16 errors_count3; + /// Autopilot-specific errors + public UInt16 errors_count4; + /// Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot estimate the remaining battery + public byte battery_remaining; + + }; + + + public const byte MAVLINK_MSG_ID_SYSTEM_TIME = 2; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=12)] + public struct mavlink_system_time_t + { + /// Timestamp of the master clock in microseconds since UNIX epoch. + public UInt64 time_unix_usec; + /// Timestamp of the component clock since boot time in milliseconds. + public UInt32 time_boot_ms; + + }; + + + public const byte MAVLINK_MSG_ID_PING = 4; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=14)] + public struct mavlink_ping_t + { + /// Unix timestamp in microseconds + public UInt64 time_usec; + /// PING sequence + public UInt32 seq; + /// 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system + public byte target_system; + /// 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL = 5; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=28)] + public struct mavlink_change_operator_control_t + { + /// System the GCS requests control for + public byte target_system; + /// 0: request control of this MAV, 1: Release control of this MAV + public byte control_request; + /// 0: key as plaintext, 1-255: future, different hashing/encryption variants. The GCS should in general use the safest mode possible initially and then gradually move down the encryption level if it gets a NACK message indicating an encryption mismatch. + public byte version; + /// Password / Key, depending on version plaintext or encrypted. 25 or less characters, NULL terminated. The characters may involve A-Z, a-z, 0-9, and "!?,.-" + [MarshalAs(UnmanagedType.ByValArray,SizeConst=25)] + public string passkey; + + }; + + + public const byte MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL_ACK = 6; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_change_operator_control_ack_t + { + /// ID of the GCS this message + public byte gcs_system_id; + /// 0: request control of this MAV, 1: Release control of this MAV + public byte control_request; + /// 0: ACK, 1: NACK: Wrong passkey, 2: NACK: Unsupported passkey encryption method, 3: NACK: Already under control + public byte ack; + + }; + + + public const byte MAVLINK_MSG_ID_AUTH_KEY = 7; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=32)] + public struct mavlink_auth_key_t + { + /// key + [MarshalAs(UnmanagedType.ByValArray,SizeConst=32)] + public string key; + + }; + + + public const byte MAVLINK_MSG_ID_SET_MODE = 11; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=6)] + public struct mavlink_set_mode_t + { + /// The new autopilot-specific mode. This field can be ignored by an autopilot. + public UInt32 custom_mode; + /// The system setting the mode + public byte target_system; + /// The new base mode + public byte base_mode; + + }; + + + public const byte MAVLINK_MSG_ID_PARAM_REQUEST_READ = 20; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=20)] + public struct mavlink_param_request_read_t + { + /// Parameter index. Send -1 to use the param ID field as identifier + public Int16 param_index; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Onboard parameter id + [MarshalAs(UnmanagedType.ByValArray,SizeConst=16)] + public string param_id; + + }; + + + public const byte MAVLINK_MSG_ID_PARAM_REQUEST_LIST = 21; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_param_request_list_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_PARAM_VALUE = 22; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=25)] + public struct mavlink_param_value_t + { + /// Onboard parameter value + public Single param_value; + /// Total number of onboard parameters + public UInt16 param_count; + /// Index of this onboard parameter + public UInt16 param_index; + /// Onboard parameter id + [MarshalAs(UnmanagedType.ByValArray,SizeConst=16)] + public byte[] param_id; + /// Onboard parameter type: see MAV_VAR enum + public byte param_type; + + }; + + + public const byte MAVLINK_MSG_ID_PARAM_SET = 23; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=23)] + public struct mavlink_param_set_t + { + /// Onboard parameter value + public Single param_value; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Onboard parameter id + [MarshalAs(UnmanagedType.ByValArray,SizeConst=16)] + public byte[] param_id; + /// Onboard parameter type: see MAV_VAR enum + public byte param_type; + + }; + + + public const byte MAVLINK_MSG_ID_GPS_RAW_INT = 24; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=30)] + public struct mavlink_gps_raw_int_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 time_usec; + /// Latitude in 1E7 degrees + public Int32 lat; + /// Longitude in 1E7 degrees + public Int32 lon; + /// Altitude in 1E3 meters (millimeters) above MSL + public Int32 alt; + /// GPS HDOP horizontal dilution of position in cm (m*100). If unknown, set to: 65535 + public UInt16 eph; + /// GPS VDOP horizontal dilution of position in cm (m*100). If unknown, set to: 65535 + public UInt16 epv; + /// GPS ground speed (m/s * 100). If unknown, set to: 65535 + public UInt16 vel; + /// Course over ground (NOT heading, but direction of movement) in degrees * 100, 0.0..359.99 degrees. If unknown, set to: 65535 + public UInt16 cog; + /// 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. + public byte fix_type; + /// Number of satellites visible. If unknown, set to 255 + public byte satellites_visible; + + }; + + + public const byte MAVLINK_MSG_ID_GPS_STATUS = 25; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=101)] + public struct mavlink_gps_status_t + { + /// Number of satellites visible + public byte satellites_visible; + /// Global satellite ID + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public byte[] satellite_prn; + /// 0: Satellite not used, 1: used for localization + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public byte[] satellite_used; + /// Elevation (0: right on top of receiver, 90: on the horizon) of satellite + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public byte[] satellite_elevation; + /// Direction of satellite, 0: 0 deg, 255: 360 deg. + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public byte[] satellite_azimuth; + /// Signal to noise ratio of satellite + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public byte[] satellite_snr; + + }; + + + public const byte MAVLINK_MSG_ID_SCALED_IMU = 26; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=22)] + public struct mavlink_scaled_imu_t + { + /// Timestamp (milliseconds since system boot) + public UInt32 time_boot_ms; + /// X acceleration (mg) + public Int16 xacc; + /// Y acceleration (mg) + public Int16 yacc; + /// Z acceleration (mg) + public Int16 zacc; + /// Angular speed around X axis (millirad /sec) + public Int16 xgyro; + /// Angular speed around Y axis (millirad /sec) + public Int16 ygyro; + /// Angular speed around Z axis (millirad /sec) + public Int16 zgyro; + /// X Magnetic field (milli tesla) + public Int16 xmag; + /// Y Magnetic field (milli tesla) + public Int16 ymag; + /// Z Magnetic field (milli tesla) + public Int16 zmag; + + }; + + + public const byte MAVLINK_MSG_ID_RAW_IMU = 27; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=26)] + public struct mavlink_raw_imu_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 time_usec; + /// X acceleration (raw) + public Int16 xacc; + /// Y acceleration (raw) + public Int16 yacc; + /// Z acceleration (raw) + public Int16 zacc; + /// Angular speed around X axis (raw) + public Int16 xgyro; + /// Angular speed around Y axis (raw) + public Int16 ygyro; + /// Angular speed around Z axis (raw) + public Int16 zgyro; + /// X Magnetic field (raw) + public Int16 xmag; + /// Y Magnetic field (raw) + public Int16 ymag; + /// Z Magnetic field (raw) + public Int16 zmag; + + }; + + + public const byte MAVLINK_MSG_ID_RAW_PRESSURE = 28; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=16)] + public struct mavlink_raw_pressure_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 time_usec; + /// Absolute pressure (raw) + public Int16 press_abs; + /// Differential pressure 1 (raw) + public Int16 press_diff1; + /// Differential pressure 2 (raw) + public Int16 press_diff2; + /// Raw Temperature measurement (raw) + public Int16 temperature; + + }; + + + public const byte MAVLINK_MSG_ID_SCALED_PRESSURE = 29; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=14)] + public struct mavlink_scaled_pressure_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt32 time_boot_ms; + /// Absolute pressure (hectopascal) + public Single press_abs; + /// Differential pressure 1 (hectopascal) + public Single press_diff; + /// Temperature measurement (0.01 degrees celsius) + public Int16 temperature; + + }; + + + public const byte MAVLINK_MSG_ID_ATTITUDE = 30; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=28)] + public struct mavlink_attitude_t + { + /// Timestamp (milliseconds since system boot) + public UInt32 time_boot_ms; + /// Roll angle (rad) + public Single roll; + /// Pitch angle (rad) + public Single pitch; + /// Yaw angle (rad) + public Single yaw; + /// Roll angular speed (rad/s) + public Single rollspeed; + /// Pitch angular speed (rad/s) + public Single pitchspeed; + /// Yaw angular speed (rad/s) + public Single yawspeed; + + }; + + + public const byte MAVLINK_MSG_ID_ATTITUDE_QUATERNION = 31; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=32)] + public struct mavlink_attitude_quaternion_t + { + /// Timestamp (milliseconds since system boot) + public UInt32 time_boot_ms; + /// Quaternion component 1 + public Single q1; + /// Quaternion component 2 + public Single q2; + /// Quaternion component 3 + public Single q3; + /// Quaternion component 4 + public Single q4; + /// Roll angular speed (rad/s) + public Single rollspeed; + /// Pitch angular speed (rad/s) + public Single pitchspeed; + /// Yaw angular speed (rad/s) + public Single yawspeed; + + }; + + + public const byte MAVLINK_MSG_ID_LOCAL_POSITION_NED = 32; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=28)] + public struct mavlink_local_position_ned_t + { + /// Timestamp (milliseconds since system boot) + public UInt32 time_boot_ms; + /// X Position + public Single x; + /// Y Position + public Single y; + /// Z Position + public Single z; + /// X Speed + public Single vx; + /// Y Speed + public Single vy; + /// Z Speed + public Single vz; + + }; + + + public const byte MAVLINK_MSG_ID_GLOBAL_POSITION_INT = 33; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=28)] + public struct mavlink_global_position_int_t + { + /// Timestamp (milliseconds since system boot) + public UInt32 time_boot_ms; + /// Latitude, expressed as * 1E7 + public Int32 lat; + /// Longitude, expressed as * 1E7 + public Int32 lon; + /// Altitude in meters, expressed as * 1000 (millimeters), above MSL + public Int32 alt; + /// Altitude above ground in meters, expressed as * 1000 (millimeters) + public Int32 relative_alt; + /// Ground X Speed (Latitude), expressed as m/s * 100 + public Int16 vx; + /// Ground Y Speed (Longitude), expressed as m/s * 100 + public Int16 vy; + /// Ground Z Speed (Altitude), expressed as m/s * 100 + public Int16 vz; + /// Compass heading in degrees * 100, 0.0..359.99 degrees. If unknown, set to: 65535 + public UInt16 hdg; + + }; + + + public const byte MAVLINK_MSG_ID_RC_CHANNELS_SCALED = 34; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=22)] + public struct mavlink_rc_channels_scaled_t + { + /// Timestamp (milliseconds since system boot) + public UInt32 time_boot_ms; + /// RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan1_scaled; + /// RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan2_scaled; + /// RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan3_scaled; + /// RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan4_scaled; + /// RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan5_scaled; + /// RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan6_scaled; + /// RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan7_scaled; + /// RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan8_scaled; + /// Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. + public byte port; + /// Receive signal strength indicator, 0: 0%, 255: 100% + public byte rssi; + + }; + + + public const byte MAVLINK_MSG_ID_RC_CHANNELS_RAW = 35; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=22)] + public struct mavlink_rc_channels_raw_t + { + /// Timestamp (milliseconds since system boot) + public UInt32 time_boot_ms; + /// RC channel 1 value, in microseconds + public UInt16 chan1_raw; + /// RC channel 2 value, in microseconds + public UInt16 chan2_raw; + /// RC channel 3 value, in microseconds + public UInt16 chan3_raw; + /// RC channel 4 value, in microseconds + public UInt16 chan4_raw; + /// RC channel 5 value, in microseconds + public UInt16 chan5_raw; + /// RC channel 6 value, in microseconds + public UInt16 chan6_raw; + /// RC channel 7 value, in microseconds + public UInt16 chan7_raw; + /// RC channel 8 value, in microseconds + public UInt16 chan8_raw; + /// Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. + public byte port; + /// Receive signal strength indicator, 0: 0%, 255: 100% + public byte rssi; + + }; + + + public const byte MAVLINK_MSG_ID_SERVO_OUTPUT_RAW = 36; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=21)] + public struct mavlink_servo_output_raw_t + { + /// Timestamp (since UNIX epoch or microseconds since system boot) + public UInt32 time_usec; + /// Servo output 1 value, in microseconds + public UInt16 servo1_raw; + /// Servo output 2 value, in microseconds + public UInt16 servo2_raw; + /// Servo output 3 value, in microseconds + public UInt16 servo3_raw; + /// Servo output 4 value, in microseconds + public UInt16 servo4_raw; + /// Servo output 5 value, in microseconds + public UInt16 servo5_raw; + /// Servo output 6 value, in microseconds + public UInt16 servo6_raw; + /// Servo output 7 value, in microseconds + public UInt16 servo7_raw; + /// Servo output 8 value, in microseconds + public UInt16 servo8_raw; + /// Servo output port (set of 8 outputs = 1 port). Most MAVs will just use one, but this allows to encode more than 8 servos. + public byte port; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_REQUEST_PARTIAL_LIST = 37; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=6)] + public struct mavlink_mission_request_partial_list_t + { + /// Start index, 0 by default + public Int16 start_index; + /// End index, -1 by default (-1: send list to end). Else a valid index of the list + public Int16 end_index; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_WRITE_PARTIAL_LIST = 38; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=6)] + public struct mavlink_mission_write_partial_list_t + { + /// Start index, 0 by default and smaller / equal to the largest index of the current onboard list. + public Int16 start_index; + /// End index, equal or greater than start index. + public Int16 end_index; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_ITEM = 39; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=37)] + public struct mavlink_mission_item_t + { + /// PARAM1 / For NAV command MISSIONs: Radius in which the MISSION is accepted as reached, in meters + public Single param1; + /// PARAM2 / For NAV command MISSIONs: Time that the MAV should stay inside the PARAM1 radius before advancing, in milliseconds + public Single param2; + /// PARAM3 / For LOITER command MISSIONs: Orbit to circle around the MISSION, in meters. If positive the orbit direction should be clockwise, if negative the orbit direction should be counter-clockwise. + public Single param3; + /// PARAM4 / For NAV and LOITER command MISSIONs: Yaw orientation in degrees, [0..360] 0 = NORTH + public Single param4; + /// PARAM5 / local: x position, global: latitude + public Single x; + /// PARAM6 / y position: global: longitude + public Single y; + /// PARAM7 / z position: global: altitude + public Single z; + /// Sequence + public UInt16 seq; + /// The scheduled action for the MISSION. see MAV_CMD in common.xml MAVLink specs + public UInt16 command; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// The coordinate system of the MISSION. see MAV_FRAME in mavlink_types.h + public byte frame; + /// false:0, true:1 + public byte current; + /// autocontinue to next wp + public byte autocontinue; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_REQUEST = 40; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=4)] + public struct mavlink_mission_request_t + { + /// Sequence + public UInt16 seq; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_SET_CURRENT = 41; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=4)] + public struct mavlink_mission_set_current_t + { + /// Sequence + public UInt16 seq; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_CURRENT = 42; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_mission_current_t + { + /// Sequence + public UInt16 seq; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_REQUEST_LIST = 43; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_mission_request_list_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_COUNT = 44; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=4)] + public struct mavlink_mission_count_t + { + /// Number of mission items in the sequence + public UInt16 count; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_CLEAR_ALL = 45; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_mission_clear_all_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_ITEM_REACHED = 46; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_mission_item_reached_t + { + /// Sequence + public UInt16 seq; + + }; + + + public const byte MAVLINK_MSG_ID_MISSION_ACK = 47; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_mission_ack_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// See MAV_MISSION_RESULT enum + public byte type; + + }; + + + public const byte MAVLINK_MSG_ID_SET_GPS_GLOBAL_ORIGIN = 48; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=13)] + public struct mavlink_set_gps_global_origin_t + { + /// global position * 1E7 + public Int32 latitude; + /// global position * 1E7 + public Int32 longitude; + /// global position * 1000 + public Int32 altitude; + /// System ID + public byte target_system; + + }; + + + public const byte MAVLINK_MSG_ID_GPS_GLOBAL_ORIGIN = 49; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=12)] + public struct mavlink_gps_global_origin_t + { + /// Latitude (WGS84), expressed as * 1E7 + public Int32 latitude; + /// Longitude (WGS84), expressed as * 1E7 + public Int32 longitude; + /// Altitude(WGS84), expressed as * 1000 + public Int32 altitude; + + }; + + + public const byte MAVLINK_MSG_ID_SET_LOCAL_POSITION_SETPOINT = 50; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=19)] + public struct mavlink_set_local_position_setpoint_t + { + /// x position + public Single x; + /// y position + public Single y; + /// z position + public Single z; + /// Desired yaw angle + public Single yaw; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Coordinate frame - valid values are only MAV_FRAME_LOCAL_NED or MAV_FRAME_LOCAL_ENU + public byte coordinate_frame; + + }; + + + public const byte MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT = 51; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=17)] + public struct mavlink_local_position_setpoint_t + { + /// x position + public Single x; + /// y position + public Single y; + /// z position + public Single z; + /// Desired yaw angle + public Single yaw; + /// Coordinate frame - valid values are only MAV_FRAME_LOCAL_NED or MAV_FRAME_LOCAL_ENU + public byte coordinate_frame; + + }; + + + public const byte MAVLINK_MSG_ID_GLOBAL_POSITION_SETPOINT_INT = 52; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=15)] + public struct mavlink_global_position_setpoint_int_t + { + /// WGS84 Latitude position in degrees * 1E7 + public Int32 latitude; + /// WGS84 Longitude position in degrees * 1E7 + public Int32 longitude; + /// WGS84 Altitude in meters * 1000 (positive for up) + public Int32 altitude; + /// Desired yaw angle in degrees * 100 + public Int16 yaw; + /// Coordinate frame - valid values are only MAV_FRAME_GLOBAL or MAV_FRAME_GLOBAL_RELATIVE_ALT + public byte coordinate_frame; + + }; + + + public const byte MAVLINK_MSG_ID_SET_GLOBAL_POSITION_SETPOINT_INT = 53; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=15)] + public struct mavlink_set_global_position_setpoint_int_t + { + /// WGS84 Latitude position in degrees * 1E7 + public Int32 latitude; + /// WGS84 Longitude position in degrees * 1E7 + public Int32 longitude; + /// WGS84 Altitude in meters * 1000 (positive for up) + public Int32 altitude; + /// Desired yaw angle in degrees * 100 + public Int16 yaw; + /// Coordinate frame - valid values are only MAV_FRAME_GLOBAL or MAV_FRAME_GLOBAL_RELATIVE_ALT + public byte coordinate_frame; + + }; + + + public const byte MAVLINK_MSG_ID_SAFETY_SET_ALLOWED_AREA = 54; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=27)] + public struct mavlink_safety_set_allowed_area_t + { + /// x position 1 / Latitude 1 + public Single p1x; + /// y position 1 / Longitude 1 + public Single p1y; + /// z position 1 / Altitude 1 + public Single p1z; + /// x position 2 / Latitude 2 + public Single p2x; + /// y position 2 / Longitude 2 + public Single p2y; + /// z position 2 / Altitude 2 + public Single p2z; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. + public byte frame; + + }; + + + public const byte MAVLINK_MSG_ID_SAFETY_ALLOWED_AREA = 55; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=25)] + public struct mavlink_safety_allowed_area_t + { + /// x position 1 / Latitude 1 + public Single p1x; + /// y position 1 / Longitude 1 + public Single p1y; + /// z position 1 / Altitude 1 + public Single p1z; + /// x position 2 / Latitude 2 + public Single p2x; + /// y position 2 / Longitude 2 + public Single p2y; + /// z position 2 / Altitude 2 + public Single p2z; + /// Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. + public byte frame; + + }; + + + public const byte MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_THRUST = 56; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_set_roll_pitch_yaw_thrust_t + { + /// Desired roll angle in radians + public Single roll; + /// Desired pitch angle in radians + public Single pitch; + /// Desired yaw angle in radians + public Single yaw; + /// Collective thrust, normalized to 0 .. 1 + public Single thrust; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_SPEED_THRUST = 57; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_set_roll_pitch_yaw_speed_thrust_t + { + /// Desired roll angular speed in rad/s + public Single roll_speed; + /// Desired pitch angular speed in rad/s + public Single pitch_speed; + /// Desired yaw angular speed in rad/s + public Single yaw_speed; + /// Collective thrust, normalized to 0 .. 1 + public Single thrust; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_ROLL_PITCH_YAW_THRUST_SETPOINT = 58; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=20)] + public struct mavlink_roll_pitch_yaw_thrust_setpoint_t + { + /// Timestamp in milliseconds since system boot + public UInt32 time_boot_ms; + /// Desired roll angle in radians + public Single roll; + /// Desired pitch angle in radians + public Single pitch; + /// Desired yaw angle in radians + public Single yaw; + /// Collective thrust, normalized to 0 .. 1 + public Single thrust; + + }; + + + public const byte MAVLINK_MSG_ID_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT = 59; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=20)] + public struct mavlink_roll_pitch_yaw_speed_thrust_setpoint_t + { + /// Timestamp in milliseconds since system boot + public UInt32 time_boot_ms; + /// Desired roll angular speed in rad/s + public Single roll_speed; + /// Desired pitch angular speed in rad/s + public Single pitch_speed; + /// Desired yaw angular speed in rad/s + public Single yaw_speed; + /// Collective thrust, normalized to 0 .. 1 + public Single thrust; + + }; + + + public const byte MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT = 62; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=26)] + public struct mavlink_nav_controller_output_t + { + /// Current desired roll in degrees + public Single nav_roll; + /// Current desired pitch in degrees + public Single nav_pitch; + /// Current altitude error in meters + public Single alt_error; + /// Current airspeed error in meters/second + public Single aspd_error; + /// Current crosstrack error on x-y plane in meters + public Single xtrack_error; + /// Current desired heading in degrees + public Int16 nav_bearing; + /// Bearing to current MISSION/target in degrees + public Int16 target_bearing; + /// Distance to active MISSION in meters + public UInt16 wp_dist; + + }; + + + public const byte MAVLINK_MSG_ID_STATE_CORRECTION = 64; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=36)] + public struct mavlink_state_correction_t + { + /// x position error + public Single xErr; + /// y position error + public Single yErr; + /// z position error + public Single zErr; + /// roll error (radians) + public Single rollErr; + /// pitch error (radians) + public Single pitchErr; + /// yaw error (radians) + public Single yawErr; + /// x velocity + public Single vxErr; + /// y velocity + public Single vyErr; + /// z velocity + public Single vzErr; + + }; + + + public const byte MAVLINK_MSG_ID_REQUEST_DATA_STREAM = 66; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=6)] + public struct mavlink_request_data_stream_t + { + /// The requested interval between two messages of this type + public UInt16 req_message_rate; + /// The target requested to send the message stream. + public byte target_system; + /// The target requested to send the message stream. + public byte target_component; + /// The ID of the requested data stream + public byte req_stream_id; + /// 1 to start sending, 0 to stop sending. + public byte start_stop; + + }; + + + public const byte MAVLINK_MSG_ID_DATA_STREAM = 67; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=4)] + public struct mavlink_data_stream_t + { + /// The requested interval between two messages of this type + public UInt16 message_rate; + /// The ID of the requested data stream + public byte stream_id; + /// 1 stream is enabled, 0 stream is stopped. + public byte on_off; + + }; + + + public const byte MAVLINK_MSG_ID_MANUAL_CONTROL = 69; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=21)] + public struct mavlink_manual_control_t + { + /// roll + public Single roll; + /// pitch + public Single pitch; + /// yaw + public Single yaw; + /// thrust + public Single thrust; + /// The system to be controlled + public byte target; + /// roll control enabled auto:0, manual:1 + public byte roll_manual; + /// pitch auto:0, manual:1 + public byte pitch_manual; + /// yaw auto:0, manual:1 + public byte yaw_manual; + /// thrust auto:0, manual:1 + public byte thrust_manual; + + }; + + + public const byte MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE = 70; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_rc_channels_override_t + { + /// RC channel 1 value, in microseconds + public UInt16 chan1_raw; + /// RC channel 2 value, in microseconds + public UInt16 chan2_raw; + /// RC channel 3 value, in microseconds + public UInt16 chan3_raw; + /// RC channel 4 value, in microseconds + public UInt16 chan4_raw; + /// RC channel 5 value, in microseconds + public UInt16 chan5_raw; + /// RC channel 6 value, in microseconds + public UInt16 chan6_raw; + /// RC channel 7 value, in microseconds + public UInt16 chan7_raw; + /// RC channel 8 value, in microseconds + public UInt16 chan8_raw; + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_VFR_HUD = 74; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=20)] + public struct mavlink_vfr_hud_t + { + /// Current airspeed in m/s + public Single airspeed; + /// Current ground speed in m/s + public Single groundspeed; + /// Current altitude (MSL), in meters + public Single alt; + /// Current climb rate in meters/second + public Single climb; + /// Current heading in degrees, in compass units (0..360, 0=north) + public Int16 heading; + /// Current throttle setting in integer percent, 0 to 100 + public UInt16 throttle; + + }; + + + public const byte MAVLINK_MSG_ID_COMMAND_LONG = 76; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=33)] + public struct mavlink_command_long_t + { + /// Parameter 1, as defined by MAV_CMD enum. + public Single param1; + /// Parameter 2, as defined by MAV_CMD enum. + public Single param2; + /// Parameter 3, as defined by MAV_CMD enum. + public Single param3; + /// Parameter 4, as defined by MAV_CMD enum. + public Single param4; + /// Parameter 5, as defined by MAV_CMD enum. + public Single param5; + /// Parameter 6, as defined by MAV_CMD enum. + public Single param6; + /// Parameter 7, as defined by MAV_CMD enum. + public Single param7; + /// Command ID, as defined by MAV_CMD enum. + public UInt16 command; + /// System which should execute the command + public byte target_system; + /// Component which should execute the command, 0 for all components + public byte target_component; + /// 0: First transmission of this command. 1-255: Confirmation transmissions (e.g. for kill command) + public byte confirmation; + + }; + + + public const byte MAVLINK_MSG_ID_COMMAND_ACK = 77; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_command_ack_t + { + /// Command ID, as defined by MAV_CMD enum. + public UInt16 command; + /// See MAV_RESULT enum + public byte result; + + }; + + + public const byte MAVLINK_MSG_ID_HIL_STATE = 90; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=56)] + public struct mavlink_hil_state_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 time_usec; + /// Roll angle (rad) + public Single roll; + /// Pitch angle (rad) + public Single pitch; + /// Yaw angle (rad) + public Single yaw; + /// Roll angular speed (rad/s) + public Single rollspeed; + /// Pitch angular speed (rad/s) + public Single pitchspeed; + /// Yaw angular speed (rad/s) + public Single yawspeed; + /// Latitude, expressed as * 1E7 + public Int32 lat; + /// Longitude, expressed as * 1E7 + public Int32 lon; + /// Altitude in meters, expressed as * 1000 (millimeters) + public Int32 alt; + /// Ground X Speed (Latitude), expressed as m/s * 100 + public Int16 vx; + /// Ground Y Speed (Longitude), expressed as m/s * 100 + public Int16 vy; + /// Ground Z Speed (Altitude), expressed as m/s * 100 + public Int16 vz; + /// X acceleration (mg) + public Int16 xacc; + /// Y acceleration (mg) + public Int16 yacc; + /// Z acceleration (mg) + public Int16 zacc; + + }; + + + public const byte MAVLINK_MSG_ID_HIL_CONTROLS = 91; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=42)] + public struct mavlink_hil_controls_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 time_usec; + /// Control output -1 .. 1 + public Single roll_ailerons; + /// Control output -1 .. 1 + public Single pitch_elevator; + /// Control output -1 .. 1 + public Single yaw_rudder; + /// Throttle 0 .. 1 + public Single throttle; + /// Aux 1, -1 .. 1 + public Single aux1; + /// Aux 2, -1 .. 1 + public Single aux2; + /// Aux 3, -1 .. 1 + public Single aux3; + /// Aux 4, -1 .. 1 + public Single aux4; + /// System mode (MAV_MODE) + public byte mode; + /// Navigation mode (MAV_NAV_MODE) + public byte nav_mode; + + }; + + + public const byte MAVLINK_MSG_ID_HIL_RC_INPUTS_RAW = 92; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=33)] + public struct mavlink_hil_rc_inputs_raw_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 time_usec; + /// RC channel 1 value, in microseconds + public UInt16 chan1_raw; + /// RC channel 2 value, in microseconds + public UInt16 chan2_raw; + /// RC channel 3 value, in microseconds + public UInt16 chan3_raw; + /// RC channel 4 value, in microseconds + public UInt16 chan4_raw; + /// RC channel 5 value, in microseconds + public UInt16 chan5_raw; + /// RC channel 6 value, in microseconds + public UInt16 chan6_raw; + /// RC channel 7 value, in microseconds + public UInt16 chan7_raw; + /// RC channel 8 value, in microseconds + public UInt16 chan8_raw; + /// RC channel 9 value, in microseconds + public UInt16 chan9_raw; + /// RC channel 10 value, in microseconds + public UInt16 chan10_raw; + /// RC channel 11 value, in microseconds + public UInt16 chan11_raw; + /// RC channel 12 value, in microseconds + public UInt16 chan12_raw; + /// Receive signal strength indicator, 0: 0%, 255: 100% + public byte rssi; + + }; + + + public const byte MAVLINK_MSG_ID_OPTICAL_FLOW = 100; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_optical_flow_t + { + /// Timestamp (UNIX) + public UInt64 time_usec; + /// Ground distance in meters + public Single ground_distance; + /// Flow in pixels in x-sensor direction + public Int16 flow_x; + /// Flow in pixels in y-sensor direction + public Int16 flow_y; + /// Sensor ID + public byte sensor_id; + /// Optical flow quality / confidence. 0: bad, 255: maximum quality + public byte quality; + + }; + + + public const byte MAVLINK_MSG_ID_GLOBAL_VISION_POSITION_ESTIMATE = 101; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=32)] + public struct mavlink_global_vision_position_estimate_t + { + /// Timestamp (milliseconds) + public UInt64 usec; + /// Global X position + public Single x; + /// Global Y position + public Single y; + /// Global Z position + public Single z; + /// Roll angle in rad + public Single roll; + /// Pitch angle in rad + public Single pitch; + /// Yaw angle in rad + public Single yaw; + + }; + + + public const byte MAVLINK_MSG_ID_VISION_POSITION_ESTIMATE = 102; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=32)] + public struct mavlink_vision_position_estimate_t + { + /// Timestamp (milliseconds) + public UInt64 usec; + /// Global X position + public Single x; + /// Global Y position + public Single y; + /// Global Z position + public Single z; + /// Roll angle in rad + public Single roll; + /// Pitch angle in rad + public Single pitch; + /// Yaw angle in rad + public Single yaw; + + }; + + + public const byte MAVLINK_MSG_ID_VISION_SPEED_ESTIMATE = 103; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=20)] + public struct mavlink_vision_speed_estimate_t + { + /// Timestamp (milliseconds) + public UInt64 usec; + /// Global X speed + public Single x; + /// Global Y speed + public Single y; + /// Global Z speed + public Single z; + + }; + + + public const byte MAVLINK_MSG_ID_VICON_POSITION_ESTIMATE = 104; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=32)] + public struct mavlink_vicon_position_estimate_t + { + /// Timestamp (milliseconds) + public UInt64 usec; + /// Global X position + public Single x; + /// Global Y position + public Single y; + /// Global Z position + public Single z; + /// Roll angle in rad + public Single roll; + /// Pitch angle in rad + public Single pitch; + /// Yaw angle in rad + public Single yaw; + + }; + + + public const byte MAVLINK_MSG_ID_MEMORY_VECT = 249; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=36)] + public struct mavlink_memory_vect_t + { + /// Starting address of the debug variables + public UInt16 address; + /// Version code of the type variable. 0=unknown, type ignored and assumed int16_t. 1=as below + public byte ver; + /// Type code of the memory variables. for ver = 1: 0=16 x int16_t, 1=16 x uint16_t, 2=16 x Q15, 3=16 x 1Q14 + public byte type; + /// Memory contents at specified address + [MarshalAs(UnmanagedType.ByValArray,SizeConst=32)] + public byte[] value; + + }; + + + public const byte MAVLINK_MSG_ID_DEBUG_VECT = 250; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=30)] + public struct mavlink_debug_vect_t + { + /// Timestamp + public UInt64 time_usec; + /// x + public Single x; + /// y + public Single y; + /// z + public Single z; + /// Name + [MarshalAs(UnmanagedType.ByValArray,SizeConst=10)] + public string name; + + }; + + + public const byte MAVLINK_MSG_ID_NAMED_VALUE_FLOAT = 251; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_named_value_float_t + { + /// Timestamp (milliseconds since system boot) + public UInt32 time_boot_ms; + /// Floating point value + public Single value; + /// Name of the debug variable + [MarshalAs(UnmanagedType.ByValArray,SizeConst=10)] + public string name; + + }; + + + public const byte MAVLINK_MSG_ID_NAMED_VALUE_INT = 252; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_named_value_int_t + { + /// Timestamp (milliseconds since system boot) + public UInt32 time_boot_ms; + /// Signed integer value + public Int32 value; + /// Name of the debug variable + [MarshalAs(UnmanagedType.ByValArray,SizeConst=10)] + public string name; + + }; + + + public const byte MAVLINK_MSG_ID_STATUSTEXT = 253; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=51)] + public struct mavlink_statustext_t + { + /// Severity of status, 0 = info message, 255 = critical fault + public byte severity; + /// Status text message, without null termination character + [MarshalAs(UnmanagedType.ByValArray,SizeConst=50)] + public string text; + + }; + + + public const byte MAVLINK_MSG_ID_DEBUG = 254; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=9)] + public struct mavlink_debug_t + { + /// Timestamp (milliseconds since system boot) + public UInt32 time_boot_ms; + /// DEBUG value + public Single value; + /// index of debug variable + public byte ind; + + }; + + + public const byte MAVLINK_MSG_ID_EXTENDED_MESSAGE = 255; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_extended_message_t + { + /// System which should execute the command + public byte target_system; + /// Component which should execute the command, 0 for all components + public byte target_component; + /// Retransmission / ACK flags + public byte protocol_flags; + + }; + + } +#endif +} diff --git a/Tools/ArdupilotMegaPlanner/Mavlink/MAVLinkTypes0.9.cs b/Tools/ArdupilotMegaPlanner/Mavlink/MAVLinkTypes0.9.cs new file mode 100644 index 0000000000..bd6d1276cc --- /dev/null +++ b/Tools/ArdupilotMegaPlanner/Mavlink/MAVLinkTypes0.9.cs @@ -0,0 +1,1836 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace ArdupilotMega +{ +#if !MAVLINK10 + partial class MAVLink + { + public const string MAVLINK_BUILD_DATE = "Sun Apr 8 12:29:41 2012"; + public const string MAVLINK_WIRE_PROTOCOL_VERSION = "0.9"; + public const int MAVLINK_MAX_DIALECT_PAYLOAD_SIZE = 42; + + public const int MAVLINK_LITTLE_ENDIAN = 1; + public const int MAVLINK_BIG_ENDIAN = 0; + + public const byte MAVLINK_STX = 85; + + public const byte MAVLINK_ENDIAN = MAVLINK_BIG_ENDIAN; + + public const bool MAVLINK_ALIGNED_FIELDS = (0 == 1); + + public const byte MAVLINK_CRC_EXTRA = 0; + + public const bool MAVLINK_NEED_BYTE_SWAP = (MAVLINK_ENDIAN == MAVLINK_LITTLE_ENDIAN); + + public byte[] MAVLINK_MESSAGE_LENGTHS = new byte[] {3, 4, 8, 14, 8, 28, 3, 32, 0, 2, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 19, 2, 23, 21, 0, 37, 26, 101, 26, 16, 32, 32, 37, 32, 11, 17, 17, 16, 18, 36, 4, 4, 2, 2, 4, 2, 2, 3, 14, 12, 18, 16, 8, 27, 25, 18, 18, 24, 24, 0, 0, 0, 26, 16, 36, 5, 6, 56, 26, 21, 18, 0, 0, 18, 20, 20, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 8, 4, 12, 15, 13, 6, 15, 14, 0, 12, 3, 8, 28, 36, 3, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 14, 14, 51, 5}; + + public byte[] MAVLINK_MESSAGE_CRCS = new byte[] {72, 39, 190, 92, 191, 217, 104, 119, 0, 219, 60, 186, 10, 0, 0, 0, 0, 0, 0, 0, 89, 159, 162, 121, 0, 149, 222, 110, 179, 136, 66, 126, 185, 147, 112, 252, 162, 215, 229, 128, 9, 106, 101, 213, 4, 229, 21, 214, 215, 14, 206, 50, 157, 126, 108, 213, 95, 5, 127, 0, 0, 0, 57, 126, 130, 119, 193, 191, 236, 158, 143, 0, 0, 104, 123, 131, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 174, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 143, 29, 208, 188, 118, 242, 19, 97, 233, 0, 18, 68, 136, 127, 42, 21, 93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 178, 224, 60, 106, 7}; + + public Type[] MAVLINK_MESSAGE_INFO = new Type[] {typeof( mavlink_heartbeat_t ), typeof( mavlink_boot_t ), typeof( mavlink_system_time_t ), typeof( mavlink_ping_t ), typeof( mavlink_system_time_utc_t ), typeof( mavlink_change_operator_control_t ), typeof( mavlink_change_operator_control_ack_t ), typeof( mavlink_auth_key_t ), null, typeof( mavlink_action_ack_t ), typeof( mavlink_action_t ), typeof( mavlink_set_mode_t ), typeof( mavlink_set_nav_mode_t ), null, null, null, null, null, null, null, typeof( mavlink_param_request_read_t ), typeof( mavlink_param_request_list_t ), typeof( mavlink_param_value_t ), typeof( mavlink_param_set_t ), null, typeof( mavlink_gps_raw_int_t ), typeof( mavlink_scaled_imu_t ), typeof( mavlink_gps_status_t ), typeof( mavlink_raw_imu_t ), typeof( mavlink_raw_pressure_t ), typeof( mavlink_attitude_t ), typeof( mavlink_local_position_t ), typeof( mavlink_gps_raw_t ), typeof( mavlink_global_position_t ), typeof( mavlink_sys_status_t ), typeof( mavlink_rc_channels_raw_t ), typeof( mavlink_rc_channels_scaled_t ), typeof( mavlink_servo_output_raw_t ), typeof( mavlink_scaled_pressure_t ), typeof( mavlink_waypoint_t ), typeof( mavlink_waypoint_request_t ), typeof( mavlink_waypoint_set_current_t ), typeof( mavlink_waypoint_current_t ), typeof( mavlink_waypoint_request_list_t ), typeof( mavlink_waypoint_count_t ), typeof( mavlink_waypoint_clear_all_t ), typeof( mavlink_waypoint_reached_t ), typeof( mavlink_waypoint_ack_t ), typeof( mavlink_gps_set_global_origin_t ), typeof( mavlink_gps_local_origin_set_t ), typeof( mavlink_local_position_setpoint_set_t ), typeof( mavlink_local_position_setpoint_t ), typeof( mavlink_control_status_t ), typeof( mavlink_safety_set_allowed_area_t ), typeof( mavlink_safety_allowed_area_t ), typeof( mavlink_set_roll_pitch_yaw_thrust_t ), typeof( mavlink_set_roll_pitch_yaw_speed_thrust_t ), typeof( mavlink_roll_pitch_yaw_thrust_setpoint_t ), typeof( mavlink_roll_pitch_yaw_speed_thrust_setpoint_t ), null, null, null, typeof( mavlink_nav_controller_output_t ), typeof( mavlink_position_target_t ), typeof( mavlink_state_correction_t ), typeof( mavlink_set_altitude_t ), typeof( mavlink_request_data_stream_t ), typeof( mavlink_hil_state_t ), typeof( mavlink_hil_controls_t ), typeof( mavlink_manual_control_t ), typeof( mavlink_rc_channels_override_t ), null, null, typeof( mavlink_global_position_int_t ), typeof( mavlink_vfr_hud_t ), typeof( mavlink_command_t ), typeof( mavlink_command_ack_t ), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, typeof( mavlink_optical_flow_t ), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, typeof( mavlink_object_detection_event_t ), null, null, null, null, null, null, null, null, null, typeof( mavlink_sensor_offsets_t ), typeof( mavlink_set_mag_offsets_t ), typeof( mavlink_meminfo_t ), typeof( mavlink_ap_adc_t ), typeof( mavlink_digicam_configure_t ), typeof( mavlink_digicam_control_t ), typeof( mavlink_mount_configure_t ), typeof( mavlink_mount_control_t ), typeof( mavlink_mount_status_t ), null, typeof( mavlink_fence_point_t ), typeof( mavlink_fence_fetch_point_t ), typeof( mavlink_fence_status_t ), typeof( mavlink_ahrs_t ), typeof( mavlink_simstate_t ), typeof( mavlink_hwstatus_t ), typeof( mavlink_radio_t ), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, typeof( mavlink_debug_vect_t ), typeof( mavlink_named_value_float_t ), typeof( mavlink_named_value_int_t ), typeof( mavlink_statustext_t ), typeof( mavlink_debug_t )}; + + public const byte MAVLINK_VERSION = 2; + + + /** @brief Enumeration of possible mount operation modes */ + public enum MAV_MOUNT_MODE + { + /// Load and keep safe position (Roll,Pitch,Yaw) from EEPROM and stop stabilization | + RETRACT=0, + /// Load and keep neutral position (Roll,Pitch,Yaw) from EEPROM. | + NEUTRAL=1, + /// Load neutral position and start MAVLink Roll,Pitch,Yaw control with stabilization | + MAVLINK_TARGETING=2, + /// Load neutral position and start RC Roll,Pitch,Yaw control with stabilization | + RC_TARGETING=3, + /// Load neutral position and start to point to Lat,Lon,Alt | + GPS_POINT=4, + /// | + ENUM_END=5, + + }; + + /** @brief */ + public enum MAV_CMD + { + /// Navigate to waypoint. |Hold time in decimal seconds. (ignored by fixed wing, time to stay at waypoint for rotary wing)| Acceptance radius in meters (if the sphere with this radius is hit, the waypoint counts as reached)| 0 to pass through the WP, if > 0 radius in meters to pass by WP. Positive value for clockwise orbit, negative value for counter-clockwise orbit. Allows trajectory control.| Desired yaw angle at waypoint (rotary wing)| Latitude| Longitude| Altitude| + WAYPOINT=16, + /// Loiter around this waypoint an unlimited amount of time |Empty| Empty| Radius around waypoint, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| + LOITER_UNLIM=17, + /// Loiter around this waypoint for X turns |Turns| Empty| Radius around waypoint, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| + LOITER_TURNS=18, + /// Loiter around this waypoint for X seconds |Seconds (decimal)| Empty| Radius around waypoint, in meters. If positive loiter clockwise, else counter-clockwise| Desired yaw angle.| Latitude| Longitude| Altitude| + LOITER_TIME=19, + /// Return to launch location |Empty| Empty| Empty| Empty| Empty| Empty| Empty| + RETURN_TO_LAUNCH=20, + /// Land at location |Empty| Empty| Empty| Desired yaw angle.| Latitude| Longitude| Altitude| + LAND=21, + /// Takeoff from ground / hand |Minimum pitch (if airspeed sensor present), desired pitch without sensor| Empty| Empty| Yaw angle (if magnetometer present), ignored without magnetometer| Latitude| Longitude| Altitude| + TAKEOFF=22, + /// Sets the region of interest (ROI) for a sensor set or the vehicle itself. This can then be used by the vehicles control system to control the vehicle attitude and the attitude of various sensors such as cameras. |Region of intereset mode. (see MAV_ROI enum)| Waypoint index/ target ID. (see MAV_ROI enum)| ROI index (allows a vehicle to manage multiple ROI's)| Empty| x the location of the fixed ROI (see MAV_FRAME)| y| z| + ROI=80, + /// Control autonomous path planning on the MAV. |0: Disable local obstacle avoidance / local path planning (without resetting map), 1: Enable local path planning, 2: Enable and reset local path planning| 0: Disable full path planning (without resetting map), 1: Enable, 2: Enable and reset map/occupancy grid, 3: Enable and reset planned route, but not occupancy grid| Empty| Yaw angle at goal, in compass degrees, [0..360]| Latitude/X of goal| Longitude/Y of goal| Altitude/Z of goal| + PATHPLANNING=81, + /// NOP - This command is only used to mark the upper limit of the NAV/ACTION commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| + LAST=95, + /// Delay mission state machine. |Delay in seconds (decimal)| Empty| Empty| Empty| Empty| Empty| Empty| + CONDITION_DELAY=112, + /// Ascend/descend at rate. Delay mission state machine until desired altitude reached. |Descent / Ascend rate (m/s)| Empty| Empty| Empty| Empty| Empty| Finish Altitude| + CONDITION_CHANGE_ALT=113, + /// Delay mission state machine until within desired distance of next NAV point. |Distance (meters)| Empty| Empty| Empty| Empty| Empty| Empty| + CONDITION_DISTANCE=114, + /// Reach a certain target angle. |target angle: [0-360], 0 is north| speed during yaw change:[deg per second]| direction: negative: counter clockwise, positive: clockwise [-1,1]| relative offset or absolute angle: [ 1,0]| Empty| Empty| Empty| + CONDITION_YAW=115, + /// NOP - This command is only used to mark the upper limit of the CONDITION commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| + CONDITION_LAST=159, + /// Set system mode. |Mode, as defined by ENUM MAV_MODE| Empty| Empty| Empty| Empty| Empty| Empty| + DO_SET_MODE=176, + /// Jump to the desired command in the mission list. Repeat this action only the specified number of times |Sequence number| Repeat count| Empty| Empty| Empty| Empty| Empty| + DO_JUMP=177, + /// Change speed and/or throttle set points. |Speed type (0=Airspeed, 1=Ground Speed)| Speed (m/s, -1 indicates no change)| Throttle ( Percent, -1 indicates no change)| Empty| Empty| Empty| Empty| + DO_CHANGE_SPEED=178, + /// Changes the home location either to the current location or a specified location. |Use current (1=use current location, 0=use specified location)| Empty| Empty| Empty| Latitude| Longitude| Altitude| + DO_SET_HOME=179, + /// Set a system parameter. Caution! Use of this command requires knowledge of the numeric enumeration value of the parameter. |Parameter number| Parameter value| Empty| Empty| Empty| Empty| Empty| + DO_SET_PARAMETER=180, + /// Set a relay to a condition. |Relay number| Setting (1=on, 0=off, others possible depending on system hardware)| Empty| Empty| Empty| Empty| Empty| + DO_SET_RELAY=181, + /// Cycle a relay on and off for a desired number of cyles with a desired period. |Relay number| Cycle count| Cycle time (seconds, decimal)| Empty| Empty| Empty| Empty| + DO_REPEAT_RELAY=182, + /// Set a servo to a desired PWM value. |Servo number| PWM (microseconds, 1000 to 2000 typical)| Empty| Empty| Empty| Empty| Empty| + DO_SET_SERVO=183, + /// Cycle a between its nominal setting and a desired PWM for a desired number of cycles with a desired period. |Servo number| PWM (microseconds, 1000 to 2000 typical)| Cycle count| Cycle time (seconds)| Empty| Empty| Empty| + DO_REPEAT_SERVO=184, + /// Control onboard camera capturing. |Camera ID (-1 for all)| Transmission: 0: disabled, 1: enabled compressed, 2: enabled raw| Transmission mode: 0: video stream, >0: single images every n seconds (decimal)| Recording: 0: disabled, 1: enabled compressed, 2: enabled raw| Empty| Empty| Empty| + DO_CONTROL_VIDEO=200, + /// Sets the region of interest (ROI) for a sensor set or the vehicle itself. This can then be used by the vehicles control system to control the vehicle attitude and the attitude of various devices such as cameras. |Region of interest mode. (see MAV_ROI enum)| Waypoint index/ target ID. (see MAV_ROI enum)| ROI index (allows a vehicle to manage multiple cameras etc.)| Empty| x the location of the fixed ROI (see MAV_FRAME)| y| z| + DO_SET_ROI=201, + /// Mission command to configure an on-board camera controller system. |Modes: P, TV, AV, M, Etc| Shutter speed: Divisor number for one second| Aperture: F stop number| ISO number e.g. 80, 100, 200, Etc| Exposure type enumerator| Command Identity| Main engine cut-off time before camera trigger in seconds/10 (0 means no cut-off)| + DO_DIGICAM_CONFIGURE=202, + /// Mission command to control an on-board camera controller system. |Session control e.g. show/hide lens| Zoom's absolute position| Zooming step value to offset zoom from the current position| Focus Locking, Unlocking or Re-locking| Shooting Command| Command Identity| Empty| + DO_DIGICAM_CONTROL=203, + /// Mission command to configure a camera or antenna mount |Mount operation mode (see MAV_MOUNT_MODE enum)| stabilize roll? (1 = yes, 0 = no)| stabilize pitch? (1 = yes, 0 = no)| stabilize yaw? (1 = yes, 0 = no)| Empty| Empty| Empty| + DO_MOUNT_CONFIGURE=204, + /// Mission command to control a camera or antenna mount |pitch(deg*100) or lat, depending on mount mode.| roll(deg*100) or lon depending on mount mode| yaw(deg*100) or alt (in cm) depending on mount mode| Empty| Empty| Empty| Empty| + DO_MOUNT_CONTROL=205, + /// NOP - This command is only used to mark the upper limit of the DO commands in the enumeration |Empty| Empty| Empty| Empty| Empty| Empty| Empty| + DO_LAST=240, + /// Trigger calibration. This command will be only accepted if in pre-flight mode. |Gyro calibration: 0: no, 1: yes| Magnetometer calibration: 0: no, 1: yes| Ground pressure: 0: no, 1: yes| Radio calibration: 0: no, 1: yes| Empty| Empty| Empty| + PREFLIGHT_CALIBRATION=241, + /// Request storage of different parameter values and logs. This command will be only accepted if in pre-flight mode. |Parameter storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Mission storage: 0: READ FROM FLASH/EEPROM, 1: WRITE CURRENT TO FLASH/EEPROM| Reserved| Reserved| Empty| Empty| Empty| + PREFLIGHT_STORAGE=245, + /// | + ENUM_END=246, + + }; + + /** @brief */ + public enum FENCE_ACTION + { + /// Disable fenced mode | + NONE=0, + /// Switched to guided mode to return point (fence point 0) | + GUIDED=1, + /// | + ENUM_END=2, + + }; + + /** @brief */ + public enum FENCE_BREACH + { + /// No last fence breach | + NONE=0, + /// Breached minimum altitude | + MINALT=1, + /// Breached minimum altitude | + MAXALT=2, + /// Breached fence boundary | + BOUNDARY=3, + /// | + ENUM_END=4, + + }; + + + + /** @brief Data stream IDs. A data stream is not a fixed set of messages, but rather a recommendation to the autopilot software. Individual autopilots may or may not obey the recommended messages. */ + public enum MAV_DATA_STREAM + { + /// Enable all data streams | + ALL=0, + /// Enable IMU_RAW, GPS_RAW, GPS_STATUS packets. | + RAW_SENSORS=1, + /// Enable GPS_STATUS, CONTROL_STATUS, AUX_STATUS | + EXTENDED_STATUS=2, + /// Enable RC_CHANNELS_SCALED, RC_CHANNELS_RAW, SERVO_OUTPUT_RAW | + RC_CHANNELS=3, + /// Enable ATTITUDE_CONTROLLER_OUTPUT, POSITION_CONTROLLER_OUTPUT, NAV_CONTROLLER_OUTPUT. | + RAW_CONTROLLER=4, + /// Enable LOCAL_POSITION, GLOBAL_POSITION/GLOBAL_POSITION_INT messages. | + POSITION=6, + /// Dependent on the autopilot | + EXTRA1=10, + /// Dependent on the autopilot | + EXTRA2=11, + /// Dependent on the autopilot | + EXTRA3=12, + /// | + ENUM_END=13, + + }; + + /** @brief The ROI (region of interest) for the vehicle. This can be be used by the vehicle for camera/vehicle attitude alignment (see MAV_CMD_NAV_ROI). */ + public enum MAV_ROI + { + /// No region of interest. | + NONE=0, + /// Point toward next waypoint. | + WPNEXT=1, + /// Point toward given waypoint. | + WPINDEX=2, + /// Point toward fixed location. | + LOCATION=3, + /// Point toward of given id. | + TARGET=4, + /// | + ENUM_END=5, + + }; + + + public const byte MAVLINK_MSG_ID_SENSOR_OFFSETS = 150; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=42)] + public struct mavlink_sensor_offsets_t + { + /// magnetometer X offset + public Int16 mag_ofs_x; + /// magnetometer Y offset + public Int16 mag_ofs_y; + /// magnetometer Z offset + public Int16 mag_ofs_z; + /// magnetic declination (radians) + public Single mag_declination; + /// raw pressure from barometer + public Int32 raw_press; + /// raw temperature from barometer + public Int32 raw_temp; + /// gyro X calibration + public Single gyro_cal_x; + /// gyro Y calibration + public Single gyro_cal_y; + /// gyro Z calibration + public Single gyro_cal_z; + /// accel X calibration + public Single accel_cal_x; + /// accel Y calibration + public Single accel_cal_y; + /// accel Z calibration + public Single accel_cal_z; + + }; + + + public const byte MAVLINK_MSG_ID_SET_MAG_OFFSETS = 151; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=8)] + public struct mavlink_set_mag_offsets_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// magnetometer X offset + public Int16 mag_ofs_x; + /// magnetometer Y offset + public Int16 mag_ofs_y; + /// magnetometer Z offset + public Int16 mag_ofs_z; + + }; + + + public const byte MAVLINK_MSG_ID_MEMINFO = 152; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=4)] + public struct mavlink_meminfo_t + { + /// heap top + public UInt16 brkval; + /// free memory + public UInt16 freemem; + + }; + + + public const byte MAVLINK_MSG_ID_AP_ADC = 153; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=12)] + public struct mavlink_ap_adc_t + { + /// ADC output 1 + public UInt16 adc1; + /// ADC output 2 + public UInt16 adc2; + /// ADC output 3 + public UInt16 adc3; + /// ADC output 4 + public UInt16 adc4; + /// ADC output 5 + public UInt16 adc5; + /// ADC output 6 + public UInt16 adc6; + + }; + + + public const byte MAVLINK_MSG_ID_DIGICAM_CONFIGURE = 154; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=15)] + public struct mavlink_digicam_configure_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Mode enumeration from 1 to N //P, TV, AV, M, Etc (0 means ignore) + public byte mode; + /// Divisor number //e.g. 1000 means 1/1000 (0 means ignore) + public UInt16 shutter_speed; + /// F stop number x 10 //e.g. 28 means 2.8 (0 means ignore) + public byte aperture; + /// ISO enumeration from 1 to N //e.g. 80, 100, 200, Etc (0 means ignore) + public byte iso; + /// Exposure type enumeration from 1 to N (0 means ignore) + public byte exposure_type; + /// Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once + public byte command_id; + /// Main engine cut-off time before camera trigger in seconds/10 (0 means no cut-off) + public byte engine_cut_off; + /// Extra parameters enumeration (0 means ignore) + public byte extra_param; + /// Correspondent value to given extra_param + public Single extra_value; + + }; + + + public const byte MAVLINK_MSG_ID_DIGICAM_CONTROL = 155; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=13)] + public struct mavlink_digicam_control_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// 0: stop, 1: start or keep it up //Session control e.g. show/hide lens + public byte session; + /// 1 to N //Zoom's absolute position (0 means ignore) + public byte zoom_pos; + /// -100 to 100 //Zooming step value to offset zoom from the current position + public byte zoom_step; + /// 0: unlock focus or keep unlocked, 1: lock focus or keep locked, 3: re-lock focus + public byte focus_lock; + /// 0: ignore, 1: shot or start filming + public byte shot; + /// Command Identity (incremental loop: 0 to 255)//A command sent multiple times will be executed or pooled just once + public byte command_id; + /// Extra parameters enumeration (0 means ignore) + public byte extra_param; + /// Correspondent value to given extra_param + public Single extra_value; + + }; + + + public const byte MAVLINK_MSG_ID_MOUNT_CONFIGURE = 156; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=6)] + public struct mavlink_mount_configure_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// mount operating mode (see MAV_MOUNT_MODE enum) + public byte mount_mode; + /// (1 = yes, 0 = no) + public byte stab_roll; + /// (1 = yes, 0 = no) + public byte stab_pitch; + /// (1 = yes, 0 = no) + public byte stab_yaw; + + }; + + + public const byte MAVLINK_MSG_ID_MOUNT_CONTROL = 157; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=15)] + public struct mavlink_mount_control_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// pitch(deg*100) or lat, depending on mount mode + public Int32 input_a; + /// roll(deg*100) or lon depending on mount mode + public Int32 input_b; + /// yaw(deg*100) or alt (in cm) depending on mount mode + public Int32 input_c; + /// if "1" it will save current trimmed position on EEPROM (just valid for NEUTRAL and LANDING) + public byte save_position; + + }; + + + public const byte MAVLINK_MSG_ID_MOUNT_STATUS = 158; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=14)] + public struct mavlink_mount_status_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// pitch(deg*100) or lat, depending on mount mode + public Int32 pointing_a; + /// roll(deg*100) or lon depending on mount mode + public Int32 pointing_b; + /// yaw(deg*100) or alt (in cm) depending on mount mode + public Int32 pointing_c; + + }; + + + public const byte MAVLINK_MSG_ID_FENCE_POINT = 160; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=12)] + public struct mavlink_fence_point_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// point index (first point is 1, 0 is for return point) + public byte idx; + /// total number of points (for sanity checking) + public byte count; + /// Latitude of point + public Single lat; + /// Longitude of point + public Single lng; + + }; + + + public const byte MAVLINK_MSG_ID_FENCE_FETCH_POINT = 161; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_fence_fetch_point_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// point index (first point is 1, 0 is for return point) + public byte idx; + + }; + + + public const byte MAVLINK_MSG_ID_FENCE_STATUS = 162; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=8)] + public struct mavlink_fence_status_t + { + /// 0 if currently inside fence, 1 if outside + public byte breach_status; + /// number of fence breaches + public UInt16 breach_count; + /// last breach type (see FENCE_BREACH_* enum) + public byte breach_type; + /// time of last breach in milliseconds since boot + public UInt32 breach_time; + + }; + + + public const byte MAVLINK_MSG_ID_AHRS = 163; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=28)] + public struct mavlink_ahrs_t + { + /// X gyro drift estimate rad/s + public Single omegaIx; + /// Y gyro drift estimate rad/s + public Single omegaIy; + /// Z gyro drift estimate rad/s + public Single omegaIz; + /// average accel_weight + public Single accel_weight; + /// average renormalisation value + public Single renorm_val; + /// average error_roll_pitch value + public Single error_rp; + /// average error_yaw value + public Single error_yaw; + + }; + + + public const byte MAVLINK_MSG_ID_SIMSTATE = 164; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=36)] + public struct mavlink_simstate_t + { + /// Roll angle (rad) + public Single roll; + /// Pitch angle (rad) + public Single pitch; + /// Yaw angle (rad) + public Single yaw; + /// X acceleration m/s/s + public Single xacc; + /// Y acceleration m/s/s + public Single yacc; + /// Z acceleration m/s/s + public Single zacc; + /// Angular speed around X axis rad/s + public Single xgyro; + /// Angular speed around Y axis rad/s + public Single ygyro; + /// Angular speed around Z axis rad/s + public Single zgyro; + + }; + + + public const byte MAVLINK_MSG_ID_HWSTATUS = 165; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_hwstatus_t + { + /// board voltage (mV) + public UInt16 Vcc; + /// I2C error count + public byte I2Cerr; + + }; + + + public const byte MAVLINK_MSG_ID_RADIO = 166; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=9)] + public struct mavlink_radio_t + { + /// local signal strength + public byte rssi; + /// remote signal strength + public byte remrssi; + /// how full the tx buffer is as a percentage + public byte txbuf; + /// background noise level + public byte noise; + /// remote background noise level + public byte remnoise; + /// receive errors + public UInt16 rxerrors; + /// count of error corrected packets + public UInt16 fixedp; + + }; + + + public const byte MAVLINK_MSG_ID_HEARTBEAT = 0; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_heartbeat_t + { + /// Type of the MAV (quadrotor, helicopter, etc., up to 15 types, defined in MAV_TYPE ENUM) + public byte type; + /// Type of the Autopilot: 0: Generic, 1: PIXHAWK, 2: SLUGS, 3: Ardupilot (up to 15 types), defined in MAV_AUTOPILOT_TYPE ENUM + public byte autopilot; + /// MAVLink version + public byte mavlink_version; + + }; + + + public const byte MAVLINK_MSG_ID_BOOT = 1; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=4)] + public struct mavlink_boot_t + { + /// The onboard software version + public UInt32 version; + + }; + + + public const byte MAVLINK_MSG_ID_SYSTEM_TIME = 2; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=8)] + public struct mavlink_system_time_t + { + /// Timestamp of the master clock in microseconds since UNIX epoch. + public UInt64 time_usec; + + }; + + + public const byte MAVLINK_MSG_ID_PING = 3; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=14)] + public struct mavlink_ping_t + { + /// PING sequence + public UInt32 seq; + /// 0: request ping from all receiving systems, if greater than 0: message is a ping response and number is the system id of the requesting system + public byte target_system; + /// 0: request ping from all receiving components, if greater than 0: message is a ping response and number is the system id of the requesting system + public byte target_component; + /// Unix timestamp in microseconds + public UInt64 time; + + }; + + + public const byte MAVLINK_MSG_ID_SYSTEM_TIME_UTC = 4; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=8)] + public struct mavlink_system_time_utc_t + { + /// GPS UTC date ddmmyy + public UInt32 utc_date; + /// GPS UTC time hhmmss + public UInt32 utc_time; + + }; + + + public const byte MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL = 5; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=28)] + public struct mavlink_change_operator_control_t + { + /// System the GCS requests control for + public byte target_system; + /// 0: request control of this MAV, 1: Release control of this MAV + public byte control_request; + /// 0: key as plaintext, 1-255: future, different hashing/encryption variants. The GCS should in general use the safest mode possible initially and then gradually move down the encryption level if it gets a NACK message indicating an encryption mismatch. + public byte version; + /// Password / Key, depending on version plaintext or encrypted. 25 or less characters, NULL terminated. The characters may involve A-Z, a-z, 0-9, and "!?,.-" + [MarshalAs(UnmanagedType.ByValArray,SizeConst=25)] + public string passkey; + + }; + + + public const byte MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL_ACK = 6; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_change_operator_control_ack_t + { + /// ID of the GCS this message + public byte gcs_system_id; + /// 0: request control of this MAV, 1: Release control of this MAV + public byte control_request; + /// 0: ACK, 1: NACK: Wrong passkey, 2: NACK: Unsupported passkey encryption method, 3: NACK: Already under control + public byte ack; + + }; + + + public const byte MAVLINK_MSG_ID_AUTH_KEY = 7; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=32)] + public struct mavlink_auth_key_t + { + /// key + [MarshalAs(UnmanagedType.ByValArray,SizeConst=32)] + public string key; + + }; + + + public const byte MAVLINK_MSG_ID_ACTION_ACK = 9; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_action_ack_t + { + /// The action id + public byte action; + /// 0: Action DENIED, 1: Action executed + public byte result; + + }; + + + public const byte MAVLINK_MSG_ID_ACTION = 10; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_action_t + { + /// The system executing the action + public byte target; + /// The component executing the action + public byte target_component; + /// The action id + public byte action; + + }; + + + public const byte MAVLINK_MSG_ID_SET_MODE = 11; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_set_mode_t + { + /// The system setting the mode + public byte target; + /// The new mode + public byte mode; + + }; + + + public const byte MAVLINK_MSG_ID_SET_NAV_MODE = 12; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_set_nav_mode_t + { + /// The system setting the mode + public byte target; + /// The new navigation mode + public byte nav_mode; + + }; + + + public const byte MAVLINK_MSG_ID_PARAM_REQUEST_READ = 20; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=19)] + public struct mavlink_param_request_read_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Onboard parameter id + [MarshalAs(UnmanagedType.ByValArray,SizeConst=15)] + public byte[] param_id; + /// Parameter index. Send -1 to use the param ID field as identifier + public Int16 param_index; + + }; + + + public const byte MAVLINK_MSG_ID_PARAM_REQUEST_LIST = 21; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_param_request_list_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_PARAM_VALUE = 22; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=23)] + public struct mavlink_param_value_t + { + /// Onboard parameter id + [MarshalAs(UnmanagedType.ByValArray,SizeConst=15)] + public byte[] param_id; + /// Onboard parameter value + public Single param_value; + /// Total number of onboard parameters + public UInt16 param_count; + /// Index of this onboard parameter + public UInt16 param_index; + + }; + + + public const byte MAVLINK_MSG_ID_PARAM_SET = 23; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=21)] + public struct mavlink_param_set_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Onboard parameter id + [MarshalAs(UnmanagedType.ByValArray,SizeConst=15)] + public byte[] param_id; + /// Onboard parameter value + public Single param_value; + + }; + + + public const byte MAVLINK_MSG_ID_GPS_RAW_INT = 25; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=37)] + public struct mavlink_gps_raw_int_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 usec; + /// 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. + public byte fix_type; + /// Latitude in 1E7 degrees + public Int32 lat; + /// Longitude in 1E7 degrees + public Int32 lon; + /// Altitude in 1E3 meters (millimeters) + public Int32 alt; + /// GPS HDOP + public Single eph; + /// GPS VDOP + public Single epv; + /// GPS ground speed (m/s) + public Single v; + /// Compass heading in degrees, 0..360 degrees + public Single hdg; + + }; + + + public const byte MAVLINK_MSG_ID_SCALED_IMU = 26; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=26)] + public struct mavlink_scaled_imu_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 usec; + /// X acceleration (mg) + public Int16 xacc; + /// Y acceleration (mg) + public Int16 yacc; + /// Z acceleration (mg) + public Int16 zacc; + /// Angular speed around X axis (millirad /sec) + public Int16 xgyro; + /// Angular speed around Y axis (millirad /sec) + public Int16 ygyro; + /// Angular speed around Z axis (millirad /sec) + public Int16 zgyro; + /// X Magnetic field (milli tesla) + public Int16 xmag; + /// Y Magnetic field (milli tesla) + public Int16 ymag; + /// Z Magnetic field (milli tesla) + public Int16 zmag; + + }; + + + public const byte MAVLINK_MSG_ID_GPS_STATUS = 27; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=101)] + public struct mavlink_gps_status_t + { + /// Number of satellites visible + public byte satellites_visible; + /// Global satellite ID + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public byte[] satellite_prn; + /// 0: Satellite not used, 1: used for localization + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public byte[] satellite_used; + /// Elevation (0: right on top of receiver, 90: on the horizon) of satellite + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public byte[] satellite_elevation; + /// Direction of satellite, 0: 0 deg, 255: 360 deg. + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public byte[] satellite_azimuth; + /// Signal to noise ratio of satellite + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public byte[] satellite_snr; + + }; + + + public const byte MAVLINK_MSG_ID_RAW_IMU = 28; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=26)] + public struct mavlink_raw_imu_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 usec; + /// X acceleration (raw) + public Int16 xacc; + /// Y acceleration (raw) + public Int16 yacc; + /// Z acceleration (raw) + public Int16 zacc; + /// Angular speed around X axis (raw) + public Int16 xgyro; + /// Angular speed around Y axis (raw) + public Int16 ygyro; + /// Angular speed around Z axis (raw) + public Int16 zgyro; + /// X Magnetic field (raw) + public Int16 xmag; + /// Y Magnetic field (raw) + public Int16 ymag; + /// Z Magnetic field (raw) + public Int16 zmag; + + }; + + + public const byte MAVLINK_MSG_ID_RAW_PRESSURE = 29; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=16)] + public struct mavlink_raw_pressure_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 usec; + /// Absolute pressure (raw) + public Int16 press_abs; + /// Differential pressure 1 (raw) + public Int16 press_diff1; + /// Differential pressure 2 (raw) + public Int16 press_diff2; + /// Raw Temperature measurement (raw) + public Int16 temperature; + + }; + + + public const byte MAVLINK_MSG_ID_SCALED_PRESSURE = 38; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_scaled_pressure_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 usec; + /// Absolute pressure (hectopascal) + public Single press_abs; + /// Differential pressure 1 (hectopascal) + public Single press_diff; + /// Temperature measurement (0.01 degrees celsius) + public Int16 temperature; + + }; + + + public const byte MAVLINK_MSG_ID_ATTITUDE = 30; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=32)] + public struct mavlink_attitude_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 usec; + /// Roll angle (rad) + public Single roll; + /// Pitch angle (rad) + public Single pitch; + /// Yaw angle (rad) + public Single yaw; + /// Roll angular speed (rad/s) + public Single rollspeed; + /// Pitch angular speed (rad/s) + public Single pitchspeed; + /// Yaw angular speed (rad/s) + public Single yawspeed; + + }; + + + public const byte MAVLINK_MSG_ID_LOCAL_POSITION = 31; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=32)] + public struct mavlink_local_position_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 usec; + /// X Position + public Single x; + /// Y Position + public Single y; + /// Z Position + public Single z; + /// X Speed + public Single vx; + /// Y Speed + public Single vy; + /// Z Speed + public Single vz; + + }; + + + public const byte MAVLINK_MSG_ID_GLOBAL_POSITION = 33; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=32)] + public struct mavlink_global_position_t + { + /// Timestamp (microseconds since unix epoch) + public UInt64 usec; + /// Latitude, in degrees + public Single lat; + /// Longitude, in degrees + public Single lon; + /// Absolute altitude, in meters + public Single alt; + /// X Speed (in Latitude direction, positive: going north) + public Single vx; + /// Y Speed (in Longitude direction, positive: going east) + public Single vy; + /// Z Speed (in Altitude direction, positive: going up) + public Single vz; + + }; + + + public const byte MAVLINK_MSG_ID_GPS_RAW = 32; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=37)] + public struct mavlink_gps_raw_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 usec; + /// 0-1: no fix, 2: 2D fix, 3: 3D fix. Some applications will not use the value of this field unless it is at least two, so always correctly fill in the fix. + public byte fix_type; + /// Latitude in degrees + public Single lat; + /// Longitude in degrees + public Single lon; + /// Altitude in meters + public Single alt; + /// GPS HDOP + public Single eph; + /// GPS VDOP + public Single epv; + /// GPS ground speed + public Single v; + /// Compass heading in degrees, 0..360 degrees + public Single hdg; + + }; + + + public const byte MAVLINK_MSG_ID_SYS_STATUS = 34; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=11)] + public struct mavlink_sys_status_t + { + /// System mode, see MAV_MODE ENUM in mavlink/include/mavlink_types.h + public byte mode; + /// Navigation mode, see MAV_NAV_MODE ENUM + public byte nav_mode; + /// System status flag, see MAV_STATUS ENUM + public byte status; + /// Maximum usage in percent of the mainloop time, (0%: 0, 100%: 1000) should be always below 1000 + public UInt16 load; + /// Battery voltage, in millivolts (1 = 1 millivolt) + public UInt16 vbat; + /// Remaining battery energy: (0%: 0, 100%: 1000) + public UInt16 battery_remaining; + /// Dropped packets (packets that were corrupted on reception on the MAV) + public UInt16 packet_drop; + + }; + + + public const byte MAVLINK_MSG_ID_RC_CHANNELS_RAW = 35; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=17)] + public struct mavlink_rc_channels_raw_t + { + /// RC channel 1 value, in microseconds + public UInt16 chan1_raw; + /// RC channel 2 value, in microseconds + public UInt16 chan2_raw; + /// RC channel 3 value, in microseconds + public UInt16 chan3_raw; + /// RC channel 4 value, in microseconds + public UInt16 chan4_raw; + /// RC channel 5 value, in microseconds + public UInt16 chan5_raw; + /// RC channel 6 value, in microseconds + public UInt16 chan6_raw; + /// RC channel 7 value, in microseconds + public UInt16 chan7_raw; + /// RC channel 8 value, in microseconds + public UInt16 chan8_raw; + /// Receive signal strength indicator, 0: 0%, 255: 100% + public byte rssi; + + }; + + + public const byte MAVLINK_MSG_ID_RC_CHANNELS_SCALED = 36; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=17)] + public struct mavlink_rc_channels_scaled_t + { + /// RC channel 1 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan1_scaled; + /// RC channel 2 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan2_scaled; + /// RC channel 3 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan3_scaled; + /// RC channel 4 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan4_scaled; + /// RC channel 5 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan5_scaled; + /// RC channel 6 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan6_scaled; + /// RC channel 7 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan7_scaled; + /// RC channel 8 value scaled, (-100%) -10000, (0%) 0, (100%) 10000 + public Int16 chan8_scaled; + /// Receive signal strength indicator, 0: 0%, 255: 100% + public byte rssi; + + }; + + + public const byte MAVLINK_MSG_ID_SERVO_OUTPUT_RAW = 37; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=16)] + public struct mavlink_servo_output_raw_t + { + /// Servo output 1 value, in microseconds + public UInt16 servo1_raw; + /// Servo output 2 value, in microseconds + public UInt16 servo2_raw; + /// Servo output 3 value, in microseconds + public UInt16 servo3_raw; + /// Servo output 4 value, in microseconds + public UInt16 servo4_raw; + /// Servo output 5 value, in microseconds + public UInt16 servo5_raw; + /// Servo output 6 value, in microseconds + public UInt16 servo6_raw; + /// Servo output 7 value, in microseconds + public UInt16 servo7_raw; + /// Servo output 8 value, in microseconds + public UInt16 servo8_raw; + + }; + + + public const byte MAVLINK_MSG_ID_WAYPOINT = 39; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=36)] + public struct mavlink_waypoint_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Sequence + public UInt16 seq; + /// The coordinate system of the waypoint. see MAV_FRAME in mavlink_types.h + public byte frame; + /// The scheduled action for the waypoint. see MAV_COMMAND in common.xml MAVLink specs + public byte command; + /// false:0, true:1 + public byte current; + /// autocontinue to next wp + public byte autocontinue; + /// PARAM1 / For NAV command waypoints: Radius in which the waypoint is accepted as reached, in meters + public Single param1; + /// PARAM2 / For NAV command waypoints: Time that the MAV should stay inside the PARAM1 radius before advancing, in milliseconds + public Single param2; + /// PARAM3 / For LOITER command waypoints: Orbit to circle around the waypoint, in meters. If positive the orbit direction should be clockwise, if negative the orbit direction should be counter-clockwise. + public Single param3; + /// PARAM4 / For NAV and LOITER command waypoints: Yaw orientation in degrees, [0..360] 0 = NORTH + public Single param4; + /// PARAM5 / local: x position, global: latitude + public Single x; + /// PARAM6 / y position: global: longitude + public Single y; + /// PARAM7 / z position: global: altitude + public Single z; + + }; + + + public const byte MAVLINK_MSG_ID_WAYPOINT_REQUEST = 40; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=4)] + public struct mavlink_waypoint_request_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Sequence + public UInt16 seq; + + }; + + + public const byte MAVLINK_MSG_ID_WAYPOINT_SET_CURRENT = 41; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=4)] + public struct mavlink_waypoint_set_current_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Sequence + public UInt16 seq; + + }; + + + public const byte MAVLINK_MSG_ID_WAYPOINT_CURRENT = 42; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_waypoint_current_t + { + /// Sequence + public UInt16 seq; + + }; + + + public const byte MAVLINK_MSG_ID_WAYPOINT_REQUEST_LIST = 43; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_waypoint_request_list_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_WAYPOINT_COUNT = 44; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=4)] + public struct mavlink_waypoint_count_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Number of Waypoints in the Sequence + public UInt16 count; + + }; + + + public const byte MAVLINK_MSG_ID_WAYPOINT_CLEAR_ALL = 45; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_waypoint_clear_all_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + + }; + + + public const byte MAVLINK_MSG_ID_WAYPOINT_REACHED = 46; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=2)] + public struct mavlink_waypoint_reached_t + { + /// Sequence + public UInt16 seq; + + }; + + + public const byte MAVLINK_MSG_ID_WAYPOINT_ACK = 47; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=3)] + public struct mavlink_waypoint_ack_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// 0: OK, 1: Error + public byte type; + + }; + + + public const byte MAVLINK_MSG_ID_GPS_SET_GLOBAL_ORIGIN = 48; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=14)] + public struct mavlink_gps_set_global_origin_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// global position * 1E7 + public Int32 latitude; + /// global position * 1E7 + public Int32 longitude; + /// global position * 1000 + public Int32 altitude; + + }; + + + public const byte MAVLINK_MSG_ID_GPS_LOCAL_ORIGIN_SET = 49; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=12)] + public struct mavlink_gps_local_origin_set_t + { + /// Latitude (WGS84), expressed as * 1E7 + public Int32 latitude; + /// Longitude (WGS84), expressed as * 1E7 + public Int32 longitude; + /// Altitude(WGS84), expressed as * 1000 + public Int32 altitude; + + }; + + + public const byte MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT_SET = 50; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_local_position_setpoint_set_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// x position + public Single x; + /// y position + public Single y; + /// z position + public Single z; + /// Desired yaw angle + public Single yaw; + + }; + + + public const byte MAVLINK_MSG_ID_LOCAL_POSITION_SETPOINT = 51; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=16)] + public struct mavlink_local_position_setpoint_t + { + /// x position + public Single x; + /// y position + public Single y; + /// z position + public Single z; + /// Desired yaw angle + public Single yaw; + + }; + + + public const byte MAVLINK_MSG_ID_CONTROL_STATUS = 52; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=8)] + public struct mavlink_control_status_t + { + /// Position fix: 0: lost, 2: 2D position fix, 3: 3D position fix + public byte position_fix; + /// Vision position fix: 0: lost, 1: 2D local position hold, 2: 2D global position fix, 3: 3D global position fix + public byte vision_fix; + /// GPS position fix: 0: no reception, 1: Minimum 1 satellite, but no position fix, 2: 2D position fix, 3: 3D position fix + public byte gps_fix; + /// Attitude estimation health: 0: poor, 255: excellent + public byte ahrs_health; + /// 0: Attitude control disabled, 1: enabled + public byte control_att; + /// 0: X, Y position control disabled, 1: enabled + public byte control_pos_xy; + /// 0: Z position control disabled, 1: enabled + public byte control_pos_z; + /// 0: Yaw angle control disabled, 1: enabled + public byte control_pos_yaw; + + }; + + + public const byte MAVLINK_MSG_ID_SAFETY_SET_ALLOWED_AREA = 53; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=27)] + public struct mavlink_safety_set_allowed_area_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. + public byte frame; + /// x position 1 / Latitude 1 + public Single p1x; + /// y position 1 / Longitude 1 + public Single p1y; + /// z position 1 / Altitude 1 + public Single p1z; + /// x position 2 / Latitude 2 + public Single p2x; + /// y position 2 / Longitude 2 + public Single p2y; + /// z position 2 / Altitude 2 + public Single p2z; + + }; + + + public const byte MAVLINK_MSG_ID_SAFETY_ALLOWED_AREA = 54; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=25)] + public struct mavlink_safety_allowed_area_t + { + /// Coordinate frame, as defined by MAV_FRAME enum in mavlink_types.h. Can be either global, GPS, right-handed with Z axis up or local, right handed, Z axis down. + public byte frame; + /// x position 1 / Latitude 1 + public Single p1x; + /// y position 1 / Longitude 1 + public Single p1y; + /// z position 1 / Altitude 1 + public Single p1z; + /// x position 2 / Latitude 2 + public Single p2x; + /// y position 2 / Longitude 2 + public Single p2y; + /// z position 2 / Altitude 2 + public Single p2z; + + }; + + + public const byte MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_THRUST = 55; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_set_roll_pitch_yaw_thrust_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Desired roll angle in radians + public Single roll; + /// Desired pitch angle in radians + public Single pitch; + /// Desired yaw angle in radians + public Single yaw; + /// Collective thrust, normalized to 0 .. 1 + public Single thrust; + + }; + + + public const byte MAVLINK_MSG_ID_SET_ROLL_PITCH_YAW_SPEED_THRUST = 56; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_set_roll_pitch_yaw_speed_thrust_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// Desired roll angular speed in rad/s + public Single roll_speed; + /// Desired pitch angular speed in rad/s + public Single pitch_speed; + /// Desired yaw angular speed in rad/s + public Single yaw_speed; + /// Collective thrust, normalized to 0 .. 1 + public Single thrust; + + }; + + + public const byte MAVLINK_MSG_ID_ROLL_PITCH_YAW_THRUST_SETPOINT = 57; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=24)] + public struct mavlink_roll_pitch_yaw_thrust_setpoint_t + { + /// Timestamp in micro seconds since unix epoch + public UInt64 time_us; + /// Desired roll angle in radians + public Single roll; + /// Desired pitch angle in radians + public Single pitch; + /// Desired yaw angle in radians + public Single yaw; + /// Collective thrust, normalized to 0 .. 1 + public Single thrust; + + }; + + + public const byte MAVLINK_MSG_ID_ROLL_PITCH_YAW_SPEED_THRUST_SETPOINT = 58; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=24)] + public struct mavlink_roll_pitch_yaw_speed_thrust_setpoint_t + { + /// Timestamp in micro seconds since unix epoch + public UInt64 time_us; + /// Desired roll angular speed in rad/s + public Single roll_speed; + /// Desired pitch angular speed in rad/s + public Single pitch_speed; + /// Desired yaw angular speed in rad/s + public Single yaw_speed; + /// Collective thrust, normalized to 0 .. 1 + public Single thrust; + + }; + + + public const byte MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT = 62; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=26)] + public struct mavlink_nav_controller_output_t + { + /// Current desired roll in degrees + public Single nav_roll; + /// Current desired pitch in degrees + public Single nav_pitch; + /// Current desired heading in degrees + public Int16 nav_bearing; + /// Bearing to current waypoint/target in degrees + public Int16 target_bearing; + /// Distance to active waypoint in meters + public UInt16 wp_dist; + /// Current altitude error in meters + public Single alt_error; + /// Current airspeed error in meters/second + public Single aspd_error; + /// Current crosstrack error on x-y plane in meters + public Single xtrack_error; + + }; + + + public const byte MAVLINK_MSG_ID_POSITION_TARGET = 63; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=16)] + public struct mavlink_position_target_t + { + /// x position + public Single x; + /// y position + public Single y; + /// z position + public Single z; + /// yaw orientation in radians, 0 = NORTH + public Single yaw; + + }; + + + public const byte MAVLINK_MSG_ID_STATE_CORRECTION = 64; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=36)] + public struct mavlink_state_correction_t + { + /// x position error + public Single xErr; + /// y position error + public Single yErr; + /// z position error + public Single zErr; + /// roll error (radians) + public Single rollErr; + /// pitch error (radians) + public Single pitchErr; + /// yaw error (radians) + public Single yawErr; + /// x velocity + public Single vxErr; + /// y velocity + public Single vyErr; + /// z velocity + public Single vzErr; + + }; + + + public const byte MAVLINK_MSG_ID_SET_ALTITUDE = 65; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=5)] + public struct mavlink_set_altitude_t + { + /// The system setting the altitude + public byte target; + /// The new altitude in meters + public UInt32 mode; + + }; + + + public const byte MAVLINK_MSG_ID_REQUEST_DATA_STREAM = 66; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=6)] + public struct mavlink_request_data_stream_t + { + /// The target requested to send the message stream. + public byte target_system; + /// The target requested to send the message stream. + public byte target_component; + /// The ID of the requested message type + public byte req_stream_id; + /// Update rate in Hertz + public UInt16 req_message_rate; + /// 1 to start sending, 0 to stop sending. + public byte start_stop; + + }; + + + public const byte MAVLINK_MSG_ID_HIL_STATE = 67; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=56)] + public struct mavlink_hil_state_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 usec; + /// Roll angle (rad) + public Single roll; + /// Pitch angle (rad) + public Single pitch; + /// Yaw angle (rad) + public Single yaw; + /// Roll angular speed (rad/s) + public Single rollspeed; + /// Pitch angular speed (rad/s) + public Single pitchspeed; + /// Yaw angular speed (rad/s) + public Single yawspeed; + /// Latitude, expressed as * 1E7 + public Int32 lat; + /// Longitude, expressed as * 1E7 + public Int32 lon; + /// Altitude in meters, expressed as * 1000 (millimeters) + public Int32 alt; + /// Ground X Speed (Latitude), expressed as m/s * 100 + public Int16 vx; + /// Ground Y Speed (Longitude), expressed as m/s * 100 + public Int16 vy; + /// Ground Z Speed (Altitude), expressed as m/s * 100 + public Int16 vz; + /// X acceleration (mg) + public Int16 xacc; + /// Y acceleration (mg) + public Int16 yacc; + /// Z acceleration (mg) + public Int16 zacc; + + }; + + + public const byte MAVLINK_MSG_ID_HIL_CONTROLS = 68; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=26)] + public struct mavlink_hil_controls_t + { + /// Timestamp (microseconds since UNIX epoch or microseconds since system boot) + public UInt64 time_us; + /// Control output -3 .. 1 + public Single roll_ailerons; + /// Control output -1 .. 1 + public Single pitch_elevator; + /// Control output -1 .. 1 + public Single yaw_rudder; + /// Throttle 0 .. 1 + public Single throttle; + /// System mode (MAV_MODE) + public byte mode; + /// Navigation mode (MAV_NAV_MODE) + public byte nav_mode; + + }; + + + public const byte MAVLINK_MSG_ID_MANUAL_CONTROL = 69; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=21)] + public struct mavlink_manual_control_t + { + /// The system to be controlled + public byte target; + /// roll + public Single roll; + /// pitch + public Single pitch; + /// yaw + public Single yaw; + /// thrust + public Single thrust; + /// roll control enabled auto:0, manual:1 + public byte roll_manual; + /// pitch auto:0, manual:1 + public byte pitch_manual; + /// yaw auto:0, manual:1 + public byte yaw_manual; + /// thrust auto:0, manual:1 + public byte thrust_manual; + + }; + + + public const byte MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE = 70; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_rc_channels_override_t + { + /// System ID + public byte target_system; + /// Component ID + public byte target_component; + /// RC channel 1 value, in microseconds + public UInt16 chan1_raw; + /// RC channel 2 value, in microseconds + public UInt16 chan2_raw; + /// RC channel 3 value, in microseconds + public UInt16 chan3_raw; + /// RC channel 4 value, in microseconds + public UInt16 chan4_raw; + /// RC channel 5 value, in microseconds + public UInt16 chan5_raw; + /// RC channel 6 value, in microseconds + public UInt16 chan6_raw; + /// RC channel 7 value, in microseconds + public UInt16 chan7_raw; + /// RC channel 8 value, in microseconds + public UInt16 chan8_raw; + + }; + + + public const byte MAVLINK_MSG_ID_GLOBAL_POSITION_INT = 73; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_global_position_int_t + { + /// Latitude, expressed as * 1E7 + public Int32 lat; + /// Longitude, expressed as * 1E7 + public Int32 lon; + /// Altitude in meters, expressed as * 1000 (millimeters) + public Int32 alt; + /// Ground X Speed (Latitude), expressed as m/s * 100 + public Int16 vx; + /// Ground Y Speed (Longitude), expressed as m/s * 100 + public Int16 vy; + /// Ground Z Speed (Altitude), expressed as m/s * 100 + public Int16 vz; + + }; + + + public const byte MAVLINK_MSG_ID_VFR_HUD = 74; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=20)] + public struct mavlink_vfr_hud_t + { + /// Current airspeed in m/s + public Single airspeed; + /// Current ground speed in m/s + public Single groundspeed; + /// Current heading in degrees, in compass units (0..360, 0=north) + public Int16 heading; + /// Current throttle setting in integer percent, 0 to 100 + public UInt16 throttle; + /// Current altitude (MSL), in meters + public Single alt; + /// Current climb rate in meters/second + public Single climb; + + }; + + + public const byte MAVLINK_MSG_ID_COMMAND = 75; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=20)] + public struct mavlink_command_t + { + /// System which should execute the command + public byte target_system; + /// Component which should execute the command, 0 for all components + public byte target_component; + /// Command ID, as defined by MAV_CMD enum. + public byte command; + /// 0: First transmission of this command. 1-255: Confirmation transmissions (e.g. for kill command) + public byte confirmation; + /// Parameter 1, as defined by MAV_CMD enum. + public Single param1; + /// Parameter 2, as defined by MAV_CMD enum. + public Single param2; + /// Parameter 3, as defined by MAV_CMD enum. + public Single param3; + /// Parameter 4, as defined by MAV_CMD enum. + public Single param4; + + }; + + + public const byte MAVLINK_MSG_ID_COMMAND_ACK = 76; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=8)] + public struct mavlink_command_ack_t + { + /// Current airspeed in m/s + public Single command; + /// 1: Action ACCEPTED and EXECUTED, 1: Action TEMPORARY REJECTED/DENIED, 2: Action PERMANENTLY DENIED, 3: Action UNKNOWN/UNSUPPORTED, 4: Requesting CONFIRMATION + public Single result; + + }; + + + public const byte MAVLINK_MSG_ID_OPTICAL_FLOW = 100; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=18)] + public struct mavlink_optical_flow_t + { + /// Timestamp (UNIX) + public UInt64 time; + /// Sensor ID + public byte sensor_id; + /// Flow in pixels in x-sensor direction + public Int16 flow_x; + /// Flow in pixels in y-sensor direction + public Int16 flow_y; + /// Optical flow quality / confidence. 0: bad, 255: maximum quality + public byte quality; + /// Ground distance in meters + public Single ground_distance; + + }; + + + public const byte MAVLINK_MSG_ID_OBJECT_DETECTION_EVENT = 140; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=36)] + public struct mavlink_object_detection_event_t + { + /// Timestamp in milliseconds since system boot + public UInt32 time; + /// Object ID + public UInt16 object_id; + /// Object type: 0: image, 1: letter, 2: ground vehicle, 3: air vehicle, 4: surface vehicle, 5: sub-surface vehicle, 6: human, 7: animal + public byte type; + /// Name of the object as defined by the detector + [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] + public string name; + /// Detection quality / confidence. 0: bad, 255: maximum confidence + public byte quality; + /// Angle of the object with respect to the body frame in NED coordinates in radians. 0: front + public Single bearing; + /// Ground distance in meters + public Single distance; + + }; + + + public const byte MAVLINK_MSG_ID_DEBUG_VECT = 251; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=30)] + public struct mavlink_debug_vect_t + { + /// Name + [MarshalAs(UnmanagedType.ByValArray,SizeConst=10)] + public string name; + /// Timestamp + public UInt64 usec; + /// x + public Single x; + /// y + public Single y; + /// z + public Single z; + + }; + + + public const byte MAVLINK_MSG_ID_NAMED_VALUE_FLOAT = 252; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=14)] + public struct mavlink_named_value_float_t + { + /// Name of the debug variable + [MarshalAs(UnmanagedType.ByValArray,SizeConst=10)] + public string name; + /// Floating point value + public Single value; + + }; + + + public const byte MAVLINK_MSG_ID_NAMED_VALUE_INT = 253; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=14)] + public struct mavlink_named_value_int_t + { + /// Name of the debug variable + [MarshalAs(UnmanagedType.ByValArray,SizeConst=10)] + public string name; + /// Signed integer value + public Int32 value; + + }; + + + public const byte MAVLINK_MSG_ID_STATUSTEXT = 254; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=51)] + public struct mavlink_statustext_t + { + /// Severity of status, 0 = info message, 255 = critical fault + public byte severity; + /// Status text message, without null termination character + [MarshalAs(UnmanagedType.ByValArray,SizeConst=50)] + public byte[] text; + + }; + + + public const byte MAVLINK_MSG_ID_DEBUG = 255; + [StructLayout(LayoutKind.Sequential,Pack=1,Size=5)] + public struct mavlink_debug_t + { + /// index of debug variable + public byte ind; + /// DEBUG value + public Single value; + + }; + + } +#endif +} diff --git a/Tools/ArdupilotMegaPlanner/Mavlink/MavlinkOther.cs b/Tools/ArdupilotMegaPlanner/Mavlink/MavlinkOther.cs index f01d258e0a..ee90b0e19d 100644 --- a/Tools/ArdupilotMegaPlanner/Mavlink/MavlinkOther.cs +++ b/Tools/ArdupilotMegaPlanner/Mavlink/MavlinkOther.cs @@ -7,6 +7,7 @@ namespace ArdupilotMega { public partial class MAVLink { + #if !MAVLINK10 enum MAV_CLASS { @@ -161,7 +162,6 @@ namespace ArdupilotMega GLOBAL_RELATIVE_ALT = 3, LOCAL_ENU = 4 }; - #endif } } diff --git a/Tools/ArdupilotMegaPlanner/Mavlink/MavlinkUtil.cs b/Tools/ArdupilotMegaPlanner/Mavlink/MavlinkUtil.cs index 7bca2468b0..c0e7dc7245 100644 --- a/Tools/ArdupilotMegaPlanner/Mavlink/MavlinkUtil.cs +++ b/Tools/ArdupilotMegaPlanner/Mavlink/MavlinkUtil.cs @@ -22,14 +22,14 @@ namespace ArdupilotMega /// The bytes of the mavlink packet /// The position in the byte array where the packet starts /// The newly created mavlink packet - public static TMavlinkPacket ByteArrayToStructure(this byte[] bytearray, int startoffset) where TMavlinkPacket : struct + public static TMavlinkPacket ByteArrayToStructure(this byte[] bytearray, int startoffset = 6) where TMavlinkPacket : struct { object newPacket = new TMavlinkPacket(); ByteArrayToStructure(bytearray, ref newPacket, startoffset); return (TMavlinkPacket)newPacket; } - public static TMavlinkPacket ByteArrayToStructureBigEndian(this byte[] bytearray, int startoffset) where TMavlinkPacket : struct + public static TMavlinkPacket ByteArrayToStructureBigEndian(this byte[] bytearray, int startoffset = 6) where TMavlinkPacket : struct { object newPacket = new TMavlinkPacket(); ByteArrayToStructureEndian(bytearray, ref newPacket, startoffset); diff --git a/Tools/ArdupilotMegaPlanner/MavlinkLog.cs b/Tools/ArdupilotMegaPlanner/MavlinkLog.cs index a4cf526e50..3b4f8458b3 100644 --- a/Tools/ArdupilotMegaPlanner/MavlinkLog.cs +++ b/Tools/ArdupilotMegaPlanner/MavlinkLog.cs @@ -439,20 +439,7 @@ namespace ArdupilotMega Application.DoEvents(); - switch (mine.aptype) - { - case MAVLink.MAV_TYPE.MAV_FIXED_WING: - MainV2.cs.firmware = MainV2.Firmwares.ArduPlane; - break; - case MAVLink.MAV_TYPE.MAV_QUADROTOR: - MainV2.cs.firmware = MainV2.Firmwares.ArduCopter2; - break; - case MAVLink.MAV_TYPE.MAV_GROUND: - MainV2.cs.firmware = MainV2.Firmwares.ArduRover; - break; - default: - break; - } + mine.setAPType(); writeGPX(logfile); writeKML(logfile + ".kml"); @@ -830,10 +817,10 @@ namespace ArdupilotMega string code = @" public double stage(object inp) { - return getAltAboveHome((MAVLink.mavlink_gps_raw_t) inp); + return getAltAboveHome((MAVLink09.mavlink_gps_raw_t) inp); } - public double getAltAboveHome(MAVLink.mavlink_gps_raw_t gps) + public double getAltAboveHome(MAVLink09.mavlink_gps_raw_t gps) { if (customforusenumber == -1 && gps.fix_type != 2) customforusenumber = gps.alt; diff --git a/Tools/ArdupilotMegaPlanner/Program.cs b/Tools/ArdupilotMegaPlanner/Program.cs index d2206e2334..1d0f51ab78 100644 --- a/Tools/ArdupilotMegaPlanner/Program.cs +++ b/Tools/ArdupilotMegaPlanner/Program.cs @@ -43,7 +43,14 @@ namespace ArdupilotMega //Console.WriteLine(srtm.getAltitude(-35.115676879882812, 117.94178754638671,20)); - //return; + + PointLatLngAlt plla = new PointLatLngAlt(54.0359, 5.4253, 0, ""); + PointLatLngAlt plla2 = new PointLatLngAlt(54.3838, 3.0412, 0, ""); + + Console.WriteLine(plla.GetDistance(plla2)); + Console.WriteLine(plla.GetDistance2(plla2)); + + if (System.Diagnostics.Debugger.IsAttached) { diff --git a/Tools/ArdupilotMegaPlanner/Properties/AssemblyInfo.cs b/Tools/ArdupilotMegaPlanner/Properties/AssemblyInfo.cs index b0555ab692..f59c0e9876 100644 --- a/Tools/ArdupilotMegaPlanner/Properties/AssemblyInfo.cs +++ b/Tools/ArdupilotMegaPlanner/Properties/AssemblyInfo.cs @@ -34,5 +34,5 @@ using System.Resources; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.1.*")] -[assembly: AssemblyFileVersion("1.1.86")] +[assembly: AssemblyFileVersion("1.1.87")] [assembly: NeutralResourcesLanguageAttribute("")] diff --git a/Tools/ArdupilotMegaPlanner/RAW_Sensor.cs b/Tools/ArdupilotMegaPlanner/RAW_Sensor.cs index e36709761f..3b77aca6d8 100644 --- a/Tools/ArdupilotMegaPlanner/RAW_Sensor.cs +++ b/Tools/ArdupilotMegaPlanner/RAW_Sensor.cs @@ -25,8 +25,6 @@ namespace ArdupilotMega int tickStart = 0; - MAVLink comPort = new MAVLink(); - public RAW_Sensor() { InitializeComponent(); @@ -141,7 +139,7 @@ namespace ArdupilotMega private void timer2serial_Tick(object sender, EventArgs e) { - if (!comPort.BaseStream.IsOpen && !MainV2.comPort.logreadmode) + if (!MainV2.comPort.BaseStream.IsOpen && !MainV2.comPort.logreadmode) return; //Console.WriteLine(DateTime.Now.Millisecond + " timer2 serial"); @@ -208,7 +206,7 @@ namespace ArdupilotMega private void ACM_Setup_FormClosed(object sender, FormClosedEventArgs e) { - if (comPort != null && comPort.BaseStream.IsOpen) + if (MainV2.comPort != null && MainV2.comPort.BaseStream.IsOpen) { try { @@ -225,9 +223,7 @@ namespace ArdupilotMega { try { - comPort = MainV2.comPort; - - if (!comPort.BaseStream.IsOpen && !MainV2.comPort.logreadmode) + if (!MainV2.comPort.BaseStream.IsOpen && !MainV2.comPort.logreadmode) { CustomMessageBox.Show("Please connect first"); this.Close(); @@ -237,13 +233,12 @@ namespace ArdupilotMega //comPort.Open(); //comPort.stopall(true); // ensure off - Console.WriteLine("Req streams {0} {1}", comPort.bps, DateTime.Now); - //comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.EXTENDED_STATUS, 0); // mode gps raw - //comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.POSITION, 3); // request location - //comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.EXTRA1, 3); // request attitude - //comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.EXTRA2, 3); // request vfr - comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.RAW_SENSORS, MainV2.cs.ratesensors); // request raw sensor - //comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.RC_CHANNELS, 3); // request rc info + //comPort.requestDatastream((byte)ArdupilotMega.MAVLink09.MAV_DATA_STREAM.EXTENDED_STATUS, 0); // mode gps raw + //comPort.requestDatastream((byte)ArdupilotMega.MAVLink09.MAV_DATA_STREAM.POSITION, 3); // request location + //comPort.requestDatastream((byte)ArdupilotMega.MAVLink09.MAV_DATA_STREAM.EXTRA1, 3); // request attitude + //comPort.requestDatastream((byte)ArdupilotMega.MAVLink09.MAV_DATA_STREAM.EXTRA2, 3); // request vfr + MainV2.comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.RAW_SENSORS, MainV2.cs.ratesensors); // request raw sensor + //comPort.requestDatastream((byte)ArdupilotMega.MAVLink09.MAV_DATA_STREAM.RC_CHANNELS, 3); // request rc info } catch { @@ -256,7 +251,7 @@ namespace ArdupilotMega private void CMB_rawupdaterate_SelectedIndexChanged(object sender, EventArgs e) { MainV2.cs.ratesensors = (byte)int.Parse(CMB_rawupdaterate.Text); - comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.RAW_SENSORS, (byte)int.Parse(CMB_rawupdaterate.Text)); // request raw sensor + MainV2.comPort.requestDatastream((byte)ArdupilotMega.MAVLink.MAV_DATA_STREAM.RAW_SENSORS, (byte)int.Parse(CMB_rawupdaterate.Text)); // request raw sensor } System.IO.StreamWriter sw = null; diff --git a/Tools/ArdupilotMegaPlanner/Radio/3DRradio.cs b/Tools/ArdupilotMegaPlanner/Radio/3DRradio.cs index df15197474..9e56ea16ec 100644 --- a/Tools/ArdupilotMegaPlanner/Radio/3DRradio.cs +++ b/Tools/ArdupilotMegaPlanner/Radio/3DRradio.cs @@ -37,7 +37,7 @@ namespace ArdupilotMega // setup netid S3.DataSource = Enumerable.Range(0, 500).ToArray(); - RS3.DataSource = S3.DataSource; + RS3.DataSource = Enumerable.Range(0, 500).ToArray(); } bool getFirmware(uploader.Uploader.Code device) @@ -515,7 +515,7 @@ namespace ArdupilotMega } // remote - foreach (Control ctl in this.Controls) + foreach (Control ctl in groupBox2.Controls) { if (ctl.Name.StartsWith("RS") && ctl.Name != "RSSI") ctl.ResetText(); @@ -553,7 +553,7 @@ namespace ArdupilotMega } else if (controls[0].GetType() == typeof(ComboBox)) { - ((ComboBox)controls[0]).SelectedText = values[2].Trim(); + ((ComboBox)controls[0]).Text = values[2].Trim(); } } else diff --git a/Tools/ArdupilotMegaPlanner/Radio/3DRradio.resx b/Tools/ArdupilotMegaPlanner/Radio/3DRradio.resx index 0a8a677ed7..6817cb57c5 100644 --- a/Tools/ArdupilotMegaPlanner/Radio/3DRradio.resx +++ b/Tools/ArdupilotMegaPlanner/Radio/3DRradio.resx @@ -1799,7 +1799,7 @@ which result in a valid packet CRC BUT_savesettings - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.35885, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, 3DRRadio, Version=0.6.4521.12642, Culture=neutral, PublicKeyToken=null $this @@ -1823,7 +1823,7 @@ which result in a valid packet CRC BUT_getcurrent - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.35885, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, 3DRRadio, Version=0.6.4521.12642, Culture=neutral, PublicKeyToken=null $this @@ -1868,7 +1868,7 @@ which result in a valid packet CRC BUT_upload - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.35885, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, 3DRRadio, Version=0.6.4521.12642, Culture=neutral, PublicKeyToken=null $this @@ -2559,7 +2559,7 @@ which result in a valid packet CRC NoControl - 338, 355 + 346, 355 102, 29 @@ -2574,7 +2574,7 @@ which result in a valid packet CRC BUT_Syncoptions - ArdupilotMega.Controls.MyButton, ArdupilotMegaPlanner, Version=1.1.4519.35885, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.MyButton, 3DRRadio, Version=0.6.4521.12642, Culture=neutral, PublicKeyToken=null $this @@ -2700,6 +2700,6 @@ which result in a valid packet CRC _3DRradio - ArdupilotMega.Controls.BackstageView.BackStageViewContentPanel, ArdupilotMegaPlanner, Version=1.1.4519.35885, Culture=neutral, PublicKeyToken=null + ArdupilotMega.Controls.BackstageView.BackStageViewContentPanel, 3DRRadio, Version=0.6.4521.12642, Culture=neutral, PublicKeyToken=null \ No newline at end of file diff --git a/Tools/ArdupilotMegaPlanner/Utilities/Video.cs b/Tools/ArdupilotMegaPlanner/Utilities/Video.cs new file mode 100644 index 0000000000..7204e9355b --- /dev/null +++ b/Tools/ArdupilotMegaPlanner/Utilities/Video.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AForge; +using AForge.Video; +using AForge.Video.DirectShow; + +namespace ArdupilotMega.Utilities +{ + public class Video + { + private static FilterInfoCollection videoDevices; + private static AsyncVideoSource asyncSource; + + public static bool isRunning { get { if (asyncSource == null) return false; return asyncSource.IsRunning; } } + + public static List getDevices() + { + List list = new List(); + // Get the collection of video devices + videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); + + foreach (FilterInfo dev in videoDevices) + { + list.Add(dev.Name); + } + + return list; + } + + public static void Start(VideoCaptureDevice videoSource) + { + videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); + + //VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[Device].MonikerString); + videoSource.DesiredFrameRate = 25; + + + asyncSource = new AsyncVideoSource(videoSource, true); + + asyncSource.NewFrame += new NewFrameEventHandler(asyncSource_NewFrame); + asyncSource.Start(); + + } + + static void asyncSource_NewFrame(object sender, NewFrameEventArgs eventArgs) + { + //GCSViews.FlightData.cam_camimage(eventArgs.Frame); + if (MainV2.instance.IsDisposed) + Dispose(); + } + + public static void Stop() + { + Dispose(); + } + + /// release everything. + public static void Dispose() + { + try + { + asyncSource.Stop(); + + asyncSource = null; + } + catch { } + + asyncSource_NewFrame(null, new NewFrameEventArgs(null)); + } + + ~Video() + { + Dispose(); + } + } +} diff --git a/Tools/ArdupilotMegaPlanner/wix/Program.cs b/Tools/ArdupilotMegaPlanner/wix/Program.cs index 9075e46227..6f6ebc754a 100644 --- a/Tools/ArdupilotMegaPlanner/wix/Program.cs +++ b/Tools/ArdupilotMegaPlanner/wix/Program.cs @@ -301,8 +301,10 @@ data = @" foreach (string filepath in files) { - if (filepath.ToLower().EndsWith("release\\config.xml") || filepath.ToLower().Contains("ardupilotplanner.log") || filepath.ToLower().Contains("dataflash.bin") || filepath.ToLower().Contains(".etag")) + if (filepath.ToLower().EndsWith("release\\config.xml") || filepath.ToLower().Contains("ardupilotplanner.log") || + filepath.ToLower().Contains("dataflash.bin") || filepath.ToLower().Contains(".etag")) continue; + no++; @@ -320,7 +322,7 @@ data = @" foreach (string dir in dirs) { - if (dir.EndsWith("gmapcache") || dir.EndsWith("srtm")) + if (dir.ToLower().EndsWith("gmapcache") || dir.ToLower().EndsWith("srtm") || dir.ToLower().EndsWith("logs")) continue; dodirectory(dir); }