static bool sendAndCheckResponse(byte[] cmd, byte[] resp)
        {
            const int TRANSFER_LENGTH = 38;

            byte[] responsePadded = new byte[TRANSFER_LENGTH];
            byte[] recBuf         = new byte[TRANSFER_LENGTH];

            if (resp.Length < TRANSFER_LENGTH)
            {
                Buffer.BlockCopy(resp, 0, responsePadded, 0, resp.Length);
            }

            _specifiedDevice.SendData(cmd);
            _specifiedDevice.ReceiveData(recBuf);            // Wait for response

            if (recBuf.SequenceEqual(responsePadded))
            {
                return(true);
            }
            else
            {
                _progessForm.SetLabel("Error read returned ");
                return(false);
            }
        }
        public static int UploadFirmare(string fileName, FirmwareLoaderUI 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)
            {
                _progessForm.SetLabel("Error. Can't connect to the GD-77");
                //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)
                {
                    _progessForm.SetLabel("Error. Missing SGL! in .sgl file header");
                    Console.WriteLine("Error. Missing SGL! in .sgl file header");
                    return(-5);
                }

                _progessForm.SetLabel("Firmware file confirmed as SGL");
            }
            else
            {
                _progessForm.SetLabel("Firmware file is unencrypted binary");
                fileBuf = encrypt(fileBuf);
            }


            if (fileBuf.Length > 0x7b000)
            {
                _progessForm.SetLabel("Error. Firmware file too large.");
                return(-2);
            }

            if (sendInitialCommands(encodeKey) == true)
            {
                int respCode = sendFileData(fileBuf);
                if (respCode == 0)
                {
                    _progessForm.SetLabel("Firmware update complete. Please reboot the GD-77");
                }
                else
                {
                    switch (respCode)
                    {
                    case -1:
                        _progessForm.SetLabel("Error. File to large");
                        break;

                    case -2:
                    case -3:
                    case -4:
                    case -5:
                        _progessForm.SetLabel("Error " + respCode + " While sending data file");
                        break;
                    }
                    return(-3);
                }
            }
            else
            {
                _progessForm.SetLabel("Error while sending initial commands. Is the GD-77 in firmware update mode?");
                return(-4);
            }
            return(0);
        }
