Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wpilibj] PowerDistribution Logger #7131

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

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 {
public class PowerDistributionFaults implements StructSerializable {
/** The faults bitfield the object was constructed with */
public final int bitfield;

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

Expand Down Expand Up @@ -136,6 +144,7 @@ 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 @@ -164,4 +173,69 @@ public PowerDistributionFaults(int faults) {
CanWarning = (faults & 0x2000000) != 0;
HardwareFault = (faults & 0x4000000) != 0;
}

public static final PowerDistributionFaultsStruct struct = new PowerDistributionFaultsStruct();

public 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,12 +4,20 @@

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 {
public class PowerDistributionStickyFaults implements StructSerializable {
/** The faults bitfield the object was constructed with */
public final int bitfield;

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

Expand Down Expand Up @@ -145,6 +153,7 @@ 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 @@ -176,4 +185,70 @@ public PowerDistributionStickyFaults(int faults) {
FirmwareFault = (faults & 0x10000000) != 0;
HasReset = (faults & 0x20000000) != 0;
}

public static final PowerDistributionStickyFaultsStruct struct = new PowerDistributionStickyFaultsStruct();

public 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

package edu.wpi.first.hal;

import java.nio.ByteBuffer;

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

/** Power distribution version. */
@SuppressWarnings("MemberName")
public class PowerDistributionVersion {
public class PowerDistributionVersion implements StructSerializable {
/** Firmware major version number. */
public final int firmwareMajor;

Expand Down Expand Up @@ -49,4 +54,56 @@ public PowerDistributionVersion(
this.hardwareMajor = hardwareMajor;
this.uniqueId = uniqueId;
}

public static final PowerDistributionVersionStruct struct = new PowerDistributionVersionStruct();

public static final class PowerDistributionVersionStruct implements Struct<PowerDistributionVersion> {
@Override
public Class<PowerDistributionVersion> getTypeClass() {
return PowerDistributionVersion.class;
}

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

@Override
public String getSchema() {
return "int8 firmwareMajor; "
+ "int8 firmwareMinor; "
+ "int8 firmwareFix; "
+ "int8 hardwareMinor; "
+ "int8 hardwareMajor; "
+ "int32 uniqueId;";
}

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

@Override
public void pack(ByteBuffer bb, PowerDistributionVersion value) {
bb.put((byte) value.firmwareMajor);
bb.put((byte) value.firmwareMinor);
bb.put((byte) value.firmwareFix);
bb.put((byte) value.hardwareMinor);
bb.put((byte) value.hardwareMajor);
bb.putLong(value.uniqueId);
}

@Override
public PowerDistributionVersion unpack(ByteBuffer bb) {
return new PowerDistributionVersion(
bb.get(),
bb.get(),
bb.get(),
bb.get(),
bb.get(),
bb.getInt()
);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,26 @@ public PowerDistributionStickyFaults getStickyFaults() {
return PowerDistributionJNI.getStickyFaults(m_handle);
}

/**
* Used internally to get the handle for the PDP.
*
* @return The handle for the PDP
*/
public int getHandle() {
return m_handle;
}

/**
* Creates a new {@link PowerDistributionLogger} for this instance.
*
* @param logPath The path to log the data to
* @param datalogOnly If true, only log to the datalog
* @return The new {@link PowerDistributionLogger}
*/
public PowerDistributionLogger createLogger(String logPath, boolean datalogOnly) {
return new PowerDistributionLogger(this, logPath, datalogOnly);
}

@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("PowerDistribution");
Expand Down
Loading
Loading