72 :
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);
345 std::string_view typeString,
ParamType defaultValue,
370 {{
"unit", T{}.name()}}, options)};
393 std::string_view typeString,
const wpi::json& properties,
395 wpi::json props = properties;
396 props[
"unit"] = T{}.name();
NetworkTables publisher.
Definition Topic.h:393
NT_Publisher m_pubHandle
NetworkTables handle.
Definition Topic.h:441
NetworkTables subscriber.
Definition Topic.h:321
NT_Subscriber m_subHandle
Definition Topic.h:386
NetworkTables Topic.
Definition Topic.h:28
NT_Topic m_handle
Definition Topic.h:317
wpi::json GetProperty(std::string_view name) const
Gets the current value of a property (as a JSON object).
NetworkTables unit-typed entry.
Definition UnitTopic.h:210
void Unpublish()
Stops publishing the entry if it's published.
Definition UnitTopic.h:258
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition UnitTopic.h:244
T ParamType
Definition UnitTopic.h:216
TopicType GetTopic() const
Get the corresponding topic.
Definition UnitTopic.h:251
T ValueType
Definition UnitTopic.h:215
UnitEntry(NT_Entry handle, ParamType defaultValue)
Construct from an entry handle; recommended to use UnitTopic::GetEntry() instead.
Definition UnitTopic.h:229
NetworkTables unit-typed publisher.
Definition UnitTopic.h:153
void Set(ParamType value, int64_t time=0)
Publish a new value.
Definition UnitTopic.h:177
void SetDefault(ParamType value)
Publish a default value.
Definition UnitTopic.h:188
UnitPublisher(NT_Publisher handle)
Construct from a publisher handle; recommended to use UnitTopic::Publish() instead.
Definition UnitTopic.h:169
T ParamType
Definition UnitTopic.h:157
TopicType GetTopic() const
Get the corresponding topic.
Definition UnitTopic.h:197
T ValueType
Definition UnitTopic.h:156
NetworkTables unit-typed subscriber.
Definition UnitTopic.h:55
ValueType Get() const
Get the last published value.
Definition UnitTopic.h:80
TopicType GetTopic() const
Get the corresponding topic.
Definition UnitTopic.h:139
std::vector< TimestampedValueType > ReadQueue()
Get an array of all value changes since the last call to ReadQueue.
Definition UnitTopic.h:125
TimestampedValueType GetAtomic(ParamType defaultValue) const
Get the last published value along with its timestamp.
Definition UnitTopic.h:110
T ValueType
Definition UnitTopic.h:58
ValueType Get(ParamType defaultValue) const
Get the last published value.
Definition UnitTopic.h:89
UnitSubscriber(NT_Subscriber handle, ParamType defaultValue)
Construct from a subscriber handle; recommended to use UnitTopic::Subscribe() instead.
Definition UnitTopic.h:71
TimestampedValueType GetAtomic() const
Get the last published value along with its timestamp If no value has been published,...
Definition UnitTopic.h:100
T ParamType
Definition UnitTopic.h:59
NetworkTables unit-typed topic.
Definition UnitTopic.h:270
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.h:344
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.h:450
PublisherType PublishEx(std::string_view typeString, const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic, with type string and initial properties.
Definition UnitTopic.h:392
bool IsMatchingUnit() const
Verify the topic has a matching unit type (if the topic is published).
Definition UnitTopic.h:302
SubscriberType Subscribe(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition UnitTopic.h:320
static constexpr std::string_view kTypeString
The default type string for this topic type.
Definition UnitTopic.h:279
T ValueType
Definition UnitTopic.h:275
UnitTopic(NT_Topic handle)
Construct from a topic handle.
Definition UnitTopic.h:288
UnitTopic(Topic topic)
Construct from a generic topic.
Definition UnitTopic.h:295
EntryType GetEntry(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition UnitTopic.h:422
T ParamType
Definition UnitTopic.h:276
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition UnitTopic.h:368
bool SetDefaultDouble(NT_Handle pubentry, double defaultValue)
Publish a default value.
TimestampedDouble GetAtomicDouble(NT_Handle subentry, double defaultValue)
Get the last published value along with its timestamp.
double GetDouble(NT_Handle subentry, double defaultValue)
Get the last published 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.
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:56
constexpr PubSubOptions kDefaultPubSubOptions
Default publish/subscribe options.
Definition ntcore_cpp.h:390
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.
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 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.
NetworkTables (ntcore) namespace.
Definition ntcore_cpp.h:36
NetworkTables publish/subscribe options.
Definition ntcore_cpp.h:305
Timestamped unit.
Definition UnitTopic.h:28
int64_t time
Time in local time base.
Definition UnitTopic.h:36
int64_t serverTime
Time in server time base.
Definition UnitTopic.h:41
TimestampedUnit(int64_t time, int64_t serverTime, T value)
Definition UnitTopic.h:30
TimestampedUnit()=default
T value
Value.
Definition UnitTopic.h:46