pycyphal.transport.loopback package

Module contents

class pycyphal.transport.loopback.LoopbackTransport(local_node_id: int | None, *, allow_anonymous_transfers: bool = True, loop: AbstractEventLoop | None = None)[source]

Bases: Transport

The loopback transport is intended for basic testing and API usage demonstrations. It works by short-circuiting input and output sessions together as if there was an underlying network.

It is not possible to exchange data between different nodes using this transport. The only valid usage is sending and receiving same data on the same node.

__init__(local_node_id: int | None, *, allow_anonymous_transfers: bool = True, loop: AbstractEventLoop | None = None)[source]
property protocol_parameters: ProtocolParameters[source]
property local_node_id: int | None[source]
property spoof_result: bool | Exception[source]

Test rigging. If True, spoof() will always succeed (this is the default). If False, it will always time out. If Exception, it will be raised.

property send_delay: float[source]

Test rigging. If positive, this delay will be inserted for each sent transfer. If after the delay the transfer deadline is in the past, it is assumed to have timed out. Zero by default (no delay is inserted, deadline not checked).

close() None[source]
get_input_session(specifier: InputSessionSpecifier, payload_metadata: PayloadMetadata) LoopbackInputSession[source]
get_output_session(specifier: OutputSessionSpecifier, payload_metadata: PayloadMetadata) LoopbackOutputSession[source]
sample_statistics() pycyphal.transport.loopback.LoopbackTransportStatistics[source]
property input_sessions: Sequence[LoopbackInputSession][source]
property output_sessions: Sequence[LoopbackOutputSession][source]
begin_capture(handler: Callable[[Capture], None]) None[source]
property capture_active: bool[source]
static make_tracer() LoopbackTracer[source]

See LoopbackTracer.

async spoof(transfer: AlienTransfer, monotonic_deadline: float) bool[source]

Spoofed transfers can be observed using begin_capture(). Also see spoof_result.

property capture_handlers: Sequence[Callable[[Capture], None]][source]
class pycyphal.transport.loopback.LoopbackInputSession(specifier: InputSessionSpecifier, payload_metadata: PayloadMetadata, closer: Callable[[], None])[source]

Bases: InputSession

DEFAULT_TRANSFER_ID_TIMEOUT = 2
__init__(specifier: InputSessionSpecifier, payload_metadata: PayloadMetadata, closer: Callable[[], None])[source]
async receive(monotonic_deadline: float) TransferFrom | None[source]
async push(transfer: TransferFrom) None[source]

Inserts a transfer into the receive queue of this loopback session.

property transfer_id_timeout: float[source]
property specifier: InputSessionSpecifier[source]
property payload_metadata: PayloadMetadata[source]
sample_statistics() SessionStatistics[source]
close() None[source]
class pycyphal.transport.loopback.LoopbackOutputSession(specifier: OutputSessionSpecifier, payload_metadata: PayloadMetadata, closer: Callable[[], None], router: Callable[[Transfer, float], Awaitable[bool]])[source]

Bases: OutputSession

__init__(specifier: OutputSessionSpecifier, payload_metadata: PayloadMetadata, closer: Callable[[], None], router: Callable[[Transfer, float], Awaitable[bool]])[source]
enable_feedback(handler: Callable[[Feedback], None]) None[source]
disable_feedback() None[source]
async send(transfer: Transfer, monotonic_deadline: float) bool[source]
property specifier: OutputSessionSpecifier[source]
property payload_metadata: PayloadMetadata[source]
sample_statistics() SessionStatistics[source]
close() None[source]
property exception: Exception | None[source]

This is a test rigging. Use this property to configure an exception object that will be raised when send() is invoked. Set None to remove the injected exception (None is the default value). Useful for testing error handling logic.

property delay: float[source]
property should_timeout: bool[source]
class pycyphal.transport.loopback.LoopbackFeedback(transfer_timestamp: Timestamp)[source]

Bases: Feedback

__init__(transfer_timestamp: Timestamp)[source]
property original_transfer_timestamp: Timestamp[source]
property first_frame_transmission_timestamp: Timestamp[source]
class pycyphal.transport.loopback.LoopbackCapture(timestamp: Timestamp, transfer: AlienTransfer)[source]

Bases: Capture

Since the loopback transport is not really a transport, its capture events contain entire transfers.

transfer: AlienTransfer
static get_transport_type() Type[LoopbackTransport][source]
__delattr__(name)[source]
__eq__(other)[source]
__hash__()[source]
__init__(timestamp: Timestamp, transfer: AlienTransfer) None[source]
__match_args__ = ('timestamp', 'transfer')
__repr__()[source]
__setattr__(name, value)[source]
class pycyphal.transport.loopback.LoopbackTracer[source]

Bases: Tracer

Since loopback transport does not have frames to trace, this tracer simply returns the transfer from the capture object.

update(cap: Capture) Trace | None[source]