CCP

CCP 2.1 session and memory transfer commands on Classical CAN. Construct CCPClient(adapter, CCPConfig(tx_id=0x6EC, rx_id=0x6ED)), then connect(station_address) directly to a known ECU. The Rust implementation handles fixed eight-byte CRO/CRM framing, echoed command counters, serialization and deadlines. Standard and extended CAN identifiers are supported. CCPConfig combines the CRO/DTO identifiers with bus (default zero), timeout in seconds (default one) and ECU memory address byte order.

Set byte_order="little" or "big" in CCPConfig to match the ECU’s memory address encoding. CCP does not negotiate byte order. Station addresses in CONNECT and DISCONNECT are always little endian.

Each method sends one command. set_mta() sets MTA0 (or MTA1), upload() reads 1–5 bytes and download() writes 1–5 bytes, post-incrementing MTA0. download6() writes exactly six bytes. Both download methods return the ECU’s post-incremented MTA0 address and extension. short_upload() reads 1–5 bytes at an explicit address without changing MTA0. Sizes count bytes. Callers implement transfer loops and seed/key algorithms. Optional commands remain subject to ECU support and resource protection.

get_ccp_version() exchanges versions; exchange_id() reports resource masks and sets MTA0 to the identification, retrieved using upload(). get_seed() accepts one CCP resource (CAL=1, DAQ=2, PGM=0x40), and unlock() sends up to six key bytes.

Commands are never retried automatically. Busy responses wait for ACK within the original deadline. After active cancellation, timeout, malformed response or an interrupting ECU event, reconnect and re-establish MTA and privileges. The interrupted command may already have executed. Negative responses raise CCPResponseError with raw command, code, and data attributes. Closing waits for the active exchange and releases the client’s adapter and receive subscription. The shared adapter remains open; closing it invalidates the client. disconnect() separately ends the ECU session.

This client implements CCP 2.1 sections 7, 12.1–12.9, 12.15 and 12.28.

Rust-backed CCP 2.1 memory transfers on Classical CAN.

Wire encoding follows CCP 2.1 sections 7 and 12.1–12.9, 12.15, 12.28. Configure the ECU’s memory address byte order before connecting.

class automotive.protocols.ccp.CCPClient(adapter: CanAdapter, config: CCPConfig)[source]

Serialized CCP session with one command per method call.

Connect directly to a known station. UPLOAD/DNLOAD operate on MTA0; SHORT_UP leaves MTA0 unchanged. Sizes count bytes. Callers implement transfer loops and seed/key algorithms. Optional commands require ECU support and sufficient access privileges.

After an active command is cancelled, times out, or receives a malformed response, connect() again and re-establish MTA and privileges. The previous command may have executed. Negative responses raise CCPResponseError with command, code, and data. The client retains the adapter and subscribes before the first command. Closing waits for the active command and releases the subscription without closing the shared adapter; disconnect() separately ends the ECU session. Closing the adapter invalidates the client.

async connect(station_address: int = 0) → None[source]

CONNECT to a known station; station addresses are always little endian.

async disconnect(temporary: bool = False) → None[source]

Disconnect temporarily or terminate the calibration session (default).

async get_ccp_version(major: int = 2, minor: int = 1) → ProtocolVersion[source]

Exchange protocol versions before EXCHANGE_ID.

async exchange_id(master_id: bytes | bytearray | memoryview = b'') → Identification[source]

Send up to six optional master ID bytes; set MTA0 to the ECU ID.

async get_seed(resource: Resource | int) → Seed[source]

Request seed bytes for one resource: CAL=1, DAQ=2 or PGM=0x40.

async unlock(key: bytes | bytearray | memoryview) → int[source]

Send 1–6 key bytes and return the current privilege resource mask.

async set_mta(address: int, address_extension: int = 0, mta: int = 0) → None[source]

Set MTA0 for memory transfers, or MTA1 for ECU memory moves.

async upload(size: int) → bytes[source]

Read 1–5 bytes at MTA0 and post-increment MTA0 by size.

async short_upload(address: int, size: int, address_extension: int = 0) → bytes[source]

SHORT_UP reads 1–5 bytes at address without changing MTA0.

async download(data: bytes | bytearray | memoryview) → MemoryAddress[source]

DNLOAD writes 1–5 bytes at MTA0; return its post-incremented address.

async download6(data: bytes | bytearray | memoryview) → MemoryAddress[source]

Optional DNLOAD_6 writes exactly six bytes at MTA0.

class automotive.protocols.ccp.CCPConfig(*, tx_id: int | Identifier, rx_id: int | Identifier, bus: int = 0, timeout: float = 1.0, byte_order: Literal['little', 'big'] = 'little')[source]

CRO/DTO identifiers, adapter bus, deadline and ECU address byte order.

Transmit and receive IDs must differ and may be standard or extended. The bus defaults to zero and the command deadline to one second. CCP does not negotiate byte order; use the ECU description or a known working trace. Station addresses are always little endian.

tx_id: int | Identifier
rx_id: int | Identifier
bus: int
timeout: float
byte_order: Literal['little', 'big']
class automotive.protocols.ccp.Command(*values)

Named Command wire values from Rust.

Members are integers and may be passed wherever a raw code is accepted. Unknown codes remain raw integers in protocol results. Iteration visits only known values; constructing this enum with an unknown value raises ValueError.

