private void downloadFromRadioIdCompleteHandler(object sender, DownloadStringCompletedEventArgs e) { string ownRadioId = GeneralSetForm.data.RadioId; string csv; // = e.Result; int maxAge = Int32.MaxValue; try { csv = e.Result; } catch (Exception) { MessageBox.Show(Settings.dicCommon["UnableDownloadFromInternet"]); return; } try { maxAge = Int32.Parse(this.txtAgeMaxDays.Text); } catch (Exception) { } try { bool first = true; foreach (var csvLine in csv.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries)) { if (first) { first = false; continue; } if (csvLine.Length > 0) { DMRDataItem item = (new DMRDataItem()).FromRadioidDotNet(csvLine); if (item.DMRIdString.IndexOf(txtRegionId.Text) == 0) { DataList.Add(item); } } } DataList = DataList.Distinct().ToList(); rebindData(); Cursor.Current = Cursors.Default; } catch (Exception ex) { MessageBox.Show(Settings.dicCommon["ErrorParsingData"]); } finally { _wc = null; _isDownloading = false; Cursor.Current = Cursors.Default; } }
private void importFromRadioIdCSV() { if (_radioIdCSV == null) { return; } try { bool first = true; foreach (var csvLine in _radioIdCSV.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries)) { if (first) { first = false; continue; } if (csvLine.Length > 0) { DMRDataItem item = (new DMRDataItem()).FromRadioidDotNet(csvLine); if (item.DMRIdString.IndexOf(txtRegionId.Text) == 0) { DataList.Add(item); } } } DataList = DataList.Distinct().ToList(); rebindData(); Cursor.Current = Cursors.Default; } catch (Exception) { MessageBox.Show(Settings.dicCommon["ErrorParsingData"]); } }
private void DMRMARCDownloadCompleteHandler(object sender, DownloadStringCompletedEventArgs e) { string ownRadioId = GeneralSetForm.data.RadioId; string csv; // = e.Result; int maxAge = Int32.MaxValue; try { csv = e.Result; } catch (Exception) { MessageBox.Show(Settings.dicCommon["UnableDownloadFromInternet"]); return; } try { maxAge = Int32.Parse(this.txtAgeMaxDays.Text); } catch (Exception) { } try { bool first = true; foreach (var csvLine in csv.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { if (first) { first = false; continue; } DMRDataItem item = (new DMRDataItem()).FromHamDigital(csvLine); if (item.AgeAsInt <= maxAge) { DataList.Add(item); } } DataList = DataList.Distinct().ToList(); rebindData(); //DataToCodeplug(); Cursor.Current = Cursors.Default; } catch (Exception ex) { MessageBox.Show(Settings.dicCommon["ErrorParsingData"]); } finally { _wc = null; _isDownloading = false; Cursor.Current = Cursors.Default; } }
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); }
private void btnImportCSV_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "firmware files|*.csv"; if (openFileDialog.ShowDialog() == DialogResult.OK && openFileDialog.FileName != null) { try { bool first = true; String region = txtRegionId.Text; using (var reader = new StreamReader(openFileDialog.FileName)) { while (!reader.EndOfStream) { string csvLine = reader.ReadLine(); if (first) { first = false; continue; } if (csvLine.Length > 0) { if (csvLine.IndexOf(txtRegionId.Text) == 0) { DMRDataItem item = (new DMRDataItem()).FromRadioidDotNet(csvLine); if (item != null) { DataList.Add(item); } } } } DataList = DataList.Distinct().ToList(); rebindData(); Cursor.Current = Cursors.Default; } } catch (Exception) { MessageBox.Show("The CSV file could not be opened"); } } }
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"); } }
public DMRIDForm() { SIG_PATTERN_BYTES = new byte[] { (byte)'I', (byte)'D', (byte)'-', 0x56, 0x30, 0x30, 0x31, 0x00 }; InitializeComponent(); this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);// Roger Clark. Added correct icon on main form! cmbStringLen.Visible = false; lblEnhancedLength.Visible = false; txtRegionId.Text = (int.Parse(GeneralSetForm.data.RadioId) / 10000).ToString(); DataList = new List <DMRDataItem>(); //cmbStringLen.SelectedIndex = 2; dataGridView1.AutoGenerateColumns = false; DataGridViewCell cell = new DataGridViewTextBoxCell(); DataGridViewTextBoxColumn colFileName = new DataGridViewTextBoxColumn() { CellTemplate = cell, Name = "Id", // internal name HeaderText = "ID", // Column header text DataPropertyName = "DMRID" // object property }; dataGridView1.Columns.Add(colFileName); cell = new DataGridViewTextBoxCell(); colFileName = new DataGridViewTextBoxColumn() { CellTemplate = cell, Name = "Call", // internal name HeaderText = "Callsign", // Column header text DataPropertyName = "Callsign" // object property }; dataGridView1.Columns.Add(colFileName); cell = new DataGridViewTextBoxCell(); colFileName = new DataGridViewTextBoxColumn() { CellTemplate = cell, Name = "Details", // internal name HeaderText = "Details", // Column header text DataPropertyName = "Details", // object property Width = 300, }; dataGridView1.Columns.Add(colFileName); /* * cell = new DataGridViewTextBoxCell(); * colFileName = new DataGridViewTextBoxColumn() * { * CellTemplate = cell, * Name = "Age",// internal name * HeaderText = "Last heard (days ago)",// Column header text * DataPropertyName = "AgeInDays", // object property * Width = 140, * ValueType = typeof(int), * SortMode = DataGridViewColumnSortMode.Automatic * }; * dataGridView1.Columns.Add(colFileName); */ dataGridView1.UserDeletedRow += new DataGridViewRowEventHandler(dataGridRowDeleted); rebindData(); cmbStringLen.SelectedIndex = 10; // Default to 16 characters cmbStringLen.Visible = true; lblEnhancedLength.Visible = true; cmbRadioType.SelectedIndex = 0; updateTotalNumberMessage(); FormBorderStyle = FormBorderStyle.FixedSingle; string s = ""; //string a = ""; for (int i = 0; i < 256; i++) { // Console.WriteLine(DMRDataItem.compressChar((char)i)); s += DMRDataItem.compressChar((char)i) + ","; //a += (char)i + ","; } //Console.WriteLine(a); //Console.WriteLine(s); }