From 5bd03b0611accf3d18be55e2f287fa10e73ef7e9 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 26 Nov 2019 09:21:23 +0100 Subject: [PATCH] - IED server: added function ConfigFileParser_createModelFromConfigFileEx with filename as argument to avoid dependency on FileSystem_... functions - .NET projects: changed target framework of some project files to v4.0 --- dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs | 37 ++++++------------- dotnet/log_client/log_client.csproj | 4 +- dotnet/server1/server1.csproj | 6 ++- dotnet/sv_subscriber/sv_subscriber.csproj | 7 ++-- .../server_example_config_file.c | 13 +------ .../inc/iec61850_config_file_parser.h | 10 +++++ .../server/model/config_file_parser.c | 20 +++++++++- 7 files changed, 52 insertions(+), 45 deletions(-) diff --git a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs index b531a48b..89d8335d 100644 --- a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs +++ b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs @@ -36,33 +36,20 @@ namespace IEC61850 /// Config file parser. /// public class ConfigFileParser - { - - [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr FileSystem_openFile(string filePath, [MarshalAs(UnmanagedType.I1)] bool readWrite); - - - [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr ConfigFileParser_createModelFromConfigFile(IntPtr fileHandle); - - public static IedModel CreateModelFromConfigFile(string filePath) - { - IntPtr fileHandle = FileSystem_openFile (filePath, false); - - if (fileHandle != IntPtr.Zero) { - - IntPtr retVal = ConfigFileParser_createModelFromConfigFile (fileHandle); - if (retVal == IntPtr.Zero) { - return null; - } + { + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr ConfigFileParser_createModelFromConfigFileEx(string filename); - return new IedModel (retVal); + public static IedModel CreateModelFromConfigFile(string filePath) + { + IntPtr retVal = ConfigFileParser_createModelFromConfigFileEx (filePath); + if (retVal == IntPtr.Zero) { + return null; + } - } else - return null; - //TODO else throw exception - } - } + return new IedModel (retVal); + } + } /// /// Representation of the IED server data model diff --git a/dotnet/log_client/log_client.csproj b/dotnet/log_client/log_client.csproj index 23243060..f9defe5c 100644 --- a/dotnet/log_client/log_client.csproj +++ b/dotnet/log_client/log_client.csproj @@ -7,7 +7,7 @@ Exe log_client log_client - v4.5 + v4.0 true @@ -41,4 +41,4 @@ IEC61850.NET - \ No newline at end of file + diff --git a/dotnet/server1/server1.csproj b/dotnet/server1/server1.csproj index a66e2c30..d1c45eeb 100644 --- a/dotnet/server1/server1.csproj +++ b/dotnet/server1/server1.csproj @@ -7,7 +7,8 @@ Exe server1 server1 - v4.5 + v4.0 + true @@ -18,6 +19,7 @@ prompt 4 true + false full @@ -46,4 +48,4 @@ PreserveNewest - \ No newline at end of file + diff --git a/dotnet/sv_subscriber/sv_subscriber.csproj b/dotnet/sv_subscriber/sv_subscriber.csproj index dc8f53fe..4d0fa10d 100644 --- a/dotnet/sv_subscriber/sv_subscriber.csproj +++ b/dotnet/sv_subscriber/sv_subscriber.csproj @@ -1,4 +1,4 @@ - + Debug @@ -7,7 +7,8 @@ Exe sv_subscriber sv_subscriber - v4.5 + v4.0 + true @@ -41,4 +42,4 @@ IEC61850.NET - \ No newline at end of file + diff --git a/examples/server_example_config_file/server_example_config_file.c b/examples/server_example_config_file/server_example_config_file.c index 924707bc..f9bfbc3d 100644 --- a/examples/server_example_config_file/server_example_config_file.c +++ b/examples/server_example_config_file/server_example_config_file.c @@ -20,7 +20,6 @@ #include #include -#include "hal_filesystem.h" #include "iec61850_config_file_parser.h" static int running = 0; @@ -39,18 +38,8 @@ main(int argc, char** argv) tcpPort = atoi(argv[1]); } - /* open configuration file */ - FileHandle configFile = FileSystem_openFile("model.cfg", false); - - if (configFile == NULL) { - printf("Error opening config file!\n"); - return 1; - } - /* parse the configuration file and create the data model */ - IedModel* model = ConfigFileParser_createModelFromConfigFile(configFile); - - FileSystem_closeFile(configFile); + IedModel* model = ConfigFileParser_createModelFromConfigFileEx("model.cfg"); if (model == NULL) { printf("Error parsing config file!\n"); diff --git a/src/iec61850/inc/iec61850_config_file_parser.h b/src/iec61850/inc/iec61850_config_file_parser.h index 7c139b3b..c1eeda83 100644 --- a/src/iec61850/inc/iec61850_config_file_parser.h +++ b/src/iec61850/inc/iec61850_config_file_parser.h @@ -40,6 +40,16 @@ extern "C" { * @{ */ +/** + * \brief Create a data model from simple text configuration file + * + * \param filename name or path of the configuraton file + * + * \return the data model to be used by \ref IedServer + */ +LIB61850_API IedModel* +ConfigFileParser_createModelFromConfigFileEx(const char* filename); + LIB61850_API IedModel* ConfigFileParser_createModelFromConfigFile(FileHandle fileHandle); diff --git a/src/iec61850/server/model/config_file_parser.c b/src/iec61850/server/model/config_file_parser.c index a05d79dd..98240366 100644 --- a/src/iec61850/server/model/config_file_parser.c +++ b/src/iec61850/server/model/config_file_parser.c @@ -90,6 +90,24 @@ terminateString(char* string, char ch) } } +IedModel* +ConfigFileParser_createModelFromConfigFileEx(const char* filename) +{ + FileHandle configFile = FileSystem_openFile((char*)filename, false); + + if (configFile == NULL) { + if (DEBUG_IED_SERVER) + printf("IED_SERVER: Error opening config file!\n"); + return NULL; + } + + IedModel* model = ConfigFileParser_createModelFromConfigFile(configFile); + + FileSystem_closeFile(configFile); + + return model; +} + IedModel* ConfigFileParser_createModelFromConfigFile(FileHandle fileHandle) { @@ -268,7 +286,7 @@ ConfigFileParser_createModelFromConfigFile(FileHandle fileHandle) if (strcmp(currentLN->name, "LLN0") != 0) { if (DEBUG_IED_SERVER) - printf("Setting group control is not defined in LLN0\n"); + printf("IED_SERVER: Setting group control is not defined in LLN0\n"); goto exit_error; }