Index: lib/Comms/include/CloudConnectFrame.h =================================================================== diff -u -rc6a4b63a37f3beb1e8a51702ec3a56a1c32cfe8f -r59b4c22f45a1d098064a886452769204e90cfb4b --- lib/Comms/include/CloudConnectFrame.h (.../CloudConnectFrame.h) (revision c6a4b63a37f3beb1e8a51702ec3a56a1c32cfe8f) +++ lib/Comms/include/CloudConnectFrame.h (.../CloudConnectFrame.h) (revision 59b4c22f45a1d098064a886452769204e90cfb4b) @@ -15,23 +15,20 @@ #include /*! - * \brief CloudConnect to Connectivity Agent message framing - * \details Transport-agnostic binary framing. build() makes a wire-ready frame; - * read() parses inbound bytes (see ReadState). On Complete, read - * type()/sequence()/payload(), then reset(). + * \brief CloudConnect frame for communicating between client and CloudConnect. * * Frame layout — header only (payload_length == 0): * * Byte: 0 1 2 3 4 5 6-9 10 11 * ┌─────────┬────────┬────────┬───────────┬────────┐ - * │ AA 55 │ type │ seq_num│ pay_length│hdr_crc │ - * │ sync │uint16BE│uint16BE│ uint32 BE │uint16BE│ + * │ AA 55 │ topic │ seq_num│ pay_length│hdr_crc │ + * │ sync │ uint16 │ uint16 │ uint32 │ uint16 │ * └─────────┴────────┴────────┴───────────┴────────┘ * * Frame layout — with payload (payload_length > 0): * * ┌── 12-byte header ──┬── N bytes payload ──┬── pay_crc (4 B) ──┐ - * │ (see above) │ uint8[] │ CRC-32/ISO-HDLC │ + * │ header │ uint8[] │ CRC-32/ISO-HDLC │ * └────────────────────┴─────────────────────┴───────────────────┘ * * Header CRC: CRC-16/CCITT (poly 0x1021, init 0xFFFF, no reflection). @@ -42,38 +39,29 @@ public: /*! * \brief MQTT topic identifier carried in every frame header - * \details The Connectivity Agent uses this value to determine the MQTT topic. */ - enum class Type : quint16 { + enum class Topic : quint16 { HighPriority = 0x0001, NormalPriority = 0x0002, DeviceLogFile = 0x0003, TreatmentLogFile = 0x0004, CloudSyncLogFile = 0x0005, - // ClinicalData = 0x0001, - // Diagnostic = 0x0002, - // Ack = 0x0003, - // Alarms = 0x0004, - // Audit = 0x0005, - // DeviceLogFile = 0x0006, - // TreatmentLogFile = 0x0007, - // CloudSyncLogFile = 0x0008, }; /*! - * \brief Result returned by feed() after processing each byte chunk + * \brief Result returned by read() after processing each byte chunk */ enum class ReadState { - Incomplete, ///< More bytes needed — continue feeding. - Complete, ///< Full valid frame assembled — read accessors, then call reset(). - HeaderError, ///< Header CRC mismatch — frame dropped, state reset automatically. - PayloadError, ///< Payload CRC mismatch or oversized payload — frame dropped, state reset automatically. + Incomplete, + Complete, + HeaderError, + PayloadError, }; - static QByteArray build(Type type, quint16 sequence, const QByteArray &payload = {}); + static QByteArray build(Topic topic, quint16 sequence, const QByteArray &payload = {}); ReadState read(QByteArray &bytes); - Type type() const; + Topic topic() const; quint16 sequence() const; QByteArray payload() const; @@ -83,7 +71,7 @@ static constexpr int SYNC_SIZE = 2; static constexpr quint8 SYNC[SYNC_SIZE] = {0xAA, 0x55}; static constexpr int HEADER_SIZE = 12; - static constexpr int TYPE_SIZE = 2; + static constexpr int TOPIC_SIZE = 2; static constexpr int SEQUENCE_SIZE = 2; static constexpr int HEADER_CRC_SIZE = 2; static constexpr int PAYLOAD_CRC_SIZE = 4; @@ -93,7 +81,7 @@ static quint32 crc32isohdlc(const quint8 *data, int len); QByteArray _headerBuf; - Type _rxType = Type::NormalPriority; + Topic _rxTopic = Topic::NormalPriority; quint16 _rxSequence = 0; quint32 _rxPayloadLen = 0; QByteArray _rxPayload;