Skip to content

Commit 6634798

Browse files
committed
Fix PING-PONG Feature and add more common::Class info
1 parent 5649312 commit 6634798

File tree

4 files changed

+172
-67
lines changed

4 files changed

+172
-67
lines changed

arsdk-rs/src/common.rs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,40 @@ pub enum Class {
4444
MavlinkState, // ARCOMMANDS_ID_COMMON_CLASS_MAVLINKSTATE = 12,
4545
FlightPlanSettings, // ARCOMMANDS_ID_COMMON_CLASS_FLIGHTPLANSETTINGS = 32,
4646
FlightPlanSettingsState, // ARCOMMANDS_ID_COMMON_CLASS_FLIGHTPLANSETTINGSSTATE = 33,
47-
Calibration, // ARCOMMANDS_ID_COMMON_CLASS_CALIBRATION = 13,
48-
CalibrationState, // ARCOMMANDS_ID_COMMON_CLASS_CALIBRATIONSTATE = 14,
49-
CameraSettingsState, // ARCOMMANDS_ID_COMMON_CLASS_CAMERASETTINGSSTATE = 15,
50-
Gps, // ARCOMMANDS_ID_COMMON_CLASS_GPS = 16,
51-
FlightPlanState, // ARCOMMANDS_ID_COMMON_CLASS_FLIGHTPLANSTATE = 17,
52-
FlightPlanEvent, // ARCOMMANDS_ID_COMMON_CLASS_FLIGHTPLANEVENT = 19,
53-
ArLibsVersionsState, // ARCOMMANDS_ID_COMMON_CLASS_ARLIBSVERSIONSSTATE = 18,
54-
Audio, // ARCOMMANDS_ID_COMMON_CLASS_AUDIO = 20,
55-
AudioState, // ARCOMMANDS_ID_COMMON_CLASS_AUDIOSTATE = 21,
56-
HeadLights, // ARCOMMANDS_ID_COMMON_CLASS_HEADLIGHTS = 22,
57-
HeadLightsState, // ARCOMMANDS_ID_COMMON_CLASS_HEADLIGHTSSTATE = 23,
58-
Animations, // ARCOMMANDS_ID_COMMON_CLASS_ANIMATIONS = 24,
59-
AnimationsState, // ARCOMMANDS_ID_COMMON_CLASS_ANIMATIONSSTATE = 25,
60-
Accessory, // ARCOMMANDS_ID_COMMON_CLASS_ACCESSORY = 26,
61-
AccessoryState, // ARCOMMANDS_ID_COMMON_CLASS_ACCESSORYSTATE = 27,
62-
Charger, // ARCOMMANDS_ID_COMMON_CLASS_CHARGER = 28,
63-
ChargerState, // ARCOMMANDS_ID_COMMON_CLASS_CHARGERSTATE = 29,
64-
Runstate, // ARCOMMANDS_ID_COMMON_CLASS_RUNSTATE = 30,
65-
Factory, // ARCOMMANDS_ID_COMMON_CLASS_FACTORY = 31,
47+
/// ARCOMMANDS_ID_COMMON_CLASS_CALIBRATION = 13
48+
///
49+
/// First cmd:
50+
/// u16 - ARCOMMANDS_ID_COMMON_CALIBRATION_CMD_MAGNETOCALIBRATION
51+
/// u8 - _calibrate
52+
///
53+
/// Second cmd:
54+
/// u16 - ARCOMMANDS_ID_COMMON_CALIBRATION_CMD_PITOTCALIBRATION
55+
/// u8 - _calibrate
56+
Calibration,
57+
/// ARCOMMANDS_ID_COMMON_CLASS_CALIBRATIONSTATE = 14
58+
/// u16 - ARCOMMANDS_ID_COMMON_CALIBRATIONSTATE_CMD_MAGNETOCALIBRATIONSTATECHANGED
59+
/// u8 - _xAxisCalibration
60+
/// u8 - _yAxisCalibration
61+
/// u8 - _zAxisCalibration
62+
/// u8 - _calibrationFailed
63+
CalibrationState,
64+
CameraSettingsState, // ARCOMMANDS_ID_COMMON_CLASS_CAMERASETTINGSSTATE = 15,
65+
Gps, // ARCOMMANDS_ID_COMMON_CLASS_GPS = 16,
66+
FlightPlanState, // ARCOMMANDS_ID_COMMON_CLASS_FLIGHTPLANSTATE = 17,
67+
FlightPlanEvent, // ARCOMMANDS_ID_COMMON_CLASS_FLIGHTPLANEVENT = 19,
68+
ArLibsVersionsState, // ARCOMMANDS_ID_COMMON_CLASS_ARLIBSVERSIONSSTATE = 18,
69+
Audio, // ARCOMMANDS_ID_COMMON_CLASS_AUDIO = 20,
70+
AudioState, // ARCOMMANDS_ID_COMMON_CLASS_AUDIOSTATE = 21,
71+
HeadLights, // ARCOMMANDS_ID_COMMON_CLASS_HEADLIGHTS = 22,
72+
HeadLightsState, // ARCOMMANDS_ID_COMMON_CLASS_HEADLIGHTSSTATE = 23,
73+
Animations, // ARCOMMANDS_ID_COMMON_CLASS_ANIMATIONS = 24,
74+
AnimationsState, // ARCOMMANDS_ID_COMMON_CLASS_ANIMATIONSSTATE = 25,
75+
Accessory, // ARCOMMANDS_ID_COMMON_CLASS_ACCESSORY = 26,
76+
AccessoryState, // ARCOMMANDS_ID_COMMON_CLASS_ACCESSORYSTATE = 27,
77+
Charger, // ARCOMMANDS_ID_COMMON_CLASS_CHARGER = 28,
78+
ChargerState, // ARCOMMANDS_ID_COMMON_CLASS_CHARGERSTATE = 29,
79+
Runstate, // ARCOMMANDS_ID_COMMON_CLASS_RUNSTATE = 30,
80+
Factory, // ARCOMMANDS_ID_COMMON_CLASS_FACTORY = 31,
6681
Unknown {
6782
class: u8,
6883
data: Vec<u8>,

arsdk-rs/src/frame.rs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,31 @@ pub mod impl_scroll {
310310
// we can receive multiple frames, so the feature should be limited
311311
// to buf_len from source
312312

313-
let feature =
314-
src[..buf_len_usize].gread_with::<Feature>(&mut actual_buf_len, ctx)?;
313+
// for the PING & PONG we don't reasonable data
314+
// only data to echo back from PING
315+
if [BufferID::PING, BufferID::PONG].contains(&buffer_id) {
316+
// even if it's a known one, the PING doesn't send sane data
317+
let feature = src[..buf_len_usize].gread_with(&mut actual_buf_len, ctx)?;
318+
319+
let mut feature_data = [0_u8; 256];
320+
let actual_written = feature_data.gwrite_with(
321+
&src[actual_buf_len..buf_len_usize],
322+
&mut 0,
323+
(),
324+
)?;
315325

316-
Some(feature)
326+
actual_buf_len += actual_written;
327+
328+
Some(Feature::Unknown {
329+
feature,
330+
data: feature_data[..actual_written].to_vec(),
331+
})
332+
} else {
333+
let feature =
334+
src[..buf_len_usize].gread_with::<Feature>(&mut actual_buf_len, ctx)?;
335+
336+
Some(feature)
337+
}
317338
} else {
318339
None
319340
};
@@ -526,6 +547,16 @@ mod frame_tests {
526547
}
527548

528549
#[test]
550+
/// [2] Type::Data
551+
/// [10] BufferId::CDNonAck
552+
/// [103] Sequence ID
553+
/// [14, 0, 0, 0] Length 14
554+
/// [3] Feature JS
555+
/// [0] - JS Class - Piloting
556+
/// [0, 0] Pilot (PCMD)
557+
/// [1] flag: true
558+
/// [0] speed
559+
/// [156] turn: -100
529560
fn test_jumpingsumo_move_command() {
530561
let message: [u8; 14] = [
531562
0x2, 0xa, 0x67, 0xe, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x1, 0x0, 0x9c,
@@ -604,8 +635,8 @@ mod frame_tests {
604635
}
605636

606637
#[test]
607-
/// [2] Data
608-
/// [127] DCNavadata
638+
/// [2] Type::Data
639+
/// [127] BufferID::DCNavadata
609640
/// [206] Sequence ID
610641
/// [15, 0, 0, 0] 15 length
611642
/// [1] ArDrone
@@ -635,12 +666,11 @@ mod frame_tests {
635666
assert_eq!(buf_len as usize, expected.len());
636667

637668
// Deserialize a Frame
638-
assert_eq!(
639-
frame,
640-
expected
641-
.pread_with::<Frame>(0, LE)
642-
.expect("Should deserialize"),
643-
);
669+
let deserialized = expected
670+
.pread_with::<Frame>(0, LE)
671+
.expect("Should deserialize");
672+
673+
assert_eq!(frame, deserialized);
644674
let mut actual = [0_u8; 256];
645675
assert!(
646676
actual.len() > buf_len as usize,

arsdk-rs/src/jumping_sumo.rs

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ pub enum JumpType {
55
DEFAULT, // ARCOMMANDS_ID_JUMPINGSUMO_CLASS_PILOTING = 0,
66
}
77

8-
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
8+
#[derive(Debug, PartialEq, Eq, Clone)]
9+
/// u8
910
pub enum Class {
1011
Piloting(PilotingID), // ARCOMMANDS_ID_JUMPINGSUMO_CLASS_PILOTING = 0,
1112
PilotingState, // ARCOMMANDS_ID_JUMPINGSUMO_CLASS_PILOTINGSTATE = 1,
@@ -40,14 +41,15 @@ pub enum Anim {
4041
SimpleAnimation = 4, // ARCOMMANDS_ID_JUMPINGSUMO_ANIMATIONS_CMD_SIMPLEANIMATION = 4,
4142
}
4243

43-
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
44+
#[derive(Debug, PartialEq, Eq, Clone)]
45+
/// u16
4446
pub enum PilotingID {
4547
Pilot(PilotState), // ARCOMMANDS_ID_JUMPINGSUMO_PILOTING_CMD_PCMD = 0,
4648
Posture, // ARCOMMANDS_ID_JUMPINGSUMO_PILOTING_CMD_POSTURE = 1,
4749
AddCapOffset, // ARCOMMANDS_ID_JUMPINGSUMO_PILOTING_CMD_ADDCAPOFFSET = 2,
4850
}
4951

50-
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy)]
52+
#[derive(Default, Debug, PartialEq, Eq, Clone)]
5153
pub struct PilotState {
5254
pub flag: bool,
5355
pub speed: i8,
@@ -56,31 +58,31 @@ pub struct PilotState {
5658

5759
// --------------------- Conversion impls --------------------- //
5860

59-
impl Into<u8> for Class {
61+
impl Into<u8> for &Class {
6062
fn into(self) -> u8 {
6163
match self {
62-
Self::Piloting(_) => 0,
63-
Self::PilotingState => 1,
64-
Self::Animations(_) => 2,
65-
Self::AnimationsState => 3,
66-
Self::SettingsState => 5,
67-
Self::MediaRecord => 6,
68-
Self::MediaRecordState => 7,
69-
Self::NetworkSettings => 8,
70-
Self::NetworkSettingsState => 9,
71-
Self::Network => 10,
72-
Self::NetworkState => 11,
73-
Self::AutioSettings => 12,
74-
Self::AudioSettingsState => 13,
75-
Self::Roadplan => 14,
76-
Self::RoadplanState => 15,
77-
Self::SpeedSettings => 16,
78-
Self::SpeedSettingsState => 17,
79-
Self::MediaStreaming => 18,
80-
Self::MediaStreamingState => 19,
81-
Self::MediaRecordEvent => 20,
82-
Self::VideoSettings => 21,
83-
Self::VideoSettingsState => 22,
64+
Class::Piloting(_) => 0,
65+
Class::PilotingState => 1,
66+
Class::Animations(_) => 2,
67+
Class::AnimationsState => 3,
68+
Class::SettingsState => 5,
69+
Class::MediaRecord => 6,
70+
Class::MediaRecordState => 7,
71+
Class::NetworkSettings => 8,
72+
Class::NetworkSettingsState => 9,
73+
Class::Network => 10,
74+
Class::NetworkState => 11,
75+
Class::AutioSettings => 12,
76+
Class::AudioSettingsState => 13,
77+
Class::Roadplan => 14,
78+
Class::RoadplanState => 15,
79+
Class::SpeedSettings => 16,
80+
Class::SpeedSettingsState => 17,
81+
Class::MediaStreaming => 18,
82+
Class::MediaStreamingState => 19,
83+
Class::MediaRecordEvent => 20,
84+
Class::VideoSettings => 21,
85+
Class::VideoSettingsState => 22,
8486
}
8587
}
8688
}
@@ -97,12 +99,12 @@ impl Into<u8> for Anim {
9799
}
98100
}
99101

100-
impl Into<u16> for PilotingID {
102+
impl Into<u16> for &PilotingID {
101103
fn into(self) -> u16 {
102104
match self {
103-
Self::Pilot(_) => 0,
104-
Self::Posture => 1,
105-
Self::AddCapOffset => 2,
105+
PilotingID::Pilot(_) => 0,
106+
PilotingID::Posture => 1,
107+
PilotingID::AddCapOffset => 2,
106108
}
107109
}
108110
}
@@ -167,7 +169,7 @@ pub mod scroll_impl {
167169
fn try_into_ctx(self, this: &mut [u8], ctx: Endian) -> Result<usize, Self::Error> {
168170
let mut offset = 0;
169171

170-
this.gwrite_with::<u8>(self.into(), &mut offset, ctx)?;
172+
this.gwrite_with::<u8>((&self).into(), &mut offset, ctx)?;
171173
match self {
172174
Self::Piloting(piloting_id) => {
173175
this.gwrite_with(piloting_id, &mut offset, ctx)?;
@@ -214,7 +216,7 @@ pub mod scroll_impl {
214216

215217
fn try_into_ctx(self, this: &mut [u8], ctx: Endian) -> Result<usize, Self::Error> {
216218
let mut offset = 0;
217-
this.gwrite_with::<u16>(self.into(), &mut offset, ctx)?;
219+
this.gwrite_with::<u16>((&self).into(), &mut offset, ctx)?;
218220

219221
match self {
220222
Self::Pilot(state) => {
@@ -315,6 +317,7 @@ pub mod scroll_impl {
315317
#[cfg(test)]
316318
mod jumping_dumo_tests {
317319
use super::*;
320+
use std::borrow::Borrow;
318321

319322
#[test]
320323
fn test_piloting_command() {
@@ -358,8 +361,8 @@ mod jumping_dumo_tests {
358361
assert_class(Class::VideoSettingsState, 22);
359362
}
360363

361-
fn assert_class(dc: Class, v: u8) {
362-
let as_u8: u8 = dc.into();
364+
fn assert_class(dc: impl Borrow<Class>, v: u8) {
365+
let as_u8: u8 = dc.borrow().into();
363366
assert_eq!(v, as_u8);
364367
}
365368

@@ -368,8 +371,8 @@ mod jumping_dumo_tests {
368371
assert_eq!(v, as_u8);
369372
}
370373

371-
fn assert_piloting(pc: PilotingID, v: u16) {
372-
let as_u8: u16 = pc.into();
374+
fn assert_piloting(pc: impl Borrow<PilotingID>, v: u16) {
375+
let as_u8: u16 = pc.borrow().into();
373376
assert_eq!(v, as_u8);
374377
}
375378
}

arsdk-rs/src/parse.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ mod parse_message_frames {
8686
use crate::jumping_sumo as js;
8787
use crate::{
8888
command::Feature,
89-
frame::{BufferID, Error, Frame, FrameType, Type},
89+
frame::{BufferID, Frame, FrameType, Type},
9090
};
9191
#[test]
9292
fn test_parsable_messages() {
@@ -161,4 +161,61 @@ mod parse_message_frames {
161161

162162
assert_eq!(FrameType::Known(frame), actual);
163163
}
164+
165+
#[test]
166+
/// [2] Type - Data
167+
/// [0] BufferID - Ping
168+
/// [1] Sequence id 1
169+
/// [23,0,0,0] length 23
170+
/// [0, 0, 0, 0, 0, 0, 0, 233, 72, 37, 42, 0, 0, 0, 0] Ping's Gibberish Data
171+
///
172+
/// Second:
173+
/// [4] Type - DataWithAck
174+
/// [126] BufferID - DCEvent
175+
/// [1] Sequence id 1
176+
/// [12, 0, 0, 0 ] Length 12
177+
/// [0] Feature - Common
178+
/// [14] Class - CalibrationState
179+
/// [1, 0 , 0] - DATA?!
180+
///
181+
fn test_two_frames_ping_and_common_class_calibration_state_unknown() {
182+
let buf: [u8; 35] = [
183+
// first:
184+
2, 0, 1, 23, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 233, 72, 37, 42, 0, 0, 0, 0,
185+
// second:
186+
4, 126, 1, 12, 0, 0, 0, 0, 14, 1, 0, 0,
187+
];
188+
189+
let expected = [
190+
FrameType::Known(Frame {
191+
frame_type: Type::Data,
192+
buffer_id: BufferID::PING,
193+
sequence_id: 1,
194+
feature: Some(Feature::Unknown {
195+
feature: 3,
196+
data: vec![0, 0, 0, 0, 0, 0, 0, 233, 72, 37, 42, 0, 0, 0, 0],
197+
}),
198+
}),
199+
FrameType::Known(Frame {
200+
frame_type: Type::DataWithAck,
201+
buffer_id: BufferID::DCEvent,
202+
sequence_id: 1,
203+
feature: Some(Feature::Common(Some(crate::common::Class::Unknown {
204+
// CalibrationState
205+
class: 14,
206+
// x y z axis
207+
data: vec![1, 0, 0],
208+
}))),
209+
}),
210+
];
211+
212+
let actual = parse_message_frames(&buf);
213+
assert_eq!(expected.len(), actual.len());
214+
215+
for (expected, parsed) in expected.iter().zip(actual) {
216+
let actual = parsed.expect("This should be Ok(_)");
217+
218+
assert_eq!(expected, &actual);
219+
}
220+
}
164221
}

0 commit comments

Comments
 (0)