• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wirenboard / wb-mqtt-serial / 689

26 Aug 2025 01:28PM UTC coverage: 73.031% (-0.08%) from 73.114%
689

push

github

web-flow
Add protocol parameter to device/Probe RPC (#988)

  * Add protocol to Modbus TCP port information in ports/Load RPC
  * Add protocol parameter to device/Probe RPC
  * Set TCP_NODELAY for TCP ports
  * Handle TCP port closing by remote

6605 of 9406 branches covered (70.22%)

28 of 59 new or added lines in 11 files covered. (47.46%)

68 existing lines in 3 files now uncovered.

12554 of 17190 relevant lines covered (73.03%)

372.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/rpc/rpc_device_probe_task.cpp
1
#include "rpc_device_probe_task.h"
2
#include "rpc_helpers.h"
3
#include "rpc_port_handler.h"
4
#include "rpc_port_scan_serial_client_task.h"
5
#include "serial_port.h"
6

7
#define LOG(logger) ::logger.Log() << "[RPC] "
8

9
template<> bool inline WBMQTT::JSON::Is<uint8_t>(const Json::Value& value)
×
10
{
11
    return value.isUInt();
×
12
}
13

14
template<> inline uint8_t WBMQTT::JSON::As<uint8_t>(const Json::Value& value)
×
15
{
16
    return value.asUInt() & 0xFF;
×
17
}
18

19
TRPCDeviceProbeSerialClientTask::TRPCDeviceProbeSerialClientTask(const Json::Value& request,
×
20
                                                                 WBMQTT::TMqttRpcServer::TResultCallback onResult,
21
                                                                 WBMQTT::TMqttRpcServer::TErrorCallback onError)
×
22
    : SerialPortSettings(ParseRPCSerialPortSettings(request)),
23
      ExpireTime(std::chrono::steady_clock::now() + DefaultRPCTotalTimeout),
×
24
      OnResult(onResult),
25
      OnError(onError)
×
26
{
27
    WBMQTT::JSON::Get(request, "slave_id", SlaveId);
×
NEW
28
    std::string protocol;
×
NEW
29
    WBMQTT::JSON::Get(request, "protocol", protocol);
×
NEW
30
    if (protocol == "modbus-tcp") {
×
NEW
31
        ModbusTraits = std::make_unique<Modbus::TModbusTCPTraits>();
×
32
    } else {
NEW
33
        ModbusTraits = std::make_unique<Modbus::TModbusRTUTraits>();
×
34
    }
35
}
36

37
ISerialClientTask::TRunResult TRPCDeviceProbeSerialClientTask::Run(PPort port,
×
38
                                                                   TSerialClientDeviceAccessHandler& lastAccessedDevice,
39
                                                                   const std::list<PSerialDevice>& polledDevices)
40
{
41
    if (std::chrono::steady_clock::now() > ExpireTime) {
×
42
        if (OnError) {
×
43
            OnError(WBMQTT::E_RPC_REQUEST_TIMEOUT, "RPC request timeout");
×
44
        }
45
        return ISerialClientTask::TRunResult::OK;
×
46
    }
47

48
    try {
49
        if (!port->IsOpen()) {
×
50
            port->Open();
×
51
        }
52
        lastAccessedDevice.PrepareToAccess(*port, nullptr);
×
53
        TSerialPortSettingsGuard settingsGuard(port, SerialPortSettings);
×
NEW
54
        RpcPortScan::TRegisterReader reader(*port, *ModbusTraits, SlaveId);
×
55
        OnResult(RpcPortScan::GetDeviceDetails(reader, SlaveId, polledDevices));
×
56
    } catch (const std::exception& error) {
×
57
        if (OnError) {
×
58
            OnError(WBMQTT::E_RPC_SERVER_ERROR, std::string("Port IO error: ") + error.what());
×
59
        }
60
    }
61

62
    return ISerialClientTask::TRunResult::OK;
×
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc