Add mcutie MQTT client implementation and improve library structure
- Integrated `mcutie` library as a core MQTT client for device communication. - Added support for Home Assistant entities (binary sensor, button) via MQTT. - Implemented buffer management, async operations, and packet encoding/decoding. - Introduced structured error handling and device registration features. - Updated `Cargo.toml` with new dependencies and enabled feature flags for `serde` and `log`. - Enhanced logging macros with configurable options (`defmt` or `log`). - Organized codebase into modules (buffer, components, IO, publish, etc.) for better maintainability.
This commit is contained in:
80
Software/MainBoard/rust/src/mcutie_3_0_0/fmt.rs
Normal file
80
Software/MainBoard/rust/src/mcutie_3_0_0/fmt.rs
Normal file
@@ -0,0 +1,80 @@
|
||||
#![macro_use]
|
||||
|
||||
#[cfg(all(feature = "defmt", feature = "log"))]
|
||||
compile_error!("The `defmt` and `log` features cannot both be enabled at the same time.");
|
||||
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
use core::fmt;
|
||||
|
||||
#[cfg(feature = "defmt")]
|
||||
pub(crate) use ::defmt::Debug2Format;
|
||||
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
pub(crate) struct Debug2Format<D: fmt::Debug>(pub(crate) D);
|
||||
|
||||
#[cfg(feature = "log")]
|
||||
impl<D: fmt::Debug> fmt::Debug for Debug2Format<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[collapse_debuginfo(yes)]
|
||||
macro_rules! trace {
|
||||
($s:literal $(, $x:expr)* $(,)?) => {
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::trace!($s $(, $x)*);
|
||||
#[cfg(feature = "log")]
|
||||
::log::trace!($s $(, $x)*);
|
||||
#[cfg(not(any(feature="defmt", feature="log")))]
|
||||
let _ = ($( & $x ),*);
|
||||
};
|
||||
}
|
||||
|
||||
#[collapse_debuginfo(yes)]
|
||||
macro_rules! debug {
|
||||
($s:literal $(, $x:expr)* $(,)?) => {
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::debug!($s $(, $x)*);
|
||||
#[cfg(feature = "log")]
|
||||
::log::debug!($s $(, $x)*);
|
||||
#[cfg(not(any(feature="defmt", feature="log")))]
|
||||
let _ = ($( & $x ),*);
|
||||
};
|
||||
}
|
||||
|
||||
#[collapse_debuginfo(yes)]
|
||||
macro_rules! info {
|
||||
($s:literal $(, $x:expr)* $(,)?) => {
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::info!($s $(, $x)*);
|
||||
#[cfg(feature = "log")]
|
||||
::log::info!($s $(, $x)*);
|
||||
#[cfg(not(any(feature="defmt", feature="log")))]
|
||||
let _ = ($( & $x ),*);
|
||||
};
|
||||
}
|
||||
|
||||
#[collapse_debuginfo(yes)]
|
||||
macro_rules! warn {
|
||||
($s:literal $(, $x:expr)* $(,)?) => {
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::warn!($s $(, $x)*);
|
||||
#[cfg(feature = "log")]
|
||||
::log::warn!($s $(, $x)*);
|
||||
#[cfg(not(any(feature="defmt", feature="log")))]
|
||||
let _ = ($( & $x ),*);
|
||||
};
|
||||
}
|
||||
|
||||
#[collapse_debuginfo(yes)]
|
||||
macro_rules! error {
|
||||
($s:literal $(, $x:expr)* $(,)?) => {
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::error!($s $(, $x)*);
|
||||
#[cfg(feature = "log")]
|
||||
::log::error!($s $(, $x)*);
|
||||
#[cfg(not(any(feature="defmt", feature="log")))]
|
||||
let _ = ($( & $x ),*);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user