2012-02-23 21:38:56 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.IO;
|
2012-04-06 05:27:26 -03:00
|
|
|
|
using ArdupilotMega.Controls.BackstageView;
|
2012-04-24 10:49:27 -03:00
|
|
|
|
using ArdupilotMega.Arduino;
|
|
|
|
|
using ArdupilotMega.Comms;
|
2012-05-07 11:25:56 -03:00
|
|
|
|
using log4net;
|
|
|
|
|
using System.Reflection;
|
2012-05-11 06:07:52 -03:00
|
|
|
|
using System.Text.RegularExpressions;
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
|
|
|
|
namespace ArdupilotMega
|
|
|
|
|
{
|
2012-07-22 04:51:05 -03:00
|
|
|
|
public partial class _3DRradio : UserControl
|
2012-02-23 21:38:56 -04:00
|
|
|
|
{
|
|
|
|
|
public delegate void LogEventHandler(string message, int level = 0);
|
|
|
|
|
|
|
|
|
|
public delegate void ProgressEventHandler(double completed);
|
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
string firmwarefile = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "radio.hex";
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-05-07 11:25:56 -03:00
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
public _3DRradio()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2012-02-24 07:39:02 -04:00
|
|
|
|
|
2012-05-16 09:21:27 -03:00
|
|
|
|
// hide advanced view
|
2012-10-30 20:02:29 -03:00
|
|
|
|
//SPLIT_local.Panel2Collapsed = true;
|
|
|
|
|
//SPLIT_remote.Panel2Collapsed = true;
|
2012-05-16 09:21:27 -03:00
|
|
|
|
|
|
|
|
|
// setup netid
|
2012-02-24 07:39:02 -04:00
|
|
|
|
S3.DataSource = Enumerable.Range(0, 500).ToArray();
|
2012-05-20 02:54:35 -03:00
|
|
|
|
RS3.DataSource = Enumerable.Range(0, 500).ToArray();
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
bool getFirmware(uploader.Uploader.Code device)
|
2012-02-23 21:38:56 -04:00
|
|
|
|
{
|
2012-04-05 21:50:04 -03:00
|
|
|
|
// was https://raw.github.com/tridge/SiK/master/Firmware/dst/radio.hm_trp.hex
|
|
|
|
|
// now http://www.samba.org/tridge/UAV/3DR/radio.hm_trp.hex
|
2012-05-11 06:07:52 -03:00
|
|
|
|
|
|
|
|
|
if (device == uploader.Uploader.Code.DEVICE_ID_HM_TRP)
|
|
|
|
|
{
|
|
|
|
|
return Common.getFilefromNet("http://www.samba.org/tridge/UAV/3DR/radio.hm_trp.hex", firmwarefile);
|
|
|
|
|
}
|
|
|
|
|
else if (device == uploader.Uploader.Code.DEVICE_ID_RFD900)
|
|
|
|
|
{
|
2012-07-05 20:27:42 -03:00
|
|
|
|
return Common.getFilefromNet("http://rfdesign.com.au/firmware/radio.rfd900.hex", firmwarefile);
|
|
|
|
|
}
|
|
|
|
|
else if (device == uploader.Uploader.Code.DEVICE_ID_RFD900A)
|
|
|
|
|
{
|
|
|
|
|
return Common.getFilefromNet("http://rfdesign.com.au/firmware/radio.rfd900a.hex", firmwarefile);
|
2012-05-11 06:07:52 -03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Sleep(int mstimeout)
|
|
|
|
|
{
|
|
|
|
|
DateTime endtime = DateTime.Now.AddMilliseconds(mstimeout);
|
|
|
|
|
|
|
|
|
|
while (DateTime.Now < endtime)
|
|
|
|
|
{
|
|
|
|
|
System.Threading.Thread.Sleep(1);
|
|
|
|
|
Application.DoEvents();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BUT_upload_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ArduinoSTK comPort = new ArduinoSTK();
|
|
|
|
|
|
|
|
|
|
uploader.Uploader uploader = new uploader.Uploader();
|
|
|
|
|
|
2012-02-24 07:39:02 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
comPort.PortName = MainV2.comPort.BaseStream.PortName;
|
|
|
|
|
comPort.BaudRate = 115200;
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-02-24 07:39:02 -04:00
|
|
|
|
comPort.Open();
|
|
|
|
|
|
|
|
|
|
}
|
2012-03-09 11:18:12 -04:00
|
|
|
|
catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
|
|
|
|
bool bootloadermode = false;
|
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
// attempt bootloader mode
|
2012-02-23 21:38:56 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
uploader_ProgressEvent(0);
|
|
|
|
|
uploader_LogEvent("Trying Bootloader Mode");
|
|
|
|
|
uploader.port = comPort;
|
|
|
|
|
uploader.connect_and_sync();
|
2012-04-21 04:30:15 -03:00
|
|
|
|
|
|
|
|
|
uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent);
|
|
|
|
|
uploader.LogEvent += new LogEventHandler(uploader_LogEvent);
|
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
uploader_LogEvent("In Bootloader Mode");
|
|
|
|
|
bootloadermode = true;
|
|
|
|
|
}
|
2012-04-03 19:58:45 -03:00
|
|
|
|
catch
|
|
|
|
|
{
|
2012-05-11 06:07:52 -03:00
|
|
|
|
// cleanup bootloader mode fail, and try firmware mode
|
2012-02-24 07:39:02 -04:00
|
|
|
|
comPort.Close();
|
|
|
|
|
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
|
|
|
|
|
comPort.Open();
|
2012-04-21 04:30:15 -03:00
|
|
|
|
|
|
|
|
|
uploader.ProgressEvent += new ProgressEventHandler(uploader_ProgressEvent);
|
|
|
|
|
uploader.LogEvent += new LogEventHandler(uploader_LogEvent);
|
|
|
|
|
|
2012-02-24 07:39:02 -04:00
|
|
|
|
uploader_LogEvent("Trying Firmware Mode");
|
|
|
|
|
bootloadermode = false;
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
// check for either already bootloadermode, or if we can do a ATI to ID the firmware
|
2012-02-24 07:39:02 -04:00
|
|
|
|
if (bootloadermode || doConnect(comPort))
|
2012-02-23 21:38:56 -04:00
|
|
|
|
{
|
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
uploader.IHex iHex = new uploader.IHex();
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
iHex.LogEvent += new LogEventHandler(iHex_LogEvent);
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
iHex.ProgressEvent += new ProgressEventHandler(iHex_ProgressEvent);
|
|
|
|
|
|
|
|
|
|
// put into bootloader mode/udpate mode
|
|
|
|
|
if (!bootloadermode)
|
|
|
|
|
{
|
2012-02-23 21:38:56 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-05-11 06:07:52 -03:00
|
|
|
|
comPort.Write("AT&UPDATE\r\n");
|
|
|
|
|
string left = comPort.ReadExisting();
|
|
|
|
|
log.Info(left);
|
|
|
|
|
Sleep(700);
|
|
|
|
|
comPort.BaudRate = 115200;
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
2012-05-11 06:07:52 -03:00
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
global::uploader.Uploader.Code device = global::uploader.Uploader.Code.FAILED;
|
|
|
|
|
global::uploader.Uploader.Code freq = global::uploader.Uploader.Code.FAILED;
|
|
|
|
|
|
|
|
|
|
// get the device type and frequency in the bootloader
|
|
|
|
|
uploader.getDevice(ref device, ref freq);
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
// get firmware for this device
|
|
|
|
|
if (getFirmware(device))
|
|
|
|
|
{
|
|
|
|
|
// load the hex
|
|
|
|
|
try
|
2012-02-23 21:38:56 -04:00
|
|
|
|
{
|
2012-05-11 06:07:52 -03:00
|
|
|
|
iHex.load(firmwarefile);
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
2012-05-11 06:07:52 -03:00
|
|
|
|
catch { CustomMessageBox.Show("Bad Firmware File"); goto exit; }
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
// upload the hex and verify
|
2012-02-23 21:38:56 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
uploader.upload(comPort, iHex);
|
|
|
|
|
}
|
2012-03-09 11:18:12 -04:00
|
|
|
|
catch (Exception ex) { CustomMessageBox.Show("Upload Failed " + ex.Message); }
|
2012-05-11 06:07:52 -03:00
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Failed to download new firmware");
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
2012-05-11 06:07:52 -03:00
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Failed to identify Radio");
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
if (comPort.IsOpen)
|
|
|
|
|
comPort.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void iHex_ProgressEvent(double completed)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Progressbar.Value = (int)(completed * 100);
|
|
|
|
|
Application.DoEvents();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uploader_LogEvent(string message, int level = 0)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (level == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(message);
|
|
|
|
|
lbl_status.Text = message;
|
2012-05-07 11:25:56 -03:00
|
|
|
|
log.Info(message);
|
2012-02-23 21:38:56 -04:00
|
|
|
|
Application.DoEvents();
|
|
|
|
|
}
|
2012-05-08 10:21:19 -03:00
|
|
|
|
else if (level < 5) // 5 = byte data
|
|
|
|
|
{
|
|
|
|
|
log.Debug(message);
|
|
|
|
|
}
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void iHex_LogEvent(string message, int level = 0)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (level == 0)
|
|
|
|
|
{
|
|
|
|
|
lbl_status.Text = message;
|
|
|
|
|
Console.WriteLine(message);
|
2012-05-07 11:25:56 -03:00
|
|
|
|
log.Info(message);
|
2012-02-23 21:38:56 -04:00
|
|
|
|
Application.DoEvents();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uploader_ProgressEvent(double completed)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Progressbar.Value = (int)(completed * 100);
|
|
|
|
|
Application.DoEvents();
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
private void BUT_savesettings_Click(object sender, EventArgs e)
|
2012-02-23 21:38:56 -04:00
|
|
|
|
{
|
2012-04-24 10:49:27 -03:00
|
|
|
|
ArdupilotMega.Comms.ICommsSerial comPort = new SerialPort();
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-04-03 19:58:45 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
comPort.PortName = MainV2.comPort.BaseStream.PortName;
|
|
|
|
|
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-04-03 19:58:45 -03:00
|
|
|
|
comPort.ReadTimeout = 4000;
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-04-03 19:58:45 -03:00
|
|
|
|
comPort.Open();
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-02-24 07:39:02 -04:00
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
}
|
2012-03-09 11:18:12 -04:00
|
|
|
|
catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }
|
2012-02-26 19:13:23 -04:00
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Connecting";
|
|
|
|
|
|
|
|
|
|
if (doConnect(comPort))
|
|
|
|
|
{
|
2012-05-16 09:21:27 -03:00
|
|
|
|
// cleanup
|
|
|
|
|
doCommand(comPort, "AT&T");
|
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
comPort.DiscardInBuffer();
|
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Doing Command";
|
|
|
|
|
|
|
|
|
|
if (RTI.Text != "")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// remote
|
|
|
|
|
string answer = doCommand(comPort, "RTI5");
|
|
|
|
|
|
|
|
|
|
string[] items = answer.Split('\n');
|
|
|
|
|
|
|
|
|
|
foreach (string item in items)
|
|
|
|
|
{
|
|
|
|
|
if (item.StartsWith("S"))
|
|
|
|
|
{
|
|
|
|
|
string[] values = item.Split(':', '=');
|
|
|
|
|
|
|
|
|
|
if (values.Length == 3)
|
|
|
|
|
{
|
2012-06-02 03:32:22 -03:00
|
|
|
|
Control[] controls = this.Controls.Find("R" + values[0].Trim(), true);
|
2012-02-26 19:13:23 -04:00
|
|
|
|
|
|
|
|
|
if (controls.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
if (controls[0].GetType() == typeof(CheckBox))
|
|
|
|
|
{
|
|
|
|
|
string value = ((CheckBox)controls[0]).Checked ? "1" : "0";
|
|
|
|
|
|
|
|
|
|
if (value != values[2].Trim())
|
|
|
|
|
{
|
|
|
|
|
string cmdanswer = doCommand(comPort, "RT" + values[0].Trim() + "=" + value + "\r");
|
|
|
|
|
|
|
|
|
|
if (cmdanswer.Contains("OK"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Set Command error");
|
2012-02-26 19:13:23 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (controls[0].Text != values[2].Trim() && controls[0].Text != "")
|
|
|
|
|
{
|
|
|
|
|
string cmdanswer = doCommand(comPort, "RT" + values[0].Trim() + "=" + controls[0].Text + "\r");
|
|
|
|
|
|
|
|
|
|
if (cmdanswer.Contains("OK"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Set Command error");
|
2012-02-26 19:13:23 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// write it
|
|
|
|
|
doCommand(comPort, "RT&W");
|
|
|
|
|
|
|
|
|
|
// return to normal mode
|
|
|
|
|
doCommand(comPort, "RTZ");
|
|
|
|
|
|
|
|
|
|
Sleep(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comPort.DiscardInBuffer();
|
|
|
|
|
{
|
|
|
|
|
//local
|
|
|
|
|
string answer = doCommand(comPort, "ATI5");
|
|
|
|
|
|
|
|
|
|
string[] items = answer.Split('\n');
|
|
|
|
|
|
|
|
|
|
foreach (string item in items)
|
|
|
|
|
{
|
|
|
|
|
if (item.StartsWith("S"))
|
|
|
|
|
{
|
|
|
|
|
string[] values = item.Split(':', '=');
|
|
|
|
|
|
|
|
|
|
if (values.Length == 3)
|
|
|
|
|
{
|
2012-06-02 03:32:22 -03:00
|
|
|
|
Control[] controls = this.Controls.Find(values[0].Trim(), true);
|
2012-02-26 19:13:23 -04:00
|
|
|
|
|
|
|
|
|
if (controls.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
if (controls[0].GetType() == typeof(CheckBox))
|
|
|
|
|
{
|
|
|
|
|
string value = ((CheckBox)controls[0]).Checked ? "1" : "0";
|
|
|
|
|
|
|
|
|
|
if (value != values[2].Trim())
|
|
|
|
|
{
|
|
|
|
|
string cmdanswer = doCommand(comPort, "AT" + values[0].Trim() + "=" + value + "\r");
|
|
|
|
|
|
|
|
|
|
if (cmdanswer.Contains("OK"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Set Command error");
|
2012-02-26 19:13:23 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (controls[0].Text != values[2].Trim())
|
|
|
|
|
{
|
|
|
|
|
string cmdanswer = doCommand(comPort, "AT" + values[0].Trim() + "=" + controls[0].Text + "\r");
|
|
|
|
|
|
|
|
|
|
if (cmdanswer.Contains("OK"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Set Command error");
|
2012-02-26 19:13:23 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// write it
|
|
|
|
|
doCommand(comPort, "AT&W");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return to normal mode
|
|
|
|
|
doCommand(comPort, "ATZ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Done";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// return to normal mode
|
|
|
|
|
doCommand(comPort, "ATZ");
|
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Fail";
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Failed to enter command mode");
|
2012-02-26 19:13:23 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
comPort.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 09:21:27 -03:00
|
|
|
|
public static IEnumerable<int> Range(int start,int step, int end)
|
|
|
|
|
{
|
|
|
|
|
List<int> list = new List<int>();
|
|
|
|
|
|
|
|
|
|
for (int a = start; a <= end; a += step)
|
|
|
|
|
{
|
|
|
|
|
list.Add(a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
|
|
|
|
|
private void BUT_getcurrent_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-04-24 10:49:27 -03:00
|
|
|
|
ArdupilotMega.Comms.ICommsSerial comPort = new SerialPort();
|
2012-02-26 19:13:23 -04:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
comPort.PortName = MainV2.comPort.BaseStream.PortName;
|
|
|
|
|
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
|
|
|
|
|
|
|
|
|
|
comPort.ReadTimeout = 4000;
|
|
|
|
|
|
|
|
|
|
comPort.Open();
|
|
|
|
|
|
|
|
|
|
|
2012-02-24 07:39:02 -04:00
|
|
|
|
}
|
2012-03-09 11:18:12 -04:00
|
|
|
|
catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }
|
2012-02-24 07:39:02 -04:00
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
lbl_status.Text = "Connecting";
|
|
|
|
|
|
|
|
|
|
if (doConnect(comPort))
|
|
|
|
|
{
|
2012-05-16 09:21:27 -03:00
|
|
|
|
// cleanup
|
|
|
|
|
doCommand(comPort, "AT&T");
|
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
comPort.DiscardInBuffer();
|
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Doing Command ATI & RTI";
|
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
ATI.Text = doCommand(comPort, "ATI");
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-05-11 06:07:52 -03:00
|
|
|
|
RTI.Text = doCommand(comPort, "RTI");
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-05-16 09:21:27 -03:00
|
|
|
|
uploader.Uploader.Code freq = (uploader.Uploader.Code)Enum.Parse(typeof(uploader.Uploader.Code), doCommand(comPort, "ATI3"));
|
|
|
|
|
uploader.Uploader.Code board = (uploader.Uploader.Code)Enum.Parse(typeof(uploader.Uploader.Code), doCommand(comPort, "ATI2"));
|
|
|
|
|
|
|
|
|
|
ATI3.Text = freq.ToString();
|
|
|
|
|
// 8 and 9
|
|
|
|
|
if (freq == uploader.Uploader.Code.FREQ_915) {
|
|
|
|
|
S8.DataSource = Range(895000, 1000, 935000);
|
|
|
|
|
RS8.DataSource = Range(895000, 1000, 935000);
|
|
|
|
|
|
|
|
|
|
S9.DataSource = Range(895000, 1000, 935000);
|
|
|
|
|
RS9.DataSource = Range(895000, 1000, 935000);
|
|
|
|
|
}
|
|
|
|
|
else if (freq == uploader.Uploader.Code.FREQ_433)
|
|
|
|
|
{
|
|
|
|
|
S8.DataSource = Range(414000, 100, 454000);
|
|
|
|
|
RS8.DataSource = Range(414000, 100, 454000);
|
|
|
|
|
|
|
|
|
|
S9.DataSource = Range(414000, 100, 454000);
|
|
|
|
|
RS9.DataSource = Range(414000, 100, 454000);
|
|
|
|
|
}
|
2012-12-07 05:19:46 -04:00
|
|
|
|
else if (freq == uploader.Uploader.Code.FREQ_868)
|
|
|
|
|
{
|
|
|
|
|
S8.DataSource = Range(868000, 100, 869000);
|
|
|
|
|
RS8.DataSource = Range(868000, 100, 869000);
|
|
|
|
|
|
|
|
|
|
S9.DataSource = Range(868000, 100, 869000);
|
|
|
|
|
RS9.DataSource = Range(868000, 100, 869000);
|
|
|
|
|
}
|
2012-05-16 09:21:27 -03:00
|
|
|
|
|
2012-07-25 10:44:24 -03:00
|
|
|
|
if (board == uploader.Uploader.Code.DEVICE_ID_RFD900 || board == uploader.Uploader.Code.DEVICE_ID_RFD900A)
|
|
|
|
|
{
|
|
|
|
|
S4.DataSource = Range(1, 1, 30);
|
|
|
|
|
RS4.DataSource = Range(1, 1, 30);
|
|
|
|
|
}
|
2012-05-16 09:21:27 -03:00
|
|
|
|
|
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
RSSI.Text = doCommand(comPort, "ATI7").Trim();
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Doing Command ATI5";
|
|
|
|
|
|
|
|
|
|
string answer = doCommand(comPort, "ATI5");
|
|
|
|
|
|
|
|
|
|
string[] items = answer.Split('\n');
|
|
|
|
|
|
|
|
|
|
foreach (string item in items)
|
|
|
|
|
{
|
|
|
|
|
if (item.StartsWith("S"))
|
|
|
|
|
{
|
|
|
|
|
string[] values = item.Split(':', '=');
|
|
|
|
|
|
|
|
|
|
if (values.Length == 3)
|
|
|
|
|
{
|
2012-05-16 09:21:27 -03:00
|
|
|
|
Control[] controls = this.Controls.Find(values[0].Trim(), true);
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
|
|
|
|
if (controls.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
if (controls[0].GetType() == typeof(CheckBox))
|
|
|
|
|
{
|
|
|
|
|
((CheckBox)controls[0]).Checked = values[2].Trim() == "1";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
controls[0].Text = values[2].Trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remote
|
2012-05-20 02:54:35 -03:00
|
|
|
|
foreach (Control ctl in groupBox2.Controls)
|
2012-02-24 07:39:02 -04:00
|
|
|
|
{
|
|
|
|
|
if (ctl.Name.StartsWith("RS") && ctl.Name != "RSSI")
|
|
|
|
|
ctl.ResetText();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
|
|
|
|
comPort.DiscardInBuffer();
|
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Doing Command RTI5";
|
|
|
|
|
|
|
|
|
|
answer = doCommand(comPort, "RTI5");
|
|
|
|
|
|
|
|
|
|
items = answer.Split('\n');
|
|
|
|
|
|
|
|
|
|
foreach (string item in items)
|
|
|
|
|
{
|
|
|
|
|
if (item.StartsWith("S"))
|
|
|
|
|
{
|
|
|
|
|
string[] values = item.Split(':', '=');
|
|
|
|
|
|
|
|
|
|
if (values.Length == 3)
|
|
|
|
|
{
|
2012-05-16 09:21:27 -03:00
|
|
|
|
Control[] controls = this.Controls.Find("R" + values[0].Trim(), true);
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-04-05 21:50:04 -03:00
|
|
|
|
if (controls.Length == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
if (controls[0].GetType() == typeof(CheckBox))
|
|
|
|
|
{
|
|
|
|
|
((CheckBox)controls[0]).Checked = values[2].Trim() == "1";
|
|
|
|
|
}
|
2012-02-24 07:39:02 -04:00
|
|
|
|
else if (controls[0].GetType() == typeof(TextBox))
|
2012-02-23 21:38:56 -04:00
|
|
|
|
{
|
2012-02-24 07:39:02 -04:00
|
|
|
|
((TextBox)controls[0]).Text = values[2].Trim();
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
2012-02-24 07:39:02 -04:00
|
|
|
|
else if (controls[0].GetType() == typeof(ComboBox))
|
|
|
|
|
{
|
2012-05-20 02:54:35 -03:00
|
|
|
|
((ComboBox)controls[0]).Text = values[2].Trim();
|
2012-02-24 07:39:02 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-05-07 11:25:56 -03:00
|
|
|
|
log.Info("Odd config line :" + item);
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 07:39:02 -04:00
|
|
|
|
// off hook
|
|
|
|
|
doCommand(comPort, "ATO");
|
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
lbl_status.Text = "Done";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-02-24 07:39:02 -04:00
|
|
|
|
|
|
|
|
|
// off hook
|
|
|
|
|
doCommand(comPort, "ATO");
|
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
lbl_status.Text = "Fail";
|
2012-03-09 11:18:12 -04:00
|
|
|
|
CustomMessageBox.Show("Failed to enter command mode");
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comPort.Close();
|
2012-04-05 21:50:04 -03:00
|
|
|
|
|
2012-05-16 09:21:27 -03:00
|
|
|
|
BUT_Syncoptions.Enabled = true;
|
|
|
|
|
|
2012-04-05 21:50:04 -03:00
|
|
|
|
BUT_savesettings.Enabled = true;
|
2012-02-24 07:39:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 10:49:27 -03:00
|
|
|
|
string Serial_ReadLine(ArdupilotMega.Comms.ICommsSerial comPort)
|
2012-02-24 07:39:02 -04:00
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
DateTime Deadline = DateTime.Now.AddMilliseconds(comPort.ReadTimeout);
|
|
|
|
|
|
|
|
|
|
while (DateTime.Now < Deadline)
|
|
|
|
|
{
|
|
|
|
|
if (comPort.BytesToRead > 0)
|
|
|
|
|
{
|
|
|
|
|
byte data = (byte)comPort.ReadByte();
|
|
|
|
|
sb.Append((char)data);
|
|
|
|
|
if (data == '\n')
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-02-24 07:39:02 -04:00
|
|
|
|
return sb.ToString();
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 09:21:27 -03:00
|
|
|
|
public string doCommand(ArdupilotMega.Comms.ICommsSerial comPort, string cmd, int level = 0)
|
2012-02-23 21:38:56 -04:00
|
|
|
|
{
|
2012-02-24 07:39:02 -04:00
|
|
|
|
if (!comPort.IsOpen)
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
comPort.ReadTimeout = 1000;
|
|
|
|
|
// setup to known state
|
|
|
|
|
comPort.Write("\r\n");
|
|
|
|
|
// alow some time to gather thoughts
|
2012-02-23 21:38:56 -04:00
|
|
|
|
Sleep(100);
|
2012-02-24 07:39:02 -04:00
|
|
|
|
// ignore all existing data
|
2012-02-23 21:38:56 -04:00
|
|
|
|
comPort.DiscardInBuffer();
|
2012-02-26 19:13:23 -04:00
|
|
|
|
lbl_status.Text = "Doing Command " + cmd;
|
2012-05-07 11:25:56 -03:00
|
|
|
|
log.Info("Doing Command " + cmd);
|
2012-02-24 07:39:02 -04:00
|
|
|
|
// write command
|
2012-02-23 21:38:56 -04:00
|
|
|
|
comPort.Write(cmd + "\r\n");
|
2012-02-24 07:39:02 -04:00
|
|
|
|
// read echoed line or existing data
|
|
|
|
|
string temp;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
temp = Serial_ReadLine(comPort);
|
|
|
|
|
}
|
|
|
|
|
catch { temp = comPort.ReadExisting(); }
|
2012-05-07 11:25:56 -03:00
|
|
|
|
log.Info("cmd " + cmd + " echo " + temp);
|
2012-02-24 07:39:02 -04:00
|
|
|
|
// delay for command
|
2012-02-23 21:38:56 -04:00
|
|
|
|
Sleep(500);
|
2012-02-24 07:39:02 -04:00
|
|
|
|
// get responce
|
2012-02-23 21:38:56 -04:00
|
|
|
|
string ans = "";
|
|
|
|
|
while (comPort.BytesToRead > 0)
|
|
|
|
|
{
|
2012-02-24 07:39:02 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-02-26 19:13:23 -04:00
|
|
|
|
ans = ans + Serial_ReadLine(comPort) + "\n";
|
2012-02-24 07:39:02 -04:00
|
|
|
|
}
|
|
|
|
|
catch { ans = ans + comPort.ReadExisting() + "\n"; }
|
2012-02-23 21:38:56 -04:00
|
|
|
|
Sleep(50);
|
|
|
|
|
|
|
|
|
|
if (ans.Length > 500)
|
2012-02-24 07:39:02 -04:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 11:25:56 -03:00
|
|
|
|
log.Info("responce " + level + " " + ans.Replace('\0', ' '));
|
2012-02-24 07:39:02 -04:00
|
|
|
|
|
|
|
|
|
// try again
|
|
|
|
|
if (ans == "" && level == 0)
|
|
|
|
|
return doCommand(comPort, cmd, 1);
|
|
|
|
|
|
2012-02-23 21:38:56 -04:00
|
|
|
|
return ans;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 09:21:27 -03:00
|
|
|
|
public bool doConnect(ArdupilotMega.Comms.ICommsSerial comPort)
|
2012-02-23 21:38:56 -04:00
|
|
|
|
{
|
2012-11-25 01:42:46 -04:00
|
|
|
|
try
|
2012-02-23 21:38:56 -04:00
|
|
|
|
{
|
2012-11-25 01:42:46 -04:00
|
|
|
|
// clear buffer
|
|
|
|
|
comPort.DiscardInBuffer();
|
|
|
|
|
// setup a known enviroment
|
2012-02-23 21:38:56 -04:00
|
|
|
|
comPort.Write("\r\n");
|
2012-11-25 01:42:46 -04:00
|
|
|
|
// wait
|
|
|
|
|
Sleep(1100);
|
|
|
|
|
// send config string
|
|
|
|
|
comPort.Write("+++");
|
|
|
|
|
// wait
|
|
|
|
|
Sleep(1100);
|
|
|
|
|
// check for config responce "OK"
|
|
|
|
|
log.Info("Connect btr " + comPort.BytesToRead + " baud " + comPort.BaudRate);
|
|
|
|
|
string conn = comPort.ReadExisting();
|
|
|
|
|
log.Info("Connect first responce " + conn.Replace('\0', ' ') + " " + conn.Length);
|
|
|
|
|
if (conn.Contains("OK"))
|
|
|
|
|
{
|
|
|
|
|
//return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// cleanup incase we are already in cmd mode
|
|
|
|
|
comPort.Write("\r\n");
|
|
|
|
|
}
|
2012-05-16 09:21:27 -03:00
|
|
|
|
|
2012-11-25 01:42:46 -04:00
|
|
|
|
doCommand(comPort, "AT&T");
|
2012-05-16 09:21:27 -03:00
|
|
|
|
|
2012-11-25 01:42:46 -04:00
|
|
|
|
string version = doCommand(comPort, "ATI");
|
2012-05-16 09:21:27 -03:00
|
|
|
|
|
2012-11-25 01:42:46 -04:00
|
|
|
|
log.Info("Connect Version: " + version.Trim() + "\n");
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-11-25 01:42:46 -04:00
|
|
|
|
Regex regex = new Regex(@"SiK\s+(.*)\s+on\s+(.*)");
|
2012-02-23 21:38:56 -04:00
|
|
|
|
|
2012-11-25 01:42:46 -04:00
|
|
|
|
if (regex.IsMatch(version))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-05-11 06:07:52 -03:00
|
|
|
|
|
2012-11-25 01:42:46 -04:00
|
|
|
|
return false;
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
2012-11-25 01:42:46 -04:00
|
|
|
|
catch { return false; }
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 09:21:27 -03:00
|
|
|
|
private void BUT_Syncoptions_Click(object sender, EventArgs e)
|
2012-02-24 07:39:02 -04:00
|
|
|
|
{
|
|
|
|
|
RS2.Text = S2.Text;
|
|
|
|
|
RS3.Text = S3.Text;
|
|
|
|
|
RS5.Checked = S5.Checked;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
RS8.Text = S8.Text;
|
|
|
|
|
RS9.Text = S9.Text;
|
2012-05-16 09:21:27 -03:00
|
|
|
|
RS10.Text = S10.Text;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 09:21:27 -03:00
|
|
|
|
private void CHK_advanced_CheckedChanged(object sender, EventArgs e)
|
2012-04-21 04:30:15 -03:00
|
|
|
|
{
|
2012-05-16 09:21:27 -03:00
|
|
|
|
SPLIT_local.Panel2Collapsed = !CHK_advanced.Checked;
|
|
|
|
|
SPLIT_remote.Panel2Collapsed = !CHK_advanced.Checked;
|
2012-04-21 04:30:15 -03:00
|
|
|
|
}
|
2012-07-22 04:51:05 -03:00
|
|
|
|
|
|
|
|
|
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CustomMessageBox.Show(@"The 3DR Radios have 2 status LEDs, one red and one green.
|
|
|
|
|
green LED blinking - searching for another radio
|
|
|
|
|
green LED solid - link is established with another radio
|
|
|
|
|
red LED flashing - transmitting data
|
|
|
|
|
red LED solid - in firmware update mode");
|
|
|
|
|
}
|
2012-10-30 20:02:29 -03:00
|
|
|
|
|
|
|
|
|
private void BUT_resettodefault_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ArdupilotMega.Comms.ICommsSerial comPort = new SerialPort();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
comPort.PortName = MainV2.comPort.BaseStream.PortName;
|
|
|
|
|
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
|
|
|
|
|
|
|
|
|
|
comPort.ReadTimeout = 4000;
|
|
|
|
|
|
|
|
|
|
comPort.Open();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch { CustomMessageBox.Show("Invalid ComPort or in use"); return; }
|
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Connecting";
|
|
|
|
|
|
|
|
|
|
if (doConnect(comPort))
|
|
|
|
|
{
|
|
|
|
|
// cleanup
|
|
|
|
|
doCommand(comPort, "AT&T");
|
|
|
|
|
|
|
|
|
|
comPort.DiscardInBuffer();
|
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Doing Command ATI & AT&F";
|
|
|
|
|
|
|
|
|
|
doCommand(comPort, "AT&F");
|
|
|
|
|
|
|
|
|
|
doCommand(comPort, "AT&W");
|
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Reset";
|
|
|
|
|
|
|
|
|
|
doCommand(comPort, "ATZ");
|
|
|
|
|
|
|
|
|
|
comPort.Close();
|
|
|
|
|
|
|
|
|
|
BUT_getcurrent_Click(sender, e);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// off hook
|
|
|
|
|
doCommand(comPort, "ATO");
|
|
|
|
|
|
|
|
|
|
lbl_status.Text = "Fail";
|
|
|
|
|
CustomMessageBox.Show("Failed to enter command mode");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (comPort.IsOpen)
|
|
|
|
|
comPort.Close();
|
|
|
|
|
}
|
2012-02-23 21:38:56 -04:00
|
|
|
|
}
|
|
|
|
|
}
|