opcua_basictypes.h 8.7 KB

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