dguscard
dguscard is a postcard style #![no_std] DWIN T5L DGUS request builder & response parser with serde support.
Setup - Cargo.toml
Don't forget to add the no-std subset of serde along with dguscard to the [dependencies] section of your Cargo.toml!
[]
= "0.1.0"
# By default, `serde` has the `std` feature enabled,
# which makes it unsuitable for embedded targets.
# Disabling default-features fixes this.
= { = "1.0.*", = false }
Examples
Take a look at Request, Response and Accumulator examples.
Word Addressing and Big Endianness
T5L is a word machine and big-endian. The example below demonstrates how the addressing works. In this example, we are building a request with the values matching their address.
// Build a write request to address 0x1000
let mut request = with_slice.unwrap;
request.push.unwrap; // @0x1000 1 word
request.push.unwrap; // @0x1001 1 word
request.push.unwrap; // @0x1002 2 words
request.push.unwrap; // @0x1004 4 words
request.push.unwrap; // @0x1008 1 word
request.push.unwrap; // @0x1009 half word MSB
request.push.unwrap; // @0x1009 half word LSB
// Finish building request with CRC
let frame = request.finalize.unwrap;
// Send the request
uart.write;
The example below demonstrates how big-endianness work. Consider we sent the write request successfully in the previous example and now we want to read the same data.
/// Build a request for reading 10 word address 0x1000
let mut request = with_slice.unwrap;
/// Finalize with CRC
let frame = request.finalize.unwrap;
uart.write;
/// Read the response
let buf = &mut ;
uart.read_until_idle;
/// Extract the response, expect CRC
let mut response = from_bytes.unwrap;
let WordData = response
else ;
assert_eq!;
assert_eq!;
let dword: u32 = content.take.unwrap;
assert_eq!;
let my_data: MyData = content.take.unwrap;
assert_eq!;
let bytes: = content.take.unwrap;
assert_eq!;
Serde Data Model Support
- ✅ i8, i16, i32, i64, i128 - encoded as big endian
- ✅ u8, u16, u32, u64, u128 - encoded as big endian
- ✅ f32, f64 - encoded as big endian
- ✅ bool - encoded as u16
- ❌ char
- ❌ string
- ❌ byte array - serialization only
- ❌ option
- ✅ unit - not encoded
- ✅ unit_struct - not encoded
- ✅ unit_variant - index encoded as u16
- ✅ newtype_struct
- ❌ newtype_variant
- ❌ seq
- ✅ tuple
- ✅ tuple_struct
- ❌ tuple_variant
- ❌ map
- ✅ struct
- ❌ struct_variant
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
NOTE: This crate contains portions of postcard code.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.