goose_subscriber.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * goose_subscriber.h
  3. *
  4. * Copyright 2013-2022 Michael Zillgith
  5. *
  6. * This file is part of libIEC61850.
  7. *
  8. * libIEC61850 is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * libIEC61850 is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with libIEC61850. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * See COPYING file for the complete license text.
  22. */
  23. #ifndef GOOSE_SUBSCRIBER_H_
  24. #define GOOSE_SUBSCRIBER_H_
  25. #include "libiec61850_common_api.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. * \defgroup goose_api_group IEC 61850 GOOSE subscriber API
  31. */
  32. /**@{*/
  33. #include "mms_value.h"
  34. typedef enum
  35. {
  36. GOOSE_PARSE_ERROR_NO_ERROR = 0,
  37. GOOSE_PARSE_ERROR_UNKNOWN_TAG,
  38. GOOSE_PARSE_ERROR_TAGDECODE,
  39. GOOSE_PARSE_ERROR_SUBLEVEL,
  40. GOOSE_PARSE_ERROR_OVERFLOW,
  41. GOOSE_PARSE_ERROR_UNDERFLOW,
  42. GOOSE_PARSE_ERROR_TYPE_MISMATCH,
  43. GOOSE_PARSE_ERROR_LENGTH_MISMATCH,
  44. GOOSE_PARSE_ERROR_INVALID_PADDING
  45. } GooseParseError;
  46. typedef struct sGooseSubscriber* GooseSubscriber;
  47. /**
  48. * \brief user provided callback function that will be invoked when a GOOSE message is received.
  49. *
  50. * \param subscriber the subscriber object that invoked the callback function,
  51. * \param parameter a user provided parameter that will be passed to the callback function
  52. */
  53. typedef void (*GooseListener)(GooseSubscriber subscriber, void* parameter);
  54. /**
  55. * \brief create a new GOOSE subscriber instance.
  56. *
  57. * A new GOOSE subscriber will be created and connected to a specific GOOSE control block reference.
  58. *
  59. * The parameter goCbRef has to be given in MMS like notation (as it also will appear in the GOOSE message
  60. * sent by the publisher). An example could be "simpleIOGenericIO/LLN0$GO$gcbEvents".
  61. *
  62. * The data set values contained in a GOOSE message will be written to the optionally provided MmsValue instance.
  63. * The MmsValue object has to be of type MMS_ARRAY. The array elements need to be of the same type as
  64. * the data set elements. It is intended that the provided MmsValue instance has been created by the
  65. * IedConnection_getDataSet() method before.
  66. *
  67. * If NULL is given as dataSetValues it will be created the first time when a appropriate GOOSE message
  68. * is received.
  69. *
  70. * \param goCbRef a string containing the object reference of the GOOSE Control Block (GoCB) in MMS notation the
  71. * GOOSE publisher uses.
  72. * \param dataSetValues the MmsValue object where the data set values will be written or NULL.
  73. */
  74. LIB61850_API GooseSubscriber
  75. GooseSubscriber_create(char* goCbRef, MmsValue* dataSetValues);
  76. /**
  77. * \brief Get the GoId value of the received GOOSE message
  78. *
  79. * \param self GooseSubscriber instance to operate on.
  80. */
  81. LIB61850_API char*
  82. GooseSubscriber_getGoId(GooseSubscriber self);
  83. /**
  84. * \brief Get the GOOSE Control Block reference value of the received GOOSE message
  85. *
  86. * \param self GooseSubscriber instance to operate on.
  87. */
  88. LIB61850_API char*
  89. GooseSubscriber_getGoCbRef(GooseSubscriber self);
  90. /**
  91. * \brief Get the DatSet value of the received GOOSE message
  92. *
  93. * \param self GooseSubscriber instance to operate on.
  94. */
  95. LIB61850_API char*
  96. GooseSubscriber_getDataSet(GooseSubscriber self);
  97. /**
  98. * \brief set the destination mac address used by the subscriber to filter relevant messages.
  99. *
  100. * If dstMac is set the subscriber will ignore all messages with other dstMac values.
  101. *
  102. * \param self GooseSubscriber instance to operate on.
  103. * \param dstMac the destination mac address
  104. */
  105. LIB61850_API void
  106. GooseSubscriber_setDstMac(GooseSubscriber self, uint8_t dstMac[6]);
  107. /**
  108. * \brief set the APPID used by the subscriber to filter relevant messages.
  109. *
  110. * If APPID is set the subscriber will ignore all messages with other APPID values.
  111. *
  112. * \param self GooseSubscriber instance to operate on.
  113. * \param appId the APPID value the subscriber should use to filter messages
  114. */
  115. LIB61850_API void
  116. GooseSubscriber_setAppId(GooseSubscriber self, uint16_t appId);
  117. /**
  118. * \brief Check if subscriber state is valid
  119. *
  120. * A GOOSE subscriber is valid if TimeAllowedToLive timeout is not elapsed and GOOSE
  121. * message were received with correct state and sequence ID.
  122. *
  123. */
  124. LIB61850_API bool
  125. GooseSubscriber_isValid(GooseSubscriber self);
  126. /**
  127. * \brief Get parse error in case of invalid subscriber state
  128. *
  129. * \param self GooseSubscriber instance to operate on.
  130. *
  131. * \return the error code representing a message parse problem of the last received message
  132. */
  133. LIB61850_API GooseParseError
  134. GooseSubscriber_getParseError(GooseSubscriber self);
  135. /**
  136. * \brief Destroy the GooseSubscriber instance
  137. *
  138. * Do not call this function when the GooseSubscriber instance was added to a GooseReceiver.
  139. * The GooseReceiver will call the destructor when \ref GooseReceiver_destroy is called!
  140. *
  141. * \param self GooseSubscriber instance to operate on.
  142. */
  143. LIB61850_API void
  144. GooseSubscriber_destroy(GooseSubscriber self);
  145. /**
  146. * \brief set a callback function that will be invoked when a GOOSE message has been received.
  147. *
  148. * \param self GooseSubscriber instance to operate on.
  149. * \param listener user provided callback function
  150. * \param parameter a user provided parameter that will be passed to the callback function
  151. */
  152. LIB61850_API void
  153. GooseSubscriber_setListener(GooseSubscriber self, GooseListener listener, void* parameter);
  154. /**
  155. * \brief Get the APPID value of the received GOOSE message
  156. *
  157. * \param self GooseSubscriber instance to operate on.
  158. */
  159. LIB61850_API int32_t
  160. GooseSubscriber_getAppId(GooseSubscriber self);
  161. /**
  162. * \brief Get the source MAC address of the received GOOSE message
  163. *
  164. * \param self GooseSubscriber instance to operate on.
  165. * \param buffer buffer to store the MAC address (at least 6 byte)
  166. */
  167. LIB61850_API void
  168. GooseSubscriber_getSrcMac(GooseSubscriber self, uint8_t* buffer);
  169. /**
  170. * \brief Get the destination MAC address of the received GOOSE message
  171. *
  172. * \param self GooseSubscriber instance to operate on.
  173. * \param buffer buffer to store the MAC address (at least 6 byte)
  174. */
  175. LIB61850_API void
  176. GooseSubscriber_getDstMac(GooseSubscriber self, uint8_t* buffer);
  177. /**
  178. * \brief return the state number (stNum) of the last received GOOSE message.
  179. *
  180. * The state number is increased if any of the values in the GOOSE data set changed due to a valid trigger condition
  181. *
  182. * \param self GooseSubscriber instance to operate on.
  183. *
  184. * \return the state number of the last received GOOSE message
  185. */
  186. LIB61850_API uint32_t
  187. GooseSubscriber_getStNum(GooseSubscriber self);
  188. /**
  189. * \brief return the sequence number (sqNum) of the last received GOOSE message.
  190. *
  191. * The sequence number is increased for every consecutive GOOSE message without state change. When a state change occurs (stNum is increased)
  192. * then the sequence number (sqNum) will be reset.
  193. *
  194. * \param self GooseSubscriber instance to operate on.
  195. *
  196. * \return the sequence number of the last received GOOSE message
  197. */
  198. LIB61850_API uint32_t
  199. GooseSubscriber_getSqNum(GooseSubscriber self);
  200. /**
  201. * \brief returns the test flag of the last received GOOSE message
  202. *
  203. * IMPORTANT: Goose messages with test=TRUE have to be ignored to be standard compliant!
  204. *
  205. * \param self GooseSubscriber instance to operate on.
  206. *
  207. * \return the state of the test flag of the last received GOOSE message.
  208. */
  209. LIB61850_API bool
  210. GooseSubscriber_isTest(GooseSubscriber self);
  211. /**
  212. * \brief returns the confRev value of the last received GOOSE message
  213. *
  214. * \param self GooseSubscriber instance to operate on.
  215. *
  216. * \return the confRev value of the last received GOOSE message. If the message does not contain such
  217. * a value the result is always 0
  218. */
  219. LIB61850_API uint32_t
  220. GooseSubscriber_getConfRev(GooseSubscriber self);
  221. /**
  222. * \brief returns the value of the ndsCom (needs commission) flag of the last received GOOSE message.
  223. *
  224. * IMPORTANT: Goose messages with ndsCom=TRUE have to be ignored to be standard compliant!
  225. *
  226. * \param self GooseSubscriber instance to operate on.
  227. *
  228. * \return the state of the ndsCom flag of the last received GOOSE message.
  229. *
  230. */
  231. LIB61850_API bool
  232. GooseSubscriber_needsCommission(GooseSubscriber self);
  233. /**
  234. * \brief Get the TimeAllowedToLive value of the last received message.
  235. *
  236. * \param self GooseSubscriber instance to operate on.
  237. *
  238. * \return the TimeAllowedToLive value of the last received GOOSE message in milliseconds.
  239. */
  240. LIB61850_API uint32_t
  241. GooseSubscriber_getTimeAllowedToLive(GooseSubscriber self);
  242. /**
  243. * \brief Get the timestamp of the last received message.
  244. *
  245. * \param self GooseSubscriber instance to operate on.
  246. *
  247. * \return the timestamp value of the last received GOOSE message in milliseconds since epoch (1.1.1970 UTC).
  248. */
  249. LIB61850_API uint64_t
  250. GooseSubscriber_getTimestamp(GooseSubscriber self);
  251. /**
  252. * \brief get the data set values received with the last report
  253. *
  254. * Note: To prevent data corruption. The MmsValue instance received should
  255. * only be used inside of the callback function, when the GOOSE receiver is
  256. * running in a separate thread.
  257. *
  258. * \param self GooseSubscriber instance to operate on.
  259. *
  260. * \return MmsValue instance of the report data set
  261. */
  262. LIB61850_API MmsValue*
  263. GooseSubscriber_getDataSetValues(GooseSubscriber self);
  264. LIB61850_API bool
  265. GooseSubscriber_isVlanSet(GooseSubscriber self);
  266. LIB61850_API uint16_t
  267. GooseSubscriber_getVlanId(GooseSubscriber self);
  268. LIB61850_API uint8_t
  269. GooseSubscriber_getVlanPrio(GooseSubscriber self);
  270. /**
  271. * \brief Configure the Subscriber to listen to any received GOOSE message
  272. *
  273. * NOTE: When the observer flag is set the subscriber also has access to the
  274. * goCbRef, goId, and datSet values of the received GOOSE message
  275. */
  276. LIB61850_API void
  277. GooseSubscriber_setObserver(GooseSubscriber self);
  278. #ifdef __cplusplus
  279. }
  280. #endif
  281. /**@}*/
  282. #endif /* GOOSE_SUBSCRIBER_H_ */