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

wirenboard / wb-mqtt-serial / 690

26 Aug 2025 01:28PM UTC coverage: 73.031%. Remained the same
690

push

github

web-flow
Add protocol parameter to device/Probe RPC (#988)

  * Add protocol to Modbus TCP port information in ports/Load RPC
  * Add protocol parameter to device/Probe RPC
  * Set TCP_NODELAY for TCP ports
  * Handle TCP port closing by remote

6605 of 9406 branches covered (70.22%)

28 of 59 new or added lines in 11 files covered. (47.46%)

136 existing lines in 8 files now uncovered.

12554 of 17190 relevant lines covered (73.03%)

372.2 hits per line

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

82.69
/src/port.cpp
1
#include "port.h"
2
#include "log.h"
3

4
void TPort::Reopen()
×
5
{
6
    if (IsOpen()) {
×
7
        Close();
×
8
        Open();
×
9
    }
10
}
11

12
void TPort::WriteBytes(const std::vector<uint8_t>& buf)
116✔
13
{
14
    WriteBytes(&buf[0], buf.size());
116✔
15
}
116✔
16

17
void TPort::WriteBytes(const std::string& buf)
×
18
{
19
    WriteBytes(reinterpret_cast<const uint8_t*>(buf.c_str()), buf.size());
×
20
}
21

22
void TPort::ApplySerialPortSettings(const TSerialPortConnectionSettings& settings)
10✔
23
{}
10✔
24

25
void TPort::ResetSerialPortSettings()
3✔
26
{}
3✔
27

28
void TPort::SetMinimalResponseTimeout(const std::chrono::microseconds& value)
94✔
29
{
30
    MinimalResponseTimeout = value;
94✔
31
}
94✔
32

33
const std::chrono::microseconds& TPort::GetMinimalResponseTimeout() const
22✔
34
{
35
    return MinimalResponseTimeout;
22✔
36
}
37

38
std::chrono::microseconds TPort::CalcResponseTimeout(const std::chrono::microseconds& timeoutFromCall) const
10✔
39
{
40
    auto responseTimeout = std::max(GetMinimalResponseTimeout(), timeoutFromCall);
10✔
41
    if (responseTimeout.count() < 0) {
10✔
UNCOV
42
        return DEFAULT_RESPONSE_TIMEOUT;
×
43
    }
44
    return responseTimeout;
10✔
45
}
46

47
TPortOpenCloseLogic::TPortOpenCloseLogic(const TPortOpenCloseLogic::TSettings& settings, util::TGetNowFn nowFn)
99✔
48
    : Settings(settings),
49
      NowFn(nowFn)
99✔
50
{}
99✔
51

52
void TPortOpenCloseLogic::OpenIfAllowed(PPort port)
620✔
53
{
54
    if (port->IsOpen()) {
620✔
55
        return;
536✔
56
    }
57

58
    auto currentTime = NowFn();
85✔
59
    if (NextOpenTryTime > currentTime) {
85✔
60
        return;
1✔
61
    }
62

63
    try {
64
        port->Open();
84✔
65
    } catch (...) {
6✔
66
        NextOpenTryTime = currentTime + Settings.ReopenTimeout;
3✔
67
        throw;
3✔
68
    }
69
    LastSuccessfulCycle = NowFn();
81✔
70
    RemainingFailCycles = Settings.ConnectionMaxFailCycles;
81✔
71
}
72

73
void TPortOpenCloseLogic::CloseIfNeeded(PPort port, bool allPreviousDataExchangeWasFailed)
616✔
74
{
75
    if (!port->IsOpen()) {
616✔
UNCOV
76
        return;
×
77
    }
78

79
    // disable reconnect functionality option
80
    if (Settings.MaxFailTime.count() < 0 || Settings.ConnectionMaxFailCycles < 0) {
616✔
UNCOV
81
        return;
×
82
    }
83

84
    auto currentTime = NowFn();
616✔
85
    if (!allPreviousDataExchangeWasFailed) {
616✔
86
        LastSuccessfulCycle = currentTime;
590✔
87
        RemainingFailCycles = Settings.ConnectionMaxFailCycles;
590✔
88
    }
89

90
    if (RemainingFailCycles > 0) {
616✔
91
        --RemainingFailCycles;
608✔
92
    }
93

94
    if ((currentTime - LastSuccessfulCycle > Settings.MaxFailTime) && RemainingFailCycles == 0) {
616✔
95
        Warn.Log() << port->GetDescription() << ": closed due to repetitive errors";
2✔
96
        port->Close();
2✔
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc