Пример #1
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);
            }
        }
Пример #2
0
        private void try_upload(string filename)
        {
            // load the intelhex file
            ihex.load(filename);

            // and try to upload it
            upl.upload(port, ihex);
        }
Пример #3
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();
            }
        }