private static IList<HexRecord> GroupDataRecords(HexRecord[] records) { var dataRecords = new List<HexRecord>(); uint upperLoadBaseAddress = 0; foreach (HexRecord entry in records) { // Set the upper part of the address if (entry.RecordType == RecordType.ExtendedLinearAddr) upperLoadBaseAddress = entry.Address; if (entry.RecordType != RecordType.Data) continue; // Calculate the full entry addres uint address = upperLoadBaseAddress + entry.Address; // Add to the list dataRecords.Add(new HexRecord { Address = address, Data = entry.Data, RecordType = RecordType.Data }); } return dataRecords; }
public static HexRecord FromString(string str) { if (!ValidateCommand(str)) return null; var record = new HexRecord(); // Get record length (RECLEN) byte length = Convert.ToByte(str.Substring(1, 2), 16); // Get data address (LOAD OFFSET) record.Address = Convert.ToUInt16(str.Substring(3, 4), 16); // Get type (RECTYPE) record.RecordType = (RecordType)Convert.ToByte(str.Substring(7, 2), 16); if (record.RecordType != RecordType.Data && record.RecordType != RecordType.Eof && record.RecordType != RecordType.ExtendedLinearAddr) throw new NotSupportedException(); // Get data record.Data = new byte[length]; for (int i = 0; i < length; i++) record.Data[i] = Convert.ToByte(str.Substring(9 + i * 2, 2), 16); // If it's extended linear address, update address if (record.RecordType == RecordType.ExtendedLinearAddr) record.Address = (uint)((record.Data[0] << 24) | (record.Data[1] << 16)); return record; }
public Hex(HexRecord[] records) { this.records = records; this.dataRecords = HexAdapter.AdaptCode(records); }
void SendDataRecord(HexRecord record) { // Sends address socket.Write(record.Address); // Sends data length socket.Write((ushort)record.Data.Length); // Sends data socket.Write(record.Data); }
public static IList<HexRecord> AdaptCode(HexRecord[] records) { var dataRecords = GroupDataRecords(records); var normalized = NormalizeAddress(dataRecords); return normalized; }