SCRIPT: wpiformat

This commit is contained in:
PJ Reiniger
2025-11-07 20:01:58 -05:00
committed by Peter Johnson
parent ae6bdc9d25
commit 2109161534
749 changed files with 5504 additions and 3936 deletions

View File

@@ -40,11 +40,11 @@ void SetLastErrorIndexOutOfRange(int32_t* status, std::string_view message,
void SetLastErrorPreviouslyAllocated(int32_t* status, std::string_view message,
int32_t channel,
std::string_view previousAllocation) {
wpi::hal::SetLastError(status,
fmt::format("{} {} previously allocated.\n"
"Location of the previous allocation:\n{}\n"
"Location of the current allocation:",
message, channel, previousAllocation));
wpi::hal::SetLastError(
status, fmt::format("{} {} previously allocated.\n"
"Location of the previous allocation:\n{}\n"
"Location of the current allocation:",
message, channel, previousAllocation));
}
} // namespace wpi::hal

View File

@@ -18,14 +18,15 @@ using namespace wpi::hal;
using namespace wpi::hal::sim;
using namespace wpi::util::java;
static wpi::hal::UnlimitedHandleResource<SIM_JniHandle, BufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>*
callbackHandles;
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, BufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>* callbackHandles;
namespace wpi::hal::sim {
void InitializeBufferStore() {
static wpi::hal::UnlimitedHandleResource<SIM_JniHandle, BufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, BufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
cb;
callbackHandles = &cb;
}

View File

@@ -19,14 +19,14 @@ using namespace wpi::hal;
using namespace wpi::hal::sim;
using namespace wpi::util::java;
static wpi::hal::UnlimitedHandleResource<SIM_JniHandle, CallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>*
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, CallbackStore, wpi::hal::HAL_HandleEnum::SimulationJni>*
callbackHandles;
namespace wpi::hal::sim {
void InitializeStore() {
static wpi::hal::UnlimitedHandleResource<SIM_JniHandle, CallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, CallbackStore, wpi::hal::HAL_HandleEnum::SimulationJni>
cb;
callbackHandles = &cb;
}

View File

@@ -18,14 +18,15 @@ using namespace wpi::hal;
using namespace wpi::hal::sim;
using namespace wpi::util::java;
static wpi::hal::UnlimitedHandleResource<SIM_JniHandle, ConstBufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>*
callbackHandles;
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, ConstBufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>* callbackHandles;
namespace wpi::hal::sim {
void InitializeConstBufferStore() {
static wpi::hal::UnlimitedHandleResource<SIM_JniHandle, ConstBufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, ConstBufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
cb;
callbackHandles = &cb;
}

View File

@@ -537,8 +537,9 @@ Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setMatchInfo
JStringRef gameSpecificMessageRef{env, gameSpecificMessage};
HAL_MatchInfo halMatchInfo;
wpi::util::format_to_n_c_str(halMatchInfo.eventName, sizeof(halMatchInfo.eventName),
"{}", eventNameRef.str());
wpi::util::format_to_n_c_str(halMatchInfo.eventName,
sizeof(halMatchInfo.eventName), "{}",
eventNameRef.str());
wpi::util::format_to_n_c_str(
reinterpret_cast<char*>(halMatchInfo.gameSpecificMessage),
sizeof(halMatchInfo.gameSpecificMessage), "{}",

View File

@@ -193,9 +193,9 @@ void ValueCallbackStore::performCallback(const char* name,
}
}
static wpi::hal::UnlimitedHandleResource<SIM_JniHandle, DeviceCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>*
deviceCallbackHandles;
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, DeviceCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>* deviceCallbackHandles;
namespace {
using RegisterDeviceCallbackFunc =
@@ -250,8 +250,8 @@ static void FreeDeviceCallback(JNIEnv* env, SIM_JniHandle handle,
callback->free(env);
}
static wpi::hal::UnlimitedHandleResource<SIM_JniHandle, ValueCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>*
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, ValueCallbackStore, wpi::hal::HAL_HandleEnum::SimulationJni>*
valueCallbackHandles;
namespace {
@@ -346,13 +346,15 @@ bool InitializeSimDeviceDataJNI(JNIEnv* env) {
return false;
}
static wpi::hal::UnlimitedHandleResource<SIM_JniHandle, DeviceCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, DeviceCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
cbDevice;
deviceCallbackHandles = &cbDevice;
static wpi::hal::UnlimitedHandleResource<SIM_JniHandle, ValueCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, ValueCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
cbValue;
valueCallbackHandles = &cbValue;

View File

@@ -91,8 +91,8 @@ std::optional<mrc::ControlData> wpi::util::Protobuf<mrc::ControlData>::Unpack(
return ControlData;
}
bool wpi::util::Protobuf<mrc::ControlData>::Pack(OutputStream& Stream,
const mrc::ControlData& Value) {
bool wpi::util::Protobuf<mrc::ControlData>::Pack(
OutputStream& Stream, const mrc::ControlData& Value) {
std::span<const mrc::Joystick> Sticks = Value.Joysticks();
wpi::util::PackCallback Joysticks{Sticks};
@@ -149,7 +149,7 @@ std::optional<mrc::Joystick> wpi::util::Protobuf<mrc::Joystick>::Unpack(
}
bool wpi::util::Protobuf<mrc::Joystick>::Pack(OutputStream& Stream,
const mrc::Joystick& Value) {
const mrc::Joystick& Value) {
wpi::util::PackCallback AxesCb{Value.Axes.Axes()};
uint32_t PovsStore = 0;

View File

@@ -50,7 +50,7 @@ std::optional<mrc::ErrorInfo> wpi::util::Protobuf<mrc::ErrorInfo>::Unpack(
}
bool wpi::util::Protobuf<mrc::ErrorInfo>::Pack(OutputStream& Stream,
const mrc::ErrorInfo& Value) {
const mrc::ErrorInfo& Value) {
std::string_view DetailsView = Value.GetDetails();
std::string_view LocationView = Value.GetLocation();
std::string_view CallStackView = Value.GetCallStack();

View File

@@ -36,7 +36,7 @@ std::optional<mrc::MatchInfo> wpi::util::Protobuf<mrc::MatchInfo>::Unpack(
}
bool wpi::util::Protobuf<mrc::MatchInfo>::Pack(OutputStream& Stream,
const mrc::MatchInfo& Value) {
const mrc::MatchInfo& Value) {
std::string_view EventNameStr = Value.GetEventName();
wpi::util::PackCallback EventName{&EventNameStr};

View File

@@ -35,7 +35,7 @@ std::optional<mrc::OpMode> wpi::util::Protobuf<mrc::OpMode>::Unpack(
}
bool wpi::util::Protobuf<mrc::OpMode>::Pack(OutputStream& Stream,
const mrc::OpMode& Value) {
const mrc::OpMode& Value) {
std::string_view EventNameStr = Value.GetName();
wpi::util::PackCallback EventName{&EventNameStr};

View File

@@ -72,7 +72,8 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
return HAL_kInvalidHandle;
}
m_structures[index] = toSet;
return static_cast<THandle>(wpi::hal::createHandle(index, enumValue, m_version));
return static_cast<THandle>(
wpi::hal::createHandle(index, enumValue, m_version));
}
template <typename THandle, typename TStruct, int16_t size,

View File

@@ -21,7 +21,8 @@ class SimCallbackRegistryBase {
using RawFunctor = void (*)();
protected:
using CallbackVector = wpi::util::UidVector<HalCallbackListener<RawFunctor>, 4>;
using CallbackVector =
wpi::util::UidVector<HalCallbackListener<RawFunctor>, 4>;
public:
void Cancel(int32_t uid) {

View File

@@ -28,8 +28,9 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
if (channel < 0 || channel >= kNumAddressableLEDs) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for AddressableLED",
0, kNumAddressableLEDs, channel);
wpi::hal::SetLastErrorIndexOutOfRange(status,
"Invalid Index for AddressableLED", 0,
kNumAddressableLEDs, channel);
return HAL_kInvalidHandle;
}
@@ -41,11 +42,11 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
if (*status != 0) {
if (port) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "PWM or DIO", channel,
port->previousAllocation);
port->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status,
"Invalid Index for AddressableLED", 0,
kNumAddressableLEDs, channel);
"Invalid Index for AddressableLED",
0, kNumAddressableLEDs, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -23,8 +23,8 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
wpi::hal::init::CheckInit();
if (channel < 0 || channel >= kNumAnalogInputs) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Input",
0, kNumAnalogInputs, channel);
wpi::hal::SetLastErrorIndexOutOfRange(
status, "Invalid Index for Analog Input", 0, kNumAnalogInputs, channel);
return HAL_kInvalidHandle;
}
@@ -33,11 +33,12 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
if (*status != 0) {
if (analog_port) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "Analog Input", channel,
analog_port->previousAllocation);
wpi::hal::SetLastErrorPreviouslyAllocated(
status, "Analog Input", channel, analog_port->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Input",
0, kNumAnalogInputs, channel);
wpi::hal::SetLastErrorIndexOutOfRange(status,
"Invalid Index for Analog Input", 0,
kNumAnalogInputs, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -8,8 +8,9 @@
#include "wpi/hal/handles/IndexedHandleResource.h"
namespace wpi::hal {
IndexedHandleResource<HAL_AnalogInputHandle, wpi::hal::AnalogPort, kNumAnalogInputs,
HAL_HandleEnum::AnalogInput>* analogInputHandles;
IndexedHandleResource<HAL_AnalogInputHandle, wpi::hal::AnalogPort,
kNumAnalogInputs, HAL_HandleEnum::AnalogInput>*
analogInputHandles;
} // namespace wpi::hal
namespace wpi::hal::init {

View File

@@ -46,10 +46,11 @@ HAL_CTREPCMHandle HAL_InitializeCTREPCM(int32_t busId, int32_t module,
if (*status != 0) {
if (pcm) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "CTRE PCM", module,
pcm->previousAllocation);
pcm->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for CTRE PCM", 0,
kNumCTREPCMModules - 1, module);
wpi::hal::SetLastErrorIndexOutOfRange(status,
"Invalid Index for CTRE PCM", 0,
kNumCTREPCMModules - 1, module);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -39,7 +39,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
if (channel < 0 || channel >= kNumDigitalChannels) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0,
kNumDigitalChannels, channel);
kNumDigitalChannels, channel);
return HAL_kInvalidHandle;
}
@@ -51,10 +51,10 @@ HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
if (*status != 0) {
if (port) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "PWM or DIO", channel,
port->previousAllocation);
port->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0,
kNumDigitalChannels, channel);
kNumDigitalChannels, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -48,10 +48,10 @@ HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
if (*status != 0) {
if (dutyCycle) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "SmartIo", channel,
dutyCycle->previousAllocation);
dutyCycle->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Duty Cycle",
0, kNumDutyCycles, channel);
wpi::hal::SetLastErrorIndexOutOfRange(
status, "Invalid Index for Duty Cycle", 0, kNumDutyCycles, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -57,7 +57,7 @@ extern "C" {
int HAL_LoadOneExtension(const char* library) {
int rc = 1; // It is expected and reasonable not to find an extra simulation
wpi::util::print("HAL Extensions: Attempting to load: {}\n",
fs::path{library}.stem().string());
fs::path{library}.stem().string());
std::fflush(stdout);
HTYPE handle = DLOPEN(library);
#if !defined(WIN32) && !defined(_WIN32)
@@ -67,8 +67,9 @@ int HAL_LoadOneExtension(const char* library) {
#else
auto libraryName = fmt::format("lib{}.so", library);
#endif
wpi::util::print("HAL Extensions: Load failed: {}\nTrying modified name: {}\n",
DLERROR, fs::path{libraryName}.stem().string());
wpi::util::print(
"HAL Extensions: Load failed: {}\nTrying modified name: {}\n", DLERROR,
fs::path{libraryName}.stem().string());
std::fflush(stdout);
handle = DLOPEN(libraryName.c_str());
}

View File

@@ -319,8 +319,8 @@ int32_t HALSIM_GetNotifierInfo(struct HALSIM_NotifierInfo* arr, int32_t size) {
arr[num].handle = handle;
if (notifier->name.empty()) {
wpi::util::format_to_n_c_str(arr[num].name, sizeof(arr[num].name),
"Notifier{}",
static_cast<int>(getHandleIndex(handle)));
"Notifier{}",
static_cast<int>(getHandleIndex(handle)));
} else {
std::strncpy(arr[num].name, notifier->name.c_str(),
sizeof(arr[num].name) - 1);

View File

@@ -31,7 +31,7 @@ HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
if (channel < 0 || channel >= kNumPWMChannels) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0,
kNumPWMChannels, channel);
kNumPWMChannels, channel);
return HAL_kInvalidHandle;
}
@@ -51,10 +51,10 @@ HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
if (*status != 0) {
if (port) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "PWM or DIO", channel,
port->previousAllocation);
port->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0,
kNumPWMChannels, channel);
kNumPWMChannels, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -46,11 +46,12 @@ HAL_PowerDistributionHandle HAL_InitializePowerDistribution(
if (!HAL_CheckPowerDistributionModule(module, type)) {
*status = RESOURCE_OUT_OF_RANGE;
if (type == HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE) {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for CTRE PDP", 0,
kNumCTREPDPModules - 1, module);
wpi::hal::SetLastErrorIndexOutOfRange(status,
"Invalid Index for CTRE PDP", 0,
kNumCTREPDPModules - 1, module);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PDH", 1,
kNumREVPDHModules, module);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PDH",
1, kNumREVPDHModules, module);
}
return HAL_kInvalidHandle;
}

