Skip to content

Commit

Permalink
[hal,wpilib] Change Power Distribution usage reporting to Instances (#…
Browse files Browse the repository at this point in the history
…7465)

LabVIEW doesn't appear to report PDP. This should reduce the number of
Unknowns in the parsed UsageReporting.
  • Loading branch information
sciencewhiz authored Dec 1, 2024
1 parent c387a7e commit 9807d60
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
3 changes: 3 additions & 0 deletions hal/src/generate/Instances.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ kLoggingFramework_Epilogue = 2
kLoggingFramework_Monologue = 3
kLoggingFramework_AdvantageKit = 4
kLoggingFramework_DogLog = 5
kPDP_CTRE = 1
kPDP_REV = 2
kPDP_Unknown = 3
6 changes: 6 additions & 0 deletions hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions hal/src/generated/main/native/include/hal/FRCUsageReporting.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions hal/src/generated/main/native/include/hal/UsageReporting.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions wpilibc/src/main/native/cpp/PowerDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ PowerDistribution::PowerDistribution() {
m_module = HAL_GetPowerDistributionModuleNumber(m_handle, &status);
FRC_ReportError(status, "Module {}", m_module);

HAL_Report(HALUsageReporting::kResourceType_PDP, m_module + 1);
if (HAL_GetPowerDistributionType(m_handle, &status) ==
HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE) {
HAL_Report(HALUsageReporting::kResourceType_PDP,
HALUsageReporting::kPDP_CTRE);
} else {
HAL_Report(HALUsageReporting::kResourceType_PDP,
HALUsageReporting::kPDP_REV);
}
wpi::SendableRegistry::AddLW(this, "PowerDistribution", m_module);
}

Expand All @@ -54,7 +61,13 @@ PowerDistribution::PowerDistribution(int module, ModuleType moduleType) {
m_module = HAL_GetPowerDistributionModuleNumber(m_handle, &status);
FRC_ReportError(status, "Module {}", module);

HAL_Report(HALUsageReporting::kResourceType_PDP, m_module + 1);
if (moduleType == ModuleType::kCTRE) {
HAL_Report(HALUsageReporting::kResourceType_PDP,
HALUsageReporting::kPDP_CTRE);
} else {
HAL_Report(HALUsageReporting::kResourceType_PDP,
HALUsageReporting::kPDP_REV);
}
wpi::SendableRegistry::AddLW(this, "PowerDistribution", m_module);
}

Expand Down
14 changes: 12 additions & 2 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/PowerDistribution.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package edu.wpi.first.wpilibj;

import edu.wpi.first.hal.FRCNetComm.tInstances;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.PowerDistributionFaults;
Expand Down Expand Up @@ -51,7 +52,11 @@ public PowerDistribution(int module, ModuleType moduleType) {
m_handle = PowerDistributionJNI.initialize(module, moduleType.value);
m_module = PowerDistributionJNI.getModuleNumber(m_handle);

HAL.report(tResourceType.kResourceType_PDP, m_module + 1);
if (moduleType == ModuleType.kCTRE) {
HAL.report(tResourceType.kResourceType_PDP, tInstances.kPDP_CTRE);
} else {
HAL.report(tResourceType.kResourceType_PDP, tInstances.kPDP_REV);
}
SendableRegistry.addLW(this, "PowerDistribution", m_module);
}

Expand All @@ -65,7 +70,12 @@ public PowerDistribution() {
m_handle = PowerDistributionJNI.initialize(kDefaultModule, PowerDistributionJNI.AUTOMATIC_TYPE);
m_module = PowerDistributionJNI.getModuleNumber(m_handle);

HAL.report(tResourceType.kResourceType_PDP, m_module + 1);
if (PowerDistributionJNI.getType(m_handle) == PowerDistributionJNI.CTRE_TYPE) {
HAL.report(tResourceType.kResourceType_PDP, tInstances.kPDP_CTRE);
} else {
HAL.report(tResourceType.kResourceType_PDP, tInstances.kPDP_REV);
}

SendableRegistry.addLW(this, "PowerDistribution", m_module);
}

Expand Down

0 comments on commit 9807d60

Please sign in to comment.