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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
use ants::*;
use ffi;
use std::mem::transmute;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum KI2CNum {
KI2C1,
KI2C2,
KI2C3,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum KANTSAnt {
Ant1,
Ant2,
Ant3,
Ant4,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum KANTSController {
Primary,
Secondary,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct AntsTelemetry {
pub raw_temp: u16,
pub deploy_status: DeployStatus,
pub uptime: u32,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct DeployStatus {
pub sys_burn_active: bool,
pub sys_ignore_deploy: bool,
pub sys_armed: bool,
pub ant_1_not_deployed: bool,
pub ant_1_stopped_time: bool,
pub ant_1_active: bool,
pub ant_2_not_deployed: bool,
pub ant_2_stopped_time: bool,
pub ant_2_active: bool,
pub ant_3_not_deployed: bool,
pub ant_3_stopped_time: bool,
pub ant_3_active: bool,
pub ant_4_not_deployed: bool,
pub ant_4_stopped_time: bool,
pub ant_4_active: bool,
}
named!(parse_status<&[u8], DeployStatus>,
do_parse!(
bits: bits!(
tuple!(
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1),
take_bits!(u8, 1)
)
) >>
(DeployStatus {
sys_burn_active: bits.3 == 1,
sys_ignore_deploy: bits.15 == 1,
sys_armed: bits.7 == 1,
ant_1_not_deployed: bits.8 == 1,
ant_1_stopped_time: bits.9 == 1,
ant_1_active: bits.10 == 1,
ant_2_not_deployed: bits.12 == 1,
ant_2_stopped_time: bits.13 == 1,
ant_2_active: bits.14 == 1,
ant_3_not_deployed: bits.0 == 1,
ant_3_stopped_time: bits.1 == 1,
ant_3_active: bits.2 == 1,
ant_4_not_deployed: bits.4 == 1,
ant_4_stopped_time: bits.5 == 1,
ant_4_active: bits.6 == 1,
})
)
);
impl AntsTelemetry {
#[doc(hidden)]
pub fn new(c_telem: ffi::AntsTelemetry) -> Result<AntsTelemetry, AntsError> {
let raw_status: [u8; 2] = unsafe { transmute(c_telem.deploy_status) };
let status = DeployStatus::new(&raw_status)?;
let telem = AntsTelemetry {
raw_temp: c_telem.raw_temp,
deploy_status: status,
uptime: c_telem.uptime,
};
Ok(telem)
}
}
impl DeployStatus {
#[doc(hidden)]
pub fn new(input: &[u8]) -> Result<DeployStatus, AntsError> {
match parse_status(input) {
Ok(v) => {
let (_input, status) = v;
Ok(status)
}
_ => Err(AntsError::GenericError.into()),
}
}
}
pub fn convert_bus(bus: &str) -> ffi::KI2CNum {
match bus {
"KI2C1" => ffi::KI2CNum::KI2C1,
"KI2C2" => ffi::KI2CNum::KI2C2,
"KI2C3" => ffi::KI2CNum::KI2C3,
_ => ffi::KI2CNum::KI2CNoBus,
}
}
pub fn convert_controller(controller: KANTSController) -> ffi::KANTSController {
match controller {
self::KANTSController::Primary => ffi::KANTSController::Primary,
self::KANTSController::Secondary => ffi::KANTSController::Secondary,
}
}
pub fn convert_antenna(antenna: KANTSAnt) -> ffi::KANTSAnt {
match antenna {
self::KANTSAnt::Ant1 => ffi::KANTSAnt::Ant1,
self::KANTSAnt::Ant2 => ffi::KANTSAnt::Ant2,
self::KANTSAnt::Ant3 => ffi::KANTSAnt::Ant3,
self::KANTSAnt::Ant4 => ffi::KANTSAnt::Ant4,
}
}