private bool IsDumperActive() { TL866_Report tl866_report = new TL866_Report(); Get_Report(tl866_report); return(tl866_report.DeviceCode.ToLower() == "codedump" && tl866_report.SerialCode == "000000000000000000000000"); }
//Functions////////////////////////////// private void Reflash(int version) { TL866_Report tl866_report = new TL866_Report(); Get_Report(tl866_report); if (tl866_report.Device_Status != (byte)Firmware.DEVICE_STATUS.BOOTLOADER_MODE) { Reset_Device(); if (!wait_for_device()) { MessageBox.Show("Reset Error!", "TL866", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } Thread.Sleep(1000); Message("<erasing...>"); worker.ReportProgress((int)led_action.led_erase_on); if (!Erase_Device(firmware.GetEraseParametter(devtype))) { MessageBox.Show("Erase failed", "TL866", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (worker.CancellationPending) { return; } worker.ReportProgress((int)led_action.led_erase_off); Thread.Sleep(1000); worker.ReportProgress((int)led_action.led_write_on); Message("<writing...>"); if (!Write_Device(version == (int)Firmware.FIRMWARE_TYPE.FIRMWARE_CUSTOM ? firmware.Encrypt_Firmware(Resources.Dumper, devtype) : firmware.GetEncryptedFirmware(version, devtype))) { worker.ReportProgress((int)led_action.led_write_off); worker.ReportProgress((int)led_action.led_erase_off); MessageBox.Show("Reflash Failed!", "TL866", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Thread.Sleep(500); Message("<resetting...>"); worker.ReportProgress((int)led_action.led_write_off); worker.ReportProgress((int)led_action.led_erase_off); Reset_Device(); if (!wait_for_device()) { SetProgressBar(0); MessageBox.Show("Reset failed", "TL866", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Get_Report(tl866_report); if (tl866_report.Device_Status == (byte)Firmware.DEVICE_STATUS.NORMAL_MODE) { MessageBox.Show("Reflash O.K.!", "TL866", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Reflash Failed!", "TL866", MessageBoxButtons.OK, MessageBoxIcon.Error); } SetProgressBar(0); }
private void Get_Report(TL866_Report report) { usbdevice.Write(new byte[] { Firmware.REPORT_COMMAND, 0, 0, 0, 0 }); usbdevice.Read(report.buffer); }
public void UsbDeviceChanged() { if (usbdevice.DevicesCount == 0 && reset_flag) { return; } reset_flag = false; Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo version = FileVersionInfo.GetVersionInfo(assembly.Location); Text = string.Format("TL866 firmware updater V{0} ({1} {2} connected)", version.FileVersion, usbdevice.DevicesCount, usbdevice.DevicesCount == 1 ? "device" : "devices"); if (usbdevice.DevicesCount > 0 && usbdevice.OpenDevice(usbdevice.Get_Devices()[0])) { TL866_Report tl866_report = new TL866_Report(); Get_Report(tl866_report); TxtInfo.Clear(); switch (tl866_report.Device_Version) { case 1: TxtInfo.AppendText("Device version: TL866A\n"); devtype = (int)Firmware.PROGRAMMER_TYPE.TL866A; break; case 2: TxtInfo.AppendText("Device version: TL866CS\n"); devtype = (int)Firmware.PROGRAMMER_TYPE.TL866CS; break; default: TxtInfo.AppendText("Device version: Unknown\n"); break; } switch ((Firmware.DEVICE_STATUS)tl866_report.Device_Status) { case Firmware.DEVICE_STATUS.NORMAL_MODE: TxtInfo.AppendText("Device status: Normal working mode.\n"); LedNorm.BackColor = LightGreen; LedBoot.BackColor = DarkGreen; break; case Firmware.DEVICE_STATUS.BOOTLOADER_MODE: TxtInfo.AppendText("Device status: Bootloader mode <waiting for update.>\n"); LedNorm.BackColor = DarkGreen; LedBoot.BackColor = LightGreen; break; default: TxtInfo.AppendText("Device status: Unknown\n"); LedNorm.BackColor = DarkGreen; LedBoot.BackColor = DarkGreen; break; } bool isDumperActive = IsDumperActive(); if (isDumperActive) { usbdevice.Write(new[] { Firmware.DUMPER_INFO }); Dumper_Report dumper_report = new Dumper_Report(); if (usbdevice.Read(dumper_report.buffer) > 0) { devcode = dumper_report.DeviceCode; serial = dumper_report.SerialCode; } else { devcode = string.Empty; serial = string.Empty; } } else { devcode = tl866_report.DeviceCode; serial = tl866_report.SerialCode; } if (AdvancedWindow != null && !AdvancedWindow.IsDisposed) { GetInfo(); } TxtInfo.AppendText(string.Format("Device code: {0}{1}\n", devcode, Firmware.Calc_CRC(devcode, serial) ? "(Bad device code)" : string.Empty)); TxtInfo.AppendText(string.Format("Serial number: {0}{1}\n", serial, Firmware.Calc_CRC(devcode, serial) ? "(Bad serial code)" : string.Empty)); TxtInfo.AppendText(string.Format("Firmware version: {0}\n", isDumperActive ? "Firmware dumper" : tl866_report.Device_Status == (byte)Firmware.DEVICE_STATUS.NORMAL_MODE ? string.Format("{0}.{1}.{2}", tl866_report.hardware_version, tl866_report.firmware_version_major, tl866_report.firmware_version_minor) : "Bootloader\n")); BtnDump.Enabled = isDumperActive; BtnAdvanced.Enabled = isDumperActive; byte cs = 0; for (int i = 5; i < 8; i++) { cs += (byte)tl866_report.DeviceCode[i]; } for (int i = 0; i < 24; i++) { cs += (byte)tl866_report.SerialCode[i]; } cs += tl866_report.b0; cs += tl866_report.b1; if (tl866_report.firmware_version_minor > 82 && cs != tl866_report.checksum && tl866_report.bad_serial == 0) { TxtInfo.AppendText("Bad serial checksum."); } if (tl866_report.firmware_version_minor > 82 && tl866_report.bad_serial != 0) { TxtInfo.AppendText("Bad serial."); } } else { BtnDump.Enabled = false; BtnAdvanced.Enabled = false; Leds_Off(); TxtInfo.Clear(); devcode = string.Empty; serial = string.Empty; if (AdvancedWindow != null && !AdvancedWindow.IsDisposed) { GetInfo(); } } }