Index: tools/AgentSim/AgentSimController.cpp =================================================================== diff -u -rcaca75be9a284ac5f98c078ec47c2e826ac5e980 -rc6a4b63a37f3beb1e8a51702ec3a56a1c32cfe8f --- tools/AgentSim/AgentSimController.cpp (.../AgentSimController.cpp) (revision caca75be9a284ac5f98c078ec47c2e826ac5e980) +++ tools/AgentSim/AgentSimController.cpp (.../AgentSimController.cpp) (revision c6a4b63a37f3beb1e8a51702ec3a56a1c32cfe8f) @@ -91,49 +91,49 @@ { _rxBuf.append(_client->readAll()); - CloudConnectFrame::FeedResult result; + CloudConnectFrame::ReadState state; do { - result = _rxMsg.feed(_rxBuf); - switch (result) { - case CloudConnectFrame::FeedResult::Complete: + state = _rxMsg.read(_rxBuf); + switch (state) { + case CloudConnectFrame::ReadState::Complete: handleMessage(_rxMsg); _rxMsg.reset(); break; - case CloudConnectFrame::FeedResult::HeaderError: + case CloudConnectFrame::ReadState::HeaderError: qWarning().noquote() << "AgentSim: header CRC error — frame dropped"; break; - case CloudConnectFrame::FeedResult::PayloadError: + case CloudConnectFrame::ReadState::PayloadError: qWarning().noquote() << "AgentSim: payload CRC error — frame dropped"; break; - case CloudConnectFrame::FeedResult::Incomplete: + case CloudConnectFrame::ReadState::Incomplete: break; } - } while (result == CloudConnectFrame::FeedResult::Complete && !_rxBuf.isEmpty()); + } while (state == CloudConnectFrame::ReadState::Complete && !_rxBuf.isEmpty()); } /*! * \brief AgentSimController::handleMessage * \details Decodes a received frame and prints its typed body as JSON, generically - * via the protobuf descriptor pool (msgId -> message name -> dynamic parse). + * via the protobuf descriptor pool (type -> message name -> dynamic parse). * \param msg The complete CloudConnectFrame frame. */ void AgentSimController::handleMessage(const CloudConnectFrame &msg) { const QByteArray payload = msg.payload(); - logMessage(msg.msgId(), msg.sequence(), payload); + logMessage(msg.type(), msg.sequence(), payload); - // Read the Header (field 1, shared by every typed message) to learn the msgId. + // Read the Header (field 1, shared by every typed message) to learn the type. leahi::messages::Envelope envelope; if (!envelope.ParseFromArray(payload.constData(), payload.size())) { qWarning().noquote() << "AgentSim: could not parse Envelope header — frame dropped"; return; } const leahi::messages::Header &header = envelope.header(); - // Identify the concrete message type from the msgId and decode it generically. + // Identify the concrete message type from the type and decode it generically. const std::string &typeName = leahi::msgIdToProtoName(static_cast(header.msgid())); if (typeName.empty()) { - qWarning().noquote() << QString("AgentSim: unknown msgId=0x%1 — cannot decode typed body") + qWarning().noquote() << QString("AgentSim: unknown type=0x%1 — cannot decode typed body") .arg(header.msgid(), 4, 16, QChar('0')); return; } @@ -158,25 +158,25 @@ opts.always_print_primitive_fields = true; google::protobuf::util::MessageToJsonString(*body, &json, opts); - // protobuf renders msgId as a decimal integer; rewrite it as 0x + 4-digit hex. + // protobuf renders type as a decimal integer; rewrite it as 0x + 4-digit hex. QString jsonStr = QString::fromStdString(json); - jsonStr.replace(QString("\"msgId\": %1").arg(header.msgid()), - QString("\"msgId\": \"0x%1\"").arg(header.msgid(), 4, 16, QChar('0'))); + jsonStr.replace(QString("\"type\": %1").arg(header.msgid()), + QString("\"type\": \"0x%1\"").arg(header.msgid(), 4, 16, QChar('0'))); qDebug().noquote() << QString::fromStdString(typeName) << ":" << Qt::endl << jsonStr; } /*! * \brief AgentSimController::logMessage * \details Logs the message identifier, sequence number, and payload length. - * \param msgId Message identifier from the parsed frame. + * \param type Message identifier from the parsed frame. * \param sequence Sequence number from the parsed frame. * \param payload Payload bytes of the parsed frame. */ -void AgentSimController::logMessage(CloudConnectFrame::MsgId msgId, quint16 sequence, const QByteArray &payload) +void AgentSimController::logMessage(CloudConnectFrame::Type type, quint16 sequence, const QByteArray &payload) { - qInfo().noquote() << QString("AgentSim: rx MsgId=0x%1 seq=%2 payloadLen=%3") - .arg(static_cast(msgId), 4, 16, QChar('0')) + qInfo().noquote() << QString("AgentSim: rx Type=0x%1 seq=%2 payloadLen=%3") + .arg(static_cast(type), 4, 16, QChar('0')) .arg(sequence) .arg(payload.size()); }