goose_subscriber.h 9.9 KB

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