[ntcore] Don't update timestamp when value is unchanged (#5356)

This fixes an issue with commands run/cancel.
This commit is contained in:
Carl Hauser
2023-07-23 17:36:26 -07:00
committed by GitHub
parent 5ec7f18bdc
commit c3fab7f1f2
4 changed files with 121 additions and 30 deletions

View File

@@ -285,7 +285,8 @@ struct LSImpl {
void CheckReset(TopicData* topic);
bool SetValue(TopicData* topic, const Value& value, unsigned int eventFlags,
bool isDuplicate, const PublisherData* publisher);
bool suppressIfDuplicate, bool isDuplicate,
const PublisherData* publisher);
void NotifyValue(TopicData* topic, unsigned int eventFlags, bool isDuplicate,
const PublisherData* publisher);
@@ -495,6 +496,7 @@ void LSImpl::CheckReset(TopicData* topic) {
bool LSImpl::SetValue(TopicData* topic, const Value& value,
unsigned int eventFlags, bool isDuplicate,
bool suppressIfDuplicate,
const PublisherData* publisher) {
DEBUG4("SetValue({}, {}, {}, {})", topic->name, value.time(), eventFlags,
isDuplicate);
@@ -504,16 +506,19 @@ bool LSImpl::SetValue(TopicData* topic, const Value& value,
if (!topic->lastValue || topic->lastValue.time() == 0 ||
value.time() >= topic->lastValue.time()) {
// TODO: notify option even if older value
topic->type = value.type();
topic->lastValue = value;
topic->lastValueFromNetwork = false;
NotifyValue(topic, eventFlags, isDuplicate, publisher);
}
if (!isDuplicate && topic->datalogType == value.type()) {
for (auto&& datalog : topic->datalogs) {
datalog.Append(value);
if (!(suppressIfDuplicate && isDuplicate)) {
topic->type = value.type();
topic->lastValue = value;
topic->lastValueFromNetwork = false;
NotifyValue(topic, eventFlags, isDuplicate, publisher);
if (topic->datalogType == value.type()) {
for (auto&& datalog : topic->datalogs) {
datalog.Append(value);
}
}
}
}
return true;
}
@@ -1259,20 +1264,21 @@ bool LSImpl::PublishLocalValue(PublisherData* publisher, const Value& value,
return false;
}
if (publisher->active) {
bool isDuplicate, isNetworkDuplicate;
bool isDuplicate, isNetworkDuplicate, suppressDuplicates;
if (force || publisher->config.keepDuplicates) {
isDuplicate = false;
suppressDuplicates = false;
isNetworkDuplicate = false;
} else {
isDuplicate = (publisher->topic->lastValue == value);
suppressDuplicates = true;
isNetworkDuplicate = (publisher->topic->lastValueNetwork == value);
}
isDuplicate = (publisher->topic->lastValue == value);
if (!isNetworkDuplicate && m_network) {
publisher->topic->lastValueNetwork = value;
m_network->SetValue(publisher->handle, value);
}
return SetValue(publisher->topic, value, NT_EVENT_VALUE_LOCAL, isDuplicate,
publisher);
suppressDuplicates, publisher);
} else {
return false;
}
@@ -1392,7 +1398,7 @@ void LocalStorage::NetworkSetValue(NT_Topic topicHandle, const Value& value) {
std::scoped_lock lock{m_mutex};
if (auto topic = m_impl->m_topics.Get(topicHandle)) {
if (m_impl->SetValue(topic, value, NT_EVENT_VALUE_REMOTE,
value == topic->lastValue, nullptr)) {
value == topic->lastValue, false, nullptr)) {
topic->lastValueNetwork = value;
topic->lastValueFromNetwork = true;
}