2011-09-08 22:31:32 -03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
2012-02-26 19:13:23 -04:00
|
|
|
|
using System.Configuration;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Diagnostics;
|
2011-12-15 20:17:13 -04:00
|
|
|
|
using System.Runtime.InteropServices;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
using System.Speech.Synthesis;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Threading;
|
2012-04-29 21:32:33 -03:00
|
|
|
|
using System.Net.Sockets;
|
2012-04-24 15:33:24 -03:00
|
|
|
|
using ArdupilotMega.Utilities;
|
2011-11-21 20:32:11 -04:00
|
|
|
|
using IronPython.Hosting;
|
2012-02-26 19:13:23 -04:00
|
|
|
|
using log4net;
|
2012-03-03 03:42:41 -04:00
|
|
|
|
using ArdupilotMega.Controls;
|
2012-04-03 19:58:45 -03:00
|
|
|
|
using System.Security.Cryptography;
|
2012-04-24 10:49:27 -03:00
|
|
|
|
using ArdupilotMega.Comms;
|
|
|
|
|
using ArdupilotMega.Arduino;
|
|
|
|
|
using System.IO.Ports;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
namespace ArdupilotMega
|
|
|
|
|
{
|
|
|
|
|
public partial class MainV2 : Form
|
|
|
|
|
{
|
2012-02-29 09:19:54 -04:00
|
|
|
|
private static readonly ILog log =
|
2012-02-26 19:13:23 -04:00
|
|
|
|
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
2012-04-21 04:30:15 -03:00
|
|
|
|
|
|
|
|
|
// used to hide/show console window
|
2011-09-08 22:31:32 -03:00
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
public static extern int FindWindow(string szClass, string szTitle);
|
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
public static extern int ShowWindow(int Handle, int showState);
|
|
|
|
|
|
|
|
|
|
const int SW_SHOWNORMAL = 1;
|
|
|
|
|
const int SW_HIDE = 0;
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Main Comport interface
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
public static MAVLink comPort = new MAVLink();
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Comport name
|
|
|
|
|
/// </summary>
|
2012-03-18 20:26:20 -03:00
|
|
|
|
public static string comPortName = "";
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// use to store all internal config
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
public static Hashtable config = new Hashtable();
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// used to prevent comport access for exclusive use
|
|
|
|
|
/// </summary>
|
2012-03-18 20:26:20 -03:00
|
|
|
|
public static bool giveComport = false;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// mono detection
|
|
|
|
|
/// </summary>
|
2011-11-21 20:32:11 -04:00
|
|
|
|
public static bool MONO = false;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// speech engein enable
|
|
|
|
|
/// </summary>
|
2012-03-18 20:26:20 -03:00
|
|
|
|
public static bool speechEnable = false;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// spech engine static class
|
|
|
|
|
/// </summary>
|
2012-03-18 20:26:20 -03:00
|
|
|
|
public static Speech speechEngine = null;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// joystick static class
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
public static Joystick joystick = null;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// track last joystick packet sent. used to track timming
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
DateTime lastjoystick = DateTime.Now;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// hud background image grabber from a video stream - not realy that efficent. ie no hardware overlays etc.
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
public static WebCamService.Capture cam = null;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// the static global state of the currently connected MAV
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
public static CurrentState cs = new CurrentState();
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// controls the main serial reader thread
|
|
|
|
|
/// </summary>
|
2012-03-18 20:26:20 -03:00
|
|
|
|
bool serialThread = false;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// unused at this point - potential to move all forms to this single binding source. need to evalutate performance/exception issues
|
|
|
|
|
/// </summary>
|
2012-04-05 21:50:04 -03:00
|
|
|
|
static internal BindingSource bs;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// used for mini https server for websockets/mjpeg video stream, and network link kmls
|
|
|
|
|
/// </summary>
|
|
|
|
|
private TcpListener listener;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// track the last heartbeat sent
|
|
|
|
|
/// </summary>
|
|
|
|
|
private DateTime heatbeatSend = DateTime.Now;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// used to call anything as needed.
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
public static MainV2 instance = null;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// used to feed in a network link kml to the http server
|
|
|
|
|
/// </summary>
|
2012-04-15 10:51:07 -03:00
|
|
|
|
public string georefkml = "";
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// enum of firmwares
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
public enum Firmwares
|
|
|
|
|
{
|
2011-09-10 03:15:14 -03:00
|
|
|
|
ArduPlane,
|
2011-09-08 22:31:32 -03:00
|
|
|
|
ArduCopter2,
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-08 10:21:19 -03:00
|
|
|
|
DateTime connectButtonUpdate = DateTime.Now;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// declared here if i want a "single" instance of the form
|
|
|
|
|
/// ie configuration gets reloaded on every click
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
GCSViews.FlightData FlightData;
|
|
|
|
|
GCSViews.FlightPlanner FlightPlanner;
|
2012-04-25 07:10:11 -03:00
|
|
|
|
//GCSViews.Configuration Configuration;
|
|
|
|
|
GCSViews.ConfigurationView.Setup Configuration;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
GCSViews.Simulation Simulation;
|
|
|
|
|
GCSViews.Firmware Firmware;
|
2011-10-25 10:20:58 -03:00
|
|
|
|
GCSViews.Terminal Terminal;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-05-08 10:21:19 -03:00
|
|
|
|
private Form connectionStatsForm;
|
|
|
|
|
private ConnectionStats _connectionStats;
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
2012-05-08 10:21:19 -03:00
|
|
|
|
/// This 'Control' is the toolstrip control that holds the comport combo, baudrate combo etc
|
|
|
|
|
/// Otiginally seperate controls, each hosted in a toolstip sqaure, combined into this custom
|
|
|
|
|
/// control for layout reasons.
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// </summary>
|
2012-05-08 10:21:19 -03:00
|
|
|
|
private readonly ConnectionControl _connectionControl;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
public MainV2()
|
|
|
|
|
{
|
2011-11-24 20:07:14 -04:00
|
|
|
|
Form splash = new Splash();
|
|
|
|
|
splash.Show();
|
|
|
|
|
|
|
|
|
|
string strVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
2012-04-21 04:30:15 -03:00
|
|
|
|
|
|
|
|
|
strVersion = "mav " + MAVLink.MAVLINK_WIRE_PROTOCOL_VERSION;
|
|
|
|
|
|
2011-11-24 20:07:14 -04:00
|
|
|
|
splash.Text = "APM Planner " + Application.ProductVersion + " " + strVersion + " By Michael Oborne";
|
|
|
|
|
|
|
|
|
|
splash.Refresh();
|
|
|
|
|
|
|
|
|
|
Application.DoEvents();
|
|
|
|
|
|
2012-01-23 09:36:20 -04:00
|
|
|
|
instance = this;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
2012-05-08 10:21:19 -03:00
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl = toolStripConnectionControl.ConnectionControl;
|
|
|
|
|
_connectionControl.CMB_baudrate.TextChanged += this.CMB_baudrate_TextChanged;
|
|
|
|
|
_connectionControl.CMB_baudrate.SelectedIndexChanged += this.CMB_baudrate_SelectedIndexChanged;
|
|
|
|
|
_connectionControl.CMB_serialport.SelectedIndexChanged += this.CMB_serialport_SelectedIndexChanged;
|
|
|
|
|
_connectionControl.CMB_serialport.Enter += this.CMB_serialport_Enter;
|
|
|
|
|
_connectionControl.CMB_serialport.Click += this.CMB_serialport_Click;
|
|
|
|
|
_connectionControl.TOOL_APMFirmware.SelectedIndexChanged += this.TOOL_APMFirmware_SelectedIndexChanged;
|
2012-01-23 09:36:20 -04:00
|
|
|
|
|
2012-05-08 10:21:19 -03:00
|
|
|
|
_connectionControl.ShowLinkStats += (sender, e) => ShowConnectionStatsForm();
|
2011-09-17 10:22:07 -03:00
|
|
|
|
srtm.datadirectory = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "srtm";
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
var t = Type.GetType("Mono.Runtime");
|
2011-11-21 20:32:11 -04:00
|
|
|
|
MONO = (t != null);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
speechEngine = new Speech();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
MyRenderer.currentpressed = MenuFlightData;
|
|
|
|
|
|
|
|
|
|
MainMenu.Renderer = new MyRenderer();
|
|
|
|
|
|
|
|
|
|
foreach (object obj in Enum.GetValues(typeof(Firmwares)))
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.TOOL_APMFirmware.Items.Add(obj);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
if (_connectionControl.TOOL_APMFirmware.Items.Count > 0)
|
|
|
|
|
_connectionControl.TOOL_APMFirmware.SelectedIndex = 0;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
this.Text = splash.Text;
|
|
|
|
|
|
|
|
|
|
comPort.BaseStream.BaudRate = 115200;
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// ** Old
|
2012-05-08 10:21:19 -03:00
|
|
|
|
// CMB_serialport.Items.AddRange(SerialPort.GetPortNames());
|
|
|
|
|
// CMB_serialport.Items.Add("TCP");
|
|
|
|
|
// CMB_serialport.Items.Add("UDP");
|
|
|
|
|
// if (CMB_serialport.Items.Count > 0)
|
|
|
|
|
// {
|
|
|
|
|
// CMB_baudrate.SelectedIndex = 7;
|
|
|
|
|
// CMB_serialport.SelectedIndex = 0;
|
|
|
|
|
// }
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// ** new
|
2012-04-24 10:49:27 -03:00
|
|
|
|
_connectionControl.CMB_serialport.Items.AddRange(ArdupilotMega.Comms.SerialPort.GetPortNames());
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.CMB_serialport.Items.Add("TCP");
|
|
|
|
|
_connectionControl.CMB_serialport.Items.Add("UDP");
|
|
|
|
|
if (_connectionControl.CMB_serialport.Items.Count > 0)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.CMB_baudrate.SelectedIndex = 7;
|
|
|
|
|
_connectionControl.CMB_serialport.SelectedIndex = 0;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// ** Done
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
splash.Refresh();
|
|
|
|
|
Application.DoEvents();
|
|
|
|
|
|
|
|
|
|
// set this before we reset it
|
|
|
|
|
MainV2.config["NUM_tracklength"] = "200";
|
|
|
|
|
|
|
|
|
|
xmlconfig(false);
|
|
|
|
|
|
|
|
|
|
if (config.ContainsKey("language") && !string.IsNullOrEmpty((string)config["language"]))
|
2012-02-26 07:14:08 -04:00
|
|
|
|
changelanguage(CultureInfoEx.GetCultureInfo((string)config["language"]));
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-11-21 20:32:11 -04:00
|
|
|
|
if (!MONO) // windows only
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
if (MainV2.config["showconsole"] != null && MainV2.config["showconsole"].ToString() == "True")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int win = FindWindow("ConsoleWindowClass", null);
|
|
|
|
|
ShowWindow(win, SW_HIDE); // hide window
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
FlightData = new GCSViews.FlightData();
|
|
|
|
|
FlightPlanner = new GCSViews.FlightPlanner();
|
|
|
|
|
//Configuration = new GCSViews.Configuration();
|
|
|
|
|
Simulation = new GCSViews.Simulation();
|
|
|
|
|
Firmware = new GCSViews.Firmware();
|
|
|
|
|
//Terminal = new GCSViews.Terminal();
|
2011-12-04 18:43:29 -04:00
|
|
|
|
|
|
|
|
|
// preload
|
|
|
|
|
Python.CreateEngine();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
2012-03-09 11:18:12 -04:00
|
|
|
|
catch (Exception e) { CustomMessageBox.Show("A Major error has occured : " + e.ToString()); this.Close(); }
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-19 21:04:58 -03:00
|
|
|
|
if (MainV2.config["CHK_GDIPlus"] != null)
|
|
|
|
|
GCSViews.FlightData.myhud.UseOpenGL = !bool.Parse(MainV2.config["CHK_GDIPlus"].ToString());
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
ChangeUnits();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2011-12-12 08:22:13 -04:00
|
|
|
|
if (config["MainLocX"] != null && config["MainLocY"] != null)
|
|
|
|
|
{
|
|
|
|
|
this.StartPosition = FormStartPosition.Manual;
|
|
|
|
|
Point startpos = new Point(int.Parse(config["MainLocX"].ToString()), int.Parse(config["MainLocY"].ToString()));
|
|
|
|
|
this.Location = startpos;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-17 23:29:55 -03:00
|
|
|
|
if (config["MainMaximised"] != null)
|
2012-04-30 07:48:52 -03:00
|
|
|
|
{
|
2012-03-17 23:29:55 -03:00
|
|
|
|
this.WindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), config["MainMaximised"].ToString());
|
2012-04-30 07:48:52 -03:00
|
|
|
|
// dont allow minimised start state
|
|
|
|
|
if (this.WindowState == FormWindowState.Minimized)
|
|
|
|
|
{
|
|
|
|
|
this.WindowState = FormWindowState.Normal;
|
|
|
|
|
this.Location = new Point(100, 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-17 23:29:55 -03:00
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
if (config["MainHeight"] != null)
|
|
|
|
|
this.Height = int.Parse(config["MainHeight"].ToString());
|
|
|
|
|
if (config["MainWidth"] != null)
|
|
|
|
|
this.Width = int.Parse(config["MainWidth"].ToString());
|
2012-03-17 23:29:55 -03:00
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
if (config["CMB_rateattitude"] != null)
|
|
|
|
|
MainV2.cs.rateattitude = byte.Parse(config["CMB_rateattitude"].ToString());
|
2012-03-29 19:17:06 -03:00
|
|
|
|
if (config["rateposition"] != null)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
MainV2.cs.rateposition = byte.Parse(config["CMB_rateposition"].ToString());
|
2012-03-29 19:17:06 -03:00
|
|
|
|
if (config["CMB_ratestatus"] != null)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
MainV2.cs.ratestatus = byte.Parse(config["CMB_ratestatus"].ToString());
|
2012-03-29 19:17:06 -03:00
|
|
|
|
if (config["CMB_raterc"] != null)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
MainV2.cs.raterc = byte.Parse(config["CMB_raterc"].ToString());
|
2012-03-17 23:29:55 -03:00
|
|
|
|
if (config["CMB_ratesensors"] != null)
|
2012-03-29 19:17:06 -03:00
|
|
|
|
MainV2.cs.ratesensors = byte.Parse(config["CMB_ratesensors"].ToString());
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
if (config["speechenable"] != null)
|
2012-03-18 20:26:20 -03:00
|
|
|
|
MainV2.speechEnable = bool.Parse(config["speechenable"].ToString());
|
2012-03-17 23:29:55 -03:00
|
|
|
|
|
2012-03-06 06:27:43 -04:00
|
|
|
|
//int fixme;
|
|
|
|
|
/*
|
|
|
|
|
MainV2.cs.rateattitude = 50;
|
|
|
|
|
MainV2.cs.rateposition = 50;
|
|
|
|
|
MainV2.cs.ratestatus = 50;
|
|
|
|
|
MainV2.cs.raterc = 50;
|
|
|
|
|
MainV2.cs.ratesensors = 50;
|
|
|
|
|
*/
|
2011-12-12 08:22:13 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (config["TXT_homelat"] != null)
|
2012-02-14 10:13:11 -04:00
|
|
|
|
cs.HomeLocation.Lat = double.Parse(config["TXT_homelat"].ToString());
|
2011-12-12 08:22:13 -04:00
|
|
|
|
|
|
|
|
|
if (config["TXT_homelng"] != null)
|
2012-02-14 10:13:11 -04:00
|
|
|
|
cs.HomeLocation.Lng = double.Parse(config["TXT_homelng"].ToString());
|
2011-12-12 08:22:13 -04:00
|
|
|
|
|
|
|
|
|
if (config["TXT_homealt"] != null)
|
2012-02-14 10:13:11 -04:00
|
|
|
|
cs.HomeLocation.Alt = double.Parse(config["TXT_homealt"].ToString());
|
2011-12-12 08:22:13 -04:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
|
|
|
|
|
if (cs.rateattitude == 0) // initilised to 10, configured above from save
|
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("NOTE: your attitude rate is 0, the hud will not work\nChange in Configuration > Planner > Telemetry Rates");
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//System.Threading.Thread.Sleep(2000);
|
|
|
|
|
|
|
|
|
|
// make sure new enough .net framework is installed
|
2011-11-21 20:32:11 -04:00
|
|
|
|
if (!MONO)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
Microsoft.Win32.RegistryKey installed_versions = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP");
|
|
|
|
|
string[] version_names = installed_versions.GetSubKeyNames();
|
|
|
|
|
//version names start with 'v', eg, 'v3.5' which needs to be trimmed off before conversion
|
|
|
|
|
double Framework = Convert.ToDouble(version_names[version_names.Length - 1].Remove(0, 1), CultureInfo.InvariantCulture);
|
|
|
|
|
int SP = Convert.ToInt32(installed_versions.OpenSubKey(version_names[version_names.Length - 1]).GetValue("SP", 0));
|
|
|
|
|
|
2012-02-17 05:09:27 -04:00
|
|
|
|
if (Framework < 3.5)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("This program requires .NET Framework 3.5. You currently have " + Framework);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Application.DoEvents();
|
|
|
|
|
|
2012-01-23 09:36:20 -04:00
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
splash.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-08 10:21:19 -03:00
|
|
|
|
|
|
|
|
|
private void ResetConnectionStats()
|
|
|
|
|
{
|
|
|
|
|
// If the form has been closed, or never shown before, we need do nothing, as
|
|
|
|
|
// connection stats will be reset when shown
|
|
|
|
|
if (this.connectionStatsForm != null && connectionStatsForm.Visible)
|
|
|
|
|
{
|
|
|
|
|
// else the form is already showing. reset the stats
|
|
|
|
|
this.connectionStatsForm.Controls.Clear();
|
|
|
|
|
_connectionStats = new ConnectionStats(comPort);
|
|
|
|
|
this.connectionStatsForm.Controls.Add(_connectionStats);
|
|
|
|
|
ThemeManager.ApplyThemeTo(this.connectionStatsForm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowConnectionStatsForm()
|
|
|
|
|
{
|
|
|
|
|
if (this.connectionStatsForm == null || this.connectionStatsForm.IsDisposed)
|
|
|
|
|
{
|
|
|
|
|
// If the form has been closed, or never shown before, we need all new stuff
|
|
|
|
|
this.connectionStatsForm = new Form
|
|
|
|
|
{
|
|
|
|
|
Width = 430,
|
|
|
|
|
Height = 180,
|
|
|
|
|
MaximizeBox = false,
|
|
|
|
|
MinimizeBox = false,
|
|
|
|
|
FormBorderStyle = FormBorderStyle.FixedDialog,
|
|
|
|
|
Text = "Link Stats"
|
|
|
|
|
};
|
|
|
|
|
// Change the connection stats control, so that when/if the connection stats form is showing,
|
|
|
|
|
// there will be something to see
|
|
|
|
|
this.connectionStatsForm.Controls.Clear();
|
|
|
|
|
_connectionStats = new ConnectionStats(comPort);
|
|
|
|
|
this.connectionStatsForm.Controls.Add(_connectionStats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.connectionStatsForm.Show();
|
|
|
|
|
ThemeManager.ApplyThemeTo(this.connectionStatsForm);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// used to create planner screenshots - access by control-s
|
|
|
|
|
/// </summary>
|
2011-10-25 10:20:58 -03:00
|
|
|
|
internal void ScreenShot()
|
|
|
|
|
{
|
|
|
|
|
Rectangle bounds = Screen.GetBounds(Point.Empty);
|
|
|
|
|
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
|
|
|
|
|
{
|
|
|
|
|
using (Graphics g = Graphics.FromImage(bitmap))
|
|
|
|
|
{
|
|
|
|
|
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
|
|
|
|
|
}
|
2012-03-23 09:52:12 -03:00
|
|
|
|
string name = "ss" + DateTime.Now.ToString("HHmmss") + ".jpg";
|
2011-10-25 10:20:58 -03:00
|
|
|
|
bitmap.Save(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + name, System.Drawing.Imaging.ImageFormat.Jpeg);
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Screenshot saved to " + name);
|
2011-11-08 09:22:07 -04:00
|
|
|
|
}
|
2011-10-25 10:20:58 -03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
private void CMB_serialport_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
string oldport = _connectionControl.CMB_serialport.Text;
|
|
|
|
|
_connectionControl.CMB_serialport.Items.Clear();
|
2012-04-24 10:49:27 -03:00
|
|
|
|
_connectionControl.CMB_serialport.Items.AddRange(ArdupilotMega.Comms.SerialPort.GetPortNames());
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.CMB_serialport.Items.Add("TCP");
|
|
|
|
|
_connectionControl.CMB_serialport.Items.Add("UDP");
|
|
|
|
|
if (_connectionControl.CMB_serialport.Items.Contains(oldport))
|
|
|
|
|
_connectionControl.CMB_serialport.Text = oldport;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void MenuFlightData_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MyView.Controls.Clear();
|
|
|
|
|
|
|
|
|
|
GCSViews.Terminal.threadrun = false;
|
|
|
|
|
|
|
|
|
|
UserControl temp = FlightData;
|
|
|
|
|
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(temp);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
temp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
|
|
|
|
|
|
|
|
|
|
temp.Location = new Point(0, MainMenu.Height);
|
|
|
|
|
|
|
|
|
|
temp.Dock = DockStyle.Fill;
|
|
|
|
|
|
|
|
|
|
MyView.Controls.Add(temp);
|
|
|
|
|
|
|
|
|
|
if (MainV2.config["FlightSplitter"] != null)
|
|
|
|
|
((GCSViews.FlightData)temp).MainHcopy.SplitterDistance = int.Parse(MainV2.config["FlightSplitter"].ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MenuFlightPlanner_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MyView.Controls.Clear();
|
|
|
|
|
|
|
|
|
|
GCSViews.Terminal.threadrun = false;
|
|
|
|
|
|
|
|
|
|
UserControl temp = FlightPlanner;
|
|
|
|
|
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(temp);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
temp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
|
|
|
|
|
|
|
|
|
|
temp.Location = new Point(0, MainMenu.Height);
|
|
|
|
|
|
|
|
|
|
temp.Dock = DockStyle.Fill;
|
|
|
|
|
|
2012-04-23 09:06:01 -03:00
|
|
|
|
// refresh ap/ac specific items
|
|
|
|
|
FlightPlanner.updateCMDParams();
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
MyView.Controls.Add(temp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MenuConfiguration_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MyView.Controls.Clear();
|
|
|
|
|
|
|
|
|
|
GCSViews.Terminal.threadrun = false;
|
|
|
|
|
|
2011-10-25 10:20:58 -03:00
|
|
|
|
// dispose of old else memory leak
|
|
|
|
|
if (Configuration != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Configuration.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-25 07:10:11 -03:00
|
|
|
|
//Configuration = new GCSViews.Configuration();
|
|
|
|
|
Configuration = new GCSViews.ConfigurationView.Setup();
|
2011-10-25 10:20:58 -03:00
|
|
|
|
|
|
|
|
|
UserControl temp = Configuration;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(temp);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-10-29 00:34:38 -03:00
|
|
|
|
temp.Location = new Point(0, 0);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
temp.Dock = DockStyle.Fill;
|
|
|
|
|
|
2011-11-08 09:22:07 -04:00
|
|
|
|
temp.Size = MyView.Size;
|
2011-10-29 00:34:38 -03:00
|
|
|
|
|
2011-11-08 09:22:07 -04:00
|
|
|
|
MyView.Controls.Add(temp);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MenuSimulation_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MyView.Controls.Clear();
|
|
|
|
|
|
|
|
|
|
GCSViews.Terminal.threadrun = false;
|
|
|
|
|
|
|
|
|
|
UserControl temp = Simulation;
|
|
|
|
|
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(temp);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
temp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
|
|
|
|
|
|
|
|
|
|
temp.Location = new Point(0, MainMenu.Height);
|
|
|
|
|
|
|
|
|
|
temp.Dock = DockStyle.Fill;
|
|
|
|
|
|
|
|
|
|
MyView.Controls.Add(temp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MenuFirmware_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MyView.Controls.Clear();
|
|
|
|
|
|
|
|
|
|
GCSViews.Terminal.threadrun = false;
|
|
|
|
|
|
|
|
|
|
UserControl temp = Firmware;
|
|
|
|
|
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(temp);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
temp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
|
|
|
|
|
|
|
|
|
|
temp.Dock = DockStyle.Fill;
|
|
|
|
|
|
2012-01-27 04:01:28 -04:00
|
|
|
|
MyView.Controls.Add(temp);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MenuTerminal_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (comPort.BaseStream.IsOpen)
|
|
|
|
|
{
|
|
|
|
|
MenuConnect_Click(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
giveComport = true;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
MyView.Controls.Clear();
|
|
|
|
|
|
|
|
|
|
this.MenuConnect.BackgroundImage = global::ArdupilotMega.Properties.Resources.disconnect;
|
|
|
|
|
|
2011-10-29 00:34:38 -03:00
|
|
|
|
// dispose of old else memory leak
|
|
|
|
|
if (Terminal != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Terminal.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Terminal = new GCSViews.Terminal();
|
|
|
|
|
|
|
|
|
|
UserControl temp = Terminal;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(temp);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
temp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
|
|
|
|
|
|
|
|
|
|
temp.Dock = DockStyle.Fill;
|
|
|
|
|
|
|
|
|
|
MyView.Controls.Add(temp);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MenuConnect_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
giveComport = false;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-01-11 13:33:42 -04:00
|
|
|
|
if (comPort.BaseStream.IsOpen && cs.groundspeed > 4)
|
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
if (DialogResult.No == CustomMessageBox.Show("Your model is still moving are you sure you want to disconnect?", "Disconnect", MessageBoxButtons.YesNo))
|
2012-01-11 13:33:42 -04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
if (comPort.BaseStream.IsOpen)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2012-02-29 09:19:54 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (speechEngine != null) // cancel all pending speech
|
|
|
|
|
speechEngine.SpeakAsyncCancelAll();
|
2012-02-29 09:19:54 -04:00
|
|
|
|
}
|
2012-05-08 10:21:19 -03:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error(ex);
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
if (comPort.logfile != null)
|
|
|
|
|
comPort.logfile.Close();
|
|
|
|
|
|
2012-03-26 07:21:49 -03:00
|
|
|
|
if (comPort.rawlogfile != null)
|
|
|
|
|
comPort.rawlogfile.Close();
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
comPort.BaseStream.DtrEnable = false;
|
|
|
|
|
comPort.Close();
|
|
|
|
|
}
|
2012-05-08 10:21:19 -03:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error(ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now that we have closed the connection, cancel the connection stats
|
|
|
|
|
// so that the 'time connected' etc does not grow, but the user can still
|
|
|
|
|
// look at the now frozen stats on the still open form
|
|
|
|
|
((ConnectionStats)this.connectionStatsForm.Controls[0]).StopUpdates();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
this.MenuConnect.BackgroundImage = global::ArdupilotMega.Properties.Resources.connect;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-05-08 10:21:19 -03:00
|
|
|
|
switch (_connectionControl.CMB_serialport.Text)
|
2011-10-12 10:37:39 -03:00
|
|
|
|
{
|
2012-05-08 10:21:19 -03:00
|
|
|
|
case "TCP":
|
|
|
|
|
comPort.BaseStream = new TcpSerial();
|
|
|
|
|
break;
|
|
|
|
|
case "UDP":
|
|
|
|
|
comPort.BaseStream = new UdpSerial();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
comPort.BaseStream = new Comms.SerialPort();
|
|
|
|
|
break;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-08 10:21:19 -03:00
|
|
|
|
// Tell the connection UI that we are now connected.
|
|
|
|
|
this._connectionControl.IsConnected(true);
|
|
|
|
|
|
|
|
|
|
// Here we want to reset the connection stats counter etc.
|
|
|
|
|
this.ResetConnectionStats();
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-04-19 21:05:33 -03:00
|
|
|
|
// set port, then options
|
2012-04-21 04:30:15 -03:00
|
|
|
|
comPort.BaseStream.PortName = _connectionControl.CMB_serialport.Text;
|
2012-03-23 09:52:12 -03:00
|
|
|
|
|
2012-04-19 21:05:33 -03:00
|
|
|
|
comPort.BaseStream.DataBits = 8;
|
|
|
|
|
comPort.BaseStream.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "1");
|
|
|
|
|
comPort.BaseStream.Parity = (Parity)Enum.Parse(typeof(Parity), "None");
|
|
|
|
|
try
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
comPort.BaseStream.BaudRate = int.Parse(_connectionControl.CMB_baudrate.Text);
|
2012-04-19 21:05:33 -03:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// false here
|
|
|
|
|
comPort.BaseStream.DtrEnable = false;
|
|
|
|
|
comPort.BaseStream.RtsEnable = false;
|
2012-03-23 09:52:12 -03:00
|
|
|
|
|
2012-04-23 09:06:01 -03:00
|
|
|
|
if (config["CHK_resetapmonconnect"] == null || bool.Parse(config["CHK_resetapmonconnect"].ToString()) == true)
|
|
|
|
|
comPort.BaseStream.toggleDTR();
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// cleanup from any previous sessions
|
2011-09-08 22:31:32 -03:00
|
|
|
|
if (comPort.logfile != null)
|
|
|
|
|
comPort.logfile.Close();
|
2012-03-26 07:21:49 -03:00
|
|
|
|
|
|
|
|
|
if (comPort.rawlogfile != null)
|
|
|
|
|
comPort.rawlogfile.Close();
|
2012-04-21 04:30:15 -03:00
|
|
|
|
|
|
|
|
|
// setup to record new logs
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"logs");
|
2012-03-21 09:13:08 -03:00
|
|
|
|
comPort.logfile = new BinaryWriter(File.Open(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"logs" + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".tlog", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read));
|
2012-03-26 07:21:49 -03:00
|
|
|
|
|
|
|
|
|
comPort.rawlogfile = new BinaryWriter(File.Open(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"logs" + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".rlog", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read));
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
2012-03-09 11:18:12 -04:00
|
|
|
|
catch { CustomMessageBox.Show("Failed to create log - wont log this session"); } // soft fail
|
2011-12-15 20:17:13 -04:00
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// do the connect
|
2011-09-08 22:31:32 -03:00
|
|
|
|
comPort.Open(true);
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// detect firmware we are conected to.
|
2011-09-08 22:31:32 -03:00
|
|
|
|
if (comPort.param["SYSID_SW_TYPE"] != null)
|
|
|
|
|
{
|
|
|
|
|
if (float.Parse(comPort.param["SYSID_SW_TYPE"].ToString()) == 10)
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.TOOL_APMFirmware.SelectedIndex = _connectionControl.TOOL_APMFirmware.Items.IndexOf(Firmwares.ArduCopter2);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
else if (float.Parse(comPort.param["SYSID_SW_TYPE"].ToString()) == 0)
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.TOOL_APMFirmware.SelectedIndex = _connectionControl.TOOL_APMFirmware.Items.IndexOf(Firmwares.ArduPlane);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// save the baudrate for this port
|
|
|
|
|
config[_connectionControl.CMB_serialport.Text + "_BAUD"] = _connectionControl.CMB_baudrate.Text;
|
2011-10-25 10:20:58 -03:00
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// load wps on connect option.
|
2011-09-08 22:31:32 -03:00
|
|
|
|
if (config["loadwpsonconnect"] != null && bool.Parse(config["loadwpsonconnect"].ToString()) == true)
|
|
|
|
|
{
|
|
|
|
|
MenuFlightPlanner_Click(null, null);
|
|
|
|
|
FlightPlanner.BUT_read_Click(null, null);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// set connected icon
|
2011-09-08 22:31:32 -03:00
|
|
|
|
this.MenuConnect.BackgroundImage = global::ArdupilotMega.Properties.Resources.disconnect;
|
|
|
|
|
}
|
2011-11-08 09:22:07 -04:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
log.Warn(ex.ToString());
|
2011-11-08 09:22:07 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
comPort.Close();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// detect firmware -> scan eeprom contents -> error if no valid ap param/apvar header detected.
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string version = ArduinoDetect.DetectVersion(comPort.BaseStream.PortName);
|
|
|
|
|
ArduinoComms port = new ArduinoSTK();
|
|
|
|
|
if (version == "1280")
|
|
|
|
|
{
|
|
|
|
|
port = new ArduinoSTK();
|
|
|
|
|
port.BaudRate = 57600;
|
|
|
|
|
}
|
|
|
|
|
else if (version == "2560")
|
|
|
|
|
{
|
|
|
|
|
port = new ArduinoSTKv2();
|
|
|
|
|
port.BaudRate = 115200;
|
|
|
|
|
}
|
|
|
|
|
else { throw new Exception("Can not determine APM board type"); }
|
|
|
|
|
port.PortName = comPort.BaseStream.PortName;
|
|
|
|
|
port.DtrEnable = true;
|
|
|
|
|
port.Open();
|
|
|
|
|
if (port.connectAP())
|
|
|
|
|
{
|
|
|
|
|
byte[] buffer = port.download(20);
|
|
|
|
|
port.Close();
|
|
|
|
|
|
2012-02-20 07:30:47 -04:00
|
|
|
|
if ((buffer[0] == 'A' || buffer[0] == 'P') && (buffer[1] == 'A' || buffer[1] == 'P')) // this is the apvar header
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info("Valid eeprom contents");
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("You dont appear to have uploaded a firmware yet,\n\nPlease goto the firmware page and upload one.");
|
2012-02-20 07:30:47 -04:00
|
|
|
|
return;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
2012-02-29 09:19:54 -04:00
|
|
|
|
log.Debug(ex.ToString());
|
2012-02-20 07:30:47 -04:00
|
|
|
|
//MessageBox.Show("Can not establish a connection\n\n" + ex.ToString());
|
2011-11-08 09:22:07 -04:00
|
|
|
|
return;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CMB_serialport_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
comPortName = _connectionControl.CMB_serialport.Text;
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (comPortName == "UDP" || comPortName == "TCP")
|
2011-11-19 20:17:17 -04:00
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.CMB_baudrate.Enabled = false;
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (comPortName == "TCP")
|
2011-11-19 20:17:17 -04:00
|
|
|
|
MainV2.comPort.BaseStream = new TcpSerial();
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (comPortName == "UDP")
|
2011-11-19 20:17:17 -04:00
|
|
|
|
MainV2.comPort.BaseStream = new UdpSerial();
|
|
|
|
|
}
|
2011-09-22 09:32:43 -03:00
|
|
|
|
else
|
2011-11-19 20:17:17 -04:00
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.CMB_baudrate.Enabled = true;
|
2012-04-24 10:49:27 -03:00
|
|
|
|
MainV2.comPort.BaseStream = new ArdupilotMega.Comms.SerialPort();
|
2011-11-19 20:17:17 -04:00
|
|
|
|
}
|
2011-09-22 20:33:25 -03:00
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
comPort.BaseStream.PortName = _connectionControl.CMB_serialport.Text;
|
2011-10-25 10:20:58 -03:00
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
MainV2.comPort.BaseStream.BaudRate = int.Parse(_connectionControl.CMB_baudrate.Text);
|
2012-01-05 18:54:47 -04:00
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// check for saved baud rate and restore
|
|
|
|
|
if (config[_connectionControl.CMB_serialport.Text + "_BAUD"] != null)
|
2011-11-24 20:07:14 -04:00
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.CMB_baudrate.Text = config[_connectionControl.CMB_serialport.Text + "_BAUD"].ToString();
|
2011-11-24 20:07:14 -04:00
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainV2_FormClosed(object sender, FormClosedEventArgs e)
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// shutdown threads
|
2011-09-08 22:31:32 -03:00
|
|
|
|
GCSViews.FlightData.threadrun = 0;
|
|
|
|
|
GCSViews.Simulation.threadrun = 0;
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// shutdown local thread
|
2012-03-18 20:26:20 -03:00
|
|
|
|
serialThread = false;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (comPort.BaseStream.IsOpen)
|
|
|
|
|
comPort.Close();
|
|
|
|
|
}
|
|
|
|
|
catch { } // i get alot of these errors, the port is still open, but not valid - user has unpluged usb
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
FlightData.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
FlightPlanner.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Simulation.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
|
|
|
|
|
// save config
|
2011-09-08 22:31:32 -03:00
|
|
|
|
xmlconfig(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void xmlconfig(bool write)
|
|
|
|
|
{
|
|
|
|
|
if (write || !File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"config.xml"))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
XmlTextWriter xmlwriter = new XmlTextWriter(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"config.xml", Encoding.ASCII);
|
|
|
|
|
xmlwriter.Formatting = Formatting.Indented;
|
|
|
|
|
|
|
|
|
|
xmlwriter.WriteStartDocument();
|
|
|
|
|
|
|
|
|
|
xmlwriter.WriteStartElement("Config");
|
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
xmlwriter.WriteElementString("comport", comPortName);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
xmlwriter.WriteElementString("baudrate", _connectionControl.CMB_baudrate.Text);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
xmlwriter.WriteElementString("APMFirmware", MainV2.cs.firmware.ToString());
|
2011-09-18 07:07:18 -03:00
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
foreach (string key in config.Keys)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2011-12-12 08:22:13 -04:00
|
|
|
|
if (key == "" || key.Contains("/")) // "/dev/blah"
|
2011-09-08 22:31:32 -03:00
|
|
|
|
continue;
|
|
|
|
|
xmlwriter.WriteElementString(key, config[key].ToString());
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xmlwriter.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
xmlwriter.WriteEndDocument();
|
|
|
|
|
xmlwriter.Close();
|
|
|
|
|
}
|
2012-03-09 11:18:12 -04:00
|
|
|
|
catch (Exception ex) { CustomMessageBox.Show(ex.ToString()); }
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (XmlTextReader xmlreader = new XmlTextReader(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"config.xml"))
|
|
|
|
|
{
|
|
|
|
|
while (xmlreader.Read())
|
|
|
|
|
{
|
|
|
|
|
xmlreader.MoveToElement();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (xmlreader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "comport":
|
|
|
|
|
string temp = xmlreader.ReadString();
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.CMB_serialport.SelectedIndex = _connectionControl.CMB_serialport.FindString(temp);
|
|
|
|
|
if (_connectionControl.CMB_serialport.SelectedIndex == -1)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.CMB_serialport.Text = temp; // allows ports that dont exist - yet
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
comPort.BaseStream.PortName = temp;
|
2012-03-18 20:26:20 -03:00
|
|
|
|
comPortName = temp;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
break;
|
|
|
|
|
case "baudrate":
|
|
|
|
|
string temp2 = xmlreader.ReadString();
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.CMB_baudrate.SelectedIndex = _connectionControl.CMB_baudrate.FindString(temp2);
|
|
|
|
|
if (_connectionControl.CMB_baudrate.SelectedIndex == -1)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.CMB_baudrate.Text = temp2;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
//CMB_baudrate.SelectedIndex = CMB_baudrate.FindString("57600"); ; // must exist
|
|
|
|
|
}
|
|
|
|
|
//bau = int.Parse(CMB_baudrate.Text);
|
|
|
|
|
break;
|
|
|
|
|
case "APMFirmware":
|
|
|
|
|
string temp3 = xmlreader.ReadString();
|
2012-04-21 04:30:15 -03:00
|
|
|
|
_connectionControl.TOOL_APMFirmware.SelectedIndex = _connectionControl.TOOL_APMFirmware.FindStringExact(temp3);
|
|
|
|
|
if (_connectionControl.TOOL_APMFirmware.SelectedIndex == -1)
|
|
|
|
|
_connectionControl.TOOL_APMFirmware.SelectedIndex = 0;
|
|
|
|
|
MainV2.cs.firmware = (MainV2.Firmwares)Enum.Parse(typeof(MainV2.Firmwares), _connectionControl.TOOL_APMFirmware.Text);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
break;
|
|
|
|
|
case "Config":
|
|
|
|
|
break;
|
|
|
|
|
case "xml":
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (xmlreader.Name == "") // line feeds
|
|
|
|
|
break;
|
|
|
|
|
config[xmlreader.Name] = xmlreader.ReadString();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-08 10:21:19 -03:00
|
|
|
|
// silent fail on bad entry
|
|
|
|
|
catch (Exception ee)
|
|
|
|
|
{
|
|
|
|
|
log.Error(ee);
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-08 10:21:19 -03:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error("Bad Config File", ex);
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CMB_baudrate_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
comPort.BaseStream.BaudRate = int.Parse(_connectionControl.CMB_baudrate.Text);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// thread used to send joystick packets to the MAV
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
private void joysticksend()
|
|
|
|
|
{
|
2012-04-06 05:27:26 -03:00
|
|
|
|
|
|
|
|
|
float rate = 50;
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
DateTime lastratechange = DateTime.Now;
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2011-11-21 20:32:11 -04:00
|
|
|
|
if (!MONO)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
//joystick stuff
|
|
|
|
|
|
|
|
|
|
if (joystick != null && joystick.enabled)
|
|
|
|
|
{
|
2012-04-05 21:50:04 -03:00
|
|
|
|
MAVLink.mavlink_rc_channels_override_t rc = new MAVLink.mavlink_rc_channels_override_t();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
rc.target_component = comPort.compid;
|
|
|
|
|
rc.target_system = comPort.sysid;
|
|
|
|
|
|
2011-10-23 06:48:00 -03:00
|
|
|
|
if (joystick.getJoystickAxis(1) != Joystick.joystickaxis.None)
|
|
|
|
|
rc.chan1_raw = cs.rcoverridech1;//(ushort)(((int)state.Rz / 65.535) + 1000);
|
|
|
|
|
if (joystick.getJoystickAxis(2) != Joystick.joystickaxis.None)
|
|
|
|
|
rc.chan2_raw = cs.rcoverridech2;//(ushort)(((int)state.Y / 65.535) + 1000);
|
|
|
|
|
if (joystick.getJoystickAxis(3) != Joystick.joystickaxis.None)
|
|
|
|
|
rc.chan3_raw = cs.rcoverridech3;//(ushort)(1000 - ((int)slider[0] / 65.535 ) + 1000);
|
|
|
|
|
if (joystick.getJoystickAxis(4) != Joystick.joystickaxis.None)
|
|
|
|
|
rc.chan4_raw = cs.rcoverridech4;//(ushort)(((int)state.X / 65.535) + 1000);
|
|
|
|
|
if (joystick.getJoystickAxis(5) != Joystick.joystickaxis.None)
|
|
|
|
|
rc.chan5_raw = cs.rcoverridech5;
|
|
|
|
|
if (joystick.getJoystickAxis(6) != Joystick.joystickaxis.None)
|
|
|
|
|
rc.chan6_raw = cs.rcoverridech6;
|
|
|
|
|
if (joystick.getJoystickAxis(7) != Joystick.joystickaxis.None)
|
|
|
|
|
rc.chan7_raw = cs.rcoverridech7;
|
|
|
|
|
if (joystick.getJoystickAxis(8) != Joystick.joystickaxis.None)
|
|
|
|
|
rc.chan8_raw = cs.rcoverridech8;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-04-06 05:27:26 -03:00
|
|
|
|
if (lastjoystick.AddMilliseconds(rate) < DateTime.Now)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-04-06 05:27:26 -03:00
|
|
|
|
/*
|
|
|
|
|
if (cs.rssi > 0 && cs.remrssi > 0)
|
|
|
|
|
{
|
|
|
|
|
if (lastratechange.Second != DateTime.Now.Second)
|
|
|
|
|
{
|
|
|
|
|
if (cs.txbuffer > 90)
|
|
|
|
|
{
|
|
|
|
|
if (rate < 20)
|
|
|
|
|
rate = 21;
|
|
|
|
|
rate--;
|
|
|
|
|
|
|
|
|
|
if (cs.linkqualitygcs < 70)
|
|
|
|
|
rate = 50;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (rate > 100)
|
|
|
|
|
rate = 100;
|
|
|
|
|
rate++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastratechange = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
*/
|
2012-05-08 10:21:19 -03:00
|
|
|
|
// Console.WriteLine(DateTime.Now.Millisecond + " {0} {1} {2} {3} {4}", rc.chan1_raw, rc.chan2_raw, rc.chan3_raw, rc.chan4_raw,rate);
|
2011-11-08 09:22:07 -04:00
|
|
|
|
comPort.sendPacket(rc);
|
2012-04-06 05:27:26 -03:00
|
|
|
|
count++;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
lastjoystick = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-08 10:21:19 -03:00
|
|
|
|
Thread.Sleep(20);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
2012-05-08 10:21:19 -03:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
} // cant fall out
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to fix the icon status for unexpected unplugs etc...
|
|
|
|
|
/// </summary>
|
2012-05-08 10:21:19 -03:00
|
|
|
|
private void UpdateConnectIcon()
|
2012-03-18 20:26:20 -03:00
|
|
|
|
{
|
2012-03-21 09:13:08 -03:00
|
|
|
|
if ((DateTime.Now - connectButtonUpdate).Milliseconds > 500)
|
2012-03-18 20:26:20 -03:00
|
|
|
|
{
|
|
|
|
|
// Console.WriteLine(DateTime.Now.Millisecond);
|
|
|
|
|
if (comPort.BaseStream.IsOpen)
|
|
|
|
|
{
|
|
|
|
|
if ((string)this.MenuConnect.BackgroundImage.Tag != "Disconnect")
|
|
|
|
|
{
|
|
|
|
|
this.Invoke((MethodInvoker)delegate
|
|
|
|
|
{
|
|
|
|
|
this.MenuConnect.BackgroundImage = global::ArdupilotMega.Properties.Resources.disconnect;
|
|
|
|
|
this.MenuConnect.BackgroundImage.Tag = "Disconnect";
|
2012-05-08 10:21:19 -03:00
|
|
|
|
_connectionControl.IsConnected(true);
|
2012-03-18 20:26:20 -03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((string)this.MenuConnect.BackgroundImage.Tag != "Connect")
|
|
|
|
|
{
|
|
|
|
|
this.Invoke((MethodInvoker)delegate
|
|
|
|
|
{
|
|
|
|
|
this.MenuConnect.BackgroundImage = global::ArdupilotMega.Properties.Resources.connect;
|
|
|
|
|
this.MenuConnect.BackgroundImage.Tag = "Connect";
|
2012-05-08 10:21:19 -03:00
|
|
|
|
_connectionControl.IsConnected(false);
|
|
|
|
|
if (_connectionStats != null)
|
|
|
|
|
_connectionStats.StopUpdates();
|
2012-03-18 20:26:20 -03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-21 09:13:08 -03:00
|
|
|
|
connectButtonUpdate = DateTime.Now;
|
2012-03-18 20:26:20 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// main serial reader thread
|
|
|
|
|
/// controls
|
|
|
|
|
/// serial reading
|
|
|
|
|
/// link quality stats
|
|
|
|
|
/// speech voltage - custom - alt warning - data lost
|
|
|
|
|
/// heartbeat packet sending
|
|
|
|
|
///
|
|
|
|
|
/// and cant fall out
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
private void SerialReader()
|
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (serialThread == true)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
return;
|
2012-03-18 20:26:20 -03:00
|
|
|
|
serialThread = true;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
int minbytes = 10;
|
|
|
|
|
|
2011-11-21 20:32:11 -04:00
|
|
|
|
if (MONO)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
minbytes = 0;
|
|
|
|
|
|
|
|
|
|
DateTime speechcustomtime = DateTime.Now;
|
|
|
|
|
|
2011-09-17 12:49:32 -03:00
|
|
|
|
DateTime linkqualitytime = DateTime.Now;
|
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
while (serialThread)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2012-05-08 10:21:19 -03:00
|
|
|
|
Thread.Sleep(5);
|
|
|
|
|
|
|
|
|
|
UpdateConnectIcon();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (speechEnable && speechEngine != null && (DateTime.Now - speechcustomtime).TotalSeconds > 30 && MainV2.cs.lat != 0 && (MainV2.comPort.logreadmode || comPort.BaseStream.IsOpen))
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
//speechbatteryvolt
|
|
|
|
|
float warnvolt = 0;
|
|
|
|
|
float.TryParse(MainV2.getConfig("speechbatteryvolt"), out warnvolt);
|
|
|
|
|
|
|
|
|
|
if (MainV2.getConfig("speechbatteryenabled") == "True" && MainV2.cs.battery_voltage <= warnvolt)
|
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
MainV2.speechEngine.SpeakAsync(Common.speechConversion(MainV2.getConfig("speechbattery")));
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MainV2.getConfig("speechcustomenabled") == "True")
|
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
MainV2.speechEngine.SpeakAsync(Common.speechConversion(MainV2.getConfig("speechcustom")));
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
speechcustomtime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-17 12:49:32 -03:00
|
|
|
|
if ((DateTime.Now - comPort.lastvalidpacket).TotalSeconds > 10)
|
|
|
|
|
{
|
|
|
|
|
MainV2.cs.linkqualitygcs = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((DateTime.Now - comPort.lastvalidpacket).TotalSeconds >= 1)
|
|
|
|
|
{
|
|
|
|
|
if (linkqualitytime.Second != DateTime.Now.Second)
|
|
|
|
|
{
|
|
|
|
|
MainV2.cs.linkqualitygcs = (ushort)(MainV2.cs.linkqualitygcs * 0.8f);
|
|
|
|
|
linkqualitytime = DateTime.Now;
|
2011-09-18 07:07:18 -03:00
|
|
|
|
|
|
|
|
|
GCSViews.FlightData.myhud.Invalidate();
|
2011-09-17 12:49:32 -03:00
|
|
|
|
}
|
2012-01-27 04:01:28 -04:00
|
|
|
|
|
|
|
|
|
GC.Collect();
|
2011-09-17 12:49:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (speechEnable && speechEngine != null && (MainV2.comPort.logreadmode || comPort.BaseStream.IsOpen))
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
float warnalt = float.MaxValue;
|
|
|
|
|
float.TryParse(MainV2.getConfig("speechaltheight"), out warnalt);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (MainV2.getConfig("speechaltenabled") == "True" && (MainV2.cs.alt - (int)double.Parse(MainV2.getConfig("TXT_homealt"))) <= warnalt)
|
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (MainV2.speechEngine.State == SynthesizerState.Ready)
|
|
|
|
|
MainV2.speechEngine.SpeakAsync(Common.speechConversion(MainV2.getConfig("speechalt")));
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { } // silent fail
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (!comPort.BaseStream.IsOpen || giveComport == true)
|
2012-01-27 04:01:28 -04:00
|
|
|
|
{
|
|
|
|
|
System.Threading.Thread.Sleep(100);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
continue;
|
2012-01-27 04:01:28 -04:00
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (heatbeatSend.Second != DateTime.Now.Second)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2011-12-15 20:17:13 -04:00
|
|
|
|
// Console.WriteLine("remote lost {0}", cs.packetdropremote);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-04-05 21:50:04 -03:00
|
|
|
|
MAVLink.mavlink_heartbeat_t htb = new MAVLink.mavlink_heartbeat_t();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-11-08 09:22:07 -04:00
|
|
|
|
#if MAVLINK10
|
2012-04-06 20:51:00 -03:00
|
|
|
|
htb.type = (byte)MAVLink.MAV_TYPE.GCS;
|
|
|
|
|
htb.autopilot = (byte)MAVLink.MAV_AUTOPILOT.ARDUPILOTMEGA;
|
2011-11-08 09:22:07 -04:00
|
|
|
|
htb.mavlink_version = 3;
|
|
|
|
|
#else
|
2011-09-08 22:31:32 -03:00
|
|
|
|
htb.type = (byte)MAVLink.MAV_TYPE.MAV_GENERIC;
|
|
|
|
|
htb.autopilot = (byte)MAVLink.MAV_AUTOPILOT_TYPE.MAV_AUTOPILOT_ARDUPILOTMEGA;
|
|
|
|
|
htb.mavlink_version = 2;
|
2011-11-08 09:22:07 -04:00
|
|
|
|
#endif
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-11-08 09:22:07 -04:00
|
|
|
|
comPort.sendPacket(htb);
|
2012-03-18 20:26:20 -03:00
|
|
|
|
heatbeatSend = DateTime.Now;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// data loss warning
|
2011-09-17 10:22:07 -03:00
|
|
|
|
if ((DateTime.Now - comPort.lastvalidpacket).TotalSeconds > 10)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (speechEnable && speechEngine != null)
|
2011-11-08 09:22:07 -04:00
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
if (MainV2.speechEngine.State == SynthesizerState.Ready)
|
|
|
|
|
MainV2.speechEngine.SpeakAsync("WARNING No Data for " + (int)(DateTime.Now - comPort.lastvalidpacket).TotalSeconds + " Seconds");
|
2011-09-17 10:22:07 -03:00
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
//Console.WriteLine(DateTime.Now.Millisecond + " " + comPort.BaseStream.BytesToRead);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
while (comPort.BaseStream.BytesToRead > minbytes && giveComport == false)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
comPort.readPacket();
|
|
|
|
|
}
|
2011-11-08 09:22:07 -04:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2012-05-08 10:21:19 -03:00
|
|
|
|
log.Error("Serial Reader fail :" + e.Message);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
comPort.Close();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-08 10:21:19 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Override the stock ToolStripProfessionalRenderer to implement 'highlighting' of the
|
|
|
|
|
/// currently selected GCS view.
|
|
|
|
|
/// </summary>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
private class MyRenderer : ToolStripProfessionalRenderer
|
|
|
|
|
{
|
|
|
|
|
public static ToolStripItem currentpressed;
|
|
|
|
|
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//BackgroundImage
|
|
|
|
|
if (e.Item.BackgroundImage == null) base.OnRenderButtonBackground(e);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Rectangle bounds = new Rectangle(Point.Empty, e.Item.Size);
|
|
|
|
|
e.Graphics.DrawImage(e.Item.BackgroundImage, bounds);
|
|
|
|
|
if (e.Item.Pressed || e.Item == currentpressed)
|
|
|
|
|
{
|
|
|
|
|
SolidBrush brush = new SolidBrush(Color.FromArgb(73, 0x2b, 0x3a, 0x03));
|
|
|
|
|
e.Graphics.FillRectangle(brush, bounds);
|
|
|
|
|
if (e.Item.Name != "MenuConnect")
|
|
|
|
|
{
|
|
|
|
|
//Console.WriteLine("new " + e.Item.Name + " old " + currentpressed.Name );
|
|
|
|
|
//e.Item.GetCurrentParent().Invalidate();
|
|
|
|
|
if (currentpressed != e.Item)
|
|
|
|
|
currentpressed.Invalidate();
|
|
|
|
|
currentpressed = e.Item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Something...
|
|
|
|
|
}
|
|
|
|
|
else if (e.Item.Selected) // mouse over
|
|
|
|
|
{
|
|
|
|
|
SolidBrush brush = new SolidBrush(Color.FromArgb(73, 0x2b, 0x3a, 0x03));
|
|
|
|
|
e.Graphics.FillRectangle(brush, bounds);
|
|
|
|
|
// Something...
|
|
|
|
|
}
|
|
|
|
|
using (Pen pen = new Pen(Color.Black))
|
|
|
|
|
{
|
|
|
|
|
//e.Graphics.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//base.OnRenderItemImage(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainV2_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
// init button depressed
|
2011-09-08 22:31:32 -03:00
|
|
|
|
MenuFlightData_Click(sender, e);
|
|
|
|
|
|
2012-03-09 11:18:12 -04:00
|
|
|
|
// for long running tasks using own threads.
|
|
|
|
|
// for short use threadpool
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// setup http server
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
listener = new TcpListener(IPAddress.Any, 56781);
|
2012-03-18 20:26:20 -03:00
|
|
|
|
new Thread(listernforclients)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
Name = "motion jpg stream-network kml",
|
2011-09-08 22:31:32 -03:00
|
|
|
|
IsBackground = true
|
2012-03-18 20:26:20 -03:00
|
|
|
|
}.Start();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Error("Error starting TCP listener thread: ", ex);
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show(ex.ToString());
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// setup joystick packet sender
|
2012-03-18 20:26:20 -03:00
|
|
|
|
new Thread(new ThreadStart(joysticksend))
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
IsBackground = true,
|
|
|
|
|
Priority = ThreadPriority.AboveNormal,
|
|
|
|
|
Name = "Main joystick sender"
|
2012-03-18 20:26:20 -03:00
|
|
|
|
}.Start();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
// setup main serial reader
|
2012-03-18 20:26:20 -03:00
|
|
|
|
new Thread(SerialReader)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
IsBackground = true,
|
|
|
|
|
Name = "Main Serial reader"
|
2012-03-18 20:26:20 -03:00
|
|
|
|
}.Start();
|
2012-01-23 09:36:20 -04:00
|
|
|
|
|
2012-04-29 21:32:33 -03:00
|
|
|
|
try
|
2012-02-29 09:19:54 -04:00
|
|
|
|
{
|
2012-05-08 10:21:19 -03:00
|
|
|
|
CheckForUpdate();
|
2012-02-26 19:13:23 -04:00
|
|
|
|
}
|
2012-04-29 21:32:33 -03:00
|
|
|
|
catch (Exception ex)
|
2012-02-26 19:13:23 -04:00
|
|
|
|
{
|
2012-05-08 10:21:19 -03:00
|
|
|
|
log.Error("Update check failed", ex);
|
2012-01-23 09:36:20 -04:00
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
|
2011-12-12 08:22:13 -04:00
|
|
|
|
public static String ComputeWebSocketHandshakeSecurityHash09(String secWebSocketKey)
|
|
|
|
|
{
|
|
|
|
|
const String MagicKEY = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
|
|
|
String secWebSocketAccept = String.Empty;
|
|
|
|
|
|
|
|
|
|
// 1. Combine the request Sec-WebSocket-Key with magic key.
|
|
|
|
|
String ret = secWebSocketKey + MagicKEY;
|
|
|
|
|
|
|
|
|
|
// 2. Compute the SHA1 hash
|
|
|
|
|
System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
|
|
|
|
|
byte[] sha1Hash = sha.ComputeHash(Encoding.UTF8.GetBytes(ret));
|
|
|
|
|
|
|
|
|
|
// 3. Base64 encode the hash
|
|
|
|
|
secWebSocketAccept = Convert.ToBase64String(sha1Hash);
|
|
|
|
|
|
|
|
|
|
return secWebSocketAccept;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// little web server for sending network link kml's
|
|
|
|
|
/// </summary>
|
|
|
|
|
void listernforclients()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
listener.Start();
|
|
|
|
|
}
|
2012-05-08 10:21:19 -03:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Error("Exception starting lister. Possible multiple instances of planner?", e);
|
|
|
|
|
return;
|
|
|
|
|
} // in use
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Enter the listening loop.
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
// Perform a blocking call to accept requests.
|
|
|
|
|
// You could also user server.AcceptSocket() here.
|
|
|
|
|
try
|
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info("Listening for client - 1 client at a time");
|
2011-09-08 22:31:32 -03:00
|
|
|
|
TcpClient client = listener.AcceptTcpClient();
|
|
|
|
|
// Get a stream object for reading and writing
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info("Accepted Client " + client.Client.RemoteEndPoint.ToString());
|
2011-09-08 22:31:32 -03:00
|
|
|
|
//client.SendBufferSize = 100 * 1024; // 100kb
|
|
|
|
|
//client.LingerState.Enabled = true;
|
|
|
|
|
//client.NoDelay = true;
|
|
|
|
|
|
|
|
|
|
// makesure we have valid image
|
|
|
|
|
GCSViews.FlightData.mymap.streamjpgenable = true;
|
|
|
|
|
GCSViews.FlightData.myhud.streamjpgenable = true;
|
2011-12-17 05:22:40 -04:00
|
|
|
|
|
|
|
|
|
MethodInvoker m = delegate()
|
|
|
|
|
{
|
|
|
|
|
GCSViews.FlightData.mymap.Refresh();
|
|
|
|
|
};
|
|
|
|
|
this.Invoke(m);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
NetworkStream stream = client.GetStream();
|
|
|
|
|
|
2012-05-08 10:21:19 -03:00
|
|
|
|
var asciiEncoding = new ASCIIEncoding();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-05-08 10:21:19 -03:00
|
|
|
|
var request = new byte[1024];
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
int len = stream.Read(request, 0, request.Length);
|
2012-05-08 10:21:19 -03:00
|
|
|
|
string head = System.Text.Encoding.ASCII.GetString(request, 0, len);
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info(head);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
int index = head.IndexOf('\n');
|
|
|
|
|
|
|
|
|
|
string url = head.Substring(0, index - 1);
|
|
|
|
|
//url = url.Replace("\r", "");
|
|
|
|
|
//url = url.Replace("GET ","");
|
|
|
|
|
//url = url.Replace(" HTTP/1.0", "");
|
|
|
|
|
//url = url.Replace(" HTTP/1.1", "");
|
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
if (url.Contains("websocket"))
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2011-12-15 20:17:13 -04:00
|
|
|
|
using (var writer = new StreamWriter(stream, Encoding.Default))
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2011-12-12 08:22:13 -04:00
|
|
|
|
writer.WriteLine("HTTP/1.1 101 WebSocket Protocol Handshake");
|
2011-09-25 05:03:00 -03:00
|
|
|
|
writer.WriteLine("Upgrade: WebSocket");
|
|
|
|
|
writer.WriteLine("Connection: Upgrade");
|
|
|
|
|
writer.WriteLine("WebSocket-Location: ws://localhost:56781/websocket/server");
|
2011-12-12 08:22:13 -04:00
|
|
|
|
|
|
|
|
|
int start = head.IndexOf("Sec-WebSocket-Key:") + 19;
|
|
|
|
|
int end = head.IndexOf('\r', start);
|
|
|
|
|
if (end == -1)
|
|
|
|
|
end = head.IndexOf('\n', start);
|
2011-12-15 20:17:13 -04:00
|
|
|
|
string accept = ComputeWebSocketHandshakeSecurityHash09(head.Substring(start, end - start));
|
2011-12-12 08:22:13 -04:00
|
|
|
|
|
|
|
|
|
writer.WriteLine("Sec-WebSocket-Accept: " + accept);
|
|
|
|
|
|
|
|
|
|
writer.WriteLine("Server: APM Planner");
|
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
writer.WriteLine("");
|
|
|
|
|
|
2011-12-12 08:22:13 -04:00
|
|
|
|
writer.Flush();
|
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
while (client.Connected)
|
|
|
|
|
{
|
2012-05-08 10:21:19 -03:00
|
|
|
|
Thread.Sleep(200);
|
|
|
|
|
log.Debug(stream.DataAvailable + " " + client.Available);
|
2011-12-12 08:22:13 -04:00
|
|
|
|
|
|
|
|
|
while (client.Available > 0)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(stream.ReadByte());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] packet = new byte[256];
|
|
|
|
|
|
|
|
|
|
string sendme = cs.roll + "," + cs.pitch + "," + cs.yaw;
|
|
|
|
|
|
|
|
|
|
packet[0] = 0x81; // fin - binary
|
|
|
|
|
packet[1] = (byte)sendme.Length;
|
|
|
|
|
|
|
|
|
|
int i = 2;
|
|
|
|
|
foreach (char ch in sendme)
|
|
|
|
|
{
|
|
|
|
|
packet[i++] = (byte)ch;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-15 20:17:13 -04:00
|
|
|
|
stream.Write(packet, 0, i);
|
2011-11-08 09:22:07 -04:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
//break;
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
2011-11-08 09:22:07 -04:00
|
|
|
|
}
|
2012-04-15 10:51:07 -03:00
|
|
|
|
else if (url.Contains("georefnetwork.kml"))
|
|
|
|
|
{
|
|
|
|
|
string header = "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.google-earth.kml+xml\n\n";
|
2012-05-08 10:21:19 -03:00
|
|
|
|
byte[] temp = asciiEncoding.GetBytes(header);
|
2012-04-15 10:51:07 -03:00
|
|
|
|
stream.Write(temp, 0, temp.Length);
|
|
|
|
|
|
|
|
|
|
byte[] buffer = Encoding.ASCII.GetBytes(georefkml);
|
|
|
|
|
|
|
|
|
|
stream.Write(buffer, 0, buffer.Length);
|
|
|
|
|
|
|
|
|
|
stream.Close();
|
|
|
|
|
}
|
2011-12-15 20:17:13 -04:00
|
|
|
|
else if (url.Contains("network.kml"))
|
|
|
|
|
{
|
|
|
|
|
string header = "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.google-earth.kml+xml\n\n";
|
2012-05-08 10:21:19 -03:00
|
|
|
|
byte[] temp = asciiEncoding.GetBytes(header);
|
2011-12-15 20:17:13 -04:00
|
|
|
|
stream.Write(temp, 0, temp.Length);
|
|
|
|
|
|
|
|
|
|
SharpKml.Dom.Document kml = new SharpKml.Dom.Document();
|
|
|
|
|
|
|
|
|
|
SharpKml.Dom.Placemark pmplane = new SharpKml.Dom.Placemark();
|
|
|
|
|
pmplane.Name = "P/Q ";
|
|
|
|
|
|
|
|
|
|
pmplane.Visibility = true;
|
|
|
|
|
|
|
|
|
|
SharpKml.Dom.Location loc = new SharpKml.Dom.Location();
|
|
|
|
|
loc.Latitude = cs.lat;
|
|
|
|
|
loc.Longitude = cs.lng;
|
|
|
|
|
loc.Altitude = cs.alt;
|
|
|
|
|
|
|
|
|
|
if (loc.Altitude < 0)
|
|
|
|
|
loc.Altitude = 0.01;
|
|
|
|
|
|
|
|
|
|
SharpKml.Dom.Orientation ori = new SharpKml.Dom.Orientation();
|
|
|
|
|
ori.Heading = cs.yaw;
|
|
|
|
|
ori.Roll = -cs.roll;
|
|
|
|
|
ori.Tilt = -cs.pitch;
|
|
|
|
|
|
|
|
|
|
SharpKml.Dom.Scale sca = new SharpKml.Dom.Scale();
|
|
|
|
|
|
|
|
|
|
sca.X = 2;
|
|
|
|
|
sca.Y = 2;
|
|
|
|
|
sca.Z = 2;
|
|
|
|
|
|
|
|
|
|
SharpKml.Dom.Model model = new SharpKml.Dom.Model();
|
|
|
|
|
model.Location = loc;
|
|
|
|
|
model.Orientation = ori;
|
|
|
|
|
model.AltitudeMode = SharpKml.Dom.AltitudeMode.Absolute;
|
|
|
|
|
model.Scale = sca;
|
|
|
|
|
|
|
|
|
|
SharpKml.Dom.Link link = new SharpKml.Dom.Link();
|
|
|
|
|
link.Href = new Uri("block_plane_0.dae", UriKind.Relative);
|
|
|
|
|
|
|
|
|
|
model.Link = link;
|
|
|
|
|
|
|
|
|
|
pmplane.Geometry = model;
|
|
|
|
|
|
2012-02-29 09:19:54 -04:00
|
|
|
|
SharpKml.Dom.LookAt la = new SharpKml.Dom.LookAt()
|
|
|
|
|
{
|
|
|
|
|
Altitude = loc.Altitude.Value,
|
|
|
|
|
Latitude = loc.Latitude.Value,
|
|
|
|
|
Longitude = loc.Longitude.Value,
|
|
|
|
|
Tilt = 80,
|
|
|
|
|
Heading = cs.yaw,
|
|
|
|
|
AltitudeMode = SharpKml.Dom.AltitudeMode.Absolute,
|
|
|
|
|
Range = 50
|
|
|
|
|
};
|
2011-12-15 20:17:13 -04:00
|
|
|
|
|
|
|
|
|
kml.Viewpoint = la;
|
2012-02-29 09:19:54 -04:00
|
|
|
|
|
2011-12-15 20:17:13 -04:00
|
|
|
|
kml.AddFeature(pmplane);
|
|
|
|
|
|
|
|
|
|
SharpKml.Base.Serializer serializer = new SharpKml.Base.Serializer();
|
|
|
|
|
serializer.Serialize(kml);
|
|
|
|
|
|
|
|
|
|
byte[] buffer = Encoding.ASCII.GetBytes(serializer.Xml);
|
|
|
|
|
|
|
|
|
|
stream.Write(buffer, 0, buffer.Length);
|
|
|
|
|
|
|
|
|
|
stream.Close();
|
|
|
|
|
}
|
|
|
|
|
else if (url.Contains("block_plane_0.dae"))
|
|
|
|
|
{
|
|
|
|
|
string header = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\n\n";
|
2012-05-08 10:21:19 -03:00
|
|
|
|
byte[] temp = asciiEncoding.GetBytes(header);
|
2011-12-15 20:17:13 -04:00
|
|
|
|
stream.Write(temp, 0, temp.Length);
|
|
|
|
|
|
|
|
|
|
BinaryReader file = new BinaryReader(File.Open("block_plane_0.dae", FileMode.Open, FileAccess.Read, FileShare.Read));
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
while (file.PeekChar() != -1)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int leng = file.Read(buffer, 0, buffer.Length);
|
|
|
|
|
|
|
|
|
|
stream.Write(buffer, 0, leng);
|
|
|
|
|
}
|
|
|
|
|
file.Close();
|
|
|
|
|
stream.Close();
|
|
|
|
|
}
|
|
|
|
|
else if (url.Contains("hud.html"))
|
2011-11-08 09:22:07 -04:00
|
|
|
|
{
|
2011-12-15 20:17:13 -04:00
|
|
|
|
string header = "HTTP/1.1 200 OK\r\nContent-Type: text/html\n\n";
|
2012-05-08 10:21:19 -03:00
|
|
|
|
byte[] temp = asciiEncoding.GetBytes(header);
|
2011-12-15 20:17:13 -04:00
|
|
|
|
stream.Write(temp, 0, temp.Length);
|
|
|
|
|
|
2011-11-08 09:22:07 -04:00
|
|
|
|
BinaryReader file = new BinaryReader(File.Open("hud.html", FileMode.Open, FileAccess.Read, FileShare.Read));
|
2011-09-25 05:03:00 -03:00
|
|
|
|
byte[] buffer = new byte[1024];
|
2011-11-08 09:22:07 -04:00
|
|
|
|
while (file.PeekChar() != -1)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int leng = file.Read(buffer, 0, buffer.Length);
|
2011-09-25 05:03:00 -03:00
|
|
|
|
|
2011-11-08 09:22:07 -04:00
|
|
|
|
stream.Write(buffer, 0, leng);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
2011-09-25 05:03:00 -03:00
|
|
|
|
file.Close();
|
|
|
|
|
stream.Close();
|
|
|
|
|
}
|
2011-11-08 09:22:07 -04:00
|
|
|
|
else if (url.ToLower().Contains("hud.jpg") || url.ToLower().Contains("map.jpg") || url.ToLower().Contains("both.jpg"))
|
2011-09-25 05:03:00 -03:00
|
|
|
|
{
|
|
|
|
|
string header = "HTTP/1.1 200 OK\r\nContent-Type: multipart/x-mixed-replace;boundary=APMPLANNER\n\n--APMPLANNER\r\n";
|
2012-05-08 10:21:19 -03:00
|
|
|
|
byte[] temp = asciiEncoding.GetBytes(header);
|
2011-09-25 05:03:00 -03:00
|
|
|
|
stream.Write(temp, 0, temp.Length);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
while (client.Connected)
|
|
|
|
|
{
|
|
|
|
|
System.Threading.Thread.Sleep(200); // 5hz
|
|
|
|
|
byte[] data = null;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
if (url.ToLower().Contains("hud"))
|
|
|
|
|
{
|
|
|
|
|
GCSViews.FlightData.myhud.streamjpgenable = true;
|
|
|
|
|
data = GCSViews.FlightData.myhud.streamjpg.ToArray();
|
|
|
|
|
}
|
|
|
|
|
else if (url.ToLower().Contains("map"))
|
|
|
|
|
{
|
|
|
|
|
GCSViews.FlightData.mymap.streamjpgenable = true;
|
|
|
|
|
data = GCSViews.FlightData.mymap.streamjpg.ToArray();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GCSViews.FlightData.mymap.streamjpgenable = true;
|
|
|
|
|
GCSViews.FlightData.myhud.streamjpgenable = true;
|
|
|
|
|
Image img1 = Image.FromStream(GCSViews.FlightData.myhud.streamjpg);
|
|
|
|
|
Image img2 = Image.FromStream(GCSViews.FlightData.mymap.streamjpg);
|
|
|
|
|
int bigger = img1.Height > img2.Height ? img1.Height : img2.Height;
|
|
|
|
|
Image imgout = new Bitmap(img1.Width + img2.Width, bigger);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
Graphics grap = Graphics.FromImage(imgout);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
grap.DrawImageUnscaled(img1, 0, 0);
|
|
|
|
|
grap.DrawImageUnscaled(img2, img1.Width, 0);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
MemoryStream streamjpg = new MemoryStream();
|
|
|
|
|
imgout.Save(streamjpg, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
|
|
data = streamjpg.ToArray();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
header = "Content-Type: image/jpeg\r\nContent-Length: " + data.Length + "\r\n\r\n";
|
2012-05-08 10:21:19 -03:00
|
|
|
|
temp = asciiEncoding.GetBytes(header);
|
2011-09-25 05:03:00 -03:00
|
|
|
|
stream.Write(temp, 0, temp.Length);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
stream.Write(data, 0, data.Length);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
header = "\r\n--APMPLANNER\r\n";
|
2012-05-08 10:21:19 -03:00
|
|
|
|
temp = asciiEncoding.GetBytes(header);
|
2011-09-25 05:03:00 -03:00
|
|
|
|
stream.Write(temp, 0, temp.Length);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2011-09-25 05:03:00 -03:00
|
|
|
|
}
|
|
|
|
|
GCSViews.FlightData.mymap.streamjpgenable = false;
|
|
|
|
|
GCSViews.FlightData.myhud.streamjpgenable = false;
|
|
|
|
|
stream.Close();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
stream.Close();
|
|
|
|
|
}
|
2012-05-08 10:21:19 -03:00
|
|
|
|
catch (Exception ee)
|
|
|
|
|
{
|
|
|
|
|
log.Error("Failed mjpg ", ee);
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TOOL_APMFirmware_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
MainV2.cs.firmware = (MainV2.Firmwares)Enum.Parse(typeof(MainV2.Firmwares), _connectionControl.TOOL_APMFirmware.Text);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainV2_Resize(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info("myview width " + MyView.Width + " height " + MyView.Height);
|
|
|
|
|
log.Info("this width " + this.Width + " height " + this.Height);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MenuHelp_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MyView.Controls.Clear();
|
|
|
|
|
|
|
|
|
|
UserControl temp = new GCSViews.Help();
|
|
|
|
|
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(temp);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
temp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
|
|
|
|
|
|
|
|
|
|
temp.Dock = DockStyle.Fill;
|
|
|
|
|
|
|
|
|
|
MyView.Controls.Add(temp);
|
|
|
|
|
|
|
|
|
|
temp.ForeColor = Color.White;
|
|
|
|
|
|
|
|
|
|
temp.BackColor = Color.FromArgb(0x26, 0x27, 0x28);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-22 19:12:28 -04:00
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
public static void updateCheckMain(ProgressReporterDialogue frmProgressReporter)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
var baseurl = ConfigurationManager.AppSettings["UpdateLocation"];
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
bool update = updateCheck(frmProgressReporter, baseurl, "");
|
2012-02-26 19:13:23 -04:00
|
|
|
|
var process = new Process();
|
|
|
|
|
string exePath = Path.GetDirectoryName(Application.ExecutablePath);
|
2011-11-21 20:32:11 -04:00
|
|
|
|
if (MONO)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
process.StartInfo.FileName = "mono";
|
|
|
|
|
process.StartInfo.Arguments = " \"" + exePath + Path.DirectorySeparatorChar + "Updater.exe\"";
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
process.StartInfo.FileName = exePath + Path.DirectorySeparatorChar + "Updater.exe";
|
|
|
|
|
process.StartInfo.Arguments = "";
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
foreach (string newupdater in Directory.GetFiles(exePath, "Updater.exe*.new"))
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
File.Copy(newupdater, newupdater.Remove(newupdater.Length - 4), true);
|
|
|
|
|
File.Delete(newupdater);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-26 19:13:23 -04:00
|
|
|
|
catch (Exception ex)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Error("Exception during update", ex);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-03 03:42:41 -04:00
|
|
|
|
if (frmProgressReporter != null)
|
|
|
|
|
frmProgressReporter.UpdateProgressAndStatus(-1, "Starting Updater");
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info("Starting new process: " + process.StartInfo.FileName + " with " + process.StartInfo.Arguments);
|
|
|
|
|
process.Start();
|
|
|
|
|
log.Info("Quitting existing process");
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-03-17 23:29:55 -03:00
|
|
|
|
MainV2.instance.BeginInvoke((MethodInvoker)delegate()
|
|
|
|
|
{
|
2012-03-03 03:42:41 -04:00
|
|
|
|
Application.Exit();
|
|
|
|
|
});
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
2012-02-26 19:13:23 -04:00
|
|
|
|
catch
|
|
|
|
|
{
|
2012-03-03 03:42:41 -04:00
|
|
|
|
Application.Exit();
|
2012-02-26 19:13:23 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error("Update Failed", ex);
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Update Failed " + ex.Message);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-24 20:07:14 -04:00
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
private static void UpdateLabel(Label loadinglabel, string text)
|
2011-11-24 20:07:14 -04:00
|
|
|
|
{
|
|
|
|
|
MainV2.instance.Invoke((MethodInvoker)delegate
|
|
|
|
|
{
|
|
|
|
|
loadinglabel.Text = text;
|
|
|
|
|
|
2012-02-20 07:30:47 -04:00
|
|
|
|
Application.DoEvents();
|
|
|
|
|
});
|
2011-11-24 20:07:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
private static void CheckForUpdate()
|
2012-01-22 19:12:28 -04:00
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
var baseurl = ConfigurationManager.AppSettings["UpdateLocation"];
|
2012-02-29 09:19:54 -04:00
|
|
|
|
string path = Path.GetFileName(Application.ExecutablePath);
|
2012-01-22 19:12:28 -04:00
|
|
|
|
|
2012-04-08 21:33:57 -03:00
|
|
|
|
path = "version.txt";
|
|
|
|
|
|
2012-02-29 09:19:54 -04:00
|
|
|
|
// Create a request using a URL that can receive a post.
|
2012-02-26 19:13:23 -04:00
|
|
|
|
string requestUriString = baseurl + path;
|
|
|
|
|
log.Debug("Checking for update at: " + requestUriString);
|
|
|
|
|
var webRequest = WebRequest.Create(requestUriString);
|
|
|
|
|
webRequest.Timeout = 5000;
|
|
|
|
|
|
2012-02-29 09:19:54 -04:00
|
|
|
|
// Set the Method property of the request to POST.
|
2012-04-08 21:33:57 -03:00
|
|
|
|
webRequest.Method = "GET";
|
2012-01-22 19:12:28 -04:00
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
((HttpWebRequest)webRequest).IfModifiedSince = File.GetLastWriteTimeUtc(path);
|
2012-01-22 19:12:28 -04:00
|
|
|
|
|
2012-02-29 09:19:54 -04:00
|
|
|
|
// Get the response.
|
2012-02-26 19:13:23 -04:00
|
|
|
|
var response = webRequest.GetResponse();
|
2012-02-29 09:19:54 -04:00
|
|
|
|
// Display the status.
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Debug("Response status: " + ((HttpWebResponse)response).StatusDescription);
|
2012-02-29 09:19:54 -04:00
|
|
|
|
// Get the stream containing content returned by the server.
|
|
|
|
|
//dataStream = response.GetResponseStream();
|
|
|
|
|
// Open the stream using a StreamReader for easy access.
|
2012-01-22 19:12:28 -04:00
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
bool shouldGetFile = false;
|
2012-01-22 19:12:28 -04:00
|
|
|
|
|
2012-02-29 09:19:54 -04:00
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
var fi = new FileInfo(path);
|
2012-01-22 19:12:28 -04:00
|
|
|
|
|
2012-04-08 21:33:57 -03:00
|
|
|
|
string LocalVersion = "";
|
|
|
|
|
string WebVersion = "";
|
2012-01-22 19:12:28 -04:00
|
|
|
|
|
2012-04-08 21:33:57 -03:00
|
|
|
|
if (File.Exists(path))
|
2012-02-29 09:19:54 -04:00
|
|
|
|
{
|
2012-04-08 21:33:57 -03:00
|
|
|
|
using (Stream fs = File.OpenRead(path))
|
2012-03-03 03:42:41 -04:00
|
|
|
|
{
|
|
|
|
|
using (StreamReader sr = new StreamReader(fs))
|
|
|
|
|
{
|
2012-04-08 21:33:57 -03:00
|
|
|
|
LocalVersion = sr.ReadLine();
|
2012-03-03 03:42:41 -04:00
|
|
|
|
sr.Close();
|
|
|
|
|
}
|
|
|
|
|
fs.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-08 21:33:57 -03:00
|
|
|
|
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
|
|
|
|
|
{
|
|
|
|
|
WebVersion = sr.ReadLine();
|
|
|
|
|
|
|
|
|
|
sr.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.Info("New file Check: local " + LocalVersion + " vs Remote " + WebVersion);
|
2012-03-03 03:42:41 -04:00
|
|
|
|
|
2012-04-08 21:33:57 -03:00
|
|
|
|
if (LocalVersion != WebVersion)
|
2012-03-06 20:01:59 -04:00
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
shouldGetFile = true;
|
2012-01-22 19:12:28 -04:00
|
|
|
|
}
|
2012-02-29 09:19:54 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
shouldGetFile = true;
|
2012-02-29 09:19:54 -04:00
|
|
|
|
log.Info("File does not exist: Getting " + path);
|
|
|
|
|
// get it
|
|
|
|
|
}
|
2012-01-22 19:12:28 -04:00
|
|
|
|
|
2012-02-29 09:19:54 -04:00
|
|
|
|
response.Close();
|
2012-01-22 19:12:28 -04:00
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
if (shouldGetFile)
|
2012-02-29 09:19:54 -04:00
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
var dr = CustomMessageBox.Show("Update Found\n\nDo you wish to update now?", "Update Now", MessageBoxButtons.YesNo);
|
2012-02-29 09:19:54 -04:00
|
|
|
|
if (dr == DialogResult.Yes)
|
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
DoUpdate();
|
2012-01-22 19:12:28 -04:00
|
|
|
|
}
|
2012-02-29 09:19:54 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-01-22 19:12:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
public static void DoUpdate()
|
2012-01-23 09:36:20 -04:00
|
|
|
|
{
|
2012-03-03 03:42:41 -04:00
|
|
|
|
ProgressReporterDialogue frmProgressReporter = new ProgressReporterDialogue()
|
2012-02-29 09:19:54 -04:00
|
|
|
|
{
|
2012-03-03 03:42:41 -04:00
|
|
|
|
Text = "Check for Updates",
|
|
|
|
|
StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
|
2012-02-29 09:19:54 -04:00
|
|
|
|
};
|
2012-02-26 19:13:23 -04:00
|
|
|
|
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(frmProgressReporter);
|
2012-01-23 09:36:20 -04:00
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
frmProgressReporter.DoWork += new Controls.ProgressReporterDialogue.DoWorkEventHandler(DoUpdateWorker_DoWork);
|
2012-01-23 09:36:20 -04:00
|
|
|
|
|
2012-03-03 03:42:41 -04:00
|
|
|
|
frmProgressReporter.UpdateProgressAndStatus(-1, "Checking for Updates");
|
|
|
|
|
|
|
|
|
|
frmProgressReporter.RunBackgroundOperationAsync();
|
2012-01-23 09:36:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
static void DoUpdateWorker_DoWork(object sender, Controls.ProgressWorkerEventArgs e)
|
2012-03-03 03:42:41 -04:00
|
|
|
|
{
|
2012-05-08 10:21:19 -03:00
|
|
|
|
// TODO: Is this the right place?
|
|
|
|
|
#region Fetch Parameter Meta Data
|
|
|
|
|
|
|
|
|
|
var progressReporterDialogue = ((ProgressReporterDialogue)sender);
|
|
|
|
|
progressReporterDialogue.UpdateProgressAndStatus(-1, "Getting Updated Parameters");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ParameterMetaDataParser.GetParameterInformation();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { log.Error(ex.ToString()); CustomMessageBox.Show("Error getting Parameter Information"); }
|
|
|
|
|
|
|
|
|
|
#endregion Fetch Parameter Meta Data
|
|
|
|
|
|
|
|
|
|
progressReporterDialogue.UpdateProgressAndStatus(-1, "Getting Base URL");
|
|
|
|
|
// check for updates
|
|
|
|
|
if (Debugger.IsAttached)
|
|
|
|
|
{
|
|
|
|
|
log.Info("Skipping update test as it appears we are debugging");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MainV2.updateCheckMain(progressReporterDialogue);
|
|
|
|
|
}
|
2012-03-03 03:42:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 20:26:20 -03:00
|
|
|
|
private static bool updateCheck(ProgressReporterDialogue frmProgressReporter, string baseurl, string subdir)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
bool update = false;
|
|
|
|
|
List<string> files = new List<string>();
|
|
|
|
|
|
|
|
|
|
// Create a request using a URL that can receive a post.
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info(baseurl);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
WebRequest request = WebRequest.Create(baseurl);
|
|
|
|
|
request.Timeout = 10000;
|
|
|
|
|
// Set the Method property of the request to POST.
|
|
|
|
|
request.Method = "GET";
|
|
|
|
|
// Get the request stream.
|
|
|
|
|
Stream dataStream; //= request.GetRequestStream();
|
|
|
|
|
// Get the response.
|
|
|
|
|
WebResponse response = request.GetResponse();
|
|
|
|
|
// Display the status.
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info(((HttpWebResponse)response).StatusDescription);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Get the stream containing content returned by the server.
|
|
|
|
|
dataStream = response.GetResponseStream();
|
|
|
|
|
// Open the stream using a StreamReader for easy access.
|
|
|
|
|
StreamReader reader = new StreamReader(dataStream);
|
|
|
|
|
// Read the content.
|
|
|
|
|
string responseFromServer = reader.ReadToEnd();
|
|
|
|
|
// Display the content.
|
|
|
|
|
Regex regex = new Regex("href=\"([^\"]+)\"", RegexOptions.IgnoreCase);
|
|
|
|
|
if (regex.IsMatch(responseFromServer))
|
|
|
|
|
{
|
|
|
|
|
MatchCollection matchs = regex.Matches(responseFromServer);
|
|
|
|
|
for (int i = 0; i < matchs.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (matchs[i].Groups[1].Value.ToString().Contains(".."))
|
|
|
|
|
continue;
|
|
|
|
|
if (matchs[i].Groups[1].Value.ToString().Contains("http"))
|
|
|
|
|
continue;
|
|
|
|
|
files.Add(System.Web.HttpUtility.UrlDecode(matchs[i].Groups[1].Value.ToString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Console.WriteLine(responseFromServer);
|
|
|
|
|
// Clean up the streams.
|
|
|
|
|
reader.Close();
|
|
|
|
|
dataStream.Close();
|
|
|
|
|
response.Close();
|
|
|
|
|
|
|
|
|
|
string dir = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + subdir;
|
|
|
|
|
if (!Directory.Exists(dir))
|
|
|
|
|
Directory.CreateDirectory(dir);
|
|
|
|
|
foreach (string file in files)
|
|
|
|
|
{
|
2012-03-03 03:42:41 -04:00
|
|
|
|
if (frmProgressReporter.doWorkArgs.CancelRequested)
|
|
|
|
|
{
|
|
|
|
|
frmProgressReporter.doWorkArgs.CancelAcknowledged = true;
|
|
|
|
|
throw new Exception("Cancel");
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-10 03:15:14 -03:00
|
|
|
|
if (file.Equals("/"))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
if (file.EndsWith("/"))
|
|
|
|
|
{
|
2012-03-18 20:26:20 -03:00
|
|
|
|
update = updateCheck(frmProgressReporter, baseurl + file, subdir.Replace('/', Path.DirectorySeparatorChar) + file) && update;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-03-03 03:42:41 -04:00
|
|
|
|
if (frmProgressReporter != null)
|
|
|
|
|
frmProgressReporter.UpdateProgressAndStatus(-1, "Checking " + file);
|
2011-09-18 20:42:22 -03:00
|
|
|
|
|
|
|
|
|
string path = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + subdir + file;
|
|
|
|
|
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Create a request using a URL that can receive a post.
|
|
|
|
|
request = WebRequest.Create(baseurl + file);
|
2012-03-06 20:01:59 -04:00
|
|
|
|
log.Info(baseurl + file + " ");
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Set the Method property of the request to POST.
|
|
|
|
|
request.Method = "HEAD";
|
2011-09-18 20:42:22 -03:00
|
|
|
|
|
|
|
|
|
((HttpWebRequest)request).IfModifiedSince = File.GetLastWriteTimeUtc(path);
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Get the response.
|
|
|
|
|
response = request.GetResponse();
|
|
|
|
|
// Display the status.
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info(((HttpWebResponse)response).StatusDescription);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Get the stream containing content returned by the server.
|
2011-09-18 20:42:22 -03:00
|
|
|
|
//dataStream = response.GetResponseStream();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Open the stream using a StreamReader for easy access.
|
|
|
|
|
|
2012-03-03 03:42:41 -04:00
|
|
|
|
bool updateThisFile = false;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
FileInfo fi = new FileInfo(path);
|
|
|
|
|
|
2012-03-03 03:42:41 -04:00
|
|
|
|
//log.Info(response.Headers[HttpResponseHeader.ETag]);
|
|
|
|
|
string CurrentEtag = "";
|
2011-09-18 20:42:22 -03:00
|
|
|
|
|
2012-03-03 03:42:41 -04:00
|
|
|
|
if (File.Exists(path + ".etag"))
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-03-03 03:42:41 -04:00
|
|
|
|
using (Stream fs = File.OpenRead(path + ".etag"))
|
|
|
|
|
{
|
|
|
|
|
using (StreamReader sr = new StreamReader(fs))
|
|
|
|
|
{
|
|
|
|
|
CurrentEtag = sr.ReadLine();
|
|
|
|
|
sr.Close();
|
|
|
|
|
}
|
|
|
|
|
fs.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-06 20:01:59 -04:00
|
|
|
|
log.Debug("New file Check: " + fi.Length + " vs " + response.ContentLength + " " + response.Headers[HttpResponseHeader.ETag] + " vs " + CurrentEtag);
|
2012-03-03 03:42:41 -04:00
|
|
|
|
|
2012-03-06 20:01:59 -04:00
|
|
|
|
if (fi.Length != response.ContentLength || response.Headers[HttpResponseHeader.ETag] != CurrentEtag)
|
|
|
|
|
{
|
2012-04-03 19:58:45 -03:00
|
|
|
|
using (StreamWriter sw = new StreamWriter(path + ".etag.new"))
|
2012-03-03 03:42:41 -04:00
|
|
|
|
{
|
|
|
|
|
sw.WriteLine(response.Headers[HttpResponseHeader.ETag]);
|
|
|
|
|
sw.Close();
|
|
|
|
|
}
|
|
|
|
|
updateThisFile = true;
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info("NEW FILE " + file);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-03-03 03:42:41 -04:00
|
|
|
|
updateThisFile = true;
|
2012-02-26 19:13:23 -04:00
|
|
|
|
log.Info("NEW FILE " + file);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// get it
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reader.Close();
|
2011-09-18 20:42:22 -03:00
|
|
|
|
//dataStream.Close();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
response.Close();
|
|
|
|
|
|
2012-03-03 03:42:41 -04:00
|
|
|
|
if (updateThisFile)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
if (!update)
|
|
|
|
|
{
|
|
|
|
|
//DialogResult dr = MessageBox.Show("Update Found\n\nDo you wish to update now?", "Update Now", MessageBoxButtons.YesNo);
|
|
|
|
|
//if (dr == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
update = true;
|
|
|
|
|
}
|
|
|
|
|
//else
|
|
|
|
|
{
|
|
|
|
|
// return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-03 03:42:41 -04:00
|
|
|
|
if (frmProgressReporter != null)
|
|
|
|
|
frmProgressReporter.UpdateProgressAndStatus(-1, "Getting " + file);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-01-09 20:16:10 -04:00
|
|
|
|
// from head
|
|
|
|
|
long bytes = response.ContentLength;
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Create a request using a URL that can receive a post.
|
2012-03-03 03:42:41 -04:00
|
|
|
|
request = HttpWebRequest.Create(baseurl + file);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Set the Method property of the request to POST.
|
|
|
|
|
request.Method = "GET";
|
2012-03-03 03:42:41 -04:00
|
|
|
|
|
|
|
|
|
((HttpWebRequest)request).AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
|
|
|
|
|
|
2012-03-17 23:29:55 -03:00
|
|
|
|
request.Headers.Add("Accept-Encoding", "gzip,deflate");
|
2012-03-03 03:42:41 -04:00
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Get the response.
|
|
|
|
|
response = request.GetResponse();
|
|
|
|
|
// Display the status.
|
2012-05-08 10:21:19 -03:00
|
|
|
|
log.Debug(((HttpWebResponse)response).StatusDescription);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
// Get the stream containing content returned by the server.
|
|
|
|
|
dataStream = response.GetResponseStream();
|
2012-02-29 09:19:54 -04:00
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
long contlen = bytes;
|
|
|
|
|
|
|
|
|
|
byte[] buf1 = new byte[1024];
|
|
|
|
|
|
|
|
|
|
FileStream fs = new FileStream(path + ".new", FileMode.Create); //
|
|
|
|
|
|
|
|
|
|
DateTime dt = DateTime.Now;
|
|
|
|
|
|
2011-09-10 03:15:14 -03:00
|
|
|
|
dataStream.ReadTimeout = 30000;
|
|
|
|
|
|
|
|
|
|
while (dataStream.CanRead)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (dt.Second != DateTime.Now.Second)
|
|
|
|
|
{
|
2012-03-03 03:42:41 -04:00
|
|
|
|
if (frmProgressReporter != null)
|
|
|
|
|
frmProgressReporter.UpdateProgressAndStatus((int)(((double)(contlen - bytes) / (double)contlen) * 100), "Getting " + file + ": " + (((double)(contlen - bytes) / (double)contlen) * 100).ToString("0.0") + "%"); //+ Math.Abs(bytes) + " bytes");
|
2011-09-08 22:31:32 -03:00
|
|
|
|
dt = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
2012-05-08 10:21:19 -03:00
|
|
|
|
log.Debug(file + " " + bytes);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
int len = dataStream.Read(buf1, 0, 1024);
|
2011-09-10 03:15:14 -03:00
|
|
|
|
if (len == 0)
|
|
|
|
|
break;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
bytes -= len;
|
|
|
|
|
fs.Write(buf1, 0, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs.Close();
|
|
|
|
|
dataStream.Close();
|
|
|
|
|
response.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//P.StartInfo.CreateNoWindow = true;
|
|
|
|
|
//P.StartInfo.RedirectStandardOutput = true;
|
|
|
|
|
return update;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-03 19:58:45 -03:00
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// trying to replicate google code etags....... this doesnt work.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fileName"></param>
|
|
|
|
|
/// <param name="modifyDate"></param>
|
|
|
|
|
/// <returns></returns>
|
2012-04-03 19:58:45 -03:00
|
|
|
|
private string GetFileETag(string fileName, DateTime modifyDate)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
string FileString;
|
|
|
|
|
|
|
|
|
|
System.Text.Encoder StringEncoder;
|
|
|
|
|
|
|
|
|
|
byte[] StringBytes;
|
|
|
|
|
|
|
|
|
|
MD5CryptoServiceProvider MD5Enc;
|
|
|
|
|
|
|
|
|
|
//use file name and modify date as the unique identifier
|
|
|
|
|
|
|
|
|
|
FileString = fileName + modifyDate.ToString("d", CultureInfo.InvariantCulture);
|
|
|
|
|
|
|
|
|
|
//get string bytes
|
|
|
|
|
|
|
|
|
|
StringEncoder = Encoding.UTF8.GetEncoder();
|
|
|
|
|
|
|
|
|
|
StringBytes = new byte[StringEncoder.GetByteCount(FileString.ToCharArray(), 0, FileString.Length, true)];
|
|
|
|
|
|
|
|
|
|
StringEncoder.GetBytes(FileString.ToCharArray(), 0, FileString.Length, StringBytes, 0, true);
|
|
|
|
|
|
|
|
|
|
//hash string using MD5 and return the hex-encoded hash
|
|
|
|
|
|
|
|
|
|
MD5Enc = new MD5CryptoServiceProvider();
|
|
|
|
|
|
|
|
|
|
byte[] hash = MD5Enc.ComputeHash((Stream)File.OpenRead(fileName));
|
|
|
|
|
|
|
|
|
|
return "\"" + BitConverter.ToString(hash).Replace("-", string.Empty) + "\"";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// keyboard shortcuts override
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msg"></param>
|
|
|
|
|
/// <param name="keyData"></param>
|
|
|
|
|
/// <returns></returns>
|
2011-09-08 22:31:32 -03:00
|
|
|
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
if (keyData == (Keys.Control | Keys.F)) // temp
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
Form frm = new temp();
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(frm);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
frm.Show();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-04-21 04:30:15 -03:00
|
|
|
|
if (keyData == (Keys.Control | Keys.S)) // screenshot
|
2011-10-25 10:20:58 -03:00
|
|
|
|
{
|
|
|
|
|
ScreenShot();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-04-21 04:30:15 -03:00
|
|
|
|
if (keyData == (Keys.Control | Keys.G)) // nmea out
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
Form frm = new SerialOutput();
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(frm);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
frm.Show();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-04-21 04:30:15 -03:00
|
|
|
|
if (keyData == (Keys.Control | Keys.A)) // 3dr radio
|
2012-02-23 21:38:56 -04:00
|
|
|
|
{
|
2012-04-08 21:33:57 -03:00
|
|
|
|
Form temp = new Form();
|
2012-04-06 05:27:26 -03:00
|
|
|
|
Control frm = new _3DRradio();
|
2012-04-08 21:33:57 -03:00
|
|
|
|
temp.Controls.Add(frm);
|
|
|
|
|
temp.Size = frm.Size;
|
|
|
|
|
frm.Dock = DockStyle.Fill;
|
|
|
|
|
ThemeManager.ApplyThemeTo(temp);
|
|
|
|
|
temp.Show();
|
2012-02-23 21:38:56 -04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-04-21 04:30:15 -03:00
|
|
|
|
if (keyData == (Keys.Control | Keys.W)) // test ac config
|
2012-04-03 19:58:45 -03:00
|
|
|
|
{
|
2012-04-12 10:39:51 -03:00
|
|
|
|
|
|
|
|
|
Controls.ConfigPanel cfg = new Controls.ConfigPanel();
|
|
|
|
|
|
|
|
|
|
cfg.LoadXML("ArduCopterConfig.xml");
|
|
|
|
|
|
2012-04-25 07:10:11 -03:00
|
|
|
|
//cfg.ShowDialog();
|
2012-04-12 10:39:51 -03:00
|
|
|
|
|
2012-04-03 19:58:45 -03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-12-12 08:22:13 -04:00
|
|
|
|
if (keyData == (Keys.Control | Keys.T)) // for override connect
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2011-12-12 08:22:13 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
MainV2.comPort.Open(false);
|
|
|
|
|
}
|
2012-03-09 11:18:12 -04:00
|
|
|
|
catch (Exception ex) { CustomMessageBox.Show(ex.ToString()); }
|
2011-09-08 22:31:32 -03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-09-17 12:49:32 -03:00
|
|
|
|
if (keyData == (Keys.Control | Keys.Y)) // for ryan beall
|
|
|
|
|
{
|
2011-11-08 09:22:07 -04:00
|
|
|
|
#if MAVLINK10
|
2011-12-13 08:52:54 -04:00
|
|
|
|
// 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);
|
2011-11-08 09:22:07 -04:00
|
|
|
|
#else
|
2011-12-13 08:52:54 -04:00
|
|
|
|
MainV2.comPort.doAction(MAVLink.MAV_ACTION.MAV_ACTION_STORAGE_WRITE);
|
2011-11-08 09:22:07 -04:00
|
|
|
|
#endif
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Done MAV_ACTION_STORAGE_WRITE");
|
2011-09-17 12:49:32 -03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
if (keyData == (Keys.Control | Keys.J)) // for jani
|
|
|
|
|
{
|
|
|
|
|
string data = "!!";
|
|
|
|
|
Common.InputBox("inject", "enter data to be written", ref data);
|
|
|
|
|
MainV2.comPort.Write(data + "\r");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return base.ProcessCmdKey(ref msg, keyData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void changelanguage(CultureInfo ci)
|
|
|
|
|
{
|
|
|
|
|
if (ci != null && !Thread.CurrentThread.CurrentUICulture.Equals(ci))
|
|
|
|
|
{
|
|
|
|
|
Thread.CurrentThread.CurrentUICulture = ci;
|
|
|
|
|
config["language"] = ci.Name;
|
|
|
|
|
//System.Threading.Thread.CurrentThread.CurrentCulture = ci;
|
|
|
|
|
|
|
|
|
|
HashSet<Control> views = new HashSet<Control> { FlightData, FlightPlanner, Simulation, Firmware };
|
|
|
|
|
|
|
|
|
|
foreach (Control view in MyView.Controls)
|
|
|
|
|
views.Add(view);
|
|
|
|
|
|
|
|
|
|
foreach (Control view in views)
|
|
|
|
|
{
|
|
|
|
|
if (view != null)
|
|
|
|
|
{
|
|
|
|
|
ComponentResourceManager rm = new ComponentResourceManager(view.GetType());
|
|
|
|
|
foreach (Control ctrl in view.Controls)
|
2012-02-26 07:14:08 -04:00
|
|
|
|
rm.ApplyResource(ctrl);
|
2011-09-08 22:31:32 -03:00
|
|
|
|
rm.ApplyResources(view, "$this");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainV2_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
config["MainHeight"] = this.Height;
|
|
|
|
|
config["MainWidth"] = this.Width;
|
|
|
|
|
config["MainMaximised"] = this.WindowState.ToString();
|
|
|
|
|
|
2011-12-12 08:22:13 -04:00
|
|
|
|
config["MainLocX"] = this.Location.X.ToString();
|
|
|
|
|
config["MainLocY"] = this.Location.Y.ToString();
|
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
comPort.logreadmode = false;
|
|
|
|
|
if (comPort.logfile != null)
|
|
|
|
|
comPort.logfile.Close();
|
2012-03-26 07:21:49 -03:00
|
|
|
|
|
|
|
|
|
if (comPort.rawlogfile != null)
|
|
|
|
|
comPort.rawlogfile.Close();
|
2012-04-05 21:50:04 -03:00
|
|
|
|
|
|
|
|
|
comPort.logfile = null;
|
|
|
|
|
comPort.rawlogfile = null;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
2011-11-08 09:22:07 -04:00
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string getConfig(string paramname)
|
|
|
|
|
{
|
|
|
|
|
if (config[paramname] != null)
|
|
|
|
|
return config[paramname].ToString();
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 04:30:15 -03:00
|
|
|
|
public void ChangeUnits()
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// dist
|
|
|
|
|
if (MainV2.config["distunits"] != null)
|
|
|
|
|
{
|
|
|
|
|
switch ((Common.distances)Enum.Parse(typeof(Common.distances), MainV2.config["distunits"].ToString()))
|
|
|
|
|
{
|
|
|
|
|
case Common.distances.Meters:
|
|
|
|
|
MainV2.cs.multiplierdist = 1;
|
|
|
|
|
break;
|
|
|
|
|
case Common.distances.Feet:
|
|
|
|
|
MainV2.cs.multiplierdist = 3.2808399f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// speed
|
|
|
|
|
if (MainV2.config["speedunits"] != null)
|
|
|
|
|
{
|
|
|
|
|
switch ((Common.speeds)Enum.Parse(typeof(Common.speeds), MainV2.config["speedunits"].ToString()))
|
|
|
|
|
{
|
|
|
|
|
case Common.speeds.ms:
|
|
|
|
|
MainV2.cs.multiplierspeed = 1;
|
|
|
|
|
break;
|
|
|
|
|
case Common.speeds.fps:
|
|
|
|
|
MainV2.cs.multiplierdist = 3.2808399f;
|
|
|
|
|
break;
|
|
|
|
|
case Common.speeds.kph:
|
|
|
|
|
MainV2.cs.multiplierspeed = 3.6f;
|
|
|
|
|
break;
|
|
|
|
|
case Common.speeds.mph:
|
|
|
|
|
MainV2.cs.multiplierspeed = 2.23693629f;
|
|
|
|
|
break;
|
|
|
|
|
case Common.speeds.knots:
|
|
|
|
|
MainV2.cs.multiplierspeed = 1.94384449f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
|
|
|
|
|
}
|
2012-04-21 04:30:15 -03:00
|
|
|
|
|
2011-09-08 22:31:32 -03:00
|
|
|
|
private void CMB_baudrate_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-05-08 10:21:19 -03:00
|
|
|
|
var sb = new StringBuilder();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
int baud = 0;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
for (int i = 0; i < _connectionControl.CMB_baudrate.Text.Length; i++)
|
|
|
|
|
if (char.IsDigit(_connectionControl.CMB_baudrate.Text[i]))
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-04-21 04:30:15 -03:00
|
|
|
|
sb.Append(_connectionControl.CMB_baudrate.Text[i]);
|
|
|
|
|
baud = baud * 10 + _connectionControl.CMB_baudrate.Text[i] - '0';
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
2012-04-21 04:30:15 -03:00
|
|
|
|
if (_connectionControl.CMB_baudrate.Text != sb.ToString())
|
|
|
|
|
{
|
|
|
|
|
_connectionControl.CMB_baudrate.Text = sb.ToString();
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (baud > 0 && comPort.BaseStream.BaudRate != baud)
|
|
|
|
|
comPort.BaseStream.BaudRate = baud;
|
|
|
|
|
}
|
2012-04-21 04:30:15 -03:00
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
2012-02-24 07:39:02 -04:00
|
|
|
|
|
|
|
|
|
private void CMB_serialport_Enter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CMB_serialport_Click(sender, e);
|
|
|
|
|
}
|
2012-04-30 07:48:52 -03:00
|
|
|
|
|
|
|
|
|
private void MenuConnect_MouseHover(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
}
|