opcua_basictypes.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * opcua_basictypes.h
  3. *
  4. * Created on: 13.03.2014
  5. * Author: mrt
  6. */
  7. #ifndef OPCUA_BASICTYPES_H_
  8. #define OPCUA_BASICTYPES_H_
  9. #include <stdint.h>
  10. typedef _Bool Boolean;
  11. typedef uint8_t Byte;
  12. typedef int8_t SByte;
  13. typedef int16_t Int16;
  14. typedef int32_t Int32;
  15. typedef int64_t Int64;
  16. typedef uint16_t UInt16;
  17. typedef uint32_t UInt32;
  18. typedef uint64_t UInt64;
  19. typedef float Float;
  20. typedef double Double;
  21. #define UA_SUCCESS 0
  22. #define UA_ERROR (0x01)
  23. #define UA_ERR_INCONSISTENT (UA_ERROR | (0x01 << 1))
  24. #define UA_ERR_INVALID_VALUE (UA_ERROR | (0x01 << 2))
  25. #define UA_ERR_NO_MEMORY (UA_ERROR | (0x01 << 3))
  26. #define UA_TRUE (42==42)
  27. #define UA_FALSE (!UA_TRUE)
  28. #define UA_NULL ((void*)0)
  29. #define UA_TYPE_METHOD_PROTOTYPES(TYPE) \
  30. Int32 TYPE##_calcSize(TYPE const * ptr);\
  31. Int32 TYPE##_encode(TYPE const * src, Int32* pos, char * dst);\
  32. Int32 TYPE##_decode(char const * src, Int32* pos, TYPE * dst);\
  33. Int32 TYPE##_delete(TYPE * p);\
  34. Int32 TYPE##_deleteMembers(TYPE * p); \
  35. typedef _Bool UA_Boolean;
  36. UA_TYPE_METHOD_PROTOTYPES (UA_Boolean)
  37. typedef int8_t UA_Byte;
  38. UA_TYPE_METHOD_PROTOTYPES (UA_Byte)
  39. typedef uint8_t UA_SByte;
  40. UA_TYPE_METHOD_PROTOTYPES (UA_SByte)
  41. typedef int16_t UA_Int16;
  42. UA_TYPE_METHOD_PROTOTYPES (UA_Int16)
  43. typedef uint16_t UA_UInt16;
  44. UA_TYPE_METHOD_PROTOTYPES (UA_UInt16)
  45. typedef int32_t UA_Int32;
  46. UA_TYPE_METHOD_PROTOTYPES (UA_Int32)
  47. typedef uint32_t UA_UInt32;
  48. UA_TYPE_METHOD_PROTOTYPES (UA_UInt32)
  49. typedef int64_t UA_Int64;
  50. UA_TYPE_METHOD_PROTOTYPES (UA_Int64)
  51. typedef uint64_t UA_UInt64;
  52. UA_TYPE_METHOD_PROTOTYPES (UA_UInt64)
  53. typedef float UA_Float;
  54. UA_TYPE_METHOD_PROTOTYPES (UA_Float)
  55. typedef double UA_Double;
  56. UA_TYPE_METHOD_PROTOTYPES (UA_Double)
  57. /**
  58. * StatusCodeBinaryEncoding
  59. * Part: 6
  60. * Chapter: 5.2.2.11
  61. * Page: 20
  62. */
  63. typedef UA_Int32 UA_StatusCode;
  64. enum UA_StatusCode_enum
  65. {
  66. // Some Values are called the same as previous Enumerations so we need
  67. //names that are unique
  68. SC_Good = 0x00
  69. };
  70. UA_TYPE_METHOD_PROTOTYPES (UA_StatusCode)
  71. typedef struct T_UA_VTable {
  72. UA_UInt32 Id;
  73. Int32 (*calcSize)(void* ptr);
  74. Int32 (*decode)(char const * src, Int32* pos, void* dst);
  75. Int32 (*encode)(void const * src, Int32* pos, char* dst);
  76. } UA_VTable;
  77. /* VariantBinaryEncoding - Part: 6, Chapter: 5.2.2.16, Page: 22 */
  78. typedef struct T_UA_Variant {
  79. UA_VTable* vt; // internal entry into vTable
  80. UA_Byte encodingMask; // Type of UA_Variant_EncodingMaskType_enum
  81. UA_Int32 arrayLength; // total number of elements
  82. void** data;
  83. } UA_Variant;
  84. UA_TYPE_METHOD_PROTOTYPES (UA_Variant)
  85. /* String - Part: 6, Chapter: 5.2.2.4, Page: 16 */
  86. typedef struct T_UA_String
  87. {
  88. UA_Int32 length;
  89. UA_Byte* data;
  90. }
  91. UA_String;
  92. UA_TYPE_METHOD_PROTOTYPES (UA_String)
  93. /* ByteString - Part: 6, Chapter: 5.2.2.7, Page: 17 */
  94. typedef struct T_UA_ByteString
  95. {
  96. UA_Int32 length;
  97. UA_Byte* data;
  98. }
  99. UA_ByteString;
  100. UA_TYPE_METHOD_PROTOTYPES (UA_ByteString)
  101. /** LocalizedTextBinaryEncoding - Part: 6, Chapter: 5.2.2.14, Page: 21 */
  102. typedef struct T_UA_LocalizedText
  103. {
  104. UA_Byte encodingMask;
  105. UA_String locale;
  106. UA_String text;
  107. }
  108. UA_LocalizedText;
  109. UA_TYPE_METHOD_PROTOTYPES (UA_LocalizedText)
  110. /* GuidType - Part: 6, Chapter: 5.2.2.6 Page: 17 */
  111. typedef struct T_UA_Guid
  112. {
  113. UA_UInt32 data1;
  114. UA_UInt16 data2;
  115. UA_UInt16 data3;
  116. UA_ByteString data4;
  117. } UA_Guid;
  118. UA_TYPE_METHOD_PROTOTYPES (UA_Guid)
  119. /* DateTime - Part: 6, Chapter: 5.2.2.5, Page: 16 */
  120. typedef UA_Int64 UA_DateTime; //100 nanosecond resolution
  121. UA_TYPE_METHOD_PROTOTYPES (UA_DateTime)
  122. typedef struct T_UA_NodeId
  123. {
  124. UA_Byte encodingByte; //enum BID_NodeIdEncodingValuesType
  125. UA_UInt16 namespace;
  126. union
  127. {
  128. UA_UInt32 numeric;
  129. UA_String string;
  130. UA_Guid guid;
  131. UA_ByteString byteString;
  132. }
  133. identifier;
  134. } UA_NodeId;
  135. UA_TYPE_METHOD_PROTOTYPES (UA_NodeId)
  136. /** XmlElement - Part: 6, Chapter: 5.2.2.8, Page: 17 */
  137. typedef struct T_UA_XmlElement
  138. {
  139. //TODO Überlegung ob man es direkt als ByteString speichert oder als String
  140. UA_ByteString data;
  141. } UA_XmlElement;
  142. UA_TYPE_METHOD_PROTOTYPES (UA_XmlElement)
  143. /** NodeIds - Part: 6, Chapter: 5.2.2.9, Table 5 */
  144. enum UA_NodeIdEncodingValuesType_enum
  145. {
  146. // Some Values are called the same as previous Enumerations so we need names that are unique
  147. NIEVT_TWO_BYTE = 0x00,
  148. NIEVT_FOUR_BYTE = 0x01,
  149. NIEVT_NUMERIC = 0x02,
  150. NIEVT_STRING = 0x03,
  151. NIEVT_GUID = 0x04,
  152. NIEVT_BYTESTRING = 0x05,
  153. NIEVT_NAMESPACE_URI_FLAG = 0x80, //Is only for ExpandedNodeId required
  154. NIEVT_SERVERINDEX_FLAG = 0x40 //Is only for ExpandedNodeId required
  155. };
  156. /* ExpandedNodeId - Part: 6, Chapter: 5.2.2.10, Page: 19 */
  157. typedef struct T_UA_ExpandedNodeId
  158. {
  159. UA_NodeId nodeId;
  160. UA_String namespaceUri;
  161. UA_UInt32 serverIndex;
  162. }
  163. UA_ExpandedNodeId;
  164. UA_TYPE_METHOD_PROTOTYPES(UA_ExpandedNodeId)
  165. /* NodeIds - Part: 6, Chapter: 5.2.2.9, Page: 17 */
  166. enum UA_IdentifierType_enum {
  167. // Some Values are called the same as previouse Enumerations so we need
  168. //names that are unique
  169. IT_NUMERIC = 0,
  170. IT_STRING = 1,
  171. IT_GUID = 2,
  172. IT_OPAQUE = 3
  173. };
  174. typedef UA_Int32 UA_IdentifierType;
  175. UA_TYPE_METHOD_PROTOTYPES(UA_IdentifierType)
  176. /* ExtensionObjectBinaryEncoding - Part: 6, Chapter: 5.2.2.15, Page: 21 */
  177. typedef struct T_UA_ExtensionObject {
  178. UA_NodeId typeId;
  179. UA_Byte encoding; //Type of the enum UA_ExtensionObjectEncodingMaskType
  180. UA_ByteString body;
  181. } UA_ExtensionObject;
  182. UA_TYPE_METHOD_PROTOTYPES(UA_ExtensionObject)
  183. enum UA_ExtensionObject_EncodingMaskType_enum
  184. {
  185. NO_BODY_IS_ENCODED = 0x00,
  186. BODY_IS_BYTE_STRING = 0x01,
  187. BODY_IS_XML_ELEMENT = 0x02
  188. };
  189. /* QualifiedNameBinaryEncoding - Part: 6, Chapter: 5.2.2.13, Page: 20 */
  190. typedef struct T_UA_QualifiedName {
  191. UInt16 namespaceIndex;
  192. UInt16 reserved;
  193. UA_String name;
  194. } UA_QualifiedName;
  195. UA_TYPE_METHOD_PROTOTYPES(UA_QualifiedName)
  196. /* DataValue - Part: 6, Chapter: 5.2.2.17, Page: 23 */
  197. typedef struct UA_DataValue {
  198. UA_Byte encodingMask;
  199. UA_Variant value;
  200. UA_StatusCode status;
  201. UA_DateTime sourceTimestamp;
  202. UA_Int16 sourcePicoseconds;
  203. UA_DateTime serverTimestamp;
  204. UA_Int16 serverPicoseconds;
  205. } UA_DataValue;
  206. UA_TYPE_METHOD_PROTOTYPES(UA_DataValue)
  207. /* DiagnosticInfo - Part: 6, Chapter: 5.2.2.12, Page: 20 */
  208. typedef struct T_UA_DiagnosticInfo {
  209. Byte encodingMask; //Type of the Enum UA_DiagnosticInfoEncodingMaskType
  210. UA_Int32 symbolicId;
  211. UA_Int32 namespaceUri;
  212. UA_Int32 localizedText;
  213. UA_Int32 locale;
  214. UA_String additionalInfo;
  215. UA_StatusCode innerStatusCode;
  216. struct T_UA_DiagnosticInfo* innerDiagnosticInfo;
  217. } UA_DiagnosticInfo;
  218. UA_TYPE_METHOD_PROTOTYPES(UA_DiagnosticInfo)
  219. enum UA_DiagnosticInfoEncodingMaskType_enum
  220. {
  221. // Some Values are called the same as previous Enumerations so we need
  222. //names that are unique
  223. DIEMT_SYMBOLIC_ID = 0x01,
  224. DIEMT_NAMESPACE = 0x02,
  225. DIEMT_LOCALIZED_TEXT = 0x04,
  226. DIEMT_LOCALE = 0x08,
  227. DIEMT_ADDITIONAL_INFO = 0x10,
  228. DIEMT_INNER_STATUS_CODE = 0x20,
  229. DIEMT_INNER_DIAGNOSTIC_INFO = 0x40
  230. };
  231. Int32 UA_Array_calcSize(Int32 noElements, Int32 type, void const ** ptr);
  232. #endif /* OPCUA_BASICTYPES_H_ */