hs added stub info grabber
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ edition = "2021"
|
|||||||
path = "src/hs.rs"
|
path = "src/hs.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = []
|
||||||
std = ["dep:sysinfo", "dep:watchdog-device"]
|
std = ["dep:sysinfo", "dep:watchdog-device"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
+3
-18
@@ -5,28 +5,13 @@ use msg::{HsCmd, HsHk, HsOutData, Msg, MsgKind, TargetMsg};
|
|||||||
use rfe::*;
|
use rfe::*;
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use alloc::vec::Vec;
|
|
||||||
|
|
||||||
mod watchdog;
|
mod watchdog;
|
||||||
use utils::ManualAuto;
|
use utils::ManualAuto;
|
||||||
pub use watchdog::*;
|
pub use watchdog::*;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
mod infograbber;
|
||||||
mod hs_std;
|
pub use infograbber::*;
|
||||||
#[cfg(feature = "std")]
|
|
||||||
pub use hs_std::*;
|
|
||||||
|
|
||||||
#[cfg(not(any(feature = "std")))]
|
|
||||||
mod hs_stub;
|
|
||||||
#[cfg(not(any(feature = "std")))]
|
|
||||||
pub use hs_stub::*;
|
|
||||||
|
|
||||||
pub trait SystemInfoGrabber {
|
|
||||||
fn check_cpu_usage(&mut self) -> Vec<u8>;
|
|
||||||
fn check_mem_usage(&mut self) -> u8;
|
|
||||||
fn check_fs_usage(&mut self) -> Vec<u8>;
|
|
||||||
fn check_temps(&mut self) -> Vec<i8>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct HsData {
|
pub struct HsData {
|
||||||
@@ -58,12 +43,12 @@ impl<'a> Hs<'a> {
|
|||||||
grabber: &'a mut dyn SystemInfoGrabber,
|
grabber: &'a mut dyn SystemInfoGrabber,
|
||||||
mut watchdog: WatchdogRef<'a>,
|
mut watchdog: WatchdogRef<'a>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
watchdog.set_timeout(config.watchdog_timeout);
|
||||||
if config.watchdog_enable {
|
if config.watchdog_enable {
|
||||||
watchdog.enable();
|
watchdog.enable();
|
||||||
} else {
|
} else {
|
||||||
watchdog.disable();
|
watchdog.disable();
|
||||||
}
|
}
|
||||||
watchdog.set_timeout(config.watchdog_timeout);
|
|
||||||
Self {
|
Self {
|
||||||
data: Default::default(),
|
data: Default::default(),
|
||||||
config,
|
config,
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
use sysinfo::{Components, CpuRefreshKind, Disks, MemoryRefreshKind, RefreshKind, System};
|
|
||||||
|
|
||||||
use crate::SystemInfoGrabber;
|
|
||||||
extern crate alloc;
|
|
||||||
use alloc::vec::Vec;
|
|
||||||
|
|
||||||
pub struct StdSystemInfoGrabber {
|
|
||||||
system: System,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StdSystemInfoGrabber {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
system: System::new_with_specifics(
|
|
||||||
RefreshKind::new()
|
|
||||||
.with_cpu(CpuRefreshKind::new().with_cpu_usage())
|
|
||||||
.with_memory(MemoryRefreshKind::new().with_ram()),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SystemInfoGrabber for StdSystemInfoGrabber {
|
|
||||||
fn check_cpu_usage(&mut self) -> Vec<u8> {
|
|
||||||
self.system.refresh_cpu_usage();
|
|
||||||
self.system
|
|
||||||
.cpus()
|
|
||||||
.iter()
|
|
||||||
.map(|x| x.cpu_usage().round() as u8)
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_mem_usage(&mut self) -> u8 {
|
|
||||||
self.system.refresh_memory();
|
|
||||||
(self.system.used_memory() * 100 / self.system.total_memory()) as u8
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_fs_usage(&mut self) -> Vec<u8> {
|
|
||||||
let mut disks = Disks::new_with_refreshed_list();
|
|
||||||
let disks = disks.list_mut();
|
|
||||||
disks.sort_by(|x, y| x.name().cmp(y.name()));
|
|
||||||
|
|
||||||
disks
|
|
||||||
.iter()
|
|
||||||
.map(|x| ((x.total_space() - x.available_space()) * 100 / x.total_space()) as u8)
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_temps(&mut self) -> Vec<i8> {
|
|
||||||
let mut components = Components::new_with_refreshed_list();
|
|
||||||
let components = components.list_mut();
|
|
||||||
components.sort_by(|x, y| x.label().cmp(y.label()));
|
|
||||||
|
|
||||||
components
|
|
||||||
.iter()
|
|
||||||
.map(|x| x.temperature().round() as i8)
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
extern crate alloc;
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
pub trait SystemInfoGrabber {
|
||||||
|
fn check_cpu_usage(&mut self) -> Vec<u8>;
|
||||||
|
fn check_mem_usage(&mut self) -> u8;
|
||||||
|
fn check_fs_usage(&mut self) -> Vec<u8>;
|
||||||
|
fn check_temps(&mut self) -> Vec<i8>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std"))]
|
||||||
|
mod infograbber_std {
|
||||||
|
use sysinfo::{Components, CpuRefreshKind, Disks, MemoryRefreshKind, RefreshKind, System};
|
||||||
|
|
||||||
|
use crate::SystemInfoGrabber;
|
||||||
|
extern crate alloc;
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
pub struct StdSystemInfoGrabber {
|
||||||
|
system: System,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StdSystemInfoGrabber {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
system: System::new_with_specifics(
|
||||||
|
RefreshKind::new()
|
||||||
|
.with_cpu(CpuRefreshKind::new().with_cpu_usage())
|
||||||
|
.with_memory(MemoryRefreshKind::new().with_ram()),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SystemInfoGrabber for StdSystemInfoGrabber {
|
||||||
|
fn check_cpu_usage(&mut self) -> Vec<u8> {
|
||||||
|
self.system.refresh_cpu_usage();
|
||||||
|
self.system
|
||||||
|
.cpus()
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.cpu_usage().round() as u8)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_mem_usage(&mut self) -> u8 {
|
||||||
|
self.system.refresh_memory();
|
||||||
|
(self.system.used_memory() * 100 / self.system.total_memory()) as u8
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_fs_usage(&mut self) -> Vec<u8> {
|
||||||
|
let mut disks = Disks::new_with_refreshed_list();
|
||||||
|
let disks = disks.list_mut();
|
||||||
|
disks.sort_by(|x, y| x.name().cmp(y.name()));
|
||||||
|
|
||||||
|
disks
|
||||||
|
.iter()
|
||||||
|
.map(|x| ((x.total_space() - x.available_space()) * 100 / x.total_space()) as u8)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_temps(&mut self) -> Vec<i8> {
|
||||||
|
let mut components = Components::new_with_refreshed_list();
|
||||||
|
let components = components.list_mut();
|
||||||
|
components.sort_by(|x, y| x.label().cmp(y.label()));
|
||||||
|
|
||||||
|
components
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.temperature().round() as i8)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std"))]
|
||||||
|
pub use infograbber_std::*;
|
||||||
|
|
||||||
|
pub struct StubSystemInfoGrabber;
|
||||||
|
impl SystemInfoGrabber for StubSystemInfoGrabber {
|
||||||
|
fn check_cpu_usage(&mut self) -> Vec<u8> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_mem_usage(&mut self) -> u8 {
|
||||||
|
255
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_fs_usage(&mut self) -> Vec<u8> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_temps(&mut self) -> Vec<i8> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ rfe.features = ["std"]
|
|||||||
example.path = "../../apps/example"
|
example.path = "../../apps/example"
|
||||||
ds.path = "../../apps/ds"
|
ds.path = "../../apps/ds"
|
||||||
hs.path = "../../apps/hs"
|
hs.path = "../../apps/hs"
|
||||||
|
hs.features = ["std"]
|
||||||
to.path = "../../apps/to"
|
to.path = "../../apps/to"
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
hashbrown.workspace = true
|
hashbrown.workspace = true
|
||||||
|
|||||||
Reference in New Issue
Block a user