View File

@@ -43,7 +43,7 @@ HAL_REVPHHandle HAL_InitializeREVPH(int32_t busId, int32_t module,
if (!HAL_CheckREVPHModuleNumber(module)) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PH", 1,
kNumREVPHModules, module);
kNumREVPHModules, module);
return HAL_kInvalidHandle;
}
@@ -54,10 +54,10 @@ HAL_REVPHHandle HAL_InitializeREVPH(int32_t busId, int32_t module,
if (*status != 0) {
if (pcm) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "REV PH", module,
pcm->previousAllocation);
pcm->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PH", 1,
kNumREVPHModules, module);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PH",
1, kNumREVPHModules, module);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -532,7 +532,8 @@ void HALSIM_SetJoystickName(int32_t stick, const WPI_String* name) {
}
void HALSIM_SetGameSpecificMessage(const WPI_String* message) {
SimDriverStationData->SetGameSpecificMessage(wpi::util::to_string_view(message));
SimDriverStationData->SetGameSpecificMessage(
wpi::util::to_string_view(message));
}
void HALSIM_SetEventName(const WPI_String* name) {

View File

@@ -29,7 +29,8 @@ class SimUnnamedCallbackRegistry {
using RawFunctor = void (*)();
protected:
using CallbackVector = wpi::util::UidVector<HalCallbackListener<RawFunctor>, 4>;
using CallbackVector =
wpi::util::UidVector<HalCallbackListener<RawFunctor>, 4>;
public:
void Cancel(int32_t uid) {

View File

@@ -90,8 +90,8 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
if (channel < 0 || channel >= kNumSmartIo) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for AddressableLED",
0, kNumSmartIo, channel);
wpi::hal::SetLastErrorIndexOutOfRange(
status, "Invalid Index for AddressableLED", 0, kNumSmartIo, channel);
return HAL_kInvalidHandle;
}
@@ -103,7 +103,7 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
if (*status != 0) {
if (port) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "SmartIo", channel,
port->previousAllocation);
port->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(
status, "Invalid Index for AddressableLED", 0, kNumSmartIo, channel);

View File

@@ -31,7 +31,7 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
if (channel < 0 || channel >= kNumSmartIo) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog", 0,
kNumSmartIo, channel);
kNumSmartIo, channel);
return HAL_kInvalidHandle;
}
@@ -43,10 +43,10 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
if (*status != 0) {
if (port) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "SmartIo", channel,
port->previousAllocation);
port->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog", 0,
kNumSmartIo, channel);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog",
0, kNumSmartIo, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -88,18 +88,21 @@ struct SocketCanState {
wpi::util::mutex writeMutex[wpi::hal::kNumCanBuses];
int socketHandle[wpi::hal::kNumCanBuses];
// ms to count/timer map
wpi::util::DenseMap<uint16_t, std::pair<size_t, std::weak_ptr<wpi::net::uv::Timer>>>
wpi::util::DenseMap<uint16_t,
std::pair<size_t, std::weak_ptr<wpi::net::uv::Timer>>>
timers;
// ms to bus mask/packet
wpi::util::DenseMap<uint16_t,
std::array<std::optional<canfd_frame>, wpi::hal::kNumCanBuses>>
wpi::util::DenseMap<
uint16_t, std::array<std::optional<canfd_frame>, wpi::hal::kNumCanBuses>>
timedFrames;
// packet to time
wpi::util::DenseMap<uint32_t, std::array<uint16_t, wpi::hal::kNumCanBuses>> packetToTime;
wpi::util::DenseMap<uint32_t, std::array<uint16_t, wpi::hal::kNumCanBuses>>
packetToTime;
wpi::util::mutex readMutex[wpi::hal::kNumCanBuses];
// TODO(thadhouse) we need a MUCH better way of doing this masking
wpi::util::DenseMap<uint32_t, HAL_CANStreamMessage> readFrames[wpi::hal::kNumCanBuses];
wpi::util::DenseMap<uint32_t, HAL_CANStreamMessage>
readFrames[wpi::hal::kNumCanBuses];
std::vector<CANStreamStorage*> canStreams[wpi::hal::kNumCanBuses];
bool InitializeBuses();
@@ -157,7 +160,7 @@ bool SocketCanState::InitializeBuses() {
socketHandle[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW);
if (socketHandle[i] == -1) {
wpi::util::print("socket() for CAN {} failed with {}\n", i,
std::strerror(errno));
std::strerror(errno));
success = false;
return;
}
@@ -167,7 +170,7 @@ bool SocketCanState::InitializeBuses() {
if (ioctl(socketHandle[i], SIOCGIFINDEX, &ifr) == -1) {
wpi::util::print("ioctl(SIOCGIFINDEX) for CAN {} failed with {}\n",
ifr.ifr_name, std::strerror(errno));
ifr.ifr_name, std::strerror(errno));
success = false;
return;
}
@@ -180,14 +183,14 @@ bool SocketCanState::InitializeBuses() {
if (bind(socketHandle[i], reinterpret_cast<const sockaddr*>(&addr),
sizeof(addr)) == -1) {
wpi::util::print("bind() for CAN {} failed with {}\n", ifr.ifr_name,
std::strerror(errno));
std::strerror(errno));
success = false;
return;
}
if (ioctl(socketHandle[i], SIOCGIFMTU, &ifr) == -1) {
wpi::util::print("ioctl(SIOCGIFMTU) for CAN {} failed with {}\n",
ifr.ifr_name, std::strerror(errno));
ifr.ifr_name, std::strerror(errno));
success = false;
return;
}
@@ -206,7 +209,8 @@ bool SocketCanState::InitializeBuses() {
auto poll = wpi::net::uv::Poll::Create(loop, socketHandle[i]);
if (!poll) {
wpi::util::print("wpi::net::uv::Poll::Create for CAN {} failed\n", ifr.ifr_name);
wpi::util::print("wpi::net::uv::Poll::Create for CAN {} failed\n",
ifr.ifr_name);
success = false;
return;
}
@@ -309,7 +313,8 @@ void SocketCanState::AddPeriodic(wpi::net::uv::Loop& loop, uint8_t busId,
if (timer.first == 1) {
auto newTimer = wpi::net::uv::Timer::Create(loop);
newTimer->timeout.connect([this, time] { TimerCallback(time); });
newTimer->Start(wpi::net::uv::Timer::Time{time}, wpi::net::uv::Timer::Time{time});
newTimer->Start(wpi::net::uv::Timer::Time{time},
wpi::net::uv::Timer::Time{time});
}
}

View File

@@ -186,10 +186,11 @@ HAL_CTREPCMHandle HAL_InitializeCTREPCM(int32_t busId, int32_t module,
if (*status != 0) {
if (pcm) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "CTRE PCM", module,
pcm->previousAllocation);
pcm->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for CTRE PCM", 0,
kNumCTREPCMModules - 1, module);
wpi::hal::SetLastErrorIndexOutOfRange(status,
"Invalid Index for CTRE PCM", 0,
kNumCTREPCMModules - 1, module);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -135,8 +135,8 @@ HAL_PDPHandle HAL_InitializePDP(int32_t busId, int32_t module,
wpi::hal::init::CheckInit();
if (!HAL_CheckPDPModule(module)) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for CTRE PDP", 0,
kNumCTREPDPModules - 1, module);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for CTRE PDP",
0, kNumCTREPDPModules - 1, module);
return HAL_kInvalidHandle;
}
@@ -146,10 +146,11 @@ HAL_PDPHandle HAL_InitializePDP(int32_t busId, int32_t module,
if (*status != 0) {
if (pdp) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "CTRE PDP", module,
pdp->previousAllocation);
pdp->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for CTRE PDP", 0,
kNumCTREPDPModules - 1, module);
wpi::hal::SetLastErrorIndexOutOfRange(status,
"Invalid Index for CTRE PDP", 0,
kNumCTREPDPModules - 1, module);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}
@@ -232,7 +233,8 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
int32_t* status) {
if (!HAL_CheckPDPChannel(channel)) {
*status = PARAMETER_OUT_OF_RANGE;
wpi::hal::SetLastError(status, fmt::format("Invalid pdp channel {}", channel));
wpi::hal::SetLastError(status,
fmt::format("Invalid pdp channel {}", channel));
return 0;
}

View File

@@ -33,8 +33,8 @@ HAL_CounterHandle HAL_InitializeCounter(int channel, HAL_Bool risingEdge,
wpi::hal::init::CheckInit();
if (channel == InvalidHandleIndex || channel >= kNumSmartIo) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Counter", 0,
kNumSmartIo, channel);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Counter",
0, kNumSmartIo, channel);
return HAL_kInvalidHandle;
}
@@ -46,10 +46,10 @@ HAL_CounterHandle HAL_InitializeCounter(int channel, HAL_Bool risingEdge,
if (*status != 0) {
if (port) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "SmartIo", channel,
port->previousAllocation);
port->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Counter", 0,
kNumSmartIo, channel);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Counter",
0, kNumSmartIo, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -33,7 +33,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
if (channel < 0 || channel >= kNumSmartIo) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0,
kNumSmartIo, channel);
kNumSmartIo, channel);
return HAL_kInvalidHandle;
}
@@ -45,10 +45,10 @@ HAL_DigitalHandle HAL_InitializeDIOPort(int32_t channel, HAL_Bool input,
if (*status != 0) {
if (port) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "SmartIo", channel,
port->previousAllocation);
port->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0,
kNumSmartIo, channel);
kNumSmartIo, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -31,8 +31,8 @@ HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
if (channel < 0 || channel >= kNumSmartIo) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DutyCycle", 0,
kNumSmartIo, channel);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DutyCycle",
0, kNumSmartIo, channel);
return HAL_kInvalidHandle;
}
@@ -44,10 +44,10 @@ HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
if (*status != 0) {
if (port) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "SmartIo", channel,
port->previousAllocation);
port->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DutyCycle", 0,
kNumSmartIo, channel);
wpi::hal::SetLastErrorIndexOutOfRange(
status, "Invalid Index for DutyCycle", 0, kNumSmartIo, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -48,7 +48,7 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
if (port < 0 || port > 2) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for I2C", 0, 1,
port);
port);
return;
}
@@ -61,9 +61,11 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
if (handle < 0) {
int err = errno;
*status = NO_AVAILABLE_RESOURCES;
wpi::hal::SetLastError(status, fmt::format("Failed to open onboard i2c bus: {}",
std::strerror(err)));
wpi::util::print("Failed to open onboard i2c bus: {}\n", std::strerror(err));
wpi::hal::SetLastError(
status,
fmt::format("Failed to open onboard i2c bus: {}", std::strerror(err)));
wpi::util::print("Failed to open onboard i2c bus: {}\n",
std::strerror(err));
handle = -1;
i2cObjs[port].objCount--;
return;
@@ -76,8 +78,8 @@ int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
uint8_t* dataReceived, int32_t receiveSize) {
if (port < 0 || port > 2) {
int32_t status = 0;
wpi::hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0, 1,
port);
wpi::hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0,
1, port);
return -1;
}
@@ -103,8 +105,8 @@ int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
const uint8_t* dataToSend, int32_t sendSize) {
if (port < 0 || port > 2) {
int32_t status = 0;
wpi::hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0, 2,
port);
wpi::hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0,
2, port);
return -1;
}
@@ -126,8 +128,8 @@ int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
int32_t count) {
if (port < 0 || port > 2) {
int32_t status = 0;
wpi::hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0, 1,
port);
wpi::hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0,
1, port);
return -1;
}
@@ -148,8 +150,8 @@ int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
void HAL_CloseI2C(HAL_I2CPort port) {
if (port < 0 || port > 2) {
int32_t status = 0;
wpi::hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0, 1,
port);
wpi::hal::SetLastErrorIndexOutOfRange(&status, "Invalid Index for I2C", 0,
1, port);
return;
}

