diff --git a/CMakeLists.txt b/CMakeLists.txt index 095e7006..690ac7bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,23 +78,23 @@ 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 - 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 @@ -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) @@ -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