Skip to main content

MeshRadio

Struct MeshRadio 

Source
pub struct MeshRadio<R> { /* private fields */ }
Expand description

A node on a LoRa mesh: a radio, the node’s address, and the rules it keeps.

Build it around a configured radio, connect to start listening, then send and receive as over any other pamoja transport.

Implementations§

Source§

impl<R: LoraRadio> MeshRadio<R>

Source

pub fn new(radio: R, node: u32, duty_cycle_permille: u32) -> MeshRadio<R>

Builds a node around a radio that is already configured.

Frames start with [Frame::DEFAULT_HOP_LIMIT] hops, and the node relays what it hears.

§Arguments
  • radio - the radio, tuned to the channel the mesh uses.
  • node - this node’s address, which every frame it sends carries as its source.
  • duty_cycle_permille - the region’s duty-cycle limit in parts per thousand, such as 10 for 1%, or 1000 where the region sets none.
§Returns

The node, not yet connected.

Source

pub fn with_hop_limit(self, hop_limit: u8) -> MeshRadio<R>

Returns the node with another hop limit for the frames it sends.

§Arguments
  • hop_limit - how many relays a frame may take; 0 keeps it to the nodes in range.
§Returns

The node.

Source

pub fn without_relaying(self) -> MeshRadio<R>

Returns the node with relaying off, so it only sends and receives its own traffic.

§Returns

The node.

Source

pub fn node(&self) -> u32

Returns this node’s address.

§Returns

The address frames carry as their source.

Source

pub fn is_connected(&self) -> bool

Reports whether the node is connected and listening.

§Returns

true after connect.

Source

pub fn duty_cycle(&self) -> &DutyCycle

Returns the duty-cycle guard, to see how long the radio must still stay silent.

§Returns

The guard, whose clock is microseconds since the node was built.

Source

pub fn radio(&self) -> &R

Returns the radio.

§Returns

A reference to the radio.

Source

pub fn radio_mut(&mut self) -> &mut R

Returns the radio, to reach what the transport does not cover.

§Returns

A mutable reference to the radio.

Source

pub fn release(self) -> R

Gives back the radio.

§Returns

The radio.

Trait Implementations§

Source§

impl<R: LoraRadio + Send> Receive for MeshRadio<R>

Source§

async fn recv(&mut self) -> Result<Option<Message>>

Awaits the next message whose topic a subscription matches.

A frame relayed on the way is sent before the message is handed up, and a message already taken off the air waits in the node if the call is dropped meanwhile, so nothing received is lost to a cancellation.

§Returns

The next message; the air never ends, so never None.

§Errors

Returns [Error::Closed] before connect, and [Error::Transport] if the radio fails.

Source§

impl<R: LoraRadio + Send> Transport for MeshRadio<R>

Source§

async fn connect(&mut self) -> Result<()>

Establishes the connection to the broker, peer, or bus. Read more
Source§

async fn send(&mut self, topic: &str, payload: &[u8]) -> Result<()>

Publishes a payload to a topic. Read more
Source§

async fn subscribe(&mut self, topic: &str) -> Result<()>

Subscribes to a topic so that matching payloads are routed to this transport. Read more
§

fn send_text( &mut self, topic: &str, text: &str, ) -> impl Future<Output = Result<(), Error>> + Send

Publishes text to a topic: words, or a number written out. Read more

Auto Trait Implementations§

§

impl<R> Freeze for MeshRadio<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for MeshRadio<R>
where R: RefUnwindSafe,

§

impl<R> Send for MeshRadio<R>
where R: Send,

§

impl<R> Sync for MeshRadio<R>
where R: Sync,

§

impl<R> Unpin for MeshRadio<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for MeshRadio<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for MeshRadio<R>
where R: UnwindSafe,

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>,

Source§

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>,

Source§

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.