| @@ 973-1000 (lines=28) @@ | ||
| 970 | if obj.Encoding & (1 << 2): |
|
| 971 | obj.SourceTimestamp = uabin.Primitives.DateTime.unpack(data) # DateTime.from_binary(data) |
|
| 972 | if obj.Encoding & (1 << 3): |
|
| 973 | obj.ServerTimestamp = uabin.Primitives.DateTime.unpack(data) # DateTime.from_binary(data) |
|
| 974 | if obj.Encoding & (1 << 4): |
|
| 975 | obj.SourcePicoseconds = uabin.Primitives.UInt16.unpack(data) |
|
| 976 | if obj.Encoding & (1 << 5): |
|
| 977 | obj.ServerPicoseconds = uabin.Primitives.UInt16.unpack(data) |
|
| 978 | return obj |
|
| 979 | ||
| 980 | def __str__(self): |
|
| 981 | s = 'DataValue(Value:{0}'.format(self.Value) |
|
| 982 | if self.StatusCode is not None: |
|
| 983 | s += ', StatusCode:{0}'.format(self.StatusCode) |
|
| 984 | if self.SourceTimestamp is not None: |
|
| 985 | s += ', SourceTimestamp:{0}'.format(self.SourceTimestamp) |
|
| 986 | if self.ServerTimestamp is not None: |
|
| 987 | s += ', ServerTimestamp:{0}'.format(self.ServerTimestamp) |
|
| 988 | if self.SourcePicoseconds is not None: |
|
| 989 | s += ', SourcePicoseconds:{0}'.format(self.SourcePicoseconds) |
|
| 990 | if self.ServerPicoseconds is not None: |
|
| 991 | s += ', ServerPicoseconds:{0}'.format(self.ServerPicoseconds) |
|
| 992 | s += ')' |
|
| 993 | return s |
|
| 994 | ||
| 995 | __repr__ = __str__ |
|
| 996 | ||
| 997 | ||
| 998 | def datatype_to_varianttype(int_type): |
|
| 999 | """ |
|
| 1000 | Takes a NodeId or int and return a VariantType |
|
| 1001 | This is only supported if int_type < 63 due to VariantType encoding |
|
| 1002 | At low level we do not have access to address space thus decoding is limited |
|
| 1003 | a better version of this method can be find in ua_utils.py |
|
| @@ 1016-1037 (lines=22) @@ | ||
| 1013 | packet.append(uabin.Primitives.UInt16.pack(self.SourcePicoseconds)) |
|
| 1014 | if self.ServerTimestamp: |
|
| 1015 | packet.append(uabin.Primitives.DateTime.pack(self.ServerTimestamp)) |
|
| 1016 | if self.ServerPicoseconds: |
|
| 1017 | packet.append(uabin.Primitives.UInt16.pack(self.ServerPicoseconds)) |
|
| 1018 | return b''.join(packet) |
|
| 1019 | ||
| 1020 | @staticmethod |
|
| 1021 | def from_binary(data): |
|
| 1022 | obj = DataValue() |
|
| 1023 | self.Encoding = uabin.Primitives.UInt8.unpack(data) |
|
| 1024 | if obj.Encoding & (1 << 0): |
|
| 1025 | obj.Value = Variant.from_binary(data) |
|
| 1026 | else: |
|
| 1027 | obj.Value = None |
|
| 1028 | if obj.Encoding & (1 << 1): |
|
| 1029 | obj.StatusCode = StatusCode.from_binary(data) |
|
| 1030 | else: |
|
| 1031 | obj.StatusCode = None |
|
| 1032 | if obj.Encoding & (1 << 2): |
|
| 1033 | self.SourceTimestamp = uabin.Primitives.DateTime.unpack(data) |
|
| 1034 | else: |
|
| 1035 | obj.SourceTimestamp = None |
|
| 1036 | if obj.Encoding & (1 << 3): |
|
| 1037 | self.SourcePicoseconds = uabin.Primitives.UInt16.unpack(data) |
|
| 1038 | else: |
|
| 1039 | obj.SourcePicoseconds = None |
|
| 1040 | if obj.Encoding & (1 << 4): |
|