Пример #1
0
        public CommPortSelector()
        {
            InitializeComponent();
            List <string> ports = SetupDiWrap.GetComPortNames();

            foreach (string s in ports)
            {
                cmbPorts.Items.Add(s);
            }
        }
Пример #2
0
 private void btnWriteToGD77_Click(object sender, EventArgs e)
 {
     if (SetupDiWrap.ComPortNameFromFriendlyNamePrefix("OpenGD77") != null)
     {
         writeToOpenGD77();
     }
     else
     {
         MessageBox.Show("Please connect the GD-77 running OpenGD77 firmware, and try again.", "OpenGD77 radio not detected.");
     }
 }
Пример #3
0
 private void btnWriteToGD77_Click(object sender, EventArgs e)
 {
     if (SetupDiWrap.ComPortNameFromFriendlyNamePrefix("OpenGD77") != null)
     {
         writeToOpenGD77();
     }
     else
     {
         writeToOfficalFirmware();
     }
 }
Пример #4
0
        private void writeToOpenGD77()
        {
            String gd77CommPort = SetupDiWrap.ComPortNameFromFriendlyNamePrefix("OpenGD77");

            try
            {
                _port             = new SerialPort(gd77CommPort, 115200, Parity.None, 8, StopBits.One);
                _port.ReadTimeout = 1000;
                _port.Open();
            }
            catch (Exception)
            {
                _port = null;
                MessageBox.Show("Failed to open comm port", "Error");
                return;
            }

            // Commands to control the screen etc in the firmware
            sendCommand(0);
            sendCommand(1);
            sendCommand(2, 0, 0, 3, 1, 0, "CPS");
            sendCommand(2, 0, 16, 3, 1, 0, "Writing");
            sendCommand(2, 0, 32, 3, 1, 0, "DMRID");
            sendCommand(2, 0, 48, 3, 1, 0, "Database");
            sendCommand(3);
            sendCommand(6, 4);            // flash red LED


            OpenGD77CommsTransferData dataObj = new OpenGD77CommsTransferData(OpenGD77CommsTransferData.CommsAction.NONE);

            dataObj.mode = OpenGD77CommsTransferData.CommsDataMode.DataModeWriteFlash;

            SIG_PATTERN_BYTES[3] = (byte)(0x4a + _stringLength + 4);

            dataObj.dataBuff = GenerateUploadData();
            dataObj.localDataBufferStartPosition = 0;
            dataObj.startDataAddressInTheRadio   = 0x30000;
            dataObj.transferLength = (dataObj.dataBuff.Length / 32) * 32;
            WriteFlash(dataObj);
            progressBar1.Value = 0;
            sendCommand(5);
            if (_port != null)
            {
                try
                {
                    _port.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed to close OpenGD77 comm port", "Warning");
                }
            }
        }
Пример #5
0
        private void writeToOpenGD77()
        {
            String gd77CommPort       = SetupDiWrap.ComPortNameFromFriendlyNamePrefix("OpenGD77");
            int    radioMemoryAddress = 0x30000;

            try
            {
                _port             = new SerialPort(gd77CommPort, 115200, Parity.None, 8, StopBits.One);
                _port.ReadTimeout = 1000;
                _port.Open();
            }
            catch (Exception)
            {
                _port = null;
                MessageBox.Show("Failed to open comm port", "Error");
                return;
            }


            RadioInfo radioInfo = readOpenGD77RadioInfo();



            // Commands to control the screen etc in the firmware
            sendCommand(0);
            sendCommand(1);
            sendCommand(2, 0, 0, 3, 1, 0, "CPS");
            sendCommand(2, 0, 16, 3, 1, 0, "Writing");
            sendCommand(2, 0, 32, 3, 1, 0, "DMRID");
            sendCommand(2, 0, 48, 3, 1, 0, "Database");
            sendCommand(3);
            sendCommand(6, 4);            // flash red LED

            OpenGD77CommsTransferData dataObj = new OpenGD77CommsTransferData(OpenGD77CommsTransferData.CommsAction.NONE);

            dataObj.mode = OpenGD77CommsTransferData.CommsDataMode.DataModeWriteFlash;

            SIG_PATTERN_BYTES[3] = (byte)(0x4a + _stringLength + 4);

            dataObj.dataBuff = GenerateUploadData(radioInfo.flashId);
            //File.WriteAllBytes("d:\\dmrid_db.bin", dataObj.dataBuff);// Write for debugging purposes


            int localBufferPosition = 0;

            dataObj.localDataBufferStartPosition = localBufferPosition;
            dataObj.startDataAddressInTheRadio   = radioMemoryAddress;

            int totalTransferSize = (dataObj.dataBuff.Length / 32) * 32;
            int recordLength      = _stringLength + 4;

            int splitPoint = HEADER_LENGTH + (recordLength * ((0x40000 - HEADER_LENGTH) / recordLength));

            if (totalTransferSize > splitPoint)
            {
                dataObj.transferLength = splitPoint;
            }
            else
            {
                dataObj.transferLength = totalTransferSize;
            }
            WriteFlash(dataObj);            // transfer the first data section

            totalTransferSize   -= dataObj.transferLength;
            localBufferPosition += dataObj.transferLength;

            if (totalTransferSize > 0)
            {
                dataObj.startDataAddressInTheRadio   = 0xB8000;
                dataObj.localDataBufferStartPosition = localBufferPosition;                // continue on from last transfer length
                dataObj.transferLength = totalTransferSize;
                WriteFlash(dataObj);
            }

            progressBar1.Value = 0;
            sendCommand(5);
            if (_port != null)
            {
                try
                {
                    _port.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed to close OpenGD77 comm port", "Warning");
                }
            }
        }
