#include #include // SQ #include #include "AlphaOmega.h" // SQ #include "CloudSyncRtController.h" #include "LeahiMsgDefs.h" CloudSyncRtController::CloudSyncRtController(QObject *parent) : QObject(parent), _canInterface(), _canThread(this), _clientSocket(QString(), QWebSocketProtocol::VersionLatest, this), _msgBuilder(this) // SQ _protoInterface(), // SQ _protoThread(this) { _canInterface.init(_canThread); connect(&_canInterface, &Can::CanInterface::didFrameReceive, this, &CloudSyncRtController::onFrameReceive); // SQ _protoInterface.init(_protoThread); // SQ connect(this, &CloudSyncRtController::didCanMessageReceive, &_protoInterface, &proto::ProtoInterface::onCanMessageReceive); connect(&_clientSocket, &QWebSocket::connected, [&]() { qDebug().noquote() << "Socket connected"; }); } CloudSyncRtController::~CloudSyncRtController() { _clientSocket.close(); } void CloudSyncRtController::openSocket(const QString host, const unsigned int port) { AO_BEGIN_END_CLASS(ao) // SQ _clientSocket.close(); _clientSocket.open(QUrl(QString("ws://%1:%2").arg(host).arg(port))); } void CloudSyncRtController::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)); // } msg.clear(); } }