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

wirenboard / wb-mqtt-serial / 2

20 Oct 2026 05:26AM UTC coverage: 86.772% (+13.9%) from 72.836%
2

Pull #1283

github

e3f11f
KraPete
Remove comment from service unit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pull Request #1283: Order service after mosquitto and restart it without limit

31090 of 80727 branches covered (38.51%)

22401 of 25816 relevant lines covered (86.77%)

2589.67 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)
678 ✔
9
{}
678 ✔
10

11
bool TRegisterHandler::NeedToFlush()
258 ✔
12
{
13
    std::lock_guard<std::mutex> lock(SetValueMutex);
258 !
14
    return Dirty;
258 ✔
15
}
258 ✔
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)
125 ✔
48
{
49
    TRegisterValue tempValue; // must be volatile
125 ✔
50
    try {
51
        {
52
            std::lock_guard<std::mutex> lock(SetValueMutex);
125 !
53
            tempValue = ValueToSet;
125 !
54
        }
125 ✔
55
        Reg->Device()->WriteRegister(port, Reg, tempValue);
151 ✔
56
        {
57
            std::lock_guard<std::mutex> lock(SetValueMutex);
112 !
58
            Dirty = (tempValue != ValueToSet);
112 !
59
            WriteFail = false;
112 ✔
60
        }
112 ✔
61
        Reg->SetValue(tempValue, false);
112 !
62
        Reg->ClearError(TRegister::TError::WriteError);
112 !
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
}
125 ✔
73

74
bool TRegisterHandler::NeedRetryAfterWriteFail()
3 ✔
75
{
76
    std::lock_guard<std::mutex> lock(SetValueMutex);
3 !
77
    if (!Dirty) {
3 !
78
        return false;
×
79
    }
80
    if (!WriteFail) {
3 !
81
        WriteFirstTryTime = steady_clock::now();
×
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)
120 ✔
95
{
96
    std::lock_guard<std::mutex> lock(SetValueMutex);
120 !
97
    Dirty = true;
120 ✔
98
    ValueToSet = ConvertToRawValue(*Reg->GetConfig(), v);
120 !
99
}
120 ✔
100

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