00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 #ifndef __OPC_UA_DATA_VALUE_H__ 00012 #define __OPC_UA_DATA_VALUE_H__ 00013 00014 #include <opc/ua/protocol/variant.h> 00015 00016 namespace OpcUa 00017 { 00018 const uint8_t DATA_VALUE = 1; 00019 const uint8_t DATA_VALUE_STATUS_CODE = 2; 00020 const uint8_t DATA_VALUE_SOURCE_TIMESTAMP = 4; 00021 const uint8_t DATA_VALUE_Server_TIMESTAMP = 8; 00022 const uint8_t DATA_VALUE_SOURCE_PICOSECONDS = 16; 00023 const uint8_t DATA_VALUE_Server_PICOSECONDS = 32; 00024 const uint8_t DATA_VALUE_ALL = ~uint8_t(); 00025 00026 struct DataValue 00027 { 00028 uint8_t Encoding; 00029 Variant Value; 00030 StatusCode Status; 00031 DateTime SourceTimestamp; 00032 uint16_t SourcePicoseconds; 00033 DateTime ServerTimestamp; 00034 uint16_t ServerPicoseconds; 00035 00036 DataValue() 00037 : Encoding(0) 00038 , Status(StatusCode::Good) 00039 , SourceTimestamp(0) 00040 , SourcePicoseconds(0) 00041 , ServerTimestamp(0) 00042 , ServerPicoseconds(0) 00043 { 00044 } 00045 00046 DataValue(const DataValue& data) = default; 00047 00048 explicit DataValue(const Variant& value) 00049 : DataValue() 00050 { 00051 Value = value; 00052 Encoding |= DATA_VALUE; 00053 } 00054 00055 template <typename T> 00056 explicit DataValue(const T val) 00057 : DataValue() 00058 { 00059 Value = Variant(val); 00060 Encoding |= DATA_VALUE; 00061 } 00062 00063 DataValue& operator= (const Variant& value) 00064 { 00065 Value = value; 00066 Encoding |= DATA_VALUE; 00067 return *this; 00068 } 00069 00070 template <typename T> 00071 DataValue& operator= (const T& value) 00072 { 00073 Value = Variant(value); 00074 Encoding |= DATA_VALUE; 00075 return *this; 00076 } 00077 00078 template <typename T> 00079 bool operator== (const T& t) const 00080 { 00081 return (Encoding & DATA_VALUE) && Value == t; 00082 } 00083 00084 bool operator== (const DataValue& data) const 00085 { 00086 if (Encoding != data.Encoding) 00087 return false; 00088 if ((Encoding & DATA_VALUE) && Value != data.Value) 00089 return false; 00090 if ((Encoding & DATA_VALUE_STATUS_CODE) && Status != data.Status) 00091 return false; 00092 if ((Encoding & DATA_VALUE_SOURCE_TIMESTAMP) && SourceTimestamp != data.SourceTimestamp) 00093 return false; 00094 if ((Encoding & DATA_VALUE_SOURCE_PICOSECONDS) && SourcePicoseconds != data.SourcePicoseconds) 00095 return false; 00096 if ((Encoding & DATA_VALUE_Server_TIMESTAMP) && ServerTimestamp != data.ServerTimestamp) 00097 return false; 00098 if ((Encoding & DATA_VALUE_Server_PICOSECONDS) && ServerPicoseconds != data.ServerPicoseconds) 00099 return false; 00100 00101 return true; 00102 } 00103 00104 void SetSourceTimestamp(const DateTime& t) 00105 { 00106 SourceTimestamp = t; 00107 Encoding |= DATA_VALUE_SOURCE_TIMESTAMP; 00108 } 00109 00110 void SetServerTimestamp(const DateTime& t) 00111 { 00112 ServerTimestamp = t; 00113 Encoding |= DATA_VALUE_Server_TIMESTAMP; 00114 } 00115 }; 00116 00117 } // namespace OpcUa 00118 00119 #endif // __OPC_UA_DATA_VALUE_H__ 00120