IJ1939TpChannel Interface¶
One J1939-TP channel bound to a single J1939 source address on one physical bus. It carries both TP.BAM (broadcast) and TP.CM (connection-mode) sessions in parallel, each in its own actor-owned state (SRS FR-TP-034/035) so multiple concurrent peers do not interfere.
Implements IDisposable
Remarks¶
Threading model (SRS FR-TP-034 = FR-TP-016/017 applied to J1939-TP): every session's state (sequence numbers, remaining bytes, block counters, T1..T4/Tr/Th deadlines) lives inside a single IProtocolActor mailbox and is only ever read/written on the actor's loop thread. Callers may invoke SendBamAsync(uint, ReadOnlyMemory<byte>, CancellationToken) or SendCmAsync(uint, byte, ReadOnlyMemory<byte>, CancellationToken) concurrently from any thread; the channel serializes them per peer so one PDU at a time is on the wire per session identity (source, destination, PGN).
Received PDUs are delivered both as an event (DatagramReceived) and via ReceiveAsync(CancellationToken) / ReceiveAllAsync(CancellationToken). Both surfaces share the same bounded buffer; if it fills, the oldest datagram is dropped so the RX pipeline never stalls the actor.
IDisposable.Dispose is thread-safe and idempotent (FR-RAW-021).
Properties¶
IJ1939TpChannel.Options Property¶
Options captured at construction time (immutable).
Property Value¶
IJ1939TpChannel.SourceAddress Property¶
The J1939 source address this channel identifies itself as on the bus.
Property Value¶
Methods¶
IJ1939TpChannel.ReceiveAllAsync(CancellationToken) Method¶
Enumerates every reassembled inbound datagram until the channel is disposed. Reassembly aborts surface as J1939TpAbortException on the enumerating waiter (same semantics as ReceiveAsync(CancellationToken)).
System.Collections.Generic.IAsyncEnumerable<CanKit.Pro.J1939Tp.J1939TpDatagram> ReceiveAllAsync(System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters¶
cancellationToken CancellationToken
Returns¶
IAsyncEnumerable<J1939TpDatagram>
IJ1939TpChannel.ReceiveAsync(CancellationToken) Method¶
Awaits the next fully reassembled inbound TP.BAM or TP.CM datagram, or faults with J1939TpAbortException when an in-flight reassembly is aborted (bad TP.DT sequence number, T1/Tr timeout, or peer Connection Abort). One waiter consumes the fault; subsequent receives remain available for later successful datagrams.
System.Threading.Tasks.Task<CanKit.Pro.J1939Tp.J1939TpDatagram> ReceiveAsync(System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters¶
cancellationToken CancellationToken
Returns¶
IJ1939TpChannel.SendBamAsync(uint, ReadOnlyMemory<byte>, CancellationToken) Method¶
Broadcasts payload as one TP.BAM session (FR-TP-030). The task completes when the last TP.DT frame is TX-confirmed by the driver. Payload length must be in [9, 1785] bytes (J1939-21 §5.10.1: TP is only used above 8 bytes).
System.Threading.Tasks.Task SendBamAsync(uint pgn, System.ReadOnlyMemory<byte> payload, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters¶
pgn UInt32
Data PGN of the multi-packet message being announced.
payload ReadOnlyMemory<Byte>
User payload; 9..1785 bytes.
cancellationToken CancellationToken
Standard .NET cancellation of the returned task.
Returns¶
IJ1939TpChannel.SendCmAsync(uint, byte, ReadOnlyMemory<byte>, CancellationToken) Method¶
Sends payload as one TP.CM session to destinationAddress (FR-TP-031). The task completes when the peer's EndOfMsgAck arrives (or faults with J1939TpAbortException on abort/timeout).
System.Threading.Tasks.Task SendCmAsync(uint pgn, byte destinationAddress, System.ReadOnlyMemory<byte> payload, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters¶
pgn UInt32
Data PGN of the multi-packet message being sent.
destinationAddress Byte
Target node's source address (must not be 0xFF).
payload ReadOnlyMemory<Byte>
User payload; 9..1785 bytes.
cancellationToken CancellationToken
Standard .NET cancellation of the returned task.
Returns¶
Events¶
IJ1939TpChannel.BackgroundExceptionOccurred Event¶
Raised when a background failure (session timeout on an idle receiver, event-handler exception, subscription failure, actor loop exception) must be surfaced to the application. Failures tied to a specific SendBamAsync(uint, ReadOnlyMemory<byte>, CancellationToken) / SendCmAsync(uint, byte, ReadOnlyMemory<byte>, CancellationToken) call are reported via that call's returned task.
Event Type¶
IJ1939TpChannel.DatagramReceived Event¶
Raised on the actor's loop thread every time a full PDU is reassembled. The same datagram is also enqueued for ReceiveAsync(CancellationToken) / ReceiveAllAsync(CancellationToken). Handlers must be lightweight and non-throwing; a throwing handler is caught and surfaced via BackgroundExceptionOccurred.