Esempio n. 1
0
        private static void UpdateFirmware(string deviceId)
        {
            var udpate = new FirmwareUpdate();

            udpate.StartFirmwareUpdate(deviceId);
            udpate.QueryTwinFwUpdateReported(deviceId);
        }
Esempio n. 2
0
 public CommPrgForm()
 {
     this.firmwareUpdate = new FirmwareUpdate();
     this.portComm       = new Class10();
     this.hidComm        = new CodeplugComms();
     //base._002Ector();
     this.InitializeComponent();
     base.Scale(Settings.smethod_6());
 }
        public CommPrgForm(bool closeWhenFinished = false)
        {
            this._closeWhenFinished = closeWhenFinished;
            this.firmwareUpdate     = new FirmwareUpdate();

            this.hidComm = new CodeplugComms();
            this.InitializeComponent();
            base.Scale(Settings.smethod_6());
        }
Esempio n. 4
0
 static public void FirmwareUpdate(IOTSAS.Comms.Serial serial, string filePath)
 {
     using (var firmware = new FirmwareUpdate(serial))
     {
         var file = File.OpenRead(filePath);
         try
         {
             firmware.Upload(file);
         }
         catch (SASException ex)
         {
             Console.WriteLine($"Error: {ex.ResultCode} {ex.Message}");
         }
     }
 }
        public async Task <MethodResponse> OnInitiateFirmwareUpdate(MethodRequest methodRequest, object userContext)
        {
            if (_deviceManagementTask != null && !_deviceManagementTask.IsCompleted)
            {
                return(await Task.FromResult(BuildMethodRespose(new
                {
                    Message = "Device is busy"
                }, 409)));
            }

            try
            {
                var operation = new FirmwareUpdate(methodRequest);
                _deviceManagementTask = operation.Run(Transport).ContinueWith(async task =>
                {
                    // after firmware completed, we reset telemetry for demo purpose
                    var telemetry = _telemetryController as ITelemetryWithTemperatureMeanValue;
                    if (telemetry != null)
                    {
                        telemetry.TemperatureMeanValue = 34.5;
                    }

                    await UpdateReportedTemperatureMeanValue();
                });

                return(await Task.FromResult(BuildMethodRespose(new
                {
                    Message = "FirmwareUpdate accepted",
                    Uri = operation.Uri
                })));
            }
            catch (Exception ex)
            {
                return(await Task.FromResult(BuildMethodRespose(new
                {
                    Message = ex.Message
                }, 400)));
            }
        }
