serialmessage
enables you to pack serial data into a fast, reliable,
and packetized form for communicating with e.g. a Microcontroller. It is compatible with
the Arduino SerialTransfer and Python pySerialTransfer
libraries by PowerBroker2. This crate is designed to be used
with any serial crate you desire, and does therefore not implement any serial
communication on its own. This crate is optionally fully no_std compatible and can
be used on any Microcontroller of your choice.
The message format: - uses start and stop bytes - uses packet ids - uses consistent overhead byte stuffing - uses CRC-8 (Polynomial 0x9B with lookup table) - allows the use of dynamically sized packets (packets can have payload lengths anywhere from 0 to 254 bytes) - can transfer bytes, ints, floats, structs, arrays, vectors
```text 01111110 00000000 11111111 00000000 00000000 00000000 ... 00000000 10000001 | | | | | | | | | | | | | | | | |_|Stop byte (constant) | | | | | | | | | | | | | | |_|__8-bit CRC | | | | | | | | | | | | ||_____Rest of payload | | | | | | | | | | ||______2nd payload byte | | | | | | | | ||_________1st payload byte | | | | | | ||____________# of payload bytes | | | | ||_______________COBS Overhead byte | | ||__________________Packet ID ||______________________Start byte (constant)
```
```rust use serialmessage::{SerMsg, ParseState};
let senddatavec: Vec
//Parsing received bytes let mut sermsg = SerMsg::new(); let (parsestate, parsedbytes) = sermsg.parsereadbytes(&sendmsg); match parsestate { ParseState::DataReady => { let rcvddata = sermsg.returnreaddata(); asserteq!(&senddatavec, rcvddata); } _ => { println!("Parsestate: {:?}", parsestate); } } ```
If you flash your microcontroller with the code provided in the /examples/arduino_code/ folder you can try the provided examples yourself.
no_rust
cargo run --example echo your_port
This crate is fully functional and tested, I use this crate a lot at work and had no issues so far. If you do encounter an issue or have a question just let me know.
Disable the default features of this crate and you are good to go.