This commit is contained in:
flower_linux
2026-05-19 16:42:01 +08:00
parent 238b814057
commit fcafa81db1
21 changed files with 224 additions and 43 deletions

View File

@@ -47,14 +47,15 @@ public:
m_lastActivity = m_lastRx;
if (m_len + n > m_cfg.maxAdu) {
// 功能 如果数据块超过最大长度,则丢弃
LOG_WARNING() << "ModbusRtuFramerPlugin: overflow endpointHash=0x"
<< QString::number(m_endpointHash, 16);
<< QString::number(m_endpointHash, 16) << "bufLen=" << m_len << "chunk=" << n;
m_len = 0;
in.payload = {};
return;
}
std::memcpy(m_buf.data() + m_len, p, n);
m_len += n;
in.payload = {};
while (m_len > 0) {
auto pred = predictAduLength(m_buf.data(), m_len, m_cfg.maxAdu);
@@ -73,7 +74,9 @@ public:
auto blk = m_pool->allocate(*pred);
if (!blk || !blk->data || blk->capacity < *pred) {
return;
LOG_WARNING() << "ModbusRtuFramerPlugin: pool allocate failed endpointHash=0x"
<< QString::number(m_endpointHash, 16) << "aduLen=" << *pred << "bufLen=" << m_len;
break;
}
std::memcpy(blk->data, m_buf.data(), *pred);
blk->size = *pred;
@@ -104,8 +107,6 @@ public:
}
m_len = rest;
}
in.payload = {};
}
void reset() override { m_len = 0; }