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

wirenboard / wb-mqtt-serial / 967

05 Oct 2026 09:41AM UTC coverage: 85.672% (+2.4%) from 83.268%
967

push

github

web-flow
Add config/Save RPC (#1273)

The RPC validates a configuration, writes it to the configuration file and
restarts the polling in-process. Port clients are stopped first, requests
arriving meanwhile get config-busy and queued ones get request-cancelled.

12445 of 14263 branches covered (87.25%)

1432 of 1623 new or added lines in 41 files covered. (88.23%)

8 existing lines in 4 files now uncovered.

21065 of 24588 relevant lines covered (85.67%)

1528.89 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 "port/serial_port.h"
3
#include "rpc_helpers.h"
4
#include "rpc_port_handler.h"
5
#include "rpc_port_scan_serial_client_task.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);
×
28
    std::string protocol;
×
29
    WBMQTT::JSON::Get(request, "protocol", protocol);
×
30
    ModbusTraits = MakeModbusTraits(protocol);
×
31
}
×
32

33
ISerialClientTask::TRunResult TRPCDeviceProbeSerialClientTask::Run(PFeaturePort port,
×
34
                                                                   TSerialClientDeviceAccessHandler& lastAccessedDevice,
35
                                                                   const std::list<PSerialDevice>& polledDevices)
36
{
NEW
37
    if (IsCancelled()) {
×
NEW
38
        AnswerRequestCancelled(OnError);
×
NEW
39
        return ISerialClientTask::TRunResult::OK;
×
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);
×
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 TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc