1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Responses to commands

/// Response to `get_fw_version()`
#[derive(Debug)]
pub struct FwVersion {
    /// Major version
    pub major: u8,
    /// Minor version
    pub minor: u8,
    /// Hardware version
    pub hw: [u8; 10],
    /// 96 bit ID of MCU
    pub uuid: [u8; 12],
}

/// Response to `get_values()`
#[derive(Debug)]
pub struct Values {
    /// FET temperature in C
    pub temp_fet: f32,
    /// Motor temperature in C
    pub temp_motor: f32,
    /// Motor current in A
    pub motor_current: f32,
    /// Input current in A
    pub input_current: f32,
    /// ?
    pub id: f32,
    /// ?
    pub iq: f32,
    /// Motor duty cycle
    pub duty_cycle: f32,
    /// Motor RPM
    pub rpm: f32,
    /// Input voltage in V
    pub input_voltage: f32,
    /// Amp hours drawn in Ah
    pub amp_hours: f32,
    /// Amp hours charged in Ah
    pub amp_hours_charged: f32,
    /// Watt hours drawn in Wh
    pub watt_hours: f32,
    /// Watt hours charged in Wh
    pub watt_hours_charged: f32,
    /// Motor tachometer
    pub tachometer: u32,
    /// Absolute reading of motor tachometer
    pub tachometer_abs: u32,
    /// Fault state of controller
    pub fault: Fault,
    /// Motor position ?
    pub pid_pos: f32,
    /// ID of controller
    pub controller_id: u8,
}

/// Controller faults
#[derive(Debug)]
pub enum Fault {
    /// No faults
    None,
    /// Input voltage too high
    OverVoltage,
    /// Input voltage too low
    UnderVoltage,
    /// DRV error
    Drv,
    /// Current too high
    AbsOverCurrent,
    /// FET temperature too high
    OverTempFet,
    /// Motor temperature too high
    OverTempMotor,
}