pub struct SupMCUModule<T: I2CDevice + Send + Sync> { /* private fields */ }
Expand description
A struct to represent/interact with a SupMCU Module connected to via I2C
In most cases this struct won’t have to be created manually, but will be
initialized during the creation of a SupMCUMaster
.
This struct has methods for interacting with a module by sending commands as well as requesting and parsing telemetry data. It also handles discovery of a module at a given I2C address.
Many of the methods also have async variants with the same basic functionality. These async methods only really differ in the type of sleep function used: synchronous or asynchronous. The IO is all synchronous because there are no async I2C crates available that I’m aware of.
use supmcu_rs::supmcu::SupMCUModule;
use std::time::Duration;
let mut module = SupMCUModule::new("/dev/i2c-1", 0x35, Some(5))?;
module.send_command("SUP:LED ON");
Implementations§
Source§impl<T> SupMCUModule<T>
impl<T> SupMCUModule<T>
Sourcepub fn send_command<S: AsRef<str>>(&mut self, cmd: S) -> Result<(), SupMCUError>
pub fn send_command<S: AsRef<str>>(&mut self, cmd: S) -> Result<(), SupMCUError>
Sends provided command to the module.
Also appends a trailing newline if one isn’t already present.
Sourcepub fn request_telemetry(
&mut self,
telemetry_type: TelemetryType,
idx: usize,
) -> Result<(), SupMCUError>
pub fn request_telemetry( &mut self, telemetry_type: TelemetryType, idx: usize, ) -> Result<(), SupMCUError>
Requests telemetry from the module using a telemetry definition found in the module definition.
Sourcepub fn get_telemetry(
&mut self,
telemetry_type: TelemetryType,
idx: usize,
) -> Result<SupMCUTelemetry, SupMCUError>
pub fn get_telemetry( &mut self, telemetry_type: TelemetryType, idx: usize, ) -> Result<SupMCUTelemetry, SupMCUError>
Requests and parses telemetry from the module using a telemetry definition found in the module definition.
Sourcepub async fn get_telemetry_async(
&mut self,
telemetry_type: TelemetryType,
idx: usize,
) -> Result<SupMCUTelemetry, SupMCUError>
pub async fn get_telemetry_async( &mut self, telemetry_type: TelemetryType, idx: usize, ) -> Result<SupMCUTelemetry, SupMCUError>
Requests and parses telemetry from the module using a telemetry definition found in the module definition.
Sourcepub fn request_telemetry_by_def(
&mut self,
def: &SupMCUTelemetryDefinition,
) -> Result<(), SupMCUError>
pub fn request_telemetry_by_def( &mut self, def: &SupMCUTelemetryDefinition, ) -> Result<(), SupMCUError>
Requests telemetry from the module using the provided definitions.
Sourcepub fn get_telemetry_by_def(
&mut self,
def: &SupMCUTelemetryDefinition,
) -> Result<SupMCUTelemetry, SupMCUError>
pub fn get_telemetry_by_def( &mut self, def: &SupMCUTelemetryDefinition, ) -> Result<SupMCUTelemetry, SupMCUError>
Requests and parses telemetry from the module using the provided definition.
Sourcepub async fn get_telemetry_by_def_async(
&mut self,
def: &SupMCUTelemetryDefinition,
) -> Result<SupMCUTelemetry, SupMCUError>
pub async fn get_telemetry_by_def_async( &mut self, def: &SupMCUTelemetryDefinition, ) -> Result<SupMCUTelemetry, SupMCUError>
Requests and parses telemetry from the module using the provided definition asynchronously
Sourcepub fn get_all_telemetry(
&mut self,
) -> Result<HashMap<String, Json<SupMCUTelemetryData>>, SupMCUError>
pub fn get_all_telemetry( &mut self, ) -> Result<HashMap<String, Json<SupMCUTelemetryData>>, SupMCUError>
Requests and parses all telemetry from the module
Sourcepub fn get_telemetry_by_names(
&mut self,
names: Vec<String>,
) -> Result<HashMap<String, Json<SupMCUTelemetryData>>, SupMCUError>
pub fn get_telemetry_by_names( &mut self, names: Vec<String>, ) -> Result<HashMap<String, Json<SupMCUTelemetryData>>, SupMCUError>
Requests and parses telemetry by name from module
Sourcepub async fn get_all_telemetry_async(
&mut self,
) -> Result<Vec<Result<SupMCUTelemetry, SupMCUError>>, SupMCUError>
pub async fn get_all_telemetry_async( &mut self, ) -> Result<Vec<Result<SupMCUTelemetry, SupMCUError>>, SupMCUError>
Requests and parses all telemetry from the module asynchronously
Sourcepub fn read_telemetry_response(
&mut self,
def: &SupMCUTelemetryDefinition,
) -> Result<SupMCUTelemetry, SupMCUError>
pub fn read_telemetry_response( &mut self, def: &SupMCUTelemetryDefinition, ) -> Result<SupMCUTelemetry, SupMCUError>
Reads a response to a telemetry request from the module.
Sourcepub async fn read_telemetry_response_safe_async(
&mut self,
def: &SupMCUTelemetryDefinition,
) -> Result<SupMCUTelemetry, SupMCUError>
pub async fn read_telemetry_response_safe_async( &mut self, def: &SupMCUTelemetryDefinition, ) -> Result<SupMCUTelemetry, SupMCUError>
Reads a response to a telemetry request and retries the request asynchronously if it comes back non-ready.
Sourcepub fn read_telemetry_response_safe(
&mut self,
def: &SupMCUTelemetryDefinition,
) -> Result<SupMCUTelemetry, SupMCUError>
pub fn read_telemetry_response_safe( &mut self, def: &SupMCUTelemetryDefinition, ) -> Result<SupMCUTelemetry, SupMCUError>
Reads a response to a telemetry request and retries the request if it comes back non-ready.
Sourcepub fn get_definition_mut(
&mut self,
) -> Result<&mut SupMCUModuleDefinition, SupMCUError>
pub fn get_definition_mut( &mut self, ) -> Result<&mut SupMCUModuleDefinition, SupMCUError>
Returns the module definition as a mutable reference
Sourcepub fn get_definition(&self) -> Result<&SupMCUModuleDefinition, SupMCUError>
pub fn get_definition(&self) -> Result<&SupMCUModuleDefinition, SupMCUError>
Returns the module definition as a immutable reference
Sourcepub fn set_definition(&mut self, def: SupMCUModuleDefinition)
pub fn set_definition(&mut self, def: SupMCUModuleDefinition)
Sets the module definition
Sourcepub fn matches(&self, other: &SupMCUModuleDefinition) -> bool
pub fn matches(&self, other: &SupMCUModuleDefinition) -> bool
Check if the module fits a particular definition, will match if addr OR cmd_name match
Sourcepub fn get_address(&self) -> u16
pub fn get_address(&self) -> u16
Returns the address
Source§impl SupMCUModule<LinuxI2CDevice>
impl SupMCUModule<LinuxI2CDevice>
Sourcepub fn new(
device: &str,
address: u16,
max_retries: Option<u8>,
) -> Result<Self, SupMCUError>
pub fn new( device: &str, address: u16, max_retries: Option<u8>, ) -> Result<Self, SupMCUError>
Creates a new SupMCUModule
Sourcepub fn new_from_def(
device: &str,
max_retries: Option<u8>,
def: SupMCUModuleDefinition,
) -> Result<Self, SupMCUError>
pub fn new_from_def( device: &str, max_retries: Option<u8>, def: SupMCUModuleDefinition, ) -> Result<Self, SupMCUError>
Creates a new SupMCUModule from a SupMCUModuleDefinition
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for SupMCUModule<T>
impl<T> RefUnwindSafe for SupMCUModule<T>where
T: RefUnwindSafe,
impl<T> Send for SupMCUModule<T>
impl<T> Sync for SupMCUModule<T>
impl<T> Unpin for SupMCUModule<T>
impl<T> UnwindSafe for SupMCUModule<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more