opcua_basictypes.h 8.1 KB

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