Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+92
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
#include "trimble_if.h"
|
||||
|
||||
#include "mainthread.h"
|
||||
#include "dgps_config.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QTcpSocket>
|
||||
#include <QHostAddress>
|
||||
#include <QFile>
|
||||
#include <QTimer>
|
||||
|
||||
namespace DifferentialGPS
|
||||
{
|
||||
TrimbleIF::TrimbleIF()
|
||||
: TcpSocket("TrimbleIF")
|
||||
, m_main(nullptr)
|
||||
, m_rxCycle_ms(10000)
|
||||
, m_socketTimeout(nullptr)
|
||||
, m_socketReconnect(nullptr)
|
||||
, m_threadIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
TrimbleIF::~TrimbleIF()
|
||||
{
|
||||
}
|
||||
|
||||
void TrimbleIF::startThread(int threadIndex, MainThread *main)
|
||||
{
|
||||
const DgpsConfig::TrimbleConfig_t &cfg = DgpsConfig::instance().getTrimbleConfig();
|
||||
m_threadIndex = threadIndex;
|
||||
m_main = main;
|
||||
startThreadInternal(cfg.ip[threadIndex], cfg.port[threadIndex]);
|
||||
}
|
||||
|
||||
void TrimbleIF::run()
|
||||
{
|
||||
m_socketTimeout = new QTimer;
|
||||
connect(m_socketTimeout, &QTimer::timeout, this, &TrimbleIF::onTimeout);
|
||||
m_socketReconnect = new QTimer;
|
||||
m_socketReconnect->setInterval(60 * 1000);
|
||||
connect(m_socketReconnect, &QTimer::timeout, this, &TrimbleIF::doConnect);
|
||||
|
||||
TcpSocket::run();
|
||||
|
||||
delete m_socketTimeout;
|
||||
delete m_socketReconnect;
|
||||
}
|
||||
|
||||
void TrimbleIF::onError(QAbstractSocket::SocketError err)
|
||||
{
|
||||
m_socketTimeout->stop(); // Timer anhalten
|
||||
|
||||
TcpSocket::onError(err); // Generelle Fehlerbehandlung
|
||||
}
|
||||
|
||||
|
||||
void TrimbleIF::onReadyRead()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Reading " << m_socket->bytesAvailable()
|
||||
<< " bytes from " << m_socket->peerAddress().toString()
|
||||
<< ":" << m_socket->peerPort();
|
||||
m_buf = m_socket->readAll();
|
||||
|
||||
m_main->addNewData(m_buf, m_threadIndex);
|
||||
|
||||
const DgpsConfig::TrimbleConfig_t &cfg = DgpsConfig::instance().getTrimbleConfig();
|
||||
m_socketTimeout->start(3 * cfg.rxCycle_ms); // starte/ restarte timeout-Ueberwachung (3-fache Zykluszeit)
|
||||
}
|
||||
|
||||
|
||||
void TrimbleIF::onTimeout()
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Socket timeout "
|
||||
<< m_socket->peerAddress().toString()
|
||||
<< ":" << m_socket->peerPort()
|
||||
<< " - trying to reconnect in " << m_socketReconnect->interval() / 1000 << " seconds";
|
||||
|
||||
m_socketTimeout->stop(); // Timer anhalten
|
||||
|
||||
m_socket->disconnectFromHost();
|
||||
if (m_socket->state() != QAbstractSocket::UnconnectedState)
|
||||
m_socket->waitForDisconnected();
|
||||
|
||||
m_socketReconnect->start();
|
||||
}
|
||||
} // namespace DifferentialGPS
|
||||
Reference in new issue
Block a user