Index: CloudConnect/CloudConnectController.h =================================================================== diff -u -r6d2ef8c97f4bb34204e95811839b3995000c47c1 -r59b4c22f45a1d098064a886452769204e90cfb4b --- CloudConnect/CloudConnectController.h (.../CloudConnectController.h) (revision 6d2ef8c97f4bb34204e95811839b3995000c47c1) +++ CloudConnect/CloudConnectController.h (.../CloudConnectController.h) (revision 59b4c22f45a1d098064a886452769204e90cfb4b) @@ -14,19 +14,24 @@ #include #include +#include // TODO: temporary for protobuf capture #include #include #include #include +#include #include #include +#include #include #include "CloudConnectFrame.h" #include "CanInterface.h" #include "CanMessage.h" #include "CloudConnectServer.h" #include "MessageDispatcher.h" +#include "MqttPublisher.h" +#include "MqttTcpTransport.h" using namespace Can; @@ -38,20 +43,15 @@ Q_OBJECT public: - explicit CloudConnectController(const QString &configPath, const QString &msgHandlingPath, QObject *parent = nullptr); + explicit CloudConnectController(const QString &configPath, const QString &msgHandlingPath, + QObject *parent = nullptr); ~CloudConnectController(); + bool startCan(); bool listenForApp(); + bool connectToCloud(); + void initThread(QThread &thread); -Q_SIGNALS: - /*! - * \brief didCanMessageReceive - * \details Emitted when a complete CAN message has been reassembled. - * \param timestamp - time the message was completed - * \param msg - the completed message - */ - void didCanMessageReceive(const QDateTime timestamp, const Can::Message msg); - private: /*! * \brief Send message handling policy for a CAN message. @@ -67,21 +67,32 @@ */ struct MsgHandling { MsgAction action = MsgAction::Drop; - CloudConnectFrame::Type topic = CloudConnectFrame::Type::NormalPriority; + CloudConnectFrame::Topic topic = CloudConnectFrame::Topic::NormalPriority; }; void loadMsgHandling(const QString &msgHandlingPath); + QString mqttTopic(CloudConnectFrame::Topic topic) const; + void captureProtobuf(const QByteArray &payload); // TODO: temporary for protobuf capture QSettings _settings; Can::CanInterface _canInterface; - QThread _canThread; Can::MessageDispatcher _dispatcher; QMap> _msgCache; QHash _msgHandling; - CloudConnectServer _appServer; - quint16 _txSequence = 0; + QSharedPointer _appServer; + QSharedPointer _mqttTransport; + MqttPublisher _publisher; + QString _topicPrefix; // TODO: define in INI? + QString _deviceId; // TODO: this needs to be sent from Leahi app or retrieved from somewhere + bool _mqttEnabled = false; + // TODO: temporary for protobuf capture + std::unique_ptr _captureSerFile; + std::unique_ptr _captureJsonFile; + private Q_SLOTS: void onFrameReceive(const QCanBusFrame frame); void onMessageReceive(const Can::Message &msg); + void onCloudConnectionChange(bool connected); + void onPublishAck(qint64 messageId, bool success); };