Exemple #1
0
        public FirmwareDownloadResult DownloadFirmware(string firmwarePath, UpdateFirmwareCallback callback, Difference[] fwChanges)
        {
            if (callback(0, true, "Please put the LoadBoard into download mode by holding the SW1 button and then clicking SW2.  \r\nAfter clicking OK do not disconnect board until the firmware download is complete.", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return FirmwareDownloadResult.StoppedNoError;
            }
            StreamReader reader = new StreamReader(firmwarePath);
            ArrayList firmware = new ArrayList();
            try
            {
                while (reader.Peek() >= 0)
                {
                    string str = reader.ReadLine().Trim();
                    if ((str.Length > 0) && (str[0] != ';'))
                    {
                        firmware.Add(str);
                    }
                }
            }
            catch
            {
                callback(0, true, "There was an error while reading in the firmware file.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            finally
            {
                reader.Close();
            }
            if (firmware.Count < 2)
            {
                callback(0, true, "The firmware file is too small.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            switch (this.WriteFirmwareToDevice(firmware, callback))
            {
                case FDResult.OK:
                    return FirmwareDownloadResult.OK;

                case FDResult.Error:
                    return FirmwareDownloadResult.StoppedWithError;

                case FDResult.FatalError:
                    return FirmwareDownloadResult.StoppedWithFatalError;
            }
            return FirmwareDownloadResult.StoppedWithError;
        }
Exemple #2
0
        public FirmwareDownloadResult DownloadFirmware(string firmwarePath, UpdateFirmwareCallback callback, Difference[] fwChanges)
        {
            StreamReader reader = new StreamReader(firmwarePath);
            ArrayList firmware = new ArrayList();
            try
            {
                while (reader.Peek() >= 0)
                {
                    string str = reader.ReadLine().Trim();
                    if ((str.Length > 0) && (str[0] != ';'))
                    {
                        firmware.Add(str);
                    }
                }
            }
            catch
            {
                callback(0, true, "There was an error while reading in the firmware file.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            finally
            {
                reader.Close();
            }
            if (firmware.Count < 2)
            {
                callback(0, true, "There was an error while reading in the firmware file.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            switch (WriteFirmwareToDevice(firmware, callback))
            {
                case FDResult.OK:
                    return FirmwareDownloadResult.OK;

                case FDResult.Error:
                    return FirmwareDownloadResult.StoppedWithError;

                case FDResult.FatalError:
                    return FirmwareDownloadResult.StoppedWithFatalError;
            }
            return FirmwareDownloadResult.StoppedWithError;
        }
Exemple #3
0
        private FDResult WriteFirmwareToDevice(ArrayList firmware, UpdateFirmwareCallback callback)
        {
            FDResult oK = FDResult.OK;
            try
            {
                if (_adtRecord.PortAddress.comAddr.COMPortId <= 0)
                {
                    callback(0, true, "The com port: " + _adtRecord.PortAddress.comAddr.COMPortId.ToString() + " is not valid.", MessageBoxButtons.OK);
                    return FDResult.FatalError;
                }
                _ddi.enablePollerRun(false);
                Thread.Sleep(300);
                bool flag = false;

                do
                {
                    flag = false;
                    try
                    {
                        int num;
                        _log.Info("==== WriteFirmwareToDevice ==== ");
                        if (_adtRecord.DeviceInfo.DeviceType.TypeID != DeviceTypeID.SRW002)
                        {
                            num = _ddi.close(_adtRecord.PortAddress.handle);
                            _adtRecord.PortAddress.comAddr.baudRate = 19200;
                            _adtRecord.PortAddress.handle = _ddi.open(_adtRecord, 'E');
                        }
                        if (!SendRequest("bl\r"))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while writing command to change to boot loader mode of the device.");
                        }
                        Thread.Sleep(100);
                        num = _ddi.close(_adtRecord.PortAddress.handle);
                        _adtRecord.PortAddress.handle = null;
                        if (num != 0)
                        {
                            oK = FDResult.Error;
                            throw new Exception("Error while closing serial port.");
                        }
                        _adtRecord.PortAddress.comAddr.baudRate = 115200;
                        _adtRecord.PortAddress.handle = _ddi.open(_adtRecord, 'E');
                        if (_adtRecord.PortAddress.handle == null)
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("The serial port could not be opened in high speed mode.");
                        }
                        Thread.Sleep(100);
                        _log.Info("in bl mode: J cmd");
                        if (!SendRequest("J\r"))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while writing command to change the communication speed on the device.");
                        }
                        if (WaitForResponse("BLD", "V1.10W"))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while waiting for response to Get Bootloader revision.");
                        }
                        string response = respBuff.objectInfo(false);
                        _log.Info("in bl mode: response of 'J':" + response);
                        if (response.Contains("SRW"))
                        {
                            string[] strArray = response.Split(new char[] { ',' });
                            string text1 = strArray[0];
                            if (strArray[3].Substring(0, 3) != "BLD")
                            {
                                oK = FDResult.FatalError;
                                throw new Exception("HW is not in Bootloader mode");
                            }
                            if (strArray[2] != "01.2r")
                            {
                                oK = FDResult.FatalError;
                                throw new Exception("Bootloader revision mismatch.");
                            }
                        }
                        response = "";
                        _log.Info("in bl mode: Na5f1H cmd");
                        if (!SendRequest("Na5f1H"))
                        {
                            oK = FDResult.Error;
                            throw new Exception("Error while writing command to Set Key Sequence on the device.");
                        }
                        if (WaitForResponse("E09", null))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while waiting for response to Set Key Sequence on the device.");
                        }
                        _log.Info("in bl mode: K cmd");
                        if (!SendRequest("K"))
                        {
                            oK = FDResult.Error;
                            throw new Exception("Error while writing command to Set Key Sequence on the device.");
                        }
                        if (WaitForResponse("EA\r\nOK\r\n>", null, 50))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while waiting for response to Set Key Sequence on the device.");
                        }
                        _log.Info("in bl mode: download loop");
                        for (int i = 0; i < firmware.Count; i++)
                        {
                            string fw_cmd = (string)firmware[i];
                            DataBuffer data = new DataBuffer(fw_cmd.Length);
                            data.copy(fw_cmd);
                            Thread.Sleep(1);
                            if (_ddi.write(_adtRecord.PortAddress.handle, data) != 0)
                            {
                                oK = FDResult.FatalError;
                                throw new Exception("Error while writing firmware command.");
                            }
                            callback((int)Math.Round((double)((((double)(i + 1)) / ((double)firmware.Count)) * 100.0), 0), false, "", MessageBoxButtons.OK);
                        }
                        _log.Info("in bl mode: end of download loop");
                        if (WaitForResponse("E09", null))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while waiting for response to Hex download.");
                        }
                        _log.Info("in bl mode: L mcd");
                        if (!SendRequest("L"))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while checking image integrity.");
                        }
                        if (WaitForResponse("00000000", null))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while waiting for response to check image integrity.");
                        }
                        _log.Info("in bl mode: M cmd");
                        if (!SendRequest("M"))
                        {
                            oK = FDResult.Error;
                            throw new Exception("Error while starting application.");
                        }
                        _log.Info("==== WriteFirmwareToDevice has finished ====");
                        Thread.Sleep(1000);
                    }
                    catch (Exception exception)
                    {
                        _log.Info("in bl mode: error occured:" + exception.Message);
                        flag = false;
                        switch (callback(0, true, "There was an error while writing the firmware to the device.\r\n" + exception.Message, MessageBoxButtons.RetryCancel))
                        {
                            case DialogResult.Cancel:
                                flag = false;
                                break;
                            case DialogResult.Retry:
                                flag = true;
                                break;
                            default:
                                flag = false;
                                break;
                        }
                    }
                } while (flag);
            }
            catch (Exception exception2)
            {
                callback(0, true, "There was a fatal error while writing the firmware to the device.\r\n" + exception2.Message, MessageBoxButtons.OK);
            }
            finally
            {
                _ddi.close(_adtRecord.PortAddress.handle);
                _adtRecord.PortAddress.comAddr.baudRate = 19200;
                _adtRecord.PortAddress.handle = _ddi.open(_adtRecord, 'D');
                _ddi.enablePollerRun(true);
            }
            return oK;
        }