Esempio n. 6
0
        private void Update_Button_Click(object sender, RoutedEventArgs e)
        {
            if (Settings.SelectedDevice.DeviceType != BaseDevice.DeviceTypeOptions.TwiKfdtool)
            {
                MessageBox.Show("Please select the KFDtool device type to perform this function", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Logger.Debug("update package path: {0}", UpdatePackage);

            if (UpdatePackage.Equals(string.Empty))
            {
                Logger.Error("no file selected");
                MessageBox.Show("No file selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // file existed when it was selected but now doesn't
            if (!File.Exists(UpdatePackage))
            {
                Logger.Error("selected file does not exist");
                MessageBox.Show("Selected file does not exist", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                UpdatePackage   = string.Empty;
                lblPath.Content = NO_FILE_SELECTED;
                return;
            }

            // check if package is cfp or ufp
            string ext = System.IO.Path.GetExtension(UpdatePackage);

            Logger.Debug("update package extension: {0}", ext);

            List <Update> pkg = null;

            if (ext == ".cfp")
            {
                Logger.Debug("opening compressed update package");

                try
                {
                    pkg = Firmware.OpenCompressedUpdatePackage(UpdatePackage);
                }
                catch (Exception ex)
                {
                    Logger.Error("unable to parse file: {0}", ex.Message);
                    MessageBox.Show(string.Format("Unable to parse file: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else if (ext == ".ufp")
            {
                Logger.Debug("opening uncompressed update package");

                try
                {
                    pkg = Firmware.OpenUncompressedUpdatePackage(UpdatePackage);
                }
                catch (Exception ex)
                {
                    Logger.Error("unable to parse file: {0}", ex.Message);
                    MessageBox.Show(string.Format("Unable to parse file: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else
            {
                Logger.Error("invalid file selected");
                MessageBox.Show("Invalid file selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Logger.Debug("items in update package: {0}", pkg.Count);

            if (pkg.Count < 1)
            {
                Logger.Error("update package does not contain any updates");
                MessageBox.Show("Update package does not contain any updates", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            string curVerStr = string.Empty;

            try
            {
                curVerStr = Interact.ReadFirmwareVersion(Settings.SelectedDevice);
                Logger.Debug("adapter version: {0}", curVerStr);
            }
            catch (Exception ex)
            {
                Logger.Error("error reading firmware version from adapter -- {0}", ex.Message);
                MessageBox.Show(string.Format("Error reading firmware version from adapter -- {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            string curModel = string.Empty;

            try
            {
                curModel = Interact.ReadModel(Settings.SelectedDevice);
                Logger.Debug("adapter model: {0}", curModel);
            }
            catch (Exception ex)
            {
                Logger.Error("error reading model from adapter -- {0}", ex.Message);
                MessageBox.Show(string.Format("Error reading model from adapter -- {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            string curHwRev = string.Empty;

            try
            {
                curHwRev = Interact.ReadHardwareRevision(Settings.SelectedDevice);
                Logger.Debug("adapter hardware revision: {0}", curHwRev);
            }
            catch (Exception ex)
            {
                Logger.Error("error reading hardware revision from adapter -- {0}", ex.Message);
                MessageBox.Show(string.Format("Error reading hardware revision from adapter -- {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Version curVersion = new Version(curVerStr);

            // select the correct firmware update item to install based on hardware

            Update fw = null;

            foreach (Update cdu in pkg)
            {
                Logger.Trace("update");

                foreach (Model cdm in cdu.ProductModel)
                {
                    Logger.Trace("model: {0}", cdm.Name);

                    if (cdm.Name == curModel)
                    {
                        foreach (string cdr in cdm.Revision)
                        {
                            Logger.Trace("revision: {0}", cdr);

                            if (cdr == curHwRev)
                            {
                                fw = cdu;
                            }
                        }
                    }
                }
            }

            if (fw != null)
            {
                Logger.Debug("found applicable firmware update in package");
            }
            else
            {
                Logger.Error("could not find applicable firmware update in package");
                MessageBox.Show("Could not find applicable firmware update in package", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Version updVersion = new Version(fw.AppVersion);

            Logger.Debug("firmware audience: {0}", fw.Audience);

            // warn the user if the firmware audience is anything other than release
            if (fw.Audience != "RELEASE")
            {
                string message = string.Format(
                    "THIS FIRMWARE IS NOT FOR GENERAL USE{0}" +
                    "{0}" +
                    "IT MAY NOT WORK CORRECTLY OR AT ALL{0}" +
                    "{0}" +
                    "Audience: {1}{0}" +
                    "{0}" +
                    "DO NOT PROCEED UNLESS YOU HAVE BEEN{0}" +
                    "DIRECTED TO DO SO IN ORDER TO TROUBLESHOOT AN ISSUE{0}" +
                    "{0}" +
                    "Continue?",
                    Environment.NewLine, fw.Audience);

                if (MessageBox.Show(message, "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                {
                    return;
                }
            }

            // adapter already has current firmware
            if (updVersion.Equals(curVersion))
            {
                Logger.Error("the version of the firmware on the device is the same as the version that you are attempting to load");
                MessageBox.Show("The version of the firmware on the device is the same as the version that you are attempting to load", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // do not allow downgrades
            if (updVersion.CompareTo(curVersion) < 0)
            {
                Logger.Error("the version of the firmware on the device is newer than the version that you are attempting to load");
                MessageBox.Show("The version of the firmware on the device is newer than the version that you are attempting to load", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // check if any devices are in app mode
            int appDeviceCount = ManualDetection.DetectConnectedAppDevices().Count;

            Logger.Debug("app devices detected: {0}", appDeviceCount);

            // check if any devices are in bsl mode
            int bslDeviceCount = ManualDetection.DetectConnectedBslDevices();

            Logger.Debug("bsl devices detected: {0}", bslDeviceCount);

            // there should not be more than one device attached at the same time
            if (appDeviceCount > 1)
            {
                Logger.Error("more than one device is connected in app mode");
                MessageBox.Show("More than one device is connected in APP mode", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else if (bslDeviceCount > 1)
            {
                Logger.Error("more than one device is connected in bsl mode");
                MessageBox.Show("More than one device is connected in BSL mode", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else if (appDeviceCount == 1 && bslDeviceCount == 1)
            {
                Logger.Error("both a device in app mode and a device in bsl mode are connected");
                MessageBox.Show("Both a device in APP mode and a device in BSL mode are connected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else if (appDeviceCount == 1 && bslDeviceCount == 0)
            {
                Logger.Debug("requesting device to enter bsl mode");

                try
                {
                    Interact.EnterBslMode(Settings.SelectedDevice);
                }
                catch (Exception ex)
                {
                    Logger.Error("error entering bsl mode -- {0}", ex.Message);
                    MessageBox.Show(string.Format("Error entering BSL mode -- {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                Logger.Debug("device intends to enter bsl mode");
            }
            else if (appDeviceCount == 0 && bslDeviceCount == 1)
            {
                Logger.Debug("device is already in bsl mode");
            }
            else
            {
                Logger.Debug("no devices are connected in either app or bsl mode");
                MessageBox.Show("No devices are connected in either APP or BSL mode", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Logger.Debug("updating device");

            bool updateResult = false;

            try
            {
                FirmwareUpdate upd = new FirmwareUpdate();

                updateResult = upd.UpdateDevice(fw);
            }
            catch (Exception ex)
            {
                Logger.Error("failed to load firmware: {0}", ex.Message);
                MessageBox.Show(string.Format("Failed to load firmware: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (updateResult)
            {
                Logger.Debug("update success");
                MessageBox.Show("Firmware Updated Successfully", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                Logger.Error("update failed");
                MessageBox.Show("Firmware update failed", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 7
0
        private void Initialize_Button_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(string.Format("This function is only to be used to bootstrap blank hardware that you built yourself{0}{0}You should only use this function if you know what it does{0}{0}Continue?", Environment.NewLine), "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
            {
                return;
            }

            Logger.Debug("update package path: {0}", UpdatePackage);

            if (UpdatePackage.Equals(string.Empty))
            {
                Logger.Error("no file selected");
                MessageBox.Show("No file selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // file existed when it was selected but now doesn't
            if (!File.Exists(UpdatePackage))
            {
                Logger.Error("selected file does not exist");
                MessageBox.Show("Selected file does not exist", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                UpdatePackage   = string.Empty;
                lblPath.Content = NO_FILE_SELECTED;
                return;
            }

            // check if package is cfp or ufp
            string ext = System.IO.Path.GetExtension(UpdatePackage);

            Logger.Debug("update package extension: {0}", ext);

            List <Update> pkg = null;

            if (ext == ".cfp")
            {
                Logger.Debug("opening compressed update package");

                try
                {
                    pkg = Firmware.OpenCompressedUpdatePackage(UpdatePackage);
                }
                catch (Exception ex)
                {
                    Logger.Error("unable to parse file: {0}", ex.Message);
                    MessageBox.Show(string.Format("Unable to parse file: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else if (ext == ".ufp")
            {
                Logger.Debug("opening uncompressed update package");

                try
                {
                    pkg = Firmware.OpenUncompressedUpdatePackage(UpdatePackage);
                }
                catch (Exception ex)
                {
                    Logger.Error("unable to parse file: {0}", ex.Message);
                    MessageBox.Show(string.Format("Unable to parse file: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else
            {
                Logger.Error("invalid file selected");
                MessageBox.Show("Invalid file selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Logger.Debug("items in update package: {0}", pkg.Count);

            if (pkg.Count < 1)
            {
                Logger.Error("update package does not contain any updates");
                MessageBox.Show("Update package does not contain any updates", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            int selIndex = cboAvailPkg.SelectedIndex;

            if (selIndex < 0)
            {
                Logger.Error("invalid selected update: {0}", selIndex);
                MessageBox.Show(string.Format("Invalid selected update: {0}", selIndex), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            UpdateItem itm = UpdItm[selIndex];

            Update fw = pkg[itm.PkgIndex];

            if (fw != null)
            {
                Logger.Debug("found applicable firmware update in package");
            }
            else
            {
                Logger.Error("could not find applicable firmware update in package");
                MessageBox.Show("Could not find applicable firmware update in package", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Logger.Debug("firmware audience: {0}", fw.Audience);

            // warn the user if the firmware audience is anything other than release
            if (fw.Audience != "RELEASE")
            {
                string message = string.Format(
                    "THIS FIRMWARE IS NOT FOR GENERAL USE{0}" +
                    "{0}" +
                    "IT MAY NOT WORK CORRECTLY OR AT ALL{0}" +
                    "{0}" +
                    "Audience: {1}{0}" +
                    "{0}" +
                    "DO NOT PROCEED UNLESS YOU HAVE BEEN{0}" +
                    "DIRECTED TO DO SO IN ORDER TO TROUBLESHOOT AN ISSUE{0}" +
                    "{0}" +
                    "Continue?",
                    Environment.NewLine, fw.Audience);

                if (MessageBox.Show(message, "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                {
                    return;
                }
            }

            // check if any devices are in app mode
            int appDeviceCount = ManualDetection.DetectConnectedAppDevices().Count;

            Logger.Debug("app devices detected: {0}", appDeviceCount);

            // check if any devices are in bsl mode
            int bslDeviceCount = ManualDetection.DetectConnectedBslDevices();

            Logger.Debug("bsl devices detected: {0}", bslDeviceCount);

            // there should not be more than one device attached at the same time
            if (appDeviceCount > 0)
            {
                Logger.Error("one or more devices is connected in APP mode");
                MessageBox.Show("One or more devices is connected in APP mode", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else if (bslDeviceCount > 1)
            {
                Logger.Error("more than one device is connected in bsl mode");
                MessageBox.Show("More than one device is connected in BSL mode", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else if (bslDeviceCount == 1)
            {
                Logger.Debug("device is already in bsl mode");
            }
            else
            {
                Logger.Debug("no device is connected in bsl mode");
                MessageBox.Show("No device is connected in BSL mode", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (MessageBox.Show(string.Format("Make sure that you have selected the correct model and hardware revision - an incorrect choice may damage the device{0}{0}Continue?", Environment.NewLine), "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
            {
                return;
            }

            Logger.Debug("updating device");

            bool updateResult = false;

            try
            {
                FirmwareUpdate upd = new FirmwareUpdate();

                updateResult = upd.UpdateDevice(fw);
            }
            catch (Exception ex)
            {
                Logger.Error("failed to load firmware: {0}", ex.Message);
                MessageBox.Show(string.Format("Failed to load firmware: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (updateResult)
            {
                Logger.Debug("update success");
            }
            else
            {
                Logger.Error("update failed");
                MessageBox.Show("Firmware update failed", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Thread.Sleep(5000); // TODO do this better - added to fix catching the device as it first connects and is not ready yet

            List <string> connected = ManualDetection.DetectConnectedAppDevices();

            if (connected.Count > 1)
            {
                Logger.Error("more than one device detected");
                MessageBox.Show("More than one device detected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else if (connected.Count == 1)
            {
                Logger.Debug("one device found");
            }
            else
            {
                Logger.Error("no device detected");
                MessageBox.Show("No device detected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                AdapterProtocol ap = new AdapterProtocol(connected[0]);

                ap.Open();

                ap.Clear();

                ap.WriteInfo(itm.MdlId, itm.HwRevMaj, itm.HwRevMin);

                ap.Close();
            }
            catch (Exception ex)
            {
                Logger.Error("failed to write model and hardware revision: {0}", ex.Message);
                MessageBox.Show(string.Format("Failed to write model and hardware revision: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            MessageBox.Show("Firmware Updated Successfully", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Esempio n. 8
0
 public CommPrgForm()
 {
     this.firmwareUpdate = new FirmwareUpdate();
     this.hidComm        = new CodeplugComms();
     this.InitializeComponent();
 }