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

Fixed sendable logging in epilogue #7518

Closed
wants to merge 5 commits into from
Closed
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,10 +4,13 @@

package edu.wpi.first.epilogue.logging;

import edu.wpi.first.networktables.NTSendableBuilder;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.networktables.Topic;
import edu.wpi.first.util.function.BooleanConsumer;
import edu.wpi.first.util.function.FloatConsumer;
import edu.wpi.first.util.function.FloatSupplier;
import edu.wpi.first.util.sendable.SendableBuilder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.BooleanSupplier;
Expand All @@ -20,9 +23,12 @@

/** A sendable builder implementation that sends data to a {@link EpilogueBackend}. */
@SuppressWarnings("PMD.CouplingBetweenObjects") // most methods simply delegate to the backend
public class LogBackedSendableBuilder implements SendableBuilder {
public class LogBackedSendableBuilder implements NTSendableBuilder {
private static final NetworkTable m_rootTable =
NetworkTableInstance.getDefault().getTable("Robot");
private final EpilogueBackend m_backend;
private final Collection<Runnable> m_updates = new ArrayList<>();
private final NetworkTable m_networkTable;

/**
* Creates a new sendable builder that delegates writes to an underlying backend.
Expand All @@ -31,6 +37,11 @@ public class LogBackedSendableBuilder implements SendableBuilder {
*/
public LogBackedSendableBuilder(EpilogueBackend backend) {
this.m_backend = backend;
if (backend instanceof NestedBackend nb) {
m_networkTable = m_rootTable.getSubTable(nb.getPrefix());
} else {
m_networkTable = m_rootTable;
}
}

@Override
Expand Down Expand Up @@ -178,6 +189,21 @@ public void publishConstRaw(String key, String typeString, byte[] value) {
m_backend.log(key, value);
}

@Override
public void setUpdateTable(Runnable func) {
m_updates.add(func);
}

@Override
public Topic getTopic(String key) {
return getTable().getTopic(key);
}

@Override
public NetworkTable getTable() {
return m_networkTable;
}

@Override
public BackendKind getBackendKind() {
return BackendKind.kUnknown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public EpilogueBackend getNested(String path) {
return m_nestedBackends.computeIfAbsent(path, k -> new NestedBackend(k, this));
}

/**
* Gets the prefix of this nested backend.
*
* @return the prefix of this nested backend
*/
public String getPrefix() {
return m_prefix;
}

@Override
public void log(String identifier, int value) {
m_impl.log(m_prefix + identifier, value);
Expand Down
Loading