WPILibC++ 2024.3.2
ntcore_c.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#ifdef __cplusplus
10#include <cstddef>
11#else
12#include <stddef.h>
13#endif
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19struct WPI_DataLog;
20
21/**
22 * @defgroup ntcore_c_api ntcore C API
23 *
24 * Handle-based interface for C.
25 *
26 * @{
27 */
28
29/** Typedefs */
30typedef int NT_Bool;
31
32typedef unsigned int NT_Handle;
43
44/** Default network tables port number (NT3) */
45#define NT_DEFAULT_PORT3 1735
46
47/** Default network tables port number (NT4) */
48#define NT_DEFAULT_PORT4 5810
49
50/** NetworkTables data types. */
51enum NT_Type {
53 NT_BOOLEAN = 0x01,
54 NT_DOUBLE = 0x02,
55 NT_STRING = 0x04,
56 NT_RAW = 0x08,
60 NT_RPC = 0x80,
61 NT_INTEGER = 0x100,
62 NT_FLOAT = 0x200,
64 NT_FLOAT_ARRAY = 0x800
65};
66
67/** NetworkTables entry flags. */
71 NT_UNCACHED = 0x04
72};
73
74/** NetworkTables logging levels. */
85};
86
87/** Client/server modes */
89 NT_NET_MODE_NONE = 0x00, /* not running */
90 NT_NET_MODE_SERVER = 0x01, /* running in server mode */
91 NT_NET_MODE_CLIENT3 = 0x02, /* running in NT3 client mode */
92 NT_NET_MODE_CLIENT4 = 0x04, /* running in NT4 client mode */
93 NT_NET_MODE_STARTING = 0x08, /* flag for starting (either client or server) */
94 NT_NET_MODE_LOCAL = 0x10, /* running in local-only mode */
95};
96
97/** Event notification flags. */
100 /** Initial listener addition. */
102 /** Client connected (on server, any client connected). */
104 /** Client disconnected (on server, any client disconnected). */
106 /** Any connection event (connect or disconnect). */
108 /** New topic published. */
110 /** Topic unpublished. */
112 /** Topic properties changed. */
114 /** Any topic event (publish, unpublish, or properties changed). */
116 /** Topic value updated (via network). */
118 /** Topic value updated (local). */
120 /** Topic value updated (network or local). */
122 /** Log message. */
124 /** Time synchronized with server. */
126};
127
128/*
129 * Structures
130 */
131
132/** A NetworkTables string. */
133struct NT_String {
134 /**
135 * String contents (UTF-8).
136 * The string is NOT required to be zero-terminated.
137 * When returned by the library, this is zero-terminated and allocated with
138 * std::malloc().
139 */
140 char* str;
141
142 /**
143 * Length of the string in bytes. If the string happens to be zero
144 * terminated, this does not include the zero-termination.
145 */
146 size_t len;
147};
148
149/** NetworkTables Entry Value. Note this is a typed union. */
150struct NT_Value {
152 int64_t last_change;
153 int64_t server_time;
154 union {
156 int64_t v_int;
157 float v_float;
158 double v_double;
160 struct {
161 uint8_t* data;
162 size_t size;
164 struct {
166 size_t size;
168 struct {
169 double* arr;
170 size_t size;
172 struct {
173 float* arr;
174 size_t size;
176 struct {
177 int64_t* arr;
178 size_t size;
180 struct {
181 struct NT_String* arr;
182 size_t size;
185};
186
187/** NetworkTables Topic Information */
189 /** Topic handle */
191
192 /** Topic name */
194
195 /** Topic type */
197
198 /** Topic type string */
200
201 /** Topic properties JSON string */
203};
204
205/** NetworkTables Connection Information */
207 /**
208 * The remote identifier (as set on the remote node by NT_StartClient4().
209 */
211
212 /** The IP address of the remote node. */
214
215 /** The port number of the remote node. */
216 unsigned int remote_port;
217
218 /**
219 * The last time any update was received from the remote node (same scale as
220 * returned by nt::Now()).
221 */
222 uint64_t last_update;
223
224 /**
225 * The protocol version being used for this connection. This in protocol
226 * layer format, so 0x0200 = 2.0, 0x0300 = 3.0).
227 */
228 unsigned int protocol_version;
229};
230
231/** NetworkTables value event data. */
233 /** Topic handle. */
235
236 /** Subscriber/entry handle. */
238
239 /** The new value. */
241};
242
243/** NetworkTables log message. */
245 /** Log level of the message. See NT_LogLevel. */
246 unsigned int level;
247
248 /** The filename of the source file that generated the message. */
249 char* filename;
250
251 /** The line number in the source file that generated the message. */
252 unsigned int line;
253
254 /** The message. */
255 char* message;
256};
257
258/** NetworkTables time sync event data. */
260 /**
261 * Offset between local time and server time, in microseconds. Add this value
262 * to local time to get the estimated equivalent server time.
263 */
265
266 /** Measured round trip time divided by 2, in microseconds. */
267 int64_t rtt2;
268
269 /**
270 * If serverTimeOffset and RTT are valid. An event with this set to false is
271 * sent when the client disconnects.
272 */
274};
275
276/** NetworkTables event */
277struct NT_Event {
278 /** Listener that triggered this event. */
280
281 /**
282 * Event flags (NT_EventFlags). Also indicates the data included with the
283 * event:
284 * - NT_EVENT_CONNECTED or NT_EVENT_DISCONNECTED: connInfo
285 * - NT_EVENT_PUBLISH, NT_EVENT_UNPUBLISH, or NT_EVENT_PROPERTIES: topicInfo
286 * - NT_EVENT_VALUE_REMOTE, NT_NOTIFY_VALUE_LOCAL: valueData
287 * - NT_EVENT_LOGMESSAGE: logMessage
288 * - NT_EVENT_TIMESYNC: timeSyncData
289 */
290 unsigned int flags;
291
292 /** Event data; content depends on flags. */
293 union {
300};
301
302/** NetworkTables publish/subscribe options. */
304 /**
305 * Structure size. Must be set to sizeof(NT_PubSubOptions).
306 */
307 unsigned int structSize;
308
309 /**
310 * Polling storage size for a subscription. Specifies the maximum number of
311 * updates NetworkTables should store between calls to the subscriber's
312 * ReadQueue() function. If zero, defaults to 1 if sendAll is false, 20 if
313 * sendAll is true.
314 */
315 unsigned int pollStorage;
316
317 /**
318 * How frequently changes will be sent over the network, in seconds.
319 * NetworkTables may send more frequently than this (e.g. use a combined
320 * minimum period for all values) or apply a restricted range to this value.
321 * The default is 100 ms.
322 */
323 double periodic;
324
325 /**
326 * For subscriptions, if non-zero, value updates for ReadQueue() are not
327 * queued for this publisher.
328 */
330
331 /**
332 * Send all value changes over the network.
333 */
335
336 /**
337 * For subscriptions, don't ask for value changes (only topic announcements).
338 */
340
341 /**
342 * Perform prefix match on subscriber topic names. Is ignored/overridden by
343 * Subscribe() functions; only present in struct for the purposes of getting
344 * information about subscriptions.
345 */
347
348 /**
349 * Preserve duplicate value changes (rather than ignoring them).
350 */
352
353 /**
354 * For subscriptions, if remote value updates should not be queued for
355 * ReadQueue(). See also disableLocal.
356 */
358
359 /**
360 * For subscriptions, if local value updates should not be queued for
361 * ReadQueue(). See also disableRemote.
362 */
364
365 /**
366 * For entries, don't queue (for ReadQueue) value updates for the entry's
367 * internal publisher.
368 */
370
371 /**
372 * For subscriptions, don't share the existence of the subscription with the
373 * network. Note this means updates will not be received from the network
374 * unless another subscription overlaps with this one, and the subscription
375 * will not appear in metatopics.
376 */
378};
379
380/**
381 * @defgroup ntcore_instance_cfunc Instance Functions
382 * @{
383 */
384
385/**
386 * Get default instance.
387 * This is the instance used by non-handle-taking functions.
388 *
389 * @return Instance handle
390 */
392
393/**
394 * Create an instance.
395 *
396 * @return Instance handle
397 */
399
400/**
401 * Destroy an instance.
402 * The default instance cannot be destroyed.
403 *
404 * @param inst Instance handle
405 */
407
408/**
409 * Get instance handle from another handle.
410 *
411 * @param handle handle
412 * @return Instance handle
413 */
415
416/** @} */
417
418/**
419 * @defgroup ntcore_table_cfunc Table Functions
420 * @{
421 */
422
423/**
424 * Get Entry Handle.
425 *
426 * @param inst instance handle
427 * @param name entry name (UTF-8 string)
428 * @param name_len length of name in bytes
429 * @return entry handle
430 */
431NT_Entry NT_GetEntry(NT_Inst inst, const char* name, size_t name_len);
432
433/**
434 * Gets the name of the specified entry.
435 * Returns an empty string if the handle is invalid.
436 *
437 * @param entry entry handle
438 * @param name_len length of the returned string (output parameter)
439 * @return Entry name
440 */
441char* NT_GetEntryName(NT_Entry entry, size_t* name_len);
442
443/**
444 * Gets the type for the specified key, or unassigned if non existent.
445 *
446 * @param entry entry handle
447 * @return Entry type
448 */
450
451/**
452 * Gets the last time the entry was changed.
453 * Returns 0 if the handle is invalid.
454 *
455 * @param entry entry handle
456 * @return Entry last change time
457 */
459
460/**
461 * Get Entry Value.
462 *
463 * Returns copy of current entry value.
464 * Note that one of the type options is "unassigned".
465 *
466 * @param entry entry handle
467 * @param value storage for returned entry value
468 *
469 * It is the caller's responsibility to free value once it's no longer
470 * needed (the utility function NT_DisposeValue() is useful for this
471 * purpose).
472 */
473void NT_GetEntryValue(NT_Entry entry, struct NT_Value* value);
474
475/**
476 * Get Entry Value.
477 *
478 * Returns copy of current entry value.
479 * Note that one of the type options is "unassigned".
480 *
481 * @param entry entry handle
482 * @param types bitmask of NT_Type values; 0 is treated specially
483 * as a "don't care"
484 * @param value storage for returned entry value
485 *
486 * It is the caller's responsibility to free value once it's no longer
487 * needed (the utility function NT_DisposeValue() is useful for this
488 * purpose).
489 */
490void NT_GetEntryValueType(NT_Entry entry, unsigned int types,
491 struct NT_Value* value);
492
493/**
494 * Set Default Entry Value.
495 *
496 * Returns copy of current entry value if it exists.
497 * Otherwise, sets passed in value, and returns set value.
498 * Note that one of the type options is "unassigned".
499 *
500 * @param entry entry handle
501 * @param default_value value to be set if name does not exist
502 * @return 0 on error (value not set), 1 on success
503 */
505 const struct NT_Value* default_value);
506
507/**
508 * Set Entry Value.
509 *
510 * Sets new entry value. If type of new value differs from the type of the
511 * currently stored entry, returns error and does not update value.
512 *
513 * @param entry entry handle
514 * @param value new entry value
515 * @return 0 on error (type mismatch), 1 on success
516 */
517NT_Bool NT_SetEntryValue(NT_Entry entry, const struct NT_Value* value);
518
519/**
520 * Set Entry Flags.
521 *
522 * @param entry entry handle
523 * @param flags flags value (bitmask of NT_EntryFlags)
524 */
525void NT_SetEntryFlags(NT_Entry entry, unsigned int flags);
526
527/**
528 * Get Entry Flags.
529 *
530 * @param entry entry handle
531 * @return Flags value (bitmask of NT_EntryFlags)
532 */
533unsigned int NT_GetEntryFlags(NT_Entry entry);
534
535/**
536 * Read Entry Queue.
537 *
538 * Returns new entry values since last call. The returned array must be freed
539 * using NT_DisposeValueArray().
540 *
541 * @param subentry subscriber or entry handle
542 * @param count count of items in returned array (output)
543 * @return entry value array; returns NULL and count=0 if no new values
544 */
545struct NT_Value* NT_ReadQueueValue(NT_Handle subentry, size_t* count);
546
547/**
548 * Read Entry Queue.
549 *
550 * Returns new entry values since last call. The returned array must be freed
551 * using NT_DisposeValueArray().
552 *
553 * @param subentry subscriber or entry handle
554 * @param types bitmask of NT_Type values; 0 is treated specially
555 * as a "don't care"
556 * @param count count of items in returned array (output)
557 * @return entry value array; returns NULL and count=0 if no new values
558 */
559struct NT_Value* NT_ReadQueueValueType(NT_Handle subentry, unsigned int types,
560 size_t* count);
561
562/** @} */
563
564/**
565 * @defgroup ntcore_topic_cfunc Topic Functions
566 * @{
567 */
568
569/**
570 * Get Published Topic Handles.
571 *
572 * Returns an array of topic handles. The results are optionally
573 * filtered by string prefix and type to only return a subset of all
574 * topics.
575 *
576 * @param inst instance handle
577 * @param prefix name required prefix; only topics whose name
578 * starts with this string are returned
579 * @param prefix_len length of prefix in bytes
580 * @param types bitmask of NT_Type values; 0 is treated specially
581 * as a "don't care"
582 * @param count output parameter; set to length of returned array
583 * @return Array of topic handles.
584 */
585NT_Topic* NT_GetTopics(NT_Inst inst, const char* prefix, size_t prefix_len,
586 unsigned int types, size_t* count);
587
588/**
589 * Get Published Topic Handles.
590 *
591 * Returns an array of topic handles. The results are optionally
592 * filtered by string prefix and type to only return a subset of all
593 * topics.
594 *
595 * @param inst instance handle
596 * @param prefix name required prefix; only topics whose name
597 * starts with this string are returned
598 * @param prefix_len length of prefix in bytes
599 * @param types array of type strings
600 * @param types_len number of elements in types array
601 * @param count output parameter; set to length of returned array
602 * @return Array of topic handles.
603 */
604NT_Topic* NT_GetTopicsStr(NT_Inst inst, const char* prefix, size_t prefix_len,
605 const char* const* types, size_t types_len,
606 size_t* count);
607
608/**
609 * Get Topics.
610 *
611 * Returns an array of topic information (handle, name, type). The results are
612 * optionally filtered by string prefix and type to only return a subset
613 * of all topics.
614 *
615 * @param inst instance handle
616 * @param prefix name required prefix; only topics whose name
617 * starts with this string are returned
618 * @param prefix_len length of prefix in bytes
619 * @param types bitmask of NT_Type values; 0 is treated specially
620 * as a "don't care"
621 * @param count output parameter; set to length of returned array
622 * @return Array of topic information.
623 */
624struct NT_TopicInfo* NT_GetTopicInfos(NT_Inst inst, const char* prefix,
625 size_t prefix_len, unsigned int types,
626 size_t* count);
627
628/**
629 * Get Topics.
630 *
631 * Returns an array of topic information (handle, name, type). The results are
632 * optionally filtered by string prefix and type to only return a subset
633 * of all topics.
634 *
635 * @param inst instance handle
636 * @param prefix name required prefix; only topics whose name
637 * starts with this string are returned
638 * @param prefix_len length of prefix in bytes
639 * @param types array of type strings
640 * @param types_len number of elements in types array
641 * @param count output parameter; set to length of returned array
642 * @return Array of topic information.
643 */
644struct NT_TopicInfo* NT_GetTopicInfosStr(NT_Inst inst, const char* prefix,
645 size_t prefix_len,
646 const char* const* types,
647 size_t types_len, size_t* count);
648
649/**
650 * Gets Topic Information.
651 *
652 * Returns information about a topic (name and type).
653 *
654 * @param topic handle
655 * @param info information (output)
656 * @return True if successful, false on error.
657 */
659
660/**
661 * Gets Topic Handle.
662 *
663 * Returns topic handle.
664 *
665 * @param inst instance handle
666 * @param name topic name
667 * @param name_len length of topic name in bytes
668 * @return Topic handle.
669 */
670NT_Topic NT_GetTopic(NT_Inst inst, const char* name, size_t name_len);
671
672/**
673 * Gets the name of the specified topic.
674 *
675 * @param topic topic handle
676 * @param name_len length of topic name (output)
677 * @return Topic name; returns NULL and name_len=0 if the handle is invalid.
678 */
679char* NT_GetTopicName(NT_Topic topic, size_t* name_len);
680
681/**
682 * Gets the type for the specified topic, or unassigned if non existent.
683 *
684 * @param topic topic handle
685 * @return Topic type
686 */
688
689/**
690 * Gets the type string for the specified topic. This may have more information
691 * than the numeric type (especially for raw values).
692 *
693 * @param topic topic handle
694 * @param type_len length of type string (output)
695 * @return Topic type string; returns NULL if non-existent
696 */
697char* NT_GetTopicTypeString(NT_Topic topic, size_t* type_len);
698
699/**
700 * Sets the persistent property of a topic. If true, the stored value is
701 * persistent through server restarts.
702 *
703 * @param topic topic handle
704 * @param value True for persistent, false for not persistent.
705 */
707
708/**
709 * Gets the persistent property of a topic.
710 *
711 * @param topic topic handle
712 * @return persistent property value
713 */
715
716/**
717 * Sets the retained property of a topic. If true, the server retains the
718 * topic even when there are no publishers.
719 *
720 * @param topic topic handle
721 * @param value new retained property value
722 */
724
725/**
726 * Gets the retained property of a topic.
727 *
728 * @param topic topic handle
729 * @return retained property value
730 */
732
733/**
734 * Sets the cached property of a topic. If true, the server and clients will
735 * store the latest value, allowing the value to be read (and not just accessed
736 * through event queues and listeners).
737 *
738 * @param topic topic handle
739 * @param value True for cached, false for not cached
740 */
742
743/**
744 * Gets the cached property of a topic.
745 *
746 * @param topic topic handle
747 * @return cached property value
748 */
750
751/**
752 * Determine if topic exists (e.g. has at least one publisher).
753 *
754 * @param handle Topic, entry, or subscriber handle.
755 * @return True if topic exists.
756 */
758
759/**
760 * Gets the current value of a property (as a JSON string).
761 *
762 * @param topic topic handle
763 * @param name property name
764 * @param len length of returned string (output)
765 * @return JSON string; empty string if the property does not exist.
766 */
767char* NT_GetTopicProperty(NT_Topic topic, const char* name, size_t* len);
768
769/**
770 * Sets a property value.
771 *
772 * @param topic topic handle
773 * @param name property name
774 * @param value property value (JSON string)
775 */
777 const char* value);
778
779/**
780 * Deletes a property. Has no effect if the property does not exist.
781 *
782 * @param topic topic handle
783 * @param name property name
784 */
786
787/**
788 * Gets all topic properties as a JSON string. Each key in the object
789 * is the property name, and the corresponding value is the property value.
790 *
791 * @param topic topic handle
792 * @param len length of returned string (output)
793 * @return JSON string
794 */
796
797/**
798 * Updates multiple topic properties. Each key in the passed-in JSON object is
799 * the name of the property to add/update, and the corresponding value is the
800 * property value to set for that property. Null values result in deletion
801 * of the corresponding property.
802 *
803 * @param topic topic handle
804 * @param properties JSON object string with keys to add/update/delete
805 * @return False if properties are not a valid JSON object
806 */
808
809/**
810 * Creates a new subscriber to value changes on a topic.
811 *
812 * @param topic topic handle
813 * @param type expected type
814 * @param typeStr expected type string
815 * @param options subscription options
816 * @return Subscriber handle
817 */
819 const char* typeStr,
820 const struct NT_PubSubOptions* options);
821
822/**
823 * Stops subscriber.
824 *
825 * @param sub subscriber handle
826 */
828
829/**
830 * Creates a new publisher to a topic.
831 *
832 * @param topic topic handle
833 * @param type type
834 * @param typeStr type string
835 * @param options publish options
836 * @return Publisher handle
837 */
839 const struct NT_PubSubOptions* options);
840
841/**
842 * Creates a new publisher to a topic.
843 *
844 * @param topic topic handle
845 * @param type type
846 * @param typeStr type string
847 * @param properties initial properties (JSON object)
848 * @param options publish options
849 * @return Publisher handle
850 */
852 const char* typeStr, const char* properties,
853 const struct NT_PubSubOptions* options);
854
855/**
856 * Stops publisher.
857 *
858 * @param pubentry publisher/entry handle
859 */
860void NT_Unpublish(NT_Handle pubentry);
861
862/**
863 * @brief Creates a new entry (subscriber and weak publisher) to a topic.
864 *
865 * @param topic topic handle
866 * @param type type
867 * @param typeStr type string
868 * @param options publish options
869 * @return Entry handle
870 */
871NT_Entry NT_GetEntryEx(NT_Topic topic, enum NT_Type type, const char* typeStr,
872 const struct NT_PubSubOptions* options);
873
874/**
875 * Stops entry subscriber/publisher.
876 *
877 * @param entry entry handle
878 */
880
881/**
882 * Stops entry/subscriber/publisher.
883 *
884 * @param pubsubentry entry/subscriber/publisher handle
885 */
886void NT_Release(NT_Handle pubsubentry);
887
888/**
889 * Gets the topic handle from an entry/subscriber/publisher handle.
890 *
891 * @param pubsubentry entry/subscriber/publisher handle
892 * @return Topic handle
893 */
895
896/** @} */
897
898/**
899 * @defgroup ntcore_advancedsub_cfunc Advanced Subscriber Functions
900 * @{
901 */
902
903/**
904 * Subscribes to multiple topics based on one or more topic name prefixes. Can
905 * be used in combination with a Value Listener or ReadQueueValue() to get value
906 * changes across all matching topics.
907 *
908 * @param inst instance handle
909 * @param prefixes topic name prefixes
910 * @param prefixes_len number of elements in prefixes array
911 * @param options subscriber options
912 * @return subscriber handle
913 */
915 const struct NT_String* prefixes,
916 size_t prefixes_len,
917 const struct NT_PubSubOptions* options);
918
919/**
920 * Unsubscribes a multi-subscriber.
921 *
922 * @param sub multi-subscriber handle
923 */
925
926/** @} */
927
928/**
929 * @defgroup ntcore_listener_cfunc Listener Functions
930 * @{
931 */
932
933/**
934 * Event listener callback function.
935 *
936 * @param data data pointer provided to callback creation function
937 * @param event event info
938 */
939typedef void (*NT_ListenerCallback)(void* data, const struct NT_Event* event);
940
941/**
942 * Creates a listener poller.
943 *
944 * A poller provides a single queue of poll events. Events linked to this
945 * poller (using NT_AddPolledXListener()) will be stored in the queue and
946 * must be collected by calling NT_ReadListenerQueue().
947 * The returned handle must be destroyed with NT_DestroyListenerPoller().
948 *
949 * @param inst instance handle
950 * @return poller handle
951 */
953
954/**
955 * Destroys a listener poller. This will abort any blocked polling
956 * call and prevent additional events from being generated for this poller.
957 *
958 * @param poller poller handle
959 */
961
962/**
963 * Read notifications.
964 *
965 * @param poller poller handle
966 * @param len length of returned array (output)
967 * @return Array of events. Returns NULL and len=0 if no events since last
968 * call.
969 */
971
972/**
973 * Removes a listener.
974 *
975 * @param listener Listener handle to remove
976 */
978
979/**
980 * Wait for the listener queue to be empty. This is primarily useful
981 * for deterministic testing. This blocks until either the listener
982 * queue is empty (e.g. there are no more events that need to be passed along to
983 * callbacks or poll queues) or the timeout expires.
984 *
985 * @param handle handle
986 * @param timeout timeout, in seconds. Set to 0 for non-blocking behavior, or a
987 * negative value to block indefinitely
988 * @return False if timed out, otherwise true.
989 */
991
992/**
993 * Create a listener for changes to topics with names that start with
994 * the given prefix. This creates a corresponding internal subscriber with the
995 * lifetime of the listener.
996 *
997 * @param inst Instance handle
998 * @param prefix Topic name string prefix
999 * @param prefix_len Length of topic name string prefix
1000 * @param mask Bitmask of NT_EventFlags values (only topic and value events will
1001 * be generated)
1002 * @param data Data passed to callback function
1003 * @param callback Listener function
1004 * @return Listener handle
1005 */
1007 size_t prefix_len, unsigned int mask,
1008 void* data, NT_ListenerCallback callback);
1009
1010/**
1011 * Create a listener for changes to topics with names that start with any of
1012 * the given prefixes. This creates a corresponding internal subscriber with the
1013 * lifetime of the listener.
1014 *
1015 * @param inst Instance handle
1016 * @param prefixes Topic name string prefixes
1017 * @param prefixes_len Number of elements in prefixes array
1018 * @param mask Bitmask of NT_EventFlags values (only topic and value events will
1019 * be generated)
1020 * @param data Data passed to callback function
1021 * @param callback Listener function
1022 * @return Listener handle
1023 */
1025 const struct NT_String* prefixes,
1026 size_t prefixes_len, unsigned int mask,
1027 void* data, NT_ListenerCallback callback);
1028
1029/**
1030 * Create a listener.
1031 *
1032 * Some combinations of handle and mask have no effect:
1033 * - connection and log message events are only generated on instances
1034 * - topic and value events are only generated on non-instances
1035 *
1036 * Adding value and topic events on a topic will create a corresponding internal
1037 * subscriber with the lifetime of the listener.
1038 *
1039 * Adding a log message listener through this function will only result in
1040 * events at NT_LOG_INFO or higher; for more customized settings, use
1041 * NT_AddLogger().
1042 *
1043 * @param handle Handle
1044 * @param mask Bitmask of NT_EventFlags values
1045 * @param data Data passed to callback function
1046 * @param callback Listener function
1047 * @return Listener handle
1048 */
1049NT_Listener NT_AddListener(NT_Handle handle, unsigned int mask, void* data,
1050 NT_ListenerCallback callback);
1051
1052/**
1053 * Creates a polled topic listener. This creates a corresponding internal
1054 * subscriber with the lifetime of the listener.
1055 * The caller is responsible for calling NT_ReadListenerQueue() to poll.
1056 *
1057 * @param poller poller handle
1058 * @param prefix UTF-8 string prefix
1059 * @param prefix_len Length of UTF-8 string prefix
1060 * @param mask NT_EventFlags bitmask (only topic and value events
1061 * will be generated)
1062 * @return Listener handle
1063 */
1065 const char* prefix, size_t prefix_len,
1066 unsigned int mask);
1067
1068/**
1069 * Creates a polled topic listener. This creates a corresponding internal
1070 * subscriber with the lifetime of the listener.
1071 * The caller is responsible for calling NT_ReadListenerQueue() to poll.
1072 *
1073 * @param poller poller handle
1074 * @param prefixes array of UTF-8 string prefixes
1075 * @param prefixes_len Length of prefixes array
1076 * @param mask NT_EventFlags bitmask (only topic and value events
1077 * will be generated)
1078 * @return Listener handle
1079 */
1081 const struct NT_String* prefixes,
1082 size_t prefixes_len,
1083 unsigned int mask);
1084
1085/**
1086 * Creates a polled listener.
1087 * The caller is responsible for calling NT_ReadListenerQueue() to poll.
1088 *
1089 * Some combinations of handle and mask have no effect:
1090 * - connection and log message events are only generated on instances
1091 * - topic and value events are only generated on non-instances
1092 *
1093 * Adding value and topic events on a topic will create a corresponding internal
1094 * subscriber with the lifetime of the listener.
1095 *
1096 * Adding a log message listener through this function will only result in
1097 * events at NT_LOG_INFO or higher; for more customized settings, use
1098 * NT_AddPolledLogger().
1099 *
1100 * @param poller poller handle
1101 * @param handle handle
1102 * @param mask NT_NotifyKind bitmask
1103 * @return Listener handle
1104 */
1106 unsigned int mask);
1107
1108/** @} */
1109
1110/**
1111 * @defgroup ntcore_network_cfunc Client/Server Functions
1112 * @{
1113 */
1114
1115/**
1116 * Get the current network mode.
1117 *
1118 * @param inst instance handle
1119 * @return Bitmask of NT_NetworkMode.
1120 */
1121unsigned int NT_GetNetworkMode(NT_Inst inst);
1122
1123/**
1124 * Starts local-only operation. Prevents calls to NT_StartServer or
1125 * NT_StartClient from taking effect. Has no effect if NT_StartServer or
1126 * NT_StartClient has already been called.
1127 */
1129
1130/**
1131 * Stops local-only operation. NT_StartServer or NT_StartClient can be called
1132 * after this call to start a server or client.
1133 */
1135
1136/**
1137 * Starts a server using the specified filename, listening address, and port.
1138 *
1139 * @param inst instance handle
1140 * @param persist_filename the name of the persist file to use (UTF-8 string,
1141 * null terminated)
1142 * @param listen_address the address to listen on, or null to listen on any
1143 * address. (UTF-8 string, null terminated)
1144 * @param port3 port to communicate over (NT3)
1145 * @param port4 port to communicate over (NT4)
1146 */
1147void NT_StartServer(NT_Inst inst, const char* persist_filename,
1148 const char* listen_address, unsigned int port3,
1149 unsigned int port4);
1150
1151/**
1152 * Stops the server if it is running.
1153 *
1154 * @param inst instance handle
1155 */
1157
1158/**
1159 * Starts a NT3 client. Use NT_SetServer or NT_SetServerTeam to set the server
1160 * name and port.
1161 *
1162 * @param inst instance handle
1163 * @param identity network identity to advertise (cannot be empty string)
1164 */
1165void NT_StartClient3(NT_Inst inst, const char* identity);
1166
1167/**
1168 * Starts a NT4 client. Use NT_SetServer or NT_SetServerTeam to set the server
1169 * name and port.
1170 *
1171 * @param inst instance handle
1172 * @param identity network identity to advertise (cannot be empty string)
1173 */
1174void NT_StartClient4(NT_Inst inst, const char* identity);
1175
1176/**
1177 * Stops the client if it is running.
1178 *
1179 * @param inst instance handle
1180 */
1182
1183/**
1184 * Sets server address and port for client (without restarting client).
1185 *
1186 * @param inst instance handle
1187 * @param server_name server name (UTF-8 string, null terminated)
1188 * @param port port to communicate over
1189 */
1190void NT_SetServer(NT_Inst inst, const char* server_name, unsigned int port);
1191
1192/**
1193 * Sets server addresses for client (without restarting client).
1194 * The client will attempt to connect to each server in round robin fashion.
1195 *
1196 * @param inst instance handle
1197 * @param count length of the server_names and ports arrays
1198 * @param server_names array of server names (each a UTF-8 string, null
1199 * terminated)
1200 * @param ports array of ports to communicate over (one for each server)
1201 */
1202void NT_SetServerMulti(NT_Inst inst, size_t count, const char** server_names,
1203 const unsigned int* ports);
1204
1205/**
1206 * Sets server addresses and port for client (without restarting client).
1207 * Connects using commonly known robot addresses for the specified team.
1208 *
1209 * @param inst instance handle
1210 * @param team team number
1211 * @param port port to communicate over
1212 */
1213void NT_SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port);
1214
1215/**
1216 * Disconnects the client if it's running and connected. This will automatically
1217 * start reconnection attempts to the current server list.
1218 *
1219 * @param inst instance handle
1220 */
1222
1223/**
1224 * Starts requesting server address from Driver Station.
1225 * This connects to the Driver Station running on localhost to obtain the
1226 * server IP address.
1227 *
1228 * @param inst instance handle
1229 * @param port server port to use in combination with IP from DS
1230 */
1231void NT_StartDSClient(NT_Inst inst, unsigned int port);
1232
1233/**
1234 * Stops requesting server address from Driver Station.
1235 *
1236 * @param inst instance handle
1237 */
1239
1240/**
1241 * Flush local updates.
1242 *
1243 * Forces an immediate flush of all local changes to the client/server.
1244 * This does not flush to the network.
1245 *
1246 * Normally this is done on a regularly scheduled interval.
1247 *
1248 * @param inst instance handle
1249 */
1251
1252/**
1253 * Flush to network.
1254 *
1255 * Forces an immediate flush of all local entry changes to network.
1256 * Normally this is done on a regularly scheduled interval (set
1257 * by update rates on individual publishers).
1258 *
1259 * Note: flushes are rate limited to avoid excessive network traffic. If
1260 * the time between calls is too short, the flush will occur after the minimum
1261 * time elapses (rather than immediately).
1262 *
1263 * @param inst instance handle
1264 */
1266
1267/**
1268 * Get information on the currently established network connections.
1269 * If operating as a client, this will return either zero or one values.
1270 *
1271 * @param inst instance handle
1272 * @param count returns the number of elements in the array
1273 * @return array of connection information
1274 *
1275 * It is the caller's responsibility to free the array. The
1276 * NT_DisposeConnectionInfoArray function is useful for this purpose.
1277 */
1279
1280/**
1281 * Return whether or not the instance is connected to another node.
1282 *
1283 * @param inst instance handle
1284 * @return True if connected.
1285 */
1287
1288/**
1289 * Get the time offset between server time and local time. Add this value to
1290 * local time to get the estimated equivalent server time. In server mode, this
1291 * always returns a valid value of 0. In client mode, this returns the time
1292 * offset only if the client and server are connected and have exchanged
1293 * synchronization messages. Note the time offset may change over time as it is
1294 * periodically updated; to receive updates as events, add a listener to the
1295 * "time sync" event.
1296 *
1297 * @param inst instance handle
1298 * @param valid set to true if the return value is valid, false otherwise
1299 * (output)
1300 * @return Time offset in microseconds (if valid is set to true)
1301 */
1303
1304/** @} */
1305
1306/**
1307 * @defgroup ntcore_utility_cfunc Utility Functions
1308 * @{
1309 */
1310
1311/**
1312 * Frees value memory.
1313 *
1314 * @param value value to free
1315 */
1316void NT_DisposeValue(struct NT_Value* value);
1317
1318/**
1319 * Initializes a NT_Value.
1320 * Sets type to NT_UNASSIGNED and clears rest of struct.
1321 *
1322 * @param value value to initialize
1323 */
1324void NT_InitValue(struct NT_Value* value);
1325
1326/**
1327 * Frees string memory.
1328 *
1329 * @param str string to free
1330 */
1331void NT_DisposeString(struct NT_String* str);
1332
1333/**
1334 * Initializes a NT_String.
1335 * Sets length to zero and pointer to null.
1336 *
1337 * @param str string to initialize
1338 */
1339void NT_InitString(struct NT_String* str);
1340
1341/**
1342 * Frees an array of NT_Values.
1343 *
1344 * @param arr pointer to the value array to free
1345 * @param count number of elements in the array
1346 *
1347 * Note that the individual NT_Values in the array should NOT be
1348 * freed before calling this. This function will free all the values
1349 * individually.
1350 */
1351void NT_DisposeValueArray(struct NT_Value* arr, size_t count);
1352
1353/**
1354 * Disposes a connection info array.
1355 *
1356 * @param arr pointer to the array to dispose
1357 * @param count number of elements in the array
1358 */
1360
1361/**
1362 * Disposes a topic info array.
1363 *
1364 * @param arr pointer to the array to dispose
1365 * @param count number of elements in the array
1366 */
1368
1369/**
1370 * Disposes a single topic info (as returned by NT_GetTopicInfo).
1371 *
1372 * @param info pointer to the info to dispose
1373 */
1375
1376/**
1377 * Disposes an event array.
1378 *
1379 * @param arr pointer to the array to dispose
1380 * @param count number of elements in the array
1381 */
1382void NT_DisposeEventArray(struct NT_Event* arr, size_t count);
1383
1384/**
1385 * Disposes a single event.
1386 *
1387 * @param event pointer to the event to dispose
1388 */
1389void NT_DisposeEvent(struct NT_Event* event);
1390
1391/**
1392 * Returns monotonic current time in 1 us increments.
1393 * This is the same time base used for entry and connection timestamps.
1394 * This function by default simply wraps WPI_Now(), but if NT_SetNow() is
1395 * called, this function instead returns the value passed to NT_SetNow();
1396 * this can be used to reduce overhead.
1397 *
1398 * @return Timestamp
1399 */
1400int64_t NT_Now(void);
1401
1402/**
1403 * Sets the current timestamp used for timestamping values that do not
1404 * provide a timestamp (e.g. a value of 0 is passed). For consistency,
1405 * it also results in NT_Now() returning the set value. This should generally
1406 * be used only if the overhead of calling WPI_Now() is a concern.
1407 * If used, it should be called periodically with the value of WPI_Now().
1408 *
1409 * @param timestamp timestamp (1 us increments)
1410 */
1411void NT_SetNow(int64_t timestamp);
1412
1413/** @} */
1414
1415/**
1416 * @defgroup ntcore_data_logger_cfunc Data Logger Functions
1417 * @{
1418 */
1419
1420/**
1421 * Starts logging entry changes to a DataLog.
1422 *
1423 * @param inst instance handle
1424 * @param log data log object; lifetime must extend until StopEntryDataLog is
1425 * called or the instance is destroyed
1426 * @param prefix only store entries with names that start with this prefix;
1427 * the prefix is not included in the data log entry name
1428 * @param logPrefix prefix to add to data log entry names
1429 * @return Data logger handle
1430 */
1432 const char* prefix, const char* logPrefix);
1433
1434/**
1435 * Stops logging entry changes to a DataLog.
1436 *
1437 * @param logger data logger handle
1438 */
1440
1441/**
1442 * Starts logging connection changes to a DataLog.
1443 *
1444 * @param inst instance handle
1445 * @param log data log object; lifetime must extend until StopConnectionDataLog
1446 * is called or the instance is destroyed
1447 * @param name data log entry name
1448 * @return Data logger handle
1449 */
1451 struct WPI_DataLog* log,
1452 const char* name);
1453
1454/**
1455 * Stops logging connection changes to a DataLog.
1456 *
1457 * @param logger data logger handle
1458 */
1460
1461/** @} */
1462
1463/**
1464 * @defgroup ntcore_logger_cfunc Logger Functions
1465 * @{
1466 */
1467
1468/**
1469 * Add logger callback function. By default, log messages are sent to stderr;
1470 * this function sends log messages to the provided callback function instead.
1471 * The callback function will only be called for log messages with level
1472 * greater than or equal to min_level and less than or equal to max_level;
1473 * messages outside this range will be silently ignored.
1474 *
1475 * @param inst instance handle
1476 * @param min_level minimum log level
1477 * @param max_level maximum log level
1478 * @param data data pointer to pass to func
1479 * @param func listener callback function
1480 * @return Listener handle
1481 */
1482NT_Listener NT_AddLogger(NT_Inst inst, unsigned int min_level,
1483 unsigned int max_level, void* data,
1484 NT_ListenerCallback func);
1485
1486/**
1487 * Set the log level for a listener poller. Events will only be generated for
1488 * log messages with level greater than or equal to min_level and less than or
1489 * equal to max_level; messages outside this range will be silently ignored.
1490 *
1491 * @param poller poller handle
1492 * @param min_level minimum log level
1493 * @param max_level maximum log level
1494 * @return Listener handle
1495 */
1496NT_Listener NT_AddPolledLogger(NT_ListenerPoller poller, unsigned int min_level,
1497 unsigned int max_level);
1498
1499/** @} */
1500
1501/**
1502 * @defgroup ntcore_schema_cfunc Schema Functions
1503 * @{
1504 */
1505
1506/**
1507 * Returns whether there is a data schema already registered with the given
1508 * name. This does NOT perform a check as to whether the schema has already
1509 * been published by another node on the network.
1510 *
1511 * @param inst instance
1512 * @param name Name (the string passed as the data type for topics using this
1513 * schema)
1514 * @return True if schema already registered
1515 */
1517
1518/**
1519 * Registers a data schema. Data schemas provide information for how a
1520 * certain data type string can be decoded. The type string of a data schema
1521 * indicates the type of the schema itself (e.g. "protobuf" for protobuf
1522 * schemas, "struct" for struct schemas, etc). In NetworkTables, schemas are
1523 * published just like normal topics, with the name being generated from the
1524 * provided name: "/.schema/<name>". Duplicate calls to this function with
1525 * the same name are silently ignored.
1526 *
1527 * @param inst instance
1528 * @param name Name (the string passed as the data type for topics using this
1529 * schema)
1530 * @param type Type of schema (e.g. "protobuf", "struct", etc)
1531 * @param schema Schema data
1532 * @param schemaSize Size of schema data
1533 */
1534void NT_AddSchema(NT_Inst inst, const char* name, const char* type,
1535 const uint8_t* schema, size_t schemaSize);
1536
1537/** @} */
1538
1539/**
1540 * @defgroup ntcore_interop_cfunc Interop Utility Functions
1541 * @{
1542 */
1543
1544/**
1545 * @defgroup ntcore_memoryallocators_cfunc Memory Allocators
1546 * @{
1547 */
1548
1549/**
1550 * Allocates an array of chars.
1551 * Note that the size is the number of elements, and not the
1552 * specific number of bytes to allocate. That is calculated internally.
1553 *
1554 * @param size the number of elements the array will contain
1555 * @return the allocated char array
1556 *
1557 * After use, the array should be freed using the NT_FreeCharArray()
1558 * function.
1559 */
1560char* NT_AllocateCharArray(size_t size);
1561
1562/**
1563 * Allocates an array of booleans.
1564 * Note that the size is the number of elements, and not the
1565 * specific number of bytes to allocate. That is calculated internally.
1566 *
1567 * @param size the number of elements the array will contain
1568 * @return the allocated boolean array
1569 *
1570 * After use, the array should be freed using the NT_FreeBooleanArray()
1571 * function.
1572 */
1574
1575/**
1576 * Allocates an array of ints.
1577 * Note that the size is the number of elements, and not the
1578 * specific number of bytes to allocate. That is calculated internally.
1579 *
1580 * @param size the number of elements the array will contain
1581 * @return the allocated double array
1582 *
1583 * After use, the array should be freed using the NT_FreeIntArray()
1584 * function.
1585 */
1586int64_t* NT_AllocateIntegerArray(size_t size);
1587
1588/**
1589 * Allocates an array of floats.
1590 * Note that the size is the number of elements, and not the
1591 * specific number of bytes to allocate. That is calculated internally.
1592 *
1593 * @param size the number of elements the array will contain
1594 * @return the allocated double array
1595 *
1596 * After use, the array should be freed using the NT_FreeFloatArray()
1597 * function.
1598 */
1599float* NT_AllocateFloatArray(size_t size);
1600
1601/**
1602 * Allocates an array of doubles.
1603 * Note that the size is the number of elements, and not the
1604 * specific number of bytes to allocate. That is calculated internally.
1605 *
1606 * @param size the number of elements the array will contain
1607 * @return the allocated double array
1608 *
1609 * After use, the array should be freed using the NT_FreeDoubleArray()
1610 * function.
1611 */
1612double* NT_AllocateDoubleArray(size_t size);
1613
1614/**
1615 * Allocates an array of NT_Strings.
1616 * Note that the size is the number of elements, and not the
1617 * specific number of bytes to allocate. That is calculated internally.
1618 *
1619 * @param size the number of elements the array will contain
1620 * @return the allocated NT_String array
1621 *
1622 * After use, the array should be freed using the NT_FreeStringArray()
1623 * function.
1624 */
1626
1627/**
1628 * Frees an array of chars.
1629 *
1630 * @param v_char pointer to the char array to free
1631 */
1632void NT_FreeCharArray(char* v_char);
1633
1634/**
1635 * Frees an array of booleans.
1636 *
1637 * @param v_boolean pointer to the boolean array to free
1638 */
1640
1641/**
1642 * Frees an array of ints.
1643 *
1644 * @param v_int pointer to the int array to free
1645 */
1646void NT_FreeIntegerArray(int64_t* v_int);
1647
1648/**
1649 * Frees an array of floats.
1650 *
1651 * @param v_float pointer to the float array to free
1652 */
1653void NT_FreeFloatArray(float* v_float);
1654
1655/**
1656 * Frees an array of doubles.
1657 *
1658 * @param v_double pointer to the double array to free
1659 */
1660void NT_FreeDoubleArray(double* v_double);
1661
1662/**
1663 * Frees an array of NT_Strings.
1664 *
1665 * @param v_string pointer to the string array to free
1666 * @param arr_size size of the string array to free
1667 *
1668 * Note that the individual NT_Strings in the array should NOT be
1669 * freed before calling this. This function will free all the strings
1670 * individually.
1671 */
1672void NT_FreeStringArray(struct NT_String* v_string, size_t arr_size);
1673
1674/** @} */
1675
1676/**
1677 * @defgroup ntcore_typedgetters_cfunc Typed Getters
1678 * @{
1679 */
1680
1681/**
1682 * Returns the type of an NT_Value struct.
1683 * Note that one of the type options is "unassigned".
1684 *
1685 * @param value The NT_Value struct to get the type from.
1686 * @return The type of the value, or unassigned if null.
1687 */
1688enum NT_Type NT_GetValueType(const struct NT_Value* value);
1689
1690/**
1691 * Returns the boolean from the NT_Value.
1692 * If the NT_Value is null, or is assigned to a different type, returns 0.
1693 *
1694 * @param value NT_Value struct to get the boolean from
1695 * @param last_change returns time in ms since the last change in the value
1696 * @param v_boolean returns the boolean assigned to the name
1697 * @return 1 if successful, or 0 if value is null or not a boolean
1698 */
1699NT_Bool NT_GetValueBoolean(const struct NT_Value* value, uint64_t* last_change,
1700 NT_Bool* v_boolean);
1701
1702/**
1703 * Returns the int from the NT_Value.
1704 * If the NT_Value is null, or is assigned to a different type, returns 0.
1705 *
1706 * @param value NT_Value struct to get the int from
1707 * @param last_change returns time in ms since the last change in the value
1708 * @param v_int returns the int assigned to the name
1709 * @return 1 if successful, or 0 if value is null or not an int
1710 */
1711NT_Bool NT_GetValueInteger(const struct NT_Value* value, uint64_t* last_change,
1712 int64_t* v_int);
1713
1714/**
1715 * Returns the float from the NT_Value.
1716 * If the NT_Value is null, or is assigned to a different type, returns 0.
1717 *
1718 * @param value NT_Value struct to get the float from
1719 * @param last_change returns time in ms since the last change in the value
1720 * @param v_float returns the float assigned to the name
1721 * @return 1 if successful, or 0 if value is null or not a float
1722 */
1723NT_Bool NT_GetValueFloat(const struct NT_Value* value, uint64_t* last_change,
1724 float* v_float);
1725
1726/**
1727 * Returns the double from the NT_Value.
1728 * If the NT_Value is null, or is assigned to a different type, returns 0.
1729 *
1730 * @param value NT_Value struct to get the double from
1731 * @param last_change returns time in ms since the last change in the value
1732 * @param v_double returns the double assigned to the name
1733 * @return 1 if successful, or 0 if value is null or not a double
1734 */
1735NT_Bool NT_GetValueDouble(const struct NT_Value* value, uint64_t* last_change,
1736 double* v_double);
1737
1738/**
1739 * Returns a copy of the string from the NT_Value.
1740 * If the NT_Value is null, or is assigned to a different type, returns 0.
1741 *
1742 * @param value NT_Value struct to get the string from
1743 * @param last_change returns time in ms since the last change in the value
1744 * @param str_len returns the length of the string
1745 * @return pointer to the string (UTF-8), or null if error
1746 *
1747 * It is the caller's responsibility to free the string once its no longer
1748 * needed. The NT_FreeCharArray() function is useful for this purpose. The
1749 * returned string is a copy of the string in the value, and must be freed
1750 * separately.
1751 */
1752char* NT_GetValueString(const struct NT_Value* value, uint64_t* last_change,
1753 size_t* str_len);
1754
1755/**
1756 * Returns a copy of the raw value from the NT_Value.
1757 * If the NT_Value is null, or is assigned to a different type, returns null.
1758 *
1759 * @param value NT_Value struct to get the string from
1760 * @param last_change returns time in ms since the last change in the value
1761 * @param raw_len returns the length of the string
1762 * @return pointer to the raw value (UTF-8), or null if error
1763 *
1764 * It is the caller's responsibility to free the raw value once its no longer
1765 * needed. The NT_FreeCharArray() function is useful for this purpose. The
1766 * returned string is a copy of the string in the value, and must be freed
1767 * separately.
1768 */
1769uint8_t* NT_GetValueRaw(const struct NT_Value* value, uint64_t* last_change,
1770 size_t* raw_len);
1771
1772/**
1773 * Returns a copy of the boolean array from the NT_Value.
1774 * If the NT_Value is null, or is assigned to a different type, returns null.
1775 *
1776 * @param value NT_Value struct to get the boolean array from
1777 * @param last_change returns time in ms since the last change in the value
1778 * @param arr_size returns the number of elements in the array
1779 * @return pointer to the boolean array, or null if error
1780 *
1781 * It is the caller's responsibility to free the array once its no longer
1782 * needed. The NT_FreeBooleanArray() function is useful for this purpose.
1783 * The returned array is a copy of the array in the value, and must be
1784 * freed separately.
1785 */
1787 uint64_t* last_change, size_t* arr_size);
1788
1789/**
1790 * Returns a copy of the int array from the NT_Value.
1791 * If the NT_Value is null, or is assigned to a different type, returns null.
1792 *
1793 * @param value NT_Value struct to get the int array from
1794 * @param last_change returns time in ms since the last change in the value
1795 * @param arr_size returns the number of elements in the array
1796 * @return pointer to the int array, or null if error
1797 *
1798 * It is the caller's responsibility to free the array once its no longer
1799 * needed. The NT_FreeIntArray() function is useful for this purpose.
1800 * The returned array is a copy of the array in the value, and must be
1801 * freed separately.
1802 */
1803int64_t* NT_GetValueIntegerArray(const struct NT_Value* value,
1804 uint64_t* last_change, size_t* arr_size);
1805
1806/**
1807 * Returns a copy of the float array from the NT_Value.
1808 * If the NT_Value is null, or is assigned to a different type, returns null.
1809 *
1810 * @param value NT_Value struct to get the float array from
1811 * @param last_change returns time in ms since the last change in the value
1812 * @param arr_size returns the number of elements in the array
1813 * @return pointer to the float array, or null if error
1814 *
1815 * It is the caller's responsibility to free the array once its no longer
1816 * needed. The NT_FreeFloatArray() function is useful for this purpose.
1817 * The returned array is a copy of the array in the value, and must be
1818 * freed separately.
1819 */
1820float* NT_GetValueFloatArray(const struct NT_Value* value,
1821 uint64_t* last_change, size_t* arr_size);
1822
1823/**
1824 * Returns a copy of the double array from the NT_Value.
1825 * If the NT_Value is null, or is assigned to a different type, returns null.
1826 *
1827 * @param value NT_Value struct to get the double array from
1828 * @param last_change returns time in ms since the last change in the value
1829 * @param arr_size returns the number of elements in the array
1830 * @return pointer to the double array, or null if error
1831 *
1832 * It is the caller's responsibility to free the array once its no longer
1833 * needed. The NT_FreeDoubleArray() function is useful for this purpose.
1834 * The returned array is a copy of the array in the value, and must be
1835 * freed separately.
1836 */
1837double* NT_GetValueDoubleArray(const struct NT_Value* value,
1838 uint64_t* last_change, size_t* arr_size);
1839
1840/**
1841 * Returns a copy of the NT_String array from the NT_Value.
1842 * If the NT_Value is null, or is assigned to a different type, returns null.
1843 *
1844 * @param value NT_Value struct to get the NT_String array from
1845 * @param last_change returns time in ms since the last change in the value
1846 * @param arr_size returns the number of elements in the array
1847 * @return pointer to the NT_String array, or null if error
1848 *
1849 * It is the caller's responsibility to free the array once its no longer
1850 * needed. The NT_FreeStringArray() function is useful for this purpose.
1851 * The returned array is a copy of the array in the value, and must be
1852 * freed separately. Note that the individual NT_Strings should not be freed,
1853 * but the entire array should be freed at once. The NT_FreeStringArray()
1854 * function will free all the NT_Strings.
1855 */
1856struct NT_String* NT_GetValueStringArray(const struct NT_Value* value,
1857 uint64_t* last_change,
1858 size_t* arr_size);
1859
1860/** @} */
1861/** @} */
1862/** @} */
1863
1864/**
1865 * @defgroup ntcore_c_meta_api ntcore C meta-topic API
1866 *
1867 * Meta-topic decoders for C.
1868 *
1869 * @{
1870 */
1871
1872/**
1873 * Subscriber options. Different from PubSubOptions in this reflects only
1874 * options that are sent over the network.
1875 */
1877 double periodic;
1881};
1882
1883/**
1884 * Topic publisher (as published via `$pub$<topic>`).
1885 */
1888 uint64_t pubuid;
1889};
1890
1891/**
1892 * Topic subscriber (as published via `$sub$<topic>`).
1893 */
1896 uint64_t subuid;
1898};
1899
1900/**
1901 * Client publisher (as published via `$clientpub$<client>` or `$serverpub`).
1902 */
1904 int64_t uid;
1906};
1907
1908/**
1909 * Client subscriber (as published via `$clientsub$<client>` or `$serversub`).
1910 */
1912 int64_t uid;
1916};
1917
1918/**
1919 * Client (as published via `$clients`).
1920 */
1924 uint16_t version;
1925};
1926
1927/**
1928 * Decodes `$pub$<topic>` meta-topic data.
1929 *
1930 * @param data data contents
1931 * @param size size of data contents
1932 * @param count number of elements in returned array (output)
1933 * @return Array of TopicPublishers, or NULL on decoding error.
1934 */
1936 const uint8_t* data, size_t size, size_t* count);
1937
1938/**
1939 * Decodes `$sub$<topic>` meta-topic data.
1940 *
1941 * @param data data contents
1942 * @param size size of data contents
1943 * @param count number of elements in returned array (output)
1944 * @return Array of TopicSubscribers, or NULL on decoding error.
1945 */
1947 const uint8_t* data, size_t size, size_t* count);
1948
1949/**
1950 * Decodes `$clientpub$<topic>` meta-topic data.
1951 *
1952 * @param data data contents
1953 * @param size size of data contents
1954 * @param count number of elements in returned array (output)
1955 * @return Array of ClientPublishers, or NULL on decoding error.
1956 */
1958 const uint8_t* data, size_t size, size_t* count);
1959
1960/**
1961 * Decodes `$clientsub$<topic>` meta-topic data.
1962 *
1963 * @param data data contents
1964 * @param size size of data contents
1965 * @param count number of elements in returned array (output)
1966 * @return Array of ClientSubscribers, or NULL on decoding error.
1967 */
1969 const uint8_t* data, size_t size, size_t* count);
1970
1971/**
1972 * Decodes `$clients` meta-topic data.
1973 *
1974 * @param data data contents
1975 * @param size size of data contents
1976 * @param count number of elements in returned array (output)
1977 * @return Array of Clients, or NULL on decoding error.
1978 */
1979struct NT_Meta_Client* NT_Meta_DecodeClients(const uint8_t* data, size_t size,
1980 size_t* count);
1981
1982/**
1983 * Frees an array of NT_Meta_TopicPublisher.
1984 *
1985 * @param arr pointer to the array to free
1986 * @param count size of the array to free
1987 */
1989 size_t count);
1990
1991/**
1992 * Frees an array of NT_Meta_TopicSubscriber.
1993 *
1994 * @param arr pointer to the array to free
1995 * @param count size of the array to free
1996 */
1998 size_t count);
1999
2000/**
2001 * Frees an array of NT_Meta_ClientPublisher.
2002 *
2003 * @param arr pointer to the array to free
2004 * @param count size of the array to free
2005 */
2007 size_t count);
2008
2009/**
2010 * Frees an array of NT_Meta_ClientSubscriber.
2011 *
2012 * @param arr pointer to the array to free
2013 * @param count size of the array to free
2014 */
2016 size_t count);
2017
2018/**
2019 * Frees an array of NT_Meta_Client.
2020 *
2021 * @param arr pointer to the array to free
2022 * @param count size of the array to free
2023 */
2024void NT_Meta_FreeClients(struct NT_Meta_Client* arr, size_t count);
2025
2026/** @} */
2027
2028#ifdef __cplusplus
2029} // extern "C"
2030#endif
2031
2032#include "ntcore_c_types.h"
dimensionless::scalar_t log(const ScalarUnit x) noexcept
Compute natural logarithm.
Definition: math.h:349
void NT_UnsubscribeMultiple(NT_MultiSubscriber sub)
Unsubscribes a multi-subscriber.
NT_MultiSubscriber NT_SubscribeMultiple(NT_Inst inst, const struct NT_String *prefixes, size_t prefixes_len, const struct NT_PubSubOptions *options)
Subscribes to multiple topics based on one or more topic name prefixes.
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_EntryFlags
NetworkTables entry flags.
Definition: ntcore_c.h:68
int NT_Bool
Typedefs.
Definition: ntcore_c.h:30
NT_LogLevel
NetworkTables logging levels.
Definition: ntcore_c.h:75
NT_NetworkMode
Client/server modes.
Definition: ntcore_c.h:88
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_EventFlags
Event notification flags.
Definition: ntcore_c.h:98
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_RETAINED
Definition: ntcore_c.h:70
@ NT_PERSISTENT
Definition: ntcore_c.h:69
@ NT_UNCACHED
Definition: ntcore_c.h:71
@ NT_LOG_DEBUG4
Definition: ntcore_c.h:84
@ NT_LOG_WARNING
Definition: ntcore_c.h:78
@ NT_LOG_INFO
Definition: ntcore_c.h:79
@ NT_LOG_DEBUG2
Definition: ntcore_c.h:82
@ NT_LOG_DEBUG
Definition: ntcore_c.h:80
@ NT_LOG_CRITICAL
Definition: ntcore_c.h:76
@ NT_LOG_ERROR
Definition: ntcore_c.h:77
@ NT_LOG_DEBUG3
Definition: ntcore_c.h:83
@ NT_LOG_DEBUG1
Definition: ntcore_c.h:81
@ NT_NET_MODE_STARTING
Definition: ntcore_c.h:93
@ NT_NET_MODE_LOCAL
Definition: ntcore_c.h:94
@ NT_NET_MODE_CLIENT4
Definition: ntcore_c.h:92
@ NT_NET_MODE_CLIENT3
Definition: ntcore_c.h:91
@ NT_NET_MODE_SERVER
Definition: ntcore_c.h:90
@ NT_NET_MODE_NONE
Definition: ntcore_c.h:89
@ NT_DOUBLE
Definition: ntcore_c.h:54
@ NT_BOOLEAN
Definition: ntcore_c.h:53
@ NT_DOUBLE_ARRAY
Definition: ntcore_c.h:58
@ NT_STRING
Definition: ntcore_c.h:55
@ NT_FLOAT_ARRAY
Definition: ntcore_c.h:64
@ NT_RPC
Definition: ntcore_c.h:60
@ NT_INTEGER
Definition: ntcore_c.h:61
@ NT_BOOLEAN_ARRAY
Definition: ntcore_c.h:57
@ NT_FLOAT
Definition: ntcore_c.h:62
@ NT_STRING_ARRAY
Definition: ntcore_c.h:59
@ NT_INTEGER_ARRAY
Definition: ntcore_c.h:63
@ NT_UNASSIGNED
Definition: ntcore_c.h:52
@ NT_RAW
Definition: ntcore_c.h:56
@ NT_EVENT_VALUE_ALL
Topic value updated (network or local).
Definition: ntcore_c.h:121
@ 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_TOPIC
Any topic event (publish, unpublish, or properties changed).
Definition: ntcore_c.h:115
@ NT_EVENT_CONNECTION
Any connection event (connect or disconnect).
Definition: ntcore_c.h:107
@ 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
struct NT_Meta_ClientSubscriber * NT_Meta_DecodeClientSubscribers(const uint8_t *data, size_t size, size_t *count)
Decodes $clientsub$<topic> meta-topic data.
struct NT_Meta_ClientPublisher * NT_Meta_DecodeClientPublishers(const uint8_t *data, size_t size, size_t *count)
Decodes $clientpub$<topic> meta-topic data.
struct NT_Meta_TopicPublisher * NT_Meta_DecodeTopicPublishers(const uint8_t *data, size_t size, size_t *count)
Decodes $pub$<topic> meta-topic data.
void NT_Meta_FreeClientSubscribers(struct NT_Meta_ClientSubscriber *arr, size_t count)
Frees an array of NT_Meta_ClientSubscriber.
void NT_Meta_FreeTopicSubscribers(struct NT_Meta_TopicSubscriber *arr, size_t count)
Frees an array of NT_Meta_TopicSubscriber.
struct NT_Meta_TopicSubscriber * NT_Meta_DecodeTopicSubscribers(const uint8_t *data, size_t size, size_t *count)
Decodes $sub$<topic> meta-topic data.
void NT_Meta_FreeClientPublishers(struct NT_Meta_ClientPublisher *arr, size_t count)
Frees an array of NT_Meta_ClientPublisher.
void NT_Meta_FreeClients(struct NT_Meta_Client *arr, size_t count)
Frees an array of NT_Meta_Client.
void NT_Meta_FreeTopicPublishers(struct NT_Meta_TopicPublisher *arr, size_t count)
Frees an array of NT_Meta_TopicPublisher.
struct NT_Meta_Client * NT_Meta_DecodeClients(const uint8_t *data, size_t size, size_t *count)
Decodes $clients meta-topic data.
void NT_StopConnectionDataLog(NT_ConnectionDataLogger logger)
Stops logging connection changes to a DataLog.
NT_DataLogger NT_StartEntryDataLog(NT_Inst inst, struct WPI_DataLog *log, const char *prefix, const char *logPrefix)
Starts logging entry changes to a DataLog.
void NT_StopEntryDataLog(NT_DataLogger logger)
Stops logging entry changes to a DataLog.
NT_ConnectionDataLogger NT_StartConnectionDataLog(NT_Inst inst, struct WPI_DataLog *log, const char *name)
Starts logging connection changes to a DataLog.
void NT_DestroyInstance(NT_Inst inst)
Destroy an instance.
NT_Inst NT_CreateInstance(void)
Create an instance.
NT_Inst NT_GetDefaultInstance(void)
Get default instance.
NT_Inst NT_GetInstanceFromHandle(NT_Handle handle)
Get instance handle from another handle.
NT_Listener NT_AddPolledListenerSingle(NT_ListenerPoller poller, const char *prefix, size_t prefix_len, unsigned int mask)
Creates a polled topic listener.
void NT_RemoveListener(NT_Listener listener)
Removes a listener.
void(* NT_ListenerCallback)(void *data, const struct NT_Event *event)
Event listener callback function.
Definition: ntcore_c.h:939
NT_ListenerPoller NT_CreateListenerPoller(NT_Inst inst)
Creates a listener poller.
NT_Listener NT_AddListenerMultiple(NT_Inst inst, const struct NT_String *prefixes, size_t prefixes_len, unsigned int mask, void *data, NT_ListenerCallback callback)
Create a listener for changes to topics with names that start with any of the given prefixes.
NT_Listener NT_AddListenerSingle(NT_Inst inst, const char *prefix, size_t prefix_len, unsigned int mask, void *data, NT_ListenerCallback callback)
Create a listener for changes to topics with names that start with the given prefix.
struct NT_Event * NT_ReadListenerQueue(NT_ListenerPoller poller, size_t *len)
Read notifications.
NT_Listener NT_AddPolledListener(NT_ListenerPoller poller, NT_Handle handle, unsigned int mask)
Creates a polled listener.
void NT_DestroyListenerPoller(NT_ListenerPoller poller)
Destroys a listener poller.
NT_Listener NT_AddListener(NT_Handle handle, unsigned int mask, void *data, NT_ListenerCallback callback)
Create a listener.
NT_Bool NT_WaitForListenerQueue(NT_Handle handle, double timeout)
Wait for the listener queue to be empty.
NT_Listener NT_AddPolledListenerMultiple(NT_ListenerPoller poller, const struct NT_String *prefixes, size_t prefixes_len, unsigned int mask)
Creates a polled topic listener.
NT_Listener NT_AddPolledLogger(NT_ListenerPoller poller, unsigned int min_level, unsigned int max_level)
Set the log level for a listener poller.
NT_Listener NT_AddLogger(NT_Inst inst, unsigned int min_level, unsigned int max_level, void *data, NT_ListenerCallback func)
Add logger callback function.
float * NT_AllocateFloatArray(size_t size)
Allocates an array of floats.
void NT_FreeIntegerArray(int64_t *v_int)
Frees an array of ints.
void NT_FreeFloatArray(float *v_float)
Frees an array of floats.
void NT_FreeStringArray(struct NT_String *v_string, size_t arr_size)
Frees an array of NT_Strings.
void NT_FreeBooleanArray(NT_Bool *v_boolean)
Frees an array of booleans.
NT_Bool * NT_AllocateBooleanArray(size_t size)
Allocates an array of booleans.
void NT_FreeDoubleArray(double *v_double)
Frees an array of doubles.
struct NT_String * NT_AllocateStringArray(size_t size)
Allocates an array of NT_Strings.
double * NT_AllocateDoubleArray(size_t size)
Allocates an array of doubles.
void NT_FreeCharArray(char *v_char)
Frees an array of chars.
int64_t * NT_AllocateIntegerArray(size_t size)
Allocates an array of ints.
char * NT_AllocateCharArray(size_t size)
Allocates an array of chars.
void NT_Disconnect(NT_Inst inst)
Disconnects the client if it's running and connected.
void NT_StartLocal(NT_Inst inst)
Starts local-only operation.
void NT_StartServer(NT_Inst inst, const char *persist_filename, const char *listen_address, unsigned int port3, unsigned int port4)
Starts a server using the specified filename, listening address, and port.
void NT_StopClient(NT_Inst inst)
Stops the client if it is running.
void NT_StartClient4(NT_Inst inst, const char *identity)
Starts a NT4 client.
void NT_StopServer(NT_Inst inst)
Stops the server if it is running.
unsigned int NT_GetNetworkMode(NT_Inst inst)
Get the current network mode.
void NT_StopLocal(NT_Inst inst)
Stops local-only operation.
void NT_SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port)
Sets server addresses and port for client (without restarting client).
void NT_Flush(NT_Inst inst)
Flush to network.
int64_t NT_GetServerTimeOffset(NT_Inst inst, NT_Bool *valid)
Get the time offset between server time and local time.
void NT_FlushLocal(NT_Inst inst)
Flush local updates.
void NT_SetServer(NT_Inst inst, const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
void NT_StartClient3(NT_Inst inst, const char *identity)
Starts a NT3 client.
NT_Bool NT_IsConnected(NT_Inst inst)
Return whether or not the instance is connected to another node.
void NT_StartDSClient(NT_Inst inst, unsigned int port)
Starts requesting server address from Driver Station.
void NT_StopDSClient(NT_Inst inst)
Stops requesting server address from Driver Station.
struct NT_ConnectionInfo * NT_GetConnections(NT_Inst inst, size_t *count)
Get information on the currently established network connections.
void NT_SetServerMulti(NT_Inst inst, size_t count, const char **server_names, const unsigned int *ports)
Sets server addresses for client (without restarting client).
void NT_AddSchema(NT_Inst inst, const char *name, const char *type, const uint8_t *schema, size_t schemaSize)
Registers a data schema.
NT_Bool NT_HasSchema(NT_Inst inst, const char *name)
Returns whether there is a data schema already registered with the given name.
NT_Bool NT_SetEntryValue(NT_Entry entry, const struct NT_Value *value)
Set Entry Value.
void NT_GetEntryValue(NT_Entry entry, struct NT_Value *value)
Get Entry Value.
void NT_GetEntryValueType(NT_Entry entry, unsigned int types, struct NT_Value *value)
Get Entry Value.
enum NT_Type NT_GetEntryType(NT_Entry entry)
Gets the type for the specified key, or unassigned if non existent.
struct NT_Value * NT_ReadQueueValue(NT_Handle subentry, size_t *count)
Read Entry Queue.
NT_Bool NT_SetDefaultEntryValue(NT_Entry entry, const struct NT_Value *default_value)
Set Default Entry Value.
unsigned int NT_GetEntryFlags(NT_Entry entry)
Get Entry Flags.
uint64_t NT_GetEntryLastChange(NT_Entry entry)
Gets the last time the entry was changed.
struct NT_Value * NT_ReadQueueValueType(NT_Handle subentry, unsigned int types, size_t *count)
Read Entry Queue.
void NT_SetEntryFlags(NT_Entry entry, unsigned int flags)
Set Entry Flags.
char * NT_GetEntryName(NT_Entry entry, size_t *name_len)
Gets the name of the specified entry.
NT_Entry NT_GetEntry(NT_Inst inst, const char *name, size_t name_len)
Get Entry Handle.
NT_Entry NT_GetEntryEx(NT_Topic topic, enum NT_Type type, const char *typeStr, const struct NT_PubSubOptions *options)
Creates a new entry (subscriber and weak publisher) to a topic.
struct NT_TopicInfo * NT_GetTopicInfos(NT_Inst inst, const char *prefix, size_t prefix_len, unsigned int types, size_t *count)
Get Topics.
char * NT_GetTopicProperty(NT_Topic topic, const char *name, size_t *len)
Gets the current value of a property (as a JSON string).
void NT_SetTopicRetained(NT_Topic topic, NT_Bool value)
Sets the retained property of a topic.
NT_Subscriber NT_Subscribe(NT_Topic topic, enum NT_Type type, const char *typeStr, const struct NT_PubSubOptions *options)
Creates a new subscriber to value changes on a topic.
NT_Bool NT_SetTopicProperty(NT_Topic topic, const char *name, const char *value)
Sets a property value.
NT_Bool NT_GetTopicExists(NT_Handle handle)
Determine if topic exists (e.g.
NT_Topic NT_GetTopicFromHandle(NT_Handle pubsubentry)
Gets the topic handle from an entry/subscriber/publisher handle.
void NT_Release(NT_Handle pubsubentry)
Stops entry/subscriber/publisher.
void NT_SetTopicPersistent(NT_Topic topic, NT_Bool value)
Sets the persistent property of a topic.
void NT_ReleaseEntry(NT_Entry entry)
Stops entry subscriber/publisher.
NT_Topic * NT_GetTopicsStr(NT_Inst inst, const char *prefix, size_t prefix_len, const char *const *types, size_t types_len, size_t *count)
Get Published Topic Handles.
NT_Bool NT_GetTopicInfo(NT_Topic topic, struct NT_TopicInfo *info)
Gets Topic Information.
NT_Publisher NT_Publish(NT_Topic topic, enum NT_Type type, const char *typeStr, const struct NT_PubSubOptions *options)
Creates a new publisher to a topic.
NT_Topic * NT_GetTopics(NT_Inst inst, const char *prefix, size_t prefix_len, unsigned int types, size_t *count)
Get Published Topic Handles.
void NT_DeleteTopicProperty(NT_Topic topic, const char *name)
Deletes a property.
char * NT_GetTopicTypeString(NT_Topic topic, size_t *type_len)
Gets the type string for the specified topic.
NT_Publisher NT_PublishEx(NT_Topic topic, enum NT_Type type, const char *typeStr, const char *properties, const struct NT_PubSubOptions *options)
Creates a new publisher to a topic.
struct NT_TopicInfo * NT_GetTopicInfosStr(NT_Inst inst, const char *prefix, size_t prefix_len, const char *const *types, size_t types_len, size_t *count)
Get Topics.
NT_Bool NT_GetTopicCached(NT_Topic topic)
Gets the cached property of a topic.
void NT_SetTopicCached(NT_Topic topic, NT_Bool value)
Sets the cached property of a topic.
NT_Bool NT_GetTopicPersistent(NT_Topic topic)
Gets the persistent property of a topic.
NT_Topic NT_GetTopic(NT_Inst inst, const char *name, size_t name_len)
Gets Topic Handle.
NT_Bool NT_SetTopicProperties(NT_Topic topic, const char *properties)
Updates multiple topic properties.
NT_Bool NT_GetTopicRetained(NT_Topic topic)
Gets the retained property of a topic.
char * NT_GetTopicProperties(NT_Topic topic, size_t *len)
Gets all topic properties as a JSON string.
void NT_Unpublish(NT_Handle pubentry)
Stops publisher.
enum NT_Type NT_GetTopicType(NT_Topic topic)
Gets the type for the specified topic, or unassigned if non existent.
char * NT_GetTopicName(NT_Topic topic, size_t *name_len)
Gets the name of the specified topic.
void NT_Unsubscribe(NT_Subscriber sub)
Stops subscriber.
int64_t * NT_GetValueIntegerArray(const struct NT_Value *value, uint64_t *last_change, size_t *arr_size)
Returns a copy of the int array from the NT_Value.
enum NT_Type NT_GetValueType(const struct NT_Value *value)
Returns the type of an NT_Value struct.
double * NT_GetValueDoubleArray(const struct NT_Value *value, uint64_t *last_change, size_t *arr_size)
Returns a copy of the double array from the NT_Value.
float * NT_GetValueFloatArray(const struct NT_Value *value, uint64_t *last_change, size_t *arr_size)
Returns a copy of the float array from the NT_Value.
NT_Bool * NT_GetValueBooleanArray(const struct NT_Value *value, uint64_t *last_change, size_t *arr_size)
Returns a copy of the boolean array from the NT_Value.
NT_Bool NT_GetValueFloat(const struct NT_Value *value, uint64_t *last_change, float *v_float)
Returns the float from the NT_Value.
NT_Bool NT_GetValueDouble(const struct NT_Value *value, uint64_t *last_change, double *v_double)
Returns the double from the NT_Value.
char * NT_GetValueString(const struct NT_Value *value, uint64_t *last_change, size_t *str_len)
Returns a copy of the string from the NT_Value.
NT_Bool NT_GetValueBoolean(const struct NT_Value *value, uint64_t *last_change, NT_Bool *v_boolean)
Returns the boolean from the NT_Value.
uint8_t * NT_GetValueRaw(const struct NT_Value *value, uint64_t *last_change, size_t *raw_len)
Returns a copy of the raw value from the NT_Value.
NT_Bool NT_GetValueInteger(const struct NT_Value *value, uint64_t *last_change, int64_t *v_int)
Returns the int from the NT_Value.
struct NT_String * NT_GetValueStringArray(const struct NT_Value *value, uint64_t *last_change, size_t *arr_size)
Returns a copy of the NT_String array from the NT_Value.
void NT_SetNow(int64_t timestamp)
Sets the current timestamp used for timestamping values that do not provide a timestamp (e....
void NT_InitValue(struct NT_Value *value)
Initializes a NT_Value.
void NT_DisposeTopicInfoArray(struct NT_TopicInfo *arr, size_t count)
Disposes a topic info array.
void NT_InitString(struct NT_String *str)
Initializes a NT_String.
void NT_DisposeString(struct NT_String *str)
Frees string memory.
void NT_DisposeTopicInfo(struct NT_TopicInfo *info)
Disposes a single topic info (as returned by NT_GetTopicInfo).
void NT_DisposeConnectionInfoArray(struct NT_ConnectionInfo *arr, size_t count)
Disposes a connection info array.
int64_t NT_Now(void)
Returns monotonic current time in 1 us increments.
void NT_DisposeValue(struct NT_Value *value)
Frees value memory.
void NT_DisposeEventArray(struct NT_Event *arr, size_t count)
Disposes an event array.
void NT_DisposeValueArray(struct NT_Value *arr, size_t count)
Frees an array of NT_Values.
void NT_DisposeEvent(struct NT_Event *event)
Disposes a single event.
constexpr auto count() -> size_t
Definition: core.h:1203
type
Definition: core.h:556
constexpr const char * name(const T &)
NetworkTables Connection Information.
Definition: ntcore_c.h:206
struct NT_String remote_ip
The IP address of the remote node.
Definition: ntcore_c.h:213
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_c.h:216
uint64_t last_update
The last time any update was received from the remote node (same scale as returned by nt::Now()).
Definition: ntcore_c.h:222
unsigned int protocol_version
The protocol version being used for this connection.
Definition: ntcore_c.h:228
struct NT_String remote_id
The remote identifier (as set on the remote node by NT_StartClient4().
Definition: ntcore_c.h:210
NetworkTables event.
Definition: ntcore_c.h:277
struct NT_LogMessage logMessage
Definition: ntcore_c.h:297
NT_Handle listener
Listener that triggered this event.
Definition: ntcore_c.h:279
unsigned int flags
Event flags (NT_EventFlags).
Definition: ntcore_c.h:290
struct NT_TopicInfo topicInfo
Definition: ntcore_c.h:295
struct NT_ConnectionInfo connInfo
Definition: ntcore_c.h:294
struct NT_TimeSyncEventData timeSyncData
Definition: ntcore_c.h:298
union NT_Event::@8 data
Event data; content depends on flags.
struct NT_ValueEventData valueData
Definition: ntcore_c.h:296
NetworkTables log message.
Definition: ntcore_c.h:244
unsigned int level
Log level of the message.
Definition: ntcore_c.h:246
char * filename
The filename of the source file that generated the message.
Definition: ntcore_c.h:249
char * message
The message.
Definition: ntcore_c.h:255
unsigned int line
The line number in the source file that generated the message.
Definition: ntcore_c.h:252
Client (as published via $clients).
Definition: ntcore_c.h:1921
struct NT_String conn
Definition: ntcore_c.h:1923
struct NT_String id
Definition: ntcore_c.h:1922
uint16_t version
Definition: ntcore_c.h:1924
Client publisher (as published via $clientpub$<client> or $serverpub).
Definition: ntcore_c.h:1903
struct NT_String topic
Definition: ntcore_c.h:1905
int64_t uid
Definition: ntcore_c.h:1904
Client subscriber (as published via $clientsub$<client> or $serversub).
Definition: ntcore_c.h:1911
struct NT_Meta_SubscriberOptions options
Definition: ntcore_c.h:1915
struct NT_String * topics
Definition: ntcore_c.h:1914
int64_t uid
Definition: ntcore_c.h:1912
size_t topicsCount
Definition: ntcore_c.h:1913
Subscriber options.
Definition: ntcore_c.h:1876
NT_Bool prefixMatch
Definition: ntcore_c.h:1880
double periodic
Definition: ntcore_c.h:1877
NT_Bool sendAll
Definition: ntcore_c.h:1879
NT_Bool topicsOnly
Definition: ntcore_c.h:1878
Topic publisher (as published via $pub$<topic>).
Definition: ntcore_c.h:1886
uint64_t pubuid
Definition: ntcore_c.h:1888
struct NT_String client
Definition: ntcore_c.h:1887
Topic subscriber (as published via $sub$<topic>).
Definition: ntcore_c.h:1894
uint64_t subuid
Definition: ntcore_c.h:1896
struct NT_String client
Definition: ntcore_c.h:1895
struct NT_Meta_SubscriberOptions options
Definition: ntcore_c.h:1897
NetworkTables publish/subscribe options.
Definition: ntcore_c.h:303
unsigned int structSize
Structure size.
Definition: ntcore_c.h:307
NT_Bool prefixMatch
Perform prefix match on subscriber topic names.
Definition: ntcore_c.h:346
NT_Bool disableRemote
For subscriptions, if remote value updates should not be queued for ReadQueue().
Definition: ntcore_c.h:357
NT_Bool keepDuplicates
Preserve duplicate value changes (rather than ignoring them).
Definition: ntcore_c.h:351
NT_Bool disableLocal
For subscriptions, if local value updates should not be queued for ReadQueue().
Definition: ntcore_c.h:363
NT_Publisher excludePublisher
For subscriptions, if non-zero, value updates for ReadQueue() are not queued for this publisher.
Definition: ntcore_c.h:329
unsigned int pollStorage
Polling storage size for a subscription.
Definition: ntcore_c.h:315
NT_Bool topicsOnly
For subscriptions, don't ask for value changes (only topic announcements).
Definition: ntcore_c.h:339
NT_Bool sendAll
Send all value changes over the network.
Definition: ntcore_c.h:334
double periodic
How frequently changes will be sent over the network, in seconds.
Definition: ntcore_c.h:323
NT_Bool excludeSelf
For entries, don't queue (for ReadQueue) value updates for the entry's internal publisher.
Definition: ntcore_c.h:369
NT_Bool hidden
For subscriptions, don't share the existence of the subscription with the network.
Definition: ntcore_c.h:377
A NetworkTables string.
Definition: ntcore_c.h:133
size_t len
Length of the string in bytes.
Definition: ntcore_c.h:146
char * str
String contents (UTF-8).
Definition: ntcore_c.h:140
NetworkTables time sync event data.
Definition: ntcore_c.h:259
int64_t rtt2
Measured round trip time divided by 2, in microseconds.
Definition: ntcore_c.h:267
NT_Bool valid
If serverTimeOffset and RTT are valid.
Definition: ntcore_c.h:273
int64_t serverTimeOffset
Offset between local time and server time, in microseconds.
Definition: ntcore_c.h:264
NetworkTables Topic Information.
Definition: ntcore_c.h:188
struct NT_String properties
Topic properties JSON string.
Definition: ntcore_c.h:202
struct NT_String type_str
Topic type string.
Definition: ntcore_c.h:199
NT_Topic topic
Topic handle.
Definition: ntcore_c.h:190
enum NT_Type type
Topic type.
Definition: ntcore_c.h:196
struct NT_String name
Topic name.
Definition: ntcore_c.h:193
NetworkTables value event data.
Definition: ntcore_c.h:232
NT_Handle subentry
Subscriber/entry handle.
Definition: ntcore_c.h:237
NT_Topic topic
Topic handle.
Definition: ntcore_c.h:234
struct NT_Value value
The new value.
Definition: ntcore_c.h:240
NetworkTables Entry Value.
Definition: ntcore_c.h:150
struct NT_Value::@1::@5 arr_float
enum NT_Type type
Definition: ntcore_c.h:151
float * arr
Definition: ntcore_c.h:173
struct NT_Value::@1::@4 arr_double
struct NT_String * arr
Definition: ntcore_c.h:181
float v_float
Definition: ntcore_c.h:157
double * arr
Definition: ntcore_c.h:169
struct NT_String v_string
Definition: ntcore_c.h:159
struct NT_Value::@1::@2 v_raw
int64_t last_change
Definition: ntcore_c.h:152
int64_t server_time
Definition: ntcore_c.h:153
double v_double
Definition: ntcore_c.h:158
uint8_t * data
Definition: ntcore_c.h:161
struct NT_Value::@1::@3 arr_boolean
struct NT_Value::@1::@6 arr_int
NT_Bool v_boolean
Definition: ntcore_c.h:155
size_t size
Definition: ntcore_c.h:162
NT_Bool * arr
Definition: ntcore_c.h:165
struct NT_Value::@1::@7 arr_string
int64_t v_int
Definition: ntcore_c.h:156
int64_t * arr
Definition: ntcore_c.h:177