mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
NetworkTables updates for beta
This commit does a few things. First, we publish ntcore as a maven artifact so the plugins can build with new networktables, and java programs will depend on the correct version when compiled. We also revert the changes to OutlineViewer for now. I got an exception when attempting to start a server with the new network tables in OutlineViewer on Windows, I will create a bug for this. Also, since we don't have the binaries integrating properly yet and won't for the first beta, we need to be using the platform agnostic version anyway. Change-Id: I9960f25bc3f2b30bb59fce665eb914ef5e661c9c
This commit is contained in:
@@ -69,7 +69,7 @@
|
||||
<artifactItem>
|
||||
<groupId>edu.wpi.first.wpilib.networktables.java</groupId>
|
||||
<artifactId>NetworkTables</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<destFileName>NetworkTables.jar</destFileName>
|
||||
<outputDirectory>${java-zip}/lib</outputDirectory>
|
||||
|
||||
@@ -34,6 +34,6 @@ sourceSets {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(":networktables:ntcore")
|
||||
compile project(":networktables:java")
|
||||
compile 'uk.gov.nationalarchives.thirdparty.netbeans:org-netbeans-swing-outline:7.2'
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
package edu.wpi.first.tableviewer;
|
||||
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTableProvider;
|
||||
import edu.wpi.first.wpilibj.networktables2.NetworkTableNode;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import org.netbeans.swing.outline.Outline;
|
||||
@@ -29,13 +30,13 @@ public abstract class AbstractTreeNode extends DefaultMutableTreeNode {
|
||||
AbstractTreeNode.outline = outline;
|
||||
}
|
||||
|
||||
public AbstractTreeNode(String key, TableEntryData data) {
|
||||
public AbstractTreeNode(NetworkTableNode node, String key, TableEntryData data) {
|
||||
super(data);
|
||||
this.data = data;
|
||||
if (treeModel != null) {
|
||||
treeModel.reload(this);
|
||||
}
|
||||
table = NetworkTable.getTable(key);
|
||||
table = new NetworkTableProvider(node).getTable(key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@ import edu.wpi.first.tableviewer.dialog.AddArrayDialog;
|
||||
import edu.wpi.first.tableviewer.dialog.AddBooleanDialog;
|
||||
import edu.wpi.first.tableviewer.dialog.AddNumberDialog;
|
||||
import edu.wpi.first.tableviewer.dialog.AddStringDialog;
|
||||
import edu.wpi.first.wpilibj.networktables2.NetworkTableNode;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JMenuItem;
|
||||
@@ -24,8 +25,8 @@ public class BranchNode extends AbstractTreeNode {
|
||||
|
||||
private final String name;
|
||||
|
||||
public BranchNode(String key, String name) {
|
||||
super(key, new TableEntryData(name, null));
|
||||
public BranchNode(NetworkTableNode node, String key, String name) {
|
||||
super(node, key, new TableEntryData(name, null));
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
*/
|
||||
package edu.wpi.first.tableviewer;
|
||||
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTableProvider;
|
||||
import edu.wpi.first.wpilibj.networktables2.NetworkTableNode;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
|
||||
/**
|
||||
@@ -15,9 +16,9 @@ import javax.swing.event.TableModelEvent;
|
||||
*/
|
||||
public class LeafNode extends AbstractTreeNode {
|
||||
|
||||
public LeafNode(String key, TableEntryData data) {
|
||||
super(key, data);
|
||||
table = NetworkTable.getTable(key.substring(0, key.lastIndexOf('/')));
|
||||
public LeafNode(NetworkTableNode node, String key, TableEntryData data) {
|
||||
super(node, key, data);
|
||||
table = new NetworkTableProvider(node).getTable(key.substring(0, key.lastIndexOf('/')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ package edu.wpi.first.tableviewer;
|
||||
|
||||
import edu.wpi.first.tableviewer.TableEntryData.EntryType;
|
||||
import edu.wpi.first.tableviewer.dialog.AbstractAddDialog;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
import edu.wpi.first.wpilibj.networktables2.NetworkTableNode;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.tables.ITableListener;
|
||||
import java.awt.BorderLayout;
|
||||
@@ -29,16 +29,18 @@ public class OutlineFrame extends JFrame implements ITableListener {
|
||||
|
||||
private final Outline outline;
|
||||
private final BranchNode rootBranch;
|
||||
private final NetworkTableNode node;
|
||||
private final boolean showMetadata;
|
||||
private final Preferences prefs = Preferences.userNodeForPackage(getClass());
|
||||
|
||||
public OutlineFrame(String title, boolean showMetadata) {
|
||||
public OutlineFrame(String title, NetworkTableNode node, boolean showMetadata) {
|
||||
this.node = node;
|
||||
this.showMetadata = showMetadata;
|
||||
|
||||
setTitle(title);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
|
||||
rootBranch = new BranchNode("", "Root");
|
||||
rootBranch = new BranchNode(node, "", "Root");
|
||||
DefaultTreeModel outlineTreeModel = new DefaultTreeModel(rootBranch);
|
||||
|
||||
OutlineModel outlineModel = DefaultOutlineModel.createOutlineModel(
|
||||
@@ -97,7 +99,7 @@ public class OutlineFrame extends JFrame implements ITableListener {
|
||||
scrollPane.setViewportView(outline);
|
||||
add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
NetworkTable.getTable("").addTableListener(this, true);
|
||||
node.addTableListener(this, true);
|
||||
|
||||
}
|
||||
|
||||
@@ -123,7 +125,7 @@ public class OutlineFrame extends JFrame implements ITableListener {
|
||||
key += "/" + name;
|
||||
if (subTableNames.getLast() == name) { // leaf
|
||||
if (currentNode == null) {
|
||||
currentNode = new LeafNode(key, new TableEntryData(name, value));
|
||||
currentNode = new LeafNode(node, key, new TableEntryData(name, value));
|
||||
if (currentNode.data.isMetadata() && !showMetadata) {
|
||||
// don't show metadata directly
|
||||
// instead, show the value in the branch's "Type" field
|
||||
@@ -138,7 +140,7 @@ public class OutlineFrame extends JFrame implements ITableListener {
|
||||
}
|
||||
|
||||
} else if (currentNode == null) {
|
||||
currentNode = new BranchNode(key, name);
|
||||
currentNode = new BranchNode(node, key, name);
|
||||
parentNode.add(currentNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,12 @@
|
||||
*/
|
||||
package edu.wpi.first.tableviewer.dialog;
|
||||
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
import edu.wpi.first.wpilibj.networktables2.type.ArrayData;
|
||||
import edu.wpi.first.wpilibj.networktables2.type.BooleanArray;
|
||||
import edu.wpi.first.wpilibj.networktables2.type.NumberArray;
|
||||
import edu.wpi.first.wpilibj.networktables2.type.StringArray;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.DefaultCellEditor;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JOptionPane;
|
||||
@@ -215,78 +219,60 @@ public class AddArrayDialog extends AbstractAddDialog {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new array object containing the values in the
|
||||
* table, which will then be put into the Network Table associated
|
||||
* Creates a new {@code ArrayData} object containing the values in the
|
||||
* table, which will then be put into the {@link NetworkTable} associated
|
||||
* with this dialog.
|
||||
*
|
||||
* @param arrayType The type of array: Boolean, Number, or String.
|
||||
* @return An array object containing the data in the table, or
|
||||
* @return An {@link ArrayData} object containing the data in the table, or
|
||||
* null if an error is present in the table (such as an invalid double
|
||||
* value).
|
||||
*/
|
||||
private Object createArrayData(String arrayType) {
|
||||
int n = 0;
|
||||
for (int i = 0; i < valueTable.getRowCount(); i++) {
|
||||
Object data = valueTable.getValueAt(i, 0);
|
||||
if (data != null) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
private ArrayData createArrayData(String arrayType) {
|
||||
ArrayData ad;
|
||||
switch (arrayType) {
|
||||
case "Boolean":
|
||||
{
|
||||
boolean[] arr = new boolean[n];
|
||||
n = 0;
|
||||
for (int i = 0; i < valueTable.getRowCount(); i++) {
|
||||
Object data = valueTable.getValueAt(i, 0);
|
||||
if (data != null) {
|
||||
arr[n] = data.toString().equalsIgnoreCase("true");
|
||||
n++;
|
||||
}
|
||||
ad = new BooleanArray();
|
||||
for (int i = 0; i < valueTable.getRowCount(); i++) {
|
||||
Object data = valueTable.getValueAt(i, 0);
|
||||
if (data != null) {
|
||||
((BooleanArray) ad).add(data.toString().equalsIgnoreCase("true"));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
break;
|
||||
case "Number":
|
||||
{
|
||||
double[] arr = new double[n];
|
||||
n = 0;
|
||||
for (int i = 0; i < valueTable.getRowCount(); i++) {
|
||||
Object data = valueTable.getValueAt(i, 0);
|
||||
try {
|
||||
if (data != null) {
|
||||
arr[n] = Double.parseDouble(data.toString());
|
||||
n++;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
JOptionPane.showMessageDialog(
|
||||
this,
|
||||
"Invalid double value \"" + data + "\" in row " + (i + 1),
|
||||
"Invalid number",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return null;
|
||||
ad = new NumberArray();
|
||||
for (int i = 0; i < valueTable.getRowCount(); i++) {
|
||||
Object data = valueTable.getValueAt(i, 0);
|
||||
try {
|
||||
if (data != null) {
|
||||
Double d = Double.parseDouble(data.toString());
|
||||
((NumberArray) ad).add(d);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
JOptionPane.showMessageDialog(
|
||||
this,
|
||||
"Invalid double value \"" + data + "\" in row " + (i + 1),
|
||||
"Invalid number",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return null;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
break;
|
||||
|
||||
case "String":
|
||||
{
|
||||
String[] arr = new String[n];
|
||||
n = 0;
|
||||
for (int i = 0; i < valueTable.getRowCount(); i++) {
|
||||
Object data = valueTable.getValueAt(i, 0);
|
||||
if (data != null) {
|
||||
arr[n] = data.toString();
|
||||
n++;
|
||||
}
|
||||
ad = new StringArray();
|
||||
for (int i = 0; i < valueTable.getRowCount(); i++) {
|
||||
Object data = valueTable.getValueAt(i, 0);
|
||||
if (data != null) {
|
||||
((StringArray) ad).add(data.toString());
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(arrayType + " is not a valid array type");
|
||||
}
|
||||
return ad;
|
||||
}
|
||||
// Variables declaration - do not modify
|
||||
private javax.swing.JButton addRowButton;
|
||||
|
||||
@@ -2,8 +2,12 @@ package edu.wpi.first.tableviewer.dialog;
|
||||
|
||||
|
||||
import edu.wpi.first.tableviewer.OutlineFrame;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTablesJNI;
|
||||
import edu.wpi.first.wpilibj.networktables2.NetworkTableNode;
|
||||
import edu.wpi.first.wpilibj.networktables2.client.NetworkTableClient;
|
||||
import edu.wpi.first.wpilibj.networktables2.server.NetworkTableServer;
|
||||
import edu.wpi.first.wpilibj.networktables2.stream.IOStreamFactory;
|
||||
import edu.wpi.first.wpilibj.networktables2.stream.IOStreamProvider;
|
||||
import edu.wpi.first.wpilibj.networktables2.stream.SocketStreams;
|
||||
import java.util.prefs.Preferences;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
@@ -110,28 +114,24 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
||||
|
||||
private void startButtonPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonPressed
|
||||
try {
|
||||
NetworkTablesJNI.setLogger(new NetworkTablesJNI.LoggerFunction() {
|
||||
public void apply(int level, String file, int line, String msg) {
|
||||
System.err.println(msg);
|
||||
}
|
||||
}, 0);
|
||||
NetworkTableNode node;
|
||||
if (evt.getSource() == clientButton) { // start client
|
||||
String host = hostField.getText();
|
||||
if (host.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
NetworkTable.setIPAddress(host);
|
||||
NetworkTable.setClientMode();
|
||||
NetworkTable.initialize();
|
||||
IOStreamFactory streamFactory = SocketStreams.newStreamFactory(host, 1735);
|
||||
NetworkTableClient client = new NetworkTableClient(streamFactory);
|
||||
client.reconnect();
|
||||
node = client;
|
||||
prefs.put("host", host);
|
||||
} else { // start server
|
||||
NetworkTable.setIPAddress("");
|
||||
NetworkTable.setServerMode();
|
||||
NetworkTable.initialize();
|
||||
IOStreamProvider streamProvider = SocketStreams.newStreamProvider(1735);
|
||||
node = new NetworkTableServer(streamProvider);
|
||||
prefs.put("host", "");
|
||||
}
|
||||
prefs.putBoolean("metadata", metadataBox.isSelected());
|
||||
new OutlineFrame("Network Table Viewer", metadataBox.isSelected()).setVisible(true);
|
||||
new OutlineFrame("Network Table Viewer", node, metadataBox.isSelected()).setVisible(true);
|
||||
dispose();
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(null, e.getClass() + ": " + e.getMessage(), "Error creating table node", JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
@@ -1,33 +1,9 @@
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
group = "edu.wpi.frc.wpilib"
|
||||
version = "2.0"
|
||||
archivesBaseName = 'NetworkTables'
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
from components.java
|
||||
artifact (networktablesSource) {
|
||||
classifier = 'sources'
|
||||
}
|
||||
artifact (networktablesJavadoc) {
|
||||
classifier = 'javadoc'
|
||||
}
|
||||
|
||||
groupId 'edu.wpi.first.wpilib.networktables.java'
|
||||
artifactId 'NetworkTables'
|
||||
version '0.1.0-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
url "file://${System.properties['user.home']}/releases/maven"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
|
||||
Submodule networktables/ntcore updated: d9fa086ec0...75358e6c45
@@ -1,4 +1,5 @@
|
||||
include 'networktables:ntcore',
|
||||
'networktables:java',
|
||||
'networktables:OutlineViewer',
|
||||
'hal',
|
||||
'wpilibj',
|
||||
|
||||
Reference in New Issue
Block a user