dji_log_parser/layout/
auxiliary.rs1use binrw::binread;
2use serde::Serialize;
3
4use crate::decoder::XorDecoder;
5
6#[binread]
7#[derive(Debug)]
8#[br(little)]
9pub(crate) enum Auxiliary {
10 #[br(magic = 0u8)]
11 Info(
12 #[br(temp)] u16,
13 #[br(pad_size_to = self_0, map_stream = |reader| XorDecoder::new(reader, 0))] AuxiliaryInfo,
14 ),
15
16 #[br(magic = 1u8)]
17 Version(
18 #[br(temp)] u16,
19 #[br(pad_size_to = self_0)] AuxiliaryVersion,
20 ),
21}
22
23#[binread]
24#[derive(Debug)]
25#[br(little)]
26pub(crate) struct AuxiliaryInfo {
27 pub version_data: u8,
28 #[br(temp)]
29 info_length: u16,
30 #[br(count = info_length)]
31 pub info_data: Vec<u8>,
32 #[br(temp)]
33 signature_length: u16,
34 #[br(count = signature_length)]
35 pub signature_data: Vec<u8>,
36}
37
38#[binread]
39#[derive(Debug)]
40#[br(little)]
41pub(crate) struct AuxiliaryVersion {
42 pub version: u16,
43 #[br(map = |x: u8| Department::from(x))]
44 pub department: Department,
45}
46
47#[derive(Serialize, Debug, Clone, PartialEq)]
48pub enum Department {
49 SDK,
50 DJIGO,
51 DJIFly,
52 AgriculturalMachinery,
53 Terra,
54 DJIGlasses,
55 DJIPilot,
56 GSPro,
57 #[serde(untagged)]
58 Unknown(u8),
59}
60
61impl From<u8> for Department {
62 fn from(num: u8) -> Self {
63 match num {
64 1 => Department::SDK,
65 2 => Department::DJIGO,
66 3 => Department::DJIFly,
67 4 => Department::AgriculturalMachinery,
68 5 => Department::Terra,
69 6 => Department::DJIGlasses,
70 7 => Department::DJIPilot,
71 8 => Department::GSPro,
72 _ => Department::Unknown(num),
73 }
74 }
75}
76
77impl From<Department> for u8 {
78 fn from(department: Department) -> Self {
79 match department {
80 Department::SDK => 1,
81 Department::DJIGO => 2,
82 Department::DJIFly => 3,
83 Department::AgriculturalMachinery => 4,
84 Department::Terra => 5,
85 Department::DJIGlasses => 6,
86 Department::DJIPilot => 7,
87 Department::GSPro => 8,
88 Department::Unknown(num) => num,
89 }
90 }
91}