opcua_basictypes.h 8.1 KB

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