From 46211a01e7e2918ee227beb4ddb81b73ccf0ab60 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 6 Nov 2018 10:15:29 +0100 Subject: [PATCH] - IEC 61850 client: IedConnection - added CONNECTING AND CLOSING states - removed IDLE state (now only CLOSED) --- src/iec61850/client/ied_connection.c | 18 ++++++++++-------- src/iec61850/inc/iec61850_client.h | 5 +++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/iec61850/client/ied_connection.c b/src/iec61850/client/ied_connection.c index 8846fc01..dcf1f96d 100644 --- a/src/iec61850/client/ied_connection.c +++ b/src/iec61850/client/ied_connection.c @@ -537,7 +537,7 @@ createNewConnectionObject(TLSConfiguration tlsConfig) else self->connection = MmsConnection_create(); - self->state = IED_STATE_IDLE; + self->state = IED_STATE_CLOSED; self->stateMutex = Semaphore_create(1); self->reportHandlerMutex = Semaphore_create(1); @@ -628,7 +628,6 @@ IedConnection_connect(IedConnection self, IedClientError* error, const char* hos MmsConnection_setConnectionLostHandler(self->connection, NULL, NULL); - MmsConnection_setConnectTimeout(self->connection, self->connectionTimeout); if (MmsConnection_connect(self->connection, &mmsError, hostname, tcpPort)) { @@ -637,7 +636,7 @@ IedConnection_connect(IedConnection self, IedClientError* error, const char* hos IedConnection_setState(self, IED_STATE_CONNECTED); } else { - IedConnection_setState(self, IED_STATE_IDLE); + IedConnection_setState(self, IED_STATE_CLOSED); *error = iedConnection_mapMmsErrorToIedError(mmsError); } } @@ -657,8 +656,6 @@ mmsConnectionStateChangedHandler(MmsConnection connection, void* parameter, MmsC { IedConnection self = (IedConnection) parameter; - printf("state changed: %d\n", newState); - if (newState == MMS_CONNECTION_STATE_CONNECTED) { IedConnection_setState(self, IED_STATE_CONNECTED); MmsConnection_setConnectionLostHandler(self->connection, connectionLostHandler, (void*) self); @@ -666,6 +663,12 @@ mmsConnectionStateChangedHandler(MmsConnection connection, void* parameter, MmsC else if (newState == MMS_CONNECTION_STATE_CLOSED) { IedConnection_setState(self, IED_STATE_CLOSED); } + else if (newState == MMS_CONNECTION_STATE_CLOSING) { + IedConnection_setState(self, IED_STATE_CLOSING); + } + else if (newState == MMS_CONNECTION_STATE_CONNECTING) { + IedConnection_setState(self, IED_STATE_CONNECTING); + } } void @@ -681,7 +684,6 @@ IedConnection_connectAsync(IedConnection self, IedClientError* error, const char //TODO move to createNewConnectionObject function MmsConnection_setConnectionStateChangedHandler(self->connection, mmsConnectionStateChangedHandler, self); - MmsConnection_connectAsync(self->connection, &mmsError, hostname, tcpPort); *error = iedConnection_mapMmsErrorToIedError(mmsError); @@ -694,7 +696,7 @@ void IedConnection_abort(IedConnection self, IedClientError* error) { if (IedConnection_getState(self) == IED_STATE_CONNECTED) { - IedConnection_setState(self, IED_STATE_CLOSED); + IedConnection_setState(self, IED_STATE_CLOSING); MmsError mmsError; @@ -753,8 +755,8 @@ void IedConnection_close(IedConnection self) { if (IedConnection_getState(self) == IED_STATE_CONNECTED) { + IedConnection_setState(self, IED_STATE_CLOSING); MmsConnection_close(self->connection); - IedConnection_setState(self, IED_STATE_CLOSED); } } diff --git a/src/iec61850/inc/iec61850_client.h b/src/iec61850/inc/iec61850_client.h index abd81340..c5eab497 100644 --- a/src/iec61850/inc/iec61850_client.h +++ b/src/iec61850/inc/iec61850_client.h @@ -71,9 +71,10 @@ typedef struct /** Connection state of the IedConnection instance (either idle, connected or closed) */ typedef enum { - IED_STATE_IDLE, + IED_STATE_CLOSED, + IED_STATE_CONNECTING, IED_STATE_CONNECTED, - IED_STATE_CLOSED + IED_STATE_CLOSING } IedConnectionState; /** used to describe the error reason for most client side service functions */