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

wirenboard / wb-mqtt-serial / 1

20 Oct 2026 04:57AM UTC coverage: 86.817% (+14.0%) from 72.836%
1

Pull #1281

github

fab311
KraPete
Fix device model fallback in device/LoadConfig RPC

The short model register was never read because the extended register
error was converted to TRPCException. The RPC error now says that
the device model could not be read.
Pull Request #1281: Fix device model fallback in device/LoadConfig RPC

31180 of 80922 branches covered (38.53%)

74 of 76 new or added lines in 2 files covered. (97.37%)

1379 existing lines in 84 files now uncovered.

22464 of 25875 relevant lines covered (86.82%)

5205.91 hits per line

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

87.5
/src/serial_driver.cpp
1
#include "serial_driver.h"
2
#include "log.h"
3

4
#include <wblib/driver.h>
5

6
#include <iostream>
7
#include <thread>
8

9
using namespace std;
10
using namespace WBMQTT;
11

12
#define LOG(logger) ::logger.Log() << "[serial] "
13

14
namespace
15
{
16
    size_t GetChannelsCount(PPortConfig portConfig)
764 ✔
17
    {
18
        size_t res = 0;
764 ✔
19
        for (const auto& device: portConfig->Devices) {
1,592 ✔
20
            res += device->Channels.size();
828 ✔
21
        }
22
        return res;
764 ✔
23
    }
24

25
    size_t GetChannelsCount(PHandlerConfig config)
374 ✔
26
    {
27
        size_t res = 0;
374 ✔
28
        for (const auto& portConfig: config->PortConfigs) {
756 ✔
29
            res += GetChannelsCount(portConfig);
382 ✔
30
        }
31
        return res;
374 ✔
32
    }
33
}
34

35
TMQTTSerialDriver::TMQTTSerialDriver(PDeviceDriver mqttDriver, PHandlerConfig config)
374 ✔
36
    : MqttDriver(mqttDriver),
374 ✔
37
      Active(false)
374 ✔
38
{
39
    try {
40
        size_t totalChannels = GetChannelsCount(config);
374 ✔
41
        for (const auto& portConfig: config->PortConfigs) {
710 ✔
42
            auto rateLimit = config->LowPriorityRegistersRateLimit;
382 ✔
43
            if (totalChannels != 0) {
382 !
44
                rateLimit *= GetChannelsCount(portConfig);
382 ✔
45
                rateLimit /= totalChannels;
382 ✔
46
            }
47
            if (rateLimit < 1) {
382 !
UNCOV
48
                rateLimit = 1;
×
49
            }
50
            PortDrivers.push_back(
382 !
51
                make_shared<TSerialPortDriver>(mqttDriver, portConfig, config->PublishParameters, rateLimit));
764 !
52
            PortDrivers.back()->SetUpDevices();
382 ✔
53
        }
54
    } catch (const exception& e) {
46 !
55
        LOG(Error) << "unable to create port driver: '" << e.what() << "'. Cleaning.";
46 !
56
        ClearDevices();
46 ✔
57
        throw;
46 ✔
58
    } catch (...) {
46 ✔
59
        LOG(Error) << "unable to create port driver. Cleaning.";
×
UNCOV
60
        ClearDevices();
×
UNCOV
61
        throw;
×
UNCOV
62
    }
×
63

64
    ControlOnValueHandler = mqttDriver->On<TControlOnValueEvent>(&TSerialPortDriver::HandleControlOnValueEvent);
328 !
65
}
512 ✔
66

67
TMQTTSerialDriver::~TMQTTSerialDriver()
328 ✔
68
{
69
    MqttDriver->RemoveEventHandler(ControlOnValueHandler);
328 ✔
70
}
328 ✔
71

72
void TMQTTSerialDriver::LoopOnce()
1,126 ✔
73
{
74
    for (const auto& portDriver: PortDrivers)
2,252 ✔
75
        portDriver->Cycle();
1,126 !
76
}
1,126 ✔
77

78
void TMQTTSerialDriver::ClearDevices()
356 ✔
79
{
80
    for (const auto& portDriver: PortDrivers) {
720 ✔
81
        portDriver->ClearDevices();
364 ✔
82
    }
83
}
356 ✔
84

85
void TMQTTSerialDriver::Start()
202 ✔
86
{
87
    {
88
        std::lock_guard<std::mutex> lg(ActiveMutex);
202 !
89
        if (Active) {
202 !
90
            LOG(Error) << "Attempt to start already active TMQTTSerialDriver";
×
91
            return;
×
92
        }
93
        Active = true;
202 ✔
94
    }
202 !
95

96
    for (const auto& portDriver: PortDrivers) {
412 ✔
97
        PortLoops.emplace_back([&] {
210 !
98
            WBMQTT::SetThreadName(portDriver->GetShortDescription());
210 ✔
99
            while (Active) {
8,489 ✔
100
                portDriver->Cycle();
8,279 ✔
101
            }
102
        });
210 ✔
103
    }
104
}
105

106
void TMQTTSerialDriver::Stop()
202 ✔
107
{
108
    {
109
        std::lock_guard<std::mutex> lg(ActiveMutex);
202 !
110
        if (!Active) {
202 !
111
            LOG(Error) << "Attempt to stop non active TMQTTSerialDriver";
×
112
            return;
×
113
        }
114
        Active = false;
202 ✔
115
    }
202 !
116

117
    for (auto& loopThread: PortLoops) {
412 ✔
118
        if (loopThread.joinable()) {
210 !
119
            loopThread.join();
210 !
120
        }
121
    }
122

123
    ClearDevices();
202 ✔
124
}
125

126
std::vector<PSerialPortDriver> TMQTTSerialDriver::GetPortDrivers()
312 ✔
127
{
128
    return PortDrivers;
312 ✔
129
}
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