mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpilib] Write REV PH firmware version to roboRIO to display on driver station (#3977)
This commit is contained in:
committed by
GitHub
parent
9fde0110b6
commit
05401e2b81
@@ -9,6 +9,11 @@ import edu.wpi.first.hal.REVPHFaults;
|
||||
import edu.wpi.first.hal.REVPHJNI;
|
||||
import edu.wpi.first.hal.REVPHStickyFaults;
|
||||
import edu.wpi.first.hal.REVPHVersion;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -29,9 +34,38 @@ public class PneumaticHub implements PneumaticsBase {
|
||||
m_handleMap.put(module, this);
|
||||
|
||||
final REVPHVersion version = REVPHJNI.getVersion(m_handle);
|
||||
final String fwVersion =
|
||||
version.firmwareMajor + "." + version.firmwareMinor + "." + version.firmwareFix;
|
||||
|
||||
if (version.firmwareMajor > 0 && RobotBase.isReal()) {
|
||||
// Write PH firmware version to roboRIO
|
||||
final String fileName = "REV_PH_" + String.format("%02d", module) + "_WPILib_Version.ini";
|
||||
final File file = new File("/tmp/frc_versions/" + fileName);
|
||||
try {
|
||||
if (file.exists() && !file.delete()) {
|
||||
throw new IOException("Failed to delete " + fileName);
|
||||
}
|
||||
|
||||
if (!file.createNewFile()) {
|
||||
throw new IOException("Failed to create new " + fileName);
|
||||
}
|
||||
|
||||
try (OutputStream output = Files.newOutputStream(file.toPath())) {
|
||||
output.write("[Version]\n".getBytes(StandardCharsets.UTF_8));
|
||||
output.write("model=REV PH\n".getBytes(StandardCharsets.UTF_8));
|
||||
output.write(
|
||||
("deviceID=" + Integer.toHexString(0x9052600 | module) + "\n")
|
||||
.getBytes(StandardCharsets.UTF_8));
|
||||
output.write(("currentVersion=" + fwVersion).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
DriverStation.reportError(
|
||||
"Could not write " + fileName + ": " + ex.toString(), ex.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
// Check PH firmware version
|
||||
if (version.firmwareMajor > 0 && version.firmwareMajor < 22) {
|
||||
final String fwVersion =
|
||||
version.firmwareMajor + "." + version.firmwareMinor + "." + version.firmwareFix;
|
||||
throw new IllegalStateException(
|
||||
"The Pneumatic Hub has firmware version "
|
||||
+ fwVersion
|
||||
|
||||
Reference in New Issue
Block a user