mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilibc] Errors: Use fmtlib
This commit is contained in:
@@ -9,7 +9,7 @@ using namespace frc2;
|
||||
bool CommandGroupBase::RequireUngrouped(Command& command) {
|
||||
if (command.IsGrouped()) {
|
||||
throw FRC_MakeError(
|
||||
frc::err::CommandIllegalUse,
|
||||
frc::err::CommandIllegalUse, "{}",
|
||||
"Commands cannot be added to more than one CommandGroup");
|
||||
}
|
||||
return true;
|
||||
@@ -23,7 +23,7 @@ bool CommandGroupBase::RequireUngrouped(
|
||||
}
|
||||
if (!allUngrouped) {
|
||||
throw FRC_MakeError(
|
||||
frc::err::CommandIllegalUse,
|
||||
frc::err::CommandIllegalUse, "{}",
|
||||
"Commands cannot be added to more than one CommandGroup");
|
||||
}
|
||||
return allUngrouped;
|
||||
@@ -37,7 +37,7 @@ bool CommandGroupBase::RequireUngrouped(
|
||||
}
|
||||
if (!allUngrouped) {
|
||||
throw FRC_MakeError(
|
||||
frc::err::CommandIllegalUse,
|
||||
frc::err::CommandIllegalUse, "{}",
|
||||
"Commands cannot be added to more than one CommandGroup");
|
||||
}
|
||||
return allUngrouped;
|
||||
|
||||
@@ -111,7 +111,7 @@ void CommandScheduler::Schedule(bool interruptible, Command* command) {
|
||||
}
|
||||
|
||||
if (command->IsGrouped()) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"A command that is part of a command group "
|
||||
"cannot be independently scheduled");
|
||||
return;
|
||||
|
||||
@@ -65,7 +65,7 @@ void ParallelCommandGroup::AddCommands(
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
}
|
||||
@@ -77,7 +77,7 @@ void ParallelCommandGroup::AddCommands(
|
||||
m_runWhenDisabled &= command->RunsWhenDisabled();
|
||||
m_commands.emplace_back(std::move(command), false);
|
||||
} else {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Multiple commands in a parallel group cannot "
|
||||
"require the same subsystems");
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ void ParallelDeadlineGroup::AddCommands(
|
||||
}
|
||||
|
||||
if (!m_finished) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
}
|
||||
@@ -72,7 +72,7 @@ void ParallelDeadlineGroup::AddCommands(
|
||||
m_runWhenDisabled &= command->RunsWhenDisabled();
|
||||
m_commands.emplace_back(std::move(command), false);
|
||||
} else {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Multiple commands in a parallel group cannot "
|
||||
"require the same subsystems");
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ void ParallelRaceGroup::AddCommands(
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
}
|
||||
@@ -62,7 +62,7 @@ void ParallelRaceGroup::AddCommands(
|
||||
m_runWhenDisabled &= command->RunsWhenDisabled();
|
||||
m_commands.emplace_back(std::move(command));
|
||||
} else {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Multiple commands in a parallel group cannot "
|
||||
"require the same subsystems");
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ void SequentialCommandGroup::AddCommands(
|
||||
}
|
||||
|
||||
if (m_currentCommandIndex != invalid_index) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Commands cannot be added to a CommandGroup "
|
||||
"while the group is running");
|
||||
}
|
||||
|
||||
@@ -180,11 +180,11 @@ class CommandScheduler final : public frc::Sendable,
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
void SetDefaultCommand(Subsystem* subsystem, T&& defaultCommand) {
|
||||
if (!defaultCommand.HasRequirement(subsystem)) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Default commands must require their subsystem!");
|
||||
}
|
||||
if (defaultCommand.IsFinished()) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Default commands should not end!");
|
||||
}
|
||||
SetDefaultCommandImpl(subsystem,
|
||||
|
||||
@@ -32,7 +32,7 @@ Command::Command(Subsystem& subsystem) : Command("", -1.0) {
|
||||
Command::Command(const wpi::Twine& name, double timeout) {
|
||||
// We use -1.0 to indicate no timeout.
|
||||
if (timeout < 0.0 && timeout != -1.0) {
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0.0", timeout);
|
||||
}
|
||||
|
||||
m_timeout = timeout;
|
||||
@@ -77,7 +77,7 @@ void Command::Requires(Subsystem* subsystem) {
|
||||
if (subsystem != nullptr) {
|
||||
m_requirements.insert(subsystem);
|
||||
} else {
|
||||
throw FRC_MakeError(err::NullParameter, "subsystem");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "subsystem");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ void Command::Start() {
|
||||
LockChanges();
|
||||
if (m_parent != nullptr) {
|
||||
throw FRC_MakeError(
|
||||
err::CommandIllegalUse,
|
||||
err::CommandIllegalUse, "{}",
|
||||
"Can not start a command that is part of a command group");
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ bool Command::Run() {
|
||||
void Command::Cancel() {
|
||||
if (m_parent != nullptr) {
|
||||
throw FRC_MakeError(
|
||||
err::CommandIllegalUse,
|
||||
err::CommandIllegalUse, "{}",
|
||||
"Can not cancel a command that is part of a command group");
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ int Command::GetID() const {
|
||||
|
||||
void Command::SetTimeout(double timeout) {
|
||||
if (timeout < 0.0) {
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0.0", timeout);
|
||||
} else {
|
||||
m_timeout = timeout;
|
||||
}
|
||||
@@ -187,18 +187,16 @@ bool Command::AssertUnlocked(const std::string& message) {
|
||||
if (m_locked) {
|
||||
throw FRC_MakeError(
|
||||
err::CommandIllegalUse,
|
||||
message +
|
||||
wpi::Twine{
|
||||
" after being started or being added to a command group"});
|
||||
"{} after being started or being added to a command group", message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Command::SetParent(CommandGroup* parent) {
|
||||
if (parent == nullptr) {
|
||||
throw FRC_MakeError(err::NullParameter, "parent");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "parent");
|
||||
} else if (m_parent != nullptr) {
|
||||
throw FRC_MakeError(err::CommandIllegalUse,
|
||||
throw FRC_MakeError(err::CommandIllegalUse, "{}",
|
||||
"Can not give command to a command group after "
|
||||
"already being put in a command group");
|
||||
} else {
|
||||
|
||||
@@ -12,7 +12,7 @@ CommandGroup::CommandGroup(const wpi::Twine& name) : Command(name) {}
|
||||
|
||||
void CommandGroup::AddSequential(Command* command) {
|
||||
if (!command) {
|
||||
throw FRC_MakeError(err::NullParameter, "command");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "command");
|
||||
}
|
||||
if (!AssertUnlocked("Cannot add new command to command group")) {
|
||||
return;
|
||||
@@ -31,13 +31,13 @@ void CommandGroup::AddSequential(Command* command) {
|
||||
|
||||
void CommandGroup::AddSequential(Command* command, double timeout) {
|
||||
if (!command) {
|
||||
throw FRC_MakeError(err::NullParameter, "command");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "command");
|
||||
}
|
||||
if (!AssertUnlocked("Cannot add new command to command group")) {
|
||||
return;
|
||||
}
|
||||
if (timeout < 0.0) {
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0.0", timeout);
|
||||
}
|
||||
|
||||
m_commands.emplace_back(command, CommandGroupEntry::kSequence_InSequence,
|
||||
@@ -54,7 +54,7 @@ void CommandGroup::AddSequential(Command* command, double timeout) {
|
||||
|
||||
void CommandGroup::AddParallel(Command* command) {
|
||||
if (!command) {
|
||||
throw FRC_MakeError(err::NullParameter, "command");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "command");
|
||||
return;
|
||||
}
|
||||
if (!AssertUnlocked("Cannot add new command to command group")) {
|
||||
@@ -74,13 +74,13 @@ void CommandGroup::AddParallel(Command* command) {
|
||||
|
||||
void CommandGroup::AddParallel(Command* command, double timeout) {
|
||||
if (!command) {
|
||||
throw FRC_MakeError(err::NullParameter, "command");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "command");
|
||||
}
|
||||
if (!AssertUnlocked("Cannot add new command to command group")) {
|
||||
return;
|
||||
}
|
||||
if (timeout < 0.0) {
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0");
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "timeout {} < 0.0", timeout);
|
||||
}
|
||||
|
||||
m_commands.emplace_back(command, CommandGroupEntry::kSequence_BranchChild,
|
||||
|
||||
@@ -65,7 +65,7 @@ void Scheduler::AddButton(ButtonScheduler* button) {
|
||||
|
||||
void Scheduler::RegisterSubsystem(Subsystem* subsystem) {
|
||||
if (!subsystem) {
|
||||
throw FRC_MakeError(err::NullParameter, "subsystem");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "subsystem");
|
||||
}
|
||||
m_impl->subsystems.insert(subsystem);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ void Scheduler::Run() {
|
||||
for (auto& addition : m_impl->additions) {
|
||||
// Check to make sure no adding during adding
|
||||
if (m_impl->adding) {
|
||||
FRC_ReportError(warn::IncompatibleState,
|
||||
FRC_ReportError(warn::IncompatibleState, "{}",
|
||||
"Can not start command from cancel method");
|
||||
} else {
|
||||
m_impl->ProcessCommandAddition(addition);
|
||||
@@ -121,7 +121,7 @@ void Scheduler::Run() {
|
||||
for (auto& subsystem : m_impl->subsystems) {
|
||||
if (subsystem->GetCurrentCommand() == nullptr) {
|
||||
if (m_impl->adding) {
|
||||
FRC_ReportError(warn::IncompatibleState,
|
||||
FRC_ReportError(warn::IncompatibleState, "{}",
|
||||
"Can not start command from cancel method");
|
||||
} else {
|
||||
m_impl->ProcessCommandAddition(subsystem->GetDefaultCommand());
|
||||
@@ -133,7 +133,7 @@ void Scheduler::Run() {
|
||||
|
||||
void Scheduler::Remove(Command* command) {
|
||||
if (!command) {
|
||||
throw FRC_MakeError(err::NullParameter, "command");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "command");
|
||||
}
|
||||
|
||||
m_impl->Remove(command);
|
||||
|
||||
@@ -24,7 +24,7 @@ void Subsystem::SetDefaultCommand(Command* command) {
|
||||
} else {
|
||||
const auto& reqs = command->GetRequirements();
|
||||
if (std::find(reqs.begin(), reqs.end(), this) == reqs.end()) {
|
||||
throw FRC_MakeError(err::CommandIllegalUse,
|
||||
throw FRC_MakeError(err::CommandIllegalUse, "{}",
|
||||
"A default command must require the subsystem");
|
||||
}
|
||||
|
||||
|
||||
@@ -15,19 +15,19 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
AddressableLED::AddressableLED(int port) {
|
||||
AddressableLED::AddressableLED(int port) : m_port{port} {
|
||||
int32_t status = 0;
|
||||
|
||||
auto stack = wpi::GetStackTrace(1);
|
||||
m_pwmHandle =
|
||||
HAL_InitializePWMPort(HAL_GetPort(port), stack.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Port " + wpi::Twine{port});
|
||||
FRC_CheckErrorStatus(status, "Port {}", port);
|
||||
if (m_pwmHandle == HAL_kInvalidHandle) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_handle = HAL_InitializeAddressableLED(m_pwmHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Port " + wpi::Twine{port});
|
||||
FRC_CheckErrorStatus(status, "Port {}", port);
|
||||
if (m_handle == HAL_kInvalidHandle) {
|
||||
HAL_FreePWMPort(m_pwmHandle, &status);
|
||||
}
|
||||
@@ -39,13 +39,13 @@ AddressableLED::~AddressableLED() {
|
||||
HAL_FreeAddressableLED(m_handle);
|
||||
int32_t status = 0;
|
||||
HAL_FreePWMPort(m_pwmHandle, &status);
|
||||
FRC_ReportError(status, "FreePWM");
|
||||
FRC_ReportError(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void AddressableLED::SetLength(int length) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAddressableLEDLength(m_handle, length, &status);
|
||||
FRC_CheckErrorStatus(status, "length " + wpi::Twine{length});
|
||||
FRC_CheckErrorStatus(status, "Port {} length {}", m_port, length);
|
||||
}
|
||||
|
||||
static_assert(sizeof(AddressableLED::LEDData) == sizeof(HAL_AddressableLEDData),
|
||||
@@ -55,14 +55,14 @@ void AddressableLED::SetData(wpi::ArrayRef<LEDData> ledData) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteAddressableLEDData(m_handle, ledData.begin(), ledData.size(),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "SetData");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void AddressableLED::SetData(std::initializer_list<LEDData> ledData) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteAddressableLEDData(m_handle, ledData.begin(), ledData.size(),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "SetData");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void AddressableLED::SetBitTiming(units::nanosecond_t lowTime0,
|
||||
@@ -73,25 +73,25 @@ void AddressableLED::SetBitTiming(units::nanosecond_t lowTime0,
|
||||
HAL_SetAddressableLEDBitTiming(
|
||||
m_handle, lowTime0.to<int32_t>(), highTime0.to<int32_t>(),
|
||||
lowTime1.to<int32_t>(), highTime1.to<int32_t>(), &status);
|
||||
FRC_CheckErrorStatus(status, "SetBitTiming");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void AddressableLED::SetSyncTime(units::microsecond_t syncTime) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAddressableLEDSyncTime(m_handle, syncTime.to<int32_t>(), &status);
|
||||
FRC_CheckErrorStatus(status, "SetSyncTime");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void AddressableLED::Start() {
|
||||
int32_t status = 0;
|
||||
HAL_StartAddressableLEDOutput(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Start");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void AddressableLED::Stop() {
|
||||
int32_t status = 0;
|
||||
HAL_StopAddressableLEDOutput(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Stop");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void AddressableLED::LEDData::SetHSV(int h, int s, int v) {
|
||||
|
||||
@@ -21,7 +21,7 @@ AnalogAccelerometer::AnalogAccelerometer(int channel)
|
||||
AnalogAccelerometer::AnalogAccelerometer(AnalogInput* channel)
|
||||
: m_analogInput(channel, NullDeleter<AnalogInput>()) {
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "channel");
|
||||
}
|
||||
InitAccelerometer();
|
||||
}
|
||||
@@ -29,7 +29,7 @@ AnalogAccelerometer::AnalogAccelerometer(AnalogInput* channel)
|
||||
AnalogAccelerometer::AnalogAccelerometer(std::shared_ptr<AnalogInput> channel)
|
||||
: m_analogInput(channel) {
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "channel");
|
||||
}
|
||||
InitAccelerometer();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ AnalogGyro::AnalogGyro(AnalogInput* channel)
|
||||
AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel)
|
||||
: m_analog(channel) {
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "channel");
|
||||
}
|
||||
InitGyro();
|
||||
Calibrate();
|
||||
@@ -48,13 +48,13 @@ AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, int center,
|
||||
double offset)
|
||||
: m_analog(channel) {
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "channel");
|
||||
}
|
||||
InitGyro();
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond,
|
||||
offset, center, &status);
|
||||
FRC_CheckErrorStatus(status, "SetAnalogGyroParameters");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -65,28 +65,28 @@ AnalogGyro::~AnalogGyro() {
|
||||
double AnalogGyro::GetAngle() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroAngle(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetAngle");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
return value;
|
||||
}
|
||||
|
||||
double AnalogGyro::GetRate() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroRate(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetRate");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
return value;
|
||||
}
|
||||
|
||||
int AnalogGyro::GetCenter() const {
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetAnalogGyroCenter(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetCenter");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
return value;
|
||||
}
|
||||
|
||||
double AnalogGyro::GetOffset() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroOffset(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetOffset");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -94,19 +94,19 @@ void AnalogGyro::SetSensitivity(double voltsPerDegreePerSecond) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroVoltsPerDegreePerSecond(m_gyroHandle,
|
||||
voltsPerDegreePerSecond, &status);
|
||||
FRC_CheckErrorStatus(status, "SetSensitivity");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
void AnalogGyro::SetDeadband(double volts) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroDeadband(m_gyroHandle, volts, &status);
|
||||
FRC_CheckErrorStatus(status, "SetDeadband");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
void AnalogGyro::Reset() {
|
||||
int32_t status = 0;
|
||||
HAL_ResetAnalogGyro(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Reset");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
void AnalogGyro::InitGyro() {
|
||||
@@ -115,12 +115,12 @@ void AnalogGyro::InitGyro() {
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_gyroHandle =
|
||||
HAL_InitializeAnalogGyro(m_analog->m_port, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "InitializeAnalogGyro");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetupAnalogGyro(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "SetupAnalogGyro");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Gyro, m_analog->GetChannel() + 1);
|
||||
|
||||
@@ -131,7 +131,7 @@ void AnalogGyro::InitGyro() {
|
||||
void AnalogGyro::Calibrate() {
|
||||
int32_t status = 0;
|
||||
HAL_CalibrateAnalogGyro(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Calibrate");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
std::shared_ptr<AnalogInput> AnalogGyro::GetAnalogInput() const {
|
||||
|
||||
@@ -21,8 +21,7 @@ using namespace frc;
|
||||
|
||||
AnalogInput::AnalogInput(int channel) {
|
||||
if (!SensorUtil::CheckAnalogInputChannel(channel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Analog Input " + wpi::Twine{channel});
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel);
|
||||
}
|
||||
|
||||
m_channel = channel;
|
||||
@@ -31,7 +30,7 @@ AnalogInput::AnalogInput(int channel) {
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_port = HAL_InitializeAnalogInputPort(port, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogChannel, channel + 1);
|
||||
|
||||
@@ -45,28 +44,28 @@ AnalogInput::~AnalogInput() {
|
||||
int AnalogInput::GetValue() const {
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetAnalogValue(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return value;
|
||||
}
|
||||
|
||||
int AnalogInput::GetAverageValue() const {
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetAnalogAverageValue(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return value;
|
||||
}
|
||||
|
||||
double AnalogInput::GetVoltage() const {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetAnalogVoltage(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
double AnalogInput::GetAverageVoltage() const {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetAnalogAverageVoltage(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
@@ -77,47 +76,47 @@ int AnalogInput::GetChannel() const {
|
||||
void AnalogInput::SetAverageBits(int bits) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogAverageBits(m_port, bits, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
int AnalogInput::GetAverageBits() const {
|
||||
int32_t status = 0;
|
||||
int averageBits = HAL_GetAnalogAverageBits(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return averageBits;
|
||||
}
|
||||
|
||||
void AnalogInput::SetOversampleBits(int bits) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogOversampleBits(m_port, bits, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
int AnalogInput::GetOversampleBits() const {
|
||||
int32_t status = 0;
|
||||
int oversampleBits = HAL_GetAnalogOversampleBits(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return oversampleBits;
|
||||
}
|
||||
|
||||
int AnalogInput::GetLSBWeight() const {
|
||||
int32_t status = 0;
|
||||
int lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return lsbWeight;
|
||||
}
|
||||
|
||||
int AnalogInput::GetOffset() const {
|
||||
int32_t status = 0;
|
||||
int offset = HAL_GetAnalogOffset(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return offset;
|
||||
}
|
||||
|
||||
bool AnalogInput::IsAccumulatorChannel() const {
|
||||
int32_t status = 0;
|
||||
bool isAccum = HAL_IsAccumulatorChannel(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return isAccum;
|
||||
}
|
||||
|
||||
@@ -125,7 +124,7 @@ void AnalogInput::InitAccumulator() {
|
||||
m_accumulatorOffset = 0;
|
||||
int32_t status = 0;
|
||||
HAL_InitAccumulator(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorInitialValue(int64_t initialValue) {
|
||||
@@ -135,7 +134,7 @@ void AnalogInput::SetAccumulatorInitialValue(int64_t initialValue) {
|
||||
void AnalogInput::ResetAccumulator() {
|
||||
int32_t status = 0;
|
||||
HAL_ResetAccumulator(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
|
||||
// Wait until the next sample, so the next call to GetAccumulator*()
|
||||
// won't have old values.
|
||||
@@ -148,46 +147,46 @@ void AnalogInput::ResetAccumulator() {
|
||||
void AnalogInput::SetAccumulatorCenter(int center) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAccumulatorCenter(m_port, center, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorDeadband(int deadband) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAccumulatorDeadband(m_port, deadband, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
int64_t AnalogInput::GetAccumulatorValue() const {
|
||||
int32_t status = 0;
|
||||
int64_t value = HAL_GetAccumulatorValue(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return value + m_accumulatorOffset;
|
||||
}
|
||||
|
||||
int64_t AnalogInput::GetAccumulatorCount() const {
|
||||
int32_t status = 0;
|
||||
int64_t count = HAL_GetAccumulatorCount(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return count;
|
||||
}
|
||||
|
||||
void AnalogInput::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
int32_t status = 0;
|
||||
HAL_GetAccumulatorOutput(m_port, &value, &count, &status);
|
||||
FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
value += m_accumulatorOffset;
|
||||
}
|
||||
|
||||
void AnalogInput::SetSampleRate(double samplesPerSecond) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogSampleRate(samplesPerSecond, &status);
|
||||
FRC_CheckErrorStatus(status, "SetSampleRate");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetSampleRate");
|
||||
}
|
||||
|
||||
double AnalogInput::GetSampleRate() {
|
||||
int32_t status = 0;
|
||||
double sampleRate = HAL_GetAnalogSampleRate(&status);
|
||||
FRC_CheckErrorStatus(status, "GetSampleRate");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetSampleRate");
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ using namespace frc;
|
||||
|
||||
AnalogOutput::AnalogOutput(int channel) {
|
||||
if (!SensorUtil::CheckAnalogOutputChannel(channel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"analog output " + wpi::Twine(channel));
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel);
|
||||
}
|
||||
|
||||
m_channel = channel;
|
||||
@@ -32,7 +31,7 @@ AnalogOutput::AnalogOutput(int channel) {
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_port = HAL_InitializeAnalogOutputPort(port, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "analog output " + wpi::Twine(channel));
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogOutput, m_channel + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "AnalogOutput", m_channel);
|
||||
@@ -45,13 +44,13 @@ AnalogOutput::~AnalogOutput() {
|
||||
void AnalogOutput::SetVoltage(double voltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogOutput(m_port, voltage, &status);
|
||||
FRC_CheckErrorStatus(status, "SetVoltage");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
double AnalogOutput::GetVoltage() const {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetAnalogOutput(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "GetVoltage");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ AnalogTrigger::AnalogTrigger(AnalogInput* input) {
|
||||
m_analogInput = input;
|
||||
int32_t status = 0;
|
||||
m_trigger = HAL_InitializeAnalogTrigger(input->m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "InitializeAnalogTrigger");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", input->GetChannel());
|
||||
int index = GetIndex();
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1);
|
||||
@@ -37,7 +37,7 @@ AnalogTrigger::AnalogTrigger(DutyCycle* input) {
|
||||
m_dutyCycle = input;
|
||||
int32_t status = 0;
|
||||
m_trigger = HAL_InitializeAnalogTriggerDutyCycle(input->m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "InitializeAnalogTriggerDutyCycle");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_dutyCycle->GetSourceChannel());
|
||||
int index = GetIndex();
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1);
|
||||
@@ -47,7 +47,7 @@ AnalogTrigger::AnalogTrigger(DutyCycle* input) {
|
||||
AnalogTrigger::~AnalogTrigger() {
|
||||
int32_t status = 0;
|
||||
HAL_CleanAnalogTrigger(m_trigger, &status);
|
||||
FRC_ReportError(status, "CleanAnalogTrigger");
|
||||
FRC_ReportError(status, "Channel {}", GetSourceChannel());
|
||||
|
||||
if (m_ownsAnalog) {
|
||||
delete m_analogInput;
|
||||
@@ -75,51 +75,51 @@ AnalogTrigger& AnalogTrigger::operator=(AnalogTrigger&& rhs) {
|
||||
void AnalogTrigger::SetLimitsVoltage(double lower, double upper) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsVoltage(m_trigger, lower, upper, &status);
|
||||
FRC_CheckErrorStatus(status, "SetLimitsVoltage");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsDutyCycle(double lower, double upper) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsDutyCycle(m_trigger, lower, upper, &status);
|
||||
FRC_CheckErrorStatus(status, "SetLimitsDutyCycle");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsRaw(int lower, int upper) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsRaw(m_trigger, lower, upper, &status);
|
||||
FRC_CheckErrorStatus(status, "SetLimitsRaw");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetAveraged(bool useAveragedValue) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerAveraged(m_trigger, useAveragedValue, &status);
|
||||
FRC_CheckErrorStatus(status, "SetAveraged");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetFiltered(bool useFilteredValue) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerFiltered(m_trigger, useFilteredValue, &status);
|
||||
FRC_CheckErrorStatus(status, "SetFiltered");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
}
|
||||
|
||||
int AnalogTrigger::GetIndex() const {
|
||||
int32_t status = 0;
|
||||
auto ret = HAL_GetAnalogTriggerFPGAIndex(m_trigger, &status);
|
||||
FRC_CheckErrorStatus(status, "GetIndex");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AnalogTrigger::GetInWindow() {
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerInWindow(m_trigger, &status);
|
||||
FRC_CheckErrorStatus(status, "GetInWindow");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool AnalogTrigger::GetTriggerState() {
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerTriggerState(m_trigger, &status);
|
||||
FRC_CheckErrorStatus(status, "GetTriggerState");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -134,3 +134,13 @@ void AnalogTrigger::InitSendable(SendableBuilder& builder) {
|
||||
m_analogInput->InitSendable(builder);
|
||||
}
|
||||
}
|
||||
|
||||
int AnalogTrigger::GetSourceChannel() const {
|
||||
if (m_analogInput) {
|
||||
return m_analogInput->GetChannel();
|
||||
} else if (m_dutyCycle) {
|
||||
return m_dutyCycle->GetSourceChannel();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ bool AnalogTriggerOutput::Get() const {
|
||||
bool result = HAL_GetAnalogTriggerOutput(
|
||||
m_trigger->m_trigger, static_cast<HAL_AnalogTriggerType>(m_outputType),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
FRC_CheckErrorStatus(status, "{}", "Get");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ BuiltInAccelerometer::BuiltInAccelerometer(Range range) {
|
||||
|
||||
void BuiltInAccelerometer::SetRange(Range range) {
|
||||
if (range == kRange_16G) {
|
||||
throw FRC_MakeError(err::ParameterOutOfRange,
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "{}",
|
||||
"16G range not supported (use k2G, k4G, or k8G)");
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ CAN::CAN(int deviceId) {
|
||||
int32_t status = 0;
|
||||
m_handle =
|
||||
HAL_InitializeCAN(kTeamManufacturer, deviceId, kTeamDeviceType, &status);
|
||||
FRC_CheckErrorStatus(status, "device id " + wpi::Twine{deviceId});
|
||||
FRC_CheckErrorStatus(status, "device id {}", deviceId);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_CAN, deviceId + 1);
|
||||
}
|
||||
@@ -29,9 +29,8 @@ CAN::CAN(int deviceId, int deviceManufacturer, int deviceType) {
|
||||
m_handle = HAL_InitializeCAN(
|
||||
static_cast<HAL_CANManufacturer>(deviceManufacturer), deviceId,
|
||||
static_cast<HAL_CANDeviceType>(deviceType), &status);
|
||||
FRC_CheckErrorStatus(status, "device id " + wpi::Twine{deviceId} + " mfg " +
|
||||
wpi::Twine{deviceManufacturer} + " type " +
|
||||
wpi::Twine{deviceType});
|
||||
FRC_CheckErrorStatus(status, "device id {} mfg {} type {}", deviceId,
|
||||
deviceManufacturer, deviceType);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_CAN, deviceId + 1);
|
||||
}
|
||||
@@ -46,20 +45,20 @@ CAN::~CAN() {
|
||||
void CAN::WritePacket(const uint8_t* data, int length, int apiId) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteCANPacket(m_handle, data, length, apiId, &status);
|
||||
FRC_CheckErrorStatus(status, "WritePacket");
|
||||
FRC_CheckErrorStatus(status, "{}", "WritePacket");
|
||||
}
|
||||
|
||||
void CAN::WritePacketRepeating(const uint8_t* data, int length, int apiId,
|
||||
int repeatMs) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteCANPacketRepeating(m_handle, data, length, apiId, repeatMs, &status);
|
||||
FRC_CheckErrorStatus(status, "WritePacketRepeating");
|
||||
FRC_CheckErrorStatus(status, "{}", "WritePacketRepeating");
|
||||
}
|
||||
|
||||
void CAN::WriteRTRFrame(int length, int apiId) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteCANRTRFrame(m_handle, length, apiId, &status);
|
||||
FRC_CheckErrorStatus(status, "WriteRTRFrame");
|
||||
FRC_CheckErrorStatus(status, "{}", "WriteRTRFrame");
|
||||
}
|
||||
|
||||
int CAN::WritePacketNoError(const uint8_t* data, int length, int apiId) {
|
||||
@@ -84,7 +83,7 @@ int CAN::WriteRTRFrameNoError(int length, int apiId) {
|
||||
void CAN::StopPacketRepeating(int apiId) {
|
||||
int32_t status = 0;
|
||||
HAL_StopCANPacketRepeating(m_handle, apiId, &status);
|
||||
FRC_CheckErrorStatus(status, "StopPacketRepeating");
|
||||
FRC_CheckErrorStatus(status, "{}", "StopPacketRepeating");
|
||||
}
|
||||
|
||||
bool CAN::ReadPacketNew(int apiId, CANData* data) {
|
||||
@@ -95,7 +94,7 @@ bool CAN::ReadPacketNew(int apiId, CANData* data) {
|
||||
return false;
|
||||
}
|
||||
if (status != 0) {
|
||||
FRC_CheckErrorStatus(status, "ReadPacketNew");
|
||||
FRC_CheckErrorStatus(status, "{}", "ReadPacketNew");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@@ -110,7 +109,7 @@ bool CAN::ReadPacketLatest(int apiId, CANData* data) {
|
||||
return false;
|
||||
}
|
||||
if (status != 0) {
|
||||
FRC_CheckErrorStatus(status, "ReadPacketLatest");
|
||||
FRC_CheckErrorStatus(status, "{}", "ReadPacketLatest");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@@ -126,7 +125,7 @@ bool CAN::ReadPacketTimeout(int apiId, int timeoutMs, CANData* data) {
|
||||
return false;
|
||||
}
|
||||
if (status != 0) {
|
||||
FRC_CheckErrorStatus(status, "ReadPacketTimeout");
|
||||
FRC_CheckErrorStatus(status, "{}", "ReadPacketTimeout");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
||||
@@ -18,7 +18,7 @@ using namespace frc;
|
||||
Compressor::Compressor(int pcmID) : m_module(pcmID) {
|
||||
int32_t status = 0;
|
||||
m_compressorHandle = HAL_InitializeCompressor(m_module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
SetClosedLoopControl(true);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Compressor, pcmID + 1);
|
||||
@@ -36,34 +36,34 @@ void Compressor::Stop() {
|
||||
bool Compressor::Enabled() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCompressor(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetPressureSwitchValue() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCompressorPressureSwitch(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return value;
|
||||
}
|
||||
|
||||
double Compressor::GetCompressorCurrent() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetCompressorCurrent(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return value;
|
||||
}
|
||||
|
||||
void Compressor::SetClosedLoopControl(bool on) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCompressorClosedLoopControl(m_compressorHandle, on, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
bool Compressor::GetClosedLoopControl() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCompressorClosedLoopControl(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ bool Compressor::GetCompressorCurrentTooHighFault() const {
|
||||
int32_t status = 0;
|
||||
bool value =
|
||||
HAL_GetCompressorCurrentTooHighFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -79,21 +79,21 @@ bool Compressor::GetCompressorCurrentTooHighStickyFault() const {
|
||||
int32_t status = 0;
|
||||
bool value =
|
||||
HAL_GetCompressorCurrentTooHighStickyFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorShortedStickyFault() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCompressorShortedStickyFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorShortedFault() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCompressorShortedFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -101,21 +101,21 @@ bool Compressor::GetCompressorNotConnectedStickyFault() const {
|
||||
int32_t status = 0;
|
||||
bool value =
|
||||
HAL_GetCompressorNotConnectedStickyFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Compressor::GetCompressorNotConnectedFault() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCompressorNotConnectedFault(m_compressorHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return value;
|
||||
}
|
||||
|
||||
void Compressor::ClearAllPCMStickyFaults() {
|
||||
int32_t status = 0;
|
||||
HAL_ClearAllPCMStickyFaults(m_module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
int Compressor::GetModule() const {
|
||||
|
||||
@@ -22,7 +22,7 @@ Counter::Counter(Mode mode) {
|
||||
int32_t status = 0;
|
||||
m_counter = HAL_InitializeCounter(static_cast<HAL_Counter_Mode>(mode),
|
||||
&m_index, &status);
|
||||
FRC_CheckErrorStatus(status, "InitializeCounter");
|
||||
FRC_CheckErrorStatus(status, "{}", "InitializeCounter");
|
||||
|
||||
SetMaxPeriod(0.5);
|
||||
|
||||
@@ -64,8 +64,8 @@ Counter::Counter(EncodingType encodingType,
|
||||
std::shared_ptr<DigitalSource> downSource, bool inverted)
|
||||
: Counter(kExternalDirection) {
|
||||
if (encodingType != k1X && encodingType != k2X) {
|
||||
throw FRC_MakeError(err::ParameterOutOfRange,
|
||||
"Counter only supports 1X and 2X quadrature decoding.");
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "{}",
|
||||
"Counter only supports 1X and 2X quadrature decoding");
|
||||
}
|
||||
SetUpSource(upSource);
|
||||
SetDownSource(downSource);
|
||||
@@ -79,7 +79,7 @@ Counter::Counter(EncodingType encodingType,
|
||||
HAL_SetCounterAverageSize(m_counter, 2, &status);
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "Counter constructor");
|
||||
FRC_CheckErrorStatus(status, "{}", "Counter constructor");
|
||||
SetDownSourceEdge(inverted, true);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ Counter::~Counter() {
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_FreeCounter(m_counter, &status);
|
||||
FRC_ReportError(status, "Counter destructor");
|
||||
FRC_ReportError(status, "{}", "Counter destructor");
|
||||
}
|
||||
|
||||
void Counter::SetUpSource(int channel) {
|
||||
@@ -124,7 +124,7 @@ void Counter::SetUpSource(std::shared_ptr<DigitalSource> source) {
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
source->GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "SetUpSource");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetUpSource");
|
||||
}
|
||||
|
||||
void Counter::SetUpSource(DigitalSource& source) {
|
||||
@@ -135,19 +135,19 @@ void Counter::SetUpSource(DigitalSource& source) {
|
||||
void Counter::SetUpSourceEdge(bool risingEdge, bool fallingEdge) {
|
||||
if (m_upSource == nullptr) {
|
||||
throw FRC_MakeError(
|
||||
err::NullParameter,
|
||||
err::NullParameter, "{}",
|
||||
"Must set non-nullptr UpSource before setting UpSourceEdge");
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterUpSourceEdge(m_counter, risingEdge, fallingEdge, &status);
|
||||
FRC_CheckErrorStatus(status, "SetUpSourceEdge");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetUpSourceEdge");
|
||||
}
|
||||
|
||||
void Counter::ClearUpSource() {
|
||||
m_upSource.reset();
|
||||
int32_t status = 0;
|
||||
HAL_ClearCounterUpSource(m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "ClearUpSource");
|
||||
FRC_CheckErrorStatus(status, "{}", "ClearUpSource");
|
||||
}
|
||||
|
||||
void Counter::SetDownSource(int channel) {
|
||||
@@ -184,76 +184,75 @@ void Counter::SetDownSource(std::shared_ptr<DigitalSource> source) {
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
source->GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "SetDownSource");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetDownSource");
|
||||
}
|
||||
|
||||
void Counter::SetDownSourceEdge(bool risingEdge, bool fallingEdge) {
|
||||
if (m_downSource == nullptr) {
|
||||
throw FRC_MakeError(
|
||||
err::NullParameter,
|
||||
err::NullParameter, "{}",
|
||||
"Must set non-nullptr DownSource before setting DownSourceEdge");
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterDownSourceEdge(m_counter, risingEdge, fallingEdge, &status);
|
||||
FRC_CheckErrorStatus(status, "SetDownSourceEdge");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetDownSourceEdge");
|
||||
}
|
||||
|
||||
void Counter::ClearDownSource() {
|
||||
m_downSource.reset();
|
||||
int32_t status = 0;
|
||||
HAL_ClearCounterDownSource(m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "ClearDownSource");
|
||||
FRC_CheckErrorStatus(status, "{}", "ClearDownSource");
|
||||
}
|
||||
|
||||
void Counter::SetUpDownCounterMode() {
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterUpDownMode(m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "SetUpDownCounterMode");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetUpDownCounterMode");
|
||||
}
|
||||
|
||||
void Counter::SetExternalDirectionMode() {
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterExternalDirectionMode(m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "SetExternalDirectionMode");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetExternalDirectionMode");
|
||||
}
|
||||
|
||||
void Counter::SetSemiPeriodMode(bool highSemiPeriod) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterSemiPeriodMode(m_counter, highSemiPeriod, &status);
|
||||
FRC_CheckErrorStatus(
|
||||
status,
|
||||
"SetSemiPeriodMode to " + wpi::Twine{highSemiPeriod ? "true" : "false"});
|
||||
FRC_CheckErrorStatus(status, "SetSemiPeriodMode to {}",
|
||||
highSemiPeriod ? "true" : "false");
|
||||
}
|
||||
|
||||
void Counter::SetPulseLengthMode(double threshold) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterPulseLengthMode(m_counter, threshold, &status);
|
||||
FRC_CheckErrorStatus(status, "SetPulseLengthMode");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetPulseLengthMode");
|
||||
}
|
||||
|
||||
void Counter::SetReverseDirection(bool reverseDirection) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterReverseDirection(m_counter, reverseDirection, &status);
|
||||
FRC_CheckErrorStatus(status,
|
||||
"SetReverseDirection to " +
|
||||
wpi::Twine{reverseDirection ? "true" : "false"});
|
||||
FRC_CheckErrorStatus(status, "SetReverseDirection to {}",
|
||||
reverseDirection ? "true" : "false");
|
||||
}
|
||||
|
||||
void Counter::SetSamplesToAverage(int samplesToAverage) {
|
||||
if (samplesToAverage < 1 || samplesToAverage > 127) {
|
||||
throw FRC_MakeError(err::ParameterOutOfRange,
|
||||
"Average counter values must be between 1 and 127");
|
||||
throw FRC_MakeError(
|
||||
err::ParameterOutOfRange,
|
||||
"Average counter values must be between 1 and 127, {} out of range",
|
||||
samplesToAverage);
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterSamplesToAverage(m_counter, samplesToAverage, &status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetSamplesToAverage to " + wpi::Twine{samplesToAverage});
|
||||
FRC_CheckErrorStatus(status, "SetSamplesToAverage to {}", samplesToAverage);
|
||||
}
|
||||
|
||||
int Counter::GetSamplesToAverage() const {
|
||||
int32_t status = 0;
|
||||
int samples = HAL_GetCounterSamplesToAverage(m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "GetSamplesToAverage");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetSamplesToAverage");
|
||||
return samples;
|
||||
}
|
||||
|
||||
@@ -264,46 +263,46 @@ int Counter::GetFPGAIndex() const {
|
||||
int Counter::Get() const {
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetCounter(m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
FRC_CheckErrorStatus(status, "{}", "Get");
|
||||
return value;
|
||||
}
|
||||
|
||||
void Counter::Reset() {
|
||||
int32_t status = 0;
|
||||
HAL_ResetCounter(m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "Reset");
|
||||
FRC_CheckErrorStatus(status, "{}", "Reset");
|
||||
}
|
||||
|
||||
double Counter::GetPeriod() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetCounterPeriod(m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "GetPeriod");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetPeriod");
|
||||
return value;
|
||||
}
|
||||
|
||||
void Counter::SetMaxPeriod(double maxPeriod) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterMaxPeriod(m_counter, maxPeriod, &status);
|
||||
FRC_CheckErrorStatus(status, "SetMaxPeriod");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetMaxPeriod");
|
||||
}
|
||||
|
||||
void Counter::SetUpdateWhenEmpty(bool enabled) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCounterUpdateWhenEmpty(m_counter, enabled, &status);
|
||||
FRC_CheckErrorStatus(status, "SetUpdateWhenEmpty");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetUpdateWhenEmpty");
|
||||
}
|
||||
|
||||
bool Counter::GetStopped() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCounterStopped(m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "GetStopped");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetStopped");
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Counter::GetDirection() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetCounterDirection(m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "GetDirection");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetDirection");
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ using namespace frc;
|
||||
DMA::DMA() {
|
||||
int32_t status = 0;
|
||||
dmaHandle = HAL_InitializeDMA(&status);
|
||||
FRC_CheckErrorStatus(status, "InitializeDMA");
|
||||
FRC_CheckErrorStatus(status, "{}", "InitializeDMA");
|
||||
}
|
||||
|
||||
DMA::~DMA() {
|
||||
@@ -29,68 +29,68 @@ DMA::~DMA() {
|
||||
void DMA::SetPause(bool pause) {
|
||||
int32_t status = 0;
|
||||
HAL_SetDMAPause(dmaHandle, pause, &status);
|
||||
FRC_CheckErrorStatus(status, "SetPause");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetPause");
|
||||
}
|
||||
|
||||
void DMA::SetRate(int cycles) {
|
||||
int32_t status = 0;
|
||||
HAL_SetDMARate(dmaHandle, cycles, &status);
|
||||
FRC_CheckErrorStatus(status, "SetRate");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetRate");
|
||||
}
|
||||
|
||||
void DMA::AddEncoder(const Encoder* encoder) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMAEncoder(dmaHandle, encoder->m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "AddEncoder");
|
||||
FRC_CheckErrorStatus(status, "{}", "AddEncoder");
|
||||
}
|
||||
|
||||
void DMA::AddEncoderPeriod(const Encoder* encoder) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMAEncoderPeriod(dmaHandle, encoder->m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "AddEncoderPeriod");
|
||||
FRC_CheckErrorStatus(status, "{}", "AddEncoderPeriod");
|
||||
}
|
||||
|
||||
void DMA::AddCounter(const Counter* counter) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMACounter(dmaHandle, counter->m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "AddCounter");
|
||||
FRC_CheckErrorStatus(status, "{}", "AddCounter");
|
||||
}
|
||||
|
||||
void DMA::AddCounterPeriod(const Counter* counter) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMACounterPeriod(dmaHandle, counter->m_counter, &status);
|
||||
FRC_CheckErrorStatus(status, "AddCounterPeriod");
|
||||
FRC_CheckErrorStatus(status, "{}", "AddCounterPeriod");
|
||||
}
|
||||
|
||||
void DMA::AddDigitalSource(const DigitalSource* digitalSource) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMADigitalSource(dmaHandle, digitalSource->GetPortHandleForRouting(),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "AddDigitalSource");
|
||||
FRC_CheckErrorStatus(status, "{}", "AddDigitalSource");
|
||||
}
|
||||
|
||||
void DMA::AddDutyCycle(const DutyCycle* dutyCycle) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMADutyCycle(dmaHandle, dutyCycle->m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "AddDutyCycle");
|
||||
FRC_CheckErrorStatus(status, "{}", "AddDutyCycle");
|
||||
}
|
||||
|
||||
void DMA::AddAnalogInput(const AnalogInput* analogInput) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMAAnalogInput(dmaHandle, analogInput->m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "AddAnalogInput");
|
||||
FRC_CheckErrorStatus(status, "{}", "AddAnalogInput");
|
||||
}
|
||||
|
||||
void DMA::AddAveragedAnalogInput(const AnalogInput* analogInput) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMAAveragedAnalogInput(dmaHandle, analogInput->m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "AddAveragedAnalogInput");
|
||||
FRC_CheckErrorStatus(status, "{}", "AddAveragedAnalogInput");
|
||||
}
|
||||
|
||||
void DMA::AddAnalogAccumulator(const AnalogInput* analogInput) {
|
||||
int32_t status = 0;
|
||||
HAL_AddDMAAnalogAccumulator(dmaHandle, analogInput->m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "AddAnalogAccumulator");
|
||||
FRC_CheckErrorStatus(status, "{}", "AddAnalogAccumulator");
|
||||
}
|
||||
|
||||
void DMA::SetExternalTrigger(DigitalSource* source, bool rising, bool falling) {
|
||||
@@ -99,17 +99,17 @@ void DMA::SetExternalTrigger(DigitalSource* source, bool rising, bool falling) {
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
source->GetAnalogTriggerTypeForRouting()),
|
||||
rising, falling, &status);
|
||||
FRC_CheckErrorStatus(status, "SetExternalTrigger");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetExternalTrigger");
|
||||
}
|
||||
|
||||
void DMA::StartDMA(int queueDepth) {
|
||||
int32_t status = 0;
|
||||
HAL_StartDMA(dmaHandle, queueDepth, &status);
|
||||
FRC_CheckErrorStatus(status, "StartDMA");
|
||||
FRC_CheckErrorStatus(status, "{}", "StartDMA");
|
||||
}
|
||||
|
||||
void DMA::StopDMA() {
|
||||
int32_t status = 0;
|
||||
HAL_StopDMA(dmaHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "StopDMA");
|
||||
FRC_CheckErrorStatus(status, "{}", "StopDMA");
|
||||
}
|
||||
|
||||
@@ -70,19 +70,17 @@ void DigitalGlitchFilter::DoAdd(DigitalSource* input, int requestedIndex) {
|
||||
// We don't support GlitchFilters on AnalogTriggers.
|
||||
if (input->IsAnalogTrigger()) {
|
||||
throw FRC_MakeError(
|
||||
-1, "Analog Triggers not supported for DigitalGlitchFilters");
|
||||
-1, "{}", "Analog Triggers not supported for DigitalGlitchFilters");
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetFilterSelect(input->GetPortHandleForRouting(), requestedIndex,
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status,
|
||||
"requested index " + wpi::Twine{requestedIndex});
|
||||
FRC_CheckErrorStatus(status, "requested index {}", requestedIndex);
|
||||
|
||||
// Validate that we set it correctly.
|
||||
int actualIndex =
|
||||
HAL_GetFilterSelect(input->GetPortHandleForRouting(), &status);
|
||||
FRC_CheckErrorStatus(status,
|
||||
"requested index " + wpi::Twine{requestedIndex});
|
||||
FRC_CheckErrorStatus(status, "requested index {}", requestedIndex);
|
||||
FRC_Assert(actualIndex == requestedIndex);
|
||||
}
|
||||
}
|
||||
@@ -114,7 +112,7 @@ void DigitalGlitchFilter::Remove(Counter* input) {
|
||||
void DigitalGlitchFilter::SetPeriodCycles(int fpgaCycles) {
|
||||
int32_t status = 0;
|
||||
HAL_SetFilterPeriod(m_channelIndex, fpgaCycles, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channelIndex);
|
||||
}
|
||||
|
||||
void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) {
|
||||
@@ -122,20 +120,20 @@ void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) {
|
||||
int fpgaCycles =
|
||||
nanoseconds * HAL_GetSystemClockTicksPerMicrosecond() / 4 / 1000;
|
||||
HAL_SetFilterPeriod(m_channelIndex, fpgaCycles, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channelIndex);
|
||||
}
|
||||
|
||||
int DigitalGlitchFilter::GetPeriodCycles() {
|
||||
int32_t status = 0;
|
||||
int fpgaCycles = HAL_GetFilterPeriod(m_channelIndex, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channelIndex);
|
||||
return fpgaCycles;
|
||||
}
|
||||
|
||||
uint64_t DigitalGlitchFilter::GetPeriodNanoSeconds() {
|
||||
int32_t status = 0;
|
||||
int fpgaCycles = HAL_GetFilterPeriod(m_channelIndex, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channelIndex);
|
||||
return static_cast<uint64_t>(fpgaCycles) * 1000L /
|
||||
static_cast<uint64_t>(HAL_GetSystemClockTicksPerMicrosecond() / 4);
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ using namespace frc;
|
||||
|
||||
DigitalInput::DigitalInput(int channel) {
|
||||
if (!SensorUtil::CheckDigitalChannel(channel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Digital Channel " + wpi::Twine{channel});
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel);
|
||||
}
|
||||
m_channel = channel;
|
||||
|
||||
@@ -31,7 +30,7 @@ DigitalInput::DigitalInput(int channel) {
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), true,
|
||||
stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_DigitalInput, channel + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "DigitalInput", channel);
|
||||
@@ -44,7 +43,7 @@ DigitalInput::~DigitalInput() {
|
||||
bool DigitalInput::Get() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetDIO(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ using namespace frc;
|
||||
DigitalOutput::DigitalOutput(int channel) {
|
||||
m_pwmGenerator = HAL_kInvalidHandle;
|
||||
if (!SensorUtil::CheckDigitalChannel(channel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Digital Channel " + wpi::Twine{channel});
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel);
|
||||
}
|
||||
m_channel = channel;
|
||||
|
||||
@@ -31,7 +30,7 @@ DigitalOutput::DigitalOutput(int channel) {
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), false,
|
||||
stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_DigitalOutput, channel + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "DigitalOutput", channel);
|
||||
@@ -51,13 +50,13 @@ DigitalOutput::~DigitalOutput() {
|
||||
void DigitalOutput::Set(bool value) {
|
||||
int32_t status = 0;
|
||||
HAL_SetDIO(m_handle, value, &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
bool DigitalOutput::Get() const {
|
||||
int32_t status = 0;
|
||||
bool val = HAL_GetDIO(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -80,20 +79,20 @@ int DigitalOutput::GetChannel() const {
|
||||
void DigitalOutput::Pulse(double length) {
|
||||
int32_t status = 0;
|
||||
HAL_Pulse(m_handle, length, &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
bool DigitalOutput::IsPulsing() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_IsPulsing(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return value;
|
||||
}
|
||||
|
||||
void DigitalOutput::SetPWMRate(double rate) {
|
||||
int32_t status = 0;
|
||||
HAL_SetDigitalPWMRate(rate, &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void DigitalOutput::EnablePWM(double initialDutyCycle) {
|
||||
@@ -104,13 +103,13 @@ void DigitalOutput::EnablePWM(double initialDutyCycle) {
|
||||
int32_t status = 0;
|
||||
|
||||
m_pwmGenerator = HAL_AllocateDigitalPWM(&status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
|
||||
HAL_SetDigitalPWMDutyCycle(m_pwmGenerator, initialDutyCycle, &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
|
||||
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, m_channel, &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void DigitalOutput::DisablePWM() {
|
||||
@@ -123,10 +122,10 @@ void DigitalOutput::DisablePWM() {
|
||||
// Disable the output by routing to a dead bit.
|
||||
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, SensorUtil::kDigitalChannels,
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
|
||||
HAL_FreeDigitalPWM(m_pwmGenerator, &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
|
||||
m_pwmGenerator = HAL_kInvalidHandle;
|
||||
}
|
||||
@@ -134,7 +133,7 @@ void DigitalOutput::DisablePWM() {
|
||||
void DigitalOutput::UpdateDutyCycle(double dutyCycle) {
|
||||
int32_t status = 0;
|
||||
HAL_SetDigitalPWMDutyCycle(m_pwmGenerator, dutyCycle, &status);
|
||||
FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void DigitalOutput::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
|
||||
@@ -28,31 +28,30 @@ DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel,
|
||||
m_forwardChannel(forwardChannel),
|
||||
m_reverseChannel(reverseChannel) {
|
||||
if (!SensorUtil::CheckSolenoidModule(m_moduleNumber)) {
|
||||
throw FRC_MakeError(err::ModuleIndexOutOfRange,
|
||||
"Solenoid Module " + wpi::Twine{m_moduleNumber});
|
||||
throw FRC_MakeError(err::ModuleIndexOutOfRange, "Module {}",
|
||||
m_moduleNumber);
|
||||
}
|
||||
if (!SensorUtil::CheckSolenoidChannel(m_forwardChannel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + wpi::Twine{m_forwardChannel});
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}",
|
||||
m_forwardChannel);
|
||||
}
|
||||
if (!SensorUtil::CheckSolenoidChannel(m_reverseChannel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + wpi::Twine{m_reverseChannel});
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}",
|
||||
m_reverseChannel);
|
||||
}
|
||||
int32_t status = 0;
|
||||
m_forwardHandle = HAL_InitializeSolenoidPort(
|
||||
HAL_GetPortWithModule(moduleNumber, m_forwardChannel), &status);
|
||||
FRC_CheckErrorStatus(status, "Solenoid Module " + wpi::Twine{m_moduleNumber} +
|
||||
" Channel " + wpi::Twine{m_forwardChannel});
|
||||
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
|
||||
m_forwardChannel);
|
||||
|
||||
m_reverseHandle = HAL_InitializeSolenoidPort(
|
||||
HAL_GetPortWithModule(moduleNumber, m_reverseChannel), &status);
|
||||
if (status != 0) {
|
||||
// free forward solenoid
|
||||
HAL_FreeSolenoidPort(m_forwardHandle);
|
||||
FRC_CheckErrorStatus(status, "Solenoid Module " +
|
||||
wpi::Twine{m_moduleNumber} + " Channel " +
|
||||
wpi::Twine{m_reverseChannel});
|
||||
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
|
||||
m_reverseChannel);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,12 +96,10 @@ void DoubleSolenoid::Set(Value value) {
|
||||
int rstatus = 0;
|
||||
HAL_SetSolenoid(m_reverseHandle, reverse, &rstatus);
|
||||
|
||||
FRC_CheckErrorStatus(fstatus, "Solenoid Module " +
|
||||
wpi::Twine{m_moduleNumber} + " Channel " +
|
||||
wpi::Twine{m_forwardChannel});
|
||||
FRC_CheckErrorStatus(rstatus, "Solenoid Module " +
|
||||
wpi::Twine{m_moduleNumber} + " Channel " +
|
||||
wpi::Twine{m_reverseChannel});
|
||||
FRC_CheckErrorStatus(fstatus, "Module {} Channel {}", m_moduleNumber,
|
||||
m_forwardChannel);
|
||||
FRC_CheckErrorStatus(rstatus, "Module {} Channel {}", m_moduleNumber,
|
||||
m_reverseChannel);
|
||||
}
|
||||
|
||||
DoubleSolenoid::Value DoubleSolenoid::Get() const {
|
||||
@@ -111,12 +108,10 @@ DoubleSolenoid::Value DoubleSolenoid::Get() const {
|
||||
bool valueForward = HAL_GetSolenoid(m_forwardHandle, &fstatus);
|
||||
bool valueReverse = HAL_GetSolenoid(m_reverseHandle, &rstatus);
|
||||
|
||||
FRC_CheckErrorStatus(fstatus, "Solenoid Module " +
|
||||
wpi::Twine{m_moduleNumber} + " Channel " +
|
||||
wpi::Twine{m_forwardChannel});
|
||||
FRC_CheckErrorStatus(rstatus, "Solenoid Module " +
|
||||
wpi::Twine{m_moduleNumber} + " Channel " +
|
||||
wpi::Twine{m_reverseChannel});
|
||||
FRC_CheckErrorStatus(fstatus, "Module {} Channel {}", m_moduleNumber,
|
||||
m_forwardChannel);
|
||||
FRC_CheckErrorStatus(rstatus, "Module {} Channel {}", m_moduleNumber,
|
||||
m_reverseChannel);
|
||||
|
||||
if (valueForward) {
|
||||
return kForward;
|
||||
|
||||
@@ -140,8 +140,7 @@ void DriverStation::ReportError(bool isError, int32_t code,
|
||||
|
||||
bool DriverStation::GetStickButton(int stick, int button) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return false;
|
||||
}
|
||||
if (button <= 0) {
|
||||
@@ -164,8 +163,7 @@ bool DriverStation::GetStickButton(int stick, int button) {
|
||||
|
||||
bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return false;
|
||||
}
|
||||
if (button <= 0) {
|
||||
@@ -194,8 +192,7 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
|
||||
bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return false;
|
||||
}
|
||||
if (button <= 0) {
|
||||
@@ -224,13 +221,11 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
|
||||
double DriverStation::GetStickAxis(int stick, int axis) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0.0;
|
||||
}
|
||||
if (axis < 0 || axis >= HAL_kMaxJoystickAxes) {
|
||||
FRC_ReportError(warn::BadJoystickAxis,
|
||||
"axis " + wpi::Twine{axis} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickAxis, "axis {} out of range", axis);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@@ -248,13 +243,11 @@ double DriverStation::GetStickAxis(int stick, int axis) {
|
||||
|
||||
int DriverStation::GetStickPOV(int stick, int pov) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return -1;
|
||||
}
|
||||
if (pov < 0 || pov >= HAL_kMaxJoystickPOVs) {
|
||||
FRC_ReportError(warn::BadJoystickAxis,
|
||||
"POV " + wpi::Twine{pov} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickAxis, "POV {} out of range", pov);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -272,8 +265,7 @@ int DriverStation::GetStickPOV(int stick, int pov) {
|
||||
|
||||
int DriverStation::GetStickButtons(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -285,8 +277,7 @@ int DriverStation::GetStickButtons(int stick) const {
|
||||
|
||||
int DriverStation::GetStickAxisCount(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -298,8 +289,7 @@ int DriverStation::GetStickAxisCount(int stick) const {
|
||||
|
||||
int DriverStation::GetStickPOVCount(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -311,8 +301,7 @@ int DriverStation::GetStickPOVCount(int stick) const {
|
||||
|
||||
int DriverStation::GetStickButtonCount(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -324,8 +313,7 @@ int DriverStation::GetStickButtonCount(int stick) const {
|
||||
|
||||
bool DriverStation::GetJoystickIsXbox(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -337,8 +325,7 @@ bool DriverStation::GetJoystickIsXbox(int stick) const {
|
||||
|
||||
int DriverStation::GetJoystickType(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -350,8 +337,7 @@ int DriverStation::GetJoystickType(int stick) const {
|
||||
|
||||
std::string DriverStation::GetJoystickName(int stick) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
}
|
||||
|
||||
HAL_JoystickDescriptor descriptor;
|
||||
@@ -362,8 +348,7 @@ std::string DriverStation::GetJoystickName(int stick) const {
|
||||
|
||||
int DriverStation::GetJoystickAxisType(int stick, int axis) const {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex,
|
||||
"stick " + wpi::Twine{stick} + " out of range");
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -552,7 +537,7 @@ double DriverStation::GetMatchTime() const {
|
||||
double DriverStation::GetBatteryVoltage() const {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetVinVoltage(&status);
|
||||
FRC_CheckErrorStatus(status, "getVinVoltage");
|
||||
FRC_CheckErrorStatus(status, "{}", "getVinVoltage");
|
||||
|
||||
return voltage;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ using namespace frc;
|
||||
DutyCycle::DutyCycle(DigitalSource* source)
|
||||
: m_source{source, NullDeleter<DigitalSource>()} {
|
||||
if (!m_source) {
|
||||
throw FRC_MakeError(err::NullParameter, "source");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "source");
|
||||
}
|
||||
InitDutyCycle();
|
||||
}
|
||||
@@ -30,7 +30,7 @@ DutyCycle::DutyCycle(DigitalSource& source)
|
||||
DutyCycle::DutyCycle(std::shared_ptr<DigitalSource> source)
|
||||
: m_source{std::move(source)} {
|
||||
if (!m_source) {
|
||||
throw FRC_MakeError(err::NullParameter, "source");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "source");
|
||||
}
|
||||
InitDutyCycle();
|
||||
}
|
||||
@@ -46,7 +46,7 @@ void DutyCycle::InitDutyCycle() {
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
m_source->GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "InitDutyCycle");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
int index = GetFPGAIndex();
|
||||
HAL_Report(HALUsageReporting::kResourceType_DutyCycle, index + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "Duty Cycle", index);
|
||||
@@ -55,35 +55,35 @@ void DutyCycle::InitDutyCycle() {
|
||||
int DutyCycle::GetFPGAIndex() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleFPGAIndex(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetFPGAIndex");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int DutyCycle::GetFrequency() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleFrequency(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetFrequency");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double DutyCycle::GetOutput() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleOutput(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetOutput");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
unsigned int DutyCycle::GetOutputRaw() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleOutputRaw(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetOutputRaw");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
unsigned int DutyCycle::GetOutputScaleFactor() const {
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleOutputScaleFactor(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetOutputScaleFactor");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@ Encoder::Encoder(DigitalSource* aSource, DigitalSource* bSource,
|
||||
: m_aSource(aSource, NullDeleter<DigitalSource>()),
|
||||
m_bSource(bSource, NullDeleter<DigitalSource>()) {
|
||||
if (!m_aSource) {
|
||||
throw FRC_MakeError(err::NullParameter, "aSource");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "aSource");
|
||||
}
|
||||
if (!m_bSource) {
|
||||
throw FRC_MakeError(err::NullParameter, "bSource");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "bSource");
|
||||
}
|
||||
InitEncoder(reverseDirection, encodingType);
|
||||
}
|
||||
@@ -52,10 +52,10 @@ Encoder::Encoder(std::shared_ptr<DigitalSource> aSource,
|
||||
EncodingType encodingType)
|
||||
: m_aSource(std::move(aSource)), m_bSource(std::move(bSource)) {
|
||||
if (!m_aSource) {
|
||||
throw FRC_MakeError(err::NullParameter, "aSource");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "aSource");
|
||||
}
|
||||
if (!m_bSource) {
|
||||
throw FRC_MakeError(err::NullParameter, "bSource");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "bSource");
|
||||
}
|
||||
InitEncoder(reverseDirection, encodingType);
|
||||
}
|
||||
@@ -63,118 +63,118 @@ Encoder::Encoder(std::shared_ptr<DigitalSource> aSource,
|
||||
Encoder::~Encoder() {
|
||||
int32_t status = 0;
|
||||
HAL_FreeEncoder(m_encoder, &status);
|
||||
FRC_ReportError(status, "FreeEncoder");
|
||||
FRC_ReportError(status, "{}", "FreeEncoder");
|
||||
}
|
||||
|
||||
int Encoder::Get() const {
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetEncoder(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
FRC_CheckErrorStatus(status, "{}", "Get");
|
||||
return value;
|
||||
}
|
||||
|
||||
void Encoder::Reset() {
|
||||
int32_t status = 0;
|
||||
HAL_ResetEncoder(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "Reset");
|
||||
FRC_CheckErrorStatus(status, "{}", "Reset");
|
||||
}
|
||||
|
||||
double Encoder::GetPeriod() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderPeriod(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetPeriod");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetPeriod");
|
||||
return value;
|
||||
}
|
||||
|
||||
void Encoder::SetMaxPeriod(double maxPeriod) {
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderMaxPeriod(m_encoder, maxPeriod, &status);
|
||||
FRC_CheckErrorStatus(status, "SetMaxPeriod");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetMaxPeriod");
|
||||
}
|
||||
|
||||
bool Encoder::GetStopped() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetEncoderStopped(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetStopped");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetStopped");
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Encoder::GetDirection() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetEncoderDirection(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetDirection");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetDirection");
|
||||
return value;
|
||||
}
|
||||
|
||||
int Encoder::GetRaw() const {
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetEncoderRaw(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetRaw");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetRaw");
|
||||
return value;
|
||||
}
|
||||
|
||||
int Encoder::GetEncodingScale() const {
|
||||
int32_t status = 0;
|
||||
int val = HAL_GetEncoderEncodingScale(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetEncodingScale");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetEncodingScale");
|
||||
return val;
|
||||
}
|
||||
|
||||
double Encoder::GetDistance() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderDistance(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetDistance");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetDistance");
|
||||
return value;
|
||||
}
|
||||
|
||||
double Encoder::GetRate() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderRate(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetRate");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetRate");
|
||||
return value;
|
||||
}
|
||||
|
||||
void Encoder::SetMinRate(double minRate) {
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderMinRate(m_encoder, minRate, &status);
|
||||
FRC_CheckErrorStatus(status, "SetMinRate");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetMinRate");
|
||||
}
|
||||
|
||||
void Encoder::SetDistancePerPulse(double distancePerPulse) {
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderDistancePerPulse(m_encoder, distancePerPulse, &status);
|
||||
FRC_CheckErrorStatus(status, "SetDistancePerPulse");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetDistancePerPulse");
|
||||
}
|
||||
|
||||
double Encoder::GetDistancePerPulse() const {
|
||||
int32_t status = 0;
|
||||
double distancePerPulse = HAL_GetEncoderDistancePerPulse(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetDistancePerPulse");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetDistancePerPulse");
|
||||
return distancePerPulse;
|
||||
}
|
||||
|
||||
void Encoder::SetReverseDirection(bool reverseDirection) {
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderReverseDirection(m_encoder, reverseDirection, &status);
|
||||
FRC_CheckErrorStatus(status, "SetReverseDirection");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetReverseDirection");
|
||||
}
|
||||
|
||||
void Encoder::SetSamplesToAverage(int samplesToAverage) {
|
||||
if (samplesToAverage < 1 || samplesToAverage > 127) {
|
||||
throw FRC_MakeError(
|
||||
err::ParameterOutOfRange,
|
||||
"Average counter values must be between 1 and 127, got " +
|
||||
wpi::Twine{samplesToAverage});
|
||||
"Average counter values must be between 1 and 127, got {}",
|
||||
samplesToAverage);
|
||||
}
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderSamplesToAverage(m_encoder, samplesToAverage, &status);
|
||||
FRC_CheckErrorStatus(status, "SetSamplesToAverage");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetSamplesToAverage");
|
||||
}
|
||||
|
||||
int Encoder::GetSamplesToAverage() const {
|
||||
int32_t status = 0;
|
||||
int result = HAL_GetEncoderSamplesToAverage(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetSamplesToAverage");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetSamplesToAverage");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ void Encoder::SetIndexSource(const DigitalSource& source,
|
||||
source.GetAnalogTriggerTypeForRouting()),
|
||||
static_cast<HAL_EncoderIndexingType>(type),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "SetIndexSource");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetIndexSource");
|
||||
}
|
||||
|
||||
void Encoder::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
@@ -203,14 +203,14 @@ void Encoder::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
int Encoder::GetFPGAIndex() const {
|
||||
int32_t status = 0;
|
||||
int val = HAL_GetEncoderFPGAIndex(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetFPGAIndex");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetFPGAIndex");
|
||||
return val;
|
||||
}
|
||||
|
||||
void Encoder::InitSendable(SendableBuilder& builder) {
|
||||
int32_t status = 0;
|
||||
HAL_EncoderEncodingType type = HAL_GetEncoderEncodingType(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "GetEncodingType");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetEncodingType");
|
||||
if (type == HAL_EncoderEncodingType::HAL_Encoder_k4X) {
|
||||
builder.SetSmartDashboardType("Quadrature Encoder");
|
||||
} else {
|
||||
@@ -236,7 +236,7 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
|
||||
m_bSource->GetAnalogTriggerTypeForRouting()),
|
||||
reverseDirection, static_cast<HAL_EncoderEncodingType>(encodingType),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "InitEncoder");
|
||||
FRC_CheckErrorStatus(status, "{}", "InitEncoder");
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Encoder, GetFPGAIndex() + 1,
|
||||
encodingType);
|
||||
@@ -247,6 +247,6 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
|
||||
double Encoder::DecodingScaleFactor() const {
|
||||
int32_t status = 0;
|
||||
double val = HAL_GetEncoderDecodingScaleFactor(m_encoder, &status);
|
||||
FRC_CheckErrorStatus(status, "DecodingScaleFactor");
|
||||
FRC_CheckErrorStatus(status, "{}", "DecodingScaleFactor");
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -9,27 +9,25 @@
|
||||
#include <hal/DriverStation.h>
|
||||
#include <hal/HALBase.h>
|
||||
#include <wpi/Path.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/StackTrace.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
RuntimeError::RuntimeError(int32_t code, const wpi::Twine& message,
|
||||
const wpi::Twine& loc, wpi::StringRef stack)
|
||||
: runtime_error{message.str()}, m_data{std::make_shared<Data>()} {
|
||||
RuntimeError::RuntimeError(int32_t code, std::string&& loc, std::string&& stack,
|
||||
std::string&& message)
|
||||
: runtime_error{std::move(message)}, m_data{std::make_shared<Data>()} {
|
||||
m_data->code = code;
|
||||
m_data->loc = loc.str();
|
||||
m_data->loc = std::move(loc);
|
||||
m_data->stack = stack;
|
||||
}
|
||||
|
||||
RuntimeError::RuntimeError(int32_t code, const wpi::Twine& message,
|
||||
const char* fileName, int lineNumber,
|
||||
const char* funcName, wpi::StringRef stack)
|
||||
: RuntimeError{code, message,
|
||||
funcName + wpi::Twine{" ["} +
|
||||
wpi::sys::path::filename(fileName) + ":" +
|
||||
wpi::Twine{lineNumber} + "]",
|
||||
stack} {}
|
||||
RuntimeError::RuntimeError(int32_t code, const char* fileName, int lineNumber,
|
||||
const char* funcName, std::string&& stack,
|
||||
std::string&& message)
|
||||
: RuntimeError{code,
|
||||
fmt::format("{} [{}:{}]", funcName,
|
||||
wpi::sys::path::filename(fileName), lineNumber),
|
||||
std::move(stack), std::move(message)} {}
|
||||
|
||||
void RuntimeError::Report() const {
|
||||
HAL_SendError(m_data->code < 0, m_data->code, 0, what(), m_data->loc.c_str(),
|
||||
@@ -51,28 +49,30 @@ const char* frc::GetErrorMessage(int32_t* code) {
|
||||
}
|
||||
}
|
||||
|
||||
void frc::ReportError(int32_t status, const wpi::Twine& message,
|
||||
const char* fileName, int lineNumber,
|
||||
const char* funcName) {
|
||||
void frc::ReportErrorV(int32_t status, const char* fileName, int lineNumber,
|
||||
const char* funcName, fmt::string_view format,
|
||||
fmt::format_args args) {
|
||||
if (status == 0) {
|
||||
return;
|
||||
}
|
||||
const char* statusMessage = GetErrorMessage(&status);
|
||||
auto stack = wpi::GetStackTrace(2);
|
||||
wpi::SmallString<128> buf;
|
||||
HAL_SendError(status < 0, status, 0,
|
||||
(statusMessage + wpi::Twine{": "} + message)
|
||||
.toNullTerminatedStringRef(buf)
|
||||
.data(),
|
||||
funcName, stack.c_str(), 1);
|
||||
fmt::memory_buffer out;
|
||||
fmt::format_to(out, "{}: ", GetErrorMessage(&status));
|
||||
fmt::vformat_to(out, format, args);
|
||||
out.push_back('\0');
|
||||
HAL_SendError(status < 0, status, 0, out.data(), funcName,
|
||||
wpi::GetStackTrace(2).c_str(), 1);
|
||||
}
|
||||
|
||||
RuntimeError frc::MakeError(int32_t status, const wpi::Twine& message,
|
||||
const char* fileName, int lineNumber,
|
||||
const char* funcName) {
|
||||
const char* statusMessage = GetErrorMessage(&status);
|
||||
auto stack = wpi::GetStackTrace(2);
|
||||
return RuntimeError{status, statusMessage + wpi::Twine{": "} + message,
|
||||
fileName, lineNumber,
|
||||
funcName, stack};
|
||||
RuntimeError frc::MakeErrorV(int32_t status, const char* fileName,
|
||||
int lineNumber, const char* funcName,
|
||||
fmt::string_view format, fmt::format_args args) {
|
||||
fmt::memory_buffer out;
|
||||
fmt::format_to(out, "{}: ", GetErrorMessage(&status));
|
||||
fmt::vformat_to(out, format, args);
|
||||
return RuntimeError{status,
|
||||
fileName,
|
||||
lineNumber,
|
||||
funcName,
|
||||
wpi::GetStackTrace(2),
|
||||
fmt::to_string(out)};
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ using namespace frc;
|
||||
|
||||
GenericHID::GenericHID(int port) : m_ds(&DriverStation::GetInstance()) {
|
||||
if (port < 0 || port >= DriverStation::kJoystickPorts) {
|
||||
throw FRC_MakeError(warn::BadJoystickIndex,
|
||||
"port " + wpi::Twine{port} + "out of range");
|
||||
throw FRC_MakeError(warn::BadJoystickIndex, "port {} out of range", port);
|
||||
}
|
||||
m_port = port;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ I2C::I2C(Port port, int deviceAddress)
|
||||
: m_port(static_cast<HAL_I2CPort>(port)), m_deviceAddress(deviceAddress) {
|
||||
int32_t status = 0;
|
||||
HAL_InitializeI2C(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Port " + wpi::Twine{static_cast<int>(port)});
|
||||
FRC_CheckErrorStatus(status, "Port {}", port);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_I2C, deviceAddress);
|
||||
}
|
||||
@@ -55,10 +55,10 @@ bool I2C::WriteBulk(uint8_t* data, int count) {
|
||||
|
||||
bool I2C::Read(int registerAddress, int count, uint8_t* buffer) {
|
||||
if (count < 1) {
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "count " + wpi::Twine{count});
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "count {}", count);
|
||||
}
|
||||
if (!buffer) {
|
||||
throw FRC_MakeError(err::NullParameter, "buffer");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "buffer");
|
||||
}
|
||||
uint8_t regAddr = registerAddress;
|
||||
return Transaction(®Addr, sizeof(regAddr), buffer, count);
|
||||
@@ -66,10 +66,10 @@ bool I2C::Read(int registerAddress, int count, uint8_t* buffer) {
|
||||
|
||||
bool I2C::ReadOnly(int count, uint8_t* buffer) {
|
||||
if (count < 1) {
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "count " + wpi::Twine{count});
|
||||
throw FRC_MakeError(err::ParameterOutOfRange, "count {}", count);
|
||||
}
|
||||
if (!buffer) {
|
||||
throw FRC_MakeError(err::NullParameter, "buffer");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "buffer");
|
||||
}
|
||||
return HAL_ReadI2C(m_port, m_deviceAddress, buffer, count) < 0;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ void InterruptableSensorBase::RequestInterrupts(
|
||||
&status);
|
||||
SetUpSourceEdge(true, false);
|
||||
HAL_AttachInterruptHandler(m_interrupt, handler, param, &status);
|
||||
FRC_CheckErrorStatus(status, "AttachInterruptHandler");
|
||||
FRC_CheckErrorStatus(status, "{}", "AttachInterruptHandler");
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::RequestInterrupts(InterruptEventHandler handler) {
|
||||
@@ -59,7 +59,7 @@ void InterruptableSensorBase::RequestInterrupts(InterruptEventHandler handler) {
|
||||
(*self)(res);
|
||||
},
|
||||
m_interruptHandler.get(), &status);
|
||||
FRC_CheckErrorStatus(status, "AttachInterruptHandler");
|
||||
FRC_CheckErrorStatus(status, "{}", "AttachInterruptHandler");
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::RequestInterrupts() {
|
||||
@@ -71,7 +71,7 @@ void InterruptableSensorBase::RequestInterrupts() {
|
||||
m_interrupt, GetPortHandleForRouting(),
|
||||
static_cast<HAL_AnalogTriggerType>(GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "RequestInterrupts");
|
||||
FRC_CheckErrorStatus(status, "{}", "RequestInterrupts");
|
||||
SetUpSourceEdge(true, false);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt(
|
||||
int result;
|
||||
|
||||
result = HAL_WaitForInterrupt(m_interrupt, timeout, ignorePrevious, &status);
|
||||
FRC_CheckErrorStatus(status, "WaitForInterrupt");
|
||||
FRC_CheckErrorStatus(status, "{}", "WaitForInterrupt");
|
||||
|
||||
// Rising edge result is the interrupt bit set in the byte 0xFF
|
||||
// Falling edge result is the interrupt bit set in the byte 0xFF00
|
||||
@@ -106,21 +106,21 @@ void InterruptableSensorBase::EnableInterrupts() {
|
||||
FRC_Assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
HAL_EnableInterrupts(m_interrupt, &status);
|
||||
FRC_CheckErrorStatus(status, "EnableInterrupts");
|
||||
FRC_CheckErrorStatus(status, "{}", "EnableInterrupts");
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::DisableInterrupts() {
|
||||
FRC_Assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
HAL_DisableInterrupts(m_interrupt, &status);
|
||||
FRC_CheckErrorStatus(status, "DisableInterrupts");
|
||||
FRC_CheckErrorStatus(status, "{}", "DisableInterrupts");
|
||||
}
|
||||
|
||||
double InterruptableSensorBase::ReadRisingTimestamp() {
|
||||
FRC_Assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
int64_t timestamp = HAL_ReadInterruptRisingTimestamp(m_interrupt, &status);
|
||||
FRC_CheckErrorStatus(status, "ReadRisingTimestamp");
|
||||
FRC_CheckErrorStatus(status, "{}", "ReadRisingTimestamp");
|
||||
return timestamp * 1e-6;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ double InterruptableSensorBase::ReadFallingTimestamp() {
|
||||
FRC_Assert(m_interrupt != HAL_kInvalidHandle);
|
||||
int32_t status = 0;
|
||||
int64_t timestamp = HAL_ReadInterruptFallingTimestamp(m_interrupt, &status);
|
||||
FRC_CheckErrorStatus(status, "ReadFallingTimestamp");
|
||||
FRC_CheckErrorStatus(status, "{}", "ReadFallingTimestamp");
|
||||
return timestamp * 1e-6;
|
||||
}
|
||||
|
||||
@@ -136,13 +136,13 @@ void InterruptableSensorBase::SetUpSourceEdge(bool risingEdge,
|
||||
bool fallingEdge) {
|
||||
if (m_interrupt == HAL_kInvalidHandle) {
|
||||
throw FRC_MakeError(
|
||||
err::NullParameter,
|
||||
err::NullParameter, "{}",
|
||||
"You must call RequestInterrupts before SetUpSourceEdge");
|
||||
}
|
||||
if (m_interrupt != HAL_kInvalidHandle) {
|
||||
int32_t status = 0;
|
||||
HAL_SetInterruptUpSourceEdge(m_interrupt, risingEdge, fallingEdge, &status);
|
||||
FRC_CheckErrorStatus(status, "SetUpSourceEdge");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetUpSourceEdge");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,5 +151,5 @@ void InterruptableSensorBase::AllocateInterrupts(bool watcher) {
|
||||
// Expects the calling leaf class to allocate an interrupt index.
|
||||
int32_t status = 0;
|
||||
m_interrupt = HAL_InitializeInterrupts(watcher, &status);
|
||||
FRC_CheckErrorStatus(status, "AllocateInterrupts");
|
||||
FRC_CheckErrorStatus(status, "{}", "AllocateInterrupts");
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ void MotorSafety::Check() {
|
||||
wpi::SmallString<128> buf;
|
||||
wpi::raw_svector_ostream desc(buf);
|
||||
GetDescription(desc);
|
||||
desc << "... Output not updated often enough.";
|
||||
FRC_ReportError(err::Timeout, desc.str());
|
||||
FRC_ReportError(err::Timeout, "{}... Output not updated often enough",
|
||||
desc.str());
|
||||
StopMotor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ using namespace frc;
|
||||
|
||||
Notifier::Notifier(std::function<void()> handler) {
|
||||
if (!handler) {
|
||||
throw FRC_MakeError(err::NullParameter, "handler");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "handler");
|
||||
}
|
||||
m_handler = handler;
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
FRC_CheckErrorStatus(status, "InitializeNotifier");
|
||||
FRC_CheckErrorStatus(status, "{}", "InitializeNotifier");
|
||||
|
||||
m_thread = std::thread([=] {
|
||||
for (;;) {
|
||||
@@ -60,12 +60,12 @@ Notifier::Notifier(std::function<void()> handler) {
|
||||
|
||||
Notifier::Notifier(int priority, std::function<void()> handler) {
|
||||
if (!handler) {
|
||||
throw FRC_MakeError(err::NullParameter, "handler");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "handler");
|
||||
}
|
||||
m_handler = handler;
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
FRC_CheckErrorStatus(status, "InitializeNotifier");
|
||||
FRC_CheckErrorStatus(status, "{}", "InitializeNotifier");
|
||||
|
||||
m_thread = std::thread([=] {
|
||||
int32_t status = 0;
|
||||
@@ -106,7 +106,7 @@ Notifier::~Notifier() {
|
||||
// atomically set handle to 0, then clean
|
||||
HAL_NotifierHandle handle = m_notifier.exchange(0);
|
||||
HAL_StopNotifier(handle, &status);
|
||||
FRC_ReportError(status, "StopNotifier");
|
||||
FRC_ReportError(status, "{}", "StopNotifier");
|
||||
|
||||
// Join the thread to ensure the handler has exited.
|
||||
if (m_thread.joinable()) {
|
||||
@@ -179,7 +179,7 @@ void Notifier::Stop() {
|
||||
m_periodic = false;
|
||||
int32_t status = 0;
|
||||
HAL_CancelNotifierAlarm(m_notifier, &status);
|
||||
FRC_CheckErrorStatus(status, "CancelNotifierAlarm");
|
||||
FRC_CheckErrorStatus(status, "{}", "CancelNotifierAlarm");
|
||||
}
|
||||
|
||||
void Notifier::UpdateAlarm(uint64_t triggerTime) {
|
||||
@@ -190,7 +190,7 @@ void Notifier::UpdateAlarm(uint64_t triggerTime) {
|
||||
return;
|
||||
}
|
||||
HAL_UpdateNotifierAlarm(notifier, triggerTime, &status);
|
||||
FRC_CheckErrorStatus(status, "UpdateNotifierAlarm");
|
||||
FRC_CheckErrorStatus(status, "{}", "UpdateNotifierAlarm");
|
||||
}
|
||||
|
||||
void Notifier::UpdateAlarm() {
|
||||
|
||||
@@ -21,24 +21,22 @@ using namespace frc;
|
||||
|
||||
PWM::PWM(int channel, bool registerSendable) {
|
||||
if (!SensorUtil::CheckPWMChannel(channel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"PWM Channel " + wpi::Twine{channel});
|
||||
return;
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel);
|
||||
}
|
||||
|
||||
auto stack = wpi::GetStackTrace(1);
|
||||
int32_t status = 0;
|
||||
m_handle =
|
||||
HAL_InitializePWMPort(HAL_GetPort(channel), stack.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "PWM Channel " + wpi::Twine{channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
m_channel = channel;
|
||||
|
||||
HAL_SetPWMDisabled(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "SetPWMDisabled");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
status = 0;
|
||||
HAL_SetPWMEliminateDeadband(m_handle, false, &status);
|
||||
FRC_CheckErrorStatus(status, "SetPWMEliminateDeadband");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_PWM, channel + 1);
|
||||
if (registerSendable) {
|
||||
@@ -50,22 +48,22 @@ PWM::~PWM() {
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_SetPWMDisabled(m_handle, &status);
|
||||
FRC_ReportError(status, "SetPWMDisabled");
|
||||
FRC_ReportError(status, "Channel {}", m_channel);
|
||||
|
||||
HAL_FreePWMPort(m_handle, &status);
|
||||
FRC_ReportError(status, "FreePWM");
|
||||
FRC_ReportError(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void PWM::SetRaw(uint16_t value) {
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMRaw(m_handle, value, &status);
|
||||
FRC_CheckErrorStatus(status, "SetRaw");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
uint16_t PWM::GetRaw() const {
|
||||
int32_t status = 0;
|
||||
uint16_t value = HAL_GetPWMRaw(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetRaw");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -73,33 +71,33 @@ uint16_t PWM::GetRaw() const {
|
||||
void PWM::SetPosition(double pos) {
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMPosition(m_handle, pos, &status);
|
||||
FRC_CheckErrorStatus(status, "SetPosition");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
double PWM::GetPosition() const {
|
||||
int32_t status = 0;
|
||||
double position = HAL_GetPWMPosition(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetPosition");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return position;
|
||||
}
|
||||
|
||||
void PWM::SetSpeed(double speed) {
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMSpeed(m_handle, speed, &status);
|
||||
FRC_CheckErrorStatus(status, "SetSpeed");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
double PWM::GetSpeed() const {
|
||||
int32_t status = 0;
|
||||
double speed = HAL_GetPWMSpeed(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetSpeed");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return speed;
|
||||
}
|
||||
|
||||
void PWM::SetDisabled() {
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMDisabled(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "SetDisabled");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void PWM::SetPeriodMultiplier(PeriodMultiplier mult) {
|
||||
@@ -118,22 +116,23 @@ void PWM::SetPeriodMultiplier(PeriodMultiplier mult) {
|
||||
HAL_SetPWMPeriodScale(m_handle, 0, &status); // Don't squelch any outputs
|
||||
break;
|
||||
default:
|
||||
throw FRC_MakeError(err::InvalidParameter, "PeriodMultiplier value");
|
||||
throw FRC_MakeError(err::InvalidParameter, "PeriodMultiplier value {}",
|
||||
mult);
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "SetPeriodMultiplier");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void PWM::SetZeroLatch() {
|
||||
int32_t status = 0;
|
||||
HAL_LatchPWMZero(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "SetZeroLatch");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void PWM::EnableDeadbandElimination(bool eliminateDeadband) {
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMEliminateDeadband(m_handle, eliminateDeadband, &status);
|
||||
FRC_CheckErrorStatus(status, "EnableDeadbandElimination");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void PWM::SetBounds(double max, double deadbandMax, double center,
|
||||
@@ -141,7 +140,7 @@ void PWM::SetBounds(double max, double deadbandMax, double center,
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMConfig(m_handle, max, deadbandMax, center, deadbandMin, min,
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "SetBounds");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void PWM::SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
|
||||
@@ -149,7 +148,7 @@ void PWM::SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMConfigRaw(m_handle, max, deadbandMax, center, deadbandMin, min,
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "SetRawBounds");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void PWM::GetRawBounds(int* max, int* deadbandMax, int* center,
|
||||
@@ -157,7 +156,7 @@ void PWM::GetRawBounds(int* max, int* deadbandMax, int* center,
|
||||
int32_t status = 0;
|
||||
HAL_GetPWMConfigRaw(m_handle, max, deadbandMax, center, deadbandMin, min,
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "GetRawBounds");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
int PWM::GetChannel() const {
|
||||
|
||||
@@ -23,7 +23,7 @@ PowerDistributionPanel::PowerDistributionPanel() : PowerDistributionPanel(0) {}
|
||||
PowerDistributionPanel::PowerDistributionPanel(int module) : m_module(module) {
|
||||
int32_t status = 0;
|
||||
m_handle = HAL_InitializePDP(module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", module);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_PDP, module + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "PowerDistributionPanel", module);
|
||||
@@ -32,14 +32,14 @@ PowerDistributionPanel::PowerDistributionPanel(int module) : m_module(module) {
|
||||
double PowerDistributionPanel::GetVoltage() const {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetPDPVoltage(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetVoltage");
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTemperature() const {
|
||||
int32_t status = 0;
|
||||
double temperature = HAL_GetPDPTemperature(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetTemperature");
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@@ -47,13 +47,13 @@ double PowerDistributionPanel::GetCurrent(int channel) const {
|
||||
int32_t status = 0;
|
||||
|
||||
if (!SensorUtil::CheckPDPChannel(channel)) {
|
||||
FRC_ReportError(err::ChannelIndexOutOfRange,
|
||||
"Channel " + wpi::Twine{channel});
|
||||
FRC_ReportError(err::ChannelIndexOutOfRange, "Module {} Channel {}",
|
||||
m_module, channel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
double current = HAL_GetPDPChannelCurrent(m_handle, channel, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{channel});
|
||||
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_module, channel);
|
||||
|
||||
return current;
|
||||
}
|
||||
@@ -61,34 +61,34 @@ double PowerDistributionPanel::GetCurrent(int channel) const {
|
||||
double PowerDistributionPanel::GetTotalCurrent() const {
|
||||
int32_t status = 0;
|
||||
double current = HAL_GetPDPTotalCurrent(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetTotalCurrent");
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return current;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTotalPower() const {
|
||||
int32_t status = 0;
|
||||
double power = HAL_GetPDPTotalPower(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetTotalPower");
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return power;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTotalEnergy() const {
|
||||
int32_t status = 0;
|
||||
double energy = HAL_GetPDPTotalEnergy(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetTotalEnergy");
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return energy;
|
||||
}
|
||||
|
||||
void PowerDistributionPanel::ResetTotalEnergy() {
|
||||
int32_t status = 0;
|
||||
HAL_ResetPDPTotalEnergy(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "ResetTotalEnergy");
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PowerDistributionPanel::ClearStickyFaults() {
|
||||
int32_t status = 0;
|
||||
HAL_ClearPDPStickyFaults(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "ClearStickyFaults");
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
int PowerDistributionPanel::GetModule() const {
|
||||
|
||||
@@ -23,8 +23,7 @@ using namespace frc;
|
||||
Relay::Relay(int channel, Relay::Direction direction)
|
||||
: m_channel(channel), m_direction(direction) {
|
||||
if (!SensorUtil::CheckRelayChannel(m_channel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Relay Channel " + wpi::Twine{m_channel});
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}", m_channel);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,7 +34,7 @@ Relay::Relay(int channel, Relay::Direction direction)
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_forwardHandle =
|
||||
HAL_InitializeRelayPort(portHandle, true, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
HAL_Report(HALUsageReporting::kResourceType_Relay, m_channel + 1);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
|
||||
@@ -43,18 +42,18 @@ Relay::Relay(int channel, Relay::Direction direction)
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_reverseHandle =
|
||||
HAL_InitializeRelayPort(portHandle, false, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
HAL_Report(HALUsageReporting::kResourceType_Relay, m_channel + 128);
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
if (m_forwardHandle != HAL_kInvalidHandle) {
|
||||
HAL_SetRelay(m_forwardHandle, false, &status);
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
if (m_reverseHandle != HAL_kInvalidHandle) {
|
||||
HAL_SetRelay(m_reverseHandle, false, &status);
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
SendableRegistry::GetInstance().AddLW(this, "Relay", m_channel);
|
||||
@@ -95,7 +94,8 @@ void Relay::Set(Relay::Value value) {
|
||||
break;
|
||||
case kForward:
|
||||
if (m_direction == kReverseOnly) {
|
||||
FRC_ReportError(err::IncompatibleMode, "setting forward");
|
||||
FRC_ReportError(err::IncompatibleMode, "channel {} setting {}",
|
||||
m_channel, "forward");
|
||||
break;
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
@@ -107,7 +107,8 @@ void Relay::Set(Relay::Value value) {
|
||||
break;
|
||||
case kReverse:
|
||||
if (m_direction == kForwardOnly) {
|
||||
FRC_ReportError(err::IncompatibleMode, "setting reverse");
|
||||
FRC_ReportError(err::IncompatibleMode, "channel {} setting {}",
|
||||
m_channel, "reverse");
|
||||
break;
|
||||
}
|
||||
if (m_direction == kBothDirections) {
|
||||
@@ -119,7 +120,7 @@ void Relay::Set(Relay::Value value) {
|
||||
break;
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "Set");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
Relay::Value Relay::Get() const {
|
||||
@@ -154,7 +155,7 @@ Relay::Value Relay::Get() const {
|
||||
}
|
||||
}
|
||||
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -30,16 +30,16 @@ uint32_t Resource::Allocate(const std::string& resourceDesc) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
throw FRC_MakeError(err::NoAvailableResources, resourceDesc);
|
||||
throw FRC_MakeError(err::NoAvailableResources, "{}", resourceDesc);
|
||||
}
|
||||
|
||||
uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
|
||||
std::scoped_lock lock(m_allocateMutex);
|
||||
if (index >= m_isAllocated.size()) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, resourceDesc);
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "{}", resourceDesc);
|
||||
}
|
||||
if (m_isAllocated[index]) {
|
||||
throw FRC_MakeError(err::ResourceAlreadyAllocated, resourceDesc);
|
||||
throw FRC_MakeError(err::ResourceAlreadyAllocated, "{}", resourceDesc);
|
||||
}
|
||||
m_isAllocated[index] = true;
|
||||
return index;
|
||||
@@ -51,10 +51,10 @@ void Resource::Free(uint32_t index) {
|
||||
return;
|
||||
}
|
||||
if (index >= m_isAllocated.size()) {
|
||||
throw FRC_MakeError(err::NotAllocated, "index " + wpi::Twine{index});
|
||||
throw FRC_MakeError(err::NotAllocated, "index {}", index);
|
||||
}
|
||||
if (!m_isAllocated[index]) {
|
||||
throw FRC_MakeError(err::NotAllocated, "index " + wpi::Twine{index});
|
||||
throw FRC_MakeError(err::NotAllocated, "index {}", index);
|
||||
}
|
||||
m_isAllocated[index] = false;
|
||||
}
|
||||
|
||||
@@ -15,147 +15,147 @@ using namespace frc;
|
||||
int RobotController::GetFPGAVersion() {
|
||||
int32_t status = 0;
|
||||
int version = HAL_GetFPGAVersion(&status);
|
||||
FRC_CheckErrorStatus(status, "GetFPGAVersion");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetFPGAVersion");
|
||||
return version;
|
||||
}
|
||||
|
||||
int64_t RobotController::GetFPGARevision() {
|
||||
int32_t status = 0;
|
||||
int64_t revision = HAL_GetFPGARevision(&status);
|
||||
FRC_CheckErrorStatus(status, "GetFPGARevision");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetFPGARevision");
|
||||
return revision;
|
||||
}
|
||||
|
||||
uint64_t RobotController::GetFPGATime() {
|
||||
int32_t status = 0;
|
||||
uint64_t time = HAL_GetFPGATime(&status);
|
||||
FRC_CheckErrorStatus(status, "GetFPGATime");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetFPGATime");
|
||||
return time;
|
||||
}
|
||||
|
||||
bool RobotController::GetUserButton() {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetFPGAButton(&status);
|
||||
FRC_CheckErrorStatus(status, "GetUserButton");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetUserButton");
|
||||
return value;
|
||||
}
|
||||
|
||||
units::volt_t RobotController::GetBatteryVoltage() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetVinVoltage(&status);
|
||||
FRC_CheckErrorStatus(status, "GetBatteryVoltage");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetBatteryVoltage");
|
||||
return units::volt_t{retVal};
|
||||
}
|
||||
|
||||
bool RobotController::IsSysActive() {
|
||||
int32_t status = 0;
|
||||
bool retVal = HAL_GetSystemActive(&status);
|
||||
FRC_CheckErrorStatus(status, "IsSysActive");
|
||||
FRC_CheckErrorStatus(status, "{}", "IsSysActive");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool RobotController::IsBrownedOut() {
|
||||
int32_t status = 0;
|
||||
bool retVal = HAL_GetBrownedOut(&status);
|
||||
FRC_CheckErrorStatus(status, "IsBrownedOut");
|
||||
FRC_CheckErrorStatus(status, "{}", "IsBrownedOut");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetInputVoltage() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetVinVoltage(&status);
|
||||
FRC_CheckErrorStatus(status, "GetInputVoltage");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetInputVoltage");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetInputCurrent() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetVinCurrent(&status);
|
||||
FRC_CheckErrorStatus(status, "GetInputCurrent");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetInputCurrent");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetVoltage3V3() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserVoltage3V3(&status);
|
||||
FRC_CheckErrorStatus(status, "GetVoltage3V3");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetVoltage3V3");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetCurrent3V3() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserCurrent3V3(&status);
|
||||
FRC_CheckErrorStatus(status, "GetCurrent3V3");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetCurrent3V3");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool RobotController::GetEnabled3V3() {
|
||||
int32_t status = 0;
|
||||
bool retVal = HAL_GetUserActive3V3(&status);
|
||||
FRC_CheckErrorStatus(status, "GetEnabled3V3");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetEnabled3V3");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int RobotController::GetFaultCount3V3() {
|
||||
int32_t status = 0;
|
||||
int retVal = HAL_GetUserCurrentFaults3V3(&status);
|
||||
FRC_CheckErrorStatus(status, "GetFaultCount3V3");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetFaultCount3V3");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetVoltage5V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserVoltage5V(&status);
|
||||
FRC_CheckErrorStatus(status, "GetVoltage5V");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetVoltage5V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetCurrent5V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserCurrent5V(&status);
|
||||
FRC_CheckErrorStatus(status, "GetCurrent5V");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetCurrent5V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool RobotController::GetEnabled5V() {
|
||||
int32_t status = 0;
|
||||
bool retVal = HAL_GetUserActive5V(&status);
|
||||
FRC_CheckErrorStatus(status, "GetEnabled5V");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetEnabled5V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int RobotController::GetFaultCount5V() {
|
||||
int32_t status = 0;
|
||||
int retVal = HAL_GetUserCurrentFaults5V(&status);
|
||||
FRC_CheckErrorStatus(status, "GetFaultCount5V");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetFaultCount5V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetVoltage6V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserVoltage6V(&status);
|
||||
FRC_CheckErrorStatus(status, "GetVoltage6V");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetVoltage6V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
double RobotController::GetCurrent6V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserCurrent6V(&status);
|
||||
FRC_CheckErrorStatus(status, "GetCurrent6V");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetCurrent6V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool RobotController::GetEnabled6V() {
|
||||
int32_t status = 0;
|
||||
bool retVal = HAL_GetUserActive6V(&status);
|
||||
FRC_CheckErrorStatus(status, "GetEnabled6V");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetEnabled6V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int RobotController::GetFaultCount6V() {
|
||||
int32_t status = 0;
|
||||
int retVal = HAL_GetUserCurrentFaults6V(&status);
|
||||
FRC_CheckErrorStatus(status, "GetFaultCount6V");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetFaultCount6V");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ CANStatus RobotController::GetCANStatus() {
|
||||
uint32_t transmitErrorCount = 0;
|
||||
HAL_CAN_GetCANStatus(&percentBusUtilization, &busOffCount, &txFullCount,
|
||||
&receiveErrorCount, &transmitErrorCount, &status);
|
||||
FRC_CheckErrorStatus(status, "GetCANStatus");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetCANStatus");
|
||||
return {percentBusUtilization, static_cast<int>(busOffCount),
|
||||
static_cast<int>(txFullCount), static_cast<int>(receiveErrorCount),
|
||||
static_cast<int>(transmitErrorCount)};
|
||||
|
||||
@@ -77,7 +77,7 @@ void SPI::Accumulator::Update() {
|
||||
// get amount of data available
|
||||
int32_t numToRead =
|
||||
HAL_ReadSPIAutoReceivedData(m_port, m_buf, 0, 0, &status);
|
||||
FRC_CheckErrorStatus(status, "ReadSPIAutoReceivedData");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
|
||||
// only get whole responses; +1 is for timestamp
|
||||
numToRead -= numToRead % m_xferSize;
|
||||
@@ -91,7 +91,7 @@ void SPI::Accumulator::Update() {
|
||||
|
||||
// read buffered data
|
||||
HAL_ReadSPIAutoReceivedData(m_port, m_buf, numToRead, 0, &status);
|
||||
FRC_CheckErrorStatus(status, "ReadSPIAutoReceivedData");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
|
||||
// loop over all responses
|
||||
for (int32_t off = 0; off < numToRead; off += m_xferSize) {
|
||||
@@ -158,7 +158,7 @@ void SPI::Accumulator::Update() {
|
||||
SPI::SPI(Port port) : m_port(static_cast<HAL_SPIPort>(port)) {
|
||||
int32_t status = 0;
|
||||
HAL_InitializeSPI(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "InitializeSPI");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_SPI,
|
||||
static_cast<uint8_t>(port) + 1);
|
||||
@@ -215,13 +215,13 @@ void SPI::SetClockActiveHigh() {
|
||||
void SPI::SetChipSelectActiveHigh() {
|
||||
int32_t status = 0;
|
||||
HAL_SetSPIChipSelectActiveHigh(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "SetChipSelectActiveHigh");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void SPI::SetChipSelectActiveLow() {
|
||||
int32_t status = 0;
|
||||
HAL_SetSPIChipSelectActiveLow(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "SetChipSelectActiveLow");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
int SPI::Write(uint8_t* data, int size) {
|
||||
@@ -251,26 +251,26 @@ int SPI::Transaction(uint8_t* dataToSend, uint8_t* dataReceived, int size) {
|
||||
void SPI::InitAuto(int bufferSize) {
|
||||
int32_t status = 0;
|
||||
HAL_InitSPIAuto(m_port, bufferSize, &status);
|
||||
FRC_CheckErrorStatus(status, "InitAuto");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void SPI::FreeAuto() {
|
||||
int32_t status = 0;
|
||||
HAL_FreeSPIAuto(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "FreeAuto");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void SPI::SetAutoTransmitData(wpi::ArrayRef<uint8_t> dataToSend, int zeroSize) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSPIAutoTransmitData(m_port, dataToSend.data(), dataToSend.size(),
|
||||
zeroSize, &status);
|
||||
FRC_CheckErrorStatus(status, "SetAutoTransmitData");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void SPI::StartAutoRate(units::second_t period) {
|
||||
int32_t status = 0;
|
||||
HAL_StartSPIAutoRate(m_port, period.to<double>(), &status);
|
||||
FRC_CheckErrorStatus(status, "StartAutoRate");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void SPI::StartAutoRate(double period) {
|
||||
@@ -283,19 +283,19 @@ void SPI::StartAutoTrigger(DigitalSource& source, bool rising, bool falling) {
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
source.GetAnalogTriggerTypeForRouting()),
|
||||
rising, falling, &status);
|
||||
FRC_CheckErrorStatus(status, "StartAutoTrigger");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void SPI::StopAuto() {
|
||||
int32_t status = 0;
|
||||
HAL_StopSPIAuto(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "StopAuto");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void SPI::ForceAutoRead() {
|
||||
int32_t status = 0;
|
||||
HAL_ForceSPIAutoRead(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "ForceAutoRead");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
int SPI::ReadAutoReceivedData(uint32_t* buffer, int numToRead,
|
||||
@@ -303,7 +303,7 @@ int SPI::ReadAutoReceivedData(uint32_t* buffer, int numToRead,
|
||||
int32_t status = 0;
|
||||
int32_t val = HAL_ReadSPIAutoReceivedData(m_port, buffer, numToRead,
|
||||
timeout.to<double>(), &status);
|
||||
FRC_CheckErrorStatus(status, "ReadAutoReceivedData");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ int SPI::ReadAutoReceivedData(uint32_t* buffer, int numToRead, double timeout) {
|
||||
int SPI::GetAutoDroppedCount() {
|
||||
int32_t status = 0;
|
||||
int32_t val = HAL_GetSPIAutoDroppedCount(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "GetAutoDroppedCount");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ void SPI::ConfigureAutoStall(HAL_SPIPort port, int csToSclkTicks,
|
||||
int32_t status = 0;
|
||||
HAL_ConfigureSPIAutoStall(m_port, csToSclkTicks, stallTicks, pow2BytesPerRead,
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "ConfigureAutoStall");
|
||||
FRC_CheckErrorStatus(status, "Port {}", m_port);
|
||||
}
|
||||
|
||||
void SPI::InitAccumulator(units::second_t period, int cmd, int xferSize,
|
||||
|
||||
@@ -20,17 +20,15 @@ SerialPort::SerialPort(int baudRate, Port port, int dataBits,
|
||||
|
||||
m_portHandle =
|
||||
HAL_InitializeSerialPort(static_cast<HAL_SerialPort>(port), &status);
|
||||
FRC_CheckErrorStatus(status, "Port " + wpi::Twine{static_cast<int>(port)});
|
||||
FRC_CheckErrorStatus(status, "Port {}", port);
|
||||
HAL_SetSerialBaudRate(m_portHandle, baudRate, &status);
|
||||
FRC_CheckErrorStatus(status, "SetSerialBaudRate " + wpi::Twine{baudRate});
|
||||
FRC_CheckErrorStatus(status, "SetSerialBaudRate {}", baudRate);
|
||||
HAL_SetSerialDataBits(m_portHandle, dataBits, &status);
|
||||
FRC_CheckErrorStatus(status, "SetSerialDataBits " + wpi::Twine{dataBits});
|
||||
FRC_CheckErrorStatus(status, "SetSerialDataBits {}", dataBits);
|
||||
HAL_SetSerialParity(m_portHandle, parity, &status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetSerialParity " + wpi::Twine{static_cast<int>(parity)});
|
||||
FRC_CheckErrorStatus(status, "SetSerialParity {}", parity);
|
||||
HAL_SetSerialStopBits(m_portHandle, stopBits, &status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetSerialStopBits " + wpi::Twine{static_cast<int>(stopBits)});
|
||||
FRC_CheckErrorStatus(status, "SetSerialStopBits {}", stopBits);
|
||||
|
||||
// Set the default timeout to 5 seconds.
|
||||
SetTimeout(5.0);
|
||||
@@ -54,17 +52,15 @@ SerialPort::SerialPort(int baudRate, const wpi::Twine& portName, Port port,
|
||||
|
||||
m_portHandle = HAL_InitializeSerialPortDirect(
|
||||
static_cast<HAL_SerialPort>(port), portNameC, &status);
|
||||
FRC_CheckErrorStatus(status, "Port " + wpi::Twine{static_cast<int>(port)});
|
||||
FRC_CheckErrorStatus(status, "Port {}", port);
|
||||
HAL_SetSerialBaudRate(m_portHandle, baudRate, &status);
|
||||
FRC_CheckErrorStatus(status, "SetSerialBaudRate " + wpi::Twine{baudRate});
|
||||
FRC_CheckErrorStatus(status, "SetSerialBaudRate {}", baudRate);
|
||||
HAL_SetSerialDataBits(m_portHandle, dataBits, &status);
|
||||
FRC_CheckErrorStatus(status, "SetSerialDataBits " + wpi::Twine{dataBits});
|
||||
FRC_CheckErrorStatus(status, "SetSerialDataBits {}", dataBits);
|
||||
HAL_SetSerialParity(m_portHandle, parity, &status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetSerialParity " + wpi::Twine{static_cast<int>(parity)});
|
||||
FRC_CheckErrorStatus(status, "SetSerialParity {}", parity);
|
||||
HAL_SetSerialStopBits(m_portHandle, stopBits, &status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetSerialStopBits " + wpi::Twine{static_cast<int>(stopBits)});
|
||||
FRC_CheckErrorStatus(status, "SetSerialStopBits {}", stopBits);
|
||||
|
||||
// Set the default timeout to 5 seconds.
|
||||
SetTimeout(5.0);
|
||||
@@ -81,40 +77,38 @@ SerialPort::SerialPort(int baudRate, const wpi::Twine& portName, Port port,
|
||||
SerialPort::~SerialPort() {
|
||||
int32_t status = 0;
|
||||
HAL_CloseSerial(m_portHandle, &status);
|
||||
FRC_ReportError(status, "CloseSerial");
|
||||
FRC_ReportError(status, "{}", "CloseSerial");
|
||||
}
|
||||
|
||||
void SerialPort::SetFlowControl(SerialPort::FlowControl flowControl) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialFlowControl(m_portHandle, flowControl, &status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetFlowControl " + wpi::Twine{static_cast<int>(flowControl)});
|
||||
FRC_CheckErrorStatus(status, "SetFlowControl {}", flowControl);
|
||||
}
|
||||
|
||||
void SerialPort::EnableTermination(char terminator) {
|
||||
int32_t status = 0;
|
||||
HAL_EnableSerialTermination(m_portHandle, terminator, &status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "EnableTermination " + wpi::Twine{static_cast<int>(terminator)});
|
||||
FRC_CheckErrorStatus(status, "EnableTermination {}", terminator);
|
||||
}
|
||||
|
||||
void SerialPort::DisableTermination() {
|
||||
int32_t status = 0;
|
||||
HAL_DisableSerialTermination(m_portHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "DisableTermination");
|
||||
FRC_CheckErrorStatus(status, "{}", "DisableTermination");
|
||||
}
|
||||
|
||||
int SerialPort::GetBytesReceived() {
|
||||
int32_t status = 0;
|
||||
int retVal = HAL_GetSerialBytesReceived(m_portHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "GetBytesReceived");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetBytesReceived");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int SerialPort::Read(char* buffer, int count) {
|
||||
int32_t status = 0;
|
||||
int retVal = HAL_ReadSerial(m_portHandle, buffer, count, &status);
|
||||
FRC_CheckErrorStatus(status, "Read");
|
||||
FRC_CheckErrorStatus(status, "{}", "Read");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -126,43 +120,42 @@ int SerialPort::Write(wpi::StringRef buffer) {
|
||||
int32_t status = 0;
|
||||
int retVal =
|
||||
HAL_WriteSerial(m_portHandle, buffer.data(), buffer.size(), &status);
|
||||
FRC_CheckErrorStatus(status, "Write");
|
||||
FRC_CheckErrorStatus(status, "{}", "Write");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void SerialPort::SetTimeout(double timeout) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialTimeout(m_portHandle, timeout, &status);
|
||||
FRC_CheckErrorStatus(status, "SetTimeout");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetTimeout");
|
||||
}
|
||||
|
||||
void SerialPort::SetReadBufferSize(int size) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialReadBufferSize(m_portHandle, size, &status);
|
||||
FRC_CheckErrorStatus(status, "SetReadBufferSize " + wpi::Twine{size});
|
||||
FRC_CheckErrorStatus(status, "SetReadBufferSize {}", size);
|
||||
}
|
||||
|
||||
void SerialPort::SetWriteBufferSize(int size) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialWriteBufferSize(m_portHandle, size, &status);
|
||||
FRC_CheckErrorStatus(status, "SetWriteBufferSize " + wpi::Twine{size});
|
||||
FRC_CheckErrorStatus(status, "SetWriteBufferSize {}", size);
|
||||
}
|
||||
|
||||
void SerialPort::SetWriteBufferMode(SerialPort::WriteBufferMode mode) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSerialWriteMode(m_portHandle, mode, &status);
|
||||
FRC_CheckErrorStatus(
|
||||
status, "SetWriteBufferMode " + wpi::Twine{static_cast<int>(mode)});
|
||||
FRC_CheckErrorStatus(status, "SetWriteBufferMode {}", mode);
|
||||
}
|
||||
|
||||
void SerialPort::Flush() {
|
||||
int32_t status = 0;
|
||||
HAL_FlushSerial(m_portHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Flush");
|
||||
FRC_CheckErrorStatus(status, "{}", "Flush");
|
||||
}
|
||||
|
||||
void SerialPort::Reset() {
|
||||
int32_t status = 0;
|
||||
HAL_ClearSerial(m_portHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Reset");
|
||||
FRC_CheckErrorStatus(status, "{}", "Reset");
|
||||
}
|
||||
|
||||
@@ -24,19 +24,18 @@ Solenoid::Solenoid(int channel)
|
||||
Solenoid::Solenoid(int moduleNumber, int channel)
|
||||
: SolenoidBase(moduleNumber), m_channel(channel) {
|
||||
if (!SensorUtil::CheckSolenoidModule(m_moduleNumber)) {
|
||||
throw FRC_MakeError(err::ModuleIndexOutOfRange,
|
||||
"Solenoid Module " + wpi::Twine{m_moduleNumber});
|
||||
throw FRC_MakeError(err::ModuleIndexOutOfRange, "Module {}",
|
||||
m_moduleNumber);
|
||||
}
|
||||
if (!SensorUtil::CheckSolenoidChannel(m_channel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + wpi::Twine{m_channel});
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
m_solenoidHandle = HAL_InitializeSolenoidPort(
|
||||
HAL_GetPortWithModule(moduleNumber, channel), &status);
|
||||
FRC_CheckErrorStatus(status, "Solenoid Module " + wpi::Twine{m_moduleNumber} +
|
||||
" Channel " + wpi::Twine{m_channel});
|
||||
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
|
||||
m_channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Solenoid, m_channel + 1,
|
||||
m_moduleNumber + 1);
|
||||
@@ -51,13 +50,15 @@ Solenoid::~Solenoid() {
|
||||
void Solenoid::Set(bool on) {
|
||||
int32_t status = 0;
|
||||
HAL_SetSolenoid(m_solenoidHandle, on, &status);
|
||||
FRC_CheckErrorStatus(status, "Set");
|
||||
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
|
||||
m_channel);
|
||||
}
|
||||
|
||||
bool Solenoid::Get() const {
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetSolenoid(m_solenoidHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
|
||||
m_channel);
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -79,13 +80,15 @@ void Solenoid::SetPulseDuration(double durationSeconds) {
|
||||
int32_t durationMS = durationSeconds * 1000;
|
||||
int32_t status = 0;
|
||||
HAL_SetOneShotDuration(m_solenoidHandle, durationMS, &status);
|
||||
FRC_CheckErrorStatus(status, "SetPulseDuration");
|
||||
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
|
||||
m_channel);
|
||||
}
|
||||
|
||||
void Solenoid::StartPulse() {
|
||||
int32_t status = 0;
|
||||
HAL_FireOneShot(m_solenoidHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "StartPulse");
|
||||
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
|
||||
m_channel);
|
||||
}
|
||||
|
||||
void Solenoid::InitSendable(SendableBuilder& builder) {
|
||||
|
||||
@@ -15,7 +15,7 @@ int SolenoidBase::GetAll(int module) {
|
||||
int value = 0;
|
||||
int32_t status = 0;
|
||||
value = HAL_GetAllSolenoids(module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", module);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ int SolenoidBase::GetAll() const {
|
||||
int SolenoidBase::GetPCMSolenoidBlackList(int module) {
|
||||
int32_t status = 0;
|
||||
int rv = HAL_GetPCMSolenoidBlackList(module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", module);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ int SolenoidBase::GetPCMSolenoidBlackList() const {
|
||||
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault(int module) {
|
||||
int32_t status = 0;
|
||||
bool rv = HAL_GetPCMSolenoidVoltageStickyFault(module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", module);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ bool SolenoidBase::GetPCMSolenoidVoltageStickyFault() const {
|
||||
bool SolenoidBase::GetPCMSolenoidVoltageFault(int module) {
|
||||
int32_t status = 0;
|
||||
bool rv = HAL_GetPCMSolenoidVoltageFault(module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", module);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ bool SolenoidBase::GetPCMSolenoidVoltageFault() const {
|
||||
void SolenoidBase::ClearAllPCMStickyFaults(int module) {
|
||||
int32_t status = 0;
|
||||
HAL_ClearAllPCMStickyFaults(module, &status);
|
||||
FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module});
|
||||
FRC_CheckErrorStatus(status, "Module {}", module);
|
||||
}
|
||||
|
||||
void SolenoidBase::ClearAllPCMStickyFaults() {
|
||||
|
||||
@@ -16,7 +16,7 @@ int GetThreadPriority(std::thread& thread, bool* isRealTime) {
|
||||
HAL_Bool rt = false;
|
||||
auto native = thread.native_handle();
|
||||
auto ret = HAL_GetThreadPriority(&native, &rt, &status);
|
||||
FRC_CheckErrorStatus(status, "GetThreadPriority");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetThreadPriority");
|
||||
*isRealTime = rt;
|
||||
return ret;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ int GetCurrentThreadPriority(bool* isRealTime) {
|
||||
int32_t status = 0;
|
||||
HAL_Bool rt = false;
|
||||
auto ret = HAL_GetCurrentThreadPriority(&rt, &status);
|
||||
FRC_CheckErrorStatus(status, "GetCurrentThreadPriority");
|
||||
FRC_CheckErrorStatus(status, "{}", "GetCurrentThreadPriority");
|
||||
*isRealTime = rt;
|
||||
return ret;
|
||||
}
|
||||
@@ -34,14 +34,14 @@ bool SetThreadPriority(std::thread& thread, bool realTime, int priority) {
|
||||
int32_t status = 0;
|
||||
auto native = thread.native_handle();
|
||||
auto ret = HAL_SetThreadPriority(&native, realTime, priority, &status);
|
||||
FRC_CheckErrorStatus(status, "SetThreadPriority");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetThreadPriority");
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SetCurrentThreadPriority(bool realTime, int priority) {
|
||||
int32_t status = 0;
|
||||
auto ret = HAL_SetCurrentThreadPriority(realTime, priority, &status);
|
||||
FRC_CheckErrorStatus(status, "SetCurrentThreadPriority");
|
||||
FRC_CheckErrorStatus(status, "{}", "SetCurrentThreadPriority");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ void TimedRobot::StartCompetition() {
|
||||
HAL_UpdateNotifierAlarm(
|
||||
m_notifier, static_cast<uint64_t>(callback.expirationTime * 1e6),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "UpdateNotifierAlarm");
|
||||
FRC_CheckErrorStatus(status, "{}", "UpdateNotifierAlarm");
|
||||
|
||||
uint64_t curTime = HAL_WaitForNotifierAlarm(m_notifier, &status);
|
||||
if (curTime == 0 || status != 0) {
|
||||
@@ -76,7 +76,7 @@ TimedRobot::TimedRobot(units::second_t period) : IterativeRobotBase(period) {
|
||||
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
FRC_CheckErrorStatus(status, "InitializeNotifier");
|
||||
FRC_CheckErrorStatus(status, "{}", "InitializeNotifier");
|
||||
HAL_SetNotifierName(m_notifier, "TimedRobot", &status);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Framework,
|
||||
@@ -87,7 +87,7 @@ TimedRobot::~TimedRobot() {
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_StopNotifier(m_notifier, &status);
|
||||
FRC_ReportError(status, "StopNotifier");
|
||||
FRC_ReportError(status, "{}", "StopNotifier");
|
||||
|
||||
HAL_CleanNotifier(m_notifier, &status);
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ Ultrasonic::Ultrasonic(DigitalOutput* pingChannel, DigitalInput* echoChannel)
|
||||
m_echoChannel(echoChannel, NullDeleter<DigitalInput>()),
|
||||
m_counter(m_echoChannel) {
|
||||
if (!pingChannel) {
|
||||
throw FRC_MakeError(err::NullParameter, "pingChannel");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "pingChannel");
|
||||
}
|
||||
if (!echoChannel) {
|
||||
throw FRC_MakeError(err::NullParameter, "echoChannel");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "echoChannel");
|
||||
}
|
||||
Initialize();
|
||||
}
|
||||
@@ -83,7 +83,7 @@ Ultrasonic::~Ultrasonic() {
|
||||
|
||||
void Ultrasonic::Ping() {
|
||||
if (m_automaticEnabled) {
|
||||
throw FRC_MakeError(err::IncompatibleMode,
|
||||
throw FRC_MakeError(err::IncompatibleMode, "{}",
|
||||
"cannot call Ping() in automatic mode");
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class Watchdog::Impl {
|
||||
Watchdog::Impl::Impl() {
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
FRC_CheckErrorStatus(status, "starting watchdog notifier");
|
||||
FRC_CheckErrorStatus(status, "{}", "starting watchdog notifier");
|
||||
HAL_SetNotifierName(m_notifier, "Watchdog", &status);
|
||||
|
||||
m_thread = std::thread([=] { Main(); });
|
||||
@@ -59,7 +59,7 @@ Watchdog::Impl::~Impl() {
|
||||
// atomically set handle to 0, then clean
|
||||
HAL_NotifierHandle handle = m_notifier.exchange(0);
|
||||
HAL_StopNotifier(handle, &status);
|
||||
FRC_ReportError(status, "stopping watchdog notifier");
|
||||
FRC_ReportError(status, "{}", "stopping watchdog notifier");
|
||||
|
||||
// Join the thread to ensure the handler has exited.
|
||||
if (m_thread.joinable()) {
|
||||
@@ -85,7 +85,7 @@ void Watchdog::Impl::UpdateAlarm() {
|
||||
1e6),
|
||||
&status);
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "updating watchdog notifier alarm");
|
||||
FRC_CheckErrorStatus(status, "{}", "updating watchdog notifier alarm");
|
||||
}
|
||||
|
||||
void Watchdog::Impl::Main() {
|
||||
|
||||
@@ -58,7 +58,7 @@ ShuffleboardLayout& ShuffleboardContainer::GetLayout(const wpi::Twine& title) {
|
||||
auto titleRef = title.toStringRef(storage);
|
||||
if (m_layouts.count(titleRef) == 0) {
|
||||
throw FRC_MakeError(err::InvalidParameter,
|
||||
"No layout with the given title has been defined");
|
||||
"No layout with title {} has been defined", titleRef);
|
||||
}
|
||||
return *m_layouts[titleRef];
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ nt::NetworkTableEntry SmartDashboard::GetEntry(wpi::StringRef key) {
|
||||
|
||||
void SmartDashboard::PutData(wpi::StringRef key, Sendable* data) {
|
||||
if (!data) {
|
||||
throw FRC_MakeError(err::NullParameter, "value");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "value");
|
||||
}
|
||||
auto& inst = Singleton::GetInstance();
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
@@ -103,7 +103,7 @@ void SmartDashboard::PutData(wpi::StringRef key, Sendable* data) {
|
||||
|
||||
void SmartDashboard::PutData(Sendable* value) {
|
||||
if (!value) {
|
||||
throw FRC_MakeError(err::NullParameter, "value");
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "value");
|
||||
}
|
||||
auto name = SendableRegistry::GetInstance().GetName(value);
|
||||
if (!name.empty()) {
|
||||
@@ -116,7 +116,7 @@ Sendable* SmartDashboard::GetData(wpi::StringRef key) {
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
auto it = inst.tablesToData.find(key);
|
||||
if (it == inst.tablesToData.end()) {
|
||||
throw FRC_MakeError(err::SmartDashboardMissingKey, key);
|
||||
throw FRC_MakeError(err::SmartDashboardMissingKey, "{}", key);
|
||||
}
|
||||
return SendableRegistry::GetInstance().GetSendable(it->getValue());
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/HALBase.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpimath/MathShared.h>
|
||||
|
||||
#include "WPILibVersion.h"
|
||||
@@ -53,10 +54,12 @@ class WPILibCameraServerShared : public frc::CameraServerShared {
|
||||
HAL_Report(HALUsageReporting::kResourceType_PCVideoServer, id);
|
||||
}
|
||||
void SetCameraServerError(const wpi::Twine& error) override {
|
||||
FRC_ReportError(err::CameraServerError, error);
|
||||
wpi::SmallString<128> buf;
|
||||
FRC_ReportError(err::CameraServerError, "{}", error.toStringRef(buf));
|
||||
}
|
||||
void SetVisionRunnerError(const wpi::Twine& error) override {
|
||||
FRC_ReportError(-1, error);
|
||||
wpi::SmallString<128> buf;
|
||||
FRC_ReportError(-1, "{}", error.toStringRef(buf));
|
||||
}
|
||||
void ReportDriverStationError(const wpi::Twine& error) override {
|
||||
DriverStation::ReportError(error);
|
||||
|
||||
@@ -159,5 +159,6 @@ class AddressableLED {
|
||||
private:
|
||||
hal::Handle<HAL_DigitalHandle> m_pwmHandle;
|
||||
hal::Handle<HAL_AddressableLEDHandle> m_handle;
|
||||
int m_port;
|
||||
};
|
||||
} // namespace frc
|
||||
|
||||
@@ -151,6 +151,8 @@ class AnalogTrigger : public Sendable, public SendableHelper<AnalogTrigger> {
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
int GetSourceChannel() const;
|
||||
|
||||
hal::Handle<HAL_AnalogTriggerHandle> m_trigger;
|
||||
AnalogInput* m_analogInput = nullptr;
|
||||
DutyCycle* m_dutyCycle = nullptr;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include <wpi/Twine.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -19,10 +19,11 @@ namespace frc {
|
||||
*/
|
||||
class RuntimeError : public std::runtime_error {
|
||||
public:
|
||||
RuntimeError(int32_t code, const wpi::Twine& message, const wpi::Twine& loc,
|
||||
wpi::StringRef stack);
|
||||
RuntimeError(int32_t code, const wpi::Twine& message, const char* fileName,
|
||||
int lineNumber, const char* funcName, wpi::StringRef stack);
|
||||
RuntimeError(int32_t code, std::string&& loc, std::string&& stack,
|
||||
std::string&& message);
|
||||
RuntimeError(int32_t code, const char* fileName, int lineNumber,
|
||||
const char* funcName, std::string&& stack,
|
||||
std::string&& message);
|
||||
|
||||
int32_t code() const noexcept { return m_data->code; }
|
||||
const char* loc() const noexcept { return m_data->loc.c_str(); }
|
||||
@@ -52,13 +53,33 @@ const char* GetErrorMessage(int32_t* code);
|
||||
* Generally the FRC_ReportError wrapper macro should be used instead.
|
||||
*
|
||||
* @param status error code
|
||||
* @param message error message details
|
||||
* @param fileName source file name
|
||||
* @param lineNumber source line number
|
||||
* @param funcName source function name
|
||||
* @param format error message format
|
||||
* @param args error message format args
|
||||
*/
|
||||
void ReportError(int32_t status, const wpi::Twine& message,
|
||||
const char* fileName, int lineNumber, const char* funcName);
|
||||
void ReportErrorV(int32_t status, const char* fileName, int lineNumber,
|
||||
const char* funcName, fmt::string_view format,
|
||||
fmt::format_args args);
|
||||
|
||||
/**
|
||||
* Reports an error to the driver station (using HAL_SendError).
|
||||
* Generally the FRC_ReportError wrapper macro should be used instead.
|
||||
*
|
||||
* @param status error code
|
||||
* @param fileName source file name
|
||||
* @param lineNumber source line number
|
||||
* @param funcName source function name
|
||||
* @param format error message format
|
||||
* @param args error message format args
|
||||
*/
|
||||
template <typename S, typename... Args>
|
||||
inline void ReportError(int32_t status, const char* fileName, int lineNumber,
|
||||
const char* funcName, const S& format, Args&&... args) {
|
||||
ReportErrorV(status, fileName, lineNumber, funcName, format,
|
||||
fmt::make_args_checked<Args...>(format, args...));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a runtime error exception object. This object should be thrown
|
||||
@@ -72,9 +93,20 @@ void ReportError(int32_t status, const wpi::Twine& message,
|
||||
* @param funcName source function name
|
||||
* @return runtime error object
|
||||
*/
|
||||
[[nodiscard]] RuntimeError MakeError(int32_t status, const wpi::Twine& message,
|
||||
const char* fileName, int lineNumber,
|
||||
const char* funcName);
|
||||
[[nodiscard]] RuntimeError MakeErrorV(int32_t status, const char* fileName,
|
||||
int lineNumber, const char* funcName,
|
||||
fmt::string_view format,
|
||||
fmt::format_args args);
|
||||
|
||||
template <typename S, typename... Args>
|
||||
[[nodiscard]] inline RuntimeError MakeError(int32_t status,
|
||||
const char* fileName,
|
||||
int lineNumber,
|
||||
const char* funcName,
|
||||
const S& format, Args&&... args) {
|
||||
return MakeErrorV(status, fileName, lineNumber, funcName, format,
|
||||
fmt::make_args_checked<Args...>(format, args...));
|
||||
}
|
||||
|
||||
namespace err {
|
||||
#define S(label, offset, message) inline constexpr int label = offset;
|
||||
@@ -93,13 +125,14 @@ namespace warn {
|
||||
* Reports an error to the driver station (using HAL_SendError).
|
||||
*
|
||||
* @param status error code
|
||||
* @param message error message details
|
||||
* @param format error message format
|
||||
*/
|
||||
#define FRC_ReportError(status, message) \
|
||||
do { \
|
||||
if ((status) != 0) { \
|
||||
::frc::ReportError(status, message, __FILE__, __LINE__, __FUNCTION__); \
|
||||
} \
|
||||
#define FRC_ReportError(status, format, ...) \
|
||||
do { \
|
||||
if ((status) != 0) { \
|
||||
::frc::ReportError(status, __FILE__, __LINE__, __FUNCTION__, \
|
||||
FMT_STRING(format), __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
@@ -107,33 +140,37 @@ namespace warn {
|
||||
* by the caller.
|
||||
*
|
||||
* @param status error code
|
||||
* @param message error message details
|
||||
* @param format error message format
|
||||
* @return runtime error object
|
||||
*/
|
||||
#define FRC_MakeError(status, message) \
|
||||
::frc::MakeError(status, message, __FILE__, __LINE__, __FUNCTION__)
|
||||
#define FRC_MakeError(status, format, ...) \
|
||||
::frc::MakeError(status, __FILE__, __LINE__, __FUNCTION__, \
|
||||
FMT_STRING(format), __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Checks a status code and depending on its value, either throws a
|
||||
* RuntimeError exception, calls ReportError, or does nothing (if no error).
|
||||
*
|
||||
* @param status error code
|
||||
* @param message error message details
|
||||
* @param format error message format
|
||||
*/
|
||||
#define FRC_CheckErrorStatus(status, message) \
|
||||
do { \
|
||||
if ((status) < 0) { \
|
||||
throw FRC_MakeError(status, message); \
|
||||
} else if ((status) > 0) { \
|
||||
FRC_ReportError(status, message); \
|
||||
} \
|
||||
#define FRC_CheckErrorStatus(status, format, ...) \
|
||||
do { \
|
||||
if ((status) < 0) { \
|
||||
throw ::frc::MakeError(status, __FILE__, __LINE__, __FUNCTION__, \
|
||||
FMT_STRING(format), __VA_ARGS__); \
|
||||
} else if ((status) > 0) { \
|
||||
::frc::ReportError(status, __FILE__, __LINE__, __FUNCTION__, \
|
||||
FMT_STRING(format), __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FRC_AssertMessage(condition, message) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
throw FRC_MakeError(err::AssertionFailure, message); \
|
||||
} \
|
||||
#define FRC_AssertMessage(condition, format, ...) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
throw ::frc::MakeError(err::AssertionFailure, __FILE__, __LINE__, \
|
||||
__FUNCTION__, FMT_STRING(format), __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FRC_Assert(condition) FRC_AssertMessage(condition, #condition)
|
||||
#define FRC_Assert(condition) FRC_AssertMessage(condition, "{}", #condition)
|
||||
|
||||
Reference in New Issue
Block a user