From d5900a9c52d5a7f61a1488abbff15b6b8f37eaa3 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Thu, 25 Jan 2018 10:23:19 +0100 Subject: [PATCH 1/2] - cmake: fixed CMakeList.txt to allow to build the library as submodule --- CMakeLists.txt | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 095e7006..6386e101 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,17 +78,17 @@ option(DEBUG_HAL_ETHERNET "Enable Ethernet HAL printf debugging" ${DEBUG}) include_directories( ${CMAKE_CURRENT_BINARY_DIR}/config - src/common/inc - src/goose - src/sampled_values - src/hal/inc - src/iec61850/inc - src/iec61850/inc_private - src/mms/inc - src/mms/inc_private - src/mms/iso_mms/asn1c - src/logging - src/tls + ${CMAKE_CURRENT_LIST_DIR}/src/common/inc + ${CMAKE_CURRENT_LIST_DIR}/src/goose + ${CMAKE_CURRENT_LIST_DIR}/src/sampled_values + ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc + ${CMAKE_CURRENT_LIST_DIR}/src/iec61850/inc + ${CMAKE_CURRENT_LIST_DIR}/src/iec61850/inc_private + ${CMAKE_CURRENT_LIST_DIR}/src/mms/inc + ${CMAKE_CURRENT_LIST_DIR}/src/mms/inc_private + ${CMAKE_CURRENT_LIST_DIR}/src/mms/iso_mms/asn1c + ${CMAKE_CURRENT_LIST_DIR}/src/logging + ${CMAKE_CURRENT_LIST_DIR}/src/tls ) set(API_HEADERS @@ -134,7 +134,7 @@ set(API_HEADERS if(MSVC) include_directories( - src/vs + ${CMAKE_CURRENT_LIST_DIR}/src/vs ) endif(MSVC) @@ -144,8 +144,8 @@ endif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/third_party/mbedtls/mbedtls-2.6.0) if(WITH_MBEDTLS) include_directories( - src/tls/mbedtls - third_party/mbedtls/mbedtls-2.6.0/include + ${CMAKE_CURRENT_LIST_DIR}/src/tls/mbedtls + ${CMAKE_CURRENT_LIST_DIR}/third_party/mbedtls/mbedtls-2.6.0/include ) file(GLOB tls_SRCS ${CMAKE_CURRENT_LIST_DIR}/third_party/mbedtls/mbedtls-2.6.0/library/*.c) From 76cfa4637806792c05f8e95df50d15e841f1501a Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Fri, 26 Jan 2018 07:57:10 +0100 Subject: [PATCH 2/2] - 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