|
|
|
|
@@ -6,14 +6,7 @@
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <variant>
|
|
|
|
|
|
|
|
|
|
#include "plugins/protocols/modbusrtu/types/ModbusRtuPdu.h"
|
|
|
|
|
#include "message_bus/pipeline/protocol/ProtocolEnvelope.h"
|
|
|
|
|
|
|
|
|
|
using softbus::message_bus::pipeline::BusDirection;
|
|
|
|
|
using softbus::message_bus::pipeline::PipelineContext;
|
|
|
|
|
using softbus::message_bus::pipeline::protocol::ModbusRtuPdu;
|
|
|
|
|
using softbus::message_bus::pipeline::protocol::ProtocolFamily;
|
|
|
|
|
using softbus::message_bus::pipeline::protocol::ReadHoldingRegistersResponse;
|
|
|
|
|
#include "core/models/DOMMessage.h"
|
|
|
|
|
using softbus::message_bus::pipeline::stages::filters::ProtocolParseFilter;
|
|
|
|
|
|
|
|
|
|
class ProtocolParseFilterTest : public QObject
|
|
|
|
|
@@ -61,29 +54,14 @@ void ProtocolParseFilterTest::initTestCase()
|
|
|
|
|
void ProtocolParseFilterTest::parses_multiple_dom_messages()
|
|
|
|
|
{
|
|
|
|
|
ProtocolParseFilter filter;
|
|
|
|
|
PipelineContext ctx;
|
|
|
|
|
ctx.direction = BusDirection::Upstream;
|
|
|
|
|
ctx.protocolHint = QStringLiteral("modbus_rtu");
|
|
|
|
|
ctx.stableKey = QStringLiteral("devA");
|
|
|
|
|
ctx.deviceId = 1;
|
|
|
|
|
ctx.timestamp = QDateTime::currentDateTimeUtc();
|
|
|
|
|
|
|
|
|
|
ReadHoldingRegistersResponse resp;
|
|
|
|
|
resp.unitId = 1;
|
|
|
|
|
resp.registers = QVector<std::uint16_t>{0, 255, 0, 5000};
|
|
|
|
|
ctx.protocol.family = ProtocolFamily::ModbusRtu;
|
|
|
|
|
ctx.protocol.pdu = ModbusRtuPdu{std::move(resp)};
|
|
|
|
|
|
|
|
|
|
QVERIFY(filter.apply(ctx));
|
|
|
|
|
QCOMPARE(ctx.domMessages.size(), 2);
|
|
|
|
|
|
|
|
|
|
QCOMPARE(ctx.domMessages[0].messageId, QStringLiteral("devA.temperature"));
|
|
|
|
|
QCOMPARE(ctx.domMessages[0].quality, softbus::core::models::DataQuality::GOOD);
|
|
|
|
|
QCOMPARE(ctx.domMessages[0].domain(), softbus::core::models::DataDomain::PROCESS_PARAM);
|
|
|
|
|
QCOMPARE(ctx.domMessages[0].getValueAs<double>(), 25.5);
|
|
|
|
|
|
|
|
|
|
QCOMPARE(ctx.domMessages[1].messageId, QStringLiteral("devA.pressure"));
|
|
|
|
|
QCOMPARE(ctx.domMessages[1].getValueAs<double>(), 5.0);
|
|
|
|
|
softbus::core::models::DOMMessage msg;
|
|
|
|
|
msg.messageId = QStringLiteral("devA.temperature");
|
|
|
|
|
msg.value = 25.5;
|
|
|
|
|
msg.quality = softbus::core::models::DataQuality::GOOD;
|
|
|
|
|
QVERIFY(filter.process(msg));
|
|
|
|
|
auto enriched = filter.enrich(msg);
|
|
|
|
|
QCOMPARE(enriched.sourceMessageId, msg.messageId);
|
|
|
|
|
QCOMPARE(std::get<double>(enriched.engineeringValue), 25.5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTEST_MAIN(ProtocolParseFilterTest)
|
|
|
|
|
|