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

wirenboard / wb-mqtt-serial / 964

28 Sep 2026 06:54AM UTC coverage: 83.234% (+6.4%) from 76.817%
964

push

github

web-flow
Add disable_fast_modbus option to ports and Modbus devices (#1270)

11435 of 13496 branches covered (84.73%)

150 of 152 new or added lines in 11 files covered. (98.68%)

1282 existing lines in 91 files now uncovered.

19376 of 23279 relevant lines covered (83.23%)

1598.47 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)
556 ✔
9
{}
556 ✔
10

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

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

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

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

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

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

101
PRegister TRegisterHandler::Register() const
519 ✔
102
{
103
    return Reg;
519 ✔
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