[hal] Add GetTeamNumber (#5596)

This commit is contained in:
Ryan Blue
2023-09-02 02:34:18 -04:00
committed by GitHub
parent a750bee54d
commit ac23f92451
19 changed files with 259 additions and 0 deletions

View File

@@ -41,6 +41,10 @@ std::string RobotController::GetComments() {
return std::string(comments, len);
}
int32_t RobotController::GetTeamNumber() {
return HAL_GetTeamNumber();
}
uint64_t RobotController::GetFPGATime() {
int32_t status = 0;
uint64_t time = HAL_GetFPGATime(&status);

View File

@@ -301,6 +301,23 @@ void RoboRioSim::SetCPUTemp(units::celsius_t cpuTemp) {
HALSIM_SetRoboRioCPUTemp(cpuTemp.value());
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterTeamNumberCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioTeamNumberCallback);
store->SetUid(HALSIM_RegisterRoboRioTeamNumberCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int32_t RoboRioSim::GetTeamNumber() {
return HALSIM_GetRoboRioTeamNumber();
}
void RoboRioSim::SetTeamNumber(int32_t teamNumber) {
HALSIM_SetRoboRioTeamNumber(teamNumber);
}
std::string RoboRioSim::GetSerialNumber() {
char serialNum[9];
size_t len = HALSIM_GetRoboRioSerialNumber(serialNum, sizeof(serialNum));

View File

@@ -63,6 +63,13 @@ class RobotController {
*/
static std::string GetComments();
/**
* Returns the team number configured for the robot controller.
*
* @return team number, or 0 if not found.
*/
static int32_t GetTeamNumber();
/**
* Read the microsecond-resolution timer on the FPGA.
*

View File

@@ -461,6 +461,31 @@ class RoboRioSim {
*/
static void SetCPUTemp(units::celsius_t cpuTemp);
/**
* Register a callback to be run whenever the team number changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
static std::unique_ptr<CallbackStore> RegisterTeamNumberCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the team number.
*
* @return the team number.
*/
static int32_t GetTeamNumber();
/**
* Set the team number.
*
* @param teamNumber the new team number.
*/
static void SetTeamNumber(int32_t teamNumber);
/**
* Get the serial number.
*

View File

@@ -222,6 +222,21 @@ TEST(RoboRioSimTest, SetCPUTemp) {
EXPECT_EQ(kCPUTemp, RobotController::GetCPUTemp().value());
}
TEST(RoboRioSimTest, SetTeamNumber) {
RoboRioSim::ResetData();
IntCallback callback;
auto cbHandle =
RoboRioSim::RegisterTeamNumberCallback(callback.GetCallback(), false);
constexpr int kTeamNumber = 9999;
RoboRioSim::SetTeamNumber(kTeamNumber);
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(kTeamNumber, callback.GetLastValue());
EXPECT_EQ(kTeamNumber, RoboRioSim::GetTeamNumber());
EXPECT_EQ(kTeamNumber, RobotController::GetTeamNumber());
}
TEST(RoboRioSimTest, SetSerialNumber) {
const std::string kSerialNum = "Hello";