pni_sdk/
command.rs

1/// The type of command being sent/recieved from the device. All frames have a command.
2#[repr(u8)]
3pub enum Command {
4    /// Queries the device’s type and firmware revision.
5    GetModInfo = 0x01,
6
7    /// Response to GetModInfo
8    GetModInfoResp = 0x02,
9
10    /// Sets the data components to be output
11    SetDataComponents = 0x03,
12
13    /// Queries the TargetPoint3 for data
14    GetData = 0x04,
15
16    /// Response to GetData
17    GetDataResp = 0x05,
18
19    /// Sets internal configurations in TargetPoint3
20    SetConfig = 0x06,
21
22    /// Queries TargetPoint3 for the current internal configuration
23    GetConfig = 0x07,
24
25    /// Response to GetConfig
26    GetConfigResp = 0x08,
27
28    /// Saves the current internal configuration and any new user calibration coefficients to non- volatile memory.
29    Save = 0x09,
30
31    /// Commands the TargetPoint3 to start user calibratio
32    StartCal = 0x0A,
33
34    /// Commands the TargetPoint3 to stop user calibration
35    StopCal = 0x0B,
36
37    /// Sets the FIR filter settings for the magnetometer & accelerometer sensors.
38    SetFIRFilters = 0x0C,
39
40    /// Queries for the FIR filter settings for the magnetometer & accelerometer sensors.
41    GetFIRFilters = 0x0D,
42
43    /// Contains the FIR filter settings for the magnetometer & accelerometer sensors.
44    GetFIRFiltersResp = 0x0E,
45
46    /// Powers down the module
47    PowerDown = 0x0F,
48
49    /// Response to kSave
50    SaveDone = 0x10,
51
52    /// Sent from the TargetPoint3 after taking a calibration sample point
53    UserCalSampleCount = 0x11,
54
55    /// Contains the calibration score
56    UserCalScore = 0x12,
57
58    /// Response to SetConfig
59    SetConfigDone = 0x13,
60
61    /// Response to SetFIRFilters
62    SetFIRFiltersDone = 0x14,
63
64    /// Commands the TargetPoint3 to output data at a fixed interval
65    StartContinuousMode = 0x15,
66
67    /// Stops data output when in Continuous Mode
68    StopContinuousMode = 0x16,
69
70    /// Confirms the TargetPoint3 has received a signal to power up
71    PowerUpDone = 0x17,
72
73    /// Sets the sensor acquisition parameters
74    SetAcqParams = 0x18,
75
76    /// Queries for the sensor acquisition parameters
77    GetAcqParams = 0x19,
78
79    /// Response to SetAcqParams
80    SetAcqParamsDone = 0x1A,
81
82    /// Response to GetAcqParams
83    GetAcqParamsResp = 0x1B,
84
85    /// Response to PowerDown
86    PowerDownDone = 0x1C,
87
88    /// Resets magnetometer calibration coefficients to original factory-established values
89    FactoryMagCoeff = 0x1D,
90
91    /// Response to kFactoryMagCoeff
92    FactoryMagCoeffDone = 0x1E,
93
94    /// Commands the TargetPoint3 to take a sample during user calibration
95    TakeUserCalSample = 0x1F,
96
97    /// Resets accelerometer calibration coefficients to original factory-established values
98    FactorylAccelCoeff = 0x24,
99
100    /// Respond to FactoryAccelCoeff
101    FactoryAccelCoeffDone = 0x25,
102
103    /// Copy one set of calibration coefficient to another set
104    CopyCoeffSet = 0x2B,
105
106    /// Respond to CopyCoeffSet
107    CopyCoeffSetDone = 0x2C,
108
109    /// Request Serial Number of TargetPoint3 unit
110    SerialNumber = 0x34,
111
112    /// Respond to SerialNumber
113    SerialNumberResp = 0x35,
114}
115
116impl Command {
117    // [unsafe]: This code pulls the integer representation of the enum, since the enum is repr(u8)
118    // and the u8 is the first element in the enum, the pointer cast will work. Additionally, this
119    // pattern has been directly copied from the rust documentation for error codes, with modification
120    // only to its parameters and return values
121    // src: https://github.com/rust-lang/rust/blob/master/compiler/rustc_error_codes/src/error_codes/E0732.md
122    pub(crate) fn discriminant(&self) -> u8 {
123        unsafe { *(self as *const Self as *const u8) }
124    }
125}