### Canadensis Library Setup Source: https://docs.rs/canadensis/latest/src/canadensis/lib.rs.html This snippet shows the basic setup for the canadensis library, including necessary crate imports and module re-exports. It defines the core modules for Cyphal functionality. ```rust #![no_std] #![deny(missing_docs)] //! //! # Canadensis: An implementation of Cyphal //! //! This library (`canadensis`) provides all the basic Cyphal functionality, with some re-exports //! from other canadensis crates. //! extern crate alloc; extern crate fallible_collections; extern crate heapless; extern crate canadensis_core; extern crate canadensis_encoding; // Re-exports from other crates pub mod core { //! Basic Cyphal types pub use canadensis_core::*; } pub mod encoding { //! Data type serialization and deserialization pub use canadensis_encoding::*; } pub use canadensis_core::nb; pub mod anonymous; pub mod node; mod publisher; pub mod register; pub mod requester; mod serialize; pub mod service; use ::core::fmt::{Debug, Formatter}; use ::core::marker::PhantomData; use alloc::vec::Vec; use canadensis_core::{OutOfMemoryError, ServiceSubscribeError}; use crate::core::transport::Transport; use canadensis_core::time::{Clock, MicrosecondDuration32}; use canadensis_core::transfer::*; use canadensis_core::transport::{Receiver, Transmitter}; use canadensis_core::{ServiceId, SubjectId}; use canadensis_encoding::{Message, Request, Response, Serialize}; ``` -------------------------------- ### Node::start_publishing Source: https://docs.rs/canadensis/latest/canadensis/node/struct.CoreNode.html Starts publishing messages on a specified subject with a given timeout and priority. ```APIDOC ## Node::start_publishing ### Description Starts publishing messages on a subject. ### Signature ```rust fn start_publishing( &mut self, subject: SubjectId, timeout: MicrosecondDuration32, priority: N::Priority, ) -> Result<(), StartSendError> ``` ### Parameters * `subject` (SubjectId): The subject ID on which to start publishing. * `timeout` (MicrosecondDuration32): The timeout for publishing. * `priority` (N::Priority): The priority for publishing. ``` -------------------------------- ### Create a new Crc16CcittFalse calculator Source: https://docs.rs/canadensis/latest/canadensis/core/crc/struct.Crc16CcittFalse.html Initializes a new instance of the Crc16CcittFalse calculator. This is the starting point for any CRC computation. ```rust pub fn new() -> Crc16CcittFalse ``` -------------------------------- ### Start Publishing Source: https://docs.rs/canadensis/latest/src/canadensis/node/basic.rs.html Initiates the publishing of data to a specified subject with a given timeout and priority. Part of the Node trait. ```APIDOC ## start_publishing ### Description Initiates the publishing of data to a specified subject with a given timeout and priority. ### Method `start_publishing` ### Parameters - `subject`: `SubjectId` - The identifier of the subject to publish to. - `timeout`: `MicrosecondDuration32` - The timeout duration for publishing. - `priority`: `::Priority` - The priority for publishing. ### Return Value - `Result<(), StartSendError<>::Error>>` - Ok if publishing is started successfully, or an error if it fails. ``` -------------------------------- ### fn publish Source: https://docs.rs/canadensis/latest/canadensis/trait.Node.html Publishes a message on a subject. Publishing needs to be started by calling `start_publishing`. ```APIDOC ## fn publish( &mut self, subject: SubjectId, payload: &T, ) ### Description Publishes a message payload on the specified subject. Ensure `start_publishing` has been called for this subject prior to using this method. ### Parameters * `subject`: The identifier of the subject to publish the message to. * `payload`: A reference to the message payload, which must implement `Message` and `Serialize`. ### Returns * `Result<(), PublishError<>::Error>>`: Ok if the message was published successfully, or an error if publishing failed. ``` -------------------------------- ### Start Publishing on BasicNode Source: https://docs.rs/canadensis/latest/canadensis/node/struct.BasicNode.html Initiates the process of publishing messages on a specified subject with a given priority and timeout. Returns a `StartSendError` if the operation fails. ```rust fn start_publishing( &mut self, subject: SubjectId, timeout: MicrosecondDuration32, priority: ::Priority, ) -> Result<(), StartSendError<>::Error>> ``` -------------------------------- ### Create a New Crc32c Calculator Source: https://docs.rs/canadensis/latest/canadensis/core/crc/struct.Crc32c.html Instantiates a new Crc32c calculator. This is the starting point for any CRC-32C computation. ```rust pub fn new() -> Crc32c ``` -------------------------------- ### Start Sending Requests Source: https://docs.rs/canadensis/latest/src/canadensis/node/basic.rs.html Initiates the process of sending requests for a given service, specifying timeouts and priorities. Part of the Node trait. ```APIDOC ## start_sending_requests ### Description Initiates the process of sending requests for a given service, specifying timeouts and priorities. ### Method `start_sending_requests` ### Parameters - `service`: `ServiceId` - The identifier of the service. - `receive_timeout`: `MicrosecondDuration32` - The timeout for receiving a response. - `response_payload_size_max`: `usize` - The maximum expected size of the response payload. - `priority`: `::Priority` - The priority for sending requests. ### Return Value - `Result, StartSendError<>::Error>>` - A `ServiceToken` if successful, or an error if the request initiation fails. ``` -------------------------------- ### PortListService::new Source: https://docs.rs/canadensis/latest/src/canadensis/service/port_list.rs.html Creates a new PortListService. It requires the node to have a NodeID and starts publishing the `uavcan.node.port.List` message with a 10-second interval. ```APIDOC ## PortListService::new ### Description Creates a new instance of `PortListService`. This function initializes the service by registering a publisher for the `uavcan.node.port.List` message with the provided node. It ensures the node is not anonymous and handles potential errors during the publishing setup. ### Parameters - `node` (&mut N): A mutable reference to the Node instance. ### Returns - `Result>`: Returns `Ok(Self)` on success, or a `NewError` variant if initialization fails (e.g., `OutOfMemory`, `Duplicate`, `Other`, `Anonymous`). ``` -------------------------------- ### fn publish_loopback Source: https://docs.rs/canadensis/latest/canadensis/trait.Node.html Publishes a message with the loopback flag set to true. Publishing needs to be started by calling `start_publishing`. ```APIDOC ## fn publish_loopback( &mut self, subject: SubjectId, payload: &T, ) ### Description Publishes a message payload on the specified subject with the loopback flag enabled. Ensure `start_publishing` has been called for this subject prior to using this method. ### Parameters * `subject`: The identifier of the subject to publish the message to. * `payload`: A reference to the message payload, which must implement `Message` and `Serialize`. ### Returns * `Result<(), PublishError<>::Error>>`: Ok if the message was published successfully, or an error if publishing failed. ``` -------------------------------- ### Start Publishing on Subject Source: https://docs.rs/canadensis/latest/canadensis/node/struct.CoreNode.html Initiates the process of publishing messages on a specified subject with a given timeout and priority. This prepares the node to send data on that subject. ```rust fn start_publishing( &mut self, subject: SubjectId, timeout: MicrosecondDuration32, priority: N::Priority, ) -> Result<(), StartSendError> ``` -------------------------------- ### PnpServerService::new Source: https://docs.rs/canadensis/latest/src/canadensis/service/pnp/server.rs.html Creates a new plug-and-play server. It subscribes to and starts publishing messages for Node ID Allocation Data versions 1.0 and 2.0. Panics if the message size exceeds the MTU or if the generic parameter C does not match the maximum NodeId value. ```APIDOC ## PnpServerService::new ### Description Creates a new plug-and-play server. It subscribes to and starts publishing messages for Node ID Allocation Data versions 1.0 and 2.0. Panics if the message size exceeds the MTU or if the generic parameter C does not match the maximum NodeId value. ### Method `new(node: &mut N) -> Result>` ### Parameters * `node`: A mutable reference to the node. ### Panics * This function will panic if the message size is larger than the MTU of the node's transmitter or if the `C` generic parameter is not equal to the maximum value of `Transport::NodeId`. ### Returns * `Ok(PnpServerService)` on success. * `Err(NewError)` if subscription or publishing fails. ``` -------------------------------- ### Create a new BasicNode Source: https://docs.rs/canadensis/latest/src/canadensis/node/basic.rs.html Initializes a BasicNode with the provided underlying node and node information. It subscribes to GetInfo requests and starts publishing the port list. Errors during subscription or publishing are mapped to NodeError. ```rust pub fn new( mut node: N, node_info: GetInfoResponse, ) -> Result< Self, NodeError< StartSendError<>::Error>, ServiceSubscribeError<>::Error>, >, > { // The MinimalNode takes care of heartbeats. // Do node info and port list here. node.subscribe_request(get_info_1_0::SERVICE, 0, milliseconds(1000)) .map_err(NodeError::Receiver)?; node.start_publishing( list_1_0::SUBJECT, milliseconds(1000), Priority::Optional.into(), ) .map_err(NodeError::Transmitter)?; let minimal = MinimalNode::new(node).map_err(NodeError::Transmitter)?; // Initialize the port list with the Heartbeat publisher, GetInfo responder, and List publisher let port_list = List { publishers: SubjectIDList::SparseList({ let mut published_topics = heapless::Vec::new(); published_topics .push(subject_id_1_0::SubjectID { value: heartbeat_1_0::SUBJECT.into(), }) .ok() .unwrap(); published_topics .push(subject_id_1_0::SubjectID { value: list_1_0::SUBJECT.into(), }) .ok() .unwrap(); published_topics }), subscribers: SubjectIDList::SparseList(heapless::Vec::new()), clients: ServiceIDList { mask: BitArray::new(512), }, servers: { let mut servers = BitArray::new(512); servers.set(get_info_1_0::SERVICE.into(), true); ServiceIDList { mask: servers } }, }; Ok(BasicNode { node: minimal, port_list, node_info, seconds_since_port_list_published: 0, }) } ``` -------------------------------- ### Create PnP Client Service Source: https://docs.rs/canadensis/latest/src/canadensis/service/pnp/client.rs.html Initializes a new PnP client service. Panics if the message size exceeds the node's MTU. Subscribes to and starts publishing allocation messages. ```rust pub fn new(node: &mut N, unique_id: [u8; 16]) -> Result> { debug_assert!( M::PAYLOAD_SIZE_MAX <= node.transmitter().mtu(), "Can't fit transfer into one frame" ); node.subscribe_message(M::SUBJECT, M::PAYLOAD_SIZE_MAX, milliseconds(1000)) .map_err(|err| NewError::Subscribe(err))?; node.start_publishing(M::SUBJECT, milliseconds(1000), Priority::Nominal.into()) .map_err(|err| match err { StartSendError::Memory(_) => NewError::OutOfMemory, StartSendError::Duplicate => NewError::Duplicate, StartSendError::Transport(err) => NewError::Publish(err), StartSendError::AnonymousRequest => unreachable!(), // we are publishing a message, not a request })?; Ok(Self { unique_id, _node: PhantomData, _message: PhantomData, }) } ``` -------------------------------- ### fn start_publishing Source: https://docs.rs/canadensis/latest/canadensis/trait.Node.html Starts publishing messages on a subject. This function returns an error if memory for the publishing data could not be allocated, or if the subject ID is already in use. ```APIDOC ## fn start_publishing( &mut self, subject: SubjectId, timeout: MicrosecondDuration32, priority: ::Priority, ) ### Description Starts publishing messages on a given subject with specified timeout and priority. ### Parameters * `subject`: The identifier of the subject to publish on. * `timeout`: The duration to wait for publishing to start. * `priority`: The priority level for publishing. ### Returns * `Result<(), StartSendError<>::Error>>`: Ok if publishing started successfully, or an error if memory allocation failed or the subject ID is already in use. ``` -------------------------------- ### Create HeartbeatService Source: https://docs.rs/canadensis/latest/src/canadensis/service/heartbeat.rs.html Initializes a new HeartbeatService and starts publishing heartbeat messages. Requires a mutable reference to the node and configures the initial heartbeat parameters. ```rust pub fn new( node: &mut N, ) -> Result>::Error>> { node.start_publishing(SUBJECT, milliseconds(1000), Priority::Nominal.into())?; let heatbeat = Heartbeat { uptime: 0, health: Health { value: Health::NOMINAL, }, mode: Mode { value: Mode::OPERATIONAL, }, vendor_specific_status_code: 0, }; Ok(Self { heartbeat: heatbeat, _node: PhantomData, }) } ``` -------------------------------- ### Start Publishing a Subject in Canadensis Node Source: https://docs.rs/canadensis/latest/src/canadensis/node/core.rs.html Initiates publishing for a given subject. Returns an error if the subject is already being published. ```rust fn start_publishing( &mut self, subject: SubjectId, timeout: MicrosecondDuration32, priority: N::Priority, ) -> Result<(), StartSendError> { if self.publishers.contains_key(&subject) { Err(StartSendError::Duplicate) } else { self.publishers .insert(subject, Publisher::new(timeout, priority)) .map(|_| ()) // Map the old value to unit .map_err(|_| StartSendError::Memory(OutOfMemoryError)) // Map insertion error to OutOfMemoryError } } } ``` -------------------------------- ### HeartbeatService::new Source: https://docs.rs/canadensis/latest/src/canadensis/service/heartbeat.rs.html Creates a new HeartbeatService instance. It starts publishing heartbeat messages on the specified subject with a 1-second interval. ```APIDOC ## HeartbeatService::new ### Description Creates a new HeartbeatService. This function initializes the service and begins publishing heartbeat messages at a regular interval. ### Signature ```rust pub fn new( node: &mut N, ) -> Result>::Error>> ``` ### Parameters * `node`: A mutable reference to the node that will be used for publishing messages. ``` -------------------------------- ### WriteCursor::new Source: https://docs.rs/canadensis/latest/canadensis/encoding/struct.WriteCursor.html Creates a new WriteCursor that starts writing at the beginning of the provided mutable byte slice. ```APIDOC ## WriteCursor::new ### Description Creates a cursor that will write starting at the beginning of the provided slice. ### Signature ```rust pub fn new(bytes: &'b mut [u8]) -> WriteCursor<'b> ``` ### Parameters * `bytes`: A mutable slice of bytes to write into. ``` -------------------------------- ### Create PortListService Source: https://docs.rs/canadensis/latest/src/canadensis/service/port_list.rs.html Initializes a new PortListService. It requires a node with a defined NodeID and starts publishing the port list message periodically. Errors can occur if the node is anonymous, out of memory, or if the subject is already in use. ```rust pub fn new(node: &mut N) -> Result> { if node.node_id().is_none() { return Err(NewError::Anonymous); } node.start_publishing(SUBJECT, milliseconds(10000), Priority::Optional.into()) .map_err(|err| match err { StartSendError::Memory(_) => NewError::OutOfMemory, StartSendError::Duplicate => NewError::Duplicate, StartSendError::Transport(err) => NewError::Other(err), StartSendError::AnonymousRequest => unreachable!(), // We are publishing a message so this should never happen })?; Ok(Self { _node: PhantomData }) } ``` -------------------------------- ### Start Sending Service Requests Source: https://docs.rs/canadensis/latest/canadensis/node/struct.CoreNode.html Configures the node to send requests for a specific service, including setting timeouts and priorities. This also automatically subscribes to the corresponding responses. ```rust fn start_sending_requests( &mut self, service: ServiceId, receive_timeout: MicrosecondDuration32, response_payload_size_max: usize, priority: N::Priority, ) -> Result, StartSendError> where M: Request, ``` -------------------------------- ### Create New PnpServerService Source: https://docs.rs/canadensis/latest/canadensis/service/pnp/server/struct.PnpServerService.html Creates a new plug-and-play server instance. Panics if the message size exceeds the MTU or if the generic parameter C is invalid. ```rust pub fn new(node: &mut N) -> Result> ``` -------------------------------- ### Get Type ID Source: https://docs.rs/canadensis/latest/canadensis/register/struct.RegisterHandler.html Gets the TypeId of the current type. This is a blanket implementation for any type T. ```rust fn type_id(&self) -> TypeId> ``` -------------------------------- ### MinimalNode::new Source: https://docs.rs/canadensis/latest/src/canadensis/node/minimal.rs.html Creates a new minimal node with default heartbeat settings. It initializes the node and starts publishing heartbeat messages. This function should be called during node initialization. ```APIDOC ## MinimalNode::new ### Description Creates a new minimal node with default heartbeat settings. It initializes the node and starts publishing heartbeat messages. This function should be called during node initialization. * `node`: The underlying node (this is usually a [`CoreNode`](crate::node::CoreNode)) ### Returns - `Result>::Error>>`: A new `MinimalNode` instance or an error if publishing fails. ``` -------------------------------- ### ReadCursor Initialization and Basic Operations Source: https://docs.rs/canadensis/latest/canadensis/encoding/struct.ReadCursor.html Demonstrates how to create a ReadCursor and perform basic byte and alignment operations. ```APIDOC ## ReadCursor A cursor over a byte slice for easy deserializing of Cyphal data types. Functions that read values will return zero when reading beyond the end of the bytes, in accordance with the implicit zero extension rule (specification section 3.7.1.5). ### `new(bytes: &'b [u8]) -> ReadCursor<'b>` Creates a cursor that will read starting at the beginning of the provided slice. ### `as_bytes(&self) -> Option<&'b [u8]>` If this cursor is aligned to a byte boundary, this function returns the slice of bytes that remain to be read. Caution: This function bypasses the normal mechanism for keeping track of which bytes have already been read. If you consume any of the returned bytes, you must call `advance_bytes()` so that they will not be read again alter. ### `advance_bytes(&mut self, byte_increment: usize)` Marks some bytes has having already been read. This function should only be used with `as_bytes()` when manually handling bytes. ### `align_to_8_bits(&mut self)` Skips up to 7 bits so that this cursor is aligned to 8 bits (one byte). ### `is_aligned_to_8_bits(&self) -> bool` Returns true if this cursor is aligned to a multiple of 8 bits. ``` -------------------------------- ### Start Sending Service Requests on BasicNode Source: https://docs.rs/canadensis/latest/canadensis/node/struct.BasicNode.html Configures the node to send requests for a specific service. This involves setting timeouts and response payload size limits. Returns a `ServiceToken` on success or a `StartSendError` on failure. ```rust fn start_sending_requests( &mut self, service: ServiceId, receive_timeout: MicrosecondDuration32, response_payload_size_max: usize, priority: ::Priority, ) -> Result, StartSendError<>::Error>> where T: Request, ``` -------------------------------- ### PnpClientService::new Source: https://docs.rs/canadensis/latest/src/canadensis/service/pnp/client.rs.html Creates a new plug-and-play client service. It initializes the service and subscribes to necessary messages, ensuring the message size does not exceed the transmitter's MTU. This function may panic if the message size is too large. ```APIDOC ## PnpClientService::new ### Description Creates a new plug-and-play client service. * `unique_id`: The unique ID of this node ### Panics This function will panic if the message size is larger than the MTU of the node's transmitter. ### Method ```rust pub fn new(node: &mut N, unique_id: [u8; 16]) -> Result> ``` ### Parameters - **node**: A mutable reference to the node. - **unique_id**: An array of 16 bytes representing the unique ID of the node. ### Returns A `Result` which is `Ok(Self)` on success or `Err(NewError)` on failure. ``` -------------------------------- ### SessionTracker Trait Source: https://docs.rs/canadensis/latest/canadensis/core/session/trait.SessionTracker.html Defines methods for tracking and managing sessions associated with nodes. It allows for getting, inserting, and removing sessions, as well as getting mutable references or inserting new sessions if they don't exist. ```APIDOC ## Trait SessionTracker Something that can keep track of receive sessions associated with other nodes This is some kind of map from node ID to session. ### Type Parameters * `N`: A node ID * `T`: A transfer ID * `D`: Additional transport-specific session data ### Required Methods #### fn get(&self, node: N) -> Option<&Session> Returns a reference to the session for the provided node, if one exists. #### fn get_mut(&mut self, node: N) -> Option<&mut Session> Returns a mutable reference to the session for the provided node, if one exists. #### fn get_mut_or_insert_with( &mut self, node: N, generator: F, ) -> Result<&mut Session, OutOfMemoryError> where N: Clone, F: FnOnce() -> Session, Returns a mutable reference to the session for the provided node. If no session exists, this function calls the provided function, inserts the result, and returns a mutable reference to it. #### fn insert( &mut self, node: N, session: Session, ) -> Result<(), OutOfMemoryError> Inserts a session. If another session with the same node already exists, it is removed. #### fn remove(&mut self, node: N) Removes a session for the provided node if one exists. If no matching session exists, this function has no effect. ``` -------------------------------- ### Get Node Reference Source: https://docs.rs/canadensis/latest/src/canadensis/node/basic.rs.html Returns an immutable reference to the enclosed node. ```APIDOC ## node ### Description Returns a reference to the enclosed node. ### Method `node` ### Return Value - `&N` - An immutable reference to the enclosed node. ``` -------------------------------- ### Version Initialization and Zeroing Source: https://docs.rs/canadensis/latest/canadensis/node/data_types/struct.Version.html Methods for creating new Version instances and initializing them with zeros. ```APIDOC ## fn zero(&mut self) Overwrites `self` with zeros. ### Parameters - **self** (&mut Self) - A mutable reference to the Version instance to be zeroed. ## fn new_zeroed() -> Self Creates an instance of `Self` from zeroed bytes. ### Returns - Self - A new Version instance initialized with zeros. ``` -------------------------------- ### start_sending_requests Source: https://docs.rs/canadensis/latest/src/canadensis/node/core.rs.html Sets up to send requests for a service and subscribes to the corresponding responses. ```APIDOC ## start_sending_requests ### Description Sets up to send requests for a service. This also subscribes to the corresponding responses. ### Method Signature `fn start_sending_requests(&mut self, service: ServiceId, receive_timeout: MicrosecondDuration32, response_payload_size_max: usize, priority: N::Priority) -> Result, StartSendError> where M: Request` ### Parameters - **service** (ServiceId) - The ID of the service to send requests to. - **receive_timeout** (MicrosecondDuration32) - The timeout for receiving responses. - **response_payload_size_max** (usize) - The maximum size of the response payload. - **priority** (N::Priority) - The priority of the requests. ### Returns - `Ok(ServiceToken)` on success, containing a token to manage the service. - `Err(StartSendError)` on failure, indicating issues like anonymous requests, duplicates, memory errors, or transport errors. ``` -------------------------------- ### Get Register Name Source: https://docs.rs/canadensis/latest/canadensis/register/basic/struct.SimpleRegister.html Returns the name of the register as a string slice. ```rust fn name(&self) -> &str ``` -------------------------------- ### Create New PnpClientService Source: https://docs.rs/canadensis/latest/canadensis/service/pnp/client/struct.PnpClientService.html Creates a new plug-and-play client instance. Panics if the message size exceeds the node's transmitter MTU. Requires a unique ID for the node. ```rust pub fn new(node: &mut N, unique_id: [u8; 16]) -> Result> ``` -------------------------------- ### Get Mutable Node Reference Source: https://docs.rs/canadensis/latest/src/canadensis/node/basic.rs.html Returns a mutable reference to the enclosed node. ```APIDOC ## node_mut ### Description Returns a mutable reference to the enclosed node. ### Method `node_mut` ### Return Value - `&mut N` - A mutable reference to the enclosed node. ``` -------------------------------- ### Create GetInfoService Source: https://docs.rs/canadensis/latest/src/canadensis/service/get_info.rs.html Creates a new GetInfo service and subscribes to the uavcan.node.GetInfo service. Requires a mutable node reference and GetInfoResponse data. The subscription has a timeout of 1000 milliseconds. ```rust pub fn new( node: &mut N, node_info: GetInfoResponse, ) -> Result>::Error>> { node.subscribe_request(SERVICE, 0, milliseconds(1000))?; Ok(Self { node_info, _node: PhantomData, }) } ``` -------------------------------- ### Get PnpServerService Handler Source: https://docs.rs/canadensis/latest/canadensis/service/pnp/server/struct.PnpServerService.html Returns a handler for the PnpServerService, allowing interaction with the server. ```rust pub fn handler(&mut self) -> PnpServerServiceHandler<'_, N, C> ``` -------------------------------- ### PnpClientService::new Source: https://docs.rs/canadensis/latest/canadensis/service/pnp/client/struct.PnpClientService.html Creates a new plug-and-play client instance. It requires a mutable reference to a node and a unique identifier for this node. Panics if the message size exceeds the transmitter's MTU. ```APIDOC ## pub fn new(node: &mut N, unique_id: [u8; 16]) -> Result> ### Description Creates a new plug-and-play client. ### Parameters #### Path Parameters - **node** (*&mut N*) - Required - A mutable reference to the node. - **unique_id** (*[u8; 16]*) - Required - The unique ID of this node. ### Panics This function will panic if the message size is larger than the MTU of the node’s transmitter. ``` -------------------------------- ### StartSendError Enum Source: https://docs.rs/canadensis/latest/canadensis/index.html Errors that may occur when starting to send messages or requests. ```APIDOC ## Enum: StartSendError ### Description Errors that may occur when starting to send messages or requests. ### Variants - `NodeNotReady`: Indicates that the node is not ready to send. - `InvalidServiceId`: Indicates an invalid service ID was provided. ``` -------------------------------- ### Get Minimal Node Reference Source: https://docs.rs/canadensis/latest/src/canadensis/node/basic.rs.html Returns an immutable reference to the enclosed minimal node. ```APIDOC ## minimal_node ### Description Returns a reference to the enclosed minimal node. ### Method `minimal_node` ### Return Value - `&MinimalNode` - An immutable reference to the enclosed minimal node. ``` -------------------------------- ### PnpServerService::new Source: https://docs.rs/canadensis/latest/canadensis/service/pnp/server/struct.PnpServerService.html Creates a new plug-and-play server. It may panic if the message size exceeds the node's MTU or if the generic parameter C is not equal to the maximum value of Transport::NodeId. ```APIDOC ## PnpServerService::new ### Description Creates a new plug-and-play server. ### Panics This function will panic if the message size is larger than the MTU of the node’s transmitter or if the `C` generic parameter is not equal to the maximum value of `Transport::NodeId`. ### Signature ```rust pub fn new(node: &mut N) -> Result> ``` ``` -------------------------------- ### BasicNode::new Source: https://docs.rs/canadensis/latest/canadensis/node/struct.BasicNode.html Creates a new BasicNode instance. This function initializes the node with provided information and sets up basic functionalities. ```APIDOC ## BasicNode::new ### Description Creates a new basic node. ### Parameters * `node` (N): The underlying node, typically a `CoreNode`. * `node_info` (GetInfoResponse): Information to be returned for node information requests. ### Returns * `Result>`: A `Result` containing the new `BasicNode` or an error if creation fails. ``` -------------------------------- ### Get RegisterServerService Handler Source: https://docs.rs/canadensis/latest/canadensis/service/register_server/struct.RegisterServerService.html Returns a handler for the RegisterServerService, which is used to manage service requests. ```rust pub fn handler(&mut self) -> RegisterServerServiceHandler<'_, N, B> ``` -------------------------------- ### Create a new BasicNode Source: https://docs.rs/canadensis/latest/canadensis/node/struct.BasicNode.html Initializes a new BasicNode instance. This function requires the underlying node and information to be returned for node info requests. It returns a Result that can contain various errors related to starting services or sending messages. ```rust pub fn new( node: N, node_info: GetInfoResponse, ) -> Result>::Error>, ServiceSubscribeError<>::Error>>> ``` -------------------------------- ### fn start_sending_requests Source: https://docs.rs/canadensis/latest/canadensis/trait.Node.html Sets up to send requests for a service, also subscribing to the corresponding responses. This function returns an error if memory could not be allocated, or if the subject ID is already in use. ```APIDOC ## fn start_sending_requests( &mut self, service: ServiceId, receive_timeout: MicrosecondDuration32, response_payload_size_max: usize, priority: ::Priority, ) ### Description Configures the node to send requests for a specific service and subscribes to its responses. This method allocates resources and establishes the necessary communication channels. ### Parameters * `service`: The identifier of the service to send requests to. * `receive_timeout`: The maximum duration to wait for a response. * `response_payload_size_max`: The maximum expected size of the response payload. * `priority`: The priority level for sending requests. ### Returns * `Result, StartSendError<>::Error>>`: A `ServiceToken` if successful, or an error if memory allocation fails or the service ID is already in use. ``` -------------------------------- ### Get PnpClientService Handler Source: https://docs.rs/canadensis/latest/canadensis/service/pnp/client/struct.PnpClientService.html Retrieves a handler for the PnpClientService, which can be used to manage client operations. ```rust pub fn handler(&mut self) -> PnpClientServiceHandler<'_, N, M> ``` -------------------------------- ### PnpServerService Initialization Source: https://docs.rs/canadensis/latest/src/canadensis/service/pnp/server.rs.html Creates a new PnP server service, subscribing to and publishing allocation messages. Panics if C does not match the maximum NodeId or if message size exceeds MTU. ```rust /// A plug-and-play allocation server pub struct PnpServerService { assignments: [Assignment; C], _node: PhantomData, } impl PnpServerService { /// Creates a new plug-and-play server /// /// # Panics /// /// This function will panic if the message size is larger than the MTU of the node's transmitter or if the `C` generic parameter is not equal to the maximum value of `Transport::NodeId`. pub fn new(node: &mut N) -> Result> { debug_assert_eq!( C, <::NodeId as Bounded>::max_value() .into() .into(), "C must be the maximum value of the node ID type" ); node.subscribe_message( >::SUBJECT, >::PAYLOAD_SIZE_MAX, milliseconds(1000), ) .map_err(|err| NewError::Subscribe(err))?; node.start_publishing( >::SUBJECT, milliseconds(1000), Priority::Nominal.into(), ) .map_err(|err| match err { StartSendError::Memory(_) => NewError::OutOfMemory, StartSendError::Duplicate => NewError::Duplicate, StartSendError::Transport(err) => NewError::Publish(err), StartSendError::AnonymousRequest => unreachable!(), // we are publishing a message, not a request })?; if >::PAYLOAD_SIZE_MAX <= node.transmitter().mtu() { node.subscribe_message( >::SUBJECT, >::PAYLOAD_SIZE_MAX, milliseconds(1000), ) .map_err(|err| NewError::Subscribe(err))?; node.start_publishing( >::SUBJECT, milliseconds(1000), Priority::Nominal.into(), ) .map_err(|err| match err { StartSendError::Memory(_) => NewError::OutOfMemory, StartSendError::Duplicate => NewError::Duplicate, StartSendError::Transport(err) => NewError::Publish(err), StartSendError::AnonymousRequest => unreachable!(), // we are publishing a message, not a request })?; } Ok(PnpServerService { assignments: [Assignment::Unassigned; C], _node: PhantomData, }) } /// Returns a handler for the server pub fn handler(&mut self) -> PnpServerServiceHandler<'_, N, C> { PnpServerServiceHandler { server: self } } /// Assigns a [`NodeId`] to a given unique ID. This will only have an effect if the [`NodeId`] has not yet been assigned or reserved. pub fn assign(&mut self, node_id: ::NodeId, unique_id: [u8; 16]) { let idx: usize = node_id.into().into(); ``` -------------------------------- ### Get Register Value Source: https://docs.rs/canadensis/latest/canadensis/register/basic/struct.SimpleRegister.html Returns an immutable reference to the current value stored in the SimpleRegister. ```rust pub fn value(&self) -> &T ``` -------------------------------- ### Get Subscribers Source: https://docs.rs/canadensis/latest/canadensis/core/transport/trait.Receiver.html Returns an iterator over the subject IDs that this receiver is currently subscribed to for messages. ```rust fn subscribers(&self) -> impl Iterator ``` -------------------------------- ### PortListService::new Source: https://docs.rs/canadensis/latest/canadensis/service/port_list/struct.PortListService.html Creates a new PortListService instance. ```APIDOC ## PortListService::new ### Description Creates a new PortListService. ### Signature ```rust pub fn new(node: &mut N) -> Result> ``` ### Parameters * `node`: A mutable reference to the node. ### Returns A `Result` containing the new `PortListService` or a `NewError`. ``` -------------------------------- ### MinimalNode Constructor Source: https://docs.rs/canadensis/latest/src/canadensis/node/minimal.rs.html Creates a new MinimalNode instance. It initializes a default heartbeat message and starts publishing it on the UAVCAN network. This function must be called with a valid underlying node. ```rust pub fn new( mut node: N, ) -> Result>::Error>> { // Default heartbeat settings let heartbeat = Heartbeat { uptime: 0, health: Health { value: Health::NOMINAL, }, mode: Mode { value: Mode::OPERATIONAL, }, vendor_specific_status_code: 0, }; let heartbeat_timeout = MicrosecondDuration32::from_ticks(500_000); node.start_publishing( heartbeat_1_0::SUBJECT, heartbeat_timeout, Priority::Nominal.into(), )?; Ok(MinimalNode { node, heartbeat }) } ``` -------------------------------- ### Get Mutable Minimal Node Reference Source: https://docs.rs/canadensis/latest/src/canadensis/node/basic.rs.html Returns a mutable reference to the enclosed minimal node. ```APIDOC ## minimal_node_mut ### Description Returns a mutable reference to the enclosed minimal node. ### Method `minimal_node_mut` ### Return Value - `&mut MinimalNode` - A mutable reference to the enclosed minimal node. ``` -------------------------------- ### GetInfoService::new Source: https://docs.rs/canadensis/latest/canadensis/service/get_info/struct.GetInfoService.html Creates a new GetInfo service instance. This service is responsible for responding to `uavcan.node.GetInfo` requests. ```APIDOC ## GetInfoService::new ### Description Creates a new GetInfo service. ### Parameters #### Path Parameters - **node** (*&mut N*) - Required - The node to use for responding to requests. - **node_info** (*GetInfoResponse*) - Required - Information about the node. #### Return Value - **Result>** - A Result containing the new GetInfoService or a ServiceSubscribeError. ``` -------------------------------- ### Get Current Assignments Source: https://docs.rs/canadensis/latest/canadensis/service/pnp/server/struct.PnpServerService.html Retrieves an iterator over the current assignments of NodeIds. This function is guaranteed not to panic. ```rust pub fn assignments( &self, ) -> impl Iterator::NodeId, Assignment)> + use<'_, N, C> ``` -------------------------------- ### Node::start_sending_requests Source: https://docs.rs/canadensis/latest/canadensis/node/struct.CoreNode.html Sets up the node to send requests for a specific service, subscribing to corresponding responses. ```APIDOC ## Node::start_sending_requests ### Description Sets up to send requests for a service. This also subscribes to the corresponding responses. ### Signature ```rust fn start_sending_requests( &mut self, service: ServiceId, receive_timeout: MicrosecondDuration32, response_payload_size_max: usize, priority: N::Priority, ) -> Result, StartSendError> where M: Request, ``` ### Parameters * `service` (ServiceId): The ID of the service for which to send requests. * `receive_timeout` (MicrosecondDuration32): The timeout for receiving a response. * `response_payload_size_max` (usize): The maximum payload size for the response. * `priority` (N::Priority): The priority of the requests. ``` -------------------------------- ### Get Register Access Information Source: https://docs.rs/canadensis/latest/canadensis/register/basic/struct.SimpleRegister.html Returns information about how the register can be accessed (e.g., read-only, read-write). ```rust fn access(&self) -> Access ``` -------------------------------- ### Clone for Instant Source: https://docs.rs/canadensis/latest/canadensis/core/time/type.Microseconds32.html Provides the ability to create a copy of an `Instant` instance. ```APIDOC ### impl Clone for Instant where T: Clone, #### fn clone(&self) -> Instant Returns a duplicate of the value. #### fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. ``` -------------------------------- ### Get Reference to Enclosed Node Source: https://docs.rs/canadensis/latest/canadensis/node/struct.MinimalNode.html Provides an immutable reference to the underlying node managed by the MinimalNode. ```rust pub fn node(&self) -> &N ``` -------------------------------- ### ServiceToken Struct Source: https://docs.rs/canadensis/latest/index.html A token returned when starting to send requests, used to make service calls. ```APIDOC ## Struct: ServiceToken ### Description A token returned from `Node::start_sending_requests` that can be used to request a service using the associated service ID. ### Usage This token is essential for initiating service calls through the Cyphal network, tied to a specific service ID. ``` -------------------------------- ### Get Node ID Source: https://docs.rs/canadensis/latest/canadensis/node/struct.CoreNode.html Returns the identifier of this node, if it has been configured with one. Anonymous nodes will return None. ```rust fn node_id(&self) -> Option<::NodeId> ``` -------------------------------- ### Get Reference to MinimalNode Source: https://docs.rs/canadensis/latest/canadensis/node/struct.BasicNode.html Returns an immutable reference to the `MinimalNode` wrapper, which provides a subset of `Node` functionalities. ```rust pub fn minimal_node(&self) -> &MinimalNode ``` -------------------------------- ### Get Servers Source: https://docs.rs/canadensis/latest/canadensis/core/transport/trait.Receiver.html Returns an iterator over the service IDs for which this receiver is currently subscribed to receive requests or responses. ```rust fn servers(&self) -> impl Iterator ``` -------------------------------- ### Type ID Conversion Source: https://docs.rs/canadensis/latest/canadensis/core/session/struct.SessionArray.html Gets the `TypeId` of the current session array instance. This is part of the `Any` trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### register_by_index Source: https://docs.rs/canadensis/latest/canadensis/register/trait.RegisterBlock.html Returns a reference to the register at the provided index. Register indexes should start at 0 and not contain any gaps. ```APIDOC ## fn register_by_index(&self, index: usize) -> Option<&dyn Register> ### Description Returns a reference to the register at the provided index. Register indexes should start at 0 and not contain any gaps. ### Parameters #### Path Parameters - **index** (usize) - Required - The index of the register to retrieve. ``` -------------------------------- ### Create New GetInfoService Instance Source: https://docs.rs/canadensis/latest/canadensis/service/get_info/struct.GetInfoService.html Creates a new GetInfoService instance. Requires a mutable reference to the node and the GetInfoResponse to be sent. Handles potential errors during service subscription. ```rust pub fn new( node: &mut N, node_info: GetInfoResponse, ) -> Result>::Error>> ``` -------------------------------- ### Create RegisterServerService Source: https://docs.rs/canadensis/latest/src/canadensis/service/register_server.rs.html Initializes the RegisterServerService by subscribing to the List and Access service IDs. Requires a node and a RegisterBlock implementation. ```rust pub fn new( node: &mut N, registers: B, ) -> Result>::Error>> { node.subscribe_request(list_1_0::SERVICE, 2, milliseconds(1000))?; node.subscribe_request(access_1_0::SERVICE, 515, milliseconds(1000))?; Ok(Self { registers, _node: PhantomData, }) } ``` -------------------------------- ### Implement CloneToUninit for T (Nightly) Source: https://docs.rs/canadensis/latest/canadensis/core/struct.OutOfMemoryError.html Nightly-only experimental API for copying data to uninitialized memory. ```rust impl CloneToUninit for T where T: Clone, unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Create a new Publisher Source: https://docs.rs/canadensis/latest/src/canadensis/publisher.rs.html Initializes a new Publisher instance with a specified timeout and priority. The next transfer ID is set to its default value. ```rust pub fn new( timeout: MicrosecondDuration32, priority: ::Priority, ) -> Self { Publisher { next_transfer_id: ::TransferId::default(), timeout, priority, } } ``` -------------------------------- ### Get GetInfoService Handler Source: https://docs.rs/canadensis/latest/canadensis/service/get_info/struct.GetInfoService.html Retrieves the handler for the GetInfoService. This handler is used to process incoming GetInfo requests for the node. ```rust pub fn handler(&self) -> GetInfoServiceHandler<'_, N> ``` -------------------------------- ### Get Mutable Register Value Source: https://docs.rs/canadensis/latest/canadensis/register/basic/struct.SimpleRegister.html Returns a mutable reference to the current value stored in the SimpleRegister, allowing modification. ```rust pub fn value_mut(&mut self) -> &mut T ``` -------------------------------- ### RegisterServerService::new Source: https://docs.rs/canadensis/latest/canadensis/service/register_server/struct.RegisterServerService.html Creates a new RegisterServerService instance. ```APIDOC ## RegisterServerService::new ### Description Creates a new `RegisterServerService`. ### Parameters * **node** (*&mut N*) - The node to use for responding to requests. * **registers** (*B*) - The register block to use for responding to requests. ### Returns * Result> - A new `RegisterServerService` instance or an error. ``` -------------------------------- ### Get Mutable Reference to MinimalNode Source: https://docs.rs/canadensis/latest/canadensis/node/struct.BasicNode.html Provides mutable access to the `MinimalNode` wrapper, allowing modifications to its state or configuration. ```rust pub fn minimal_node_mut(&mut self) -> &mut MinimalNode ``` -------------------------------- ### Get Priority from Header Source: https://docs.rs/canadensis/latest/canadensis/core/transfer/enum.Header.html Retrieves a reference to the priority of the header. The priority type is determined by the associated Transport trait. ```rust pub fn priority(&self) -> &::Priority ``` -------------------------------- ### try_from Source: https://docs.rs/canadensis/latest/canadensis/core/time/type.MicrosecondDuration32.html Attempts to convert a u64 duration to a MicrosecondDuration32. Returns an error if the conversion fails. ```APIDOC ## try_from ### Description Performs the conversion from `Duration` to `Duration`. ### Signature `fn try_from(val: Duration) -> Result, ()>` ### Error Type `type Error = ()` ``` -------------------------------- ### Get Timestamp from Header Source: https://docs.rs/canadensis/latest/canadensis/core/transfer/enum.Header.html Retrieves the timestamp associated with the header. The timestamp is represented as an Instant with specific generic parameters. ```rust pub fn timestamp(&self) -> Instant ``` -------------------------------- ### Create and Use a ValidatedRegister Source: https://docs.rs/canadensis/latest/canadensis/register/basic/struct.ValidatedRegister.html Demonstrates creating a ValidatedRegister for f32 values with a validator that checks for finite numbers. Shows successful writes and rejected writes for infinite or NaN values. ```rust fn is_finite_float(value: &f32) -> bool { !(value.is_infinite() || value.is_nan()) } let mut finite_float_register = ValidatedRegister::new("test.float", true, true, is_finite_float); assert!(finite_float_register .write(&Value::Real32(Real32 { value: heapless::Vec::from_slice(&[37.0]).unwrap() })) .is_ok()); assert!(finite_float_register .write(&Value::Real32(Real32 { value: heapless::Vec::from_slice(&[f32::INFINITY]).unwrap()} )) .is_err()); assert!(finite_float_register .write(&Value::Real32(Real32 { value:heapless::Vec::from_slice(&[f32::NEG_INFINITY]).unwrap()} )) .is_err()); assert!(finite_float_register .write(&Value::Real32(Real32 { value: heapless::Vec::from_slice(&[f32::NAN]).unwrap()} )) .is_err()); ```