• 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

90.0
/src/register_handler.cpp
1
#include "register_handler.h"
2
#include "log.h"
3

4
#define LOG(logger) ::logger.Log() << "[register handler] "
5

6
using namespace std::chrono;
7

8
TRegisterHandler::TRegisterHandler(PRegister reg): Reg(reg), WriteFail(false)
1,356 ✔
9
{}
1,356 ✔
10

11
bool TRegisterHandler::NeedToFlush()
516 ✔
12
{
13
    std::lock_guard<std::mutex> lock(SetValueMutex);
516 !
14
    return Dirty;
516 ✔
15
}
516 ✔
16

17
void TRegisterHandler::HandleWriteErrorNoRetry(const TRegisterValue& tempValue, const char* msg)
6 ✔
18
{
19
    LOG(Warn) << "failed to write: " << Reg->ToString() << ": " << msg;
6 !
20
    {
21
        std::lock_guard<std::mutex> lock(SetValueMutex);
6 !
22
        Dirty = (tempValue != ValueToSet);
6 !
23
        WriteFail = false;
6 ✔
24
    }
6 ✔
25
    Reg->SetError(TRegister::TError::WriteError);
6 ✔
26
}
6 ✔
27

28
void TRegisterHandler::HandleWriteErrorRetryWrite(const TRegisterValue& tempValue, const char* msg)
20 ✔
29
{
30
    LOG(Warn) << "failed to write: " << Reg->ToString() << ": " << msg;
20 !
31
    {
32
        std::lock_guard<std::mutex> lock(SetValueMutex);
20 !
33
        if (!WriteFail) {
20 ✔
34
            WriteFirstTryTime = steady_clock::now();
16 ✔
35
        }
36
        WriteFail = true;
20 ✔
37
        if (duration_cast<seconds>(steady_clock::now() - WriteFirstTryTime) >
40 !
38
            Reg->Device()->DeviceConfig()->MaxWriteFailTime)
40 !
39
        {
40
            Dirty = (tempValue != ValueToSet);
×
41
            WriteFail = false;
×
42
        }
43
    }
20 ✔
44
    Reg->SetError(TRegister::TError::WriteError);
20 ✔
45
}
20 ✔
46

47
void TRegisterHandler::Flush(TPort& port)
250 ✔
48
{
49
    TRegisterValue tempValue; // must be volatile
250 ✔
50
    try {
51
        {
52
            std::lock_guard<std::mutex> lock(SetValueMutex);
250 !
53
            tempValue = ValueToSet;
250 !
54
        }
250 ✔
55
        Reg->Device()->WriteRegister(port, Reg, tempValue);
302 ✔
56
        {
57
            std::lock_guard<std::mutex> lock(SetValueMutex);
224 !
58
            Dirty = (tempValue != ValueToSet);
224 !
59
            WriteFail = false;
224 ✔
60
        }
224 ✔
61
        Reg->SetValue(tempValue, false);
224 !
62
        Reg->ClearError(TRegister::TError::WriteError);
224 !
63
    } catch (const TSerialDeviceInternalErrorException& e) {
26 !
64
        HandleWriteErrorNoRetry(tempValue, e.what());
×
65
        return;
×
66
    } catch (const TSerialDevicePermanentRegisterException& e) {
6 !
67
        HandleWriteErrorNoRetry(tempValue, e.what());
6 !
68
        return;
6 ✔
69
    } catch (const TSerialDeviceException& e) {
26 !
70
        HandleWriteErrorRetryWrite(tempValue, e.what());
20 !
71
    }
20 !
72
}
250 ✔
73

74
bool TRegisterHandler::NeedRetryAfterWriteFail()
6 ✔
75
{
76
    std::lock_guard<std::mutex> lock(SetValueMutex);
6 !
77
    if (!Dirty) {
6 !
UNCOV
78
        return false;
×
79
    }
80
    if (!WriteFail) {
6 !
UNCOV
81
        WriteFirstTryTime = steady_clock::now();
×
UNCOV
82
        WriteFail = true;
×
83
    }
84
    if (duration_cast<seconds>(steady_clock::now() - WriteFirstTryTime) >
12 !
85
        Reg->Device()->DeviceConfig()->MaxWriteFailTime)
12 !
86
    {
87
        Dirty = false;
2 ✔
88
        WriteFail = false;
2 ✔
89
        return false;
2 ✔
90
    }
91
    return true;
4 ✔
92
}
6 ✔
93

94
void TRegisterHandler::SetTextValue(const std::string& v)
240 ✔
95
{
96
    std::lock_guard<std::mutex> lock(SetValueMutex);
240 !
97
    Dirty = true;
240 ✔
98
    ValueToSet = ConvertToRawValue(*Reg->GetConfig(), v);
240 !
99
}
240 ✔
100

101
PRegister TRegisterHandler::Register() const
1,048 ✔
102
{
103
    return Reg;
1,048 ✔
104
}
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