ds/proto/udp/outbound/types.rs
1pub mod tags;
2
3bitflags! {
4 /// bitflag struct for the Control value of the packet
5 pub struct Control: u8 {
6 const ESTOP = 0b1000_0000;
7 const FMS_CONNECTED = 0b0000_1000;
8 const ENABLED = 0b0000_0100;
9
10 // Mode flags
11 const TELEOP = 0b00;
12 const TEST = 0b01;
13 const AUTO = 0b10;
14 }
15}
16
17bitflags! {
18 /// bitflags for reboot and code restart requests
19 pub struct Request: u8 {
20 const REBOOT_ROBORIO = 0b0000_1000;
21 const RESTART_CODE = 0b0000_0100;
22 }
23}
24
25/// Struct abstracting the byte value for alliance colour and position
26#[derive(Copy, Clone, Debug)]
27pub struct Alliance(pub u8);
28
29impl Alliance {
30 /// Creates a new `Alliance` for the given position, on the red alliance
31 pub fn new_red(position: u8) -> Alliance {
32 // assert!((1u8..3).contains(&position));
33
34 Alliance(position - 1)
35 }
36
37 /// Creates a new `Alliance` for the given position, on the blue alliance
38 pub fn new_blue(position: u8) -> Alliance {
39 // assert!((1u8..3).contains(&position));
40
41 Alliance(position + 2)
42 }
43
44 /// Returns true if `self` is on the red alliance, false otherwise
45 ///
46 /// !is_red() implies is_blue()
47 pub fn is_red(self) -> bool {
48 self.0 < 3
49 }
50
51 /// Returns true if `self` is on the blue alliance, false otherwise
52 pub fn is_blue(self) -> bool {
53 !self.is_red()
54 }
55
56 /// Returns the alliance station position for `self`
57 pub fn position(self) -> u8 {
58 (self.0 % 3) + 1
59 }
60}