Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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).
21 changes: 20 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down