diff --git a/src/common/constants.h b/src/common/constants.h index 5564cbd9f..c52a55648 100644 --- a/src/common/constants.h +++ b/src/common/constants.h @@ -321,6 +321,9 @@ const QLatin1String OPTIONS_MAPWIDGET_DEBUG("Options/MapWidgetDebug"); const QLatin1String OPTIONS_DOCKHANDLER_DEBUG("Options/DockHandlerDebug"); const QLatin1String OPTIONS_WHAZZUP_PARSER_DEBUG("Options/WhazzupParserDebug"); const QLatin1String OPTIONS_DATAREADER_DEBUG("Options/DataReaderDebug"); +const QLatin1String OPTIONS_DATAREADER_RECONNECT_SIM("Options/DataReaderReconnectSim"); +const QLatin1String OPTIONS_DATAREADER_RECONNECT_XP("Options/DataReaderReconnectXp"); +const QLatin1String OPTIONS_DATAREADER_RECONNECT_SOCKET("Options/DataReaderReconnectSocket"); const QLatin1String OPTIONS_WEATHER_DEBUG("Options/WeatherDebug"); const QLatin1String OPTIONS_MAP_JUMP_BACK_DEBUG("Options/MapJumpBackDebug"); const QLatin1String OPTIONS_PROFILE_JUMP_BACK_DEBUG("Options/ProfileJumpBackDebug"); diff --git a/src/connect/connectclient.cpp b/src/connect/connectclient.cpp index 4ee610d6a..3ddb2bd4a 100644 --- a/src/connect/connectclient.cpp +++ b/src/connect/connectclient.cpp @@ -40,6 +40,12 @@ using atools::fs::sc::DataReaderThread; +const static int FLUSH_QUEUE_MS = 50; + +/* Any metar fetched from the Simulator will time out in 15 seconds */ +const static int WEATHER_TIMEOUT_FS_SECS = 15; +const static int NOT_AVAILABLE_TIMEOUT_FS_SECS = 300; + ConnectClient::ConnectClient(MainWindow *parent) : QObject(parent), mainWindow(parent), metarIdentCache(WEATHER_TIMEOUT_FS_SECS), notAvailableStations(NOT_AVAILABLE_TIMEOUT_FS_SECS) @@ -58,16 +64,22 @@ ConnectClient::ConnectClient(MainWindow *parent) xpConnectHandler = new atools::fs::sc::XpConnectHandler(); // Create thread class that reads data from handler - dataReader = - new DataReaderThread(mainWindow, settings.getAndStoreValue(lnm::OPTIONS_DATAREADER_DEBUG, false).toBool()); + dataReader = new DataReaderThread(mainWindow, settings.getAndStoreValue(lnm::OPTIONS_DATAREADER_DEBUG, false).toBool()); + + directReconnectSimSec = settings.getAndStoreValue(lnm::OPTIONS_DATAREADER_RECONNECT_SIM, 15).toInt(); + directReconnectXpSec = settings.getAndStoreValue(lnm::OPTIONS_DATAREADER_RECONNECT_XP, 5).toInt(); + socketReconnectSec = settings.getAndStoreValue(lnm::OPTIONS_DATAREADER_RECONNECT_SOCKET, 10).toInt(); if(simConnectHandler->isLoaded()) + { dataReader->setHandler(simConnectHandler); + dataReader->setReconnectRateSec(directReconnectSimSec); + } else + { dataReader->setHandler(xpConnectHandler); - - // We were able to connect - dataReader->setReconnectRateSec(DIRECT_RECONNECT_SEC); + dataReader->setReconnectRateSec(directReconnectXpSec); + } connect(dataReader, &DataReaderThread::postSimConnectData, this, &ConnectClient::postSimConnectData); connect(dataReader, &DataReaderThread::postStatus, this, &ConnectClient::statusPosted); @@ -387,6 +399,12 @@ void ConnectClient::restoreState() dialog->restoreState(); dataReader->setHandler(handlerByDialogSettings()); + + if(isXpConnect()) + dataReader->setReconnectRateSec(directReconnectXpSec); + else if(isSimConnect()) + dataReader->setReconnectRateSec(directReconnectSimSec); + dataReader->setUpdateRate(dialog->getUpdateRateMs(dialog->getCurrentSimType())); dataReader->setAiFetchRadius(atools::geo::nmToKm(dialog->getAiFetchRadiusNm(dialog->getCurrentSimType()))); fetchOptionsChanged(dialog->getCurrentSimType()); @@ -583,9 +601,15 @@ void ConnectClient::connectInternal() if(dialog->isAnyConnectDirect()) { qDebug() << "Starting direct connection"; + // Datareader has its own reconnect mechanism dataReader->setHandler(handlerByDialogSettings()); + if(isXpConnect()) + dataReader->setReconnectRateSec(directReconnectXpSec); + else if(isSimConnect()) + dataReader->setReconnectRateSec(directReconnectSimSec); + // Copy settings from dialog updateRateChanged(dialog->getCurrentSimType()); fetchOptionsChanged(dialog->getCurrentSimType()); @@ -747,7 +771,7 @@ void ConnectClient::closeSocket(bool allowRestart) { // For socket based connection use a timer - direct connection reconnects automatically silent = true; - reconnectNetworkTimer.start(SOCKET_RECONNECT_SEC * 1000); + reconnectNetworkTimer.start(socketReconnectSec * 1000); } else silent = false; diff --git a/src/connect/connectclient.h b/src/connect/connectclient.h index cb5f9fea1..c5957f93a 100644 --- a/src/connect/connectclient.h +++ b/src/connect/connectclient.h @@ -117,16 +117,6 @@ class ConnectClient : void aiFetchOptionsChanged(); private: - /* Try to reconnect every 5 seconds when network connection is lost */ - const int SOCKET_RECONNECT_SEC = 5; - /* Try to reconnect every 5 seconds when the SimConnect or X-Plane connection is lost */ - const int DIRECT_RECONNECT_SEC = 5; - const int FLUSH_QUEUE_MS = 50; - - /* Any metar fetched from the Simulator will time out in 15 seconds */ - const int WEATHER_TIMEOUT_FS_SECS = 15; - const int NOT_AVAILABLE_TIMEOUT_FS_SECS = 300; - void readFromSocket(); void readFromSocketError(QAbstractSocket::SocketError); void connectedToServerSocket(); @@ -188,6 +178,15 @@ class ConnectClient : bool socketConnected = false; bool errorState = false; + + /* Try to reconnect every 10 seconds when network connection is lost */ + int socketReconnectSec = 10; + + /* Try to reconnect every 15 seconds when the SimConnect connection is lost */ + int directReconnectSimSec = 15; + + /* Try to reconnect every 5 seconds when the X-Plane connection is lost */ + int directReconnectXpSec = 5; }; #endif // LITTLENAVMAP_CONNECTCLIENT_H