ashv2
Asynchronous Serial Host protocol, version 2
Documentation
The official protocol description can be found
at silabs.com.
Usage
This library provides the Actor struct which implements the actor model
for the ASHv2 protocol.
It is to be initialized with the underlying serial port, response channel sender and messaging channel size.
use ashv2::{Actor, BaudRate, FlowControl, open};
use tokio::sync::mpsc::channel;
#[tokio::main]
async fn main() {
let serial_port = open("/dev/ttymxc3", BaudRate::RstCts, FlowControl::Hardware)
.expect("Failed to open serial port");
let (response_tx, response_rx) = channel(64);
let actor = Actor::new(serial_port, response_tx, 64).expect("Failed to create actor");
let (tasks, proxy) = actor.spawn();
let request_data = vec![0x00, 0x00, 0x00, 0x02];
proxy
.send(request_data.into_iter().collect())
.await
.expect("Failed to send request")
.await
.expect("Failed to receive response")
.expect("Actor reported an error");
if let Some(response) = response_rx.recv().await {
println!("Received response: {response:?}");
}
let _serial_port = tasks.terminate().await.expect("Actor tasks failed to join");
}
Expected result:
Received response: [0, 128, 0, 8, 2, 48, 106]
Legal
This project is free software and is not affiliated with Silicon Labs.
Contribution guidelines
- Use
cargo fmt
- Check code with
cargo clippy
Credits
- Special thanks to Simon Farnsworth, Kevin Reid and the rest of the great community
at users.rust-lang.org.