Trait canadensis::Node

source ·
pub trait Node {
    type Clock: Clock<Instant = Self::Instant>;
    type Instant: Instant;
    type Transport: Transport;
    type Transmitter: Transmitter<Self::Clock, Transport = Self::Transport>;
    type Receiver: Receiver<Self::Clock, Transport = Self::Transport>;

Show 20 methods // Required methods fn receive<H>( &mut self, handler: &mut H ) -> Result<(), <Self::Receiver as Receiver<Self::Clock>>::Error> where H: TransferHandler<Self::Instant, Self::Transport>; fn start_publishing<T>( &mut self, subject: SubjectId, timeout: <<<Self as Node>::Clock as Clock>::Instant as Instant>::Duration, priority: <Self::Transport as Transport>::Priority ) -> Result<PublishToken<T>, StartSendError<<Self::Transmitter as Transmitter<Self::Clock>>::Error>> where T: Message; fn stop_publishing<T>(&mut self, token: PublishToken<T>) where T: Message; fn publish<T>( &mut self, token: &PublishToken<T>, payload: &T ) -> Result<(), <Self::Transmitter as Transmitter<Self::Clock>>::Error> where T: Message + Serialize; fn publish_loopback<T>( &mut self, token: &PublishToken<T>, payload: &T ) -> Result<(), <Self::Transmitter as Transmitter<Self::Clock>>::Error> where T: Message + Serialize; fn start_sending_requests<T>( &mut self, service: ServiceId, receive_timeout: <<<Self as Node>::Clock as Clock>::Instant as Instant>::Duration, response_payload_size_max: usize, priority: <Self::Transport as Transport>::Priority ) -> Result<ServiceToken<T>, StartSendError<<Self::Receiver as Receiver<Self::Clock>>::Error>> where T: Request; fn stop_sending_requests<T>(&mut self, token: ServiceToken<T>) where T: Request; fn send_request<T>( &mut self, token: &ServiceToken<T>, payload: &T, destination: <Self::Transport as Transport>::NodeId ) -> Result<<Self::Transport as Transport>::TransferId, <Self::Transmitter as Transmitter<Self::Clock>>::Error> where T: Request + Serialize; fn send_request_loopback<T>( &mut self, token: &ServiceToken<T>, payload: &T, destination: <Self::Transport as Transport>::NodeId ) -> Result<<Self::Transport as Transport>::TransferId, <Self::Transmitter as Transmitter<Self::Clock>>::Error> where T: Request + Serialize; fn subscribe_message( &mut self, subject: SubjectId, payload_size_max: usize, timeout: <<<Self as Node>::Clock as Clock>::Instant as Instant>::Duration ) -> Result<(), <Self::Receiver as Receiver<Self::Clock>>::Error>; fn subscribe_request( &mut self, service: ServiceId, payload_size_max: usize, timeout: <<<Self as Node>::Clock as Clock>::Instant as Instant>::Duration ) -> Result<(), <Self::Receiver as Receiver<Self::Clock>>::Error>; fn send_response<T>( &mut self, token: ResponseToken<Self::Transport>, timeout: <<<Self as Node>::Clock as Clock>::Instant as Instant>::Duration, payload: &T ) -> Result<(), <Self::Transmitter as Transmitter<Self::Clock>>::Error> where T: Response + Serialize; fn flush( &mut self ) -> Result<(), <Self::Transmitter as Transmitter<Self::Clock>>::Error>; fn clock(&self) -> &Self::Clock; fn clock_mut(&mut self) -> &mut Self::Clock; fn transmitter(&self) -> &Self::Transmitter; fn transmitter_mut(&mut self) -> &mut Self::Transmitter; fn receiver(&self) -> &Self::Receiver; fn receiver_mut(&mut self) -> &mut Self::Receiver; fn node_id(&self) -> <Self::Transport as Transport>::NodeId;
}
Expand description

A Cyphal node

A node has a node ID (it is not anonymous), a clock, a queue of outgoing frames waiting to be sent, and information about the subjects and services it is using.

Required Associated Types§

source

type Clock: Clock<Instant = Self::Instant>

The clock that this node uses

source

type Instant: Instant

The instant that this node’s clock produces

source

type Transport: Transport

The transport that this node uses

source

type Transmitter: Transmitter<Self::Clock, Transport = Self::Transport>

The transmitter that this node uses

source

type Receiver: Receiver<Self::Clock, Transport = Self::Transport>

The receiver that this node uses

Required Methods§

source

fn receive<H>( &mut self, handler: &mut H ) -> Result<(), <Self::Receiver as Receiver<Self::Clock>>::Error>where H: TransferHandler<Self::Instant, Self::Transport>,

Receives any available incoming frames and attempts ot reassemble them into a transfer

If the frame completes a transfer, the transfer is passed to the provided handler.

This function returns an error if memory for the received transfer could not be allocated. Other types of errors, like an invalid frame format or an incorrect transfer CRC, may cause transfers to be lost but are not reported as errors here.

source

fn start_publishing<T>( &mut self, subject: SubjectId, timeout: <<<Self as Node>::Clock as Clock>::Instant as Instant>::Duration, priority: <Self::Transport as Transport>::Priority ) -> Result<PublishToken<T>, StartSendError<<Self::Transmitter as Transmitter<Self::Clock>>::Error>>where T: Message,

