pub struct CommandHandler { /* private fields */ }Expand description
Command handler for MeshCore operations
Implementations§
Source§impl CommandHandler
impl CommandHandler
Sourcepub fn new(
sender: Sender<Vec<u8>>,
dispatcher: Arc<EventDispatcher>,
reader: Arc<MessageReader>,
) -> Self
pub fn new( sender: Sender<Vec<u8>>, dispatcher: Arc<EventDispatcher>, reader: Arc<MessageReader>, ) -> Self
Create a new command handler
Sourcepub fn set_default_timeout(&mut self, timeout: Duration)
pub fn set_default_timeout(&mut self, timeout: Duration)
Set the default timeout for commands
Sourcepub async fn send(
&self,
data: &[u8],
expected_event: Option<EventType>,
) -> Result<MeshCoreEvent>
pub async fn send( &self, data: &[u8], expected_event: Option<EventType>, ) -> Result<MeshCoreEvent>
Send raw data and wait for a response
Sourcepub async fn send_with_timeout(
&self,
data: &[u8],
expected_event: Option<EventType>,
timeout: Duration,
) -> Result<MeshCoreEvent>
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
Sourcepub async fn send_multi(
&self,
data: &[u8],
expected_events: &[EventType],
timeout: Duration,
) -> Result<MeshCoreEvent>
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
Sourcepub async fn wait_for_event(
&self,
event_type: Option<EventType>,
filters: HashMap<String, String>,
timeout: Duration,
) -> Result<MeshCoreEvent>
pub async fn wait_for_event( &self, event_type: Option<EventType>, filters: HashMap<String, String>, timeout: Duration, ) -> Result<MeshCoreEvent>
Wait for a specific event
Sourcepub async fn wait_for_any_event(
&self,
event_types: &[EventType],
timeout: Duration,
) -> Result<MeshCoreEvent>
pub async fn wait_for_any_event( &self, event_types: &[EventType], timeout: Duration, ) -> Result<MeshCoreEvent>
Wait for any of the specified events
Sourcepub async fn send_appstart(&self) -> Result<SelfInfo>
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”]
Sourcepub async fn send_device_query(&self) -> Result<DeviceInfoData>
pub async fn send_device_query(&self) -> Result<DeviceInfoData>
Query device info
Format: [CMD_DEVICE_QUERY=0x16][protocol_version]
Sourcepub async fn get_bat(&self) -> Result<BatteryInfo>
pub async fn get_bat(&self) -> Result<BatteryInfo>
Get battery level and storage info
Format: [CMD_GET_BATT_AND_STORAGE=0x14]
Sourcepub async fn set_time(&self, timestamp: u32) -> Result<MeshCoreEvent>
pub async fn set_time(&self, timestamp: u32) -> Result<MeshCoreEvent>
Set device time
Format: [CMD_SET_DEVICE_TIME=0x06][timestamp: u32]
Sourcepub async fn set_name(&self, name: &str) -> Result<MeshCoreEvent>
pub async fn set_name(&self, name: &str) -> Result<MeshCoreEvent>
Set the device name
Format: [CMD_SET_ADVERT_NAME=0x08][name]
Sourcepub async fn set_coords(&self, lat: f64, lon: f64) -> Result<MeshCoreEvent>
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]
Sourcepub async fn set_tx_power(&self, power: u8) -> Result<MeshCoreEvent>
pub async fn set_tx_power(&self, power: u8) -> Result<MeshCoreEvent>
Set TX power
Format: [CMD_SET_RADIO_TX_POWER=0x0C][power: u8]
Sourcepub async fn send_advert(&self, flood: bool) -> Result<MeshCoreEvent>
pub async fn send_advert(&self, flood: bool) -> Result<MeshCoreEvent>
Send advertisement
Format: [CMD_SEND_SELF_ADVERT=0x07][flood: optional]
Sourcepub async fn reboot(&self) -> Result<()>
pub async fn reboot(&self) -> Result<()>
Reboot device (no response expected)
Format: [CMD_REBOOT=0x13][“reboot”]
Sourcepub async fn get_custom_vars(&self) -> Result<HashMap<String, String>>
pub async fn get_custom_vars(&self) -> Result<HashMap<String, String>>
Get custom variables
Format: [CMD_GET_CUSTOM_VARS=0x28]
Sourcepub async fn set_custom_var(&self, key: &str, value: &str) -> Result<()>
pub async fn set_custom_var(&self, key: &str, value: &str) -> Result<()>
Set a custom variable
Format: [CMD_SET_CUSTOM_VAR=0x29][key=value]
Sourcepub async fn get_channel(&self, channel_idx: u8) -> Result<ChannelInfoData>
pub async fn get_channel(&self, channel_idx: u8) -> Result<ChannelInfoData>
Get channel info
Format: [CMD_GET_CHANNEL=0x1F][channel_idx: u8]
Sourcepub async fn set_channel(
&self,
channel_idx: u8,
name: &str,
secret: &[u8; 16],
) -> Result<()>
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
Sourcepub async fn set_flood_scope(&self, scope: Option<&str>) -> Result<()>
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)
Sourcepub async fn export_private_key(&self) -> Result<[u8; 64]>
pub async fn export_private_key(&self) -> Result<[u8; 64]>
Export private key
Format: [CMD_EXPORT_PRIVATE_KEY=0x17]
Sourcepub async fn import_private_key(&self, key: &[u8; 64]) -> Result<()>
pub async fn import_private_key(&self, key: &[u8; 64]) -> Result<()>
Import private key
Format: [CMD_IMPORT_PRIVATE_KEY=0x18][key: 64 bytes]
Sourcepub async fn get_contacts(
&self,
last_modification_timestamp: u32,
) -> Result<Vec<Contact>>
pub async fn get_contacts( &self, last_modification_timestamp: u32, ) -> Result<Vec<Contact>>
Get the contact list
Sourcepub async fn get_contacts_with_timeout(
&self,
last_modification_timestamp: u32,
timeout: Duration,
) -> Result<Vec<Contact>>
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]
Sourcepub async fn add_contact(&self, contact: &Contact) -> Result<()>
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]
Sourcepub async fn remove_contact(&self, key: impl Into<Destination>) -> Result<()>
pub async fn remove_contact(&self, key: impl Into<Destination>) -> Result<()>
Remove a contact by public key
Format: [CMD_REMOVE_CONTACT=0x0F][pubkey: 32]
Sourcepub async fn export_contact(
&self,
key: Option<impl Into<Destination>>,
) -> Result<String>
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]
Sourcepub async fn import_contact(&self, card_data: &[u8]) -> Result<()>
pub async fn import_contact(&self, card_data: &[u8]) -> Result<()>
Import contact from card data
Format: [CMD_IMPORT_CONTACT=0x12][card_data]
Sourcepub async fn get_msg(&self) -> Result<Option<MeshCoreEvent>>
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::ContactMsgRecv→EventPayload::ContactMessage(msg)EventType::ChannelMsgRecv→EventPayload::ChannelMessage(msg)
Sourcepub async fn get_msg_with_timeout(
&self,
timeout: Duration,
) -> Result<Option<MeshCoreEvent>>
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]
Sourcepub async fn send_msg(
&self,
dest: impl Into<Destination>,
msg: &str,
timestamp: Option<u32>,
) -> Result<MsgSentInfo>
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]
Sourcepub async fn send_channel_msg(
&self,
channel: u8,
msg: &str,
timestamp: Option<u32>,
) -> Result<()>
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]
Sourcepub async fn send_login(
&self,
dest: impl Into<Destination>,
password: &str,
) -> Result<MsgSentInfo>
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]
Sourcepub async fn send_logout(&self, dest: impl Into<Destination>) -> Result<()>
pub async fn send_logout(&self, dest: impl Into<Destination>) -> Result<()>
Send logout request
Format: [CMD_LOGOUT=0x1D][pubkey: 32]
Sourcepub async fn send_binary_req(
&self,
dest: impl Into<Destination>,
req_type: BinaryReqType,
) -> Result<MsgSentInfo>
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]
Sourcepub async fn request_status(
&self,
dest: impl Into<Destination>,
) -> Result<StatusData>
pub async fn request_status( &self, dest: impl Into<Destination>, ) -> Result<StatusData>
Request status from a contact
Sourcepub async fn request_status_with_timeout(
&self,
dest: impl Into<Destination>,
timeout: Duration,
) -> Result<StatusData>
pub async fn request_status_with_timeout( &self, dest: impl Into<Destination>, timeout: Duration, ) -> Result<StatusData>
Request status with the custom timeout
Sourcepub async fn request_telemetry(
&self,
dest: impl Into<Destination>,
) -> Result<Vec<u8>>
pub async fn request_telemetry( &self, dest: impl Into<Destination>, ) -> Result<Vec<u8>>
Request telemetry from a contact
Sourcepub async fn request_telemetry_with_timeout(
&self,
dest: impl Into<Destination>,
timeout: Duration,
) -> Result<Vec<u8>>
pub async fn request_telemetry_with_timeout( &self, dest: impl Into<Destination>, timeout: Duration, ) -> Result<Vec<u8>>
Request telemetry with the custom timeout
Sourcepub async fn request_acl(
&self,
dest: impl Into<Destination>,
) -> Result<Vec<AclEntry>>
pub async fn request_acl( &self, dest: impl Into<Destination>, ) -> Result<Vec<AclEntry>>
Request ACL from a contact
Sourcepub async fn request_acl_with_timeout(
&self,
dest: impl Into<Destination>,
timeout: Duration,
) -> Result<Vec<AclEntry>>
pub async fn request_acl_with_timeout( &self, dest: impl Into<Destination>, timeout: Duration, ) -> Result<Vec<AclEntry>>
Request ACL with the custom timeout
Sourcepub async fn request_neighbours(
&self,
dest: impl Into<Destination>,
count: u16,
offset: u16,
) -> Result<NeighboursData>
pub async fn request_neighbours( &self, dest: impl Into<Destination>, count: u16, offset: u16, ) -> Result<NeighboursData>
Request neighbours from a contact
Sourcepub async fn request_neighbours_with_timeout(
&self,
dest: impl Into<Destination>,
count: u16,
offset: u16,
timeout: Duration,
) -> Result<NeighboursData>
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]
Sourcepub async fn sign_start(&self) -> Result<u32>
pub async fn sign_start(&self) -> Result<u32>
Start a signing session
Format: [CMD_SIGN_START=0x21]
Sourcepub async fn sign_data(&self, chunk: &[u8]) -> Result<()>
pub async fn sign_data(&self, chunk: &[u8]) -> Result<()>
Send data chunk for signing
Format: [CMD_SIGN_DATA=0x22][chunk]