- reporting.c: fixed report entry counter and assert problems

- IED server: disactivate all RCB instances when stopping the server
pull/367/head
Michael Zillgith 4 years ago
parent 434b9f59b7
commit 93d8dfc856

@ -153,6 +153,9 @@ Reporting_processReportEventsAfterUnlock(MmsMapping* self);
LIB61850_INTERNAL void LIB61850_INTERNAL void
Reporting_sendReports(MmsMapping* self, MmsServerConnection connection); Reporting_sendReports(MmsMapping* self, MmsServerConnection connection);
LIB61850_INTERNAL void
Reporting_deactivateAllReports(MmsMapping* self);
LIB61850_INTERNAL void LIB61850_INTERNAL void
Reporting_deactivateReportsForConnection(MmsMapping* self, MmsServerConnection connection); Reporting_deactivateReportsForConnection(MmsMapping* self, MmsServerConnection connection);

@ -719,6 +719,8 @@ IedServer_stop(IedServer self)
MmsMapping_stopEventWorkerThread(self->mmsMapping); MmsMapping_stopEventWorkerThread(self->mmsMapping);
Reporting_deactivateAllReports(self->mmsMapping);
#if (CONFIG_MMS_SINGLE_THREADED == 1) #if (CONFIG_MMS_SINGLE_THREADED == 1)
Thread_destroy(self->serverThread); Thread_destroy(self->serverThread);
self->serverThread = NULL; self->serverThread = NULL;

