private static bool WriteMarelliBlockAndReadAck(IKwpCommon kwpCommon, byte[] data) { var count = (ushort)(data.Length + 2); // Count includes 2-byte checksum var countH = (byte)(count / 256); var countL = (byte)(count % 256); kwpCommon.WriteByte(countH); kwpCommon.WriteByte(countL); var sum = (ushort)(countH + countL); foreach (var b in data) { kwpCommon.WriteByte(b); sum += b; } kwpCommon.WriteByte((byte)(sum / 256)); kwpCommon.WriteByte((byte)(sum % 256)); var expectedAck = new byte[] { 0x03, 0x09, 0x00, 0x0C }; Logger.WriteLine("Receiving ACK"); var ack = new List <byte>(); for (int i = 0; i < 4; i++) { var b = kwpCommon.ReadByte(); ack.Add(b); } if (!ack.SequenceEqual(expectedAck)) { Logger.WriteLine($"Expected ACK but received {Utils.Dump(ack)}"); return(false); } return(true); }
public Edc15VM(IKwpCommon kwpCommon, int controllerAddress) { _kwpCommon = kwpCommon; _controllerAddress = controllerAddress; }