Пример #6
0
        private void btnWrite_Click(object sender, EventArgs e)
        {
            //bool retVal;

            /*	if (DialogResult.Yes != MessageBox.Show("Writing the calibration data to Radioddity GD-77 or any other compatible radio, could potentially damage your radio. By clicking 'Yes' you acknowledge that you use this feature entirely at your own risk", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button2))
             *      {
             *              return;
             *      }
             */
            String gd77CommPort = SetupDiWrap.ComPortNameFromFriendlyNamePrefix("OpenGD77");

            if (gd77CommPort != null)
            {
                OpenGD77CommsTransferData dataObj = new OpenGD77CommsTransferData(OpenGD77CommsTransferData.CommsAction.NONE);
                dataObj.dataBuff = new Byte[CALIBRATION_DATA_SIZE];

                _port             = new SerialPort(gd77CommPort, 115200, Parity.None, 8, StopBits.One);
                _port.ReadTimeout = 1000;



                int calibrationDataSize = Marshal.SizeOf(typeof(CalibrationData));

                byte[] array = DataToByte(this.calibrationBandControlUHF.data);
                Array.Copy(array, 0, dataObj.dataBuff, 0, calibrationDataSize);

                array = DataToByte(this.calibrationBandControlVHF.data);
                Array.Copy(array, 0, dataObj.dataBuff, VHF_OFFSET, calibrationDataSize);



                _port.Open();
                sendCommand(0);
                sendCommand(1);
                sendCommand(2, 0, 0, 3, 1, 0, "CPS");
                sendCommand(2, 0, 16, 3, 1, 0, "Restoring");
                sendCommand(2, 0, 32, 3, 1, 0, "Calibration");
                sendCommand(3);
                sendCommand(6, 4);                // flash red LED

                dataObj.mode = OpenGD77CommsTransferData.CommsDataMode.DataModeWriteFlash;

                dataObj.localDataBufferStartPosition = 0;
                dataObj.startDataAddressInTheRadio   = MEMORY_LOCATION;
                dataObj.transferLength = CALIBRATION_DATA_SIZE;
                //displayMessage("Restoring Flash");
                if (WriteFlash(dataObj))
                {
                    //displayMessage("Restore complete");
                }
                else
                {
                    MessageBox.Show("Error while restoring");
                    //displayMessage("Error while restoring");
                    dataObj.responseCode = 1;
                }
                sendCommand(6, 2);                // Save settings and VFO's
                sendCommand(6, 1);                // Reboot
                _port.Close();
                lblMessage.Text = "Calibration update completed";
                //MessageBox.Show("Calibration update completed");
            }
            else
            {
                // Pre-read to see if the Calibration area appears to be writable
                CodeplugComms.CommunicationMode = CodeplugComms.CommunicationType.dataRead;
                CommPrgForm commPrgForm = new CommPrgForm(true);                // true =  close download form as soon as download is complete
                commPrgForm.StartPosition    = FormStartPosition.CenterParent;
                CodeplugComms.startAddress   = CALIBRATION_MEMORY_LOCATION_OFFICIAL_USB_PROTOCOL;
                CodeplugComms.transferLength = 0x20;
                DialogResult result = commPrgForm.ShowDialog();

                int calibrationDataSize = Marshal.SizeOf(typeof(CalibrationData));

                byte[] array = DataToByte(this.calibrationBandControlUHF.data);
                Array.Copy(array, 0, MainForm.CommsBuffer, CALIBRATION_MEMORY_LOCATION_OFFICIAL_USB_PROTOCOL, calibrationDataSize);

                array = DataToByte(this.calibrationBandControlVHF.data);
                Array.Copy(array, 0, MainForm.CommsBuffer, CALIBRATION_MEMORY_LOCATION_OFFICIAL_USB_PROTOCOL + VHF_OFFSET, calibrationDataSize);

                CodeplugComms.CommunicationMode = CodeplugComms.CommunicationType.calibrationWrite;

                commPrgForm = new CommPrgForm(true);                // true =  close download form as soon as download is complete
                commPrgForm.StartPosition = FormStartPosition.CenterParent;
                commPrgForm.ShowDialog();
                MessageBox.Show("Calibration update completed");
            }
        }
