From 26a45a078b6c26a25ff6a2ec5d65e21866884fe3 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Mon, 25 Mar 2019 23:09:58 +0100 Subject: [PATCH] - added error handling code to client_example_log.c - fixed bug in ClientSVControlBlock --- .../client_example_log.c | 20 ++++++++++++------- src/iec61850/client/client_sv_control.c | 8 ++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/iec61850_client_example_log/client_example_log.c b/examples/iec61850_client_example_log/client_example_log.c index b7774848..333e0a70 100644 --- a/examples/iec61850_client_example_log/client_example_log.c +++ b/examples/iec61850_client_example_log/client_example_log.c @@ -72,16 +72,22 @@ int main(int argc, char** argv) { LinkedList logs = IedConnection_getLogicalNodeDirectory(con, &error, "simpleIOGenericIO/LLN0", ACSI_CLASS_LOG); if (error == IED_ERROR_OK) { - printf("Found log in LN simpleIOGenericIO/LLN0:\n"); - LinkedList log = LinkedList_getNext(logs); + if (LinkedList_size(logs) > 0) { + printf("Found logs in LN simpleIOGenericIO/LLN0:\n"); - while (log != NULL) { - char* logName = (char*) LinkedList_getData(log); + LinkedList log = LinkedList_getNext(logs); - printf(" %s\n", logName); + while (log != NULL) { + char* logName = (char*) LinkedList_getData(log); - log = LinkedList_getNext(log); + printf(" %s\n", logName); + + log = LinkedList_getNext(log); + } + } + else { + printf("No logs found\n"); } LinkedList_destroy(logs); @@ -90,7 +96,7 @@ int main(int argc, char** argv) { /* read log control block (using the generic read function) */ MmsValue* lcbValue = IedConnection_readObject(con, &error, "simpleIOGenericIO/LLN0.EventLog", IEC61850_FC_LG); - if (error == IED_ERROR_OK) { + if ((error == IED_ERROR_OK) && (MmsValue_getType(lcbValue) != MMS_DATA_ACCESS_ERROR)) { char printBuf[1024]; diff --git a/src/iec61850/client/client_sv_control.c b/src/iec61850/client/client_sv_control.c index 55e8ae5f..3f083243 100644 --- a/src/iec61850/client/client_sv_control.c +++ b/src/iec61850/client/client_sv_control.c @@ -45,17 +45,17 @@ ClientSVControlBlock_create(IedConnection connection, const char* reference) IedClientError error; MmsValue* value = IedConnection_readObject(connection, &error, reference, IEC61850_FC_MS); - if (value != NULL) { + if ((error == IED_ERROR_OK) && (MmsValue_getType(value) != MMS_DATA_ACCESS_ERROR)) { isMulticast = true; MmsValue_delete(value); } else { value = IedConnection_readObject(connection, &error, reference, IEC61850_FC_US); - if (value == NULL) + if ((error == IED_ERROR_OK) && (MmsValue_getType(value) != MMS_DATA_ACCESS_ERROR)) + MmsValue_delete(value); + else return NULL; - - MmsValue_delete(value); } ClientSVControlBlock self = (ClientSVControlBlock) GLOBAL_CALLOC(1, sizeof(struct sClientSVControlBlock));