diff --git a/hal/include/HAL/PDP.hpp b/hal/include/HAL/PDP.hpp index 3dde22b48f..5988702f80 100644 --- a/hal/include/HAL/PDP.hpp +++ b/hal/include/HAL/PDP.hpp @@ -8,12 +8,13 @@ extern "C" { - double getPDPTemperature(int32_t *status); - double getPDPVoltage(int32_t *status); - double getPDPChannelCurrent(uint8_t channel, int32_t *status); - double getPDPTotalCurrent(int32_t *status); - double getPDPTotalPower(int32_t *status); - double getPDPTotalEnergy(int32_t *status); - void resetPDPTotalEnergy(int32_t *status); - void clearPDPStickyFaults(int32_t *status); + void initializePDP(int module); + double getPDPTemperature(int32_t *status, uint8_t module); + double getPDPVoltage(int32_t *status, uint8_t module); + double getPDPChannelCurrent(uint8_t channel, int32_t *status, uint8_t module); + double getPDPTotalCurrent(int32_t *status, uint8_t module); + double getPDPTotalPower(int32_t *status, uint8_t module); + double getPDPTotalEnergy(int32_t *status, uint8_t module); + void resetPDPTotalEnergy(int32_t *status, uint8_t module); + void clearPDPStickyFaults(int32_t *status, uint8_t module); } diff --git a/hal/lib/Athena/PDP.cpp b/hal/lib/Athena/PDP.cpp index 6129c06ed5..fff7a1f33f 100644 --- a/hal/lib/Athena/PDP.cpp +++ b/hal/lib/Athena/PDP.cpp @@ -1,61 +1,71 @@ #include "HAL/PDP.hpp" #include "ctre/PDP.h" -static PDP pdp; +//static PDP pdp; -double getPDPTemperature(int32_t *status) { +static const int NUM_MODULE_NUMBERS = 63; + +PDP *pdp[NUM_MODULE_NUMBERS] = { NULL }; + +void initializePDP(int module) { + if(!pdp[module]) { + pdp[module] = new PDP(module); + } +} + +double getPDPTemperature(int32_t *status, uint8_t module) { double temperature; - *status = pdp.GetTemperature(temperature); + *status = pdp[module]->GetTemperature(temperature); return temperature; } -double getPDPVoltage(int32_t *status) { +double getPDPVoltage(int32_t *status, uint8_t module) { double voltage; - *status = pdp.GetVoltage(voltage); + *status = pdp[module]->GetVoltage(voltage); return voltage; } -double getPDPChannelCurrent(uint8_t channel, int32_t *status) { +double getPDPChannelCurrent(uint8_t channel, int32_t *status, uint8_t module) { double current; - *status = pdp.GetChannelCurrent(channel, current); + *status = pdp[module]->GetChannelCurrent(channel, current); return current; } -double getPDPTotalCurrent(int32_t *status) { +double getPDPTotalCurrent(int32_t *status, uint8_t module) { double current; - *status = pdp.GetTotalCurrent(current); + *status = pdp[module]->GetTotalCurrent(current); return current; } -double getPDPTotalPower(int32_t *status) { +double getPDPTotalPower(int32_t *status, uint8_t module) { double power; - *status = pdp.GetTotalPower(power); + *status = pdp[module]->GetTotalPower(power); return power; } -double getPDPTotalEnergy(int32_t *status) { +double getPDPTotalEnergy(int32_t *status, uint8_t module) { double energy; - *status = pdp.GetTotalEnergy(energy); + *status = pdp[module]->GetTotalEnergy(energy); return energy; } -void resetPDPTotalEnergy(int32_t *status) { - *status = pdp.ResetEnergy(); +void resetPDPTotalEnergy(int32_t *status, uint8_t module) { + *status = pdp[module]->ResetEnergy(); } -void clearPDPStickyFaults(int32_t *status) { - *status = pdp.ClearStickyFaults(); +void clearPDPStickyFaults(int32_t *status, uint8_t module) { + *status = pdp[module]->ClearStickyFaults(); } diff --git a/wpilibc/wpilibC++Devices/include/PowerDistributionPanel.h b/wpilibc/wpilibC++Devices/include/PowerDistributionPanel.h index 24f53e5f80..8ab8fb9b55 100644 --- a/wpilibc/wpilibC++Devices/include/PowerDistributionPanel.h +++ b/wpilibc/wpilibC++Devices/include/PowerDistributionPanel.h @@ -19,6 +19,7 @@ class PowerDistributionPanel : public SensorBase, public LiveWindowSendable { public: PowerDistributionPanel(); + PowerDistributionPanel(uint8_t module); double GetVoltage(); double GetTemperature(); @@ -38,6 +39,7 @@ class PowerDistributionPanel : public SensorBase, public LiveWindowSendable { private: ITable *m_table; + uint8_t m_module; }; #endif /* __WPILIB_POWER_DISTRIBUTION_PANEL_H__ */ diff --git a/wpilibc/wpilibC++Devices/src/PowerDistributionPanel.cpp b/wpilibc/wpilibC++Devices/src/PowerDistributionPanel.cpp index 2a961a0875..4337c79799 100644 --- a/wpilibc/wpilibC++Devices/src/PowerDistributionPanel.cpp +++ b/wpilibc/wpilibC++Devices/src/PowerDistributionPanel.cpp @@ -9,11 +9,17 @@ #include "HAL/PDP.hpp" #include "LiveWindow/LiveWindow.h" +PowerDistributionPanel::PowerDistributionPanel() { + PowerDistributionPanel(0); +} + /** * Initialize the PDP. */ -PowerDistributionPanel::PowerDistributionPanel() { +PowerDistributionPanel::PowerDistributionPanel(uint8_t module) { m_table=NULL; + m_module = module; + initializePDP(m_module); } /** @@ -24,7 +30,7 @@ double PowerDistributionPanel::GetVoltage() { int32_t status = 0; - double voltage = getPDPVoltage(&status); + double voltage = getPDPVoltage(&status, m_module); if(status) { wpi_setWPIErrorWithContext(Timeout, ""); @@ -41,7 +47,7 @@ double PowerDistributionPanel::GetTemperature() { int32_t status = 0; - double temperature = getPDPTemperature(&status); + double temperature = getPDPTemperature(&status, m_module); if(status) { wpi_setWPIErrorWithContext(Timeout, ""); @@ -65,7 +71,7 @@ PowerDistributionPanel::GetCurrent(uint8_t channel) { wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf); } - double current = getPDPChannelCurrent(channel, &status); + double current = getPDPChannelCurrent(channel, &status, m_module); if(status) { wpi_setWPIErrorWithContext(Timeout, ""); @@ -82,7 +88,7 @@ double PowerDistributionPanel::GetTotalCurrent() { int32_t status = 0; - double current = getPDPTotalCurrent(&status); + double current = getPDPTotalCurrent(&status, m_module); if(status) { wpi_setWPIErrorWithContext(Timeout, ""); @@ -99,7 +105,7 @@ double PowerDistributionPanel::GetTotalPower() { int32_t status = 0; - double power = getPDPTotalPower(&status); + double power = getPDPTotalPower(&status, m_module); if(status) { wpi_setWPIErrorWithContext(Timeout, ""); @@ -116,7 +122,7 @@ double PowerDistributionPanel::GetTotalEnergy() { int32_t status = 0; - double energy = getPDPTotalEnergy(&status); + double energy = getPDPTotalEnergy(&status, m_module); if(status) { wpi_setWPIErrorWithContext(Timeout, ""); @@ -133,7 +139,7 @@ void PowerDistributionPanel::ResetTotalEnergy() { int32_t status = 0; - resetPDPTotalEnergy(&status); + resetPDPTotalEnergy(&status, m_module); if(status) { wpi_setWPIErrorWithContext(Timeout, ""); @@ -147,7 +153,7 @@ void PowerDistributionPanel::ClearStickyFaults() { int32_t status = 0; - clearPDPStickyFaults(&status); + clearPDPStickyFaults(&status, m_module); if(status) { wpi_setWPIErrorWithContext(Timeout, ""); diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java index b265a82efc..bca3de0396 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java @@ -22,9 +22,20 @@ import edu.wpi.first.wpilibj.tables.ITable; * @author Thomas Clark */ public class PowerDistributionPanel extends SensorBase implements LiveWindowSendable { - public PowerDistributionPanel() { + + int m_module; + + public PowerDistributionPanel(int module) { + m_module = module; + checkPDPModule(m_module); + PDPJNI.initializePDP(m_module); } + public PowerDistributionPanel() { + this(0); + } + + /** * Query the input voltage of the PDP * @return The voltage of the PDP in volts @@ -33,7 +44,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend ByteBuffer status = ByteBuffer.allocateDirect(4); status.order(ByteOrder.LITTLE_ENDIAN); - double voltage = PDPJNI.getPDPVoltage(status.asIntBuffer()); + double voltage = PDPJNI.getPDPVoltage(status.asIntBuffer(), m_module); return voltage; } @@ -46,7 +57,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend ByteBuffer status = ByteBuffer.allocateDirect(4); status.order(ByteOrder.LITTLE_ENDIAN); - double temperature = PDPJNI.getPDPTemperature(status.asIntBuffer()); + double temperature = PDPJNI.getPDPTemperature(status.asIntBuffer(), m_module); return temperature; } @@ -59,7 +70,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend ByteBuffer status = ByteBuffer.allocateDirect(4); status.order(ByteOrder.LITTLE_ENDIAN); - double current = PDPJNI.getPDPChannelCurrent((byte)channel, status.asIntBuffer()); + double current = PDPJNI.getPDPChannelCurrent((byte)channel, status.asIntBuffer(), m_module); checkPDPChannel(channel); @@ -74,7 +85,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend ByteBuffer status = ByteBuffer.allocateDirect(4); status.order(ByteOrder.LITTLE_ENDIAN); - double current = PDPJNI.getPDPTotalCurrent(status.asIntBuffer()); + double current = PDPJNI.getPDPTotalCurrent(status.asIntBuffer(), m_module); return current; } @@ -87,7 +98,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend ByteBuffer status = ByteBuffer.allocateDirect(4); status.order(ByteOrder.LITTLE_ENDIAN); - double power = PDPJNI.getPDPTotalPower(status.asIntBuffer()); + double power = PDPJNI.getPDPTotalPower(status.asIntBuffer(), m_module); return power; @@ -101,7 +112,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend ByteBuffer status = ByteBuffer.allocateDirect(4); status.order(ByteOrder.LITTLE_ENDIAN); - double energy = PDPJNI.getPDPTotalEnergy(status.asIntBuffer()); + double energy = PDPJNI.getPDPTotalEnergy(status.asIntBuffer(), m_module); return energy; } @@ -113,7 +124,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend ByteBuffer status = ByteBuffer.allocateDirect(4); status.order(ByteOrder.LITTLE_ENDIAN); - PDPJNI.resetPDPTotalEnergy(status.asIntBuffer()); + PDPJNI.resetPDPTotalEnergy(status.asIntBuffer(), m_module); } /** @@ -123,7 +134,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend ByteBuffer status = ByteBuffer.allocateDirect(4); status.order(ByteOrder.LITTLE_ENDIAN); - PDPJNI.clearPDPStickyFaults(status.asIntBuffer()); + PDPJNI.clearPDPStickyFaults(status.asIntBuffer(), m_module); } public String getSmartDashboardType() { diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SensorBase.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SensorBase.java index b0765612c8..5dc40fff19 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SensorBase.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SensorBase.java @@ -55,7 +55,11 @@ public abstract class SensorBase { // TODO: Refactor * Number of power distribution channels */ public static final int kPDPChannels = 16; - + /** + * Number of power distribution modules + */ + public static final int kPDPModules = 63; + private static int m_defaultSolenoidModule = 0; /** @@ -174,6 +178,18 @@ public abstract class SensorBase { // TODO: Refactor } } + /** + * Verify that the PDP module number is within limits. + * module numbers are 0-based. + * + * @param channel The module number to check. + */ + protected static void checkPDPModule(final int module) { + if (module < 0 || module > kPDPModules) { + throw new IndexOutOfBoundsException("Requested PDP module number is out of range."); + } + } + /** * Get the number of the default solenoid module. * diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java index 525ba68840..f595e0a086 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java @@ -4,12 +4,13 @@ import java.nio.ByteBuffer; import java.nio.IntBuffer; public class PDPJNI extends JNIWrapper { - public static native double getPDPTemperature(IntBuffer status); - public static native double getPDPVoltage(IntBuffer status); - public static native double getPDPChannelCurrent(byte channel, IntBuffer status); - public static native double getPDPTotalCurrent(IntBuffer status); - public static native double getPDPTotalPower(IntBuffer status); - public static native double getPDPTotalEnergy(IntBuffer status); - public static native void resetPDPTotalEnergy(IntBuffer status); - public static native void clearPDPStickyFaults(IntBuffer status); + public static native void initializePDP(int module); + public static native double getPDPTemperature(IntBuffer status, int module); + public static native double getPDPVoltage(IntBuffer status, int module); + public static native double getPDPChannelCurrent(byte channel, IntBuffer status, int module); + public static native double getPDPTotalCurrent(IntBuffer status, int module); + public static native double getPDPTotalPower(IntBuffer status, int module); + public static native double getPDPTotalEnergy(IntBuffer status, int module); + public static native void resetPDPTotalEnergy(IntBuffer status, int module); + public static native void clearPDPStickyFaults(IntBuffer status, int module); } \ No newline at end of file diff --git a/wpilibj/wpilibJavaJNI/lib/PDPJNI.cpp b/wpilibj/wpilibJavaJNI/lib/PDPJNI.cpp index 8e2096eb64..47525aad45 100644 --- a/wpilibj/wpilibJavaJNI/lib/PDPJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/PDPJNI.cpp @@ -1,17 +1,28 @@ #include "edu_wpi_first_wpilibj_hal_PDPJNI.h" #include "HAL/PDP.hpp" +/* + * Class: edu_wpi_first_wpilibj_hal_PDPJNI + * Method: getPDPTemperature + * Signature: (Ljava/nio/IntBuffer;)D + */ +JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_initializePDP + (JNIEnv *, jclass, jint module) +{ + initializePDP(module); +} + /* * Class: edu_wpi_first_wpilibj_hal_PDPJNI * Method: getPDPTemperature * Signature: (Ljava/nio/IntBuffer;)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTemperature - (JNIEnv *env, jclass, jobject status) + (JNIEnv *env, jclass, jobject status, jint module) { jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - return getPDPTemperature(status_ptr); + return getPDPTemperature(status_ptr, module); } /* @@ -20,11 +31,11 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTemperatur * Signature: (Ljava/nio/IntBuffer;)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPVoltage - (JNIEnv *env, jclass, jobject status) + (JNIEnv *env, jclass, jobject status, jint module) { jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - return getPDPVoltage(status_ptr); + return getPDPVoltage(status_ptr, module); } /* @@ -33,11 +44,11 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPVoltage * Signature: (BLjava/nio/IntBuffer;)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPChannelCurrent - (JNIEnv *env, jclass, jbyte channel, jobject status) + (JNIEnv *env, jclass, jbyte channel, jobject status, jint module) { jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - return getPDPChannelCurrent(channel, status_ptr); + return getPDPChannelCurrent(channel, status_ptr, module); } /* @@ -46,11 +57,11 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPChannelCur * Signature: (BLjava/nio/IntBuffer;)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalCurrent - (JNIEnv *env, jclass, jobject status) + (JNIEnv *env, jclass, jobject status, jint module) { jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - return getPDPTotalCurrent(status_ptr); + return getPDPTotalCurrent(status_ptr, module); } /* @@ -59,11 +70,11 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalCurre * Signature: (BLjava/nio/IntBuffer;)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalPower - (JNIEnv *env, jclass, jobject status) + (JNIEnv *env, jclass, jobject status, jint module) { jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - return getPDPTotalPower(status_ptr); + return getPDPTotalPower(status_ptr, module); } /* @@ -72,11 +83,11 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalPower * Signature: (BLjava/nio/IntBuffer;)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalEnergy - (JNIEnv *env, jclass, jobject status) + (JNIEnv *env, jclass, jobject status, jint module) { jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - return getPDPTotalEnergy(status_ptr); + return getPDPTotalEnergy(status_ptr, module); } @@ -86,11 +97,11 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalEnerg * Signature: (BLjava/nio/IntBuffer;)D */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_resetPDPTotalEnergy - (JNIEnv *env, jclass, jobject status) + (JNIEnv *env, jclass, jobject status, jint module) { jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - resetPDPTotalEnergy(status_ptr); + resetPDPTotalEnergy(status_ptr, module); } /* @@ -99,9 +110,9 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_resetPDPTotalEnergy * Signature: (BLjava/nio/IntBuffer;)D */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_clearPDPStickyFaults - (JNIEnv *env, jclass, jobject status) + (JNIEnv *env, jclass, jobject status, jint module) { jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - clearPDPStickyFaults(status_ptr); + clearPDPStickyFaults(status_ptr, module); } \ No newline at end of file