239 int64_t rtt2,
bool valid)
265 bool Is(
unsigned int kind)
const {
return (
flags & kind) != 0; }
273 return std::get_if<ConnectionInfo>(&
data);
276 return std::get_if<ConnectionInfo>(&
data);
280 return std::get_if<TopicInfo>(&
data);
285 return std::get_if<ValueEventData>(&
data);
288 return std::get_if<ValueEventData>(&
data);
292 return std::get_if<LogMessage>(&
data);
297 return std::get_if<TimeSyncEventData>(&
data);
300 return std::get_if<TimeSyncEventData>(&
data);
587 std::span<const std::string_view> types);
620 std::span<const std::string_view> types);
747 const wpi::json& value);
820 const wpi::json& properties,
882 NT_Inst inst, std::span<const std::string_view> prefixes,
962 std::span<const std::string_view> prefixes,
998 std::span<const std::string_view> prefixes,
1064 const char* listen_address,
unsigned int port3,
1065 unsigned int port4);
1117 std::span<
const std::pair<std::string_view, unsigned int>> servers);
1339 unsigned int max_level);
1376 std::span<const uint8_t> schema);
1397 std::span<const uint8_t>{
reinterpret_cast<const uint8_t*
>(schema.data()),
1479 std::span<const uint8_t> data);
1488 std::span<const uint8_t> data);
1497 std::span<const uint8_t> data);
1506 std::span<const uint8_t> data);
NetworkTables event.
Definition: ntcore_cpp.h:217
Event(NT_Listener listener, unsigned int flags, ValueEventData data)
Definition: ntcore_cpp.h:224
Event(NT_Listener listener, unsigned int flags, ConnectionInfo info)
Definition: ntcore_cpp.h:220
const LogMessage * GetLogMessage() const
Definition: ntcore_cpp.h:291
const TimeSyncEventData * GetTimeSyncEventData() const
Definition: ntcore_cpp.h:296
Event(NT_Listener listener, unsigned int flags, int64_t serverTimeOffset, int64_t rtt2, bool valid)
Definition: ntcore_cpp.h:238
TopicInfo * GetTopicInfo()
Definition: ntcore_cpp.h:282
ValueEventData * GetValueEventData()
Definition: ntcore_cpp.h:287
const ValueEventData * GetValueEventData() const
Definition: ntcore_cpp.h:284
LogMessage * GetLogMessage()
Definition: ntcore_cpp.h:294
Event(NT_Listener listener, unsigned int flags, unsigned int level, std::string_view filename, unsigned int line, std::string_view message)
Definition: ntcore_cpp.h:233
std::variant< ConnectionInfo, TopicInfo, ValueEventData, LogMessage, TimeSyncEventData > data
Event data; content depends on flags.
Definition: ntcore_cpp.h:270
bool Is(unsigned int kind) const
Test event flags.
Definition: ntcore_cpp.h:265
Event(NT_Listener listener, unsigned int flags, NT_Topic topic, NT_Handle subentry, Value value)
Definition: ntcore_cpp.h:228
unsigned int flags
Event flags (NT_EventFlags).
Definition: ntcore_cpp.h:257
const ConnectionInfo * GetConnectionInfo() const
Definition: ntcore_cpp.h:272
ConnectionInfo * GetConnectionInfo()
Definition: ntcore_cpp.h:275
Event(NT_Listener listener, unsigned int flags, TopicInfo info)
Definition: ntcore_cpp.h:222
NT_Listener listener
Listener that triggered this event.
Definition: ntcore_cpp.h:245
TimeSyncEventData * GetTimeSyncEventData()
Definition: ntcore_cpp.h:299
Event(NT_Listener listener, unsigned int flags, LogMessage msg)
Definition: ntcore_cpp.h:226
const TopicInfo * GetTopicInfo() const
Definition: ntcore_cpp.h:279
NetworkTables log message.
Definition: ntcore_cpp.h:173
unsigned int line
The line number in the source file that generated the message.
Definition: ntcore_cpp.h:187
LogMessage(unsigned int level, std::string_view filename, unsigned int line, std::string_view message)
Definition: ntcore_cpp.h:176
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:181
std::string message
The message.
Definition: ntcore_cpp.h:190
std::string filename
The filename of the source file that generated the message.
Definition: ntcore_cpp.h:184
NetworkTables time sync event data.
Definition: ntcore_cpp.h:194
int64_t rtt2
Measured round trip time divided by 2, in microseconds.
Definition: ntcore_cpp.h:207
TimeSyncEventData()=default
int64_t serverTimeOffset
Offset between local time and server time, in microseconds.
Definition: ntcore_cpp.h:204
bool valid
If serverTimeOffset and RTT are valid.
Definition: ntcore_cpp.h:213
TimeSyncEventData(int64_t serverTimeOffset, int64_t rtt2, bool valid)
Definition: ntcore_cpp.h:197
NetworkTables Value Event Data.
Definition: ntcore_cpp.h:156
NT_Handle subentry
Subscriber/entry handle.
Definition: ntcore_cpp.h:166
ValueEventData(NT_Topic topic, NT_Handle subentry, Value value)
Definition: ntcore_cpp.h:159
NT_Topic topic
Topic handle.
Definition: ntcore_cpp.h:163
Value value
The new value.
Definition: ntcore_cpp.h:169
A network table entry value.
Definition: NetworkTableValue.h:32
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:579
A data log.
Definition: DataLog.h:90
basic_string_view< char > string_view
Definition: core.h:501
dimensionless::scalar_t log(const ScalarUnit x) noexcept
Compute natural logarithm.
Definition: math.h:349
NT_MultiSubscriber SubscribeMultiple(NT_Inst inst, std::span< const std::string_view > prefixes, const PubSubOptions &options=kDefaultPubSubOptions)
Subscribes to multiple topics based on one or more topic name prefixes.
void UnsubscribeMultiple(NT_MultiSubscriber sub)
Unsubscribes a multi-subscriber.
NT_Handle NT_Topic
Definition: ntcore_c.h:40
NT_Handle NT_ConnectionDataLogger
Definition: ntcore_c.h:33
NT_Handle NT_Listener
Definition: ntcore_c.h:37
NT_Handle NT_Subscriber
Definition: ntcore_c.h:41
unsigned int NT_Handle
Definition: ntcore_c.h:32
NT_Type
NetworkTables data types.
Definition: ntcore_c.h:51
NT_Handle NT_Inst
Definition: ntcore_c.h:36
NT_Handle NT_Publisher
Definition: ntcore_c.h:42
NT_Handle NT_ListenerPoller
Definition: ntcore_c.h:38
NT_Handle NT_MultiSubscriber
Definition: ntcore_c.h:39
NT_Handle NT_Entry
Definition: ntcore_c.h:35
NT_Handle NT_DataLogger
Definition: ntcore_c.h:34
@ NT_UNASSIGNED
Definition: ntcore_c.h:52
@ NT_EVENT_LOGMESSAGE
Log message.
Definition: ntcore_c.h:123
@ NT_EVENT_NONE
Definition: ntcore_c.h:99
@ NT_EVENT_UNPUBLISH
Topic unpublished.
Definition: ntcore_c.h:111
@ NT_EVENT_PROPERTIES
Topic properties changed.
Definition: ntcore_c.h:113
@ NT_EVENT_CONNECTED
Client connected (on server, any client connected).
Definition: ntcore_c.h:103
@ NT_EVENT_TIMESYNC
Time synchronized with server.
Definition: ntcore_c.h:125
@ NT_EVENT_VALUE_REMOTE
Topic value updated (via network).
Definition: ntcore_c.h:117
@ NT_EVENT_PUBLISH
New topic published.
Definition: ntcore_c.h:109
@ NT_EVENT_DISCONNECTED
Client disconnected (on server, any client disconnected).
Definition: ntcore_c.h:105
@ NT_EVENT_IMMEDIATE
Initial listener addition.
Definition: ntcore_c.h:101
@ NT_EVENT_VALUE_LOCAL
Topic value updated (local).
Definition: ntcore_c.h:119
constexpr PubSubOptions kDefaultPubSubOptions
Default publish/subscribe options.
Definition: ntcore_cpp.h:390
NT_ConnectionDataLogger StartConnectionDataLog(NT_Inst inst, wpi::log::DataLog &log, std::string_view name)
Starts logging connection changes to a DataLog.
void StopConnectionDataLog(NT_ConnectionDataLogger logger)
Stops logging connection changes to a DataLog.
NT_DataLogger StartEntryDataLog(NT_Inst inst, wpi::log::DataLog &log, std::string_view prefix, std::string_view logPrefix)
Starts logging entry changes to a DataLog.
void StopEntryDataLog(NT_DataLogger logger)
Stops logging entry changes to a DataLog.
NT_Inst GetInstanceFromHandle(NT_Handle handle)
Get instance handle from another handle.
void ResetInstance(NT_Inst inst)
Reset the internals of an instance.
NT_Inst CreateInstance()
Create an instance.
NT_Inst GetDefaultInstance()
Get default instance.
void DestroyInstance(NT_Inst inst)
Destroy an instance.
std::function< void(const Event &)> ListenerCallback
Definition: ntcore_cpp.h:899
NT_Listener AddPolledListener(NT_ListenerPoller poller, std::span< const std::string_view > prefixes, unsigned int mask)
Creates a polled listener.
NT_ListenerPoller CreateListenerPoller(NT_Inst inst)
Creates a listener poller.
bool WaitForListenerQueue(NT_Handle handle, double timeout)
Wait for the listener queue to be empty.
NT_Listener AddListener(NT_Inst inst, std::span< const std::string_view > prefixes, unsigned int mask, ListenerCallback callback)
Create a listener for changes to topics with names that start with any of the given prefixes.
void DestroyListenerPoller(NT_ListenerPoller poller)
Destroys a listener poller.
void RemoveListener(NT_Listener listener)
Removes a listener.
std::vector< Event > ReadListenerQueue(NT_ListenerPoller poller)
Read notifications.
NT_Listener AddPolledLogger(NT_ListenerPoller poller, unsigned int min_level, unsigned int max_level)
Set the log level for a log poller.
NT_Listener AddLogger(NT_Inst inst, unsigned int min_level, unsigned int max_level, ListenerCallback func)
Add logger callback function.
void StartClient4(NT_Inst inst, std::string_view identity)
Starts a NT4 client.
void Disconnect(NT_Inst inst)
Disconnects the client if it's running and connected.
std::optional< int64_t > GetServerTimeOffset(NT_Inst inst)
Get the time offset between server time and local time.
unsigned int GetNetworkMode(NT_Inst inst)
Get the current network mode.
void StopLocal(NT_Inst inst)
Stops local-only operation.
void StopDSClient(NT_Inst inst)
Stops requesting server address from Driver Station.
bool IsConnected(NT_Inst inst)
Return whether or not the instance is connected to another node.
void StopServer(NT_Inst inst)
Stops the server if it is running.
void StartLocal(NT_Inst inst)
Starts local-only operation.
void Flush(NT_Inst inst)
Flush to network.
void SetServer(NT_Inst inst, const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
void StartClient3(NT_Inst inst, std::string_view identity)
Starts a NT3 client.
void StartDSClient(NT_Inst inst, unsigned int port)
Starts requesting server address from Driver Station.
void StopClient(NT_Inst inst)
Stops the client if it is running.
void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port)
Sets server addresses and port for client (without restarting client).
void StartServer(NT_Inst inst, std::string_view persist_filename, const char *listen_address, unsigned int port3, unsigned int port4)
Starts a server using the specified filename, listening address, and port.
std::vector< ConnectionInfo > GetConnections(NT_Inst inst)
Get information on the currently established network connections.
void FlushLocal(NT_Inst inst)
Flush local updates.
bool HasSchema(NT_Inst inst, std::string_view name)
Returns whether there is a data schema already registered with the given name.
void AddSchema(NT_Inst inst, std::string_view name, std::string_view type, std::span< const uint8_t > schema)
Registers a data schema.
NT_Type GetEntryType(NT_Entry entry)
Gets the type for the specified entry, or unassigned if non existent.
Value GetEntryValue(NT_Handle subentry)
Get Entry Value.
void SetEntryFlags(NT_Entry entry, unsigned int flags)
Set Entry Flags.
NT_Entry GetEntry(NT_Inst inst, std::string_view name)
Get Entry Handle.
int64_t GetEntryLastChange(NT_Handle subentry)
Gets the last time the entry was changed.
unsigned int GetEntryFlags(NT_Entry entry)
Get Entry Flags.
std::vector< Value > ReadQueueValue(NT_Handle subentry)
Read Entry Queue.
std::string GetEntryName(NT_Entry entry)
Gets the name of the specified entry.
bool SetEntryValue(NT_Entry entry, const Value &value)
Set Entry Value.
bool SetDefaultEntryValue(NT_Entry entry, const Value &value)
Set Default Entry Value.
NT_Topic GetTopicFromHandle(NT_Handle pubsubentry)
Gets the topic handle from an entry/subscriber/publisher handle.
void Unsubscribe(NT_Subscriber sub)
Stops subscriber.
void Release(NT_Handle pubsubentry)
Stops entry/subscriber/publisher.
bool GetTopicRetained(NT_Topic topic)
Gets the retained property of a topic.
bool GetTopicExists(NT_Handle handle)
Determine if topic exists (e.g.
wpi::json GetTopicProperties(NT_Topic topic)
Gets all topic properties as a JSON object.
NT_Type GetTopicType(NT_Topic topic)
Gets the type for the specified topic, or unassigned if non existent.
bool GetTopicCached(NT_Topic topic)
Gets the cached property of a topic.
std::string GetTopicTypeString(NT_Topic topic)
Gets the type string for the specified topic, or empty string if non existent.
std::string GetTopicName(NT_Topic topic)
Gets the name of the specified topic.
NT_Topic GetTopic(NT_Inst inst, std::string_view name)
Gets Topic Handle.
void SetTopicProperty(NT_Topic topic, std::string_view name, const wpi::json &value)
Sets a property value.
void SetTopicCached(NT_Topic topic, bool value)
Sets the cached property of a topic.
NT_Publisher PublishEx(NT_Topic topic, NT_Type type, std::string_view typeStr, const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new publisher to a topic.
void SetTopicRetained(NT_Topic topic, bool value)
Sets the retained property of a topic.
bool SetTopicProperties(NT_Topic topic, const wpi::json &update)
Updates multiple topic properties.
NT_Publisher Publish(NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new publisher to a topic.
std::vector< NT_Topic > GetTopics(NT_Inst inst, std::string_view prefix, unsigned int types)
Get Published Topics.
std::vector< TopicInfo > GetTopicInfo(NT_Inst inst, std::string_view prefix, unsigned int types)
Get Topic Information about multiple topics.
void SetTopicPersistent(NT_Topic topic, bool value)
Sets the persistent property of a topic.
wpi::json GetTopicProperty(NT_Topic topic, std::string_view name)
Gets the current value of a property (as a JSON object).
void ReleaseEntry(NT_Entry entry)
Stops entry subscriber/publisher.
void Unpublish(NT_Handle pubentry)
Stops publisher.
NT_Subscriber Subscribe(NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new subscriber to value changes on a topic.
void DeleteTopicProperty(NT_Topic topic, std::string_view name)
Deletes a property.
bool GetTopicPersistent(NT_Topic topic)
Gets the persistent property of a topic.
NT_Type GetTypeFromString(std::string_view typeString)
Turns a type string into a type enum value.
int64_t Now()
Returns monotonic current time in 1 us increments.
void SetNow(int64_t timestamp)
Sets the current timestamp used for timestamping values that do not provide a timestamp (e....
std::string_view GetStringFromType(NT_Type type)
Turns a type enum value into a type string.
const T & first(const T &value, const Tail &...)
Definition: compile.h:60
type
Definition: core.h:556
NetworkTables (ntcore) namespace.
Definition: ntcore_cpp.h:36
WPI_BASIC_JSON_TPL_DECLARATION void swap(wpi::WPI_BASIC_JSON_TPL &j1, wpi::WPI_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< wpi::WPI_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< wpi::WPI_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.h:5219
Definition: ntcore_cpp.h:31
Definition: ntcore_cpp.h:26
NetworkTables Connection Information.
Definition: ntcore_cpp.h:120
unsigned int protocol_version
The protocol version being used for this connection.
Definition: ntcore_cpp.h:143
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:131
friend void swap(ConnectionInfo &first, ConnectionInfo &second)
Definition: ntcore_cpp.h:145
int64_t last_update
The last time any update was received from the remote node (same scale as returned by nt::Now()).
Definition: ntcore_cpp.h:137
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::StartClient4() or nt::Start...
Definition: ntcore_cpp.h:125
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:128
Event notification flags.
Definition: ntcore_cpp.h:53
static constexpr unsigned int kValueRemote
Topic value updated (via network).
Definition: ntcore_cpp.h:78
static constexpr unsigned int kValueAll
Topic value updated (network or local).
Definition: ntcore_cpp.h:82
static constexpr unsigned int kTopic
Any topic event (publish, unpublish, or properties changed).
Definition: ntcore_cpp.h:76
static constexpr unsigned int kNone
Definition: ntcore_cpp.h:56
static constexpr unsigned int kLogMessage
Log message.
Definition: ntcore_cpp.h:84
static constexpr unsigned int kUnpublish
Topic unpublished.
Definition: ntcore_cpp.h:72
static constexpr unsigned int kImmediate
Initial listener addition.
Definition: ntcore_cpp.h:62
static constexpr unsigned int kConnection
Any connection event (connect or disconnect).
Definition: ntcore_cpp.h:68
static constexpr unsigned int kTimeSync
Time synchronized with server.
Definition: ntcore_cpp.h:86
static constexpr unsigned int kPublish
New topic published.
Definition: ntcore_cpp.h:70
static constexpr unsigned int kProperties
Topic properties changed.
Definition: ntcore_cpp.h:74
static constexpr unsigned int kValueLocal
Topic value updated (local).
Definition: ntcore_cpp.h:80
static constexpr unsigned int kConnected
Client connected (on server, any client connected).
Definition: ntcore_cpp.h:64
static constexpr unsigned int kDisconnected
Client disconnected (on server, any client disconnected).
Definition: ntcore_cpp.h:66
NetworkTables publish/subscribe options.
Definition: ntcore_cpp.h:305
bool topicsOnly
For subscriptions, don't ask for value changes (only topic announcements).
Definition: ntcore_cpp.h:346
NT_Publisher excludePublisher
For subscriptions, if non-zero, value updates for ReadQueue() are not queued for this publisher.
Definition: ntcore_cpp.h:336
bool excludeSelf
For entries, don't queue (for ReadQueue) value updates for the entry's internal publisher.
Definition: ntcore_cpp.h:376
bool sendAll
Send all value changes over the network.
Definition: ntcore_cpp.h:341
static constexpr double kDefaultPeriodic
Default value of periodic.
Definition: ntcore_cpp.h:309
bool keepDuplicates
Preserve duplicate value changes (rather than ignoring them).
Definition: ntcore_cpp.h:351
bool disableLocal
For subscriptions, if local value updates should not be queued for ReadQueue().
Definition: ntcore_cpp.h:370
bool disableRemote
For subscriptions, if remote value updates should not be queued for ReadQueue().
Definition: ntcore_cpp.h:364
bool prefixMatch
Perform prefix match on subscriber topic names.
Definition: ntcore_cpp.h:358
unsigned int structSize
Structure size.
Definition: ntcore_cpp.h:314
bool hidden
For subscriptions, don't share the existence of the subscription with the network.
Definition: ntcore_cpp.h:384
double periodic
How frequently changes will be sent over the network, in seconds.
Definition: ntcore_cpp.h:330
unsigned int pollStorage
Polling storage size for a subscription.
Definition: ntcore_cpp.h:322
NetworkTables Topic Information.
Definition: ntcore_cpp.h:90
wpi::json GetProperties() const
Get topic properties as a JSON object.
std::string name
Topic name.
Definition: ntcore_cpp.h:95
NT_Topic topic
Topic handle.
Definition: ntcore_cpp.h:92
std::string type_str
Topic type string.
Definition: ntcore_cpp.h:101
std::string properties
Topic properties JSON string.
Definition: ntcore_cpp.h:104
friend void swap(TopicInfo &first, TopicInfo &second)
Definition: ntcore_cpp.h:109
NT_Type type
Topic type.
Definition: ntcore_cpp.h:98