Пример #1
0
        private byte[] GenerateUploadData(UInt32 flashMemoryId)
        {
            int dmrIdMemorySize;

            switch (flashMemoryId)
            {
            case 0x4015:                              // 4015 25Q16 16M bits 2M bytes, used in the Baofeng DM-1801 ?
                dmrIdMemorySize = 0x88000 + 0x100000; // 1M
                break;

            case 0x4017:                        // 4017 25Q64 64M bits. Used in Roger's special GD-77 radios modified on the TYT production line
                dmrIdMemorySize = 0x700000;     //7M
                break;

            case 0x4014:                    // 4014 25Q80 8M bits 2M bytes, used in the GD-77
            // fallthrough
            default:
                dmrIdMemorySize = 0x88000;                        //544k
                break;
            }

            dmrIdMemorySize += (chkUseVPMemory.Checked ? 0x28C00 : 0);

            int recordSize = DMRDataItem.compressSize(_stringLength) + ID_NUMBER_SIZE;            // _stringLength + ID_NUMBER_SIZE

            int maxRecords = (dmrIdMemorySize - HEADER_LENGTH) / (recordSize);
            int numRecords = Math.Min(DataList.Count, maxRecords);
            int dataSize   = numRecords * (recordSize) + HEADER_LENGTH;

            dataSize = ((dataSize / 32) + 1) * 32;
            byte[] buffer = new byte[dataSize];

            Array.Copy(SIG_PATTERN_BYTES, buffer, SIG_PATTERN_BYTES.Length);


            Array.Copy(BitConverter.GetBytes(numRecords), 0, buffer, 8, 4);

            if (DataList == null)
            {
                return(buffer);
            }
            List <DMRDataItem> uploadList = new List <DMRDataItem>(DataList);          // Need to make a copy so we can sort it and not screw up the list in the dataGridView

            uploadList.Sort();



            for (int i = 0; i < numRecords; i++)
            {
                Array.Copy(uploadList[i].getRadioData(_stringLength), 0, buffer, HEADER_LENGTH + i * (recordSize), (recordSize));
            }
            return(buffer);
        }
Пример #2
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();

            if (radioInfo.buildDateTime != null)
            {
                // 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;

                if (ID_NUMBER_SIZE == 3)
                {
                    if (chkUseVPMemory.Checked)
                    {
                        SIG_PATTERN_BYTES[2] = (byte)'n';                        // signal use VP memory to the firmware
                    }
                    else
                    {
                        SIG_PATTERN_BYTES[2] = (byte)'N';
                    }
                }

                int recordLength = DMRDataItem.compressSize(_stringLength) + ID_NUMBER_SIZE;

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

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


                int localBufferPosition = 0;

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

                int totalTransferSize = (dataObj.dataBuff.Length / 32) * 32;

                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   = (chkUseVPMemory.Checked ? 0x8F400 : 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");
                }
            }
            if (radioInfo.buildDateTime == null)
            {
                MessageBox.Show("Incompatible firmware. Please update the firmware in your radio", "Error");
            }
        }