Skip to content

Commit

Permalink
feat(init-reset): implemented small state machine for link opening an…
Browse files Browse the repository at this point in the history
…d reset (#9)

* feat(init-reset): implemented small state machine for link opening and reset

Signed-off-by: Gabriele Baldoni <gabriele.baldoni@gmail.com>

* feat: configurable timeout

Signed-off-by: Gabriele Baldoni <gabriele.baldoni@gmail.com>

* chore: adding test with empty payload for serialization

Signed-off-by: Gabriele Baldoni <gabriele.baldoni@gmail.com>

* fix: empty payload during handshake

Signed-off-by: Gabriele Baldoni <gabriele.baldoni@gmail.com>

* tests: adding empty payload CRC test

Signed-off-by: Gabriele Baldoni <gabriele.baldoni@gmail.com>

* feat: adding check if file exists on read and write calls

Signed-off-by: Gabriele Baldoni <gabriele.baldoni@gmail.com>

---------

Signed-off-by: Gabriele Baldoni <gabriele.baldoni@gmail.com>
  • Loading branch information
gabrik authored Dec 10, 2024
1 parent 79e47ce commit 1ccb5f0
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = {version = "1.17.0", features = ["io-util"] }
tokio = {version = "1.17.0", features = ["io-util", "time"] }
tokio-serial = "5.4.1"
futures = "0.3.21"
cobs = "0.2"
Expand Down
25 changes: 16 additions & 9 deletions examples/serial-echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,25 @@ async fn main() -> tokio_serial::Result<()> {

println!("Arguments: {:?}", args);

let mut port = ZSerial::new(args.port, args.baud_rate, true)?;
let mut port = ZSerial::new(args.port, args.baud_rate, false)?;

if args.server {
loop {
match port.read_msg(&mut buff).await {
Ok(read) => {
println!(">> Read {read} bytes: {:02X?}", &buff[0..read]);
port.accept().await?;

port.write(&buff[..read]).await?;
'inner: loop {
match port.read_msg(&mut buff).await {
Ok(read) => {
println!(">> Read {read} bytes: {:02X?}", &buff[0..read]);

println!("<< Echoed back");
}
Err(e) => {
println!("Got error: {e} received {:02X?}", &buff[..8]);
port.write(&buff[..read]).await?;

println!("<< Echoed back");
}
Err(e) => {
println!("Got error: {e} received {:02X?}", &buff[..8]);
break 'inner;
}
}
}
}
Expand All @@ -68,6 +73,8 @@ async fn main() -> tokio_serial::Result<()> {
2.0
};

port.connect(None).await?;

loop {
tokio::time::sleep(Duration::from_secs_f64(args.interval)).await;

Expand Down
Loading

0 comments on commit 1ccb5f0

Please sign in to comment.