goose_receiver.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * goose_receiver.h
  3. *
  4. * Copyright 2014-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_RECEIVER_H_
  24. #define GOOSE_RECEIVER_H_
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #include <stdbool.h>
  29. #include "hal_ethernet.h"
  30. #include "goose_subscriber.h"
  31. #include "r_session.h"
  32. /**
  33. * \addtogroup goose_api_group
  34. */
  35. /**@{*/
  36. typedef struct sGooseReceiver* GooseReceiver;
  37. /**
  38. * \brief Create a new receiver instance
  39. *
  40. * A GooseReceiver instance is used to handle all GOOSE messages received on a specific
  41. * network interface.
  42. *
  43. * \return the new GooseReceiver instance
  44. */
  45. LIB61850_API GooseReceiver
  46. GooseReceiver_create(void);
  47. /**
  48. * \brief Create a new receiver instance using the provided buffer instead of allocating an own buffer
  49. *
  50. * A GooseReceiver instance is used to handle all GOOSE messages received on a specific
  51. * network interface.
  52. *
  53. * \param buffer buffer to store Ethernet messages or NULL when using \ref GooseReceiver_handleMessage
  54. *
  55. * \return the new GooseReceiver instance
  56. */
  57. LIB61850_API GooseReceiver
  58. GooseReceiver_createEx(uint8_t* buffer);
  59. /**
  60. * \brief Create a new R-GOOSE receiver instance.
  61. *
  62. * \param session the remote session protocol instance
  63. *
  64. * \return the newly created receiver instance
  65. */
  66. LIB61850_API GooseReceiver
  67. GooseReceiver_createRemote(RSession session);
  68. /**
  69. * \brief sets the interface for the GOOSE receiver
  70. *
  71. * \param self the GooseReceiver instance
  72. * \param interfaceId
  73. */
  74. LIB61850_API void
  75. GooseReceiver_setInterfaceId(GooseReceiver self, const char* interfaceId);
  76. /**
  77. * \brief return the interface ID used by the GOOSE receiver
  78. *
  79. * \param self the GosseReceiver instance
  80. *
  81. * \return the Ethernet interface ID string
  82. */
  83. LIB61850_API const char*
  84. GooseReceiver_getInterfaceId(GooseReceiver self);
  85. /**
  86. * \brief Add a subscriber to this receiver instance
  87. *
  88. * NOTE: Do not call this function while the receiver is running (after GooseReceiver_start
  89. * has been called)!
  90. *
  91. * \param self the GooseReceiver instance
  92. * \param subscriber the GooseSubscriber instance to add
  93. */
  94. LIB61850_API void
  95. GooseReceiver_addSubscriber(GooseReceiver self, GooseSubscriber subscriber);
  96. /**
  97. * \brief Remove a subscriber from this receiver instance
  98. *
  99. * NOTE: Do not call this function while the receiver is running (after GooseReceiver_start
  100. * has been called)!
  101. *
  102. * \param self the GooseReceiver instance
  103. * \param subscriber the GooseSubscriber instance to remove
  104. */
  105. LIB61850_API void
  106. GooseReceiver_removeSubscriber(GooseReceiver self, GooseSubscriber subscriber);
  107. /**
  108. * \brief start the GOOSE receiver in a separate thread
  109. *
  110. * \param self the GooseReceiver instance
  111. */
  112. LIB61850_API void
  113. GooseReceiver_start(GooseReceiver self);
  114. /**
  115. * \brief stop the GOOSE receiver running in a separate thread
  116. *
  117. * This function is used to stop the receiver thread started with GooseReceiver_start
  118. *
  119. * \param self the GooseReceiver instance
  120. */
  121. LIB61850_API void
  122. GooseReceiver_stop(GooseReceiver self);
  123. /**
  124. * \brief Check if GOOSE receiver is running
  125. *
  126. * Can be used to check if \ref GooseReceiver_start has been successful.
  127. *
  128. * \param self the GooseReceiver instance
  129. *
  130. * \return true if GOOSE receiver is running, false otherwise
  131. */
  132. LIB61850_API bool
  133. GooseReceiver_isRunning(GooseReceiver self);
  134. /**
  135. * \brief Free all resource of the GooseReceiver and all installed GooseSubscribers
  136. *
  137. * \param self the GooseReceiver instance
  138. */
  139. LIB61850_API void
  140. GooseReceiver_destroy(GooseReceiver self);
  141. /***************************************
  142. * Functions for non-threaded operation
  143. ***************************************/
  144. LIB61850_API EthernetSocket
  145. GooseReceiver_startThreadless(GooseReceiver self);
  146. LIB61850_API void
  147. GooseReceiver_stopThreadless(GooseReceiver self);
  148. /**
  149. * \brief Parse GOOSE messages if they are available
  150. *
  151. * Call after reception of an Ethernet frame or periodically
  152. *
  153. * \param self the receiver object
  154. *
  155. * \return true if a message was available and has been parsed, false otherwise
  156. */
  157. LIB61850_API bool
  158. GooseReceiver_tick(GooseReceiver self);
  159. /**
  160. * \brief Parse a GOOSE message
  161. *
  162. * Call after reception of an Ethernet frame (can be used as an alternative to \ref GooseReceiver_tick
  163. * to avoid implementing the Ethernet HAL)
  164. *
  165. * \param self the receiver object
  166. * \param buffer a buffer containing the complete Ethernet message
  167. * \param size size of the Ethernet message
  168. */
  169. LIB61850_API void
  170. GooseReceiver_handleMessage(GooseReceiver self, uint8_t* buffer, int size);
  171. /**@}*/
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #endif /* GOOSE_RECEIVER_H_ */