diff --git a/CMakeLists.txt b/CMakeLists.txt index f9f395ea..5afc22fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ option(CONFIG_IEC61850_REPORT_SERVICE "Build with support for IEC 61850 reportin option(CONFIG_IEC61850_LOG_SERVICE "Build with support for IEC 61850 logging services" ON) option(CONFIG_IEC61850_SETTING_GROUPS "Build with support for IEC 61850 setting group services" ON) -set(CONFIG_REPORTING_DEFAULT_REPORT_BUFFER_SIZE "8000" CACHE STRING "Default buffer size for buffered reports in byte" ) +set(CONFIG_REPORTING_DEFAULT_REPORT_BUFFER_SIZE "65536" CACHE STRING "Default buffer size for buffered reports in byte" ) # advanced options option(DEBUG "Enable debugging mode (include assertions)" OFF) @@ -60,22 +60,6 @@ option(DEBUG_SV_SUBSCRIBER "Enable Sampled Values subscriber debugging" ${DEBUG} option(DEBUG_SV_PUBLISHER "Enable Sampled Values publisher debugging" ${DEBUG}) option(DEBUG_HAL_ETHERNET "Enable Ethernet HAL printf debugging" ${DEBUG}) -#mark_as_advanced( -# DEBUG_SOCKET -# DEBUG_COTP -# DEBUG_ISO_SERVER -# DEBUG_ISO_CLIENT -# DEBUG_IED_SERVER -# DEBUG_IED_CLIENT -# DEBUG_MMS_SERVER -# DEBUG_MMS_CLIENT -# DEBUG_GOOSE_SUBSCRIBER -# DEBUG_GOOSE_PUBLISHER -# DEBUG_SV_SUBSCRIBER -# DEBUG_SV_PUBLISHER -# DEBUG_HAL_ETHERNET -#) - include_directories( ${CMAKE_CURRENT_BINARY_DIR}/config ${CMAKE_CURRENT_LIST_DIR}/src/common/inc @@ -161,7 +145,12 @@ configure_file( ${CMAKE_CURRENT_BINARY_DIR}/config/stack_config.h ) -include("${CMAKE_CURRENT_LIST_DIR}/hal/CMakeLists.txt") +#include("${CMAKE_CURRENT_LIST_DIR}/hal/CMakeLists.txt") +include_directories( + ${CMAKE_CURRENT_LIST_DIR}/hal/inc +) + +add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/hal") if(BUILD_EXAMPLES) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/examples) diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt index b2803309..850fe052 100644 --- a/hal/CMakeLists.txt +++ b/hal/CMakeLists.txt @@ -24,6 +24,7 @@ set (libhal_linux_SRCS ${CMAKE_CURRENT_LIST_DIR}/filesystem/linux/file_provider_linux.c ${CMAKE_CURRENT_LIST_DIR}/time/unix/time.c ${CMAKE_CURRENT_LIST_DIR}/serial/linux/serial_port_linux.c + ${CMAKE_CURRENT_LIST_DIR}/memory/lib_memory.c ) set (libhal_windows_SRCS @@ -33,6 +34,7 @@ set (libhal_windows_SRCS ${CMAKE_CURRENT_LIST_DIR}/filesystem/win32/file_provider_win32.c ${CMAKE_CURRENT_LIST_DIR}/time/win32/time.c ${CMAKE_CURRENT_LIST_DIR}/serial/win32/serial_port_win32.c + ${CMAKE_CURRENT_LIST_DIR}/memory/lib_memory.c ) set (libhal_bsd_SRCS @@ -41,6 +43,7 @@ set (libhal_bsd_SRCS ${CMAKE_CURRENT_LIST_DIR}/thread/bsd/thread_bsd.c ${CMAKE_CURRENT_LIST_DIR}/filesystem/linux/file_provider_linux.c ${CMAKE_CURRENT_LIST_DIR}/time/unix/time.c + ${CMAKE_CURRENT_LIST_DIR}/memory/lib_memory.c ) IF(WIN32) diff --git a/hal/ethernet/bsd/ethernet_bsd.c b/hal/ethernet/bsd/ethernet_bsd.c index f35d8b5d..f0eb48da 100644 --- a/hal/ethernet/bsd/ethernet_bsd.c +++ b/hal/ethernet/bsd/ethernet_bsd.c @@ -35,7 +35,7 @@ #include #include -#include "libiec61850_platform_includes.h" +#include "lib_memory.h" #include "hal_ethernet.h" struct sEthernetSocket { diff --git a/hal/ethernet/linux/ethernet_linux.c b/hal/ethernet/linux/ethernet_linux.c index 538a5e0e..36dde5ce 100644 --- a/hal/ethernet/linux/ethernet_linux.c +++ b/hal/ethernet/linux/ethernet_linux.c @@ -29,10 +29,11 @@ #include #include #include +#include #include -#include "libiec61850_platform_includes.h" +#include "lib_memory.h" #include "hal_ethernet.h" struct sEthernetSocket { diff --git a/hal/ethernet/win32/ethernet_win32.c b/hal/ethernet/win32/ethernet_win32.c index 8dca819c..a005c7c7 100644 --- a/hal/ethernet/win32/ethernet_win32.c +++ b/hal/ethernet/win32/ethernet_win32.c @@ -24,10 +24,10 @@ #include "stack_config.h" #include +#include #include "hal_ethernet.h" - -#include "libiec61850_platform_includes.h" +#include "lib_memory.h" #ifndef DEBUG_HAL_ETHERNET #define DEBUG_HAL_ETHERNET 1 diff --git a/hal/filesystem/linux/file_provider_linux.c b/hal/filesystem/linux/file_provider_linux.c index 235c5969..23805da1 100644 --- a/hal/filesystem/linux/file_provider_linux.c +++ b/hal/filesystem/linux/file_provider_linux.c @@ -1,7 +1,7 @@ /* * file_provider_linux.c * - * Copyright 2014 Michael Zillgith + * Copyright 2014-2018 Michael Zillgith * * This file is part of libIEC61850. * @@ -23,16 +23,16 @@ #include #include - +#include +#include +#include #include #include #include -#include "libiec61850_platform_includes.h" - #include "hal_filesystem.h" - #include "stack_config.h" +#include "lib_memory.h" struct sDirectoryHandle { DIR* handle; diff --git a/hal/filesystem/win32/file_provider_win32.c b/hal/filesystem/win32/file_provider_win32.c index 2f531e1d..ba795872 100644 --- a/hal/filesystem/win32/file_provider_win32.c +++ b/hal/filesystem/win32/file_provider_win32.c @@ -30,8 +30,9 @@ #include "hal_filesystem.h" -#include "libiec61850_platform_includes.h" +#include "platform_endian.h" #include "stack_config.h" +#include "lib_memory.h" #include diff --git a/hal/inc/hal_serial.h b/hal/inc/hal_serial.h new file mode 100644 index 00000000..b28804d5 --- /dev/null +++ b/hal/inc/hal_serial.h @@ -0,0 +1,155 @@ +/* + * hal_serial.h + * + * Copyright 2017 MZ Automation GmbH + * + * This file is part of lib60870-C + * + * lib60870-C is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * lib60870-C is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with lib60870-C. If not, see . + * + * See COPYING file for the complete license text. + */ + +#ifndef SRC_IEC60870_LINK_LAYER_SERIAL_PORT_H_ +#define SRC_IEC60870_LINK_LAYER_SERIAL_PORT_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \file hal_serial.h + * \brief Abstraction layer for serial ports. + * Has to be implemented for the serial link layer of CS 101. + */ + +/*! \addtogroup hal Platform (Hardware/OS) abstraction layer + * + * @{ + */ + +/** + * @defgroup HAL_SERIAL Access to serial interfaces + * + * Serial interface abstraction layer. This functions have to be implemented to + * port lib60870 to new platforms when the serial link layers are required. + * + * @{ + */ + +typedef struct sSerialPort* SerialPort; + +typedef enum { + SERIAL_PORT_ERROR_NONE = 0, + SERIAL_PORT_ERROR_INVALID_ARGUMENT = 1, + SERIAL_PORT_ERROR_INVALID_BAUDRATE = 2, + SERIAL_PORT_ERROR_OPEN_FAILED = 3, + SERIAL_PORT_ERROR_UNKNOWN = 99 +} SerialPortError; + +/** + * \brief Create a new SerialPort instance + * + * \param interfaceName identifier or name of the serial interface (e.g. "/dev/ttyS1" or "COM4") + * \param baudRate the baud rate in baud (e.g. 9600) + * \param dataBits the number of data bits (usually 8) + * \param parity defines what kind of parity to use ('E' - even parity, 'O' - odd parity, 'N' - no parity) + * \param stopBits the number of stop buts (usually 1) + * + * \return the new SerialPort instance + */ +SerialPort +SerialPort_create(const char* interfaceName, int baudRate, uint8_t dataBits, char parity, uint8_t stopBits); + +/** + * \brief Destroy the SerialPort instance and release all resources + */ +void +SerialPort_destroy(SerialPort self); + +/** + * \brief Open the serial interface + * + * \return true in case of success, false otherwise (use \ref SerialPort_getLastError for a detailed error code) + */ +bool +SerialPort_open(SerialPort self); + +/** + * \brief Close (release) the serial interface + */ +void +SerialPort_close(SerialPort self); + +/** + * \brief Get the baudrate used by the serial interface + * + * \return the baud rate in baud + */ +int +SerialPort_getBaudRate(SerialPort self); + +/** + * \brief Set the timeout used for message reception + * + * \param timeout the timeout value in ms. + */ +void +SerialPort_setTimeout(SerialPort self, int timeout); + +/** + * \brief Discard all data in the input buffer of the serial interface + */ +void +SerialPort_discardInBuffer(SerialPort self); + +/** + * \brief Read a byte from the interface + * + * \return number of read bytes of -1 in case of an error + */ +int +SerialPort_readByte(SerialPort self); + +/** + * \brief Write the number of bytes from the buffer to the serial interface + * + * \param buffer the buffer containing the data to write + * \param startPos start position in the buffer of the data to write + * \param numberOfBytes number of bytes to write + * + * \return number of bytes written, or -1 in case of an error + */ +int +SerialPort_write(SerialPort self, uint8_t* buffer, int startPos, int numberOfBytes); + +/** + * \brief Get the error code of the last operation + */ +SerialPortError +SerialPort_getLastError(SerialPort self); + +/*! @} */ + +/*! @} */ + +#ifdef __cplusplus +} +#endif + + +#endif /* SRC_IEC60870_LINK_LAYER_SERIAL_PORT_H_ */ diff --git a/src/common/inc/lib_memory.h b/hal/inc/lib_memory.h similarity index 99% rename from src/common/inc/lib_memory.h rename to hal/inc/lib_memory.h index 506a24ca..95314af0 100644 --- a/src/common/inc/lib_memory.h +++ b/hal/inc/lib_memory.h @@ -1,5 +1,5 @@ /* - * memory.h + * lib_memory.h * * Copyright 2014 Michael Zillgith * diff --git a/src/common/lib_memory.c b/hal/memory/lib_memory.c similarity index 95% rename from src/common/lib_memory.c rename to hal/memory/lib_memory.c index 0a4106b3..623ba212 100644 --- a/src/common/lib_memory.c +++ b/hal/memory/lib_memory.c @@ -1,7 +1,7 @@ /* * lib_memory.c * - * Copyright 2014 Michael Zillgith + * Copyright 2014-2018 Michael Zillgith * * This file is part of libIEC61850. * @@ -21,7 +21,8 @@ * See COPYING file for the complete license text. */ -#include "libiec61850_platform_includes.h" +#include +#include "lib_memory.h" static MemoryExceptionHandler exceptionHandler = NULL; static void* exceptionHandlerParameter = NULL; diff --git a/hal/socket/linux/socket_linux.c b/hal/socket/linux/socket_linux.c index e1761d47..2dded754 100644 --- a/hal/socket/linux/socket_linux.c +++ b/hal/socket/linux/socket_linux.c @@ -1,7 +1,7 @@ /* * socket_linux.c * - * Copyright 2013, 2014 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * * This file is part of libIEC61850. * @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -38,7 +39,8 @@ #include "hal_thread.h" -#include "libiec61850_platform_includes.h" +#include "stack_config.h" +#include "lib_memory.h" #ifndef DEBUG_SOCKET #define DEBUG_SOCKET 0 diff --git a/hal/socket/win32/socket_win32.c b/hal/socket/win32/socket_win32.c index b699816e..065e80b2 100644 --- a/hal/socket/win32/socket_win32.c +++ b/hal/socket/win32/socket_win32.c @@ -25,10 +25,11 @@ #include #include #include +#include #pragma comment (lib, "Ws2_32.lib") -#include "libiec61850_platform_includes.h" +#include "lib_memory.h" #include "hal_socket.h" #include "stack_config.h" diff --git a/hal/thread/bsd/thread_bsd.c b/hal/thread/bsd/thread_bsd.c index df16fc9c..7d882d22 100644 --- a/hal/thread/bsd/thread_bsd.c +++ b/hal/thread/bsd/thread_bsd.c @@ -26,7 +26,7 @@ #include #include "hal_thread.h" -#include "libiec61850_platform_includes.h" +#include "lib_memory.h" struct sThread { ThreadExecutionFunction function; diff --git a/hal/thread/linux/thread_linux.c b/hal/thread/linux/thread_linux.c index 0fd19e5a..488b7339 100644 --- a/hal/thread/linux/thread_linux.c +++ b/hal/thread/linux/thread_linux.c @@ -27,7 +27,7 @@ #include #include "hal_thread.h" -#include "libiec61850_platform_includes.h" +#include "lib_memory.h" struct sThread { ThreadExecutionFunction function; diff --git a/hal/thread/win32/thread_win32.c b/hal/thread/win32/thread_win32.c index 0eb39f65..aa72e613 100644 --- a/hal/thread/win32/thread_win32.c +++ b/hal/thread/win32/thread_win32.c @@ -22,7 +22,7 @@ */ #include -#include "libiec61850_platform_includes.h" +#include "lib_memory.h" #include "hal_thread.h" struct sThread { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f8cad77b..43aeb3b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,6 @@ set (lib_common_SRCS ./common/map.c ./common/linked_list.c ./common/byte_buffer.c -./common/lib_memory.c ./common/string_utilities.c ./common/buffer_chain.c ./common/conversions.c