@ -3135,6 +3135,11 @@ mmsConnectionHandler(void* parameter, MmsServerConnection connection, MmsServerE
else if (event == MMS_SERVER_CONNECTION_CLOSED) { else if (event == MMS_SERVER_CONNECTION_CLOSED) {
ClientConnection clientConnection = private_IedServer_getClientConnectionByHandle(self->iedServer, connection); ClientConnection clientConnection = private_IedServer_getClientConnectionByHandle(self->iedServer, connection);
if (clientConnection == NULL) {
printf("clientConnection == NULL -> exit\n");
exit(-1);
}
/* call user provided handler function */ /* call user provided handler function */
if (self->connectionIndicationHandler != NULL) if (self->connectionIndicationHandler != NULL)
self->connectionIndicationHandler(self->iedServer, clientConnection, false, self->connectionIndicationHandler(self->iedServer, clientConnection, false,

@ -2099,16 +2099,9 @@ exit_function:
return retVal; return retVal;
} }
void static void
Reporting_deactivateReportsForConnection(MmsMapping* self, MmsServerConnection connection) Reporting_disableReportControlInstance(MmsMapping* self, ReportControl* rc)
{ {
LinkedList reportControl = self->reportControls;
while ((reportControl = LinkedList_getNext(reportControl)) != NULL) {
ReportControl* rc = (ReportControl*) reportControl->data;
if (rc->clientConnection == connection) {
rc->enabled = false; rc->enabled = false;
rc->clientConnection = NULL; rc->clientConnection = NULL;
@ -2143,6 +2136,34 @@ Reporting_deactivateReportsForConnection(MmsMapping* self, MmsServerConnection c
updateGenericTrackingObjectValues(self, rc, IEC61850_SERVICE_TYPE_INTERNAL_CHANGE, DATA_ACCESS_ERROR_SUCCESS); updateGenericTrackingObjectValues(self, rc, IEC61850_SERVICE_TYPE_INTERNAL_CHANGE, DATA_ACCESS_ERROR_SUCCESS);
#endif /* (CONFIG_IEC61850_SERVICE_TRACKING == 1) */ #endif /* (CONFIG_IEC61850_SERVICE_TRACKING == 1) */
} }
void
Reporting_deactivateAllReports(MmsMapping* self)
{
LinkedList rcElem = LinkedList_getNext(self->reportControls);
while (rcElem) {
ReportControl* rc = (ReportControl*)LinkedList_getData(rcElem);
Reporting_disableReportControlInstance(self, rc);
rcElem = LinkedList_getNext(rcElem);
}
}
void
Reporting_deactivateReportsForConnection(MmsMapping* self, MmsServerConnection connection)
{
LinkedList rcElem = LinkedList_getNext(self->reportControls);
while (rcElem) {
ReportControl* rc = (ReportControl*)LinkedList_getData(rcElem);
if (rc->clientConnection == connection) {
Reporting_disableReportControlInstance(self, rc);
}
rcElem = LinkedList_getNext(rcElem);
} }
} }
@ -2224,6 +2245,8 @@ removeAllGIReportsFromReportBuffer(ReportBuffer* reportBuffer)
printf("\n"); printf("\n");
#endif #endif
reportBuffer->reportsCount--;
if (reportBuffer->nextToTransmit == currentReport) if (reportBuffer->nextToTransmit == currentReport)
reportBuffer->nextToTransmit = currentReport->next; reportBuffer->nextToTransmit = currentReport->next;
@ -2253,6 +2276,10 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_
reportControl->name, (unsigned) reportControl->sqNum, reportControl->enabled, reportControl->name, (unsigned) reportControl->sqNum, reportControl->enabled,
reportControl->isBuffering, reportControl->buffered, isIntegrity, isGI); reportControl->isBuffering, reportControl->buffered, isIntegrity, isGI);
ReportBuffer* buffer = reportControl->reportBuffer;
Semaphore_wait(buffer->lock);
bool isBuffered = reportControl->buffered; bool isBuffered = reportControl->buffered;
bool overflow = false; bool overflow = false;
@ -2260,10 +2287,6 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_
int inclusionBitStringSize = MmsValue_getBitStringSize(reportControl->inclusionField); int inclusionBitStringSize = MmsValue_getBitStringSize(reportControl->inclusionField);
ReportBuffer* buffer = reportControl->reportBuffer;
Semaphore_wait(buffer->lock);
/* calculate size of complete buffer entry */ /* calculate size of complete buffer entry */
int bufferEntrySize = MemoryAllocator_getAlignedSize(sizeof(ReportBufferEntry)); int bufferEntrySize = MemoryAllocator_getAlignedSize(sizeof(ReportBufferEntry));
@ -2417,9 +2440,8 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_
#if (DEBUG_IED_SERVER == 1) #if (DEBUG_IED_SERVER == 1)
printf("IED_SERVER: REMOVE report with ID "); printf("IED_SERVER: REMOVE report with ID ");
printReportId(buffer->oldestReport); printReportId(buffer->oldestReport);
printf("\n"); printf(" (index: %li, size: %i)\n", (void*)(buffer->oldestReport) - (void*)(buffer->memoryBlock), buffer->oldestReport->entryLength);
#endif #endif
buffer->oldestReport = buffer->oldestReport->next; buffer->oldestReport = buffer->oldestReport->next;
buffer->reportsCount--; buffer->reportsCount--;
@ -2451,7 +2473,7 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_
} }
#if (DEBUG_IED_SERVER == 1) #if (DEBUG_IED_SERVER == 1)
printf("IED_SERVER: REMOVE report with ID "); printf("IED_SERVER: REMOVE[1] report with ID ");
printReportId(buffer->oldestReport); printReportId(buffer->oldestReport);
printf("\n"); printf("\n");
#endif #endif
@ -2474,7 +2496,7 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_
} }
#if (DEBUG_IED_SERVER == 1) #if (DEBUG_IED_SERVER == 1)
printf("IED_SERVER: REMOVE report with ID "); printf("IED_SERVER: REMOVE[2] report with ID ");
printReportId(buffer->oldestReport); printReportId(buffer->oldestReport);
printf("\n"); printf("\n");
#endif #endif
@ -2498,7 +2520,7 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_
} }
#if (DEBUG_IED_SERVER == 1) #if (DEBUG_IED_SERVER == 1)
printf("IED_SERVER: REMOVE report with ID "); printf("IED_SERVER: REMOVE[3] report with ID ");
printReportId(buffer->oldestReport); printReportId(buffer->oldestReport);
printf("\n"); printf("\n");
#endif #endif
@ -3031,8 +3053,6 @@ sendNextReportEntrySegment(ReportControl* self)
DataSetEntry* dataSetEntry = getDataSetEntryWithIndex(self->dataSet->fcdas, startElementIndex); DataSetEntry* dataSetEntry = getDataSetEntryWithIndex(self->dataSet->fcdas, startElementIndex);
for (i = startElementIndex; i < maxIndex; i++) { for (i = startElementIndex; i < maxIndex; i++) {
assert(dataSetEntry->value != NULL);
bool addReferenceForEntry = false; bool addReferenceForEntry = false;
if (report->flags > 0) if (report->flags > 0)

Loading…
Cancel
Save