示例#1
0
        /// <summary>
        /// Get the correct object for the modem which is in bootloader mode.
        /// </summary>
        /// <param name="Session">The session.  Must not be null.</param>
        /// <returns>null if could not generate modem object</returns>
        public static RFD900APU GetObjectForModem(TSession Session)
        {
            uploader.Uploader U = new uploader.Uploader();
            U.port = Session.Port;
            uploader.Uploader.Board     Board = uploader.Uploader.Board.FAILED;
            uploader.Uploader.Frequency Freq  = uploader.Uploader.Frequency.FAILED;

            U.getDevice(ref Board, ref Freq);
            switch (Board)
            {
            case uploader.Uploader.Board.DEVICE_ID_RFD900A:
                return(new RFD900a(Session));

            case uploader.Uploader.Board.DEVICE_ID_RFD900P:
                return(new RFD900p(Session));

            case uploader.Uploader.Board.DEVICE_ID_RFD900U:
                return(new RFD900u(Session));

            case Uploader.Board.DEVICE_ID_RFD900:
                return(new RFD900old(Session));

            case Uploader.Board.DEVICE_ID_HM_TRP:
                return(new HM_TRP(Session));

            default:
                return(null);
            }
        }
示例#2
0
        public override bool ProgramFirmware(string FilePath, Action <double> Progress)
        {
            try
            {
                uploader.IHex Hex = new uploader.IHex();
                Hex.load(FilePath);

                if (SearchHex(Hex, GetFirmwareSearchTokens()))
                {
                    uploader.Uploader UL = new uploader.Uploader();
                    UL.ProgressEvent += (d) => Progress(d);
                    UL.upload(_Session.Port, Hex);
                    return(true);
                }
                else
                {
                    ShowWrongFirmwareMessageBox();
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
示例#3
0
        private bool getFirmware(Uploader.Board device, bool custom = false)
        {
            if (custom)
            {
                return getFirmwareLocal(device);
            }

            if (device == Uploader.Board.DEVICE_ID_HM_TRP)
            {
                if (beta)
                {
                    return Common.getFilefromNet("http://firmware.ardupilot.org/SiK/beta/radio~hm_trp.ihx", firmwarefile);
                }
                return Common.getFilefromNet("http://firmware.ardupilot.org/SiK/stable/radio~hm_trp.ihx",
                    firmwarefile);
            }
            if (device == Uploader.Board.DEVICE_ID_RFD900)
            {
                if (beta)
                {
                    return Common.getFilefromNet("http://firmware.ardupilot.org/SiK/beta/radio~rfd900.ihx", firmwarefile);
                }
                return Common.getFilefromNet("http://firmware.ardupilot.org/SiK/stable/radio~rfd900.ihx", firmwarefile);
            }
            if (device == Uploader.Board.DEVICE_ID_RFD900A)
            {
                if (beta)
                {
                    return Common.getFilefromNet("http://firmware.ardupilot.org/SiK/beta/radio~rfd900a.ihx",
                        firmwarefile);
                }
                return Common.getFilefromNet("http://firmware.ardupilot.org/SiK/stable/radio~rfd900a.ihx", firmwarefile);
            }
            if (device == Uploader.Board.DEVICE_ID_RFD900U)
            {
                if (beta)
                {
                    return Common.getFilefromNet("http://files.rfdesign.com.au/Files/firmware/MPSiK%20V2.6%20rfd900u.ihx", firmwarefile);
                }
                return Common.getFilefromNet("http://files.rfdesign.com.au/Files/firmware/RFDSiK%20V1.9%20rfd900u.ihx", firmwarefile);
            }
            if (device == Uploader.Board.DEVICE_ID_RFD900P)
            {
                if (beta)
                {
                    return Common.getFilefromNet("http://files.rfdesign.com.au/Files/firmware/MPSiK%20V2.6%20rfd900p.ihx", firmwarefile);
                }
                return Common.getFilefromNet("http://files.rfdesign.com.au/Files/firmware/RFDSiK%20V1.9%20rfd900p.ihx", firmwarefile);
            }
            return false;
        }
示例#4
0
        private bool getFirmware(Uploader.Board device, bool custom = false)
        {
            if (custom)
            {
                return getFirmwareLocal(device);
            }

            if (device == Uploader.Board.DEVICE_ID_HM_TRP)
            {
                if (beta)
                {
                    return Common.getFilefromNet("http://firmware.diydrones.com/SiK/beta/radio~hm_trp.ihx", firmwarefile);
                }
                return Common.getFilefromNet("http://firmware.diydrones.com/SiK/stable/radio~hm_trp.ihx",
                    firmwarefile);
            }
            if (device == Uploader.Board.DEVICE_ID_RFD900)
            {
                if (beta)
                {
                    return Common.getFilefromNet("http://firmware.diydrones.com/SiK/beta/radio~rfd900.ihx", firmwarefile);
                }
                return Common.getFilefromNet("http://rfdesign.com.au/firmware/radio.rfd900.hex", firmwarefile);
            }
            if (device == Uploader.Board.DEVICE_ID_RFD900A)
            {
                if (beta)
                {
                    return Common.getFilefromNet("http://firmware.diydrones.com/SiK/beta/radio~rfd900a.ihx",
                        firmwarefile);
                }
                return Common.getFilefromNet("http://rfdesign.com.au/firmware/radio.rfd900a.hex", firmwarefile);
            }
            if (device == Uploader.Board.DEVICE_ID_RFD900U)
            {
                if (beta)
                {
                    return Common.getFilefromNet("http://rfdesign.com.au/firmware/radio~rfd900u.ihx", firmwarefile);
                }
                return Common.getFilefromNet("http://rfdesign.com.au/firmware/radio~rfd900u.ihx", firmwarefile);
            }
            if (device == Uploader.Board.DEVICE_ID_RFD900P)
            {
                if (beta)
                {
                    return Common.getFilefromNet("http://rfdesign.com.au/firmware/radio~rfd900p.ihx", firmwarefile);
                }
                return Common.getFilefromNet("http://rfdesign.com.au/firmware/radio~rfd900p.ihx", firmwarefile);
            }
            return false;
        }
示例#5
0
文件: Main.cs 项目: cjswin/SiK
		public AppLogic ()
		{
			// Get the current configuration file.
			config = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
		
			// Look for our settings and add/create them if missing
			if (config.Sections [config_name] == null) {
				config_section = new ConfigSection ();
				config.Sections.Add (config_name, config_section);
				config_section.SectionInformation.ForceSave = true;
				config.Save (ConfigurationSaveMode.Full);
			}
			config_section = config.GetSection (config_name) as ConfigSection;

			// Hook up main window events
			win = new MainWindow ();
			win.MonitorEvent += show_monitor;
			win.UploadEvent += do_upload;
			win.LogEvent += log;
			win.QuitEvent += at_exit;
			
			// restore the last path that we uploaded
			win.FileName = config_section.lastPath;
			
			// restore the last port that we opened
			win.PortName = config_section.lastPort;
			
			// Create the intelhex loader
			ihex = new IHex ();
			ihex.LogEvent += log;
			
			// And the uploader
			upl = new Uploader ();
			upl.LogEvent += log;
			upl.ProgressEvent += win.set_progress;
			
			// Emit some basic help
			log ("Select a serial port and a .hex file to be uploaded, then hit Upload.\n");
			
			win.Show ();
		}
示例#6
0
        private void UploadFW(bool custom = false)
        {
            ICommsSerial comPort = new SerialPort();

            var uploader = new Uploader();

            if (MainV2.comPort.BaseStream.IsOpen)
            {
                try
                {
                    getTelemPortWithRadio(ref comPort);

                    uploader.PROG_MULTI_MAX = 64;
                }
                catch (Exception ex)
                {
                    CustomMessageBox.Show("Error " + ex);
                }
            }

            try
            {
                comPort.PortName = MainV2.comPort.BaseStream.PortName;
                comPort.BaudRate = 115200;

                comPort.Open();
            }
            catch
            {
                CustomMessageBox.Show("Invalid ComPort or in use");
                return;
            }

            // prep what we are going to upload
            var iHex = new IHex();

            iHex.LogEvent += iHex_LogEvent;

            iHex.ProgressEvent += iHex_ProgressEvent;

            var bootloadermode = false;

            // attempt bootloader mode
            try
            {
                if (upload_xmodem(comPort))
                {
                    comPort.Close();
                    return;
                }

                comPort.BaudRate = 115200;

                uploader_ProgressEvent(0);
                uploader_LogEvent("Trying Bootloader Mode");

                uploader.port = comPort;
                uploader.connect_and_sync();

                uploader.ProgressEvent += uploader_ProgressEvent;
                uploader.LogEvent += uploader_LogEvent;

                uploader_LogEvent("In Bootloader Mode");
                bootloadermode = true;
            }
            catch (Exception ex1)
            {
                log.Error(ex1);

                // cleanup bootloader mode fail, and try firmware mode
                comPort.Close();
                if (MainV2.comPort.BaseStream.IsOpen)
                {
                    // default baud... guess
                    comPort.BaudRate = 57600;
                }
                else
                {
                    comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
                }
                try
                {
                    comPort.Open();
                }
                catch
                {
                    CustomMessageBox.Show("Error opening port", "Error");
                    return;
                }

                uploader.ProgressEvent += uploader_ProgressEvent;
                uploader.LogEvent += uploader_LogEvent;

                uploader_LogEvent("Trying Firmware Mode");
                bootloadermode = false;
            }

            // check for either already bootloadermode, or if we can do a ATI to ID the firmware 
            if (bootloadermode || doConnect(comPort))
            {
                // put into bootloader mode/update mode
                if (!bootloadermode)
                {
                    try
                    {
                        comPort.Write("AT&UPDATE\r\n");
                        var left = comPort.ReadExisting();
                        log.Info(left);
                        Sleep(700);
                        comPort.BaudRate = 115200;
                    }
                    catch
                    {
                    }

                    if (upload_xmodem(comPort))
                    {
                        comPort.Close();
                        return;
                    }

                    comPort.BaudRate = 115200;
                }

                try
                {
                    // force sync after changing baudrate
                    uploader.connect_and_sync();
                }
                catch
                {
                    CustomMessageBox.Show("Failed to sync with Radio");
                    goto exit;
                }

                var device = Uploader.Board.FAILED;
                var freq = Uploader.Frequency.FAILED;

                // get the device type and frequency in the bootloader
                uploader.getDevice(ref device, ref freq);

                // get firmware for this device
                if (getFirmware(device, custom))
                {
                    // load the hex
                    try
                    {
                        iHex.load(firmwarefile);
                    }
                    catch
                    {
                        CustomMessageBox.Show("Bad Firmware File");
                        goto exit;
                    }

                    // upload the hex and verify
                    try
                    {
                        uploader.upload(comPort, iHex);
                    }
                    catch (Exception ex)
                    {
                        CustomMessageBox.Show("Upload Failed " + ex.Message);
                    }
                }
                else
                {
                    CustomMessageBox.Show("Failed to download new firmware");
                }
            }
            else
            {
                CustomMessageBox.Show("Failed to identify Radio");
            }

            exit:
            if (comPort.IsOpen)
                comPort.Close();
        }
示例#7
0
        private bool getFirmwareLocal(Uploader.Board device)
        {
            using (var openFileDialog1 = new OpenFileDialog())
            {
                openFileDialog1.Filter = "Firmware|*.hex;*.ihx";
                openFileDialog1.RestoreDirectory = true;
                openFileDialog1.Multiselect = false;

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        File.Copy(openFileDialog1.FileName, firmwarefile, true);
                    }
                    catch (Exception ex)
                    {
                        CustomMessageBox.Show("Error copying file\n" + ex, "ERROR");
                        return false;
                    }
                    return true;
                }

                return false;
            }
        }
示例#8
0
        private void UploadFW()
        {
            SerialPort comPort = new SerialPort();

            var uploader = new Uploader();

            try
            {
                comPort.PortName = PortName;
                comPort.BaudRate = 115200;

                comPort.Open();
            }
            catch
            {
                log("Invalid ComPort or in use");
                return;
            }

            uploader.ProgressEvent += progress;
            uploader.LogEvent      += log;

            // prep what we are going to upload
            var iHex = new IHex();

            var bootloadermode = false;

            // attempt bootloader mode
            try
            {
                comPort.BaudRate = 115200;

                log("Trying Bootloader Mode");

                uploader.port = comPort;
                uploader.connect_and_sync();

                log("In Bootloader Mode");
                bootloadermode = true;
            }
            catch (Exception ex1)
            {
                log(ex1.Message);

                // cleanup bootloader mode fail, and try firmware mode
                comPort.Close();
                if (comPort.IsOpen)
                {
                    // default baud... guess
                    comPort.BaudRate = 57600;
                }
                else
                {
                    comPort.BaudRate = BaudRate;
                }
                try
                {
                    comPort.Open();
                }
                catch
                {
                    log("Error opening port");
                    return;
                }


                log("Trying Firmware Mode");
                bootloadermode = false;
            }

            // check for either already bootloadermode, or if we can do a ATI to ID the firmware
            if (bootloadermode || doConnect(comPort))
            {
                // put into bootloader mode/update mode
                if (!bootloadermode)
                {
                    try
                    {
                        comPort.Write("AT&UPDATE\r\n");
                        var left = comPort.ReadExisting();
                        log(left);
                        Sleep(700);
                        comPort.BaudRate = 115200;
                    }
                    catch
                    {
                    }

                    comPort.BaudRate = 115200;
                }

                try
                {
                    // force sync after changing baudrate
                    uploader.connect_and_sync();
                }
                catch
                {
                    log("Failed to sync with Radio");
                    goto exit;
                }

                var device = Uploader.Board.FAILED;
                var freq   = Uploader.Frequency.FAILED;

                // get the device type and frequency in the bootloader
                uploader.getDevice(ref device, ref freq);


                // load the hex
                try
                {
                    iHex.load(FileName);
                }
                catch
                {
                    log("Bad Firmware File");
                    goto exit;
                }

                // upload the hex and verify
                try
                {
                    uploader.upload(comPort, iHex);
                }
                catch (Exception ex)
                {
                    log("Upload Failed " + ex.Message);
                }
            }
            else
            {
                log("Failed to identify Radio");
            }

exit:
            if (comPort.IsOpen)
            {
                comPort.Close();
            }
        }