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

wirenboard / wb-mqtt-serial / 666

08 Jul 2025 11:10AM UTC coverage: 73.854% (+0.1%) from 73.706%
666

push

github

web-flow
Port handling refactoring (#960)

Pass port by reference when needed instead of storing it in every device

6444 of 9057 branches covered (71.15%)

526 of 700 new or added lines in 56 files covered. (75.14%)

6 existing lines in 5 files now uncovered.

12341 of 16710 relevant lines covered (73.85%)

305.53 hits per line

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

14.29
/src/devices/iec_mode_c_device.cpp
1
#include "iec_mode_c_device.h"
2

3
#include "iec_common.h"
4
#include <memory>
5
#include <string.h>
6

7
namespace
8
{
9
    const char* LOG_PREFIX = "[IEC61107] ";
10

11
    enum RegisterType
12
    {
13
        DEFAULT = 0
14
    };
15

16
    const TRegisterTypes RegisterTypes{{RegisterType::DEFAULT, "default", "value", Double, true}};
17

18
    TRegisterValue GetValue(const TRegisterConfig& reg, const std::string& value)
×
19
    {
20
        // (019132.530*kWh)
21
        auto startPos = value.find('(');
×
22
        if (startPos == std::string::npos) {
×
23
            throw TSerialDeviceTransientErrorException("malformed response: " + value);
×
24
        }
25
        if (reg.Format == U8 || reg.Format == U16 || reg.Format == U24 || reg.Format == U32 || reg.Format == U64) {
×
26
            return TRegisterValue{strtoull(value.c_str() + startPos + 1, nullptr, 10)};
×
27
        }
28
        if (reg.Format == S8 || reg.Format == S16 || reg.Format == S24 || reg.Format == S32 || reg.Format == S64) {
×
29
            return TRegisterValue{static_cast<uint64_t>(strtoll(value.c_str() + startPos + 1, nullptr, 10))};
×
30
        }
31
        return TRegisterValue{CopyDoubleToUint64(strtod(value.c_str() + startPos + 1, nullptr))};
×
32
    }
33
}
34

35
void TIecModeCDevice::Register(TSerialDeviceFactory& factory)
143✔
36
{
37
    factory.RegisterProtocol(new TIEC61107Protocol("iec_mode_c", RegisterTypes),
429✔
38
                             new TBasicDeviceFactory<TIecModeCDevice, TStringRegisterAddressFactory>(
39
                                 "#/definitions/iec_mode_c_device",
40
                                 "#/definitions/channel_with_string_address"));
286✔
41
}
143✔
42

NEW
43
TIecModeCDevice::TIecModeCDevice(PDeviceConfig device_config, PProtocol protocol)
×
NEW
44
    : TIEC61107ModeCDevice(device_config, protocol, LOG_PREFIX, IEC::CalcXorCRC)
×
45
{
46
    SetDesiredBaudRate(9600);
×
47
    SetDefaultBaudRate(300);
×
48
    SetReadCommand(IEC::FormattedReadCommand);
×
49
}
50

51
std::string TIecModeCDevice::GetParameterRequest(const TRegisterConfig& reg) const
×
52
{
53
    return reg.GetAddress().ToString();
×
54
}
55

56
TRegisterValue TIecModeCDevice::GetRegisterValue(const TRegisterConfig& reg, const std::string& value)
×
57
{
58
    switch (reg.Type) {
×
59
        case RegisterType::DEFAULT:
×
60
            return GetValue(reg, value);
×
61
    }
62
    throw TSerialDevicePermanentRegisterException("unsupported register type: " + std::to_string(reg.Type));
×
63
}
64

NEW
65
void TIecModeCDevice::PrepareImpl(TPort& port)
×
66
{
67
    // Some energy meters require a period of silence before open session request
68
    // The timeout is not defined in standard and meter's documentation
69
    // Closest similar timeout is minimal time between session start request and meter's response
70
    // It is 200ms. So use it as timeout before session start
NEW
71
    port.SleepSinceLastInteraction(std::chrono::milliseconds(200));
×
NEW
72
    TIEC61107ModeCDevice::PrepareImpl(port);
×
73
}
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