use crate::{Error, MacAddr, Result};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum DeviceId {
Mac(MacAddr),
Name(String),
}
impl core::str::FromStr for DeviceId {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
Ok(s.parse()
.map(Self::Mac)
.unwrap_or_else(|_| Self::Name(s.into())))
}
}
impl From<MacAddr> for DeviceId {
fn from(mac: MacAddr) -> Self {
Self::Mac(mac)
}
}
impl From<&'_ str> for DeviceId {
fn from(name: &'_ str) -> Self {
Self::Name(name.into())
}
}
impl From<String> for DeviceId {
fn from(name: String) -> Self {
Self::Name(name)
}
}
impl core::fmt::Display for DeviceId {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Self::Mac(mac) => mac.fmt(f),
Self::Name(name) => name.fmt(f),
}
}
}
#[derive(Clone, Default, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DeviceInfo {
pub device_model: String,
pub hardware_version: String,
pub software_version: String,
pub up_time: usize,
pub poweron_times: usize,
pub device_name: String,
pub device_passcode: String,
pub manufacturing_date: String,
pub serial_number: String,
pub passcode: String,
pub userdata: String,
pub setup_passcode: String,
pub userdata2: String,
}
#[derive(Clone, Default, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct CellData {
pub cell_voltage: Vec<f32>,
pub average_cell_voltage: f32,
pub delta_cell_voltage: f32,
pub balance_current: f32,
pub cell_resistance: Vec<f32>,
pub battery_voltage: f32,
pub battery_power: f32,
pub battery_current: f32,
pub battery_temperature: Vec<f32>,
pub mosfet_temperature: f32,
pub remain_percent: u8,
pub remain_capacity: f32,
pub nominal_capacity: f32,
pub cycle_count: usize,
pub cycle_capacity: f32,
pub up_time: usize,
}