diff --git a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs index 926d008..b3fbc53 100644 --- a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs +++ b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs @@ -561,6 +561,9 @@ namespace IEC61850 [DllImport ("iec61850", CallingConvention=CallingConvention.Cdecl)] static extern IntPtr IedServer_create(IntPtr modelRef); + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern void IedServer_setLocalIpAddress(IntPtr self, string localIpAddress); + [DllImport ("iec61850", CallingConvention=CallingConvention.Cdecl)] static extern void IedServer_start(IntPtr self, int tcpPort); @@ -796,7 +799,28 @@ namespace IEC61850 private InternalConnectionHandler internalConnectionHandler = null; + /// + /// Sets the local ip address for listening + /// + /// Local IP address. + public void SetLocalIpAddress(string localIpAddress) + { + IedServer_setLocalIpAddress (self, localIpAddress); + } + + /// + /// Start MMS server + /// + /// Local IP address. + /// TCP port to use + public void Start(string localIpAddress, int tcpPort) + { + SetLocalIpAddress (localIpAddress); + Start (tcpPort); + } + /// Start MMS server + /// TCP port to use public void Start(int tcpPort) { if (internalConnectionHandler == null) diff --git a/dotnet/IEC61850forCSharp/IEC61850forCSharp.csproj b/dotnet/IEC61850forCSharp/IEC61850forCSharp.csproj index dc2a4dc..1c22e5a 100644 --- a/dotnet/IEC61850forCSharp/IEC61850forCSharp.csproj +++ b/dotnet/IEC61850forCSharp/IEC61850forCSharp.csproj @@ -7,6 +7,8 @@ Library iec61850dotnet iec61850dotnet + 8.0.30703 + 2.0 true diff --git a/src/iec61850/inc/iec61850_server.h b/src/iec61850/inc/iec61850_server.h index 338f76b..cf409da 100644 --- a/src/iec61850/inc/iec61850_server.h +++ b/src/iec61850/inc/iec61850_server.h @@ -76,6 +76,15 @@ IedServer_create(IedModel* iedModel); void IedServer_destroy(IedServer self); +/** + * \brief Set the local IP address to listen on + * + * \param self the IedServer instance + * \param localIpAddress the local IP address as C string (an internal copy will be created) + */ +void +IedServer_setLocalIpAddress(IedServer self, const char* localIpAddress); + /** * \brief Start handling client connections * @@ -106,6 +115,19 @@ IedServer_stop(IedServer self); void IedServer_startThreadless(IedServer self, int tcpPort); +/** + * \brief Wait until a server connection is ready (with timeout) + * + * The function will wait until a server connection is ready (data available) or the + * timeout elapsed. This function is intended for the non-threaded mode. Its use is optional. + * It is equivalent of using select on sockets on Linux. If the return value is != 0 the + * IedServer_processIncomingData function should be called. + * + * \param self the IedServer instance + * \param timeoutMs the timeout to wait when no connection is ready + * + * \return 0 if no connection is ready; otherwise at least one connection is ready + */ int IedServer_waitReady(IedServer self, unsigned int timeoutMs); diff --git a/src/iec61850/inc_private/ied_server_private.h b/src/iec61850/inc_private/ied_server_private.h index df14082..a9e5d9f 100644 --- a/src/iec61850/inc_private/ied_server_private.h +++ b/src/iec61850/inc_private/ied_server_private.h @@ -39,6 +39,7 @@ struct sIedServer MmsDevice* mmsDevice; MmsServer mmsServer; IsoServer isoServer; + char* localIpAddress; MmsMapping* mmsMapping; LinkedList clientConnections; uint8_t writeAccessPolicies; diff --git a/src/iec61850/server/impl/ied_server.c b/src/iec61850/server/impl/ied_server.c index eb20a5d..ebf1cc2 100644 --- a/src/iec61850/server/impl/ied_server.c +++ b/src/iec61850/server/impl/ied_server.c @@ -405,6 +405,7 @@ IedServer_create(IedModel* iedModel) self->model = iedModel; // self->running = false; /* not required due to CALLOC */ + // self->localIpAddress = NULL; /* not required due to CALLOC */ #if (CONFIG_MMS_THREADLESS_STACK != 1) self->dataModelLock = Semaphore_create(1); @@ -464,6 +465,9 @@ IedServer_destroy(IedServer self) MmsServer_destroy(self->mmsServer); IsoServer_destroy(self->isoServer); + if (self->localIpAddress != NULL) + GLOBAL_FREEMEM(self->localIpAddress); + #if ((CONFIG_MMS_SINGLE_THREADED == 1) && (CONFIG_MMS_THREADLESS_STACK == 0)) /* trigger stopping background task thread */ @@ -600,6 +604,16 @@ IedServer_stop(IedServer self) } #endif /* (CONFIG_MMS_THREADLESS_STACK != 1) */ +void +IedServer_setLocalIpAddress(IedServer self, const char* localIpAddress) +{ + if (self->localIpAddress != NULL) + GLOBAL_FREEMEM(self->localIpAddress); + + self->localIpAddress = StringUtils_copyString(localIpAddress); + IsoServer_setLocalIpAddress(self->isoServer, self->localIpAddress); +} + void IedServer_startThreadless(IedServer self, int tcpPort) diff --git a/src/vs/libiec61850-wo-goose.def b/src/vs/libiec61850-wo-goose.def index 065650a..9711a2c 100644 --- a/src/vs/libiec61850-wo-goose.def +++ b/src/vs/libiec61850-wo-goose.def @@ -560,4 +560,5 @@ EXPORTS IedConnection_readInt64Value Timestamp_create Timestamp_destroy - Timestamp_setByMmsUtcTime \ No newline at end of file + Timestamp_setByMmsUtcTime + IedServer_setLocalIpAddress \ No newline at end of file diff --git a/src/vs/libiec61850.def b/src/vs/libiec61850.def index 3a2ca38..45dc4d2 100644 --- a/src/vs/libiec61850.def +++ b/src/vs/libiec61850.def @@ -638,4 +638,5 @@ EXPORTS IedConnection_readInt64Value Timestamp_create Timestamp_destroy - Timestamp_setByMmsUtcTime \ No newline at end of file + Timestamp_setByMmsUtcTime + IedServer_setLocalIpAddress \ No newline at end of file