From 76cfa4637806792c05f8e95df50d15e841f1501a Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Fri, 26 Jan 2018 07:57:10 +0100 Subject: [PATCH] - fixed cmake file - added function IedModel_getDeviceByIndex --- CMakeLists.txt | 8 ++++---- src/iec61850/inc/iec61850_model.h | 11 +++++++++++ src/iec61850/server/model/model.c | 27 ++++++++++++++++++++++++--- src/vs/libiec61850-wo-goose.def | 3 ++- src/vs/libiec61850.def | 3 ++- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6386e101..690ac7bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,10 +91,10 @@ include_directories( ${CMAKE_CURRENT_LIST_DIR}/src/tls ) -set(API_HEADERS - src/hal/inc/hal_time.h +set(API_HEADERS + src/hal/inc/hal_time.h src/hal/inc/hal_thread.h - src/hal/inc/hal_filesystem.h + src/hal/inc/hal_filesystem.h src/hal/inc/hal_ethernet.h src/hal/inc/platform_endian.h src/common/inc/libiec61850_common_api.h @@ -162,7 +162,7 @@ configure_file( ) if(BUILD_EXAMPLES) - add_subdirectory(examples) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/examples) endif(BUILD_EXAMPLES) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src) diff --git a/src/iec61850/inc/iec61850_model.h b/src/iec61850/inc/iec61850_model.h index d4fbcb76..1828db19 100644 --- a/src/iec61850/inc/iec61850_model.h +++ b/src/iec61850/inc/iec61850_model.h @@ -468,6 +468,17 @@ IedModel_getModelNodeByShortAddress(IedModel* self, uint32_t shortAddress); LogicalDevice* IedModel_getDeviceByInst(IedModel* self, const char* ldInst); +/** + * \brief Lookup logical device (LD) instance by index + * + * \param self IedModel instance + * \param index the index of the LD in the range (0 .. number of LDs - 1) + * + * \return the corresponding LogicalDevice* object or NULL if the index is out of range + */ +LogicalDevice* +IedModel_getDeviceByIndex(IedModel* self, int index); + /** * \brief Lookup a logical node by name that is part of the given logical device diff --git a/src/iec61850/server/model/model.c b/src/iec61850/server/model/model.c index 6c709b95..0b5f84b7 100644 --- a/src/iec61850/server/model/model.c +++ b/src/iec61850/server/model/model.c @@ -75,12 +75,12 @@ IedModel_setAttributeValuesToNull(IedModel* iedModel) int -IedModel_getLogicalDeviceCount(IedModel* iedModel) +IedModel_getLogicalDeviceCount(IedModel* self) { - if (iedModel->firstChild == NULL) + if (self->firstChild == NULL) return 0; - LogicalDevice* logicalDevice = iedModel->firstChild; + LogicalDevice* logicalDevice = self->firstChild; int ldCount = 1; @@ -165,6 +165,27 @@ IedModel_getDeviceByInst(IedModel* self, const char* ldInst) return NULL; } + +LogicalDevice* +IedModel_getDeviceByIndex(IedModel* self, int index) +{ + LogicalDevice* logicalDevice = self->firstChild; + + int currentIndex = 0; + + while (logicalDevice) { + + if (currentIndex == index) + return logicalDevice; + + currentIndex++; + + logicalDevice = (LogicalDevice*) logicalDevice->sibling; + } + + return NULL; +} + static DataAttribute* ModelNode_getDataAttributeByMmsValue(ModelNode* self, MmsValue* value) { diff --git a/src/vs/libiec61850-wo-goose.def b/src/vs/libiec61850-wo-goose.def index d296c09c..f6c247ea 100644 --- a/src/vs/libiec61850-wo-goose.def +++ b/src/vs/libiec61850-wo-goose.def @@ -579,4 +579,5 @@ EXPORTS ClientGooseControlBlock_setDstAddress CDC_VSS_create CDC_VSG_create - Timestamp_createFromByteArray \ No newline at end of file + Timestamp_createFromByteArray + IedModel_getDeviceByIndex \ No newline at end of file diff --git a/src/vs/libiec61850.def b/src/vs/libiec61850.def index f6a6e8d2..b3289f79 100644 --- a/src/vs/libiec61850.def +++ b/src/vs/libiec61850.def @@ -705,4 +705,5 @@ EXPORTS SVSubscriber_ASDU_getQuality SVPublisher_ASDU_addQuality SVPublisher_ASDU_setQuality - Timestamp_createFromByteArray \ No newline at end of file + Timestamp_createFromByteArray + IedModel_getDeviceByIndex \ No newline at end of file