/// <summary> /// Create an ECU identifier request packet /// </summary> public static SsmPacket CreateEcuIdentifierRequest() { SsmPacket packet = new SsmPacket(); packet.SetHeader(SsmDirection.ToEcu, SsmCommand.EcuInitRequest); packet.SetLengthByte(); packet.AppendChecksum(); return(packet); }
/// <summary> /// Create a block-read response packet /// </summary> public static SsmPacket CreateBlockReadResponse(byte[] payload) { SsmPacket packet = new SsmPacket(); packet.SetHeader(SsmDirection.FromEcu, SsmCommand.ReadBlockResponse); packet.AppendPayload(payload); packet.SetLengthByte(); packet.AppendChecksum(); return(packet); }
/// <summary> /// Create a multiple-address-read response packet /// </summary> public static SsmPacket CreateMultipleReadResponse(IList <byte> values) { SsmPacket packet = new SsmPacket(); packet.SetHeader(SsmDirection.FromEcu, SsmCommand.ReadAddressesResponse); for (int i = 0; i < values.Count; i++) { packet.AppendByte(values[i]); } packet.SetLengthByte(); packet.AppendChecksum(); return(packet); }
/// <summary> /// Create a multiple-address-read request packet /// </summary> public static SsmPacket CreateMultipleReadRequest(IList <int> addresses) { SsmPacket packet = new SsmPacket(); packet.SetHeader(SsmDirection.ToEcu, SsmCommand.ReadAddressesRequest); for (int i = 0; i < addresses.Count; i++) { packet.AppendAddress(addresses[i]); } packet.SetLengthByte(); packet.AppendChecksum(); return(packet); }
/// <summary> /// Create an ECU request packet with an arbitrary command and payload. /// </summary> /// <remarks> /// For experimentation... /// </remarks> /// <param name="direction">Which direction the packet will be traveling.</param> /// <param name="command">Command byte.</param> /// <param name="payload">Payload.</param> /// <returns>SsmPacket built from the given parameters.</returns> public static SsmPacket CreateArbitrary( SsmDirection direction, SsmCommand command, byte[] payload) { SsmPacket packet = new SsmPacket(); packet.SetHeader(direction, command); packet.AppendPayload(payload); packet.SetLengthByte(); packet.AppendChecksum(); return(packet); }
/// <summary> /// Create a request packet for an arbitrary device with an arbitrary command and payload. /// </summary> /// <remarks> /// For experimentation... /// </remarks> /// <param name="device">Which device the packet will to go.</param> /// <param name="command">Command byte.</param> /// <param name="pad">If true, an extra byte will be added to the header.</param> /// <param name="payload">Payload.</param> /// <returns>SsmPacket built from the given parameters.</returns> public static SsmPacket CreateArbitrary( byte device, byte command, bool pad, byte[] payload) { SsmPacket packet = new SsmPacket(); packet.SetHeader(device, command, pad); packet.AppendPayload(payload); packet.SetLengthByte(); packet.AppendChecksum(); return(packet); }
/// <summary> /// Create a block-read request packet /// </summary> public static SsmPacket CreateBlockReadRequest(int address, int length) { if (length == int.MinValue) { throw new ArgumentOutOfRangeException("length"); } SsmPacket packet = new SsmPacket(); packet.SetHeader(SsmDirection.ToEcu, SsmCommand.ReadBlockRequest); packet.AppendAddress(address); packet.AppendByte((byte)(length - 1)); packet.SetLengthByte(); packet.AppendChecksum(); return(packet); }
/// <summary> /// Create an ECU identifier response packet /// </summary> public static SsmPacket CreateEcuIdentifierResponse() { SsmPacket packet = new SsmPacket(); packet.SetHeader(SsmDirection.FromEcu, SsmCommand.EcuInitResponse); // Remove header and checksum from sample packet data List <byte> payload = new List <byte>(SamplePacketData.EcuInitResponse); payload.RemoveRange(0, 5); payload.RemoveRange(payload.Count - 1, 1); packet.AppendPayload(payload.ToArray()); packet.SetLengthByte(); packet.AppendChecksum(); return(packet); }