diff --git a/src/goose/goose_receiver.c b/src/goose/goose_receiver.c index 1985ee8c..c081542c 100644 --- a/src/goose/goose_receiver.c +++ b/src/goose/goose_receiver.c @@ -59,7 +59,7 @@ struct sGooseReceiver }; GooseReceiver -GooseReceiver_create() +GooseReceiver_createEx(uint8_t* buffer) { GooseReceiver self = (GooseReceiver) GLOBAL_MALLOC(sizeof(struct sGooseReceiver)); @@ -67,7 +67,7 @@ GooseReceiver_create() self->running = false; self->stop = false; self->interfaceId = NULL; - self->buffer = (uint8_t*) GLOBAL_MALLOC(ETH_BUFFER_LENGTH); + self->buffer = buffer; self->ethSocket = NULL; self->subscriberList = LinkedList_create(); #if (CONFIG_MMS_THREADLESS_STACK == 0) @@ -78,6 +78,18 @@ GooseReceiver_create() return self; } +GooseReceiver +GooseReceiver_create() +{ + GooseReceiver self = GooseReceiver_createEx(NULL); + + if (self) { + self->buffer = (uint8_t*) GLOBAL_MALLOC(ETH_BUFFER_LENGTH); + } + + return self; +} + void GooseReceiver_addSubscriber(GooseReceiver self, GooseSubscriber subscriber) { @@ -692,11 +704,10 @@ exit_with_fault: } static void -parseGooseMessage(GooseReceiver self, int numbytes) +parseGooseMessage(GooseReceiver self, uint8_t* buffer, int numbytes) { int bufPos; bool subscriberFound = false; - uint8_t* buffer = self->buffer; if (numbytes < 22) return; @@ -884,9 +895,15 @@ GooseReceiver_tick(GooseReceiver self) int packetSize = Ethernet_receivePacket(self->ethSocket, self->buffer, ETH_BUFFER_LENGTH); if (packetSize > 0) { - parseGooseMessage(self, packetSize); + parseGooseMessage(self, self->buffer, packetSize); return true; } else return false; } + +void +GooseReceiver_handleMessage(GooseReceiver self, uint8_t* buffer, int size) +{ + parseGooseMessage(self, buffer, size); +} diff --git a/src/goose/goose_receiver.h b/src/goose/goose_receiver.h index 997cb142..b13c2d21 100644 --- a/src/goose/goose_receiver.h +++ b/src/goose/goose_receiver.h @@ -1,7 +1,7 @@ /* * goose_receiver.h * - * Copyright 2014-2018 Michael Zillgith + * Copyright 2014-2019 Michael Zillgith * * This file is part of libIEC61850. * @@ -51,6 +51,19 @@ typedef struct sGooseReceiver* GooseReceiver; LIB61850_API GooseReceiver GooseReceiver_create(void); +/** + * \brief Create a new receiver instance using the provided buffer instead of allocating an own buffer + * + * A GooseReceiver instance is used to handle all GOOSE messages received on a specific + * network interface. + * + * \param buffer buffer to store Ethernet messages or NULL when using \ref GooseReceiver_handleMessage + * + * \return the new GooseReceiver instance + */ +LIB61850_API GooseReceiver +GooseReceiver_createEx(uint8_t* buffer); + /** * \brief sets the interface for the GOOSE receiver * @@ -134,7 +147,7 @@ GooseReceiver_stopThreadless(GooseReceiver self); /** * \brief Parse GOOSE messages if they are available * - * Call after reception of ethernet frame and periodically to to house keeping tasks + * Call after reception of an Ethernet frame or periodically * * \param self the receiver object * @@ -143,6 +156,19 @@ GooseReceiver_stopThreadless(GooseReceiver self); LIB61850_API bool GooseReceiver_tick(GooseReceiver self); +/** + * \brief Parse a GOOSE message + * + * Call after reception of an Ethernet frame (can be used as an alternative to \ref GooseReceiver_tick + * to avoid implementing the Ethernet HAL) + * + * \param self the receiver object + * \param buffer a buffer containing the complete Ethernet message + * \param size size of the Ethernet message + */ +LIB61850_API void +GooseReceiver_handleMessage(GooseReceiver self, uint8_t* buffer, int size); + /**@}*/ #ifdef __cplusplus diff --git a/src/mms/inc/mms_type_spec.h b/src/mms/inc/mms_type_spec.h index 2f07e4e2..4e710908 100644 --- a/src/mms/inc/mms_type_spec.h +++ b/src/mms/inc/mms_type_spec.h @@ -123,7 +123,10 @@ MmsVariableSpecification_getStructureElements(MmsVariableSpecification* self); * \brief returns the number of elements if the type is a complex type (structure, array) or the * bit size of integers, unsigned integers, floats, bit strings, visible and MMS strings and octet strings. * + * + * * \param self the MmsVariableSpecification object + * * \return the number of elements or -1 if not applicable */ LIB61850_API int