diff --git a/libshvchainpack/src/rpcdriver.cpp b/libshvchainpack/src/rpcdriver.cpp index 71d61899b..d998f07b3 100644 --- a/libshvchainpack/src/rpcdriver.cpp +++ b/libshvchainpack/src/rpcdriver.cpp @@ -49,7 +49,7 @@ void RpcDriver::sendRpcFrame(RpcFrame &&frame) frame = msg.toToRpcFrame(m_clientProtocolType); } auto frame_data = frame.toFrameData(); - logRpcData().nospace() << "FRAME DATA WRITE " << frame_data.size() << " bytes of data:\n" << shv::chainpack::utils::hexDump(frame_data); + //logRpcData().nospace() << "FRAME DATA WRITE " << frame_data.size() << " bytes of data:\n" << shv::chainpack::utils::hexDump(frame_data); writeFrameData(frame_data); } catch (const std::exception &e) { @@ -59,11 +59,6 @@ void RpcDriver::sendRpcFrame(RpcFrame &&frame) void RpcDriver::onFrameDataRead(const std::string &frame_data) { -#ifdef _MSC_VER - logRpcData() << __FUNCSIG__ << "+++++++++++++++++++++++++++++++++"; -#else - logRpcData() << __PRETTY_FUNCTION__ << "+++++++++++++++++++++++++++++++++"; -#endif logRpcData().nospace() << "FRAME DATA READ " << frame_data.size() << " bytes of data read:\n" << shv::chainpack::utils::hexDump(frame_data); try { auto frame = RpcFrame::fromFrameData(frame_data); diff --git a/libshvchainpack/src/rpcmessage.cpp b/libshvchainpack/src/rpcmessage.cpp index f68846358..1e7c7f569 100644 --- a/libshvchainpack/src/rpcmessage.cpp +++ b/libshvchainpack/src/rpcmessage.cpp @@ -52,13 +52,24 @@ void RpcMessage::MetaType::registerMetaType() //================================================================== RpcMessage RpcFrame::toRpcMessage(std::string *errmsg) const { + auto make_rpcmsg = [](const RpcValue &val, std::string *err_msg) { + try { + return RpcMessage(val); + } + catch (const std::exception &e) { + if (err_msg) { + *err_msg = e.what(); + } + } + return RpcMessage(); + }; switch (protocol) { case Rpc::ProtocolType::ChainPack: { auto val = RpcValue::fromChainPack(data, errmsg); if (!errmsg || (errmsg && errmsg->empty())) { auto m = meta; val.setMetaData(std::move(m)); - return RpcMessage(val); + return make_rpcmsg(val, errmsg); } break; } @@ -67,17 +78,21 @@ RpcMessage RpcFrame::toRpcMessage(std::string *errmsg) const if (!errmsg || (errmsg && errmsg->empty())) { auto m = meta; val.setMetaData(std::move(m)); - return RpcMessage(val); + return make_rpcmsg(val, errmsg); } break; } default: { + constexpr auto msg = "Invalid protocol type"; if (errmsg) { - *errmsg = "Invalid protocol type"; + *errmsg = msg; + } + else { + throw std::runtime_error(msg); } - return {}; } } + return {}; } diff --git a/libshviotqt/src/rpc/serialportsocket.cpp b/libshviotqt/src/rpc/serialportsocket.cpp index 25d79b943..2f075c4f5 100644 --- a/libshviotqt/src/rpc/serialportsocket.cpp +++ b/libshviotqt/src/rpc/serialportsocket.cpp @@ -12,6 +12,8 @@ #define logSerialPortSocketM() nCMessage("SerialPortSocket") #define logSerialPortSocketW() nCWarning("SerialPortSocket") +#define logRpcData() nCMessage("RpcData") + using namespace std; namespace shv::iotqt::rpc { @@ -38,7 +40,7 @@ SerialFrameReader::SerialFrameReader(CrcCheck crc) QList SerialFrameReader::addData(std::string_view data) { - shvDebug() << "===> received:" << data.size() << "bytes:" << chainpack::utils::hexArray(data.data(), data.size()); + logRpcData().nospace() << "FRAME DATA READ " << data.size() << " bytes of data read:\n" << shv::chainpack::utils::hexDump(data); QList response_request_ids; auto check_response_id = [this, &response_request_ids]() { std::istringstream in(m_readBuffer); diff --git a/libshviotqt/src/rpc/socket.cpp b/libshviotqt/src/rpc/socket.cpp index 0fc91d48a..8b8531da8 100644 --- a/libshviotqt/src/rpc/socket.cpp +++ b/libshviotqt/src/rpc/socket.cpp @@ -16,6 +16,8 @@ #include #endif +#define logRpcData() nCMessage("RpcData") + namespace shv::iotqt::rpc { //====================================================== @@ -102,10 +104,10 @@ int FrameReader::tryToReadMeta(std::istringstream &in) //====================================================== QList StreamFrameReader::addData(std::string_view data) { + logRpcData().nospace() << "FRAME DATA READ " << data.size() << " bytes of data read:\n" << shv::chainpack::utils::hexDump(data); using namespace chainpack; QList response_request_ids; m_readBuffer += data; - shvDebug() << "received:\n" << utils::hexDump(data); while (true) { std::istringstream in(m_readBuffer); int err_code;