Exemple #4
0
        private bool PromptUser(string a_msg, UpdateFirmwareCallback callback)
        {
            switch (callback(0, true, "There was an error while writing the firmware to the device.\r\n" + a_msg, MessageBoxButtons.RetryCancel))
            {
                case DialogResult.Cancel:
                    return false;

                case DialogResult.Retry:
                    return true;
            }
            return false;
        }
Exemple #5
0
        private FDResult WriteFirmwareToDevice(ArrayList firmware, UpdateFirmwareCallback callback, ushort vid, ushort pid, string serial, string hexFileName)
        {
            BootloadStatus fail = BootloadStatus.Fail;
            int num = 0;
            int num2 = 0;
            m_hidApp = _adtRecord.PortAddress.handle;
            if (((m_hidApp.HIDhnd.hnd.IsOpened() != 0) || m_hidApp.HIDhnd.hnd.Connect(vid, pid, serial, 0x7d0, 0x7d0)) &&
                ((fail = LoadHexFile(hexFileName)) == BootloadStatus.Success))
            {
                bool[] flashPageModified = m_flashPageModified;
                for (int i = 0; i < flashPageModified.Length; i++)
                    if (flashPageModified[i])
                        num++;

                EzDCP2 zdcp = new EzDCP2(m_hidApp);
                fail = zdcp.initiateIcommand() ? BootloadStatus.Success : BootloadStatus.Fail;
                byte[] rxDara = new byte[1];
                callback(0, false, "", MessageBoxButtons.OK);
                fail = zdcp.exchangeMessagese(new byte[] { 0x80, 0x55, 4, 0x18, 0x2a, 0, 0x36 }, ref rxDara, 0x9c4, true, false) ? BootloadStatus.Success : BootloadStatus.Fail;
                if (fail != BootloadStatus.Success)
                    return FDResult.Error;

                for (int j = 0; j < m_flashPageModified.Length; j++)
                {
                    if (m_flashPageModified[j])
                    {
                        ushort num6;
                        ushort sourceIndex = (ushort)(j * 512);
                        for (ushort k = 0; k < 512; k = (ushort)(k + num6))
                        {
                            num6 = (ushort)(512 - k);
                            num6 = Math.Min(num6, (ushort)32);
                            byte[] destinationArray = new byte[num6];
                            Array.Copy(m_flashMemory, sourceIndex, destinationArray, 0, num6);
                            fail = zdcp.exchangeMessagese(zdcp.createDCP2Commands(destinationArray, sourceIndex), ref rxDara, 0, true, false) ? BootloadStatus.Success : BootloadStatus.Fail;
                            if (fail != BootloadStatus.Success)
                                return FDResult.Error;

                            sourceIndex = (ushort)(sourceIndex + num6);
                        }
                        num2++;
                        if (num > 0)
                        {
                            int percentageComplete = (num2 * 100) / num;
                            callback(percentageComplete, false, "", MessageBoxButtons.OK);
                        }
                        if (fail != BootloadStatus.Success)
                            return FDResult.Error;
                    }
                }
                fail = zdcp.exchangeMessagese(new byte[] { 0x80, 0x55, 4, 0x18, 0x29, 0, 0x35 }, ref rxDara, 0, true, false) ? BootloadStatus.Success : BootloadStatus.Fail;
                zdcp.initiateIcommand();
            }
            Thread.Sleep(500);
            return FDResult.OK;
        }
