diff --git a/config/stack_config.h b/config/stack_config.h index 5512c57f..54907198 100644 --- a/config/stack_config.h +++ b/config/stack_config.h @@ -68,9 +68,6 @@ /* maximum COTP (ISO 8073) TPDU size - valid range is 1024 - 8192 */ #define CONFIG_COTP_MAX_TPDU_SIZE 8192 -/* timeout while reading from TCP stream in ms */ -#define CONFIG_TCP_READ_TIMEOUT_MS 1000 - /* Ethernet interface ID for GOOSE and SV */ #define CONFIG_ETHERNET_INTERFACE_ID "eth0" //#define CONFIG_ETHERNET_INTERFACE_ID "vboxnet0" diff --git a/config/stack_config.h.cmake b/config/stack_config.h.cmake index 9365b492..45963309 100644 --- a/config/stack_config.h.cmake +++ b/config/stack_config.h.cmake @@ -63,9 +63,6 @@ /* maximum COTP (ISO 8073) TPDU size - valid range is 1024 - 8192 */ #define CONFIG_COTP_MAX_TPDU_SIZE 8192 -/* timeout while reading from TCP stream in ms */ -#define CONFIG_TCP_READ_TIMEOUT_MS 1000 - /* Ethernet interface ID for GOOSE and SV */ #define CONFIG_ETHERNET_INTERFACE_ID "eth0" //#define CONFIG_ETHERNET_INTERFACE_ID "vboxnet0" diff --git a/src/mms/inc_private/iso_client_connection.h b/src/mms/inc_private/iso_client_connection.h index 022ac6a9..1925cd2b 100644 --- a/src/mms/inc_private/iso_client_connection.h +++ b/src/mms/inc_private/iso_client_connection.h @@ -59,7 +59,7 @@ LIB61850_INTERNAL void IsoClientConnection_destroy(IsoClientConnection self); LIB61850_INTERNAL bool -IsoClientConnection_associateAsync(IsoClientConnection self, uint32_t connectTimeoutInMs); +IsoClientConnection_associateAsync(IsoClientConnection self, uint32_t connectTimeoutInMs, uint32_t readTimeoutInMs); /** * called by tick function diff --git a/src/mms/iso_client/iso_client_connection.c b/src/mms/iso_client/iso_client_connection.c index 709ce67b..7f12051f 100644 --- a/src/mms/iso_client/iso_client_connection.c +++ b/src/mms/iso_client/iso_client_connection.c @@ -77,6 +77,7 @@ struct sIsoClientConnection volatile int state; Semaphore stateMutex; + uint32_t readTimeoutInMs; /* read timeout in ms */ uint64_t nextReadTimeout; /* timeout value for read and connect */ Socket socket; @@ -322,7 +323,7 @@ IsoClientConnection_handleConnection(IsoClientConnection self) if (socketState == SOCKET_STATE_CONNECTED) { if (sendConnectionRequestMessage(self)) { - self->nextReadTimeout = Hal_getTimeInMs() + CONFIG_TCP_READ_TIMEOUT_MS; + self->nextReadTimeout = Hal_getTimeInMs() + self->readTimeoutInMs; nextState = INT_STATE_WAIT_FOR_COTP_CONNECT_RESP; } else { @@ -392,7 +393,7 @@ IsoClientConnection_handleConnection(IsoClientConnection self) else { sendAcseInitiateRequest(self); - self->nextReadTimeout = Hal_getTimeInMs() + CONFIG_TCP_READ_TIMEOUT_MS; + self->nextReadTimeout = Hal_getTimeInMs() + self->readTimeoutInMs; nextState = INT_STATE_WAIT_FOR_ACSE_RESP; } @@ -426,7 +427,7 @@ IsoClientConnection_handleConnection(IsoClientConnection self) self->callback(ISO_IND_ASSOCIATION_FAILED, self->callbackParameter, NULL); - nextState = INT_STATE_ERROR; + nextState = INT_STATE_CLOSE_ON_ERROR; } else { @@ -634,7 +635,7 @@ IsoClientConnection_handleConnection(IsoClientConnection self) bool -IsoClientConnection_associateAsync(IsoClientConnection self, uint32_t connectTimeoutInMs) +IsoClientConnection_associateAsync(IsoClientConnection self, uint32_t connectTimeoutInMs, uint32_t readTimeoutInMs) { Semaphore_wait(self->tickMutex); @@ -659,6 +660,9 @@ IsoClientConnection_associateAsync(IsoClientConnection self, uint32_t connectTim CONFIG_TCP_KEEPALIVE_CNT); #endif + /* set read timeout */ + self->readTimeoutInMs = readTimeoutInMs; + /* set timeout for connect */ self->nextReadTimeout = Hal_getTimeInMs() + connectTimeoutInMs; diff --git a/src/mms/iso_mms/client/mms_client_connection.c b/src/mms/iso_mms/client/mms_client_connection.c index 235f5fd6..4a304171 100644 --- a/src/mms/iso_mms/client/mms_client_connection.c +++ b/src/mms/iso_mms/client/mms_client_connection.c @@ -1741,7 +1741,7 @@ MmsConnection_connectAsync(MmsConnection self, MmsError* mmsError, const char* s } #endif /* (CONFIG_MMS_RAW_MESSAGE_LOGGING == 1) */ - if (IsoClientConnection_associateAsync(self->isoClient, self->connectTimeout)) { + if (IsoClientConnection_associateAsync(self->isoClient, self->connectTimeout, self->requestTimeout)) { setConnectionState(self, MMS_CONNECTION_STATE_CONNECTING); *mmsError = MMS_ERROR_NONE; }