diff --git a/README.md b/README.md index 1447613..e15dc3a 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,14 @@ application that needs to communicate with VESC motor controllers. > If you find a missing command, feel free to contribute! Adding a new command > should be relatively easy. Just follow the well-established pattern. -| Command Name | Status | -|-----------------------------------|--------| -| `GetValues` | ✅ | -| `SetCurrent` | ✅ | -| `SetRpm` | ✅ | -| `SetHandbrake` | ✅ | -| `ForwardCan` | ✅ | -| `GetValuesSelective` | ✅ | +| Command ID | Command Name | Status | +|:----------:|-----------------------------------|--------| +| `4` | `GetValues` | ✅ | +| `6` | `SetCurrent` | ✅ | +| `8` | `SetRpm` | ✅ | +| `10` | `SetHandbrake` | ✅ | +| `34` | `ForwardCan` | ✅ | +| `50` | `GetValuesSelective` | ✅ | ## Supported command replies @@ -29,10 +29,10 @@ application that needs to communicate with VESC motor controllers. > Many commands have no replies, so this list need not mirror the supported > commands. -| Command Name | Status | -|-----------------------------------|--------| -| `GetValues` | ✅ | -| `GetValuesSelective` | ✅ | +| Command ID | Command Name | Status | +|------------|-----------------------------------|--------| +| `4` | `GetValues` | ✅ | +| `50` | `GetValuesSelective` | ✅ | ## Installation @@ -43,6 +43,28 @@ Add this to your Cargo.toml: vesc = "0.1" ``` +## Usage + +```rust +let mut buf = [0u8; 16]; +let size = vesc::encode(Command::SetRpm(5000), &mut buf).unwrap(); +tx.write_all(&buf[..size]).unwrap(); +``` + +```rust +let mut decoder = Decoder::default(); +let mut buf = [0u8; 512]; + +loop { + let size = rx.read(&mut buf).unwrap() + decoder.feed(&buf[..size]).unwrap(); + + for reply in self.decoder.by_ref() { + // process `reply` + } +} +``` + ## License This project is licensed under the [MIT license](LICENSE). diff --git a/src/lib.rs b/src/lib.rs index 9570217..e32cc45 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,10 +24,29 @@ //! Ok((_, CommandReply::GetValuesSelective(values))) => { //! let rpm = values.rpm; //! let voltage_in = values.voltage_in; -//! } +//! }, //! _ => (), //! } //! ``` +//! +//! ## Decoding a Stream +//! +//! ```no_run +//! use vesc::{Decoder, CommandReply}; +//! +//! let mut decoder = Decoder::default(); +//! decoder.feed(&[2, 7, 50, 0, 0, 1, 128, 0, 0, 4, 210, 1, 176, 254, 22, 3]); +//! +//! for reply in decoder.by_ref() { +//! match reply { +//! CommandReply::GetValuesSelective(values) => { +//! let rpm = values.rpm; +//! let voltage_in = values.voltage_in; +//! }, +//! _ => (), +//! } +//! } +//! ``` #![cfg_attr(not(feature = "std"), no_std)] mod command;