/*! * * Copyright (c) 2024-2026 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file CloudConnectController.h * \author (original) Stephen Quong * \date (original) 24-May-2026 * */ #pragma once #include #include #include #include #include #include #include #include "CanInterface.h" #include "CanMessage.h" #include "CloudConnectFrame.h" #include "CloudConnectServer.h" #include "MessageDispatcher.h" #include "MqttClient.h" using namespace Can; /*! * \brief CloudConnect controller */ class CloudConnectController : public QObject { Q_OBJECT public: explicit CloudConnectController(QObject *parent = nullptr); ~CloudConnectController(); bool loadConfig(const QString &configPath); bool startCan(); bool listenForApp(); bool connectToCloud(); void initThread(QThread &thread); private: /*! * \brief CAN message routing actions */ enum class CanAction { Drop, SendAlways, SendDelta, }; /*! * \brief CAN message routing entry loaded from CAN handling INI. */ struct CanRouting { CanAction action = CanAction::Drop; CloudConnectFrame::Topic topic = CloudConnectFrame::Topic::NormalPriority; }; bool loadCanRouting(const QString &canRoutingPath); QString mqttTopic(CloudConnectFrame::Topic topic) const; Can::CanInterface _canInterface; Can::MessageDispatcher _dispatcher; QMap> _canCache; QHash _canRouting; QString _appServerSocketPath; QSharedPointer _appServer; MqttClient _mqttClient; QString _topicPrefix; // TODO: define in INI? QString _deviceId; // TODO: this needs to be sent from Leahi app or retrieved from somewhere QString _serialNumber; QString _deviceCertPath; QString _deviceKeyPath; private Q_SLOTS: void onCanFrameReceive(const QCanBusFrame &frame); void onCanMessageReceive(const Can::Message &msg); void onCloudStateChanged(QMqttClient::ClientState state); void onCloudMessageStatusChanged(qint32 id, QMqtt::MessageStatus status, const QMqttMessageStatusProperties &properties); void onCloudMessageReceived(const QString &topic, const QByteArray &payload); };