-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRio.java
88 lines (74 loc) · 2.76 KB
/
Rio.java
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package frc.spectrumLib;
import edu.wpi.first.wpilibj.Alert;
import edu.wpi.first.wpilibj.Alert.AlertType;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.RobotController;
import java.util.HashMap;
import java.util.Map;
/*
* Represents a specific RoboRIO, as a key for configurations.
*
* The serial numbers here can be found on the label on the back: add a leading zero.
*
* Please keep the ID strings in lexical order.
*
* Note that the ID string may change when you reflash the RoboRIO.
* Based on: https://github.com/Team100/all24/blob/2a109b28467cfddcafb93c7fc85ef60b56a628a2/lib/src/main/java/org/team100/lib/config/Identity.java
*/
public enum Rio {
AM_2024("032B1F69", false),
PM_2024("032B4BB3", true),
FM_2024("032B1F69", true),
PHOTON_2024("0329AD07", true),
SUMMER_2024("00", false), // TODO:GET Summer Serial Number
SIM("", true), // e.g. test default or simulation
UNKNOWN(null, true);
private static final Map<String, Rio> IDs = new HashMap<>();
static {
for (Rio i : Rio.values()) {
IDs.put(i.serialNumber, i);
}
}
private static final Alert rioIdAlert = new Alert("RIO: ", AlertType.kInfo);
private static final Alert rioIdUnknown = new Alert("UNKNOWN RIO: ", AlertType.kError);
private static final Alert rio1alert = new Alert("RIO 1.0", AlertType.kWarning);
public static final Rio id = checkID();
public static final String CANIVORE = "*"; // Use the first CANivore bus found
public static final String RIO_CANBUS = "rio";
private final String serialNumber;
private final boolean isRio2;
private Rio(String serialNumber, boolean isRio2) {
this.serialNumber = serialNumber;
this.isRio2 = isRio2;
}
private static Rio checkID() {
rioIdAlert.set(false);
rioIdUnknown.set(false);
String serialNumber = "";
if (RobotBase.isReal()) {
// Calling getSerialNumber in a vscode unit test
// SEGVs because it does the wrong
// thing with JNIs, so don't do that.
serialNumber = RobotController.getSerialNumber();
System.out.println("RIO SERIAL: " + serialNumber);
} else {
serialNumber = "";
}
if (IDs.containsKey(serialNumber)) {
Rio id = IDs.get(serialNumber);
rioIdAlert.setText("Rio: " + id.name());
rioIdAlert.set(true);
System.out.println("RIO NAME: " + id.name());
if (id.isRio2) {
rio1alert.set(true);
}
return id;
}
rioIdUnknown.setText("Unknown Rio: " + serialNumber);
rioIdUnknown.set(true);
return UNKNOWN;
}
public boolean isRio2() {
return isRio2;
}
}