Skip to content

Commit

Permalink
Revert "wip"
Browse files Browse the repository at this point in the history
This reverts commit 3c21556.
  • Loading branch information
oh-yes-0-fps committed Sep 16, 2024
1 parent c6eb4d4 commit 8c1f052
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 249 deletions.
76 changes: 1 addition & 75 deletions hal/src/main/java/edu/wpi/first/hal/PowerDistributionFaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@

package edu.wpi.first.hal;

import java.nio.ByteBuffer;

import edu.wpi.first.util.struct.Struct;
import edu.wpi.first.util.struct.StructSerializable;

/**
* Faults for a PowerDistribution device. These faults are only active while the condition is
* active.
*/
@SuppressWarnings("MemberName")
public class PowerDistributionFaults implements StructSerializable {
/** The faults bitfield the object was constructed with */
public final int bitfield;

public class PowerDistributionFaults {
/** Breaker fault on channel 0. */
public final boolean Channel0BreakerFault;

Expand Down Expand Up @@ -144,7 +136,6 @@ public final boolean getBreakerFault(int channel) {
* @param faults faults
*/
public PowerDistributionFaults(int faults) {
bitfield = faults;
Channel0BreakerFault = (faults & 0x1) != 0;
Channel1BreakerFault = (faults & 0x2) != 0;
Channel2BreakerFault = (faults & 0x4) != 0;
Expand Down Expand Up @@ -173,69 +164,4 @@ public PowerDistributionFaults(int faults) {
CanWarning = (faults & 0x2000000) != 0;
HardwareFault = (faults & 0x4000000) != 0;
}

public static final PowerDistributionFaultsStruct struct = new PowerDistributionFaultsStruct();

protected static final class PowerDistributionFaultsStruct implements Struct<PowerDistributionFaults> {
@Override
public Class<PowerDistributionFaults> getTypeClass() {
return PowerDistributionFaults.class;
}

@Override
public int getSize() {
return kSizeInt32;
}

@Override
public String getSchema() {
return "bool channel0BreakerFault:1; "
+ "bool channel1BreakerFault:1; "
+ "bool channel2BreakerFault:1; "
+ "bool channel3BreakerFault:1; "
+ "bool channel4BreakerFault:1; "
+ "bool channel5BreakerFault:1; "
+ "bool channel6BreakerFault:1; "
+ "bool channel7BreakerFault:1; "
+ "bool channel8BreakerFault:1; "
+ "bool channel9BreakerFault:1; "
+ "bool channel10BreakerFault:1; "
+ "bool channel11BreakerFault:1; "
+ "bool channel12BreakerFault:1; "
+ "bool channel13BreakerFault:1; "
+ "bool channel14BreakerFault:1; "
+ "bool channel15BreakerFault:1; "
+ "bool channel16BreakerFault:1; "
+ "bool channel17BreakerFault:1; "
+ "bool channel18BreakerFault:1; "
+ "bool channel19BreakerFault:1; "
+ "bool channel20BreakerFault:1; "
+ "bool channel21BreakerFault:1; "
+ "bool channel22BreakerFault:1; "
+ "bool channel23BreakerFault:1; "
+ "bool brownout:1; "
+ "bool canWarning:1; "
+ "bool hardwareFault:1;";
}

@Override
public String getTypeName() {
return "PowerDistributionFaults";
}

@Override
public void pack(ByteBuffer bb, PowerDistributionFaults value) {
bb.putInt(value.bitfield);
}

public void pack(ByteBuffer bb, int value) {
bb.putInt(value);
}

@Override
public PowerDistributionFaults unpack(ByteBuffer bb) {
int packed = bb.getInt();
return new PowerDistributionFaults(packed);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@

package edu.wpi.first.hal;

import java.nio.ByteBuffer;

import edu.wpi.first.util.struct.Struct;
import edu.wpi.first.util.struct.StructSerializable;

/**
* Sticky faults for a PowerDistribution device. These faults will remain active until they are
* reset by the user.
*/
@SuppressWarnings("MemberName")
public class PowerDistributionStickyFaults implements StructSerializable {
/** The faults bitfield the object was constructed with */
public final int bitfield;

public class PowerDistributionStickyFaults {
/** Breaker fault on channel 0. */
public final boolean Channel0BreakerFault;

Expand Down Expand Up @@ -153,7 +145,6 @@ public final boolean getBreakerFault(int channel) {
* @param faults faults
*/
public PowerDistributionStickyFaults(int faults) {
bitfield = faults;
Channel0BreakerFault = (faults & 0x1) != 0;
Channel1BreakerFault = (faults & 0x2) != 0;
Channel2BreakerFault = (faults & 0x4) != 0;
Expand Down Expand Up @@ -185,68 +176,4 @@ public PowerDistributionStickyFaults(int faults) {
FirmwareFault = (faults & 0x10000000) != 0;
HasReset = (faults & 0x20000000) != 0;
}

protected static final class PowerDistributionStickyFaultsStruct implements Struct<PowerDistributionStickyFaults> {
@Override
public Class<PowerDistributionStickyFaults> getTypeClass() {
return PowerDistributionStickyFaults.class;
}

@Override
public int getSize() {
return 4; //doing bitfields on a u32
}

@Override
public String getSchema() {
return "bool channel0BreakerFault:1; "
+ "bool channel1BreakerFault:1; "
+ "bool channel2BreakerFault:1; "
+ "bool channel3BreakerFault:1; "
+ "bool channel4BreakerFault:1; "
+ "bool channel5BreakerFault:1; "
+ "bool channel6BreakerFault:1; "
+ "bool channel7BreakerFault:1; "
+ "bool channel8BreakerFault:1; "
+ "bool channel9BreakerFault:1; "
+ "bool channel10BreakerFault:1; "
+ "bool channel11BreakerFault:1; "
+ "bool channel12BreakerFault:1; "
+ "bool channel13BreakerFault:1; "
+ "bool channel14BreakerFault:1; "
+ "bool channel15BreakerFault:1; "
+ "bool channel16BreakerFault:1; "
+ "bool channel17BreakerFault:1; "
+ "bool channel18BreakerFault:1; "
+ "bool channel19BreakerFault:1; "
+ "bool channel20BreakerFault:1; "
+ "bool channel21BreakerFault:1; "
+ "bool channel22BreakerFault:1; "
+ "bool channel23BreakerFault:1; "
+ "bool brownout:1; "
+ "bool canWarning:1; "
+ "bool canBusOff:1; "
+ "bool hasReset:1;";
}

@Override
public String getTypeName() {
return "PowerDistributionStickyFaults";
}

@Override
public void pack(ByteBuffer bb, PowerDistributionStickyFaults value) {
bb.putInt(value.bitfield);
}

public void pack(ByteBuffer bb, int value) {
bb.putInt(value);
}

@Override
public PowerDistributionStickyFaults unpack(ByteBuffer bb) {
int packed = bb.getInt();
return new PowerDistributionStickyFaults(packed);
}
}
}
100 changes: 0 additions & 100 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/PowerDistribution.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package edu.wpi.first.wpilibj;

import java.nio.ByteBuffer;

import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.PowerDistributionFaults;
Expand All @@ -15,8 +13,6 @@
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.util.struct.Struct;
import edu.wpi.first.util.struct.StructSerializable;

/**
* Class for getting voltage, current, temperature, power and energy from the CTRE Power
Expand All @@ -25,7 +21,6 @@
public class PowerDistribution implements Sendable, AutoCloseable {
private final int m_handle;
private final int m_module;
private final PowerDistributionStats m_stats;

/** Default module number. */
public static final int kDefaultModule = PowerDistributionJNI.DEFAULT_MODULE;
Expand Down Expand Up @@ -55,7 +50,6 @@ public enum ModuleType {
public PowerDistribution(int module, ModuleType moduleType) {
m_handle = PowerDistributionJNI.initialize(module, moduleType.value);
m_module = PowerDistributionJNI.getModuleNumber(m_handle);
m_stats = new PowerDistributionStats(this);

HAL.report(tResourceType.kResourceType_PDP, m_module + 1);
SendableRegistry.addLW(this, "PowerDistribution", m_module);
Expand All @@ -70,7 +64,6 @@ public PowerDistribution(int module, ModuleType moduleType) {
public PowerDistribution() {
m_handle = PowerDistributionJNI.initialize(kDefaultModule, PowerDistributionJNI.AUTOMATIC_TYPE);
m_module = PowerDistributionJNI.getModuleNumber(m_handle);
m_stats = new PowerDistributionStats(this);

HAL.report(tResourceType.kResourceType_PDP, m_module + 1);
SendableRegistry.addLW(this, "PowerDistribution", m_module);
Expand Down Expand Up @@ -266,97 +259,4 @@ public void initSendable(SendableBuilder builder) {
() -> PowerDistributionJNI.getSwitchableChannelNoError(m_handle),
value -> PowerDistributionJNI.setSwitchableChannel(m_handle, value));
}

protected static final class PowerDistributionStats implements StructSerializable {
public int faults = 0;
public int stickyFaults = 0;
public double voltage = 0.0;
public double totalCurrent = 0.0;
public boolean switchableChannel = false;
public double temperature = 0.0;
public double[] currents;

public PowerDistributionStats(final PowerDistribution pd) {
currents = new double[pd.getNumChannels()];
update(pd);
}

public void update(final PowerDistribution pd) {
faults = PowerDistributionJNI.getFaultsNative(pd.m_handle);
stickyFaults = PowerDistributionJNI.getStickyFaultsNative(pd.m_handle);
voltage = pd.getVoltage();
totalCurrent = pd.getTotalCurrent();
switchableChannel = pd.getSwitchableChannel();
temperature = pd.getTemperature();
PowerDistributionJNI.getAllCurrents(pd.m_handle, currents);
}

public final static PDDataStruct struct = new PDDataStruct();
}

protected static final class PDDataStruct implements Struct<PowerDistributionStats> {
private static final int kSize = 4 + 4 + 8 + 8 + 1 + 8 + (8 * 24);

@Override
public Class<PowerDistributionStats> getTypeClass() {
return PowerDistributionStats.class;
}

@Override
public int getSize() {
return kSize;
}

@Override
public String getSchema() {
return "PowerDistributionFaults faults; "
+ "PowerDistributionStickyFaults stickyFaults; "
+ "double voltage; "
+ "double totalCurrent; "
+ "bool switchableChannel; "
+ "double temperature;"
+ "double currents[24];";
}

@Override
public String getTypeName() {
return "PDData";
}

@Override
public void pack(ByteBuffer bb, PowerDistributionStats value) {
bb.putInt(value.faults);
bb.putInt(value.stickyFaults);
bb.putDouble(value.voltage);
bb.putDouble(value.totalCurrent);
bb.put((byte) (value.switchableChannel ? 1 : 0));
bb.putDouble(value.temperature);
for (int i = 0; i < value.currents.length; i++) {
bb.putDouble(value.currents[i]);
}
}

@Override
public PowerDistributionStats unpack(ByteBuffer bb) {
PowerDistributionStats data = new PowerDistributionStats(null);
data.faults = bb.getInt();
data.stickyFaults = bb.getInt();
data.voltage = bb.getDouble();
data.totalCurrent = bb.getDouble();
data.switchableChannel = bb.get() == 1;
data.temperature = bb.getDouble();
for (int i = 0; i < 24; i++) {
data.currents[i] = bb.getDouble();
}
return data;
}

@Override
public Struct<?>[] getNested() {
return new Struct<?>[] {
new PowerDistributionFaultsStruct(),
new PowerDistributionStickyFaultsStruct()
};
}
}
}

0 comments on commit 8c1f052

Please sign in to comment.