[hal] Add RobotController.getSerialNumber() (#4783)

This commit is contained in:
Ryan Blue
2022-12-09 00:58:55 -05:00
committed by GitHub
parent 69a66ec5ec
commit 5a52b51443
19 changed files with 292 additions and 0 deletions

View File

@@ -4,6 +4,11 @@
#pragma once
#include <cstddef>
#include <string>
#include <wpi/spinlock.h>
#include "hal/simulation/RoboRioData.h"
#include "hal/simulation/SimDataValue.h"
@@ -26,6 +31,8 @@ class RoboRioData {
HAL_SIMDATAVALUE_DEFINE_NAME(UserFaults3V3)
HAL_SIMDATAVALUE_DEFINE_NAME(BrownoutVoltage)
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(SerialNumber)
public:
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetFPGAButtonName> fpgaButton{false};
SimDataValue<double, HAL_MakeDouble, GetVInVoltageName> vInVoltage{12.0};
@@ -50,7 +57,20 @@ class RoboRioData {
SimDataValue<double, HAL_MakeDouble, GetBrownoutVoltageName> brownoutVoltage{
6.75};
int32_t RegisterSerialNumberCallback(HAL_RoboRioStringCallback callback,
void* param, HAL_Bool initialNotify);
void CancelSerialNumberCallback(int32_t uid);
size_t GetSerialNumber(char* buffer, size_t size);
void SetSerialNumber(const char* serialNumber, size_t size);
virtual void ResetData();
private:
wpi::spinlock m_serialNumberMutex;
std::string m_serialNumber;
SimCallbackRegistry<HAL_RoboRioStringCallback, GetSerialNumberName>
m_serialNumberCallbacks;
};
extern RoboRioData* SimRoboRioData;
} // namespace hal