Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmaa committed Mar 4, 2023
1 parent 07a7c06 commit e825007
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use nom::{
branch::alt,
bytes::streaming::tag,
character::complete::char,
combinator::{all_consuming, complete},
combinator::{all_consuming, complete, eof},
multi::many0,
number::complete::float,
sequence::{delimited, preceded, separated_pair, terminated, tuple},
Expand Down Expand Up @@ -33,7 +33,9 @@ pub fn value(input: &str) -> IResult<&str, f32, nom::error::Error<&str>> {
parse(input)
}

pub fn keyword<'a>(name: &'a str) -> impl FnMut(&'a str) -> IResult<&str, &str, nom::error::Error<&str>> {
pub fn keyword<'a>(
name: &'a str,
) -> impl FnMut(&'a str) -> IResult<&str, &str, nom::error::Error<&str>> {
alt((
terminated(tag(name), whitespaces),
delimited(whitespaces, tag(name), whitespaces),
Expand All @@ -42,7 +44,9 @@ pub fn keyword<'a>(name: &'a str) -> impl FnMut(&'a str) -> IResult<&str, &str,
))
}

pub fn reading<'a>(name: &'a str) -> impl FnMut(&'a str) -> IResult<&str, (&str, f32), nom::error::Error<&str>> {
pub fn reading<'a>(
name: &'a str,
) -> impl FnMut(&'a str) -> IResult<&str, (&str, f32), nom::error::Error<&str>> {
return separated_pair(keyword(name), char(':'), value);
}

Expand All @@ -67,7 +71,7 @@ pub fn readings(input: &str) -> IResult<&str, Readings, nom::error::Error<&str>>
}

pub fn consume(input: &str) -> IResult<&str, Readings, nom::error::Error<&str>> {
let mut parse = all_consuming(readings);
let mut parse = all_consuming(terminated(readings, eof));
parse(input)
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub fn start(baud_rate: u32, timeout: u64) {

let mut to_resolve: Vec<u8> = Vec::new();
let mut buf = [0; 32];

loop {
match open_port(OS, baud_rate, timeout) {
Ok(mut port) => {
Expand All @@ -159,7 +159,7 @@ pub fn start(baud_rate: u32, timeout: u64) {
let marker = b'$'; // splitting symbol

// filter null bytes (unix)
let buffer = &buf[0..num]
let buffer = &buf
.iter()
.filter_map(|&b| if b != 0 { Some(b) } else { None })
.collect::<Vec<u8>>();
Expand Down

0 comments on commit e825007

Please sign in to comment.