Skip to content

Commit

Permalink
src: drivers: fake: Move Fakesink driver to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoantoniocardoso committed Nov 14, 2024
1 parent f1175e8 commit 0c43e6a
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/lib/drivers/fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,17 @@ impl Driver for FakeSink {
}
}

let version = match &**message {
Packet::V1(_) => mavlink::MavlinkVersion::V1,
Packet::V2(_) => mavlink::MavlinkVersion::V2,
};

let frame = match mavlink::MavFrame::<mavlink::ardupilotmega::MavMessage>::deser(
version,
message.as_slice(),
) {
Ok(frame) => frame,
Err(error) => {
warn!("Failed to deserialize Mavlink Message: {error:?}");
continue;
}
let Ok(mavlink_json) = message
.to_mavlink_json::<mavlink::ardupilotmega::MavMessage>()
.await
else {
continue;
};

let mavlink::MavFrame {
header,
msg: message,
protocol_version: _,
} = frame;

if self.print {
println!("Message received: {header:?} {message:?}");
println!("Message received: {mavlink_json:#?}");
} else {
trace!("Message received: {header:?} {message:?}");
trace!("Message received: {mavlink_json:#?}");
}
}

Expand Down

0 comments on commit 0c43e6a

Please sign in to comment.