Skip to main content

CommandHandler

Struct CommandHandler 

Source
pub struct CommandHandler { /* private fields */ }
Expand description

Command handler for MeshCore operations

Implementations§

Source§

impl CommandHandler

Source

pub fn new( sender: Sender<Vec<u8>>, dispatcher: Arc<EventDispatcher>, reader: Arc<MessageReader>, ) -> Self

Create a new command handler

Source

pub fn set_default_timeout(&mut self, timeout: Duration)

Set the default timeout for commands

Source

pub async fn send( &self, data: &[u8], expected_event: Option<EventType>, ) -> Result<MeshCoreEvent>

Send raw data and wait for a response

Source

pub async fn send_with_timeout( &self, data: &[u8], expected_event: Option<EventType>, timeout: Duration, ) -> Result<MeshCoreEvent>

Send raw data and wait for a response with the custom timeout

Source

pub async fn send_multi( &self, data: &[u8], expected_events: &[EventType], timeout: Duration, ) -> Result<MeshCoreEvent>

Send raw data and wait for one of multiple response types

Source

pub async fn wait_for_event( &self, event_type: Option<EventType>, filters: HashMap<String, String>, timeout: Duration, ) -> Result<MeshCoreEvent>

Wait for a specific event

Source

pub async fn wait_for_any_event( &self, event_types: &[EventType], timeout: Duration, ) -> Result<MeshCoreEvent>

Wait for any of the specified events

Source

pub async fn send_appstart(&self) -> Result<SelfInfo>

Send APPSTART command to initialise connection

Format: [CMD_APP_START=0x01][reserved: 7 bytes][app_name: “mccli”]

Source

pub async fn send_device_query(&self) -> Result<DeviceInfoData>

Query device info

Format: [CMD_DEVICE_QUERY=0x16][protocol_version]

Source

pub async fn get_bat(&self) -> Result<BatteryInfo>

Get battery level and storage info

Format: [CMD_GET_BATT_AND_STORAGE=0x14]

Source

pub async fn get_time(&self) -> Result<u32>

Get device time

Format: [CMD_GET_DEVICE_TIME=0x05]

Source

pub async fn set_time(&self, timestamp: u32) -> Result<MeshCoreEvent>

Set device time

Format: [CMD_SET_DEVICE_TIME=0x06][timestamp: u32]

Source

pub async fn set_name(&self, name: &str) -> Result<MeshCoreEvent>

Set the device name

Format: [CMD_SET_ADVERT_NAME=0x08][name]

Source

pub async fn set_coords(&self, lat: f64, lon: f64) -> Result<MeshCoreEvent>

Set device coordinates

Format: [CMD_SET_ADVERT_LATLON=0x0E][lat: i32][lon: i32][alt: i32]

Source

pub async fn set_tx_power(&self, power: u8) -> Result<MeshCoreEvent>

Set TX power

Format: [CMD_SET_RADIO_TX_POWER=0x0C][power: u8]

Source

pub async fn send_advert(&self, flood: bool) -> Result<MeshCoreEvent>

Send advertisement

Format: [CMD_SEND_SELF_ADVERT=0x07][flood: optional]

Source

pub async fn reboot(&self) -> Result<()>

Reboot device (no response expected)

Format: [CMD_REBOOT=0x13][“reboot”]

Source

pub async fn get_custom_vars(&self) -> Result<HashMap<String, String>>

Get custom variables

Format: [CMD_GET_CUSTOM_VARS=0x28]

Source

pub async fn set_custom_var(&self, key: &str, value: &str) -> Result<()>

Set a custom variable

Format: [CMD_SET_CUSTOM_VAR=0x29][key=value]

Source

pub async fn get_channel(&self, channel_idx: u8) -> Result<ChannelInfoData>

Get channel info

Format: [CMD_GET_CHANNEL=0x1F][channel_idx: u8]

Source

pub async fn set_channel( &self, channel_idx: u8, name: &str, secret: &[u8; 16], ) -> Result<()>

Set channel

Format: [CMD_SET_CHANNEL=0x20][channel_idx][name: CHANNEL_NAME_LEN bytes][secret: CHANNEL_SECRET_LEN bytes] Note: name is null-terminated, so max usable length is CHANNEL_NAME_LEN - 1 bytes

Source

pub async fn set_flood_scope(&self, scope: Option<&str>) -> Result<()>

Set flood scope (region code)

Format: [CMD_SET_FLOOD_SCOPE=0x36][0][scope: 16 bytes] Format: [CMD_SET_FLOOD_SCOPE=0x36][0] (to reset flood scope)

Source

pub async fn export_private_key(&self) -> Result<[u8; 64]>

Export private key

Format: [CMD_EXPORT_PRIVATE_KEY=0x17]

Source

pub async fn import_private_key(&self, key: &[u8; 64]) -> Result<()>

Import private key

Format: [CMD_IMPORT_PRIVATE_KEY=0x18][key: 64 bytes]

Source

pub async fn get_contacts( &self, last_modification_timestamp: u32, ) -> Result<Vec<Contact>>

Get the contact list

Source

pub async fn get_contacts_with_timeout( &self, last_modification_timestamp: u32, timeout: Duration, ) -> Result<Vec<Contact>>

