opcua_basictypes.h 8.5 KB

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