opcua_basictypes.h 7.0 KB

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