#include #include #include "LeahiRtController.h" #include "LeahiMsgDefs.h" LeahiRtController::LeahiRtController(const QString &configPath, QObject *parent) : QObject(parent), _settings(configPath, QSettings::IniFormat), _canInterface(), _canThread(this), _msgBuilder(this) { _canInterface.init(_canThread); connect(&_canInterface, &Can::CanInterface::didFrameReceive, this, &LeahiRtController::onFrameReceive); } LeahiRtController::~LeahiRtController() { _canThread.quit(); _canThread.wait(); _agentThread.quit(); _agentThread.wait(); } void LeahiRtController::connectToAgent() { 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]; if (_msgBuilder.buildMessage(frame.payload(), msg, canId) && msg.isComplete()) { 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(); } }