endpointhash
This commit is contained in:
@@ -17,10 +17,10 @@ class ModbusRtuFramerSession final : public softbus::core::plugin_system::IProto
|
||||
public:
|
||||
ModbusRtuFramerSession(std::shared_ptr<softbus::core::memory::MemoryPool> pool,
|
||||
ModbusRtuFramerPluginConfig cfg,
|
||||
QString endpoint)
|
||||
std::uint32_t endpointHash)
|
||||
: m_pool(std::move(pool))
|
||||
, m_cfg(cfg)
|
||||
, m_endpoint(std::move(endpoint))
|
||||
, m_endpointHash(endpointHash)
|
||||
{
|
||||
m_buf.resize(m_cfg.maxAdu);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
return;
|
||||
}
|
||||
const std::uint8_t* p = in.payload.bytes();
|
||||
const std::size_t n = in.payloadSize ? in.payloadSize : in.payload.length;
|
||||
const std::size_t n = in.payload.length;
|
||||
if (!p || n == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -47,7 +47,8 @@ public:
|
||||
m_lastActivity = m_lastRx;
|
||||
|
||||
if (m_len + n > m_cfg.maxAdu) {
|
||||
LOG_WARNING() << "ModbusRtuFramerPlugin: overflow endpoint=" << m_endpoint;
|
||||
LOG_WARNING() << "ModbusRtuFramerPlugin: overflow endpointHash=0x"
|
||||
<< QString::number(m_endpointHash, 16);
|
||||
m_len = 0;
|
||||
return;
|
||||
}
|
||||
@@ -78,16 +79,22 @@ public:
|
||||
|
||||
softbus::core::models::RawBusMessage framed;
|
||||
framed.deviceId = in.deviceId;
|
||||
framed.stableKey = in.stableKey;
|
||||
framed.endpoint = in.endpoint;
|
||||
framed.timestamp = in.timestamp;
|
||||
framed.protocolHint = in.protocolHint;
|
||||
framed.endpointHash = in.endpointHash;
|
||||
framed.protocol = softbus::core::models::ProtocolType::MODBUS_RTU;
|
||||
framed.logicalAddress = in.logicalAddress;
|
||||
framed.routingKey = in.routingKey;
|
||||
framed.header = in.header;
|
||||
framed.timestampMs = in.timestampMs;
|
||||
framed.traceId = in.traceId;
|
||||
framed.direction = in.direction;
|
||||
framed.payload.block = std::move(blk);
|
||||
framed.payload.offset = 0;
|
||||
framed.payload.length = *pred;
|
||||
framed.payloadSize = *pred;
|
||||
if (*pred >= 2 && framed.payload.block && framed.payload.block->data) {
|
||||
framed.header.modbus.slaveId = framed.payload.block->data[0];
|
||||
framed.header.modbus.functionCode = framed.payload.block->data[1];
|
||||
framed.logicalAddress = framed.header.modbus.slaveId;
|
||||
}
|
||||
out.push_back(std::move(framed));
|
||||
|
||||
const std::size_t rest = m_len - *pred;
|
||||
@@ -98,7 +105,6 @@ public:
|
||||
}
|
||||
|
||||
in.payload = {};
|
||||
in.payloadSize = 0;
|
||||
}
|
||||
|
||||
void reset() override { m_len = 0; }
|
||||
@@ -107,7 +113,7 @@ public:
|
||||
private:
|
||||
std::shared_ptr<softbus::core::memory::MemoryPool> m_pool;
|
||||
ModbusRtuFramerPluginConfig m_cfg;
|
||||
QString m_endpoint;
|
||||
std::uint32_t m_endpointHash{0};
|
||||
std::vector<std::uint8_t> m_buf;
|
||||
std::size_t m_len{0};
|
||||
std::chrono::steady_clock::time_point m_lastRx{std::chrono::steady_clock::now()};
|
||||
@@ -128,9 +134,9 @@ QString ModbusRtuFramerPlugin::pluginId() const
|
||||
return QStringLiteral("modbus_rtu_framer");
|
||||
}
|
||||
|
||||
bool ModbusRtuFramerPlugin::supports(const QString& protocolHint) const
|
||||
softbus::core::models::ProtocolType ModbusRtuFramerPlugin::protocolType() const
|
||||
{
|
||||
return isModbusRtuHint(protocolHint);
|
||||
return softbus::core::models::ProtocolType::MODBUS_RTU;
|
||||
}
|
||||
|
||||
void ModbusRtuFramerPlugin::bindMemoryPool(std::shared_ptr<softbus::core::memory::MemoryPool> pool)
|
||||
@@ -139,7 +145,7 @@ void ModbusRtuFramerPlugin::bindMemoryPool(std::shared_ptr<softbus::core::memory
|
||||
}
|
||||
|
||||
std::unique_ptr<softbus::core::plugin_system::IProtocolFramerSession>
|
||||
ModbusRtuFramerPlugin::createFramerSession(const QString& endpoint, const QJsonObject& params)
|
||||
ModbusRtuFramerPlugin::createFramerSession(std::uint32_t endpointHash, const QJsonObject& params)
|
||||
{
|
||||
if (!m_pool) {
|
||||
return {};
|
||||
@@ -152,7 +158,7 @@ ModbusRtuFramerPlugin::createFramerSession(const QString& endpoint, const QJsonO
|
||||
if (params.contains(QStringLiteral("modbusRtuInterFrameTimeoutMs"))) {
|
||||
cfg.interFrameTimeoutMs = params.value(QStringLiteral("modbusRtuInterFrameTimeoutMs")).toInt(cfg.interFrameTimeoutMs);
|
||||
}
|
||||
return std::make_unique<ModbusRtuFramerSession>(m_pool, cfg, endpoint);
|
||||
return std::make_unique<ModbusRtuFramerSession>(m_pool, cfg, endpointHash);
|
||||
}
|
||||
|
||||
std::shared_ptr<softbus::core::plugin_system::IProtocolFramerPlugin> makeModbusRtuFramerPlugin(
|
||||
|
||||
Reference in New Issue
Block a user