Struct SupMCUModule

Source
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>
where T: I2CDevice + Send + Sync,

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn request_telemetry_by_def( &mut self, def: &SupMCUTelemetryDefinition, ) -> Result<(), SupMCUError>

Requests telemetry from the module using the provided definitions.

Source

pub fn get_telemetry_by_def( &mut self, def: &SupMCUTelemetryDefinition, ) -> Result<SupMCUTelemetry, SupMCUError>

Requests and parses telemetry from the module using the provided definition.

Source

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

Source

pub fn get_all_telemetry( &mut self, ) -> Result<HashMap<String, Json<SupMCUTelemetryData>>, SupMCUError>

Requests and parses all telemetry from the module

Source

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

Source

pub async fn get_all_telemetry_async( &mut self, ) -> Result<Vec<Result<SupMCUTelemetry, SupMCUError>>, SupMCUError>

Requests and parses all telemetry from the module asynchronously

Source

pub fn read_telemetry_response( &mut self, def: &SupMCUTelemetryDefinition, ) -> Result<SupMCUTelemetry, SupMCUError>

Reads a response to a telemetry request from the module.

Source

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.

Source

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.

Source

pub fn get_definition_mut( &mut self, ) -> Result<&mut SupMCUModuleDefinition, SupMCUError>

Returns the module definition as a mutable reference

Source

pub fn get_definition(&self) -> Result<&SupMCUModuleDefinition, SupMCUError>

Returns the module definition as a immutable reference

Source

pub fn set_definition(&mut self, def: SupMCUModuleDefinition)

Sets the module definition

Source

pub fn matches(&self, other: &SupMCUModuleDefinition) -> bool

Check if the module fits a particular definition, will match if addr OR cmd_name match

Source

pub fn get_address(&self) -> u16

Returns the address

Source§

impl SupMCUModule<LinuxI2CDevice>

Source

pub fn new( device: &str, address: u16, max_retries: Option<u8>, ) -> Result<Self, SupMCUError>

Creates a new SupMCUModule

Source

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§

Source§

impl<T> Debug for SupMCUModule<T>
where T: I2CDevice + Send + Sync,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.