Beispiel #1
0
        void UpdateFWList()
        {
            pdr = new ProgressReporterDialogue();

            pdr.DoWork -= pdr_DoWork;

            pdr.DoWork += pdr_DoWork;

            ThemeManager.ApplyThemeTo(pdr);

            pdr.RunBackgroundOperationAsync();
        }
Beispiel #2
0
        internal void Firmware_Load(object sender, EventArgs e)
        {
            pdr = new ProgressReporterDialogue();

            pdr.DoWork -= pdr_DoWork;

            pdr.DoWork += pdr_DoWork;

            ThemeManager.ApplyThemeTo(pdr);

            pdr.RunBackgroundOperationAsync();
        }
Beispiel #3
0
        private void BUT_MagCalibration_Click(object sender, EventArgs e)
        {
            CustomMessageBox.Show("Data will be collected for 60 seconds, Please click ok and move the apm around all axises");

            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            Utilities.ThemeManager.ApplyThemeTo(prd);

            prd.DoWork += prd_DoWork;

            prd.RunBackgroundOperationAsync();
        }
Beispiel #4
0
        public static void DoUpdate()
        {
            ProgressReporterDialogue frmProgressReporter = new ProgressReporterDialogue()
            {
                Text          = "Check for Updates",
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            };

            ThemeManager.ApplyThemeTo(frmProgressReporter);

            frmProgressReporter.DoWork += new ProgressReporterDialogue.DoWorkEventHandler(DoUpdateWorker_DoWork);

            frmProgressReporter.UpdateProgressAndStatus(-1, "Checking for Updates");

            frmProgressReporter.RunBackgroundOperationAsync();
        }
        private void BUT_paramgen_Click(object sender, System.EventArgs e)
        {
            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            prd.DoWork += dialogue =>
            {
                ParameterMetaDataParser.GetParameterInformation(
                    ConfigurationManager.AppSettings["ParameterLocationsBleeding"] + ";" +
                    ConfigurationManager.AppSettings["ParameterLocations"]);

                ParameterMetaDataRepositoryAPM.Reload();
            };

            prd.doWorkArgs.ForceExit = true;

            prd.RunBackgroundOperationAsync();
        }
        private void GetParameters(byte nodeID)
        {
            IProgressReporterDialogue prd = new ProgressReporterDialogue();
            List <uavcan.uavcan_protocol_param_GetSet_res> paramlist =
                new List <uavcan.uavcan_protocol_param_GetSet_res>();

            prd.doWorkArgs.ForceExit             = true;
            prd.doWorkArgs.CancelRequestChanged += (sender2, args) => { prd.doWorkArgs.CancelAcknowledged = true; };
            prd.DoWork += dialogue => { paramlist = can.GetParameters(nodeID); };
            prd.UpdateProgressAndStatus(-1, Strings.GettingParams);
            prd.RunBackgroundOperationAsync();

            if (!prd.doWorkArgs.CancelRequested)
            {
                new UAVCANParams(can, nodeID, paramlist).ShowUserControl();
            }
        }
Beispiel #7
0
        void doUI(string inputfn, string outputfn, bool showui = true)
        {
            this.inputfn  = inputfn;
            this.outputfn = outputfn;

            prd = new ProgressReporterDialogue();

            prd.DoWork += prd_DoWork;

            prd.UpdateProgressAndStatus(-1, Strings.Converting_bin_to_log);

            this.convertstatus += BinaryLog_convertstatus;

            ThemeManager.ApplyThemeTo(prd);

            prd.RunBackgroundOperationAsync();

            prd.Dispose();
        }
Beispiel #8
0
        private void BUT_MagCalibration_Click(object sender, EventArgs e)
        {
            MainV2.comPort.MAV.cs.ratesensors = 2;

            MainV2.comPort.requestDatastream(ArdupilotMega.MAVLink.MAV_DATA_STREAM.EXTRA3, MainV2.comPort.MAV.cs.ratesensors);
            MainV2.comPort.requestDatastream(ArdupilotMega.MAVLink.MAV_DATA_STREAM.RAW_SENSORS, MainV2.comPort.MAV.cs.ratesensors);

            MainV2.comPort.setParam("MAG_ENABLE", 1);

            CustomMessageBox.Show("Data will be collected for 60 seconds, Please click ok and move the apm around all axises");

            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            Utilities.ThemeManager.ApplyThemeTo(prd);

            prd.DoWork += prd_DoWork;

            prd.RunBackgroundOperationAsync();
        }
        public void Open()
        {
            if (client.Client.Connected)
            {
                log.Info("udpserial socket already open");
                return;
            }

            ProgressReporterDialogue frmProgressReporter = new ProgressReporterDialogue
            {
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen,
                Text          = "Connecting Mavlink UDP"
            };

            frmProgressReporter.DoWork += frmProgressReporter_DoWork;

            frmProgressReporter.UpdateProgressAndStatus(-1, "Connecting Mavlink UDP");

            frmProgressReporter.RunBackgroundOperationAsync();
        }
Beispiel #10
0
        public static void DownloadGStreamer()
        {
            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            ThemeManager.ApplyThemeTo(prd);
            prd.DoWork += sender =>
            {
                GStreamer.DownloadGStreamer(((i, s) =>
                {
                    prd.UpdateProgressAndStatus(i, s);
                    if (prd.doWorkArgs.CancelRequested)
                    {
                        throw new Exception("User Request");
                    }
                }));
            };
            prd.RunBackgroundOperationAsync();

            GStreamer.gstlaunch = GStreamer.LookForGstreamer();
        }
Beispiel #11
0
        private void BUT_paramgen_Click(object sender, System.EventArgs e)
        {
            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            prd.DoWork += dialogue =>
            {
                prd.UpdateProgressAndStatus(-1, "Downloading updated data");
                ParameterMetaDataParser.GetParameterInformation(
                    ConfigurationManager.AppSettings["ParameterLocationsBleeding"] + ";" +
                    ConfigurationManager.AppSettings["ParameterLocations"] + ";"
                    + "https://raw.githubusercontent.com/BeagleSystems/ardupilot/master/ArduPlane/Parameters.cpp;");

                ParameterMetaDataRepositoryAPM.Reload();
            };

            prd.doWorkArgs.CancelRequestChanged += (sender2, args) => { prd.doWorkArgs.CancelAcknowledged = true; };

            prd.doWorkArgs.ForceExit = true;

            prd.RunBackgroundOperationAsync();
        }
