serialmessage

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

Packet Anatomy:

```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)

```

Example

Basic Example

```rust use serialmessage::{SerMsg, ParseState};

let senddatavec: Vec = vec![1, 2, 3, 4]; let sendmsg = SerMsg::createmsgvec(&senddata_vec, 1).unwrap(); // Send the message bytes with a serial crate of your choice

//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); } } ```

Using the crate provided examples

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

Status of this crate

Current state

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.

Goals for the future

no_std usage

Disable the default features of this crate and you are good to go.