Index: CloudConnect/CloudConnectController.h =================================================================== diff -u -raaebfee335c74b0250864a6dce0555f866adadea -re9aa2c82ccb8cb5662f05ed878d2f7b5ef9f4a65 --- CloudConnect/CloudConnectController.h (.../CloudConnectController.h) (revision aaebfee335c74b0250864a6dce0555f866adadea) +++ CloudConnect/CloudConnectController.h (.../CloudConnectController.h) (revision e9aa2c82ccb8cb5662f05ed878d2f7b5ef9f4a65) @@ -15,11 +15,16 @@ #include #include #include +#include #include #include #include #include +#include +#include +#include + #include "CanInterface.h" #include "CanMessage.h" #include "CloudConnectFrame.h" @@ -41,10 +46,10 @@ ~CloudConnectController(); bool loadConfig(const QString &configPath); + void initThread(QThread &thread); bool startCan(); bool listenForApp(); bool connectToCloud(); - void initThread(QThread &thread); private: /*! @@ -74,18 +79,55 @@ QString _appServerSocketPath; QSharedPointer _appServer; MqttClient _mqttClient; + quint64 _publishSeqNum = 0; 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; + // BEGIN: Mesg Stats + struct MsgStats { + quint64 published = 0; ///< handed to the broker + quint64 echoed = 0; ///< came back on our own subscription and matched a publish + quint64 stale = 0; ///< came back but matched no in-flight publish + quint64 expired = 0; ///< published, never echoed within the echo window + }; + struct Inflight { + enum Status { + Unknown, + Sent, + ACK, + Published, + }; + Status status = Unknown; + Can::MsgId msgId = 0; + Can::Sequence sequence = 0; + qint64 sentUs = 0; ///< _msgTimer reading when the publish was handed to the broker + }; + QString canStats(Can::MsgId msgId, qint64 sinceLastUs) const; + qint64 msgElapsedUs(); + QString msgStats(const QString &label, Can::MsgId msgId, qint16 sequence, + const QString &latencyLabel, qint64 latencyUs, qint64 avgUs) const; + quint64 _canCount = 0; + qint64 _canAvgTime = 0; + qint64 _canTotalTime = 0; + qint64 _canLastRecv = 0; + QElapsedTimer _canTimer; + QElapsedTimer _msgTimer; + QHash _inflight; + quint64 _msgSentCount = 0; + quint64 _msgAckCount = 0; + quint64 _msgRecvCount = 0; + quint64 _msgRecvMatchCount = 0; + qint64 _msgAckTotalTime = 0; + qint64 _msgRecvTotalTime = 0; + qint64 _msgAckAvgTime = 0; + qint64 _msgRecvAvgTime = 0; + // END: Mesg Stats 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); + void onCloudMessageReceived(const QByteArray &message, const QMqttTopicName &topic); };