Beispiel #12
0
        public int WizardValidate()
        {
            comport = CMB_port.Text;

            pdr = new ProgressReporterDialogue();

            pdr.DoWork -= pdr_DoWork;

            pdr.DoWork += pdr_DoWork;

            ThemeManager.ApplyThemeTo(pdr);

            pdr.RunBackgroundOperationAsync();

            MainV2.comPort.BaseStream.BaudRate = 115200;
            MainV2.comPort.BaseStream.PortName = comport;

            MainV2.comPort.Open(true);

            if (!MainV2.comPort.BaseStream.IsOpen)
            {
                return(0);
            }

            if (string.IsNullOrEmpty(pdr.doWorkArgs.ErrorMessage))
            {
                if (Wizard.config["fwtype"].ToString() == "copter")
                {
                    // check if its a quad, and show the frame type screen
                    return(1);
                }
                else
                {
                    // skip the frame type screen as its not valid for anythine else
                    return(2);
                }
            }

            return(0);
        }
        private void BUT_paramgen_Click(object sender, System.EventArgs e)
        {
            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            prd.DoWork += dialogue =>
            {
                prd.UpdateProgressAndStatus(-1, "Downloading updated data");
                ParameterMetaDataParser.GetParameterInformation(
                    ConfigurationManager.AppSettings["ParameterLocationsBleeding"] + ";" +
                    ConfigurationManager.AppSettings["ParameterLocations"] + ";"
                    + "https://raw.githubusercontent.com/ArduPilot/ardupilot/Copter-3.6/ArduCopter/Parameters.cpp;" +
                    "https://raw.githubusercontent.com/ArduPilot/ardupilot/Copter-3.5/ArduCopter/Parameters.cpp;" +
                    "https://raw.githubusercontent.com/ArduPilot/ardupilot/plane3.9/ArduCopter/Parameters.cpp;" +
                    "https://raw.githubusercontent.com/ArduPilot/ardupilot/plane3.8/ArduCopter/Parameters.cpp;");

                ParameterMetaDataRepositoryAPM.Reload();
            };

            prd.doWorkArgs.ForceExit = true;

            prd.RunBackgroundOperationAsync();
        }
Beispiel #14
0
        public void Open()
        {
            if (client.Client.Connected || IsOpen)
            {
                log.Info("udpserial socket already open");
                return;
            }

            client.Close();

            string dest = Port;

            dest = OnSettings("UDP_port", dest);

            if (System.Windows.Forms.DialogResult.Cancel == InputBox.Show("Listern Port", "Enter Local port (ensure remote end is already sending)", ref dest))
            {
                return;
            }
            Port = dest;

            OnSettings("UDP_port", Port, true);

            ProgressReporterDialogue frmProgressReporter = new ProgressReporterDialogue
            {
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen,
                Text          = "Connecting UDP"
            };

            ApplyThemeTo(frmProgressReporter);

            frmProgressReporter.DoWork += frmProgressReporter_DoWork;

            frmProgressReporter.UpdateProgressAndStatus(-1, "Connecting UDP");

            frmProgressReporter.RunBackgroundOperationAsync();

            frmProgressReporter.Dispose();
        }
Beispiel #15
0
        public static void DoUpdate()
        {
            if (Program.WindowsStoreApp)
            {
                CustomMessageBox.Show(Strings.Not_available_when_used_as_a_windows_store_app);
                return;
            }

            IProgressReporterDialogue frmProgressReporter = new ProgressReporterDialogue()
            {
                Text          = "Check for Updates",
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            };

            ThemeManager.ApplyThemeTo(frmProgressReporter);

            frmProgressReporter.DoWork += new DoWorkEventHandler(DoUpdateWorker_DoWork);

            frmProgressReporter.UpdateProgressAndStatus(-1, "Checking for Updates");

            frmProgressReporter.RunBackgroundOperationAsync();

            frmProgressReporter.Dispose();
        }
Beispiel #16
0
        public static void DoUpdate()
        {
            ProgressReporterDialogue frmProgressReporter = new ProgressReporterDialogue()
            {
                Text = "Check for Updates",
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            };

            ThemeManager.ApplyThemeTo(frmProgressReporter);

            frmProgressReporter.DoWork += new Controls.ProgressReporterDialogue.DoWorkEventHandler(DoUpdateWorker_DoWork);

            frmProgressReporter.UpdateProgressAndStatus(-1, "Checking for Updates");

            frmProgressReporter.RunBackgroundOperationAsync();
        }
