1use num_enum::IntoPrimitive;
2use num_enum::TryFromPrimitive;
3use std::convert::TryFrom;
4use byteorder::{ByteOrder, LittleEndian};
5
6
7#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
9#[repr(u32)]
10pub enum ModelNumber {
11 None = 0x00000000,
12
13 Drone3DroneP1 = 0x00031001, Drone3DroneP2 = 0x00031002, Drone3DroneP3 = 0x00031003, Drone3DroneP4 = 0x00031004, Drone3DroneP5 = 0x00031005, Drone3DroneP6 = 0x00031006, Drone3DroneP7 = 0x00031007, Drone3DroneP8 = 0x00031008, Drone3DroneP9 = 0x00031009, Drone3DroneP10 = 0x0003100A, Drone3ControllerP1 = 0x00032001, Drone3ControllerP2 = 0x00032002, Drone3ControllerP3 = 0x00032003, Drone3ControllerP4 = 0x00032004, Drone3ControllerP5 = 0x00032005, Drone3LinkP0 = 0x00033000, Drone3AnalyzerP0 = 0x00034100, Drone3TesterP4 = 0x0003A004, Drone3TesterP6 = 0x0003A006, Drone3TesterP7 = 0x0003A007, Drone4DroneP5 = 0x00041005, Drone4DroneP6 = 0x00041006, Drone4DroneP7 = 0x00041007, Drone4ControllerP2 = 0x00042002, Drone4ControllerP3 = 0x00042003, Drone4ControllerP4 = 0x00042004, Drone4ControllerP5 = 0x00042005, Drone4LinkP0 = 0x00043000, Drone4TesterP6 = 0x0004A006, Drone4TesterP7 = 0x0004A007, Drone7DroneP2 = 0x00071002, Drone7BleClientP0 = 0x00073200, Drone7BleClientP5 = 0x00073205, Drone7BleServerP2 = 0x00073302, Drone7TesterP5 = 0x0007A005, Drone7TesterP6 = 0x0007A006, Drone7MonitorP4 = 0x0007A104, Drone7MonitorP5 = 0x0007A105, Drone8DroneP0 = 0x00081000, Drone8DroneP1 = 0x00081001, Drone8TesterP6 = 0x0008A006, Drone8MonitorP6 = 0x0008A106, Drone9DroneP0 = 0x00091000, Drone9DroneP1 = 0x00091001, Drone9DroneP2 = 0x00091002, Drone9DroneP3 = 0x00091003, Drone9DroneP4 = 0x00091004, Drone9DroneP5 = 0x00091005, Drone9TesterP6 = 0x0009A006, Drone9TesterP7 = 0x0009A007, }
83
84
85impl ModelNumber {
86 pub fn from_u32(data_u32: u32) -> ModelNumber {
101 match ModelNumber::try_from( data_u32 ) {
102 Ok(data) => { data },
103 _ => { ModelNumber::None },
104 }
105 }
106
107 pub fn to_array(&self) -> [u8; 4] {
108 let mut buf = [0; 4];
109 LittleEndian::write_u32(&mut buf, self.clone().into());
110 buf
111 }
112
113 pub fn get_device_type(&self) -> DeviceType {
114 DeviceType::from_u8(self.to_array()[1])
115 }
116}
117
118
119#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
121#[repr(u8)]
122pub enum DeviceType {
123 None = 0x00,
124
125 Drone = 0x10, Controller = 0x20, LinkClient = 0x30, LinkServer = 0x31, BleClient = 0x32, BleServer = 0x33, Range = 0x40, Analyzer = 0x41, Base = 0x70, Base2 = 0x71, ByScratch = 0x80, Scratch = 0x81, Entry = 0x82, Tester = 0xA0, Monitor = 0xA1, Updater = 0xA2, Encrypter = 0xA3, UWB = 0xE0, Whispering = 0xFE, Broadcasting = 0xFF, }
154
155
156impl DeviceType {
157 pub fn from_u8(data_u8: u8) -> DeviceType {
159 match DeviceType::try_from( data_u8 ) {
160 Ok(data) => { data },
161 _ => { DeviceType::None },
162 }
163 }
164}
165
166
167
168#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
170#[repr(u8)]
171pub enum ModeSystem {
172 None = 0x00, Boot = 0x10,
175 Start = 0x11,
176 Running = 0x12,
177 ReadyToReset = 0x13,
178
179 Error = 0xA0,
180}
181
182
183impl ModeSystem {
184 pub fn from_u8(data_u8: u8) -> ModeSystem {
185 match ModeSystem::try_from( data_u8 ) {
186 Ok(data) => { data },
187 _ => { ModeSystem::None },
188 }
189 }
190}
191
192
193
194#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
196#[repr(u8)]
197pub enum ModeControlFlight {
198 None = 0x00, Attitude = 0x10, Position = 0x11, Manual = 0x12, Rate = 0x13, Function = 0x14, Error = 0xA0,
207}
208
209
210impl ModeControlFlight {
211 pub fn from_u8(data_u8: u8) -> ModeControlFlight {
212 match ModeControlFlight::try_from( data_u8 ) {
213 Ok(data) => { data },
214 _ => { ModeControlFlight::None },
215 }
216 }
217}
218
219
220
221#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
223#[repr(u8)]
224pub enum ModeFlight {
225 None = 0x00,
226
227 Ready = 0x10,
228
229 Start = 0x11,
230 Takeoff = 0x12,
231 Flight = 0x13,
232 Landing = 0x14,
233 Flip = 0x15,
234 Reverse = 0x16,
235
236 Stop = 0x20,
237
238 Accident = 0x30,
239 Error = 0x31,
240
241 Test = 0x40,
242}
243
244
245impl ModeFlight {
246 pub fn from_u8(data_u8: u8) -> ModeFlight {
247 match ModeFlight::try_from( data_u8 ) {
248 Ok(data) => { data },
249 _ => { ModeFlight::None },
250 }
251 }
252}
253
254
255#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
257#[repr(u8)]
258pub enum ModeMovement {
259 None = 0x00,
260
261 Ready = 0x01,
262 Hovering = 0x02,
263 Moving = 0x03,
264 ReturnHome = 0x04
265}
266
267
268impl ModeMovement {
269 pub fn from_u8(data_u8: u8) -> ModeMovement {
270 match ModeMovement::try_from( data_u8 ) {
271 Ok(data) => { data },
272 _ => { ModeMovement::None },
273 }
274 }
275}
276
277
278#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
280#[repr(u8)]
281pub enum ModeUpdate {
282 None = 0x00, Ready = 0x01, Update = 0x02, Complete = 0x03, Failed = 0x04, NotAvailable = 0x05, RunApplication = 0x06, NotRegistered = 0x07, EndOfType = 0x08,
295}
296
297
298impl ModeUpdate {
299 pub fn from_u8(data_u8: u8) -> ModeUpdate {
300 match ModeUpdate::try_from( data_u8 ) {
301 Ok(data) => { data },
302 _ => { ModeUpdate::None },
303 }
304 }
305}
306
307
308#[derive(Debug, Copy, Clone)]
310pub struct Version {
311 pub build: u16,
312 pub minor: u8,
313 pub major: u8,
314}
315
316
317impl Version {
318 pub fn from_slice(data_array: &[u8]) -> Version {
319 if data_array.len() == 4 {
320 Version {
321 build: LittleEndian::read_u16(&data_array[0..2]),
322 minor: data_array[2],
323 major: data_array[3],
324 }
325 }
326 else {
327 Version {
328 build: 1,
329 minor: 1,
330 major: 21,
331 }
332 }
333 }
334
335 pub fn from_u32(version: u32) -> Version {
336 Version {
337 build: (version & 0xFFFF) as u16,
338 minor: ((version >> 16) & 0xFF) as u8,
339 major: ((version >> 24) & 0xFF) as u8,
340 }
341 }
342
343 pub fn to_array(&self) -> [u8; 4] {
344 let mut buf = [0; 4];
345 LittleEndian::write_u32(&mut buf, self.to_u32());
346 buf
347 }
348
349 pub fn to_u32(&self) -> u32 {
350 ((self.major as u32) << 24) | ((self.minor as u32) << 16) | self.build as u32
351 }
352}
353
354
355#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
357#[repr(u32)]
358pub enum ErrorFlagsForSensor {
359 None = 0x00000000,
360
361 MotionNoAnswer = 0x00000001, MotionWrongValue = 0x00000002, MotionNotCalibrated = 0x00000004, MotionCalibrating = 0x00000008, PressureNoAnswer = 0x00000010, PressureWrongValue = 0x00000020, RangeGroundNoAnswer = 0x00000100, RangeGroundWrongValue = 0x00000200, RangeFrontNoAnswer = 0x00000400, RangeFrontWrongValue = 0x00000800, FlowNoAnswer = 0x00001000, FlowWrongValue = 0x00002000, FlowCannotRecognizeGroundImage = 0x00004000, RfNoAnswer = 0x10000000, RfPaired = 0x20000000, RfConnected = 0x40000000, }
382
383
384impl ErrorFlagsForSensor {
385 pub fn from_u8(data_u32: u32) -> ErrorFlagsForSensor {
386 match ErrorFlagsForSensor::try_from( data_u32 ) {
387 Ok(data) => { data },
388 _ => { ErrorFlagsForSensor::None },
389 }
390 }
391}
392
393
394#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
396#[repr(u32)]
397pub enum ErrorFlagsForState {
398 None = 0x00000000,
399
400 NotRegistered = 0x00000001, FlashReadLockUnLocked = 0x00000002, BootloaderWriteLockUnLocked = 0x00000004, LowBattery = 0x00000008, TakeoffFailureCheckPropellerAndMotor = 0x00000010, CheckPropellerVibration = 0x00000020, AttitudeNotStable = 0x00000040, CanNotFlipLowBattery = 0x00000100, CanNotFlipTooHeavy = 0x00000200, }
412
413
414impl ErrorFlagsForState {
415 pub fn from_u8(data_u32: u32) -> ErrorFlagsForState {
416 match ErrorFlagsForState::try_from( data_u32 ) {
417 Ok(data) => { data },
418 _ => { ErrorFlagsForState::None },
419 }
420 }
421}
422
423
424
425#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
427#[repr(u8)]
428pub enum Direction {
429 None = 0,
430
431 Left,
432 Front,
433 Right,
434 Rear,
435
436 Top,
437 Bottom,
438
439 Center,
440}
441
442
443impl Direction {
444 pub fn from_u8(data_u8: u8) -> Direction {
445 match Direction::try_from( data_u8 ) {
446 Ok(data) => { data },
447 _ => { Direction::None },
448 }
449 }
450}
451
452
453
454#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
456#[repr(u8)]
457pub enum Rotation {
458 None = 0x00,
459
460 Clockwise = 0x01, Counterclockwise = 0x02, }
463
464
465impl Rotation {
466 pub fn from_u8(data_u8: u8) -> Rotation {
467 match Rotation::try_from( data_u8 ) {
468 Ok(data) => { data },
469 _ => { Rotation::None },
470 }
471 }
472}
473
474
475#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
477#[repr(u8)]
478pub enum FlightEvent {
479 None = 0x00, Stop = 0x10, Takeoff = 0x11, Landing = 0x12, Reverse = 0x14, FlipFront = 0x15, FlipRear = 0x16, FlipLeft = 0x17, FlipRight = 0x18, ReturnHone = 0x19, Shot = 0x90, UnderAttack = 0x91, ResetHeading = 0xA0, }
499
500
501impl FlightEvent {
502 pub fn from_u8(data_u8: u8) -> FlightEvent {
503 match FlightEvent::try_from( data_u8 ) {
504 Ok(data) => { data },
505 _ => { FlightEvent::None },
506 }
507 }
508}
509
510
511#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
513#[repr(u8)]
514pub enum SensorOrientation {
515 None = 0, Normal, ReverseStart, Reversed, }
521
522
523impl SensorOrientation {
524 pub fn from_u8(data_u8: u8) -> SensorOrientation {
525 match SensorOrientation::try_from( data_u8 ) {
526 Ok(data) => { data },
527 _ => { SensorOrientation::None },
528 }
529 }
530}
531
532
533#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
535#[repr(u8)]
536pub enum Headless {
537 None = 0, Headless, Normal, }
542
543
544impl Headless {
545 pub fn from_u8(data_u8: u8) -> Headless {
546 match Headless::try_from( data_u8 ) {
547 Ok(data) => { data },
548 _ => { Headless::None },
549 }
550 }
551}
552
553
554#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
556#[repr(u8)]
557pub enum TrimDirection {
558 None = 0, RollIncrease, RollDecrease, PitchIncrease, PitchDecrease, YawIncrease, YawDecrease, ThrottleIncrease, ThrottleDecrease, Reset, }
571
572
573impl TrimDirection {
574 pub fn from_u8(data_u8: u8) -> TrimDirection {
575 match TrimDirection::try_from( data_u8 ) {
576 Ok(data) => { data },
577 _ => { TrimDirection::None },
578 }
579 }
580}
581
582