From f794fc27ce0f5eefe69d2928dea71cdb33c9026c Mon Sep 17 00:00:00 2001 From: vlad Date: Mon, 24 Jan 2022 19:52:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BD=D0=BE=D1=80=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=B4=D0=B5=D0=BA=D0=BE=D0=B4=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20explicit=20=D1=81=D0=BE=D0=BE?= =?UTF-8?q?=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MessageDecoder.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/MessageDecoder.cpp b/src/MessageDecoder.cpp index c3e97a0..92dab62 100644 --- a/src/MessageDecoder.cpp +++ b/src/MessageDecoder.cpp @@ -69,6 +69,7 @@ int MessageDecoder::getDestMac() const { switch (getGroup()) { case 3: case 1: + // там куча MsgId, но я ебал их в рот if (msg.dataLen != 0) return msg.data[0] & 0x3F; else @@ -105,7 +106,7 @@ std::string MessageDecoder::getMessageDescription() const { case 0xC: return "Slave I/O Change of state or cyclic message"; case 0xE: return "Slave I/O Bit-Strobe response message"; case 0xF: return "Slave I/O Poll response or COS/Cyclic Ack message"; - default: return "group 2 message"; + default: return "Group 1 message"; } case 2: switch (getMsgId()) { @@ -127,6 +128,7 @@ std::string MessageDecoder::getMessageDescription() const { } static std::string buildDataArray(const MessageStruct& msg) { + if (msg.dataLen == 0) return "{}"; std::string out = "{"; for (int i = 0; i < msg.dataLen; i++) { char tmp[8]; @@ -142,16 +144,30 @@ static std::string buildDataArray(const MessageStruct& msg) { static std::string buildExplicitMessageFrame(const MessageStruct& msg) { if (msg.dataLen == 0) return "empty explicit frame"; char buff[256]; - sprintf(buff, "{{Frag=%d, XID=%d, MAC=%d}, ", - (msg.data[0] & 0x80) != 0, (msg.data[0] & 0x40) != 0, msg.data[0] & 0x3F); + int headerLen; + if (msg.data[0] & 0x80) { + // Frag=1 + sprintf(buff, "{{Frag=1, XID=%d, MAC=%d}, {FragType=%d, Fragment count=%d}, {R/R=%d, ServiceCode=%d} Data=", + (msg.data[0] & 0x40) != 0, msg.data[0] & 0x3F, + (msg.data[1] & 0xC0) >> 6, msg.data[1] & 0x3F, + (msg.data[2] & 0x80) != 0, msg.data[2] & 0x7F); + headerLen = 3; + } else { + sprintf(buff, "{{Frag=0, XID=%d, MAC=%d}, {R/R=%d, ServiceCode=%d} Data=", + (msg.data[0] & 0x40) != 0, msg.data[0] & 0x3F, + (msg.data[1] & 0x80) != 0, msg.data[1] & 0x7F); + headerLen = 2; + } MessageStruct tmpMsg = msg; - if (tmpMsg.dataLen >= 1) { + if (tmpMsg.dataLen >= headerLen) { // убираем первый байт, чтобы посылка была - tmpMsg.dataLen--; - for (int i = 0; i < tmpMsg.dataLen; i++) { - tmpMsg.data[i] = tmpMsg.data[i + 1]; + tmpMsg.dataLen -= headerLen; + for (int i = 0; i < tmpMsg.dataLen - headerLen; i++) { + tmpMsg.data[i] = tmpMsg.data[i + headerLen]; } + } else { + return "invalid explicit frame " + buildDataArray(tmpMsg); } return buff + buildDataArray(tmpMsg) + "}"; }