Beispiel #17
0
        public int WizardValidate()
        {
            comport = CMB_port.Text;

            if (comport == "")
            {
                CustomMessageBox.Show("Please select a comport", "error");
                return(0);
            }

            if (!fwdone)
            {
                pdr = new ProgressReporterDialogue();

                pdr.DoWork += pdr_DoWork;

                ThemeManager.ApplyThemeTo(pdr);

                pdr.RunBackgroundOperationAsync();

                if (pdr.doWorkArgs.CancelRequested || !string.IsNullOrEmpty(pdr.doWorkArgs.ErrorMessage))
                {
                    return(0);
                }
            }

            if (MainV2.comPort.BaseStream.IsOpen)
            {
                MainV2.comPort.BaseStream.Close();
            }

            // setup for over usb
            MainV2.comPort.BaseStream.BaudRate = 115200;
            MainV2.comPort.BaseStream.PortName = comport;


            MainV2.comPort.Open(true);

            // try again
            if (!MainV2.comPort.BaseStream.IsOpen)
            {
                CustomMessageBox.Show("Error connecting. Please unplug, plug back in, wait 10 seconds, and click OK", "Try Again");
                MainV2.comPort.Open(true);
            }

            if (!MainV2.comPort.BaseStream.IsOpen)
            {
                return(0);
            }

            if (string.IsNullOrEmpty(pdr.doWorkArgs.ErrorMessage))
            {
                if (Wizard.config["fwtype"].ToString() == "copter")
                {
                    // check if its a quad, and show the frame type screen
                    return(1);
                }
                else
                {
                    // skip the frame type screen as its not valid for anythine else
                    return(2);
                }
            }

            return(0);
        }
        private void FirmwareUpdate(byte nodeID, bool beta = false)
        {
            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            uavcan.FileSendProgressArgs filesend = (id, file, percent) =>
            {
                prd.UpdateProgressAndStatus((int)percent, id + " " + file);
            };
            can.FileSendProgress += filesend;
            var devicename = can.GetNodeName(nodeID);
            var hwversion  =
                double.Parse(
                    can.NodeInfo[nodeID].hardware_version.major + "." + can.NodeInfo[nodeID].hardware_version.minor,
                    CultureInfo.InvariantCulture);

            if (CustomMessageBox.Show("Do you want to search the internet for an update?", "Update",
                                      CustomMessageBox.MessageBoxButtons.YesNo) == CustomMessageBox.DialogResult.Yes)
            {
                var url = can.LookForUpdate(devicename, hwversion, beta);

                if (url != string.Empty)
                {
                    try
                    {
                        var cancel = new CancellationTokenSource();

                        prd.DoWork += dialogue =>
                        {
                            prd.UpdateProgressAndStatus(5, "Download FW");
                            var tempfile = Path.GetTempFileName();
                            Download.getFilefromNet(url, tempfile);

                            uavcan.FileSendCompleteArgs file = (p, s) =>
                            {
                                prd.UpdateProgressAndStatus(100, "File send complete");
                            };
                            uavcan.FileSendProgressArgs fileprog = (n, f, p) =>
                            {
                                prd.UpdateProgressAndStatus((int)p, f);
                            };
                            can.FileSendComplete += file;
                            can.FileSendProgress += fileprog;

                            try
                            {
                                can.Update(nodeID, devicename, hwversion, tempfile, cancel.Token);
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                            finally
                            {
                                can.FileSendComplete -= file;
                                can.FileSendProgress -= fileprog;
                            }

                            return;
                        };

                        prd.btnCancel.Click += (sender, args) =>
                        {
                            prd.doWorkArgs.CancelAcknowledged = true;
                            cancel.Cancel();
                        };

                        prd.RunBackgroundOperationAsync();
                    }
                    catch (Exception ex)
                    {
                        CustomMessageBox.Show(ex.Message, Strings.ERROR);
                    }
                }
                else
                {
                    CustomMessageBox.Show(Strings.UpdateNotFound, Strings.UpdateNotFound);
                }
            }
            else
            {
                FileDialog fd = new OpenFileDialog();
                fd.RestoreDirectory = true;
                fd.Filter           = "*.bin|*.bin";
                var dia = fd.ShowDialog();

                if (fd.CheckFileExists && dia == DialogResult.OK)
                {
                    uavcan.FileSendCompleteArgs file = (p, s) =>
                    {
                        prd.UpdateProgressAndStatus(100, "File send complete");
                    };
                    uavcan.FileSendProgressArgs fileprog = (n, f, p) =>
                    {
                        prd.UpdateProgressAndStatus((int)p, f);
                    };
                    can.FileSendComplete += file;
                    can.FileSendProgress += fileprog;

                    try
                    {
                        var cancel = new CancellationTokenSource();

                        prd.DoWork += dialogue =>
                        {
                            can.Update(nodeID,
                                       devicename, 0,
                                       fd.FileName, cancel.Token);

                            return;
                        };

                        prd.btnCancel.Click += (sender, args) =>
                        {
                            prd.doWorkArgs.CancelAcknowledged = true;
                            cancel.Cancel();
                        };

                        prd.RunBackgroundOperationAsync();
                    }
                    catch (Exception ex)
                    {
                        CustomMessageBox.Show(ex.Message, Strings.ERROR);
                    }
                    finally
                    {
                        can.FileSendComplete -= file;
                        can.FileSendProgress -= fileprog;
                    }
                }
            }

            can.FileSendProgress -= filesend;
            prd.Dispose();
        }
Beispiel #19
0
        private async void myDataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            // Ignore clicks that are not on button cells.
            if (e.RowIndex < 0 || e.ColumnIndex !=
                myDataGridView1.Columns["updateDataGridViewTextBoxColumn"].Index &&
                e.ColumnIndex != myDataGridView1.Columns["Parameter"].Index)
            {
                return;
            }

            byte nodeID = (byte)myDataGridView1[iDDataGridViewTextBoxColumn.Index, e.RowIndex].Value;

            if (e.ColumnIndex == myDataGridView1.Columns["Parameter"].Index)
            {
                var paramlist = can.GetParameters(nodeID);

                new UAVCANParams(can, nodeID, paramlist).ShowUserControl();
            }
            else if (e.ColumnIndex == myDataGridView1.Columns["updateDataGridViewTextBoxColumn"].Index)
            {
                ProgressReporterDialogue    prd      = new ProgressReporterDialogue();
                uavcan.FileSendProgressArgs filesend = (id, file, percent) =>
                {
                    prd.UpdateProgressAndStatus((int)percent, id + " " + file);
                };
                can.FileSendProgress += filesend;
                if (CustomMessageBox.Show("Do you want to search the internet for an update?", "Update", CustomMessageBox.MessageBoxButtons.YesNo) == CustomMessageBox.DialogResult.Yes)
                {
                    var devicename = myDataGridView1[nameDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString();
                    var hwversion  = double.Parse(myDataGridView1[hardwareVersionDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString(), CultureInfo.InvariantCulture);

                    var url = can.LookForUpdate(devicename, hwversion);

                    if (url != string.Empty)
                    {
                        try
                        {
                            prd.DoWork += dialogue =>
                            {
                                var tempfile = Path.GetTempFileName();
                                Download.getFilefromNet(url, tempfile);

                                can.Update(nodeID, devicename, hwversion, tempfile);

                                return;
                            };

                            prd.RunBackgroundOperationAsync();
                        }
                        catch (Exception ex)
                        {
                            CustomMessageBox.Show(ex.Message, Strings.ERROR);
                        }
                    }
                    else
                    {
                        CustomMessageBox.Show(Strings.UpdateNotFound, Strings.UpdateNotFound);
                    }
                }
                else
                {
                    FileDialog fd = new OpenFileDialog();
                    fd.RestoreDirectory = true;
                    fd.Filter           = "*-crc.bin|*-crc.bin";
                    var dia = fd.ShowDialog();

                    if (fd.CheckFileExists && dia == DialogResult.OK)
                    {
                        try
                        {
                            prd.DoWork += dialogue =>
                            {
                                can.Update(nodeID, myDataGridView1[nameDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString(), 0,
                                           fd.FileName);

                                return;
                            };

                            prd.RunBackgroundOperationAsync();
                        }
                        catch (Exception ex)
                        {
                            CustomMessageBox.Show(ex.Message, Strings.ERROR);
                        }
                    }
                }
                can.FileSendProgress -= filesend;
                prd.Dispose();
            }
        }
Beispiel #20
0
        private void SetupSLCanPort(ICommsSerial port)
        {
            //check if we started from within mavlink - if not get settings from menu and create port
            if (port == null || !port.IsOpen)
            {
                switch (MainV2._connectionControl.CMB_serialport.Text)
                {
                case "TCP":
                    port = new TcpSerial();
                    break;

                case "UDP":
                    port = new UdpSerial();
                    break;

                case "WS":
                    port = new WebSocket();
                    break;

                case "UDPCl":
                    port = new UdpSerialConnect();
                    break;

                default:
                    port = new SerialPort()
                    {
                        PortName = MainV2._connectionControl.CMB_serialport.Text,
                        BaudRate = int.Parse(MainV2._connectionControl.CMB_baudrate.Text)
                    };
                    break;
                }
            }

            if (can == null)
            {
                can = new DroneCAN.DroneCAN();
            }

            can.SourceNode = 127;

            can.NodeAdded += (id, msg) =>
            {
                this.BeginInvoke((Action) delegate
                {
                    allnodes.Add(new DroneCANModel()
                    {
                        ID     = id,
                        Name   = "?",
                        Health = msg.health.ToString(),
                        Mode   = msg.mode.ToString(),
                        Uptime = TimeSpan.FromSeconds(msg.uptime_sec),
                        VSC    = msg.vendor_specific_status_code
                    });

                    uAVCANModelBindingSource.ResetBindings(false);
                });
            };

            if (!port.IsOpen)
            {
                try
                {
                    port.Open();
                }
                catch (Exception)
                {
                    CustomMessageBox.Show(Strings.CheckPortSettingsOr);
                    return;
                }
            }

            if (chk_log.Checked)
            {
                can.LogFile = Settings.Instance.LogDir + Path.DirectorySeparatorChar +
                              DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".can";
            }

            var prd = new ProgressReporterDialogue();

            prd.UpdateProgressAndStatus(-1, "Trying to connect");
            prd.DoWork          += sender => can.StartSLCAN(port.BaseStream);
            prd.btnCancel.Click += (sender, args) =>
            {
                prd.doWorkArgs.CancelAcknowledged = true;
                port.Close();
            };
            prd.RunBackgroundOperationAsync();

            if (prd.doWorkArgs.CancelRequested || prd.doWorkArgs.ErrorMessage != null)
            {
                return;
            }

            can.SetupFileServer();

            can.SetupDynamicNodeAllocator();

            can.MessageReceived += (frame, msg, transferID) =>
            {
                if (msg.GetType() == typeof(DroneCAN.DroneCAN.uavcan_protocol_NodeStatus))
                {
                    var ns = msg as DroneCAN.DroneCAN.uavcan_protocol_NodeStatus;

                    var nodes = allnodes.Where((a) => a.ID == frame.SourceNode);

                    if (nodes.Count() > 0 && nodes.First().Name == "?")
                    {
                        var statetracking = new DroneCAN.DroneCAN.statetracking();
                        // get node info
                        DroneCAN.DroneCAN.uavcan_protocol_GetNodeInfo_req gnireq =
                            new DroneCAN.DroneCAN.uavcan_protocol_GetNodeInfo_req()
                        {
                        };
                        gnireq.encode(DroneCAN.DroneCAN.dronecan_transmit_chunk_handler, statetracking);

                        var slcan = can.PackageMessageSLCAN(frame.SourceNode, 30, 0, gnireq);
                        can.WriteToStreamSLCAN(slcan);
                    }

                    foreach (var item in nodes)
                    {
                        switch (ns.health)
                        {
                        case (byte)DroneCAN.DroneCAN.uavcan_protocol_NodeStatus.UAVCAN_PROTOCOL_NODESTATUS_HEALTH_OK:
                            item.Health = "OK";
                            break;

                        case (byte)DroneCAN.DroneCAN.uavcan_protocol_NodeStatus.UAVCAN_PROTOCOL_NODESTATUS_HEALTH_WARNING:
                            item.Health = "WARNING";
                            break;

                        case (byte)DroneCAN.DroneCAN.uavcan_protocol_NodeStatus.UAVCAN_PROTOCOL_NODESTATUS_HEALTH_ERROR:
                            item.Health = "ERROR";
                            break;

                        case (byte)DroneCAN.DroneCAN.uavcan_protocol_NodeStatus.UAVCAN_PROTOCOL_NODESTATUS_HEALTH_CRITICAL:
                            item.Health = "CRITICAL";
                            break;
                        }

                        switch (ns.mode)
                        {
                        case (byte)DroneCAN.DroneCAN.uavcan_protocol_NodeStatus.UAVCAN_PROTOCOL_NODESTATUS_MODE_OPERATIONAL:
                            item.Mode = "OPERATIONAL";
                            break;

                        case (byte)DroneCAN.DroneCAN.uavcan_protocol_NodeStatus.UAVCAN_PROTOCOL_NODESTATUS_MODE_INITIALIZATION:
                            item.Mode = "INITIALIZATION";
                            break;

                        case (byte)DroneCAN.DroneCAN.uavcan_protocol_NodeStatus.UAVCAN_PROTOCOL_NODESTATUS_MODE_MAINTENANCE:
                            item.Mode = "MAINTENANCE";
                            break;

                        case (byte)DroneCAN.DroneCAN.uavcan_protocol_NodeStatus.UAVCAN_PROTOCOL_NODESTATUS_MODE_SOFTWARE_UPDATE:
                            item.Mode = "SOFTWARE_UPDATE";
                            break;

                        case (byte)DroneCAN.DroneCAN.uavcan_protocol_NodeStatus.UAVCAN_PROTOCOL_NODESTATUS_MODE_OFFLINE:
                            item.Mode = "OFFLINE";
                            break;
                        }

                        item.Uptime = TimeSpan.FromSeconds(ns.uptime_sec);
                    }

                    _updatePending = true;
                }
                else if (msg.GetType() == typeof(DroneCAN.DroneCAN.uavcan_protocol_GetNodeInfo_res))
                {
                    var gnires = msg as DroneCAN.DroneCAN.uavcan_protocol_GetNodeInfo_res;

                    var nodes = allnodes.Where((a) => a.ID == frame.SourceNode);

                    foreach (var item in nodes)
                    {
                        item.Name            = ASCIIEncoding.ASCII.GetString(gnires.name, 0, gnires.name_len);
                        item.HardwareVersion = gnires.hardware_version.major + "." + gnires.hardware_version.minor;
                        item.SoftwareVersion = gnires.software_version.major + "." + gnires.software_version.minor + "." +
                                               gnires.software_version.vcs_commit.ToString("X");
                        item.SoftwareCRC = gnires.software_version.image_crc;
                        item.HardwareUID = gnires.hardware_version.unique_id.Select(a => a.ToString("X2")).Aggregate((a, b) =>
                        {
                            return(a + " " + b);
                        });
                        item.RawMsg = gnires;
                        item.VSC    = gnires.status.vendor_specific_status_code;
                    }

                    _updatePending = true;
                }
                else if (msg.GetType() == typeof(DroneCAN.DroneCAN.uavcan_protocol_debug_LogMessage))
                {
                    var debug = msg as DroneCAN.DroneCAN.uavcan_protocol_debug_LogMessage;

                    this.BeginInvoke((Action) delegate()
                    {
                        DGDebug.Rows.Insert(0, new object[]
                        {
                            frame.SourceNode, debug.level.value,
                            ASCIIEncoding.ASCII.GetString(debug.source, 0, debug.source_len),
                            ASCIIEncoding.ASCII.GetString(debug.text, 0, debug.text_len)
                        });
                        if (DGDebug.Rows.Count > 100)
                        {
                            DGDebug.Rows.RemoveAt(DGDebug.Rows.Count - 1);
                        }
                    });
                }
            };
        }
Beispiel #21
0
        private void WriteParameters(bool silent)
        {
            if (!osdSettings.Any(o => o.Changed))
            {
                if (!silent)
                {
                    CustomMessageBox.Show("No Changes to Write!");
                }

                return;
            }

            if (!CheckConnected())
            {
                return;
            }

            var dialog = new ProgressReporterDialogue()
            {
                StartPosition = FormStartPosition.CenterScreen, Text = "Writing changes..."
            };

            CancellationTokenSource cts = new CancellationTokenSource();
            var cancellationToken       = cts.Token;

            List <string> failed = null;

            dialog.DoWork += (s) =>
            {
                foreach (var p in osdSettings.Where(o => o.Changed))
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    try
                    {
                        MainV2.comPort.setParam(p.Name, p.Value);
                        p.ClearChanged();
                    }
                    catch
                    {
                        (failed ?? (failed = new List <string>())).Add(p.Name);
                    }
                }
            };

            dialog.doWorkArgs.CancelRequestChanged += (s, e) =>
            {
                if (dialog.doWorkArgs.CancelRequested)
                {
                    cts.Cancel();
                }
            };

            dialog.RunBackgroundOperationAsync();

            if (!silent && null != failed)
            {
                var failedParamsEnum = string.Join(", ", failed.Take(3)) + (failed.Count > 3 ? "..." : "");
                CustomMessageBox.Show($"Write Failed for {failed.Count} params: {failedParamsEnum}");
            }
        }
Beispiel #22
0
        public void startslcan(byte canport)
        {
            but_slcanmode1.Enabled = false;
            but_slcanmode2.Enabled = false;

            try
            {
                if (!MainV2.comPort.BaseStream.IsOpen)
                {
                    if (CustomMessageBox.Show(
                            "You are not currently connected via mavlink. Please make sure the device is already in slcan mode or this is the slcan serialport.",
                            "SLCAN", CustomMessageBox.MessageBoxButtons.OKCancel) != CustomMessageBox.DialogResult.OK)
                    {
                        return;
                    }
                }

                if (MainV2.comPort.BaseStream.IsOpen)
                {
                    var cport = MainV2.comPort.MAV.param["CAN_SLCAN_CPORT"].Value;
                    MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent,
                                            "CAN_SLCAN_CPORT", canport, true);
                    if (cport == 0)
                    {
                        CustomMessageBox.Show("Reboot required" + " after setting CPORT. Please reboot!",
                                              Strings.ERROR);
                        return;
                    }

                    MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent,
                                            "CAN_SLCAN_TIMOUT", 2, true);
                    MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent,
                                            "CAN_P" + canport + "_DRIVER", 1);
                    //MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "CAN_SLCAN_SERNUM", 0, true); // usb
                    // blind send
                    var paramname = "CAN_SLCAN_SERNUM";
                    var req       = new MAVLink.mavlink_param_set_t
                    {
                        target_system    = (byte)MainV2.comPort.sysidcurrent,
                        target_component = (byte)MainV2.comPort.compidcurrent,
                        param_type       = (byte)MainV2.comPort
                                           .MAVlist[(byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent]
                                           .param_types[paramname],
                        param_id = paramname.MakeBytesSize(16)
                    };
                    MainV2.comPort.sendPacket(req, (byte)MainV2.comPort.sysidcurrent,
                                              (byte)MainV2.comPort.compidcurrent);
                    MainV2.comPort.sendPacket(req, (byte)MainV2.comPort.sysidcurrent,
                                              (byte)MainV2.comPort.compidcurrent);
                }
            }
            catch
            {
            }

            {
                // grab the connected port
                var port = MainV2.comPort.BaseStream;

                // place an invalid port in its place
                if (port != null)
                {
                    MainV2.comPort.BaseStream = new Comms.SerialPort()
                    {
                        PortName = port.PortName, BaudRate = port.BaudRate
                    }
                }
                ;

                //check if we started from within mavlink - if not get settings from menu and create port
                if (port == null || !port.IsOpen)
                {
                    port = new Comms.SerialPort()
                    {
                        PortName = MainV2._connectionControl.CMB_serialport.Text,
                        BaudRate = int.Parse(MainV2._connectionControl.CMB_baudrate.Text)
                    };
                }

                if (can == null)
                {
                    can = new uavcan();
                }

                can.SourceNode = 127;

                can.NodeAdded += (id, msg) =>
                {
                    this.BeginInvoke((Action) delegate
                    {
                        allnodes.Add(new UAVCANModel()
                        {
                            ID     = id,
                            Name   = "?",
                            Health = msg.health.ToString(),
                            Mode   = msg.mode.ToString(),
                            Uptime = TimeSpan.FromSeconds(msg.uptime_sec),
                            VSC    = msg.vendor_specific_status_code
                        });
                    });
                };

                if (!port.IsOpen)
                {
                    try
                    {
                        port.Open();
                    }
                    catch (Exception e)
                    {
                        CustomMessageBox.Show(Strings.CheckPortSettingsOr);
                        return;
                    }
                }

                if (chk_log.Checked)
                {
                    can.LogFile = Settings.Instance.LogDir + Path.DirectorySeparatorChar +
                                  DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".can";
                }

                var prd = new ProgressReporterDialogue();
                prd.UpdateProgressAndStatus(-1, "Trying to connect");
                prd.DoWork          += sender => can.StartSLCAN(port.BaseStream);
                prd.btnCancel.Click += (sender, args) =>
                {
                    prd.doWorkArgs.CancelAcknowledged = true;
                    port.Close();
                };
                prd.RunBackgroundOperationAsync();

                if (prd.doWorkArgs.CancelRequested || prd.doWorkArgs.ErrorMessage != null)
                {
                    return;
                }

                can.SetupFileServer();

                can.SetupDynamicNodeAllocator();

                can.MessageReceived += (frame, msg, transferID) =>
                {
                    if (msg.GetType() == typeof(UAVCAN.uavcan.uavcan_protocol_NodeStatus))
                    {
                        var ns = msg as UAVCAN.uavcan.uavcan_protocol_NodeStatus;

                        var nodes = allnodes.Where((a) => a.ID == frame.SourceNode);

                        if (nodes.Count() > 0 && nodes.First().Name == "?")
                        {
                            var statetracking = new UAVCAN.uavcan.statetracking();
                            // get node info
                            UAVCAN.uavcan.uavcan_protocol_GetNodeInfo_req gnireq = new UAVCAN.uavcan.uavcan_protocol_GetNodeInfo_req()
                            {
                            };
                            gnireq.encode(UAVCAN.uavcan.uavcan_transmit_chunk_handler, statetracking);

                            var slcan = can.PackageMessage(frame.SourceNode, 30, 0, gnireq);
                            can.WriteToStream(slcan);
                        }

                        foreach (var item in nodes)
                        {
                            switch (ns.health)
                            {
                            case (byte)UAVCAN.uavcan.UAVCAN_PROTOCOL_NODESTATUS_HEALTH_OK:
                                item.Health = "OK";
                                break;

                            case (byte)UAVCAN.uavcan.UAVCAN_PROTOCOL_NODESTATUS_HEALTH_WARNING:
                                item.Health = "WARNING";
                                break;

                            case (byte)UAVCAN.uavcan.UAVCAN_PROTOCOL_NODESTATUS_HEALTH_ERROR:
                                item.Health = "ERROR";
                                break;

                            case (byte)UAVCAN.uavcan.UAVCAN_PROTOCOL_NODESTATUS_HEALTH_CRITICAL:
                                item.Health = "CRITICAL";
                                break;
                            }
                            switch (ns.mode)
                            {
                            case (byte)UAVCAN.uavcan.UAVCAN_PROTOCOL_NODESTATUS_MODE_OPERATIONAL:
                                item.Mode = "OPERATIONAL";
                                break;

                            case (byte)UAVCAN.uavcan.UAVCAN_PROTOCOL_NODESTATUS_MODE_INITIALIZATION:
                                item.Mode = "INITIALIZATION";
                                break;

                            case (byte)UAVCAN.uavcan.UAVCAN_PROTOCOL_NODESTATUS_MODE_MAINTENANCE:
                                item.Mode = "MAINTENANCE";
                                break;

                            case (byte)UAVCAN.uavcan.UAVCAN_PROTOCOL_NODESTATUS_MODE_SOFTWARE_UPDATE:
                                item.Mode = "SOFTWARE_UPDATE";
                                break;

                            case (byte)UAVCAN.uavcan.UAVCAN_PROTOCOL_NODESTATUS_MODE_OFFLINE:
                                item.Mode = "OFFLINE";
                                break;
                            }
                            item.Uptime = TimeSpan.FromSeconds(ns.uptime_sec);
                        }

                        _updatePending = true;
                        this.BeginInvoke((Action) delegate
                        {
                            if (_updatePending)
                            {
                                _updatePending = false;
                                uAVCANModelBindingSource.ResetBindings(false);
                            }
                        });
                    }
                    else if (msg.GetType() == typeof(UAVCAN.uavcan.uavcan_protocol_GetNodeInfo_res))
                    {
                        var gnires = msg as UAVCAN.uavcan.uavcan_protocol_GetNodeInfo_res;

                        var nodes = allnodes.Where((a) => a.ID == frame.SourceNode);

                        foreach (var item in nodes)
                        {
                            item.Name            = ASCIIEncoding.ASCII.GetString(gnires.name, 0, gnires.name_len);
                            item.HardwareVersion = gnires.hardware_version.major + "." + gnires.hardware_version.minor;
                            item.SoftwareVersion = gnires.software_version.major + "." + gnires.software_version.minor + "." + gnires.software_version.vcs_commit.ToString("X");
                            item.SoftwareCRC     = gnires.software_version.image_crc;
                            item.HardwareUID     = gnires.hardware_version.unique_id.Select(a => a.ToString("X2")).Aggregate((a, b) =>
                            {
                                return(a + " " + b);
                            });
                            item.RawMsg = gnires;
                            item.VSC    = gnires.status.vendor_specific_status_code;
                        }

                        _updatePending = true;
                        this.BeginInvoke((Action) delegate
                        {
                            if (_updatePending)
                            {
                                _updatePending = false;
                                uAVCANModelBindingSource.ResetBindings(false);
                            }
                        });
                    }
                    else if (msg.GetType() == typeof(UAVCAN.uavcan.uavcan_protocol_debug_LogMessage))
                    {
                        var debug = msg as UAVCAN.uavcan.uavcan_protocol_debug_LogMessage;

                        this.BeginInvoke((Action) delegate()
                        {
                            DGDebug.Rows.Insert(0, new object[]
                            {
                                frame.SourceNode, debug.level.value,
                                ASCIIEncoding.ASCII.GetString(debug.source, 0, debug.source_len),
                                ASCIIEncoding.ASCII.GetString(debug.text, 0, debug.text_len)
                            });
                            if (DGDebug.Rows.Count > 100)
                            {
                                DGDebug.Rows.RemoveAt(DGDebug.Rows.Count - 1);
                            }
                        });
                    }
                };
            }
        }

        UAVCAN.uavcan can = new UAVCAN.uavcan();
