mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[hal] Add RobotController.getSerialNumber() (#4783)
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "frc/RobotController.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <hal/CAN.h>
|
||||
#include <hal/HALBase.h>
|
||||
#include <hal/Power.h>
|
||||
@@ -26,6 +28,13 @@ int64_t RobotController::GetFPGARevision() {
|
||||
return revision;
|
||||
}
|
||||
|
||||
std::string RobotController::GetSerialNumber() {
|
||||
// Serial number is 8 characters
|
||||
char serialNum[9];
|
||||
size_t len = HAL_GetSerialNumber(serialNum, sizeof(serialNum));
|
||||
return std::string(serialNum, len);
|
||||
}
|
||||
|
||||
uint64_t RobotController::GetFPGATime() {
|
||||
int32_t status = 0;
|
||||
uint64_t time = HAL_GetFPGATime(&status);
|
||||
|
||||
@@ -284,6 +284,16 @@ void RoboRioSim::SetBrownoutVoltage(units::volt_t vInVoltage) {
|
||||
HALSIM_SetRoboRioBrownoutVoltage(vInVoltage.value());
|
||||
}
|
||||
|
||||
std::string RoboRioSim::GetSerialNumber() {
|
||||
char serialNum[9];
|
||||
size_t len = HALSIM_GetRoboRioSerialNumber(serialNum, sizeof(serialNum));
|
||||
return std::string(serialNum, len);
|
||||
}
|
||||
|
||||
void RoboRioSim::SetSerialNumber(std::string_view serialNumber) {
|
||||
HALSIM_SetRoboRioSerialNumber(serialNumber.data(), serialNumber.size());
|
||||
}
|
||||
|
||||
void RoboRioSim::ResetData() {
|
||||
HALSIM_ResetRoboRioData();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <units/voltage.h>
|
||||
|
||||
namespace frc {
|
||||
@@ -42,6 +44,13 @@ class RobotController {
|
||||
*/
|
||||
static int64_t GetFPGARevision();
|
||||
|
||||
/**
|
||||
* Returns the serial number of the roboRIO.
|
||||
*
|
||||
* @return The serial number of the roboRIO.
|
||||
*/
|
||||
static std::string GetSerialNumber();
|
||||
|
||||
/**
|
||||
* Read the microsecond-resolution timer on the FPGA.
|
||||
*
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <units/current.h>
|
||||
#include <units/voltage.h>
|
||||
@@ -418,6 +419,20 @@ class RoboRioSim {
|
||||
*/
|
||||
static void SetBrownoutVoltage(units::volt_t brownoutVoltage);
|
||||
|
||||
/**
|
||||
* Get the serial number.
|
||||
*
|
||||
* @return The serial number.
|
||||
*/
|
||||
static std::string GetSerialNumber();
|
||||
|
||||
/**
|
||||
* Set the serial number.
|
||||
*
|
||||
* @param serialNumber The serial number.
|
||||
*/
|
||||
static void SetSerialNumber(std::string_view serialNumber);
|
||||
|
||||
/**
|
||||
* Reset all simulation data.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user