コード例 #1
0
        static public OutputType probeModel()
        {
            byte[]                commandLetterA = new byte[] { 0x41 };                                                                                                                           // 'A'
            byte[][]              command0       = new byte[][] { new byte[] { 0x44, 0x4f, 0x57, 0x4e, 0x4c, 0x4f, 0x41, 0x44 }, new byte[] { 0x23, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x3f } }; // DOWNLOAD
            byte[][]              command1       = new byte[][] { commandLetterA, responseOK };
            byte[]                commandDummy   = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
            byte[][][]            commandID      = { command0, command1 };
            StringAndOutputType[] models         = new StringAndOutputType[] {
                new StringAndOutputType {
                    Model = Encoding.ASCII.GetBytes("DV01"), Type = OutputType.OutputType_GD77
                },
                new StringAndOutputType {
                    Model = Encoding.ASCII.GetBytes("DV02"), Type = OutputType.OutputType_GD77S
                },
                new StringAndOutputType {
                    Model = Encoding.ASCII.GetBytes("DV03"), Type = OutputType.OutputType_DM1801
                },
                new StringAndOutputType {
                    Model = Encoding.ASCII.GetBytes("DV02"), Type = OutputType.OutputType_RD5R
                }
            };
            int commandNumber = 0;

            byte[] resp;


#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 the transceiver");
                return(OutputType.OutputType_UNKNOWN);
            }

            while (commandNumber < commandID.Length)
            {
                if (sendAndCheckResponse(commandID[commandNumber][0], commandID[commandNumber][1]) == false)
                {
                    Console.WriteLine("Error sending command.");
                    _specifiedDevice.Dispose();
                    _specifiedDevice = null;
                    return(OutputType.OutputType_UNKNOWN);
                }

                commandNumber = commandNumber + 1;
            }

            resp = sendAndGetResponse(commandDummy);

            if (resp.Length >= 4)
            {
                foreach (StringAndOutputType model in models)
                {
                    if (model.Model.SequenceEqual(resp.ToList().GetRange(0, 4).ToArray()))
                    {
                        _specifiedDevice.Dispose();
                        _specifiedDevice = null;
                        return(model.Type);
                    }
                }
            }

            _specifiedDevice.Dispose();
            _specifiedDevice = null;
            return(OutputType.OutputType_UNKNOWN);
        }
コード例 #2
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);
        }