Index: lib/Comms/include/CloudConnectFrame.h =================================================================== diff -u -rcaca75be9a284ac5f98c078ec47c2e826ac5e980 -rc6a4b63a37f3beb1e8a51702ec3a56a1c32cfe8f --- lib/Comms/include/CloudConnectFrame.h (.../CloudConnectFrame.h) (revision caca75be9a284ac5f98c078ec47c2e826ac5e980) +++ lib/Comms/include/CloudConnectFrame.h (.../CloudConnectFrame.h) (revision c6a4b63a37f3beb1e8a51702ec3a56a1c32cfe8f) @@ -17,14 +17,14 @@ /*! * \brief CloudConnect to Connectivity Agent message framing * \details Transport-agnostic binary framing. build() makes a wire-ready frame; - * feed() parses inbound bytes (see FeedResult). On Complete, read - * msgId()/sequence()/payload(), then reset(). + * read() parses inbound bytes (see ReadState). On Complete, read + * type()/sequence()/payload(), then reset(). * * Frame layout — header only (payload_length == 0): * * Byte: 0 1 2 3 4 5 6-9 10 11 * ┌─────────┬────────┬────────┬───────────┬────────┐ - * │ AA 55 │ msg_id │ seq_num│ pay_length│hdr_crc │ + * │ AA 55 │ type │ seq_num│ pay_length│hdr_crc │ * │ sync │uint16BE│uint16BE│ uint32 BE │uint16BE│ * └─────────┴────────┴────────┴───────────┴────────┘ * @@ -44,51 +44,56 @@ * \brief MQTT topic identifier carried in every frame header * \details The Connectivity Agent uses this value to determine the MQTT topic. */ - enum class MsgId : quint16 { - ClinicalData = 0x0001, - Diagnostic = 0x0002, - Ack = 0x0003, - Alarms = 0x0004, - Audit = 0x0005, - DeviceLogFile = 0x0006, - TreatmentLogFile = 0x0007, - CloudSyncLogFile = 0x0008, + enum class Type : 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 */ - enum class FeedResult { + 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. }; - static QByteArray build(MsgId msgId, quint16 sequence, const QByteArray &payload = {}); - FeedResult feed(QByteArray &bytes); + static QByteArray build(Type type, quint16 sequence, const QByteArray &payload = {}); + ReadState read(QByteArray &bytes); - MsgId msgId() const; + Type type() const; quint16 sequence() const; QByteArray payload() const; void reset(); private: - static quint16 crc16ccitt(const quint8 *data, int len); - static quint32 crc32isohdlc(const quint8 *data, int len); - static constexpr int SYNC_SIZE = 2; static constexpr quint8 SYNC[SYNC_SIZE] = {0xAA, 0x55}; static constexpr int HEADER_SIZE = 12; - static constexpr int MSGID_SIZE = 2; + static constexpr int TYPE_SIZE = 2; static constexpr int SEQUENCE_SIZE = 2; static constexpr int HEADER_CRC_SIZE = 2; static constexpr int PAYLOAD_CRC_SIZE = 4; static constexpr quint32 MAX_PAYLOAD_LEN = 64 * 1024; + static quint16 crc16ccitt(const quint8 *data, int len); + static quint32 crc32isohdlc(const quint8 *data, int len); + QByteArray _headerBuf; - MsgId _rxMsgId = MsgId::ClinicalData; + Type _rxType = Type::NormalPriority; quint16 _rxSequence = 0; quint32 _rxPayloadLen = 0; QByteArray _rxPayload;