2023-10-03 07:19:19 +00:00
|
|
|
use std::collections::HashMap;
|
2023-09-28 08:09:33 +00:00
|
|
|
|
|
|
|
use crate::command::CommandRequest;
|
2023-09-26 12:37:59 +00:00
|
|
|
|
2023-09-26 06:30:16 +00:00
|
|
|
pub mod e1;
|
|
|
|
|
2023-10-03 07:19:19 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
|
|
pub enum AttributeValue {
|
|
|
|
String(Option<String>),
|
|
|
|
Bool(bool),
|
|
|
|
Int(u8),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AttributeValue {
|
|
|
|
pub fn set(&mut self, value: impl Into<Self>) {
|
|
|
|
match (self, value.into()) {
|
|
|
|
(Self::String(current), Self::String(new)) => *current = new,
|
|
|
|
(Self::String(current), Self::Bool(new)) => *current = Some(new.to_string()),
|
|
|
|
(Self::String(current), Self::Int(new)) => *current = Some(new.to_string()),
|
|
|
|
(Self::Bool(current), Self::Bool(new)) => *current = new,
|
|
|
|
(Self::Int(current), Self::Int(new)) => *current = new,
|
|
|
|
|
|
|
|
_ => panic!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn str(&self) -> Option<&str> {
|
|
|
|
match self {
|
|
|
|
Self::String(opt) => opt.as_ref().map(|s| s.as_str()),
|
|
|
|
_ => panic!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn bool(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
Self::Bool(bool) => *bool,
|
|
|
|
_ => panic!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn byte(&self) -> u8 {
|
|
|
|
match self {
|
|
|
|
Self::Int(b) => *b,
|
|
|
|
_ => panic!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for AttributeValue {
|
|
|
|
fn from(value: String) -> Self {
|
|
|
|
Self::String(Some(value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Option<String>> for AttributeValue {
|
|
|
|
fn from(value: Option<String>) -> Self {
|
|
|
|
Self::String(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<bool> for AttributeValue {
|
|
|
|
fn from(value: bool) -> Self {
|
|
|
|
Self::Bool(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<u8> for AttributeValue {
|
|
|
|
fn from(value: u8) -> Self {
|
|
|
|
Self::Int(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 06:30:16 +00:00
|
|
|
pub trait DeviceBackend {
|
2023-09-28 18:28:56 +00:00
|
|
|
fn build_query(&self) -> CommandRequest;
|
2023-10-03 07:19:19 +00:00
|
|
|
fn process_message(&mut self, msg: &[u8]);
|
|
|
|
fn attributes(&self) -> &HashMap<&'static str, AttributeValue>;
|
2023-09-26 06:30:16 +00:00
|
|
|
fn set_attribute(&self, attribute: &str, value: &str) -> ();
|
|
|
|
}
|