Пример #7
0
        public bool readDataFromRadio()
        {
            bool         retVal = true;
            DialogResult result = DialogResult.OK;

            lblMessage.Text = "";

            int calibrationDataSize = Marshal.SizeOf(typeof(CalibrationData));

            byte[] array = new byte[calibrationDataSize];

            String gd77CommPort = SetupDiWrap.ComPortNameFromFriendlyNamePrefix("OpenGD77");

            if (gd77CommPort != null)
            {
                _port             = new SerialPort(gd77CommPort, 115200, Parity.None, 8, StopBits.One);
                _port.ReadTimeout = 1000;

                OpenGD77CommsTransferData dataObj = new OpenGD77CommsTransferData(OpenGD77CommsTransferData.CommsAction.NONE);

                _port.Open();
                sendCommand(0);
                sendCommand(1);
                sendCommand(2, 0, 0, 3, 1, 0, "CPS");                // Write a line of text to CPS screen at position x=0,y=3 with font size 3, alignment centre
                sendCommand(2, 0, 16, 3, 1, 0, "Backup");
                sendCommand(2, 0, 32, 3, 1, 0, "Calibration");
                sendCommand(3);
                sendCommand(6, 3);                // flash green LED

                dataObj.mode     = OpenGD77CommsTransferData.CommsDataMode.DataModeReadFlash;
                dataObj.dataBuff = new Byte[CALIBRATION_DATA_SIZE];
                dataObj.localDataBufferStartPosition = 0;
                dataObj.startDataAddressInTheRadio   = MEMORY_LOCATION;
                dataObj.transferLength = CALIBRATION_DATA_SIZE;
                //displayMessage("Reading Calibration");
                if (!ReadFlashOrEEPROM(dataObj))
                {
                    //displayMessage("Error while reading calibration");
                    result = DialogResult.Abort;
                    retVal = false;
                    dataObj.responseCode = 1;
                }
                else
                {
                    //displayMessage("");
                }
                sendCommand(5);                // close CPS screen
                _port.Close();



                for (int p = 0; p < CALIBRATION_HEADER_SIZE; p++)
                {
                    if (dataObj.dataBuff[p] != CALIBRATION_HEADER[p])
                    {
                        MessageBox.Show("Calibration data could not be found. Please update your firmware");
                        return(false);
                    }
                }

                Array.Copy(dataObj.dataBuff, 0, array, 0, calibrationDataSize);
                this.calibrationBandControlUHF.data = (CalibrationData)ByteToData(array);

                array = new byte[calibrationDataSize];
                Array.Copy(dataObj.dataBuff, 0 + VHF_OFFSET, array, 0, calibrationDataSize);
                this.calibrationBandControlVHF.data = (CalibrationData)ByteToData(array);
            }
            else
            {
                CommPrgForm commPrgForm;
                MainForm.CommsBuffer = new byte[1024 * 1024];

                // Pre-read to see if the calibration area appears to be readable.
                CodeplugComms.CommunicationMode = CodeplugComms.CommunicationType.dataRead;
                commPrgForm = new CommPrgForm(true);                // true =  close download form as soon as download is complete
                commPrgForm.StartPosition    = FormStartPosition.CenterParent;
                CodeplugComms.startAddress   = CalibrationForm.CALIBRATION_MEMORY_LOCATION_OFFICIAL_USB_PROTOCOL;
                CodeplugComms.transferLength = 0x20;
                result = commPrgForm.ShowDialog();

                CodeplugComms.CommunicationMode = CodeplugComms.CommunicationType.calibrationRead;
                commPrgForm = new CommPrgForm(true);                // true =  close download form as soon as download is complete
                commPrgForm.StartPosition = FormStartPosition.CenterParent;
                result = commPrgForm.ShowDialog();

                if (DialogResult.OK == result)
                {
                    // Need to setup the VHF and UHF data storage class first, as its used when initialising the components

                    Array.Copy(MainForm.CommsBuffer, CALIBRATION_MEMORY_LOCATION_OFFICIAL_USB_PROTOCOL, array, 0, calibrationDataSize);
                    this.calibrationBandControlUHF.data = (CalibrationData)ByteToData(array);

                    array = new byte[calibrationDataSize];
                    Array.Copy(MainForm.CommsBuffer, CALIBRATION_MEMORY_LOCATION_OFFICIAL_USB_PROTOCOL + VHF_OFFSET, array, 0, calibrationDataSize);
                    this.calibrationBandControlVHF.data = (CalibrationData)ByteToData(array);
                }
                else
                {
                    lblMessage.Text = "Error";
                    retVal          = false;
                }
            }

            return(retVal);
        }