private static void DumpEeprom( IKW1281Dialog kwp1281, ushort startAddr, ushort length, byte maxReadLength, string fileName) { bool succeeded = true; using (var fs = File.Create(fileName, maxReadLength, FileOptions.WriteThrough)) { for (uint addr = startAddr; addr < (startAddr + length); addr += maxReadLength) { var readLength = (byte)Math.Min(startAddr + length - addr, maxReadLength); var blockBytes = kwp1281.ReadEeprom((ushort)addr, (byte)readLength); if (blockBytes == null) { blockBytes = Enumerable.Repeat((byte)0, readLength).ToList(); succeeded = false; } fs.Write(blockBytes.ToArray(), 0, blockBytes.Count); fs.Flush(); } } if (!succeeded) { Logger.WriteLine(); Logger.WriteLine("**********************************************************************"); Logger.WriteLine("*** Warning: Some bytes could not be read and were replaced with 0 ***"); Logger.WriteLine("**********************************************************************"); Logger.WriteLine(); } }
private void ReadEeprom(IKW1281Dialog kwp1281, uint address) { UnlockControllerForEepromReadWrite(kwp1281); var blockBytes = kwp1281.ReadEeprom((ushort)address, 1); if (blockBytes == null) { Logger.WriteLine("EEPROM read failed"); } else { var value = blockBytes[0]; Logger.WriteLine( $"Address {address} (${address:X4}): Value {value} (${value:X2})"); } }
private void MapCcmEeprom(IKW1281Dialog kwp1281) { kwp1281.Login(19283, 222); var bytes = new List <byte>(); const byte blockSize = 1; for (int addr = 0; addr <= 65535; addr += blockSize) { var blockBytes = kwp1281.ReadEeprom((ushort)addr, blockSize); blockBytes = Enumerable.Repeat( blockBytes == null ? (byte)0 : (byte)0xFF, blockSize).ToList(); bytes.AddRange(blockBytes); } var dumpFileName = _filename ?? "ccm_eeprom_map.bin"; Logger.WriteLine($"Saving EEPROM map to {dumpFileName}"); File.WriteAllBytes(dumpFileName, bytes.ToArray()); }
// End top-level commands private void MapClusterEeprom(IKW1281Dialog kwp1281) { // Unlock partial EEPROM read _ = kwp1281.SendCustom(new List <byte> { 0x9D, 0x39, 0x34, 0x34, 0x40 }); var bytes = new List <byte>(); const byte blockSize = 1; for (ushort addr = 0; addr < 2048; addr += blockSize) { var blockBytes = kwp1281.ReadEeprom(addr, blockSize); blockBytes = Enumerable.Repeat( blockBytes == null ? (byte)0 : (byte)0xFF, blockSize).ToList(); bytes.AddRange(blockBytes); } var dumpFileName = _filename ?? "eeprom_map.bin"; Logger.WriteLine($"Saving EEPROM map to {dumpFileName}"); File.WriteAllBytes(dumpFileName, bytes.ToArray()); }