CONNECT = 0x01
SET_MTA = 0x02
DOWNLOAD = 0x03
UPLOAD = 0x04
DISCONNECT = 0x07
SHORT_UPLOAD = 0x0F
GET_SEED = 0x12
UNLOCK = 0x13
EXCHANGE_ID = 0x17
GET_CCP_VERSION = 0x1B
DOWNLOAD6 = 0x23
class automotive.protocols.ccp.ErrorCode(*values)

Named ErrorCode wire values from Rust.

Members are integers and may be passed wherever a raw code is accepted. Unknown codes remain raw integers in protocol results. Iteration visits only known values; constructing this enum with an unknown value raises ValueError.

ACKNOWLEDGE = 0x00
DAQ_OVERLOAD = 0x01
COMMAND_BUSY = 0x10
DAQ_BUSY = 0x11
INTERNAL_TIMEOUT = 0x12
KEY_REQUEST = 0x18
SESSION_STATUS_REQUEST = 0x19
COLD_START_REQUEST = 0x20
CALIBRATION_DATA_INIT_REQUEST = 0x21
DAQ_LIST_INIT_REQUEST = 0x22
CODE_UPDATE_REQUEST = 0x23
COMMAND_UNKNOWN = 0x30
COMMAND_SYNTAX = 0x31
OUT_OF_RANGE = 0x32
ACCESS_DENIED = 0x33
OVERLOAD = 0x34
ACCESS_LOCKED = 0x35
RESOURCE_NOT_AVAILABLE = 0x36
class automotive.protocols.ccp.Identification(length: int, data_type: int, resource_availability: int, resource_protection: int)[source]

EXCHANGE_ID result; UPLOAD reads the identification at MTA0.

length: int
data_type: int
resource_availability: int
resource_protection: int
class automotive.protocols.ccp.MemoryAddress(address: int, address_extension: int)[source]

Post-incremented MTA0 returned by DNLOAD or DNLOAD_6.

address: int
address_extension: int
class automotive.protocols.ccp.ProtocolVersion(major: int, minor: int)[source]

ECU protocol version returned by GET_CCP_VERSION.

major: int
minor: int
class automotive.protocols.ccp.Resource(*values)

Named Resource wire values from Rust.

Members are integers and may be passed wherever a raw code is accepted. Flags may be combined; unknown bits are preserved.

CAL = 1
DAQ = 2
PGM = 64
class automotive.protocols.ccp.Seed(protected: bool, data: bytes)[source]

Four seed bytes; protected=False means UNLOCK is unnecessary.

protected: bool
data: bytes

Synchronous API

Use identical configuration, values and exceptions through ordinary methods under automotive.sync.protocols.ccp.

Blocking CCP API forwarding to the Rust-backed asynchronous client.

class automotive.sync.protocols.ccp.CCPClient(adapter: CanAdapter, config: CCPConfig)[source]

Synchronous CCP; configuration, results and exceptions match the async API.

After timeout, cancellation or a malformed response, reconnect and re-establish MTA and access privileges before continuing. The client retains the adapter and subscribes before the first command. Closing waits for the active command and releases the subscription without closing the shared adapter; disconnect() separately ends the ECU session. Closing the adapter invalidates the client.

property config: CCPConfig

CAN identifiers, bus, deadline and ECU memory address byte order.

connect(station_address: int = 0) → None[source]

CONNECT to a known station; station addresses are always little endian.

disconnect(temporary: bool = False) → None[source]

Disconnect temporarily or terminate the calibration session (default).

get_ccp_version(major: int = 2, minor: int = 1) → ProtocolVersion[source]

Exchange protocol versions before EXCHANGE_ID.

exchange_id(master_id: bytes | bytearray | memoryview = b'') → Identification[source]

Send up to six optional master ID bytes; set MTA0 to the ECU ID.

get_seed(resource: Resource | int) → Seed[source]

Request seed bytes for one resource: CAL=1, DAQ=2 or PGM=0x40.

unlock(key: bytes | bytearray | memoryview) → int[source]

Send 1–6 key bytes and return the current privilege resource mask.

set_mta(address: int, address_extension: int = 0, mta: int = 0) → None[source]

Set MTA0 for memory transfers, or MTA1 for ECU memory moves.

upload(size: int) → bytes[source]

Read 1–5 bytes at MTA0 and post-increment MTA0 by size.

short_upload(address: int, size: int, address_extension: int = 0) → bytes[source]

SHORT_UP reads 1–5 bytes at address without changing MTA0.

download(data: bytes | bytearray | memoryview) → MemoryAddress[source]

DNLOAD writes 1–5 bytes at MTA0; return its post-incremented address.

download6(data: bytes | bytearray | memoryview) → MemoryAddress[source]

Optional DNLOAD_6 writes exactly six bytes at MTA0.

class automotive.sync.protocols.ccp.CCPConfig(*, tx_id: int | Identifier, rx_id: int | Identifier, bus: int = 0, timeout: float = 1.0, byte_order: Literal['little', 'big'] = 'little')[source]

CRO/DTO identifiers, adapter bus, deadline and ECU address byte order.

Transmit and receive IDs must differ and may be standard or extended. The bus defaults to zero and the command deadline to one second. CCP does not negotiate byte order; use the ECU description or a known working trace. Station addresses are always little endian.