Skip to content

Commit 7d6aabe

Browse files
committed
Merge pull request #340 from ThomasJClark/nt
Remove network protocol setting
2 parents 811346f + 628d37f commit 7d6aabe

File tree

5 files changed

+24
-32
lines changed

5 files changed

+24
-32
lines changed

core/src/main/java/edu/wpi/grip/core/Pipeline.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ public synchronized void removeStep(Step step) {
169169
for (OutputSocket<?> socket : step.getOutputSockets()) {
170170
socket.setPreviewed(false);
171171
}
172-
this.eventBus.post(new StepRemovedEvent(step));
173172
this.eventBus.unregister(step);
173+
this.eventBus.post(new StepRemovedEvent(step));
174174
}
175175

176176
public synchronized void moveStep(Step step, int delta) {

core/src/main/java/edu/wpi/grip/core/operations/networktables/NTManager.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import com.google.inject.Singleton;
55
import edu.wpi.first.wpilibj.networktables.NetworkTable;
66
import edu.wpi.first.wpilibj.networktables.NetworkTablesJNI;
7+
import edu.wpi.grip.core.Pipeline;
78
import edu.wpi.grip.core.events.ProjectSettingsChangedEvent;
9+
import edu.wpi.grip.core.events.StepRemovedEvent;
810
import edu.wpi.grip.core.settings.ProjectSettings;
911

1012
import javax.inject.Inject;
@@ -37,6 +39,8 @@ public class NTManager {
3739
put(6, Level.FINEST);
3840
}};
3941

42+
@Inject Pipeline pipeline;
43+
4044
@Inject
4145
public NTManager(Logger logger) {
4246
// We may have another instance of this method lying around
@@ -51,18 +55,26 @@ public NTManager(Logger logger) {
5155
NetworkTable.setClientMode();
5256
}
5357

54-
5558
/**
5659
* Change the server address according to the project setting.
5760
*/
5861
@Subscribe
5962
public void updateSettings(ProjectSettingsChangedEvent event) {
6063
final ProjectSettings projectSettings = event.getProjectSettings();
6164

62-
NetworkTable.shutdown();
63-
if (projectSettings.getNetworkProtocol() == ProjectSettings.NetworkProtocol.NETWORK_TABLES) {
65+
synchronized (NetworkTable.class) {
66+
NetworkTable.shutdown();
6467
NetworkTable.setIPAddress(projectSettings.computePublishAddress());
65-
NetworkTable.initialize();
68+
}
69+
}
70+
71+
/**
72+
* If there are no NTPublishOperation steps, we can shut down NetworkTables
73+
*/
74+
@Subscribe
75+
public void disableNetworkTables(StepRemovedEvent event) {
76+
if (!pipeline.getSteps().stream().anyMatch(step -> step.getOperation() instanceof NTPublishOperation)) {
77+
NetworkTable.shutdown();
6678
}
6779
}
6880
}

core/src/main/java/edu/wpi/grip/core/operations/networktables/NTPublishOperation.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323
*/
2424
public class NTPublishOperation<T extends NTPublishable> implements Operation {
2525

26-
private final NetworkTable table;
2726
private final Class<T> type;
2827
private final List<Method> ntValueMethods = new ArrayList<>();
2928

3029
public NTPublishOperation(Class<T> type) {
31-
this.table = NetworkTable.getTable("GRIP");
3230
this.type = checkNotNull(type, "Type was null");
3331

3432
// Any accessor method with an @NTValue annotation can be published to NetworkTables.
@@ -99,7 +97,10 @@ public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs) {
9997

10098
// Get a subtable to put the values in. Each NTPublishable has multiple properties that are published (such as
10199
// x, y, width, height, etc...), so they're grouped together in a subtable.
102-
final ITable subtable = table.getSubTable(subtableName);
100+
final ITable subtable;
101+
synchronized (NetworkTable.class) {
102+
subtable = NetworkTable.getTable("GRIP").getSubTable(subtableName);
103+
}
103104

104105
// For each NTValue method in the object being published, put it in the table if the the corresponding
105106
// checkbox is selected.

core/src/main/java/edu/wpi/grip/core/settings/ProjectSettings.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@
1212
*/
1313
public class ProjectSettings implements Cloneable {
1414

15-
/**
16-
* What protocol to use to publish values. Only NetworkTables is supported right now, but in the future we may
17-
* make the publish operations work with other protocols like ROS.
18-
*/
19-
public enum NetworkProtocol {
20-
NETWORK_TABLES,
21-
NONE
22-
}
23-
24-
@Setting(label = "Network Protocol", description = "The protocol to use to publish results")
25-
private NetworkProtocol networkProtocol = NetworkProtocol.NONE;
26-
2715
@Setting(label = "FRC Team Number", description = "The team number, if used for FRC")
2816
private int teamNumber = 0;
2917

@@ -36,14 +24,6 @@ public enum NetworkProtocol {
3624
"not specified, the hostname is derived from the team number.")
3725
private String deployAddress = "";
3826

39-
public void setNetworkProtocol(NetworkProtocol networkProtocol) {
40-
this.networkProtocol = checkNotNull(networkProtocol, "Network protocol cannot be null");
41-
}
42-
43-
public NetworkProtocol getNetworkProtocol() {
44-
return networkProtocol;
45-
}
46-
4727
public void setTeamNumber(int teamNumber) {
4828
checkArgument(teamNumber >= 0, "Team number cannot be negative");
4929
this.teamNumber = teamNumber;
@@ -94,7 +74,6 @@ private String computeFRCAddress(String address) {
9474
@Override
9575
public String toString() {
9676
return MoreObjects.toStringHelper(this)
97-
.add("networkProtocol", networkProtocol)
9877
.add("publishAddress", publishAddress)
9978
.add("deployAddress", deployAddress)
10079
.add("teamNumber", teamNumber)

core/src/test/java/edu/wpi/grip/core/serialization/ProjectTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ public void testSerializePipelineWithSource() throws Exception {
235235
public void testSerializedProjectSettings() {
236236
ProjectSettings projectSettings = new ProjectSettings();
237237
projectSettings.setTeamNumber(190);
238-
projectSettings.setNetworkProtocol(ProjectSettings.NetworkProtocol.NETWORK_TABLES);
238+
projectSettings.setDeployAddress("roborio-191-frc.local");
239239
eventBus.post(new ProjectSettingsChangedEvent(projectSettings));
240240

241241
serializeAndDeserialize();
242242

243243
assertEquals("Team number was not serialized/deserialized",
244244
190, pipeline.getProjectSettings().getTeamNumber());
245-
assertEquals("Network protocol was not serialized/deserialized",
246-
ProjectSettings.NetworkProtocol.NETWORK_TABLES, pipeline.getProjectSettings().getNetworkProtocol());
245+
assertEquals("Deploy address was not serialized/deserialized",
246+
"roborio-191-frc.local", pipeline.getProjectSettings().getDeployAddress());
247247
}
248248
}

0 commit comments

Comments
 (0)