Exemple #6
0
        public FirmwareDownloadResult DownloadFirmware(string firmwarePath, UpdateFirmwareCallback callback, Difference[] fwChanges)
        {
            StreamReader reader = new StreamReader(firmwarePath);
            ArrayList firmware = new ArrayList();
            try
            {
                while (reader.Peek() >= 0)
                {
                    string str = reader.ReadLine().Trim();
                    if ((str.Length > 0) && (str[0] != ';'))
                        firmware.Add(str);
                }
            }
            catch
            {
                callback(0, true, "There was an error while reading in the firmware file.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            finally
            {
                reader.Close();
            }
            if (firmware.Count < 2)
            {
                callback(0, true, "There was an error while reading in the firmware file.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            ushort vID = _adtRecord.PortAddress.hidAddr.VID;
            ushort pID = _adtRecord.PortAddress.hidAddr.PID;
            string serial = _adtRecord.PortAddress.hidAddr.Serial;
            FDResult result = WriteFirmwareToDevice(firmware, callback, vID, pID, serial, firmwarePath);
            _adtRecord.DeviceInfo = _adtRecord.PortAddress.handle.HIDhnd.hnd.ADT.DeviceInfo = ((DDI_HID) _ddi).queryDeviceInfo(_adtRecord.PortAddress.handle);
            switch (result)
            {
                case FDResult.OK:
                    return FirmwareDownloadResult.OK;

                case FDResult.Error:
                    return FirmwareDownloadResult.StoppedWithError;

                case FDResult.FatalError:
                    return FirmwareDownloadResult.StoppedWithFatalError;
            }
            return FirmwareDownloadResult.StoppedWithError;
        }
Exemple #7
0
        public FirmwareDownloadResult DownloadFirmware(string firmwarePath, UpdateFirmwareCallback callback, Difference[] fwChanges)
        {
            StreamReader reader = new StreamReader(firmwarePath);
            List<string> list = new List<string>();
            string str = "tmp";
            string path = Path.Combine(Path.Combine(Application.CommonAppDataPath, str), Path.ChangeExtension(Path.GetRandomFileName(), "hex"));
            try
            {
                while (reader.Peek() >= 0)
                {
                    string item = reader.ReadLine().Trim();
                    if ((item.Length > 0) && (item[0] != ';'))
                    {
                        list.Add(item);
                    }
                }
                if (!Directory.Exists(Path.GetDirectoryName(path)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                }
                File.WriteAllLines(path, list.ToArray());
                if (fwChanges != null)
                {
                    new HexFileManipulation(path).changeDifferences(fwChanges);
                }
            }
            catch (Exception exception)
            {
                callback(0, true, "There was an error while reading in the firmware file.\n" + exception.Message, MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            finally
            {
                reader.Close();
            }
            if (list.Count < 2)
            {
                callback(0, true, "There was an error while reading in the firmware file.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            ushort vID = this._adtRecord.PortAddress.toolstickAddr.VID;
            ushort pID = this._adtRecord.PortAddress.toolstickAddr.PID;
            string serial = this._adtRecord.PortAddress.toolstickAddr.Serial;
            WDS_MainProg.frameWin().DisablePlugAndPlay();
            ADTManager.instance().removeADTRecord(this._adtRecord);
            FDResult result = this.WriteFirmwareToDevice(path, callback, vID, pID, serial, firmwarePath);
            this._adtRecord.PortAddress.handle = DDI_TOOLSTICK.instance().open(this._adtRecord);
            if (this._adtRecord.PortAddress.handle != null)
            {
                this._adtRecord.PortAddress.handle.TOOLSTICKhnd.hnd.ADT.DeviceInfo = this._adtRecord.DeviceInfo;
                WDS_MainProg.frameWin().RestorePlugAndPlay();
                switch (result)
                {
                    case FDResult.OK:
                        return FirmwareDownloadResult.OK;

                    case FDResult.Error:
                        return FirmwareDownloadResult.StoppedWithError;

                    case FDResult.FatalError:
                        return FirmwareDownloadResult.StoppedWithFatalError;
                }
            }
            return FirmwareDownloadResult.StoppedWithError;
        }
Exemple #8
0
 private FDResult WriteFirmwareToDevice(string firmwarePath, UpdateFirmwareCallback callback, ushort vid, ushort pid, string serial, string hexFileName)
 {
     int dwDevices = 0;
     new StringBuilder(0x100);
     for (int i = 0; i < 10; i++)
     {
         if (ToolStickDebugUtil.USBDebugDevices(ref dwDevices) != 0)
         {
             Console.WriteLine("FatalError");
             return FDResult.FatalError;
         }
         if (dwDevices > 0)
         {
             break;
         }
     }
     for (int j = 0; j < dwDevices; j++)
     {
         StringBuilder psSerialNum = new StringBuilder(0x80);
         if (((ToolStickDebugUtil.GetUSBDeviceSN(j, ref psSerialNum) == 0) && (psSerialNum.ToString() == serial)) && (ToolStickDebugUtil.ConnectUSB(psSerialNum, 1, 1, 0) == 0))
         {
             if (ToolStickDebugUtil.Download(new StringBuilder(firmwarePath), 1, 1, 0, -1, 0, false) != 0)
             {
                 return FDResult.Error;
             }
             if (ToolStickDebugUtil.SetTargetGo() != 0)
             {
                 return FDResult.FatalError;
             }
             if (ToolStickDebugUtil.DisconnectUSB() != 0)
             {
                 return FDResult.Error;
             }
             if (ToolStickDebugUtil.Connected())
             {
                 return FDResult.Error;
             }
             Thread.Sleep(250);
             return FDResult.OK;
         }
     }
     return FDResult.FatalError;
 }
Exemple #9
0
 public FirmwareDownloadResult DownloadFirmware(FirmwareItem item, UpdateFirmwareCallback callback, Difference[] fwChanges)
 {
     _driver = GetIOFD(_adtRecord, item);
     return _driver.DownloadFirmware(item.firmwareLocation, callback, fwChanges);
 }
Exemple #10
0
        private FDResult WriteFirmwareToDevice(ArrayList firmware, UpdateFirmwareCallback callback)
        {
            FDResult oK = FDResult.OK;
            try
            {
                if (this._adtRecord.PortAddress.comAddr.COMPortId <= 0)
                {
                    callback(0, true, "The com port: " + this._adtRecord.PortAddress.comAddr.COMPortId.ToString() + " is not valid.", MessageBoxButtons.OK);
                    return FDResult.FatalError;
                }
                this._ddi.enablePollerRun(false);
                bool flag = false;
            Label_0065:
                flag = false;
                try
                {
                    string str = "C\r";
                    DataBuffer data = new DataBuffer(str.Length);
                    data.copy(str);
                    if (this._ddi.write(this._adtRecord.PortAddress.handle, data) != 0)
                    {
                        oK = FDResult.Error;
                        throw new Exception("Error while writing command to change the communication speed on the device.");
                    }
                    int num = this._ddi.close(this._adtRecord.PortAddress.handle);
                    this._adtRecord.PortAddress.handle = null;
                    if (num != 0)
                    {
                        oK = FDResult.Error;
                        throw new Exception("Error while closing serial port.");
                    }
                    this._adtRecord.PortAddress.comAddr.baudRate = 0xe100;
                    this._adtRecord.PortAddress.handle = this._ddi.open(this._adtRecord, 'D');
                    if (this._adtRecord.PortAddress.handle == null)
                    {
                        oK = FDResult.FatalError;
                        throw new Exception("The serial port could not be opened in high speed mode.");
                    }
                    this.inputBuffer.Clear();
                    bool flag2 = true;
                    for (int i = 0; i < firmware.Count; i++)
                    {
                        string str2 = ((string) firmware[i]) + "\r\n";
                        if (flag2)
                        {
                            str2 = "L" + str2;
                            flag2 = false;
                        }
                        data = new DataBuffer(str.Length);
                        data.copy(str2);
                        if (this._ddi.write(this._adtRecord.PortAddress.handle, data) != 0)
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while writing firmware command.");
                        }
                        if ((i + 1) < firmware.Count)
                        {
                            lock (this)
                            {
                                this.inputBuffer.Clear();
                            }
                            if (this.WaitForResult(ResultType.XOFF))
                            {
                                oK = FDResult.FatalError;
                                throw new Exception("Error while waiting for XOFF while writing the file.");
                            }
                            if (this.WaitForResult(ResultType.XON))
                            {
                                oK = FDResult.FatalError;
                                throw new Exception("Error while waiting for XON while writing the file.");
                            }
                        }
                        callback((int) Math.Round((double) ((((double) (i + 1)) / ((double) firmware.Count)) * 100.0), 0), false, "", MessageBoxButtons.OK);
                    }
                    if (this._adtRecord.PortAddress.handle != null)
                    {
                        this._ddi.close(this._adtRecord.PortAddress.handle);
                        this._adtRecord.PortAddress.handle = null;
                        this._adtRecord.PortAddress.comAddr.baudRate = 0x4b00;
                        this._adtRecord.PortAddress.handle = this._ddi.open(this._adtRecord, 'D');
                    }
                }
                catch (Exception exception)
                {
                    switch (callback(0, true, "There was an error while writing the firmware to the device.\r\n" + exception.Message, MessageBoxButtons.RetryCancel))
                    {
                        case DialogResult.Cancel:
                            flag = false;
                            goto Label_0339;

                        case DialogResult.Retry:
                            flag = true;
                            goto Label_0339;
                    }
                    flag = false;
                }
            Label_0339:
                if (flag)
                {
                    goto Label_0065;
                }
            }
            catch (Exception exception2)
            {
                callback(0, true, "There was a fatal error while writing the firmware to the device.\r\n" + exception2.Message, MessageBoxButtons.OK);
            }
            finally
            {
                this._ddi.enablePollerRun(true);
            }
            return oK;
        }
Exemple #11
0
        private FDResult WriteFirmwareToDevice(ArrayList firmware, UpdateFirmwareCallback callback, ushort vid, ushort pid, string serial, string hexFileName)
        {
            BootloadStatus fail = BootloadStatus.Fail;
            int num = 0;
            int num2 = 0;
            bool mode = false;
            if (this.m_hidApp.Connect(vid, pid, serial, 0x7d0, 0x7d0))
            {
                if (!this.m_hidApp.GetBootloadMode(ref mode) || !mode)
                {
                    fail = BootloadStatus.NotInBootloadMode;
                }
                else if ((((fail = this.LoadHexFile(hexFileName)) == BootloadStatus.Success) && ((fail = this.SetFlashKeyCodes(true)) == BootloadStatus.Success)) && ((fail = this.ErasePage(0xf7fc)) == BootloadStatus.Success))
                {
                    bool[] flashPageModified = this.m_flashPageModified;
                    for (int i = 0; i < flashPageModified.Length; i++)
                    {
                        if (flashPageModified[i])
                        {
                            num++;
                        }
                    }
                    for (int j = 0; j < this.m_flashPageModified.Length; j++)
                    {
                        ushort num6;
                        if (!this.m_flashPageModified[j])
                        {
                            continue;
                        }
                        ushort address = (ushort) (j * 0x200);
                        ushort num5 = 0;
                        fail = this.ErasePage(address);
                        if (fail == BootloadStatus.Success)
                        {
                            goto Label_011C;
                        }
                        break;
                    Label_00CD:
                        num6 = (ushort) (0x200 - num5);
                        num6 = Math.Min(num6, (ushort)50);
                        byte[] destinationArray = new byte[num6];
                        Array.Copy(this.m_flashMemory, address, destinationArray, 0, num6);
                        fail = this.WriteBytes(destinationArray, address);
                        if (fail != BootloadStatus.Success)
                        {
                            goto Label_0125;
                        }
                        address = (ushort) (address + num6);
                        num5 = (ushort) (num5 + num6);
                    Label_011C:
                        if (num5 < 0x200)
                        {
                            goto Label_00CD;
                        }
                    Label_0125:
                        num2++;
                        if (num > 0)
                        {
                            int percentageComplete = (num2 * 100) / num;
                            callback(percentageComplete, false, "", MessageBoxButtons.OK);
                        }
                        if (fail != BootloadStatus.Success)
                        {
                            break;
                        }
                    }
                    switch (fail)
                    {
                        case BootloadStatus.Success:
                            if ((((fail = this.WriteValidation()) != BootloadStatus.Success) || ((fail = this.SetFlashKeyCodes(false)) != BootloadStatus.Success)) || !this.m_hidApp.SetBootloadMode(false))
                            {
                            }
                            break;

                        case BootloadStatus.Cancelled:
                            this.SetFlashKeyCodes(false);
                            break;
                    }
                }
            }
            this.m_hidApp.Close();
            return FDResult.OK;
        }
Exemple #12
0
        public FirmwareDownloadResult DownloadFirmware(string firmwarePath, UpdateFirmwareCallback callback, Difference[] fwChanges)
        {
            FormWait wait;
            StreamReader reader = new StreamReader(firmwarePath);
            ArrayList firmware = new ArrayList();
            try
            {
                while (reader.Peek() >= 0)
                {
                    string str = reader.ReadLine().Trim();
                    if ((str.Length > 0) && (str[0] != ';'))
                    {
                        firmware.Add(str);
                    }
                }
            }
            catch
            {
                callback(0, true, "There was an error while reading in the firmware file.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            finally
            {
                reader.Close();
            }
            if (firmware.Count < 2)
            {
                callback(0, true, "There was an error while reading in the firmware file.", MessageBoxButtons.OK);
                return FirmwareDownloadResult.StoppedWithError;
            }
            ushort vID = this._adtRecord.PortAddress.hidAddr.VID;
            ushort pID = this._adtRecord.PortAddress.hidAddr.PID;
            string serial = this._adtRecord.PortAddress.hidAddr.Serial;
            WDS_MainProg.frameWin().DisablePlugAndPlay();
            if (!this._adtRecord.DeviceInfo.BootloaderMode)
            {
                if (!this.EnterBootloadMode())
                {
                    callback(0, true, "There was an error trying to enter booload mode.", MessageBoxButtons.OK);
                    WDS_MainProg.frameWin().RestorePlugAndPlay();
                    return FirmwareDownloadResult.StoppedWithError;
                }
                ADTManager.instance().removeADTRecord(this._adtRecord);
                this._ddi.close(this._adtRecord.PortAddress.handle);
                Thread.Sleep(100);
                wait = new FormWait(vID, pID, serial, true, 0x1388, 100) {
                    Text = "Enumerating Bootloader..."
                };
                if (wait.ShowDialog() != DialogResult.OK)
                {
                    callback(0, true, "There was an error trying to reenumerate in bootload mode.", MessageBoxButtons.OK);
                    WDS_MainProg.frameWin().RestorePlugAndPlay();
                    return FirmwareDownloadResult.StoppedWithError;
                }
            }
            else
            {
                this._ddi.close(this._adtRecord.PortAddress.handle);
                ADTManager.instance().removeADTRecord(this._adtRecord);
            }
            FDResult result2 = this.WriteFirmwareToDevice(firmware, callback, vID, pID, serial, firmwarePath);
            wait = new FormWait(vID, pID, serial, false, 0x1388, 100) {
                Text = "Enumerating Device..."
            };
            if (wait.ShowDialog() == DialogResult.OK)
            {
                this._adtRecord.PortAddress.handle = DDI_HID.instance().open(this._adtRecord, ' ');
                this._adtRecord.DeviceInfo = this._adtRecord.PortAddress.handle.HIDhnd.hnd.ADT.DeviceInfo;
            }
            WDS_MainProg.frameWin().RestorePlugAndPlay();
            switch (result2)
            {
                case FDResult.OK:
                    return FirmwareDownloadResult.OK;

                case FDResult.Error:
                    return FirmwareDownloadResult.StoppedWithError;

                case FDResult.FatalError:
                    return FirmwareDownloadResult.StoppedWithFatalError;
            }
            return FirmwareDownloadResult.StoppedWithError;
        }