opcua_basictypes.h 8.3 KB

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