Exemple #1
0
        private void Initialize()
        {
            AssemblyName assembly = Assembly.GetExecutingAssembly().GetName();

            txtToolBar.Text = "MYCADDY DWONLOADER version:" + assembly.Version.ToString();

            download_status = DOWNLOAD_STATUS.ini;
            device_detected = false;
            upgrade_status  = UPGRADE_STATUS.ini;

            // DOWNLOAD_PATH = $@"{Directory.GetCurrentDirectory()}\_download";
            DOWNLOAD_PATH = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\mycaddy\_download";
            if (!Directory.Exists(DOWNLOAD_PATH))
            {
                Directory.CreateDirectory(DOWNLOAD_PATH);
            }
            // Load default model and manual
            download_config();

            // USB Devices init
            usbDetector = new USBDetector();
            usbDetector.StartWatching();
            usbDetector.VolumeChanged += UsbDetector_VolumeChanged;
            usbList = new ObservableCollection <USBDeviceInfo>();
            dispatch_usbList();

            // Model List
            modelList = new ObservableCollection <ModelInfo>();
            dispatch_modelList();

            // Language List
            languageList = new ObservableCollection <LanguageInfo>();

            update_ui();
        }
Exemple #2
0
        private void Initialize()
        {
            download_status = DOWNLOAD_STATUS.ini;
            device_detected = false;
            upgrade_status  = UPGRADE_STATUS.ini;

            // DOWNLOAD_PATH = $@"{Directory.GetCurrentDirectory()}\_download";
            DOWNLOAD_PATH = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\mycaddy\_download";
            if (!Directory.Exists(DOWNLOAD_PATH))
            {
                Directory.CreateDirectory(DOWNLOAD_PATH);
            }
            // Load default manual
            download_manual();

            // USB Devices init
            usbDetector = new USBDetector();
            usbDetector.StartWatching();
            usbDetector.VolumeChanged += UsbDetector_VolumeChanged;
            usbList = new ObservableCollection <USBDeviceInfo>();
            dispatch_usbList();

            // Model List
            modelList = new ObservableCollection <ModelInfo>();
            dispatch_modelList();

            // Language List
            languageList = new ObservableCollection <LanguageInfo>();

            update_ui();
        }
        public SoftwareUpgrade(string MacAddress, IBleCommands Ble, byte[] Image)
        {
            _status     = UPGRADE_STATUS.NOT_STARTED;
            _macAddress = MacAddress;
            _ble        = Ble;
            _image      = Image;
            BleDevices devices = new BleDevices();

            dps = devices[_macAddress];
        }
 private bool SetTimers(ushort Handle)
 {
     _ble.SetTimers(Handle);
     if (!WaitForWriteResponse())
     {
         _status = UPGRADE_STATUS.ERROR;
         OnUpgradeEnd(this, new UpgradeEventArgs(_macAddress, "device not responding to set Timer message", _status));
         return(false);
     }
     return(true);
 }
 public void StopUpgrade()
 {
     if (_upgradeThread != null)
     {
         if (_upgradeThread.IsAlive)
         {
             _upgradeThread.Abort();
             _status = UPGRADE_STATUS.NOT_STARTED;
         }
     }
 }
 public void StartUpgrade()
 {
     if (_busy == false)
     {
         _complitionPercentage = 0;
         _status = UPGRADE_STATUS.STARTED;
         Thread thread = new Thread(UpgradeThread);
         thread.Start();
     }
     else
     {
         _status = UPGRADE_STATUS.BUSY;
     }
 }
