vesc_api/packet/
commands.rs1pub trait Command {
2 fn get_data(&self) -> Vec<u8>;
3}
4
5pub struct SetDutyCycle {
6 id: u8,
7 duty_cycle: i32,
8}
9
10pub struct Alive {
11 id: u8,
12}
13
14pub struct GetValues {
15 id: u8,
16}
17
18impl SetDutyCycle {
19 pub fn new(duty_cycle: i32) -> SetDutyCycle {
20 SetDutyCycle { id: 5, duty_cycle }
21 }
22}
23
24impl Default for Alive {
25 fn default() -> Self {
26 Alive { id: 30 }
27 }
28}
29
30impl Default for GetValues {
31 fn default() -> Self {
32 GetValues { id: 4 }
33 }
34}
35
36impl Command for SetDutyCycle {
37 fn get_data(&self) -> Vec<u8> {
38 let bytes = self.duty_cycle.to_be_bytes();
39 vec![self.id, bytes[0], bytes[1], bytes[2], bytes[3]]
40 }
41}
42
43impl Command for Alive {
44 fn get_data(&self) -> Vec<u8> {
45 vec![self.id]
46 }
47}
48
49impl Command for GetValues {
50 fn get_data(&self) -> Vec<u8> {
51 vec![self.id]
52 }
53}