71 :
Subscriber{handle}, m_defaultValue{defaultValue} {}
112 return {doubleVal.time, doubleVal.serverTime, doubleVal.value};
126 std::vector<TimestampedUnit<T>> vals;
128 vals.reserve(doubleVals.size());
129 for (
auto&& val : doubleVals) {
130 vals.emplace_back(val.time, val.serverTime, val.value);
346 std::string_view typeString,
ParamType defaultValue,
394 std::string_view typeString,
const wpi::util::json& properties,
396 wpi::util::json props = properties;
397 props[
"unit"] = T{}.name();
Publisher(const Publisher &)=delete
NT_Publisher m_pubHandle
NetworkTables handle.
Definition Topic.hpp:440
Subscriber(const Subscriber &)=delete
NT_Subscriber m_subHandle
Definition Topic.hpp:385
wpi::util::json GetProperty(std::string_view name) const
Gets the current value of a property (as a JSON object).
NT_Topic m_handle
Definition Topic.hpp:316
NetworkTables unit-typed entry.
Definition UnitTopic.hpp:210
UnitSubscriber< T > SubscriberType
Definition UnitTopic.hpp:212
T ParamType
Definition UnitTopic.hpp:216
TimestampedUnit< T > TimestampedValueType
Definition UnitTopic.hpp:218
UnitEntry(NT_Entry handle, ParamType defaultValue)
Construct from an entry handle; recommended to use UnitTopic::GetEntry() instead.
Definition UnitTopic.hpp:229
TopicType GetTopic() const
Get the corresponding topic.
Definition UnitTopic.hpp:251
void Unpublish()
Stops publishing the entry if it's published.
Definition UnitTopic.hpp:258
UnitPublisher< T > PublisherType
Definition UnitTopic.hpp:213
T ValueType
Definition UnitTopic.hpp:215
UnitTopic< T > TopicType
Definition UnitTopic.hpp:214
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition UnitTopic.hpp:244
NetworkTables unit-typed publisher.
Definition UnitTopic.hpp:153
void SetDefault(ParamType value)
Publish a default value.
Definition UnitTopic.hpp:188
TopicType GetTopic() const
Get the corresponding topic.
Definition UnitTopic.hpp:197
TimestampedUnit< T > TimestampedValueType
Definition UnitTopic.hpp:159
void Set(ParamType value, int64_t time=0)
Publish a new value.
Definition UnitTopic.hpp:177
UnitTopic< T > TopicType
Definition UnitTopic.hpp:155
UnitPublisher(NT_Publisher handle)
Construct from a publisher handle; recommended to use UnitTopic::Publish() instead.
Definition UnitTopic.hpp:169
T ValueType
Definition UnitTopic.hpp:156
T ParamType
Definition UnitTopic.hpp:157
NetworkTables unit-typed subscriber.
Definition UnitTopic.hpp:54
TimestampedValueType GetAtomic() const
Get the last published value along with its timestamp If no value has been published,...
Definition UnitTopic.hpp:99
std::vector< TimestampedValueType > ReadQueue()
Get an array of all value changes since the last call to ReadQueue.
Definition UnitTopic.hpp:125
UnitTopic< T > TopicType
Definition UnitTopic.hpp:56
T ParamType
Definition UnitTopic.hpp:58
ValueType Get() const
Get the last published value.
Definition UnitTopic.hpp:79
TimestampedValueType GetAtomic(ParamType defaultValue) const
Get the last published value along with its timestamp.
Definition UnitTopic.hpp:109
TopicType GetTopic() const
Get the corresponding topic.
Definition UnitTopic.hpp:139
TimestampedUnit< T > TimestampedValueType
Definition UnitTopic.hpp:59
UnitSubscriber(NT_Subscriber handle, ParamType defaultValue)
Construct from a subscriber handle; recommended to use UnitTopic::Subscribe() instead.
Definition UnitTopic.hpp:70
T ValueType
Definition UnitTopic.hpp:57
ValueType Get(ParamType defaultValue) const
Get the last published value.
Definition UnitTopic.hpp:88
NetworkTables unit-typed topic.
Definition UnitTopic.hpp:270
UnitPublisher< T > PublisherType
Definition UnitTopic.hpp:273
UnitEntry< T > EntryType
Definition UnitTopic.hpp:274
EntryType GetEntry(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition UnitTopic.hpp:423
static constexpr std::string_view kTypeString
The default type string for this topic type.
Definition UnitTopic.hpp:279
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition UnitTopic.hpp:369
EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic, with specific type string.
Definition UnitTopic.hpp:452
TimestampedUnit< T > TimestampedValueType
Definition UnitTopic.hpp:277
PublisherType PublishEx(std::string_view typeString, const wpi::util::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic, with type string and initial properties.
Definition UnitTopic.hpp:393
T ValueType
Definition UnitTopic.hpp:275
SubscriberType SubscribeEx(std::string_view typeString, ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic, with specific type string.
Definition UnitTopic.hpp:345
SubscriberType Subscribe(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition UnitTopic.hpp:320
UnitTopic(Topic topic)
Construct from a generic topic.
Definition UnitTopic.hpp:295
T ParamType
Definition UnitTopic.hpp:276
UnitSubscriber< T > SubscriberType
Definition UnitTopic.hpp:272
bool IsMatchingUnit() const
Verify the topic has a matching unit type (if the topic is published).
Definition UnitTopic.hpp:302
UnitTopic(NT_Topic handle)
Construct from a topic handle.
Definition UnitTopic.hpp:288
bool SetDefaultDouble(NT_Handle pubentry, double defaultValue)
Publish a default value.
bool SetDouble(NT_Handle pubentry, double value, int64_t time=0)
Publish a new value.
std::vector< TimestampedDouble > ReadQueueDouble(NT_Handle subentry)
Get an array of all value changes since the last call to ReadQueue.
double GetDouble(NT_Handle subentry, double defaultValue)
Get the last published value.
TimestampedDouble GetAtomicDouble(NT_Handle subentry, double defaultValue)
Get the last published value along with its timestamp.
NT_Handle NT_Topic
Definition ntcore_c.h:42
NT_Handle NT_Subscriber
Definition ntcore_c.h:43
NT_Handle NT_Publisher
Definition ntcore_c.h:44
NT_Handle NT_Entry
Definition ntcore_c.h:37
@ NT_DOUBLE
Definition ntcore_c.h:53
constexpr PubSubOptions kDefaultPubSubOptions
Default publish/subscribe options.
Definition ntcore_cpp.hpp:388
NT_Entry GetEntry(NT_Inst inst, std::string_view name)
Get Entry Handle.
NT_Topic GetTopicFromHandle(NT_Handle pubsubentry)
Gets the topic handle from an entry/subscriber/publisher handle.
void Unpublish(NT_Handle pubentry)
Stops publisher.
NT_Publisher PublishEx(NT_Topic topic, NT_Type type, std::string_view typeStr, const wpi::util::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new publisher to a topic.
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.
NetworkTables (ntcore) namespace.
Definition NTSendable.hpp:9
NetworkTables publish/subscribe options.
Definition ntcore_cpp.hpp:303
Timestamped unit.
Definition UnitTopic.hpp:27
int64_t time
Time in local time base.
Definition UnitTopic.hpp:35
int64_t serverTime
Time in server time base.
Definition UnitTopic.hpp:40
TimestampedUnit()=default
T value
Value.
Definition UnitTopic.hpp:45
TimestampedUnit(int64_t time, int64_t serverTime, T value)
Definition UnitTopic.hpp:29