Expand description
§Laad
This library decodes frames from the TBS battery monitor and TBS charger products.
Example usage (see also examples/laadreader/main.rs):
use tokio::sync::mpsc;
use laad::{decoder::Decoder,frameparser::FrameParser,protocol::TbsPg,types::Bytes};
#[tokio::main]
async fn main() {
let (bytes_tx, bytes_rx) = mpsc::channel(5);
let (frames_tx, mut frames_rx) = mpsc::channel(5);
// Configure source and send send bytes to bytes_tx using bytes_tx.send(Bytes(bytes)).await.
let mut frame_parser = FrameParser::new();
tokio::spawn(async move {
frame_parser.parse_frames(bytes_rx, frames_tx).await;
});
while let Some(frame) = frames_rx.recv().await {
let decoder = Decoder::new();
let decoded = decoder.decode_frame(frame);
match decoded {
TbsPg::Unknown => {
println!("Received unknown frame");
}
_ => {
println!("Decoded frame: {:?}", decoded);
}
}
}
}Modules§
- decoder
- Decoder decodes frames into protocol types.
- frameparser
- FrameParser identifies frames in a stream of bytes and sends the frames to a Tokio channel.
- protocol
- Protocol defines the TBS protocol and decoded information for frame types that are understood. This module defines known enums, structs, and implementations related to the protocol for the TBS battery monitors and chargers.
- types
- Basic types for bytes and frames.