@@ 973-1000 (lines=28) @@ | ||
970 | return obj |
|
971 | ||
972 | def __str__(self): |
|
973 | s = 'DataValue(Value:{0}'.format(self.Value) |
|
974 | if self.StatusCode is not None: |
|
975 | s += ', StatusCode:{0}'.format(self.StatusCode) |
|
976 | if self.SourceTimestamp is not None: |
|
977 | s += ', SourceTimestamp:{0}'.format(self.SourceTimestamp) |
|
978 | if self.ServerTimestamp is not None: |
|
979 | s += ', ServerTimestamp:{0}'.format(self.ServerTimestamp) |
|
980 | if self.SourcePicoseconds is not None: |
|
981 | s += ', SourcePicoseconds:{0}'.format(self.SourcePicoseconds) |
|
982 | if self.ServerPicoseconds is not None: |
|
983 | s += ', ServerPicoseconds:{0}'.format(self.ServerPicoseconds) |
|
984 | s += ')' |
|
985 | return s |
|
986 | ||
987 | __repr__ = __str__ |
|
988 | ||
989 | ||
990 | def datatype_to_varianttype(int_type): |
|
991 | """ |
|
992 | Takes a NodeId or int and return a VariantType |
|
993 | This is only supported if int_type < 63 due to VariantType encoding |
|
994 | At low level we do not have access to address space thus decoding is limited |
|
995 | a better version of this method can be find in ua_utils.py |
|
996 | """ |
|
997 | if isinstance(int_type, NodeId): |
|
998 | int_type = int_type.Identifier |
|
999 | ||
1000 | if int_type <= 25: |
|
1001 | return VariantType(int_type) |
|
1002 | else: |
|
1003 | return VariantTypeCustom(int_type) |
@@ 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 = Variant() |
|
1028 | if obj.Encoding & (1 << 1): |
|
1029 | obj.StatusCode = StatusCode.from_binary(data) |
|
1030 | else: |
|
1031 | obj.StatusCode = StatusCode() |
|
1032 | if obj.Encoding & (1 << 2): |
|
1033 | self.SourceTimestamp = uabin.Primitives.DateTime.unpack(data) |
|
1034 | else: |
|
1035 | obj.SourceTimestamp = datetime.utcnow() |
|
1036 | if obj.Encoding & (1 << 3): |
|
1037 | self.SourcePicoseconds = uabin.Primitives.UInt16.unpack(data) |
|
1038 | else: |
|
1039 | obj.SourcePicoseconds = 0 |
|
1040 | if obj.Encoding & (1 << 4): |