ua_pubsub_networkmessage.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright (c) 2017 - 2018 Fraunhofer IOSB (Author: Tino Bischoff)
  6. */
  7. #ifndef UA_NETWORKMESSAGE_H_
  8. #define UA_NETWORKMESSAGE_H_
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include "ua_types.h"
  13. #include "ua_types_generated.h"
  14. /* DataSet Payload Header */
  15. typedef struct {
  16. UA_Byte count;
  17. UA_UInt16* dataSetWriterIds;
  18. } UA_DataSetPayloadHeader;
  19. /* FieldEncoding Enum */
  20. typedef enum {
  21. UA_FIELDENCODING_VARIANT = 0,
  22. UA_FIELDENCODING_RAWDATA = 1,
  23. UA_FIELDENCODING_DATAVALUE = 2
  24. } UA_FieldEncoding;
  25. /* DataSetMessage Type */
  26. typedef enum {
  27. UA_DATASETMESSAGE_DATAKEYFRAME = 0,
  28. UA_DATASETMESSAGE_DATADELTAFRAME = 1,
  29. UA_DATASETMESSAGE_EVENT = 2,
  30. UA_DATASETMESSAGE_KEEPALIVE = 3
  31. } UA_DataSetMessageType;
  32. /* DataSetMessage Header */
  33. typedef struct {
  34. UA_Boolean dataSetMessageValid;
  35. UA_FieldEncoding fieldEncoding;
  36. UA_Boolean dataSetMessageSequenceNrEnabled;
  37. UA_Boolean timestampEnabled;
  38. UA_Boolean statusEnabled;
  39. UA_Boolean configVersionMajorVersionEnabled;
  40. UA_Boolean configVersionMinorVersionEnabled;
  41. UA_DataSetMessageType dataSetMessageType;
  42. UA_Boolean picoSecondsIncluded;
  43. UA_UInt16 dataSetMessageSequenceNr;
  44. UA_UtcTime timestamp;
  45. UA_UInt16 picoSeconds;
  46. UA_UInt16 status;
  47. UA_UInt32 configVersionMajorVersion;
  48. UA_UInt32 configVersionMinorVersion;
  49. } UA_DataSetMessageHeader;
  50. UA_StatusCode
  51. UA_DataSetMessageHeader_encodeBinary(const UA_DataSetMessageHeader* src,
  52. UA_Byte **bufPos, const UA_Byte *bufEnd);
  53. UA_StatusCode
  54. UA_DataSetMessageHeader_decodeBinary(const UA_ByteString *src, size_t *offset,
  55. UA_DataSetMessageHeader* dst);
  56. size_t
  57. UA_DataSetMessageHeader_calcSizeBinary(const UA_DataSetMessageHeader* p);
  58. /**
  59. * DataSetMessage
  60. * ^^^^^^^^^^^^^^ */
  61. typedef struct {
  62. UA_UInt16 fieldCount;
  63. UA_DataValue* dataSetFields;
  64. } UA_DataSetMessage_DataKeyFrameData;
  65. typedef struct {
  66. UA_UInt16 fieldIndex;
  67. UA_DataValue fieldValue;
  68. } UA_DataSetMessage_DeltaFrameField;
  69. typedef struct {
  70. UA_UInt16 fieldCount;
  71. UA_DataSetMessage_DeltaFrameField* deltaFrameFields;
  72. } UA_DataSetMessage_DataDeltaFrameData;
  73. typedef struct {
  74. UA_DataSetMessageHeader header;
  75. union {
  76. UA_DataSetMessage_DataKeyFrameData keyFrameData;
  77. UA_DataSetMessage_DataDeltaFrameData deltaFrameData;
  78. } data;
  79. } UA_DataSetMessage;
  80. UA_StatusCode
  81. UA_DataSetMessage_encodeBinary(const UA_DataSetMessage* src, UA_Byte **bufPos,
  82. const UA_Byte *bufEnd);
  83. UA_StatusCode
  84. UA_DataSetMessage_decodeBinary(const UA_ByteString *src, size_t *offset,
  85. UA_DataSetMessage* dst);
  86. size_t
  87. UA_DataSetMessage_calcSizeBinary(const UA_DataSetMessage* p);
  88. void UA_DataSetMessage_free(const UA_DataSetMessage* p);
  89. typedef struct {
  90. UA_UInt16* sizes;
  91. UA_DataSetMessage* dataSetMessages;
  92. } UA_DataSetPayload;
  93. typedef enum {
  94. UA_PUBLISHERDATATYPE_BYTE = 0,
  95. UA_PUBLISHERDATATYPE_UINT16 = 1,
  96. UA_PUBLISHERDATATYPE_UINT32 = 2,
  97. UA_PUBLISHERDATATYPE_UINT64 = 3,
  98. UA_PUBLISHERDATATYPE_STRING = 4
  99. } UA_PublisherIdDatatype;
  100. typedef enum {
  101. UA_NETWORKMESSAGE_DATASET = 0,
  102. UA_NETWORKMESSAGE_DISCOVERY_REQUEST = 1,
  103. UA_NETWORKMESSAGE_DISCOVERY_RESPONSE = 2
  104. } UA_NetworkMessageType;
  105. /**
  106. * UA_NetworkMessageGroupHeader
  107. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
  108. typedef struct {
  109. UA_Boolean writerGroupIdEnabled;
  110. UA_Boolean groupVersionEnabled;
  111. UA_Boolean networkMessageNumberEnabled;
  112. UA_Boolean sequenceNumberEnabled;
  113. UA_UInt16 writerGroupId;
  114. UA_UInt32 groupVersion; // spec: type "VersionTime"
  115. UA_UInt16 networkMessageNumber;
  116. UA_UInt16 sequenceNumber;
  117. } UA_NetworkMessageGroupHeader;
  118. /**
  119. * UA_NetworkMessageSecurityHeader
  120. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
  121. typedef struct {
  122. UA_Boolean networkMessageSigned;
  123. UA_Boolean networkMessageEncrypted;
  124. UA_Boolean securityFooterEnabled;
  125. UA_Boolean forceKeyReset;
  126. UA_UInt32 securityTokenId; // spec: IntegerId
  127. UA_Byte nonceLength;
  128. UA_ByteString messageNonce;
  129. UA_UInt16 securityFooterSize;
  130. } UA_NetworkMessageSecurityHeader;
  131. /**
  132. * UA_NetworkMessage
  133. * ^^^^^^^^^^^^^^^^^ */
  134. typedef struct {
  135. UA_Byte version;
  136. UA_Boolean publisherIdEnabled;
  137. UA_Boolean groupHeaderEnabled;
  138. UA_Boolean payloadHeaderEnabled;
  139. UA_PublisherIdDatatype publisherIdType;
  140. UA_Boolean dataSetClassIdEnabled;
  141. UA_Boolean securityEnabled;
  142. UA_Boolean timestampEnabled;
  143. UA_Boolean picosecondsEnabled;
  144. UA_Boolean chunkMessage;
  145. UA_Boolean promotedFieldsEnabled;
  146. UA_NetworkMessageType networkMessageType;
  147. union {
  148. UA_Byte publisherIdByte;
  149. UA_UInt16 publisherIdUInt16;
  150. UA_UInt32 publisherIdUInt32;
  151. UA_UInt64 publisherIdUInt64;
  152. UA_Guid publisherIdGuid;
  153. UA_String publisherIdString;
  154. } publisherId;
  155. UA_Guid dataSetClassId;
  156. UA_NetworkMessageGroupHeader groupHeader;
  157. union {
  158. UA_DataSetPayloadHeader dataSetPayloadHeader;
  159. } payloadHeader;
  160. UA_DateTime timestamp;
  161. UA_UInt16 picoseconds;
  162. UA_UInt16 promotedFieldsSize;
  163. UA_Variant* promotedFields; /* BaseDataType */
  164. UA_NetworkMessageSecurityHeader securityHeader;
  165. union {
  166. UA_DataSetPayload dataSetPayload;
  167. } payload;
  168. UA_ByteString securityFooter;
  169. UA_ByteString signature;
  170. } UA_NetworkMessage;
  171. UA_StatusCode
  172. UA_NetworkMessage_encodeBinary(const UA_NetworkMessage* src,
  173. UA_Byte **bufPos, const UA_Byte *bufEnd);
  174. UA_StatusCode
  175. UA_NetworkMessage_decodeBinary(const UA_ByteString *src, size_t *offset,
  176. UA_NetworkMessage* dst);
  177. size_t
  178. UA_NetworkMessage_calcSizeBinary(const UA_NetworkMessage* p);
  179. void
  180. UA_NetworkMessage_deleteMembers(UA_NetworkMessage* p);
  181. void
  182. UA_NetworkMessage_delete(UA_NetworkMessage* p);
  183. #ifdef __cplusplus
  184. } // extern "C"
  185. #endif
  186. #endif /* UA_NETWORKMESSAGE_H_ */