diff --git a/hal/src/main/native/athena/REVPH.cpp b/hal/src/main/native/athena/REVPH.cpp index 9d8dc95e548..37b38659884 100644 --- a/hal/src/main/native/athena/REVPH.cpp +++ b/hal/src/main/native/athena/REVPH.cpp @@ -249,7 +249,7 @@ void HAL_FreeREVPH(HAL_REVPHHandle handle) { } HAL_Bool HAL_CheckREVPHModuleNumber(int32_t module) { - return module >= 1 && module <= kNumREVPDHModules; + return module >= 1 && module <= kNumREVPHModules; } HAL_Bool HAL_CheckREVPHSolenoidChannel(int32_t channel) { diff --git a/hal/src/main/native/sim/CTREPCM.cpp b/hal/src/main/native/sim/CTREPCM.cpp index 9d06ecb6364..0ac921f0406 100644 --- a/hal/src/main/native/sim/CTREPCM.cpp +++ b/hal/src/main/native/sim/CTREPCM.cpp @@ -49,7 +49,7 @@ HAL_CTREPCMHandle HAL_InitializeCTREPCM(int32_t module, pcm->previousAllocation); } else { hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for CTRE PCM", 0, - kNumCTREPCMModules, module); + kNumCTREPCMModules - 1, module); } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } diff --git a/hal/src/main/native/sim/PowerDistribution.cpp b/hal/src/main/native/sim/PowerDistribution.cpp index 22e4bba258d..25a0d36ccc3 100644 --- a/hal/src/main/native/sim/PowerDistribution.cpp +++ b/hal/src/main/native/sim/PowerDistribution.cpp @@ -44,8 +44,14 @@ HAL_PowerDistributionHandle HAL_InitializePowerDistribution( } if (!HAL_CheckPowerDistributionModule(module, type)) { - *status = PARAMETER_OUT_OF_RANGE; - hal::SetLastError(status, fmt::format("Invalid pdp module {}", module)); + *status = RESOURCE_OUT_OF_RANGE; + if (type == HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE) { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for CTRE PDP", 0, + kNumCTREPDPModules - 1, module); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PDH", 1, + kNumREVPDHModules, module); + } return HAL_kInvalidHandle; } hal::init::CheckInit(); @@ -74,7 +80,7 @@ HAL_Bool HAL_CheckPowerDistributionModule(int32_t module, if (type == HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE) { return module < kNumCTREPDPModules && module >= 0; } else { - return module < kNumREVPDHModules && module >= 1; + return module <= kNumREVPDHModules && module >= 1; } } diff --git a/hal/src/main/native/sim/REVPH.cpp b/hal/src/main/native/sim/REVPH.cpp index e09deeaea5f..89fda1ad35a 100644 --- a/hal/src/main/native/sim/REVPH.cpp +++ b/hal/src/main/native/sim/REVPH.cpp @@ -40,14 +40,16 @@ HAL_REVPHHandle HAL_InitializeREVPH(int32_t module, int32_t* status) { hal::init::CheckInit(); - if (module == 0) { + if (!HAL_CheckREVPHModuleNumber(module)) { + *status = RESOURCE_OUT_OF_RANGE; hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for REV PH", 1, kNumREVPHModules, module); return HAL_kInvalidHandle; } HAL_REVPHHandle handle; - auto pcm = pcmHandles->Allocate(module, &handle, status); + // Module starts at 1 + auto pcm = pcmHandles->Allocate(module - 1, &handle, status); if (*status != 0) { if (pcm) { @@ -82,7 +84,7 @@ void HAL_FreeREVPH(HAL_REVPHHandle handle) { } HAL_Bool HAL_CheckREVPHModuleNumber(int32_t module) { - return module >= 1 && module < kNumREVPDHModules; + return module >= 1 && module <= kNumREVPHModules; } HAL_Bool HAL_CheckREVPHSolenoidChannel(int32_t channel) {