goose_receiver.h 4.9 KB

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