Example #3
0
        public static int UploadFirmare(string fileName, FirmwareLoaderUI 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)
                };
                break;

            case OutputType.OutputType_GD77S:
                encodeKey = new Byte[4] {
                    (0x47), (0x70), (0x6d), (0x4a)
                };
                break;

            case OutputType.OutputType_DM1801:
                encodeKey = new Byte[4] {
                    (0x74), (0x21), (0x44), (0x39)
                };
                break;

            case OutputType.OutputType_UNKOWN:
                return(-99);
            }

            _specifiedDevice = SpecifiedDevice.FindSpecifiedDevice(VENDOR_ID, PRODUCT_ID);
            if (_specifiedDevice == null)
            {
                _progessForm.SetLabel(String.Format("Error. Can't connect to the {0}", getModelName()));
                //Console.WriteLine("Error. Can't connect to the GD-77");
                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)
                {
                    _progessForm.SetLabel("Error. Missing SGL! in .sgl file header");
                    Console.WriteLine("Error. Missing SGL! in .sgl file header.");
                    _specifiedDevice.Dispose();
                    _specifiedDevice = null;
                    return(-5);
                }

                _progessForm.SetLabel("Firmware file confirmed as SGL");

                if (firmwareModelTag[FirmwareLoader.outputType] != headerModel)
                {
                    MessageBox.Show("Error. The firmware doesn't match the transceiver model.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    _specifiedDevice.Dispose();
                    _specifiedDevice = null;
                    return(-10);
                }
            }
            else
            {
                _progessForm.SetLabel("Firmware file is unencrypted binary");
                fileBuf = encrypt(fileBuf);
            }


            if (fileBuf.Length > 0x7b000)
            {
                _progessForm.SetLabel("Error. Firmware file too large.");
                _specifiedDevice.Dispose();
                _specifiedDevice = null;
                return(-2);
            }

            if (sendInitialCommands(encodeKey) == true)
            {
                int respCode = sendFileData(fileBuf);
                if (respCode == 0)
                {
                    _progessForm.SetLabel("Success");
                    MessageBox.Show(String.Format("Firmware update complete. Please reboot the {0}", getModelName()), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    switch (respCode)
                    {
                    case -1:
                        _progessForm.SetLabel("Error. Firmware file too large.");
                        break;

                    case -2:
                    case -3:
                    case -4:
                    case -5:
                        _progessForm.SetLabel("Error " + respCode + " While sending data file");
                        break;
                    }
                    _specifiedDevice.Dispose();
                    _specifiedDevice = null;
                    return(-3);
                }
            }
            else
            {
                _progessForm.SetLabel(String.Format("Error while sending initial commands. Is the {0} in firmware update mode?", getModelName()));
                _specifiedDevice.Dispose();
                _specifiedDevice = null;
                return(-4);
            }
            _specifiedDevice.Dispose();
            _specifiedDevice = null;
            return(0);
        }
        public static int UploadFirmare(string fileName, FirmwareLoaderUI 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)
                };
                break;

            case OutputType.OutputType_GD77S:
                encodeKey = new Byte[4] {
                    (0x47), (0x70), (0x6d), (0x4a)
                };
                break;

            case OutputType.OutputType_DM1801:
                encodeKey = new Byte[4] {
                    (0x74), (0x21), (0x44), (0x39)
                };
                break;

            case OutputType.OutputType_RD5R:
                encodeKey = new Byte[4] {
                    (0x53), (0x36), (0x37), (0x62)
                };
                break;

            case OutputType.OutputType_UNKNOWN:
                return(-99);
            }

            _specifiedDevice = SpecifiedDevice.FindSpecifiedDevice(VENDOR_ID, PRODUCT_ID);
            if (_specifiedDevice == null)
            {
                _progessForm.SetLabel(String.Format(FirmwareLoaderUI.StringsDict["Error._Cant_connect_to_the"] + " {0}", getModelName()));
                //Console.WriteLine("Error. Can't connect to the GD-77");
                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)
                {
                    _progessForm.SetLabel(FirmwareLoaderUI.StringsDict["Error._Missing_SGL!_in_.sgl_file_header"]);
                    //Console.WriteLine("Error. Missing SGL! in .sgl file header.");
                    _specifiedDevice.Dispose();
                    _specifiedDevice = null;
                    return(-5);
                }

                _progessForm.SetLabel(FirmwareLoaderUI.StringsDict["Firmware_file_confirmed_as_SGL"]);

                if (firmwareModelTag[FirmwareLoader.outputType] != headerModel)
                {
                    MessageBox.Show(FirmwareLoaderUI.StringsDict["Error._The_firmware_doesnt_match_the_transceiver_model."], FirmwareLoaderUI.StringsDict["Error"], MessageBoxButtons.OK, MessageBoxIcon.Error);
                    _specifiedDevice.Dispose();
                    _specifiedDevice = null;
                    return(-10);
                }
            }
            else
            {
                _progessForm.SetLabel(FirmwareLoaderUI.StringsDict["Firmware_file_is_unencrypted_binary"]);
                fileBuf = encrypt(fileBuf);
            }


            if (fileBuf.Length > 0x7b000)
            {
                _progessForm.SetLabel(FirmwareLoaderUI.StringsDict["Error._Firmware_file_too_large"]);
                _specifiedDevice.Dispose();
                _specifiedDevice = null;
                return(-2);
            }

            if (sendInitialCommands(encodeKey) == true)
            {
                int respCode = sendFileData(fileBuf);
                if (respCode == 0)
                {
                    _progessForm.SetLabel(FirmwareLoaderUI.StringsDict["Success"]);
                    MessageBox.Show(String.Format(FirmwareLoaderUI.StringsDict["Firmware_update_complete"] + " {0}", getModelName()), FirmwareLoaderUI.StringsDict["Success"], MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    switch (respCode)
                    {
                    case -1:
                        _progessForm.SetLabel(FirmwareLoaderUI.StringsDict["Error._Firmware_file_too_large"]);
                        break;

                    case -2:
                    case -3:
                    case -4:
                    case -5:
                        _progessForm.SetLabel(FirmwareLoaderUI.StringsDict["Error"] + " " + respCode + " " + FirmwareLoaderUI.StringsDict["While_sending_data_file"]);
                        break;
                    }
                    _specifiedDevice.Dispose();
                    _specifiedDevice = null;
                    return(-3);
                }
            }
            else
            {
                _progessForm.SetLabel(String.Format(FirmwareLoaderUI.StringsDict["Error_while_sending_initial_commands._Is_the_{0}_in_firmware_update_mode?"], getModelName()));
                _specifiedDevice.Dispose();
                _specifiedDevice = null;
                return(-4);
            }
            _specifiedDevice.Dispose();
            _specifiedDevice = null;
            return(0);
        }