Skip to content

Commit 23b0fda

Browse files
author
Viacheslav Kalenikov
committed
MonitoredItem FB: TimestampSource property; tests for different sources
1 parent 5d1fb9e commit 23b0fda

7 files changed

Lines changed: 245 additions & 162 deletions

File tree

shared/libraries/opcua/opcuashared/include/opcuashared/opcuadatavalue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class OpcUaDataValue : public OpcUaObject<UA_DataValue>
2929
using OpcUaObject<UA_DataValue>::OpcUaObject;
3030

3131
static uint64_t toUnixTimeUs(UA_DateTime date);
32+
static UA_DateTime fromUnixTimeUs(uint64_t date);
3233

3334
const UA_DataValue& getDataValue() const;
3435

shared/libraries/opcua/opcuashared/src/opcuadatavalue.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ uint64_t OpcUaDataValue::toUnixTimeUs(UA_DateTime date)
5353
return static_cast<uint64_t>((date - UA_DATETIME_UNIX_EPOCH) / UA_DATETIME_USEC);
5454
}
5555

56+
UA_DateTime OpcUaDataValue::fromUnixTimeUs(uint64_t date)
57+
{
58+
if (date == 0)
59+
return 0;
60+
return static_cast<UA_DateTime>(date * UA_DATETIME_USEC + UA_DATETIME_UNIX_EPOCH);
61+
}
62+
5663
bool OpcUaDataValue::isInteger() const
5764
{
5865
return VariantUtils::IsInteger(this->value.value);

shared/libraries/opcuageneric/opcuageneric_client/include/opcuageneric_client/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static constexpr const char* PROPERTY_NAME_OPCUA_NODE_ID_TYPE = "NodeIDType";
3232
static constexpr const char* PROPERTY_NAME_OPCUA_NODE_ID = "NodeID";
3333
static constexpr const char* PROPERTY_NAME_OPCUA_NAMESPACE_INDEX = "NamespaceIndex";
3434
static constexpr const char* PROPERTY_NAME_OPCUA_SAMPLING_INTERVAL = "SamplingInterval";
35+
static constexpr const char* PROPERTY_NAME_OPCUA_TS_MODE = "TimestampMode";
3536
// ----------
3637

3738
// Defaults

shared/libraries/opcuageneric/opcuageneric_client/src/opcua_monitored_item_fb_impl.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ FunctionBlockTypePtr OpcUaMonitoredItemFbImpl::CreateType()
131131
defaultConfig.addProperty(builder.build());
132132
}
133133

134+
{
135+
auto builder =
136+
SelectionPropertyBuilder(PROPERTY_NAME_OPCUA_TS_MODE, List<IString>("None", "ServerTimestamp", "SourceTimestamp"), static_cast<int>(DomainSource::ServerTimestamp))
137+
.setDescription("");
138+
defaultConfig.addProperty(builder.build());
139+
}
140+
134141
const auto fbType =
135142
FunctionBlockType(GENERIC_OPCUA_MONITORED_ITEM_FB_NAME,
136143
GENERIC_OPCUA_MONITORED_ITEM_FB_NAME,
@@ -203,7 +210,16 @@ void OpcUaMonitoredItemFbImpl::readProperties()
203210
config.samplingInterval = DEFAULT_OPCUA_MIFB_SAMPLING_INTERVAL;
204211
}
205212

206-
config.domainSource = DomainSource::ServerTimestamp;
213+
const auto tmpDomainSource =
214+
readProperty<int, IInteger>(objPtr, PROPERTY_NAME_OPCUA_TS_MODE, static_cast<int>(DomainSource::ServerTimestamp));
215+
if (tmpDomainSource < static_cast<int>(DomainSource::_count) && tmpDomainSource >= 0)
216+
{
217+
config.domainSource = static_cast<DomainSource>(tmpDomainSource);
218+
}
219+
else
220+
{
221+
config.domainSource = DomainSource::ServerTimestamp;
222+
}
207223

208224
updateStatuses();
209225
}

shared/libraries/opcuageneric/opcuageneric_client/tests/opcuaservertesthelper.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,17 @@ void OpcUaServerTestHelper::publishVariable(std::string identifier,
233233
CheckStatusCodeException(status);
234234
}
235235

236-
void OpcUaServerTestHelper::writeNode(const OpcUaNodeId& nodeId, const OpcUaVariant& value)
236+
void OpcUaServerTestHelper::writeValueNode(const OpcUaNodeId& nodeId, const OpcUaVariant& value)
237237
{
238238
CheckStatusCodeException(UA_Server_writeValue(server, *nodeId, *value));
239239
}
240240

241+
void OpcUaServerTestHelper::writeDataValueNode(const OpcUaNodeId& nodeId, const OpcUaDataValue& value)
242+
{
243+
CheckStatusCodeException(UA_Server_writeDataValue(server, *nodeId, *value));
244+
}
245+
246+
241247
void OpcUaServerTestHelper::publishFolder(const char* identifier, UA_NodeId* parentNodeId, const char* locale, int nodeIndex)
242248
{
243249
OpcUaObject<UA_ObjectAttributes> attr = UA_ObjectAttributes_default;

shared/libraries/opcuageneric/opcuageneric_client/tests/opcuaservertesthelper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class OpcUaServerTestHelper final
5353
uint16_t nodeIndex = 1,
5454
size_t dimension = 1);
5555

56-
void writeNode(const OpcUaNodeId& nodeId, const OpcUaVariant& value);
56+
void writeValueNode(const OpcUaNodeId& nodeId, const OpcUaVariant& value);
57+
void writeDataValueNode(const OpcUaNodeId& nodeId, const OpcUaDataValue& value);
5758

5859
private:
5960
void runServer();

0 commit comments

Comments
 (0)