Index: LeahiRt/LeahiRtController.cpp =================================================================== diff -u -r42bfa9903a12ff03e4051a6c9a9a0d188606dea7 -rf8c0a0b1c19dc386b2f88484d53db022270690a7 --- LeahiRt/LeahiRtController.cpp (.../LeahiRtController.cpp) (revision 42bfa9903a12ff03e4051a6c9a9a0d188606dea7) +++ LeahiRt/LeahiRtController.cpp (.../LeahiRtController.cpp) (revision f8c0a0b1c19dc386b2f88484d53db022270690a7) @@ -1,50 +1,44 @@ -#include -#include // SQ +#include #include #include "LeahiRtController.h" #include "LeahiMsgDefs.h" -LeahiRtController::LeahiRtController(QObject *parent) : +LeahiRtController::LeahiRtController(const QString &configPath, QObject *parent) : QObject(parent), + _settings(configPath, QSettings::IniFormat), _canInterface(), _canThread(this), - _clientSocket(QString(), QWebSocketProtocol::VersionLatest, this), _msgBuilder(this) - // SQ _protoInterface(), - // SQ _protoThread(this) { _canInterface.init(_canThread); connect(&_canInterface, &Can::CanInterface::didFrameReceive, this, &LeahiRtController::onFrameReceive); - - // SQ _protoInterface.init(_protoThread); - // SQ connect(this, &LeahiRtController::didCanMessageReceive, &_protoInterface, &proto::ProtoInterface::onCanMessageReceive); - - connect(&_clientSocket, &QWebSocket::connected, [&]() { qDebug().noquote() << "Socket connected"; }); } LeahiRtController::~LeahiRtController() { - _clientSocket.close(); + _canThread.quit(); + _canThread.wait(); + + _agentThread.quit(); + _agentThread.wait(); } -void LeahiRtController::openSocket(const QString host, const unsigned int port) +void LeahiRtController::connectToAgent() { - _clientSocket.close(); - _clientSocket.open(QUrl(QString("ws://%1:%2").arg(host).arg(port))); + const QString socketPath = _settings.value("Socket/LocalSocketName", "/tmp/leahi_rt.sock").toString(); + const int reconnectIntervalMs = _settings.value("Socket/ReconnectIntervalMs", 5000).toInt(); + _agentInterface.init(socketPath, reconnectIntervalMs, _agentThread); } void LeahiRtController::onFrameReceive(const QCanBusFrame frame) { const Can::CanId canId = Can::CanId(frame.frameId()); Can::Message &msg = _messages[canId]; - // construct the message from the received frame and determine if a complete message has been received if (_msgBuilder.buildMessage(frame.payload(), msg, canId) && msg.isComplete()) { - // SQ Q_EMIT didCanMessageReceive(QDateTime::currentDateTime(), msg); - // if (_clientSocket.isValid()) { - qDebug().noquote() << QString("Received message with MsgId=0x%1").arg(QString("%1").arg(msg.msgId, 4, 16, QChar('0')).toUpper()); - _clientSocket.sendBinaryMessage(leahi::canMessageToProtobufByteArray(QDateTime::currentDateTime(), QStringLiteral("test_device"), msg)); - // } + qDebug().noquote() << QString("Received message with MsgId=0x%1").arg(QString("%1").arg(msg.msgId, 4, 16, QChar('0')).toUpper()); + const QByteArray payload = leahi::canMessageToProtobufByteArray(QDateTime::currentDateTime(), QStringLiteral("test_device"), msg); + _agentInterface.send(AgentMessage::MsgId::ClinicalData, _txSequence++, payload); msg.clear(); } }