Ejemplo n.º 1
0
 private void TxtDevcode_TextChanged(object sender, EventArgs e)
 {
     if (Firmware.Calc_CRC(TxtDevcode.Text, TxtSerial.Text))
     {
         MessageBox.Show("Bad Device and serial code!", "TL866", MessageBoxButtons.OK,
                         MessageBoxIcon.Exclamation);
     }
 }
Ejemplo n.º 2
0
        private void BtnRndDev_Click(object sender, EventArgs e)
        {
            string s;

            do
            {
                s = Utils.Generator.Next(0, 99999999).ToString("00000000");
            } while (Firmware.Calc_CRC(s, TxtSerial.Text));
            TxtDevcode.Text = s;
        }
Ejemplo n.º 3
0
        private void BtnRndSer_Click(object sender, EventArgs e)
        {
            string s;

            do
            {
                s = "";
                for (int i = 0; i < 24; i++)
                {
                    s += Utils.Generator.Next(0, 15).ToString("X");
                }
            } while (Firmware.Calc_CRC(TxtDevcode.Text, s));
            TxtSerial.Text = s;
        }
Ejemplo n.º 4
0
        public void GetInfo()
        {
            if (IsDumperActive())
            {
                AdvancedWindow.TxtInfo.Clear();
                usbdevice.Write(new[] { Firmware.DUMPER_INFO });
                Dumper_Report dumper_report = new Dumper_Report();
                if (usbdevice.Read(dumper_report.buffer) > 0)
                {
                    AdvancedWindow.TxtDevcode.Text = dumper_report.DeviceCode;
                    AdvancedWindow.TxtSerial.Text  = dumper_report.SerialCode;

                    AdvancedWindow.TxtInfo.AppendText(string.Format("Device code: {0}{1}\n",
                                                                    AdvancedWindow.TxtDevcode.Text,
                                                                    Firmware.Calc_CRC(AdvancedWindow.TxtDevcode.Text, AdvancedWindow.TxtSerial.Text)
                            ? "(Bad device code)"
                            : string.Empty));
                    AdvancedWindow.TxtInfo.AppendText(string.Format("Serial number: {0}{1}\n",
                                                                    AdvancedWindow.TxtSerial.Text,
                                                                    Firmware.Calc_CRC(AdvancedWindow.TxtDevcode.Text, AdvancedWindow.TxtSerial.Text)
                            ? "(Bad serial code)"
                            : string.Empty));
                    AdvancedWindow.TxtInfo.AppendText(string.Format("Bootloader version: {0}\n",
                                                                    dumper_report.bootloader_version == 1 ? "A" : "CS"));
                    AdvancedWindow.TxtInfo.AppendText(string.Format("Code Protection bit: {0}",
                                                                    dumper_report.cp_bit > 0 ? "No" : "Yes"));
                    AdvancedWindow.ChkCP.CheckState = dumper_report.cp_bit == 0
                        ? CheckState.Checked
                        : CheckState.Unchecked;
                    if (dumper_report.bootloader_version == 1)
                    {
                        AdvancedWindow.RadioA.Checked = true;
                    }
                    else
                    {
                        AdvancedWindow.RadioCS.Checked = true;
                    }
                    return;
                }
            }
            AdvancedWindow.TxtInfo.Clear();
            AdvancedWindow.TxtDevcode.Clear();
            AdvancedWindow.TxtSerial.Clear();
            AdvancedWindow.ChkCP.CheckState = CheckState.Indeterminate;
            AdvancedWindow.RadioA.Checked   = false;
            AdvancedWindow.RadioCS.Checked  = false;
        }
Ejemplo n.º 5
0
 private void OK_Button_Click(object sender, EventArgs e)
 {
     if (TxtDevcode.Text.Trim().ToLower() == "codedump" && TxtSerial.Text.Trim() == "000000000000000000000000")
     {
         MessageBox.Show("Please enter another device and serial code!\nThese are reserved.", "TL866",
                         MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return;
     }
     if (Firmware.Calc_CRC(TxtDevcode.Text, TxtSerial.Text))
     {
         MessageBox.Show("Bad Device and serial code!", "TL866", MessageBoxButtons.OK,
                         MessageBoxIcon.Exclamation);
         return;
     }
     DialogResult = DialogResult.OK;
     Close();
 }
Ejemplo n.º 6
0
 public MainForm()
 {
     InitializeComponent();
     firmware   = new Firmware();
     usbdevice  = new UsbDevice();
     reset_flag = false;
     devcode    = string.Empty;
     serial     = string.Empty;
     usbdevice.UsbDeviceChanged += UsbDeviceChanged;
     usbdevice.RegisterForDeviceChange(true, this);
     worker                            = new BackgroundWorker();
     worker.DoWork                    += Worker_DoWork;
     worker.ProgressChanged           += Worker_ProgressChanged;
     worker.WorkerReportsProgress      = true;
     worker.WorkerSupportsCancellation = true;
     Leds_Off();
     UsbDeviceChanged();
 }
Ejemplo n.º 7
0
        private void BtnRndSer_Click(object sender, EventArgs e)
        {
            if (TxtDevcode.Text == string.Empty)
            {
                BtnRndDev_Click(null, null);
            }
            string s;
            ushort crc = get_dev_crc();

            do
            {
                s = (crc >> 8).ToString("X2") + Utils.Generator.Next(0, 255).ToString("X2") + (crc & 0xFF).ToString("X2");
                for (int i = 0; i < 9; i++)
                {
                    s += Utils.Generator.Next(0, 255).ToString("X2");
                }
            } while (Firmware.Calc_CRC(TxtDevcode.Text, s));
            TxtSerial.Text = s;
        }
Ejemplo n.º 8
0
        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();
                }
            }
        }