Starts publishing messages on subject

The returned PublishToken can be used with the publish function to send a message.

This function returns an error if memory for the publishing data could not be allocated, or if the subject ID is already in use.

source

fn stop_publishing<T>(&mut self, token: PublishToken<T>)where T: Message,

Stops publishing messages on a subject

source

fn publish<T>( &mut self, token: &PublishToken<T>, payload: &T ) -> Result<(), <Self::Transmitter as Transmitter<Self::Clock>>::Error>where T: Message + Serialize,

Publishes a message

A token can be created by calling start_publishing.

source

fn publish_loopback<T>( &mut self, token: &PublishToken<T>, payload: &T ) -> Result<(), <Self::Transmitter as Transmitter<Self::Clock>>::Error>where T: Message + Serialize,

Publishes a message with the loopback flag set to true

A token can be created by calling start_publishing.

source

fn start_sending_requests<T>( &mut self, service: ServiceId, receive_timeout: <<<Self as Node>::Clock as Clock>::Instant as Instant>::Duration, response_payload_size_max: usize, priority: <Self::Transport as Transport>::Priority ) -> Result<ServiceToken<T>, StartSendError<<Self::Receiver as Receiver<Self::Clock>>::Error>>where T: Request,

Sets up to send requests for a service

This also subscribes to the corresponding responses.

This function returns an error if memory could not be allocated, or if the subject ID is already in use.

source

fn stop_sending_requests<T>(&mut self, token: ServiceToken<T>)where T: Request,

Stops sending requests for a service

source

fn send_request<T>( &mut self, token: &ServiceToken<T>, payload: &T, destination: <Self::Transport as Transport>::NodeId ) -> Result<<Self::Transport as Transport>::TransferId, <Self::Transmitter as Transmitter<Self::Clock>>::Error>where T: Request + Serialize,

Sends a service request to another node

On success, this function returns the transfer ID of the request.

source

fn send_request_loopback<T>( &mut self, token: &ServiceToken<T>, payload: &T, destination: <Self::Transport as Transport>::NodeId ) -> Result<<Self::Transport as Transport>::TransferId, <Self::Transmitter as Transmitter<Self::Clock>>::Error>where T: Request + Serialize,

Sends a service request to another node, with the loopback flag set to true

On success, this function returns the transfer ID of the request.

source

fn subscribe_message( &mut self, subject: SubjectId, payload_size_max: usize, timeout: <<<Self as Node>::Clock as Clock>::Instant as Instant>::Duration ) -> Result<(), <Self::Receiver as Receiver<Self::Clock>>::Error>

Subscribes to messages on a topic

source

fn subscribe_request( &mut self, service: ServiceId, payload_size_max: usize, timeout: <<<Self as Node>::Clock as Clock>::Instant as Instant>::Duration ) -> Result<(), <Self::Receiver as Receiver<Self::Clock>>::Error>

Subscribes to requests for a service

source

fn send_response<T>( &mut self, token: ResponseToken<Self::Transport>, timeout: <<<Self as Node>::Clock as Clock>::Instant as Instant>::Duration, payload: &T ) -> Result<(), <Self::Transmitter as Transmitter<Self::Clock>>::Error>where T: Response + Serialize,

Responds to a service request

This function requires a response token to match this response to its corresponding request. The token is passed to a transfer handler along with a request, so that the handler can send a response.

The response has its loopback flag set to false.

source

fn flush( &mut self ) -> Result<(), <Self::Transmitter as Transmitter<Self::Clock>>::Error>

Attempts to flush all outgoing frames

source

fn clock(&self) -> &Self::Clock

Returns a reference to the enclosed clock

source

fn clock_mut(&mut self) -> &mut Self::Clock

Returns a mutable reference to the enclosed clock

source

fn transmitter(&self) -> &Self::Transmitter

Returns a reference to the transport transmitter

source

fn transmitter_mut(&mut self) -> &mut Self::Transmitter

Returns a mutable reference to the transport transmitter

source

fn receiver(&self) -> &Self::Receiver

Returns a reference to the transport receiver

source

fn receiver_mut(&mut self) -> &mut Self::Receiver

Returns a mutable reference to the transport receiver

source

fn node_id(&self) -> <Self::Transport as Transport>::NodeId

Returns the identifier of this node

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<C, T, U, N, TR, D, const P: usize, const R: usize> Node for CoreNode<C, T, U, TR, D, P, R>where C: Clock, N: Transport, T: Transmitter<C, Transport = N, Driver = D>, U: Receiver<C, Transport = N, Driver = D>, TR: TransferIdTracker<N>,

§

type Clock = C

§

type Instant = <C as Clock>::Instant

§

type Transport = N

§

type Transmitter = T

§

type Receiver = U

source§

impl<N> Node for BasicNode<N>where N: Node,

§

type Clock = <N as Node>::Clock

§

type Instant = <N as Node>::Instant

§

type Transport = <N as Node>::Transport

§

type Transmitter = <N as Node>::Transmitter

§

type Receiver = <N as Node>::Receiver