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 ofNode.send- Sends thedatato exact device. Call of this method does not provide any response back.send_ping_pong- Sends thedatato 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 thedatato 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
impl Node
sourcepub fn new(config: NodeConfig) -> Node
pub fn new(config: NodeConfig) -> Node
Creates new instance of Node.
parameters:
config- Instance ofNodeConfig.
sourcepub 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>
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 ofPacketDataBytes, 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_identifieris 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 returnErr(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.
sourcepub 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>
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 ofPacketDataBytes, 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_identifieris instance ofExactDeviceAddressType, 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 ofLifeTimeType. 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 returnErr(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.
sourcepub fn send(
&mut self,
data: Vec<u8, { CONTENT_SIZE }>,
destination_device_identifier: GeneralAddressType,
lifetime: LifeTimeType,
filter_out_duplication: bool
) -> Result<(), SendError>
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 ofPacketDataBytes, 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_identifieris instance ofGeneralAddressType, That type is made to limit possible mess-ups during the usage of method. -
lifetime- is the instance ofLifeTimeType. 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.
sourcepub fn receive(&mut self) -> Option<PacketMetaData>
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.
sourcepub fn update<TIMER: PlatformMillis, SERIAL: PlatformSerial<u8>>(
&mut self
) -> Result<(), NodeUpdateError>
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.