/// <summary> /// Set the basic header bytes for a packet /// </summary> private void SetHeader(SsmDirection direction, SsmCommand command) { this.data.Add(0x80); if (direction == SsmDirection.ToEcu) { this.data.Add((byte)SsmDeviceType.SubaruEcu); this.data.Add((byte)SsmDeviceType.DiagnosticTool); } else { this.data.Add((byte)SsmDeviceType.DiagnosticTool); this.data.Add((byte)SsmDeviceType.SubaruEcu); } // placeholder for the length this.data.Add(0); this.data.Add((byte)command); // Padding byte required for read requests if (command == SsmCommand.ReadBlockRequest) { this.data.Add(0x00); } if (command == SsmCommand.ReadAddressesRequest) { this.data.Add(0x00); } }
/// <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); }