Добавлено нормальное декодирование explicit сообщений

This commit is contained in:
vlad 2022-01-24 19:52:56 +03:00
parent c7efe2a31e
commit f794fc27ce

View File

@ -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) + "}";
}