View File

@@ -36,7 +36,7 @@ HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
if (channel < 0 || channel >= kNumSmartIo) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0,
kNumSmartIo, channel);
kNumSmartIo, channel);
return HAL_kInvalidHandle;
}
@@ -48,10 +48,10 @@ HAL_DigitalHandle HAL_InitializePWMPort(int32_t channel,
if (*status != 0) {
if (port) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "SmartIo", channel,
port->previousAllocation);
port->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0,
kNumSmartIo, channel);
kNumSmartIo, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -194,8 +194,8 @@ HAL_REVPDHHandle HAL_InitializeREVPDH(int32_t busId, int32_t module,
wpi::hal::init::CheckInit();
if (!HAL_CheckREVPDHModuleNumber(module)) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PDH", 1,
kNumREVPDHModules, module);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PDH",
1, kNumREVPDHModules, module);
return HAL_kInvalidHandle;
}
@@ -205,10 +205,10 @@ HAL_REVPDHHandle HAL_InitializeREVPDH(int32_t busId, int32_t module,
if (*status != 0) {
if (hpdh) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "REV PDH", module,
hpdh->previousAllocation);
hpdh->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PDH", 1,
kNumREVPDHModules, module);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PDH",
1, kNumREVPDHModules, module);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -198,7 +198,7 @@ HAL_REVPHHandle HAL_InitializeREVPH(int32_t busId, int32_t module,
if (!HAL_CheckREVPHModuleNumber(module)) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PH", 1,
kNumREVPHModules, module);
kNumREVPHModules, module);
return HAL_kInvalidHandle;
}
@@ -208,10 +208,10 @@ HAL_REVPHHandle HAL_InitializeREVPH(int32_t busId, int32_t module,
if (*status != 0) {
if (hph) {
wpi::hal::SetLastErrorPreviouslyAllocated(status, "REV PH", module,
hph->previousAllocation);
hph->previousAllocation);
} else {
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PH", 1,
kNumREVPHModules, module);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PH",
1, kNumREVPHModules, module);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}
@@ -398,8 +398,8 @@ double HAL_GetREVPHAnalogVoltage(HAL_REVPHHandle handle, int32_t channel,
if (channel < 0 || channel > 1) {
*status = PARAMETER_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid REV Analog Index", 0, 2,
channel);
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid REV Analog Index", 0,
2, channel);
return 0;
}

View File

@@ -46,6 +46,7 @@ int32_t HAL_ReportUsage(const struct WPI_String* resource,
namespace wpi::hal::init {
void InitializeUsageReporting() {
systemServerUsage = new ::SystemServerUsageReporting{wpi::hal::GetSystemServer()};
systemServerUsage =
new ::SystemServerUsageReporting{wpi::hal::GetSystemServer()};
}
} // namespace wpi::hal::init