Index: lib/Comms/src/CloudConnectFrame.cpp =================================================================== diff -u -rcaca75be9a284ac5f98c078ec47c2e826ac5e980 -rc6a4b63a37f3beb1e8a51702ec3a56a1c32cfe8f --- lib/Comms/src/CloudConnectFrame.cpp (.../CloudConnectFrame.cpp) (revision caca75be9a284ac5f98c078ec47c2e826ac5e980) +++ lib/Comms/src/CloudConnectFrame.cpp (.../CloudConnectFrame.cpp) (revision c6a4b63a37f3beb1e8a51702ec3a56a1c32cfe8f) @@ -21,12 +21,12 @@ /*! * \brief CloudConnectFrame::build * \details Builds a complete wire-ready frame with header and optional payload CRCs. - * \param msgId - message identifier for Agent MQTT topic + * \param type - message identifier for Agent MQTT topic * \param sequence - caller-managed sequence number * \param payload - optional payload; pass empty for zero-length frames (e.g. Ack) * \return complete frame ready to write to the transport */ -QByteArray CloudConnectFrame::build(MsgId msgId, quint16 sequence, const QByteArray &payload) +QByteArray CloudConnectFrame::build(Type type, quint16 sequence, const QByteArray &payload) { const quint32 payloadLen = static_cast(payload.size()); @@ -36,9 +36,9 @@ header[0] = SYNC[0]; header[1] = SYNC[1]; - qToBigEndian(static_cast(msgId), header + SYNC_SIZE); - qToBigEndian(sequence, header + SYNC_SIZE + MSGID_SIZE); - qToBigEndian(payloadLen, header + SYNC_SIZE + MSGID_SIZE + SEQUENCE_SIZE); + qToBigEndian(static_cast(type), header + SYNC_SIZE); + qToBigEndian(sequence, header + SYNC_SIZE + TYPE_SIZE); + qToBigEndian(payloadLen, header + SYNC_SIZE + TYPE_SIZE + SEQUENCE_SIZE); const quint16 hCrc = crc16ccitt(header, HEADER_SIZE - HEADER_CRC_SIZE); qToBigEndian(hCrc, header + HEADER_SIZE - HEADER_CRC_SIZE); @@ -59,21 +59,21 @@ // --------------------------------------------------------------------------- /*! - * \brief CloudConnectFrame::feed + * \brief CloudConnectFrame::read * \details Feeds raw bytes into the inbound parser state machine. * Consumed bytes are removed from the front of the buffer. - * On HeaderError or PayloadError the caller may call feed() again + * On HeaderError or PayloadError the caller may call read() again * immediately if the buffer is non-empty. * \param bytes - raw bytes from the transport; modified in-place - * \return FeedResult indicating the parser outcome + * \return ReadState indicating the parser outcome */ -CloudConnectFrame::FeedResult CloudConnectFrame::feed(QByteArray &bytes) +CloudConnectFrame::ReadState CloudConnectFrame::read(QByteArray &bytes) { int pos = 0; - FeedResult result = FeedResult::Incomplete; + ReadState state = ReadState::Incomplete; - // scan for a valid header — skipped when _headerBuf is already populated from a prior feed() call - while (_headerBuf.size() == 0 && bytes.size() - pos >= HEADER_SIZE && result != FeedResult::HeaderError) { + // scan for a valid header — skipped when _headerBuf is already populated from a prior read() call + while (_headerBuf.size() == 0 && bytes.size() - pos >= HEADER_SIZE && state != ReadState::HeaderError) { if (static_cast(bytes.at(pos)) == SYNC[0] && static_cast(bytes.at(pos + 1)) == SYNC[1]) { _headerBuf.append(bytes.constData() + pos, HEADER_SIZE); if (crc16ccitt(reinterpret_cast(_headerBuf.constData()), HEADER_SIZE - HEADER_CRC_SIZE) == @@ -82,8 +82,8 @@ { const quint8 *header = reinterpret_cast(_headerBuf.constData()); int header_pos = SYNC_SIZE; - _rxMsgId = static_cast(qFromBigEndian(header + header_pos)); - header_pos += MSGID_SIZE; + _rxType = static_cast(qFromBigEndian(header + header_pos)); + header_pos += TYPE_SIZE; _rxSequence = qFromBigEndian(header + header_pos); header_pos += SEQUENCE_SIZE; _rxPayloadLen = qFromBigEndian(header + header_pos); @@ -93,7 +93,7 @@ // TODO: log the header CRC failure _headerBuf.clear(); pos += SYNC_SIZE; - result = FeedResult::HeaderError; + state = ReadState::HeaderError; } } else { @@ -102,14 +102,14 @@ } // process payload if a valid header has been accumulated - if (result != FeedResult::HeaderError && _headerBuf.size() == HEADER_SIZE) { + if (state != ReadState::HeaderError && _headerBuf.size() == HEADER_SIZE) { if (_rxPayloadLen == 0) { - result = FeedResult::Complete; + state = ReadState::Complete; } else if (_rxPayloadLen > MAX_PAYLOAD_LEN) { // TODO: log the oversized payload _headerBuf.clear(); - result = FeedResult::PayloadError; + state = ReadState::PayloadError; } else if (bytes.size() - pos >= static_cast(_rxPayloadLen) + PAYLOAD_CRC_SIZE) { const quint8 *payload = reinterpret_cast(bytes.constData() + pos); @@ -118,37 +118,37 @@ { _rxPayload = QByteArray(reinterpret_cast(payload), static_cast(_rxPayloadLen)); pos += static_cast(_rxPayloadLen) + PAYLOAD_CRC_SIZE; - result = FeedResult::Complete; + state = ReadState::Complete; } else { // TODO: log the payload CRC failure _headerBuf.clear(); - result = FeedResult::PayloadError; + state = ReadState::PayloadError; } } } // remove the consumed bytes from the input buffer bytes.remove(0, pos); - return result; + return state; } /*! - * \brief CloudConnectFrame::msgId + * \brief CloudConnectFrame::type * \details Message identifier of the last complete frame. - * Valid only after feed() returns FeedResult::Complete. - * \return MsgId of the last complete frame + * Valid only after read() returns ReadState::Complete. + * \return Type of the last complete frame */ -CloudConnectFrame::MsgId CloudConnectFrame::msgId() const +CloudConnectFrame::Type CloudConnectFrame::type() const { - return _rxMsgId; + return _rxType; } /*! * \brief CloudConnectFrame::sequence * \details Sequence number of the last complete frame. - * Valid only after feed() returns FeedResult::Complete. + * Valid only after read() returns ReadState::Complete. * \return sequence number of the last complete frame */ quint16 CloudConnectFrame::sequence() const @@ -159,7 +159,7 @@ /*! * \brief CloudConnectFrame::payload * \details Payload bytes of the last complete frame. Empty for zero-length frames. - * Valid only after feed() returns FeedResult::Complete. + * Valid only after read() returns ReadState::Complete. * \return payload of the last complete frame */ QByteArray CloudConnectFrame::payload() const @@ -175,7 +175,7 @@ void CloudConnectFrame::reset() { _headerBuf.clear(); - _rxMsgId = MsgId::ClinicalData; + _rxType = Type::NormalPriority; _rxSequence = 0; _rxPayloadLen = 0; _rxPayload.clear();