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

@@ -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