tof_control/helper/
rb_type.rs

1use serde::{Deserialize, Serialize};
2
3/// RB Data Type
4// All RB Monitoring Types
5#[derive(Debug, Serialize, Deserialize)]
6pub struct RBMoniData {
7    pub rb_info: RBInfo,
8    pub rb_temp: RBTemp,
9    pub rb_vcp: RBVcp,
10    pub rb_ph: RBPh,
11    pub rb_mag: RBMag,
12}
13// RB Information Data Type
14#[derive(Debug, Serialize, Deserialize)]
15pub struct RBInfo {
16    pub board_id        : u8,
17    pub sub_board       : u8,
18    pub lol             : u8,
19    pub lol_stable      : u8,
20    pub trig_rate       : u16,
21    pub fw_version      : String,
22    pub fw_hash         : String,
23    pub uptime          : u32,
24    pub sd_usage        : u8,
25    pub input_mode      : String,
26    pub rat_num         : u8,
27    pub rat_pos         : u8,
28    pub rb_pos          : u8, 
29}
30// RB Temperature Sensor Data Type
31#[derive(Debug, Serialize, Deserialize)]
32pub struct RBTemp {
33    pub zynq_temp       : f32,
34    pub drs_temp        : f32,
35    pub clk_temp        : f32,
36    pub adc_temp        : f32,
37    pub bme280_temp     : f32,
38    pub lis3mdltr_temp  : f32,
39}
40// RB VCP (Voltage, Current and Power) Sensor Data Type
41#[derive(Debug, Serialize, Deserialize)]
42pub struct RBVcp {
43    pub zynq_vcp        : [f32; 3],
44    pub p3v3_vcp        : [f32; 3],
45    pub p3v5_vcp        : [f32; 3],
46    pub n1v5_vcp        : [f32; 3],
47    pub drs_dvdd_vcp    : [f32; 3],
48    pub drs_avdd_vcp    : [f32; 3],
49    pub adc_dvdd_vcp    : [f32; 3],
50    pub adc_avdd_vcp    : [f32; 3],
51}
52// RB HP (Humidity and Pressure) Sensor Data Type
53#[derive(Debug, Serialize, Deserialize)]
54pub struct RBPh {
55    pub pressure        : f32,
56    pub humidity        : f32,
57}
58// RB Magnetic Sensor Data Type
59#[derive(Debug, Serialize, Deserialize)]
60pub struct RBMag {
61    pub mag_xyz         : [f32; 3],
62}
63
64/// RB Error Type
65#[derive(Debug)]
66pub enum RBError {
67    // Register Error
68    Register(crate::memory::RegisterError),
69    // I2C Error
70    I2C(i2cdev::linux::LinuxI2CError),
71    // JSON Error
72    JSON(serde_json::Error),
73    // ParseInt Error
74    ParseInt(std::num::ParseIntError),
75    // OsString Error
76    OsString,
77}
78
79impl std::fmt::Display for RBError {
80    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81        write!(f, "RBError")
82    }
83}
84
85impl From<crate::memory::RegisterError> for RBError {
86    fn from(e: crate::memory::RegisterError) -> Self {
87        RBError::Register(e)
88    }
89}
90
91impl From<i2cdev::linux::LinuxI2CError> for RBError {
92    fn from(e: i2cdev::linux::LinuxI2CError) -> Self {
93        RBError::I2C(e)
94    }
95}
96
97impl From<serde_json::Error> for RBError {
98    fn from(e: serde_json::Error) -> Self {
99        RBError::JSON(e)
100    }
101}
102
103impl From<std::num::ParseIntError> for RBError {
104    fn from(e: std::num::ParseIntError) -> Self {
105        RBError::ParseInt(e)
106    }
107}
108
109impl From<std::ffi::OsString> for RBError {
110    fn from(_: std::ffi::OsString) -> Self {
111        RBError::OsString
112    }
113}