Beispiel #23
0
        private void FirmwareUpdate(byte nodeID)
        {
            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            uavcan.FileSendProgressArgs filesend = (id, file, percent) =>
            {
                prd.UpdateProgressAndStatus((int)percent, id + " " + file);
            };
            can.FileSendProgress += filesend;
            var devicename = can.NodeInfo[nodeID].name.Aggregate("", (a, b) => a + (char)b).ToString();
            var hwversion  =
                double.Parse(
                    can.NodeInfo[nodeID].hardware_version.major + "." + can.NodeInfo[nodeID].hardware_version.minor,
                    CultureInfo.InvariantCulture);

            if (CustomMessageBox.Show("Do you want to search the internet for an update?", "Update",
                                      CustomMessageBox.MessageBoxButtons.YesNo) == CustomMessageBox.DialogResult.Yes)
            {
                var usebeta = false;

                if (CustomMessageBox.Show("Do you want to search for a beta firmware? (not recommended)", "Update",
                                          CustomMessageBox.MessageBoxButtons.YesNo) == CustomMessageBox.DialogResult.Yes)
                {
                    usebeta = true;
                }

                var url = can.LookForUpdate(devicename, hwversion, usebeta);

                if (url != string.Empty)
                {
                    try
                    {
                        prd.DoWork += dialogue =>
                        {
                            var tempfile = Path.GetTempFileName();
                            Download.getFilefromNet(url, tempfile);

                            try
                            {
                                can.Update(nodeID, devicename, hwversion, tempfile);
                            }
                            catch (Exception ex)
                            {
                                throw;
                            }

                            return;
                        };

                        prd.RunBackgroundOperationAsync();
                    }
                    catch (Exception ex)
                    {
                        CustomMessageBox.Show(ex.Message, Strings.ERROR);
                    }
                }
                else
                {
                    CustomMessageBox.Show(Strings.UpdateNotFound, Strings.UpdateNotFound);
                }
            }
            else
            {
                FileDialog fd = new OpenFileDialog();
                fd.RestoreDirectory = true;
                fd.Filter           = "*.bin|*.bin";
                var dia = fd.ShowDialog();

                if (fd.CheckFileExists && dia == DialogResult.OK)
                {
                    try
                    {
                        prd.DoWork += dialogue =>
                        {
                            can.Update(nodeID,
                                       devicename, 0,
                                       fd.FileName);

                            return;
                        };

                        prd.RunBackgroundOperationAsync();
                    }
                    catch (Exception ex)
                    {
                        CustomMessageBox.Show(ex.Message, Strings.ERROR);
                    }
                }
            }

            can.FileSendProgress -= filesend;
            prd.Dispose();
        }