Get the contact list with a custom timeout

Format: [CMD_GET_CONTACTS=0x04][last_mod_timestamp: u32]

Source

pub async fn add_contact(&self, contact: &Contact) -> Result<()>

Add or update a contact

Format: [CMD_ADD_UPDATE_CONTACT=0x09][pubkey: 32][type: u8][flags: u8][path_len: u8][path: 64][name: 32][timestamp: u32][lat: i32][lon: i32]

Source

pub async fn remove_contact(&self, key: impl Into<Destination>) -> Result<()>

Remove a contact by public key

Format: [CMD_REMOVE_CONTACT=0x0F][pubkey: 32]

Source

pub async fn export_contact( &self, key: Option<impl Into<Destination>>, ) -> Result<String>

Export contact as URI

Format: [CMD_EXPORT_CONTACT=0x11][pubkey: 32 optional]

Source

pub async fn import_contact(&self, card_data: &[u8]) -> Result<()>

Import contact from card data

Format: [CMD_IMPORT_CONTACT=0x12][card_data]

Source

pub async fn get_msg(&self) -> Result<Option<MeshCoreEvent>>

Get the next message from the queue

Returns the event containing either a ContactMessage or ChannelMessage payload. Returns None if there are no more messages.

The caller should check event.event_type to determine the message type:

  • EventType::ContactMsgRecvEventPayload::ContactMessage(msg)
  • EventType::ChannelMsgRecvEventPayload::ChannelMessage(msg)
Source

pub async fn get_msg_with_timeout( &self, timeout: Duration, ) -> Result<Option<MeshCoreEvent>>

Get the next message with a custom timeout

Format: [CMD_SYNC_NEXT_MESSAGE=0x0A]

Source

pub async fn send_msg( &self, dest: impl Into<Destination>, msg: &str, timestamp: Option<u32>, ) -> Result<MsgSentInfo>

Send a message to a contact

Format: [CMD_SEND_TXT_MSG=0x02][txt_type][attempt][timestamp: u32][pubkey_prefix: 6][message]

Source

pub async fn send_channel_msg( &self, channel: u8, msg: &str, timestamp: Option<u32>, ) -> Result<()>

Send a channel message

Format: [CMD_SEND_CHANNEL_TXT_MSG=0x03][txt_type][channel_idx][timestamp: u32][message]

Source

pub async fn send_login( &self, dest: impl Into<Destination>, password: &str, ) -> Result<MsgSentInfo>

Send login request

Format: [CMD_SEND_LOGIN=0x1A][pubkey: 32][password]

Source

pub async fn send_logout(&self, dest: impl Into<Destination>) -> Result<()>

Send logout request

Format: [CMD_LOGOUT=0x1D][pubkey: 32]

Source

pub async fn send_binary_req( &self, dest: impl Into<Destination>, req_type: BinaryReqType, ) -> Result<MsgSentInfo>

Send a binary request to a contact

Format: [CMD_SEND_BINARY_REQ=0x32][req_type][pubkey: 32]

Source

pub async fn request_status( &self, dest: impl Into<Destination>, ) -> Result<StatusData>

Request status from a contact

Source

pub async fn request_status_with_timeout( &self, dest: impl Into<Destination>, timeout: Duration, ) -> Result<StatusData>

Request status with the custom timeout

Source

pub async fn request_telemetry( &self, dest: impl Into<Destination>, ) -> Result<Vec<u8>>

Request telemetry from a contact

Source

pub async fn request_telemetry_with_timeout( &self, dest: impl Into<Destination>, timeout: Duration, ) -> Result<Vec<u8>>

Request telemetry with the custom timeout

Source

pub async fn request_acl( &self, dest: impl Into<Destination>, ) -> Result<Vec<AclEntry>>

Request ACL from a contact

Source

pub async fn request_acl_with_timeout( &self, dest: impl Into<Destination>, timeout: Duration, ) -> Result<Vec<AclEntry>>

Request ACL with the custom timeout

Source

pub async fn request_neighbours( &self, dest: impl Into<Destination>, count: u16, offset: u16, ) -> Result<NeighboursData>

Request neighbours from a contact

Source

pub async fn request_neighbours_with_timeout( &self, dest: impl Into<Destination>, count: u16, offset: u16, timeout: Duration, ) -> Result<NeighboursData>

Request neighbours with custom timeout

Format: [CMD_SEND_BINARY_REQ=0x32][req_type][pubkey: 32][count: u16][offset: u16]

Source

pub async fn sign_start(&self) -> Result<u32>

Start a signing session

Format: [CMD_SIGN_START=0x21]

Source

pub async fn sign_data(&self, chunk: &[u8]) -> Result<()>

Send data chunk for signing

Format: [CMD_SIGN_DATA=0x22][chunk]

Source

pub async fn sign_finish(&self, timeout: Duration) -> Result<Vec<u8>>

Finish signing and get the signature

Format: [CMD_SIGN_FINISH=0x23]

Source

pub async fn sign( &self, data_to_sign: &[u8], chunk_size: usize, ) -> Result<Vec<u8>>

Sign data (high-level helper)

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more