NT4Server
A NetworkTables 4 server that publishes values to dashboards such as AdvantageScope, Glass and Shuffleboard.
Publish a topic with publish, publishStruct or publishStructArray, which return its id, and then set values on it with the set* methods. A client that connects and subscribes is told about the topics it asked for and is sent their current values, and then every change after that.
val server = NT4Server()
server.start()
val voltage = server.publish("/Robot/Battery", NT4Type.DOUBLE)
server.setDouble(voltage, 12.4)This is a publish-only server. It ignores publish, unpublish and setproperties messages, and values clients try to publish, so clients can read but not write. It sends every change to a subscriber, whatever the subscription's periodic and all options say, and it has no meta topics such as $clients. It answers the clock-synchronization messages that clients use to convert its timestamps.
Every timestamp is in microseconds since origin, as measured by timeSource. That is also the time base that clients synchronize to, so a log writer that stamps values with the same source and origin agrees with what dashboards see.
A client that can't keep up is disconnected, so it can reconnect and catch up, rather than making the robot wait or run out of memory.
All methods are safe to call from multiple threads, and the set* methods never block on the network.
Parameters
The port to listen on. The standard NetworkTables 4 port is DEFAULT_PORT, and 0 picks a free one, which boundPort reports after start.
The address to listen on. The default is every network interface.
The clock that timestamps are measured on. A server created on its own can use the default. To line it up with a dev.nextftc.telemetry.wpilog.WPILogWriter, give them the same source and the same origin.
The moment timestamp zero refers to, a mark from timeSource. The default is the moment the server is created. Share one origin between sinks that should agree on every timestamp.
Adds Ktor routes to the server, for pages or downloads on the same port. They are installed after the server's own, so they can't replace / or /nt/.... It runs each time start is called.
Throws
if origin isn't from timeSource, or is in the future
Constructors
Properties
Functions
Publishes a topic of type. See the overload that takes a type string.
Publishes a topic and returns its id, or returns the id of the topic with this name if it is already published.
Publishes a topic that holds single values of schema, and returns its id.
Publishes a topic that holds arrays of schema values, and returns its id. Otherwise the same as publishStruct.
Sets the value of the boolean topic id.
Sets the value of the boolean[] topic id.
Sets the value of the double[] topic id.
Sets the value of the float[] topic id.
Sets the value of the int topic id.
Sets the value of the int[] topic id.
Sets the value of the string[] topic id.
Sets the value of a topic published with publishStruct, packing value with schema.
Sets the value of a topic published with publishStructArray, packing values back to back with schema.