1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use super::{instruction_id, packet_id, Instruction};

#[derive(Debug, Clone)]
pub struct Reboot {
	pub motor_id: u8,
}

impl Reboot {
	pub fn unicast(motor_id: u8) -> Self {
		Self { motor_id }
	}

	pub fn broadcast() -> Self {
		Self {
			motor_id: packet_id::BROADCAST,
		}
	}
}

impl Instruction for Reboot {
	type Response = ();

	fn request_packet_id(&self) -> u8 {
		self.motor_id
	}

	fn request_instruction_id(&self) -> u8 {
		instruction_id::REBOOT
	}

	fn request_parameters_len(&self) -> u16 {
		0
	}

	fn encode_request_parameters(&self, _buffer: &mut [u8]) {
		// Empty parameters.
	}

	fn decode_response_parameters(&mut self, packet_id: u8, parameters: &[u8]) -> Result<Self::Response, crate::InvalidMessage> {
		crate::InvalidPacketId::check_ignore_broadcast(packet_id, self.motor_id)?;
		crate::InvalidParameterCount::check(parameters.len(), 0)?;
		Ok(())
	}
}