Delay opening the IPSC connection in error cases.
This commit is contained in:
parent
5cbfa2b331
commit
f8790d91a8
2 changed files with 27 additions and 16 deletions
41
DMRIPSC.cpp
41
DMRIPSC.cpp
|
@ -43,8 +43,8 @@ m_socket(local),
|
||||||
m_enabled(false),
|
m_enabled(false),
|
||||||
m_slot1(slot1),
|
m_slot1(slot1),
|
||||||
m_slot2(slot2),
|
m_slot2(slot2),
|
||||||
m_status(DISCONNECTED),
|
m_status(WAITING_CONNECT),
|
||||||
m_retryTimer(1000U, 5U),
|
m_retryTimer(1000U, 10U),
|
||||||
m_timeoutTimer(1000U, 60U),
|
m_timeoutTimer(1000U, 60U),
|
||||||
m_buffer(NULL),
|
m_buffer(NULL),
|
||||||
m_salt(NULL),
|
m_salt(NULL),
|
||||||
|
@ -287,17 +287,32 @@ void CDMRIPSC::close()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_socket.close();
|
m_socket.close();
|
||||||
|
|
||||||
|
m_retryTimer.stop();
|
||||||
|
m_timeoutTimer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDMRIPSC::clock(unsigned int ms)
|
void CDMRIPSC::clock(unsigned int ms)
|
||||||
{
|
{
|
||||||
|
if (m_status == WAITING_CONNECT) {
|
||||||
|
m_retryTimer.clock(ms);
|
||||||
|
if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) {
|
||||||
|
bool ret = open();
|
||||||
|
if (!ret)
|
||||||
|
m_retryTimer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
in_addr address;
|
in_addr address;
|
||||||
unsigned int port;
|
unsigned int port;
|
||||||
int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, port);
|
int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, port);
|
||||||
if (length < 0) {
|
if (length < 0) {
|
||||||
LogError("Socket has failed, retrying connection to the master");
|
LogError("Socket has failed, retrying connection to the master");
|
||||||
close();
|
close();
|
||||||
open();
|
m_status = WAITING_CONNECT;
|
||||||
|
m_retryTimer.start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,20 +336,13 @@ void CDMRIPSC::clock(unsigned int ms)
|
||||||
m_timeoutTimer.start();
|
m_timeoutTimer.start();
|
||||||
m_retryTimer.start();
|
m_retryTimer.start();
|
||||||
} else {
|
} else {
|
||||||
/*
|
|
||||||
LogError("Login to the master has failed, stopping IPSC");
|
|
||||||
m_status = DISCONNECTED;
|
|
||||||
m_timeoutTimer.stop();
|
|
||||||
m_retryTimer.stop();
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Once the modem death spiral has been prevented in Modem.cpp
|
/* Once the modem death spiral has been prevented in Modem.cpp
|
||||||
the IPSC sometimes times out and reaches here.
|
the IPSC sometimes times out and reaches here.
|
||||||
We want it to reconnect so... */
|
We want it to reconnect so... */
|
||||||
|
|
||||||
LogError("Login to the master has failed, retrying ...");
|
LogError("Login to the master has failed, retrying ...");
|
||||||
close();
|
close();
|
||||||
open();
|
m_status = WAITING_CONNECT;
|
||||||
|
m_retryTimer.start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (::memcmp(m_buffer, "RPTACK", 6U) == 0) {
|
} else if (::memcmp(m_buffer, "RPTACK", 6U) == 0) {
|
||||||
|
@ -364,7 +372,8 @@ void CDMRIPSC::clock(unsigned int ms)
|
||||||
} else if (::memcmp(m_buffer, "MSTCL", 5U) == 0) {
|
} else if (::memcmp(m_buffer, "MSTCL", 5U) == 0) {
|
||||||
LogError("Master is closing down");
|
LogError("Master is closing down");
|
||||||
close();
|
close();
|
||||||
open();
|
m_status = WAITING_CONNECT;
|
||||||
|
m_retryTimer.start();
|
||||||
} else if (::memcmp(m_buffer, "MSTPONG", 7U) == 0) {
|
} else if (::memcmp(m_buffer, "MSTPONG", 7U) == 0) {
|
||||||
m_timeoutTimer.start();
|
m_timeoutTimer.start();
|
||||||
} else if (::memcmp(m_buffer, "RPTSBKN", 7U) == 0) {
|
} else if (::memcmp(m_buffer, "RPTSBKN", 7U) == 0) {
|
||||||
|
@ -400,7 +409,8 @@ void CDMRIPSC::clock(unsigned int ms)
|
||||||
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) {
|
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) {
|
||||||
LogError("Connection to the master has timed out, retrying connection");
|
LogError("Connection to the master has timed out, retrying connection");
|
||||||
close();
|
close();
|
||||||
open();
|
m_status = WAITING_CONNECT;
|
||||||
|
m_retryTimer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,7 +504,8 @@ bool CDMRIPSC::write(const unsigned char* data, unsigned int length)
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
LogError("Socket has failed when writing data to the master, retrying connection");
|
LogError("Socket has failed when writing data to the master, retrying connection");
|
||||||
close();
|
close();
|
||||||
open();
|
m_status = WAITING_CONNECT;
|
||||||
|
m_retryTimer.start();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ private:
|
||||||
bool m_slot2;
|
bool m_slot2;
|
||||||
|
|
||||||
enum STATUS {
|
enum STATUS {
|
||||||
DISCONNECTED,
|
WAITING_CONNECT,
|
||||||
WAITING_LOGIN,
|
WAITING_LOGIN,
|
||||||
WAITING_AUTHORISATION,
|
WAITING_AUTHORISATION,
|
||||||
WAITING_CONFIG,
|
WAITING_CONFIG,
|
||||||
|
|
Loading…
Reference in a new issue