View Single Post
  #3   Spotlight this post!  
Unread 14-02-2014, 11:06
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 332
fovea1959 will become famous soon enough
Re: How do I use NetworkTables' SubTables?

super straightforward: I implemented ITableListener, then called networkTableClient.addTableListener (this, true).

If you need to see connections and disconnections, implement IRemoteConnectionListener, and call networkTableClient.addTableListener(this,true).

of course, you can have different objects for your listener (so you wouldn't use this), but hopefully you'll get the gist of it.

your valueChanged() can be a little tricky: you could get back an array or just a single variable of unknown type, and you don't know ahead of time what it will be. I had a few instance operators in there to sort stuff out. For display purposes, this worked nice:

Code:
if (o instanceof Object[]) {
 for (Object o1 : (Object[]) o) {
  sb.append("\t");
  sb.append(o1.toString());
 } else {
 sb.append("\t");
 sb.append(o.toString());
}
You *could* also get the type by going back to the client.getEntryStore().getEntry(name).getType(), but I didn't need it. I did grab client.getEntryStore().getEntry(name).getSequenceN umber() so I could see if we had updates that didn't get to the client (this is from our telemetry receiver).
Reply With Quote