Beispiel #24
0
        private async void myDataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            // Ignore clicks that are not on button cells.
            if (e.RowIndex < 0)
            {
                return;
            }

            try {
                byte nodeID = (byte)myDataGridView1[iDDataGridViewTextBoxColumn.Index, e.RowIndex].Value;

                if (e.ColumnIndex == myDataGridView1.Columns["Parameter"].Index)
                {
                    IProgressReporterDialogue prd = new ProgressReporterDialogue();
                    List <uavcan.uavcan_protocol_param_GetSet_res> paramlist =
                        new List <uavcan.uavcan_protocol_param_GetSet_res>();
                    prd.doWorkArgs.ForceExit             = true;
                    prd.doWorkArgs.CancelRequestChanged += (sender2, args) => { prd.doWorkArgs.CancelAcknowledged = true; };
                    prd.DoWork += dialogue =>
                    {
                        paramlist = can.GetParameters(nodeID);
                    };
                    prd.UpdateProgressAndStatus(-1, Strings.GettingParams);
                    prd.RunBackgroundOperationAsync();

                    if (!prd.doWorkArgs.CancelRequested)
                    {
                        new UAVCANParams(can, nodeID, paramlist).ShowUserControl();
                    }
                }
                else if (e.ColumnIndex == myDataGridView1.Columns["Restart"].Index)
                {
                    can.RestartNode(nodeID);
                }
                else if (e.ColumnIndex == myDataGridView1.Columns["updateDataGridViewTextBoxColumn"].Index)
                {
                    ProgressReporterDialogue    prd      = new ProgressReporterDialogue();
                    uavcan.FileSendProgressArgs filesend = (id, file, percent) =>
                    {
                        prd.UpdateProgressAndStatus((int)percent, id + " " + file);
                    };
                    can.FileSendProgress += filesend;
                    if (CustomMessageBox.Show("Do you want to search the internet for an update?", "Update",
                                              CustomMessageBox.MessageBoxButtons.YesNo) == CustomMessageBox.DialogResult.Yes)
                    {
                        var devicename = myDataGridView1[nameDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString();
                        var hwversion  =
                            double.Parse(
                                myDataGridView1[hardwareVersionDataGridViewTextBoxColumn.Index, e.RowIndex].Value
                                .ToString(), CultureInfo.InvariantCulture);

                        var usebeta = false;

                        if (CustomMessageBox.Show("Do you want to search for a beta firmware? (not recommended)", "Update",
                                                  CustomMessageBox.MessageBoxButtons.YesNo) == CustomMessageBox.DialogResult.Yes)
                        {
                            usebeta = true;
                        }

                        var url = can.LookForUpdate(devicename, hwversion, usebeta);

                        if (url != string.Empty)
                        {
                            try
                            {
                                prd.DoWork += dialogue =>
                                {
                                    var tempfile = Path.GetTempFileName();
                                    Download.getFilefromNet(url, tempfile);

                                    try
                                    {
                                        can.Update(nodeID, devicename, hwversion, tempfile);
                                    }
                                    catch (Exception ex)
                                    {
                                        throw;
                                    }

                                    return;
                                };

                                prd.RunBackgroundOperationAsync();
                            }
                            catch (Exception ex)
                            {
                                CustomMessageBox.Show(ex.Message, Strings.ERROR);
                            }
                        }
                        else
                        {
                            CustomMessageBox.Show(Strings.UpdateNotFound, Strings.UpdateNotFound);
                        }
                    }
                    else
                    {
                        FileDialog fd = new OpenFileDialog();
                        fd.RestoreDirectory = true;
                        fd.Filter           = "*.bin|*.bin";
                        var dia = fd.ShowDialog();

                        if (fd.CheckFileExists && dia == DialogResult.OK)
                        {
                            try
                            {
                                prd.DoWork += dialogue =>
                                {
                                    can.Update(nodeID, myDataGridView1[nameDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString(), 0,
                                               fd.FileName);

                                    return;
                                };

                                prd.RunBackgroundOperationAsync();
                            }
                            catch (Exception ex)
                            {
                                CustomMessageBox.Show(ex.Message, Strings.ERROR);
                            }
                        }
                    }
                    can.FileSendProgress -= filesend;
                    prd.Dispose();
                }
            } catch
            {
            }
        }
Beispiel #25
0
        private void BUT_MagCalibration_Click(object sender, EventArgs e)
        {
            CustomMessageBox.Show("Data will be collected for 60 seconds, Please click ok and move the apm around all axises");

            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            Utilities.ThemeManager.ApplyThemeTo(prd);

            prd.DoWork += prd_DoWork;

            prd.RunBackgroundOperationAsync();
        }
Beispiel #26
0
        public void Open()
        {
            if (client.Client.Connected)
            {
                log.Info("udpserial socket already open");
                return;
            }

            ProgressReporterDialogue frmProgressReporter = new ProgressReporterDialogue
            {
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen,
                Text = "Connecting Mavlink UDP"
            };

            frmProgressReporter.DoWork += frmProgressReporter_DoWork;

            frmProgressReporter.UpdateProgressAndStatus(-1, "Connecting Mavlink UDP");

            frmProgressReporter.RunBackgroundOperationAsync();
        }
Beispiel #27
0
        private void UpdateOsdTuningSlots(SetupDialog.Change[] changes)
        {
            if (!CheckConnected())
            {
                return;
            }

            var dialog = new ProgressReporterDialogue()
            {
                StartPosition = FormStartPosition.CenterScreen, Text = "Updating Parameters..."
            };

            var errors        = new List <string>();
            int responseCount = 0;

            dialog.DoWork += (s) =>
            {
                using (var osdParamsProvider = new OsdTuningSlotProvider())
                {
                    var lastResponseTime = DateTime.Now;

                    osdParamsProvider.OnParamSetResponce += r =>
                    {
                        responseCount++;
                        lastResponseTime = DateTime.Now;

                        if (!r.Success)
                        {
                            errors.Add($"Screen {r.Screen} Slot {r.Index}: Update Failed");
                        }
                    };

                    foreach (var change in changes)
                    {
                        if (dialog.doWorkArgs.CancelRequested)
                        {
                            break;
                        }

                        osdParamsProvider.ParamSet(change.Screen, change.Index, change.ParamName,
                                                   (OSD_PARAM_CONFIG_TYPE)change.Type,
                                                   (float)change.Min, (float)change.Max, (float)change.Increment);
                    }

                    while (responseCount < changes.Length && (DateTime.Now - lastResponseTime).TotalSeconds < 10)
                    {
                        Thread.Sleep(100);
                    }
                }
            };

            dialog.RunBackgroundOperationAsync();

            if (dialog.doWorkArgs.CancelRequested)
            {
                return;
            }

            if (responseCount != changes.Length)
            {
                errors.Add($"Got {responseCount} responses of {changes.Length} requests");
            }

            if (errors.Any())
            {
                var errorMsg = string.Join(Environment.NewLine, errors);
                CustomMessageBox.Show(errorMsg);
            }
        }