Exemplo n.º 1
0
        public DeviceViewModel(Device device)
        {
            Device = device;
            if (!IsNull)
            {
                PeripheralConfiguration = new blfwkdll.Peripheral.PeripheralConfigData();
                PeripheralConfiguration.peripheralType = this.PeripheralType;
                if (IsSerial)
                {
                    PeripheralConfiguration.usePing                = true;
                    PeripheralConfiguration.comPortName            = Port;
                    PeripheralConfiguration.comPortSpeed           = 57600;
                    PeripheralConfiguration.serialReadTimeoutMs    = 5000;      //TODO: Get this info
                    PeripheralConfiguration.busPalConfig.transport = this.BusPalTransport;
                }
                else if (IsUsbHid)
                {
                    var hid = (HidDevice)this.Device;
                    PeripheralConfiguration.usbHidVid           = hid.Vid;
                    PeripheralConfiguration.usbHidPid           = hid.Pid;
                    PeripheralConfiguration.serialReadTimeoutMs = 5000;         //TODO: Get this info
                    PeripheralConfiguration.usbHidSerialNumber  = String.Empty; //TODO: Get this info
                }

                // We must initialize this.PeripheralConfiguration before
                // creating the BootloaderViewModel.
                UpdaterModel = new UpdaterViewModel(this);
            }
        }
Exemplo n.º 2
0
        private async Task Update(UpdaterViewModel updaterModel,
                                  IProgress <blfwkdll.Updater.UpdaterOperationProgressData> progress,
                                  CancellationToken token = new CancellationToken())
        {
#if (TEST_WINDOW_LOGIC)
            blfwkdll.Updater.UpdaterOperationProgressData dummyOpData =
                new blfwkdll.Updater.UpdaterOperationProgressData(new blfwkdll.Updater.UpdaterEnum(0, "Updating..."));
            dummyOpData.Tasks.Add(new blfwkdll.Updater.UpdaterTask(new blfwkdll.Updater.UpdaterEnum(0, "Erasing..."), 0, 100));
            dummyOpData.Tasks.Add(new blfwkdll.Updater.UpdaterTask(new blfwkdll.Updater.UpdaterEnum(1, "Writing..."), 0, 100));

            for (int j = 0; j < dummyOpData.Tasks.Count; ++j)
            {
                dummyOpData.CurrentTaskIndex = j;
                if (progress != null)
                {
                    progress.Report(dummyOpData);
                }

                for (UInt32 i = 10; i <= dummyOpData.Tasks[j].Total; i += 10)
                {
                    dummyOpData.Tasks[j].CurrentPosition = i;
                    if (progress != null)
                    {
                        progress.Report(dummyOpData);
                    }

                    await Task.Delay(TimeSpan.FromSeconds(.1), token).ConfigureAwait(false);

                    if (j == 1 && i == 20)
                    {
                        throw new Exception("The updater threw an error.");
                    }
                }
            }
#else
            Updater.setCallback(UpdaterProgress);
            await Task.Run(() =>
            {
                try
                {
                    if (DeviceModel.IsSerial)
                    {
                        IsConnectedTimer.Stop();
                    }

                    if (InSecurity)
                    {
                        if (UnlockWithBackdoorKey == true)
                        {
                            Updater.unlockWithKey(BackdoorKey);
                        }
                        else if (FlashEraseAllUnsecure == true)
                        {
                            Updater.eraseAllUnsecure();
                        }
                        Status = "Unlocked";
                    }
                    //Updater.flashFirmware(ImageFileModel.FullPath, ImageFileModel.BaseAddress);
                    Updater.flashFirmware(this.ImageFileModel.FullPath, this.ImageFileModel.BaseAddress);   // TODO: handle exceptions! (see below ...)

                    Reset();
                    if (DeviceModel.IsSerial)
                    {
                        Status = "Complete! Waiting for application to start.";
                    }
                    else
                    {
                        Status = "Complete! Press Reset button to start application.";
                    }
                    Value = 100;

                    if (DeviceModel.IsSerial)
                    {
                        IsConnectedTimer.Interval = new TimeSpan(0, 0, 10);
                        IsConnectedTimer.Start();
                    }
                }
                catch (Exception e)
                {
                    if (DeviceModel.IsSerial)
                    {
                        IsConnectedTimer.Start();
                    }
                    throw e;
                }
            }, token);
#endif
        } // Update()