Skip to content

Commit

Permalink
Optionally parse sync (address) byte
Browse files Browse the repository at this point in the history
  • Loading branch information
anti-social committed Apr 24, 2024
1 parent ed6f51d commit 1f04332
Show file tree
Hide file tree
Showing 5 changed files with 434 additions and 132 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/tact1m4n3/crsf-rs"
documentation = "https://docs.rs/crsf"

[dependencies]
bitflags = "2.5.0"
crc = "3.2"
defmt = { version = "0.3.6", optional = true }
num_enum = { version = "0.7.2", default-features = false }
Expand Down
10 changes: 5 additions & 5 deletions examples/local_serial.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{env, io, time::Duration};

use crsf::{Packet, PacketReader};
use crsf::{Packet, PacketPayload, PacketReader};

fn main() {
let path = env::args().nth(1).expect("no serial port supplied");
Expand All @@ -10,19 +10,19 @@ fn main() {
.expect("failed to open serial port");

let mut buf = [0; 1024];
let mut reader = PacketReader::new();
let mut reader = PacketReader::default();
loop {
match port.read(buf.as_mut_slice()) {
Ok(n) => {
if n > 0 {
let mut remaining = &buf[..n];
while let (Some(raw_packet), consumed) = reader.push_bytes(remaining) {
match Packet::parse(raw_packet) {
Ok(packet) => match packet {
Packet::LinkStatistics(link_statistics) => {
Ok(packet) => match packet.payload {
PacketPayload::LinkStatistics(link_statistics) => {
println!("{:?}", link_statistics);
}
Packet::RcChannels(channels) => {
PacketPayload::RcChannels(channels) => {
println!("{:?}", channels);
}
_ => {}
Expand Down
Loading

0 comments on commit 1f04332

Please sign in to comment.