private void btnOpenFile_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "firmware files (*.sgl)|*.sgl|binary files (*.bin)|*.bin|All files (*.*)|*.*"; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { enableUI(false); FrmProgress frmProgress = new FrmProgress(); frmProgress.SetLabel(""); frmProgress.SetProgressPercentage(0); frmProgress.FormBorderStyle = FormBorderStyle.FixedSingle; frmProgress.MaximizeBox = false; frmProgress.Show(); FirmwareLoader.UploadFirmware(openFileDialog1.FileName, frmProgress); frmProgress.Close(); } catch (Exception) { } enableUI(true); } }
static void Main(string[] args) { /* Testing only * args = new string[2]; * args[0] = "test.bin"; * args[1] = "GUI"; */ if (args.Length == 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } else { if (args.Length > 1 && args[1] == "GUI") { FrmProgress frmProgress = new FrmProgress(); frmProgress.SetLabel(""); frmProgress.SetProgressPercentage(0); frmProgress.Show(); FirmwareLoader.UploadFirmare(args[0], frmProgress); frmProgress.Close(); } else { FirmwareLoader.UploadFirmare(args[0]); } } // Console.WriteLine("Usage GD77_FirmwareLoader filename"); }
private void downloadFileCompletedCallback(object sender, AsyncCompletedEventArgs ev) { this.progressBar.Visible = false; this.progressBar.Value = 0; // Now flash the downloaded firmware try { FrmProgress frmProgress = new FrmProgress(); frmProgress.SetLabel(""); frmProgress.SetProgressPercentage(0); frmProgress.FormBorderStyle = FormBorderStyle.FixedSingle; frmProgress.MaximizeBox = false; frmProgress.Show(); if (FirmwareLoader.UploadFirmware(tempFile, frmProgress) != 0) { MessageBox.Show("Error: Unable to upload the firmware to the " + FirmwareLoader.getModelName(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } frmProgress.Close(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // Cleanup if (File.Exists(tempFile)) { File.Delete(tempFile); } enableUI(true); }
private void btnOpenFile_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "binary files (*.bin)|*.bin|firmware files (*.sgl)|*.sgl|All files (*.*)|*.*"; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { FrmProgress frmProgress = new FrmProgress(); frmProgress.SetLabel(""); frmProgress.SetProgressPercentage(0); frmProgress.Show(); FirmwareLoader.UploadFirmare(openFileDialog1.FileName, frmProgress); frmProgress.Close(); } catch (Exception) { } } }
public static int UploadFirmare(string fileName, FrmProgress progessForm = null) { byte[] encodeKey = new Byte[4] { (0x61 + 0x00), (0x61 + 0x0C), (0x61 + 0x0D), (0x61 + 0x01) }; _progessForm = progessForm; _specifiedDevice = SpecifiedDevice.FindSpecifiedDevice(0x15A2, 0x0073); if (_specifiedDevice == null) { Console.WriteLine("Error. Can't connect to the GD-77"); return(-1); } byte[] fileBuf = File.ReadAllBytes(fileName); if (Path.GetExtension(fileName).ToLower() == ".sgl") { // Couls be a SGL file ! fileBuf = checkForSGLAndReturnEncryptedData(fileBuf, encodeKey); if (fileBuf == null) { Console.WriteLine("Error. Missing SGL! in .sgl file header"); return(-5); } Console.WriteLine("Firmware file confirmed as SGL"); } else { Console.WriteLine("Firmware file is unencrypted binary"); fileBuf = encrypt(fileBuf); } if (fileBuf.Length > 0x7b000) { Console.WriteLine("\nError. Firmware file too large."); return(-2); } if (sendInitialCommands(encodeKey) == true) { int respCode = sendFileData(fileBuf); if (respCode == 0) { Console.WriteLine("\nFirmware update complete. Please reboot the GD-77"); } else { switch (respCode) { case -1: Console.WriteLine("\nError. File to large"); break; case -2: case -3: case -4: case -5: Console.WriteLine("\nError " + respCode + " While sending data file"); break; } return(-3); } } else { Console.WriteLine("\nError while sending initial commands"); return(-4); } return(0); }
static void Main(string[] args) { int exitCode = 0; /* Testing only * args = new string[2]; * args[0] = "test.bin"; * args[1] = "GUI"; */ if (args.Length == 0) { FirmwareLoader.outputType = FirmwareLoader.probeModel(); if ((FirmwareLoader.outputType < FirmwareLoader.OutputType.OutputType_GD77) || (FirmwareLoader.outputType > FirmwareLoader.OutputType.OutputType_DM1801)) { Console.WriteLine("Unable to detect HT model, using GD-77 as fallback."); FirmwareLoader.outputType = FirmwareLoader.OutputType.OutputType_GD77; } else { Console.WriteLine(String.Format("Detected mode: {0}", FirmwareLoader.getModelName())); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } else { if (args.Contains("--help") || args.Contains("-h") || args.Contains("/h")) { //FirmwareLoader.OutputType[] models = new FirmwareLoader.OutputType[] { FirmwareLoader.OutputType.OutputType_GD77, FirmwareLoader.OutputType.OutputType_GD77S, FirmwareLoader.OutputType.OutputType_DM1801 }; String[] modelsString = { FirmwareLoader.getModelString(FirmwareLoader.OutputType.OutputType_GD77), FirmwareLoader.getModelString(FirmwareLoader.OutputType.OutputType_GD77S), FirmwareLoader.getModelString(FirmwareLoader.OutputType.OutputType_DM1801) }; String allModels = String.Join(" | ", modelsString); Console.WriteLine(String.Format("\nUsage: GD77_FirmwareLoader [GUI] [{0}] [filename]\n\n", allModels)); Environment.Exit(exitCode); } int idxGD77 = Array.IndexOf(args, "GD-77"); int idxDM1801 = Array.IndexOf(args, "DM-1801"); int idxGD77S = Array.IndexOf(args, "GD-77S"); if (idxGD77 >= 0) { FirmwareLoader.outputType = FirmwareLoader.OutputType.OutputType_GD77; args = RemoveArgAt(args, idxGD77); } else if (idxGD77S >= 0) { FirmwareLoader.outputType = FirmwareLoader.OutputType.OutputType_GD77S; args = RemoveArgAt(args, idxGD77S); } else if (idxDM1801 >= 0) { FirmwareLoader.outputType = FirmwareLoader.OutputType.OutputType_DM1801; args = RemoveArgAt(args, idxDM1801); } else { FirmwareLoader.outputType = FirmwareLoader.probeModel(); Console.WriteLine(String.Format(" - Detected model: {0}", FirmwareLoader.getModelName())); } if (args.Length == 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } int idx = Array.IndexOf(args, "GUI"); if (idx >= 0) { args = RemoveArgAt(args, idx); if (args.Length <= 0) { Console.WriteLine("ERROR: No filename specified."); Environment.Exit(-1); } FrmProgress frmProgress = new FrmProgress(); frmProgress.SetLabel(""); frmProgress.SetProgressPercentage(0); frmProgress.Show(); exitCode = FirmwareLoader.UploadFirmware(args[0], frmProgress); frmProgress.Close(); } else { if (args.Length <= 0) { Console.WriteLine("ERROR: No filename specified."); Environment.Exit(-1); } exitCode = FirmwareLoader.UploadFirmware(args[0]); } } // Console.WriteLine("Usage GD77_FirmwareLoader filename"); Environment.Exit(exitCode); }
public static int UploadFirmware(string fileName, FrmProgress progessForm = null) { byte[] encodeKey; _progessForm = progessForm; if (outputType == OutputType.OutputType_GD77) { encodeKey = new Byte[4] { (0x61 + 0x00), (0x61 + 0x0C), (0x61 + 0x0D), (0x61 + 0x01) }; Console.WriteLine("GD-77 Support"); } else // DM-1801 { encodeKey = new Byte[4] { (0x74), (0x21), (0x44), (0x39) }; Console.WriteLine("DM-1801 Support"); } _specifiedDevice = SpecifiedDevice.FindSpecifiedDevice(0x15A2, 0x0073); if (_specifiedDevice == null) { Console.WriteLine("Error. Can't connect to the {0}", ((outputType == OutputType.OutputType_GD77) ? "GD-77" : "DM-1801")); return(-1); } byte[] fileBuf = File.ReadAllBytes(fileName); if (Path.GetExtension(fileName).ToLower() == ".sgl") { // Couls be a SGL file ! fileBuf = checkForSGLAndReturnEncryptedData(fileBuf, encodeKey); if (fileBuf == null) { Console.WriteLine("Error. Missing SGL! in .sgl file header"); return(-5); } Console.WriteLine("Firmware file confirmed as SGL"); } else { Console.WriteLine("Firmware file is unencrypted binary"); fileBuf = encrypt(fileBuf); } if (fileBuf.Length > 0x7b000) { Console.WriteLine("\nError. Firmware file too large."); return(-2); } if (sendInitialCommands(encodeKey) == true) { int respCode = sendFileData(fileBuf); if (respCode == 0) { Console.WriteLine("\n *** Firmware update complete. Please reboot the {0} ***", ((outputType == OutputType.OutputType_GD77) ? "GD-77" : "DM-1801")); if (_progessForm != null) { MessageBox.Show(String.Format("Firmware update complete.Please reboot the {0}.", ((outputType == OutputType.OutputType_GD77) ? "GD-77" : "DM-1801")), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { switch (respCode) { case -1: Console.WriteLine("\nError. File to large"); break; case -2: case -3: case -4: case -5: Console.WriteLine("\nError " + respCode + " While sending data file"); break; } return(-3); } } else { Console.WriteLine("\nError while sending initial commands"); return(-4); } return(0); }
public static int UploadFirmware(string fileName, FrmProgress progessForm = null) { byte[] encodeKey = null; _progessForm = progessForm; switch (outputType) { case OutputType.OutputType_GD77: encodeKey = new Byte[4] { (0x61 + 0x00), (0x61 + 0x0C), (0x61 + 0x0D), (0x61 + 0x01) }; Console.WriteLine(" - GD-77 Support"); break; case OutputType.OutputType_GD77S: encodeKey = new Byte[4] { (0x47), (0x70), (0x6d), (0x4a) }; Console.WriteLine(" - GD-77S Support"); break; case OutputType.OutputType_DM1801: encodeKey = new Byte[4] { (0x74), (0x21), (0x44), (0x39) }; Console.WriteLine(" - DM-1801 Support"); break; case OutputType.OutputType_RD5R: encodeKey = new Byte[4] { (0x53), (0x36), (0x37), (0x62) }; Console.WriteLine(" - RD-5R Support"); break; case OutputType.OutputType_UNKNOWN: Console.WriteLine("Error. Unknown model type"); return(-99); } #if (LINUX_BUILD) _specifiedDevice = UsbLibDotNetHIDDevice.FindDevice(VENDOR_ID, PRODUCT_ID); #else _specifiedDevice = SpecifiedDevice.FindSpecifiedDevice(VENDOR_ID, PRODUCT_ID); #endif if (_specifiedDevice == null) { Console.WriteLine("Error. Can't connect to the {0}", getModelName()); return(-1); } byte[] fileBuf = File.ReadAllBytes(fileName); if (Path.GetExtension(fileName).ToLower() == ".sgl") { Dictionary <FirmwareLoader.OutputType, byte> firmwareModelTag = new Dictionary <FirmwareLoader.OutputType, byte>(); byte headerModel = 0x00; firmwareModelTag.Add(OutputType.OutputType_GD77, 0x1B); firmwareModelTag.Add(OutputType.OutputType_GD77S, 0x70); firmwareModelTag.Add(OutputType.OutputType_DM1801, 0x4F); firmwareModelTag.Add(OutputType.OutputType_RD5R, 0x5C); // valid value for DM5R firmware v2.1.7 // Couls be a SGL file ! fileBuf = checkForSGLAndReturnEncryptedData(fileBuf, encodeKey, ref headerModel); if (fileBuf == null) { Console.WriteLine("Error. Missing SGL! in .sgl file header"); _specifiedDevice.Dispose(); _specifiedDevice = null; return(-5); } Console.WriteLine(" - Firmware file confirmed as SGL"); if (firmwareModelTag[FirmwareLoader.outputType] != headerModel) { Console.WriteLine("Error. The firmware doesn't match the transceiver model."); if (_progessForm != null) { MessageBox.Show("Error. The firmware doesn't match the transceiver model.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } _specifiedDevice.Dispose(); _specifiedDevice = null; return(-10); } } else { Console.WriteLine(" - Firmware file is unencrypted binary"); fileBuf = encrypt(fileBuf); } if (fileBuf.Length > 0x7b000) { Console.WriteLine("Error. Firmware file too large."); _specifiedDevice.Dispose(); _specifiedDevice = null; return(-2); } if (sendInitialCommands(encodeKey) == true) { int respCode = sendFileData(fileBuf); if (respCode == 0) { Console.WriteLine("\n *** Firmware update complete. Please power cycle the {0} ***", getModelName()); if (_progessForm != null) { MessageBox.Show(String.Format("Firmware update complete.Please power cycle the {0}.", getModelName()), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { switch (respCode) { case -1: Console.WriteLine("\nError. File to large"); if (_progessForm != null) { MessageBox.Show("Error. File to large.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; case -2: case -3: case -4: case -5: Console.WriteLine("\nError " + respCode + " While sending data file"); if (_progessForm != null) { MessageBox.Show("Error " + respCode + " While sending data file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; } _specifiedDevice.Dispose(); _specifiedDevice = null; return(-3); } } else { Console.WriteLine("\nError while sending initial commands"); if (_progessForm != null) { MessageBox.Show("Error while sending initial commands.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } _specifiedDevice.Dispose(); _specifiedDevice = null; return(-4); } _specifiedDevice.Dispose(); _specifiedDevice = null; return(0); }
static void Main(string[] args) { int exitCode = 0; /* Testing only * args = new string[2]; * args[0] = "test.bin"; * args[1] = "GUI"; */ if (args.Length == 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } else { int idx = Array.IndexOf(args, "DM-1801"); FirmwareLoader.outputType = ((idx >= 0) ? FirmwareLoader.OutputType.OutputType_DM1801 : FirmwareLoader.OutputType.OutputType_GD77); if (idx >= 0) { args = RemoveArgAt(args, idx); } if (args.Contains("--help") || args.Contains("-h") || args.Contains("/h")) { Console.WriteLine("\nUsage: GD77_FirmwareLoader [GUI] [DM-1801] [filename]\n\n"); Environment.Exit(exitCode); } if (args.Length == 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } idx = Array.IndexOf(args, "GUI"); if (idx >= 0) { args = RemoveArgAt(args, idx); if (args.Length <= 0) { Console.WriteLine("ERROR: No filename specified."); Environment.Exit(-1); } FrmProgress frmProgress = new FrmProgress(); frmProgress.SetLabel(""); frmProgress.SetProgressPercentage(0); frmProgress.Show(); exitCode = FirmwareLoader.UploadFirmware(args[0], frmProgress); frmProgress.Close(); } else { if (args.Length <= 0) { Console.WriteLine("ERROR: No filename specified."); Environment.Exit(-1); } exitCode = FirmwareLoader.UploadFirmware(args[0]); } } // Console.WriteLine("Usage GD77_FirmwareLoader filename"); Environment.Exit(exitCode); }