Struct embedded_nano_mesh::Node

source ·
pub struct Node { /* private fields */ }
Expand description

The main structure of the library to use communication in the mesh network. The node works in the manner of listening of ether for specified period of time, which is called listen_period, and then sending out packets between those periods.

Also node resends caught packets, that were addressed to other nodes.

It has next methods:

  • new - Creates new instance of Node.
  • send - Sends the data to exact device. Call of this method does not provide any response back.
  • send_ping_pong - Sends the data to exact device, and the receiving device will be forsed to make answer back. The answer from receiving device may tell if sending was successful.
  • send_with_transaction - Sends the data to exact device, and the receiving device will be forsed to make answer back. The answer from receiving device will tell if sending was successful.
  • update - Updates the state of the node. This method should be called in every loop iteration.

Implementations§

source§

impl Node

source

pub fn new(config: NodeConfig) -> Node

Creates new instance of Node.

parameters:

  • config - Instance of NodeConfig.
source

pub fn send_ping_pong<TIMER: PlatformMillis, SERIAL: PlatformSerial<u8>>( &mut self, data: Vec<u8, { CONTENT_SIZE }>, destination_device_identifier: ExactAddressType, lifetime: LifeTimeType, timeout: ms ) -> Result<(), SpecialSendError>

Sends the data to exact device with ping flag set, and the receiving device will be forsed to make answer back with ‘pong’ flag set. The answer from receiving device will tell if sending was successful.

parameters:

  • data - Is the instance of PacketDataBytes, which is just type alias of heapless vector of bytes of special size. This size is configured in the node/packet/config.rs file, and can be adjusted for case of other data size is needed. Note! That all devices should have same version of protocol flashed, in order to be able to correctly to communicate with each other.

  • destination_device_identifier is instance of ExactDeviceAddressType, This is made to presend device’s address within the network.

*lifetime - is the instance of LifeTimeType. This value configures the count of how many nodes - the packet will be able to pass. Also this value is needed to void the ether being jammed by packets, that in theory might be echoed by the nodes to the infinity…

  • timeout - Is the period of time in milliseconds that this device will listen for response. In case if no response was caught during that period of time, the method will return Err(SpecialSendError::Timeout).

  • Call of this method also requires the general types to be passed in. As the process relies onto timing countings and onto serial stream,

That parts can be platform dependent, so general trait bound types are made to be able to use this method in any platform, by just providing platform specific types.

source

pub fn send_with_transaction<TIMER: PlatformMillis, SERIAL: PlatformSerial<u8>>( &mut self, data: Vec<u8, { CONTENT_SIZE }>, destination_device_identifier: ExactAddressType, lifetime: LifeTimeType, timeout: ms ) -> Result<(), SpecialSendError>

Sends the data to exact device with the response, that tells if the message was sent successfully, or sending has failed.

  • data - Is the instance of PacketDataBytes, which is just type alias of heapless vector of bytes of special size. This size is configured in the node/packet/config.rs file, and can be adjusted for case of other data size is needed. Note! That all devices should have same version of protocol flashed, in order to be able to correctly to communicate with each other.

  • destination_device_identifier is instance of ExactDeviceAddressType, That type is made for simplicity of reading the code, and to strict possible mess-ups during the usage of methods. It is made to present device id within the network.

  • lifetime - is the instance of LifeTimeType. This value configures the count of how many nodes - the packet will be able to pass. Also this value is needed to void the ether being jammed by packets, that in theory might be echoed by the nodes to the infinity… Each device, once passes transit packet trough it - it reduces packet’s lifetime.

  • timeout - Is the period of time in milliseconds that this device will wait until packet that finishes the transaction - arrives. In case if no response was caught during that period of time, the method will return Err(SpecialSendError::Timeout).

  • Call of this method also requires the general types to be passed in. As the process relies onto timing countings and onto serial stream,

That parts can be platform dependent, so general trait bound types are made to be able to use this method in any platform, by just providing platform specific types.

source

pub fn send( &mut self, data: Vec<u8, { CONTENT_SIZE }>, destination_device_identifier: GeneralAddressType, lifetime: LifeTimeType, filter_out_duplication: bool ) -> Result<(), SendError>

Sends the data to exact device. or to all devices. In order to send data to all devices, use GeneralAddressType::Broadcast, otherwise - `GeneralAddressType::Exact(ExactAddressType::new(…).unwrap()) identifier in order to set exact receiver device address.

  • data - Is the instance of PacketDataBytes, which is just type alias of heapless vector of bytes of special size. This size is configured in the node/packet/config.rs file. Note! That all devices should have same version of protocol flashed, in order to be able to correctly to communicate with each other.

  • destination_device_identifier is instance of GeneralAddressType, That type is made to limit possible mess-ups during the usage of method.

  • lifetime - is the instance of LifeTimeType. This value configures the count of how many nodes - the packet will be able to pass. Also this value is provided to void the ether being jammed by packets, that in theory might be echoed by other nodes to the infinity… Each device, once passes transit packet trough it - it reduces packet’s lifetime.

  • filter_out_duplication - Tells if the protocol on the other devices will be ignoring echoes of this message. It is strongly recommended to use in order to make lower load onto the network.

source

pub fn receive(&mut self) -> Option<PacketMetaData>

Optionally returns PacketDataBytes instance with data, which has been send exactly to this device, or has been broadcasted trough all the network.

source

pub fn update<TIMER: PlatformMillis, SERIAL: PlatformSerial<u8>>( &mut self ) -> Result<(), NodeUpdateError>

Does all necessary internal work of mesh node:

  • Receives packets from ether, and manages their further life. ** Data that is addressed to other devices are going to be send back into ether. ** Data addressed to current device, will be unpacked and stored.

  • Call of this method also requires the general types to be passed in. As the process relies onto timing countings and onto serial stream,

That parts are platform dependent, so general trait bound types are made to be able to use this method in any platform, by just providing platform specific types with all required traits implemented.

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.