Commit 7e0e28a5 authored by Christoph Ziebuhr's avatar Christoph Ziebuhr Committed by oroulet

Automatically set ServerTimestamp on Value attributes

parent e680d7ee
......@@ -100,8 +100,12 @@ class AttributeService:
):
res.append(ua.StatusCode(ua.StatusCodes.BadUserAccessDenied))
continue
if writevalue.AttributeId == ua.AttributeIds.Value and self._aspace.force_server_timestamp:
dv = dataclasses.replace(writevalue.Value, ServerTimestamp=datetime.utcnow(), ServerPicoseconds=None)
else:
dv = writevalue.Value
res.append(
await self._aspace.write_attribute_value(writevalue.NodeId, writevalue.AttributeId, writevalue.Value)
await self._aspace.write_attribute_value(writevalue.NodeId, writevalue.AttributeId, dv)
)
return res
......@@ -506,6 +510,7 @@ class NodeManagementService:
dv = ua.DataValue(
ua.Variant(getattr(attributes, name), vtype, is_array=is_array),
SourceTimestamp=datetime.utcnow() if add_timestamps else None,
ServerTimestamp=datetime.utcnow() if add_timestamps and self._aspace.force_server_timestamp else None,
)
nodedata.attributes[getattr(ua.AttributeIds, name)] = AttributeValue(dv)
......@@ -605,6 +610,7 @@ class AddressSpace:
def __init__(self):
self.logger = logging.getLogger(__name__)
self.force_server_timestamp: bool = True
self._nodes: Dict[ua.NodeId, NodeData] = {}
self._datachange_callback_counter = 200
self._handle_to_attribute_map: Dict[int, Tuple[ua.NodeId, ua.AttributeIds]] = {}
......
......@@ -110,7 +110,7 @@ class InternalServer:
attr.Value = ua.DataValue(
ua.Variant(10000, ua.VariantType.UInt32),
StatusCode_=ua.StatusCode(ua.StatusCodes.Good),
ServerTimestamp=datetime.utcnow(),
SourceTimestamp=datetime.utcnow(),
)
params.NodesToWrite.append(attr)
result = await self.isession.write(params)
......
......@@ -139,6 +139,12 @@ class Server:
"""
self.iserver.match_discovery_source_ip = match_discovery_client_ip
def set_force_server_timestamp(self, force_server_timestamp: bool):
"""
Enables or disables automatically setting ServerTimestamp on Value attributes
"""
self.iserver.aspace.force_server_timestamp = force_server_timestamp
async def set_build_info(self, product_uri, manufacturer_name, product_name, software_version,
build_number, build_date):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment