- GOOSE publisher: integrated error handling when Ethernet interface is not available

pull/179/head
Michael Zillgith 6 years ago
parent 1549367eed
commit 9a97519815

@ -51,6 +51,7 @@ main(int argc, char** argv)
*/
GoosePublisher publisher = GoosePublisher_create(&gooseCommParameters, interface);
if (publisher) {
GoosePublisher_setGoCbRef(publisher, "simpleIOGenericIO/LLN0$GO$gcbAnalogValues");
GoosePublisher_setConfRev(publisher, 1);
GoosePublisher_setDataSetRef(publisher, "simpleIOGenericIO/LLN0$AnalogValues");
@ -66,6 +67,10 @@ main(int argc, char** argv)
}
GoosePublisher_destroy(publisher);
}
else {
printf("Failed to create GOOSE publisher. Reason can be that the Ethernet interface doesn't exist or you need root permissions.\n");
}
LinkedList_destroyDeep(dataSetValues, (LinkedListValueDeleteFunction) MmsValue_delete);
}

@ -35,7 +35,7 @@
#define GOOSE_MAX_MESSAGE_SIZE 1518
static void
static bool
prepareGooseBuffer(GoosePublisher self, CommParameters* parameters, const char* interfaceID, bool useVlanTags);
struct sGoosePublisher {
@ -68,11 +68,19 @@ GoosePublisher_createEx(CommParameters* parameters, const char* interfaceID, boo
{
GoosePublisher self = (GoosePublisher) GLOBAL_CALLOC(1, sizeof(struct sGoosePublisher));
prepareGooseBuffer(self, parameters, interfaceID, useVlanTag);
if (self) {
if (prepareGooseBuffer(self, parameters, interfaceID, useVlanTag)) {
self->timestamp = MmsValue_newUtcTimeByMsTime(Hal_getTimeInMs());
GoosePublisher_reset(self);
}
else {
GoosePublisher_destroy(self);
self = NULL;
}
}
return self;
}
@ -86,7 +94,9 @@ GoosePublisher_create(CommParameters* parameters, const char* interfaceID)
void
GoosePublisher_destroy(GoosePublisher self)
{
if (self->ethernetSocket) {
Ethernet_destroySocket(self->ethernetSocket);
}
MmsValue_delete(self->timestamp);
@ -99,7 +109,9 @@ GoosePublisher_destroy(GoosePublisher self)
if (self->dataSetRef != NULL)
GLOBAL_FREEMEM(self->dataSetRef);
if (self->buffer)
GLOBAL_FREEMEM(self->buffer);
GLOBAL_FREEMEM(self);
}
@ -164,7 +176,7 @@ GoosePublisher_setTimeAllowedToLive(GoosePublisher self, uint32_t timeAllowedToL
self->timeAllowedToLive = timeAllowedToLive;
}
static void
static bool
prepareGooseBuffer(GoosePublisher self, CommParameters* parameters, const char* interfaceID, bool useVlanTags)
{
uint8_t srcAddr[6];
@ -199,6 +211,7 @@ prepareGooseBuffer(GoosePublisher self, CommParameters* parameters, const char*
else
self->ethernetSocket = Ethernet_createSocket(CONFIG_ETHERNET_INTERFACE_ID, dstAddr);
if (self->ethernetSocket) {
self->buffer = (uint8_t*) GLOBAL_MALLOC(GOOSE_MAX_MESSAGE_SIZE);
memcpy(self->buffer, dstAddr, 6);
@ -243,6 +256,12 @@ prepareGooseBuffer(GoosePublisher self, CommParameters* parameters, const char*
self->buffer[bufPos++] = 0x00;
self->payloadStart = bufPos;
return true;
}
else {
return false;
}
}
static int32_t

Loading…
Cancel
Save