rm_frame/validator.rs
1use crate::{calc_dji8, calc_dji16};
2
3///
4/// CRC validator abstraction for the frame protocol.
5///
6/// Implementations define how frame integrity is verified:
7/// - CRC8 for the frame header
8/// - CRC16 for the frame body
9///
10#[doc(alias("CrcValidator", "FrameValidator", "IntegrityChecker"))]
11pub trait Validator {
12 ///
13 /// Calculate CRC8 over the given raw bytes.
14 ///
15 /// Typically used for validating the frame header.
16 ///
17 fn calculate_crc8(raw: &[u8]) -> u8;
18 ///
19 /// Calculate CRC16 over the given raw bytes.
20 ///
21 /// Typically used for validating the full frame
22 /// (header + command + payload).
23 ///
24 fn calculate_crc16(raw: &[u8]) -> u16;
25}
26
27///
28/// DJI protocol CRC validator.
29///
30/// This implementation uses DJI-compatible CRC8 and CRC16
31/// algorithms for frame validation.
32///
33#[doc(alias("DefaultValidator", "DJIValidator"))]
34pub struct DjiValidator;
35
36impl Validator for DjiValidator {
37 fn calculate_crc8(raw: &[u8]) -> u8 {
38 calc_dji8(raw)
39 }
40
41 fn calculate_crc16(raw: &[u8]) -> u16 {
42 calc_dji16(raw)
43 }
44}