Exemple #7
0
        private async void upgrade_process()
        {
            if (lstDevice.Items.Count == 1)
            {
                lstDevice.SelectAll();
            }

            if (lstDevice.SelectedItem != null)
            {
                upgrade_status = UPGRADE_STATUS.start;
                update_ui();

                bool bFormat = false;

                USBDeviceInfo item = (USBDeviceInfo)lstDevice.SelectedItems[0];
                if (cbxUpgradeFormat.IsChecked == true)
                {
                    await Task.Run(() => {
                        bFormat = format_device(item.DiskName);
                    });
                }
                else
                {
                    bFormat = true;
                }

                if (bFormat == true)
                {
                    if (cbbModels.SelectedItem != null && cbbLanguage.SelectedItem != null)
                    {
                        ModelInfo    model = (ModelInfo)cbbModels.SelectedItem;
                        LanguageInfo lan   = (LanguageInfo)cbbLanguage.SelectedItem;

                        try
                        {
                            await Task.Run(() => {
                                upgrade_device(item.DiskName, model, lan);
                            });

                            MessageBoxResult messageBoxResult = MessageBox.Show("업그레이드가 완료되었습니다, 안전하게 장치를 꺼내시겠습니까?", "Remove device confirmation", System.Windows.MessageBoxButton.YesNo);
                            if (messageBoxResult == MessageBoxResult.Yes)
                            {
                                bool remove_safe = RemoveDriveTools.RemoveDrive(item.DiskName);
                                if (remove_safe)
                                {
                                    MessageBox.Show("연결된 장치를 분리하셔도 됩니다.");
                                    // dispatch_usbList();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Select Model and Langauge");
                    }
                }

                upgrade_status = UPGRADE_STATUS.end;
                update_ui();
            }
            else
            {
                MessageBox.Show("Select device!");
            }
        }
Exemple #8
0
        private async void upgrade_task()
        {
            ModelInfo    model = (ModelInfo)cbbModels.SelectedItem;
            LanguageInfo lan   = (LanguageInfo)cbbLanguage.SelectedItem;

            load_manual($"{model.id}.{LanguageResources.Instance.CultureName.Substring(0, 2)}.html");

            try
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                upgrade_status = UPGRADE_STATUS.start;
                update_ui();

                USBDeviceInfo item    = (USBDeviceInfo)lstDevice.SelectedItems[0];
                bool          bFormat = false;
                if (cbxUpgradeFormat.IsChecked == true)
                {
                    await Task.Run(() => {
                        bFormat = format_device(item.DiskName, model.id, model.fileSystem, model.quickFormat, model.clusterSize);
                    });
                }

                // Check Drive size

                /*
                 * DriveInfo drive_info = new DriveInfo(item.DiskName);
                 * if (model.size != drive_info.TotalSize)
                 * {
                 *  Application.Current.Dispatcher.Invoke(() => {
                 *      prgbUpgrade.Value = 0;
                 *      prgbUpgradeText.Foreground = Brushes.Red;
                 *      prgbUpgradeText.Text = "Upgrade Fail: Invalid disk drive size! retry Format";
                 *  });
                 * }
                 */

                await Task.Run(() => {
                    upgrade_device(item.DiskName, model, lan);
                });

                /*
                 * MessageBoxResult messageBoxResult = MessageBox.Show("Upgrade completed, do you want to safely eject your device?", "Remove device confirmation", System.Windows.MessageBoxButton.YesNo);
                 * if (messageBoxResult == MessageBoxResult.Yes)
                 * {
                 *  bool remove_safe = RemoveDriveTools.RemoveDrive(item.DiskName);
                 *  if (remove_safe)
                 *  {
                 *      MessageBox.Show("You can also disconnect the connected device.");
                 *      // dispatch_usbList();
                 *  }
                 * }
                 */
                if (stopWatch.IsRunning)
                {
                    stopWatch.Stop();
                }
                TimeSpan ts          = stopWatch.Elapsed;
                string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

                Application.Current.Dispatcher.Invoke(() => {
                    prgbUpgrade.Value    = upgrade_count;
                    prgbUpgradeText.Text = $"Completed({elapsedTime})";
                    load_manual($"{model.id}.{LanguageResources.Instance.CultureName.Substring(0, 2)}.complete.html");
                });
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                Application.Current.Dispatcher.Invoke(() => {
                    prgbUpgrade.Value          = 0;
                    prgbUpgradeText.Foreground = Brushes.Red;
                    prgbUpgradeText.Text       = "Upgrade Fail:" + e.Message;
                });
            }
            finally
            {
                upgrade_status = UPGRADE_STATUS.end;
                update_ui();
            }
        }
        private void UpgradeThread()
        {
            #region Check that the device is "known"
            if (dps == null)
            {
                _status = UPGRADE_STATUS.ERROR;
                OnUpgradeEnd(this, new UpgradeEventArgs(_macAddress, "device not exist", _status));
                return;
            }
            #endregion

            #region Force to enter OAD mode if the name is not starts with "SimpleBLEPer"
            //_ble.TerminateLinkRequest(dps.Handle);
            if (dps.Name != "SimpleBLEPer")
            {
                // connect
                if (!SD_Connect())
                {
                    _status = UPGRADE_STATUS.ERROR;
                    OnUpgradeEnd(this, new UpgradeEventArgs(_macAddress, "device not connected", _status));
                    return;
                }

                // reboot the device
                _ble.WriteCharValueByHandle(dps.Handle, 0x2B, new byte[] { 0xde, 0 }); // reboot into software download mode
                WaitForResponse();
                //_ble.WriteCharValueByHandle(dps.Handle, 0x34, new byte[] { 0xde, 0 }); // reboot into software download mode

                // Wait for the DPS to reboot into software doaload mode
                Thread.Sleep(DELAY_AFTER_REBOOT);
            }
            #endregion

            #region Initiate OAD session
            ushort NextBloxk = 0xFFFF;
            ImgHdr header    = new ImgHdr(ref _image);
            int    MaxRetry  = 0;

            do
            {
                _ble.TerminateLinkRequest(dps.Handle);
                #region Connect to the DPS
                SD_Connect();
                //_ble.SetTimers(dps.Handle);

                EnableNotification(dps.Handle);
                WaitForWriteResponse();

                EnableIdentityNotification(dps.Handle);
                WaitForWriteResponse();

                EnableOacNotification(dps.Handle);
                WaitForWriteResponse();

                EnableNotification(dps.Handle);
                WaitForWriteResponse();

                _ble.WriteOADByHandle(dps.Handle, OAD_IMAGE_IDENTITY, header.GetBuffer()); // new byte { 1,0 }); // header.GetBuffer()
                WaitForWriteResponse();
                #endregion
            } while ((MaxRetry++ < MAX_RETRY) && (NextBloxk = GetNextBlock()) == 0xFFFF);
            #endregion

            #region Init download vars
            int nBlocks = header.len / 4; // Len is already divided by HAL_FLASH_WORD_SIZE
            int iBlocks = 0;
            int iBytes  = 0;
            #endregion

            #region Write all blocks
            do
            {
                if (NextBloxk == 0xFFFF)
                {
                    _status = UPGRADE_STATUS.ERROR;
                    OnUpgradeEnd(this, new UpgradeEventArgs(_macAddress, "device timeout. Upgarde failed", _status));
                    return;
                }

                byte[] mOadBuffer = new byte[OAD_BUFFER_SIZE];
                // Prepare block
                mOadBuffer[0] = BitConverter.GetBytes(NextBloxk)[0];
                mOadBuffer[1] = BitConverter.GetBytes(NextBloxk)[1];
                Array.Copy(_image, NextBloxk * OAD_BLOCK_SIZE, mOadBuffer, 2, OAD_BLOCK_SIZE); //OAD_BLOCK_SIZE = 16

                // Send block
                _ble.WriteOADByHandle(dps.Handle, OAD_IMAGE_BLOCK, mOadBuffer);

                // Update stats
                iBlocks++;
                iBytes += OAD_BLOCK_SIZE;
                ComplitionPercentage = (int)((float)(NextBloxk * OAD_BLOCK_SIZE) / _image.Length * 100);
                NextBloxk            = GetNextBlock();
                // Thread.Sleep(15);
            } while (NextBloxk < nBlocks);
            #endregion

            _ble.TerminateLinkRequest(dps.Handle);
            // return
            _status = UPGRADE_STATUS.COMPLITED;
            OnUpgradeEnd(this, new UpgradeEventArgs(_macAddress, "device upgraded", _status));
            return;

            #endregion
        }
 public UpgradeEventArgs(string MacAddress = null, string msg = "", UPGRADE_STATUS Status = UPGRADE_STATUS.UNKNOWN)
 {
     this.MacAddress = MacAddress;
     Message         = msg;
     this.Status     = Status;
 }