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

traintastic / traintastic / 26121453997

19 May 2026 07:52PM UTC coverage: 25.063% (-0.6%) from 25.624%
26121453997

Pull #221

github

web-flow
Merge 598936246 into 15e38bcf7
Pull Request #221: Xpressnet new messages

49 of 1129 new or added lines in 16 files covered. (4.34%)

782 existing lines in 21 files now uncovered.

8483 of 33847 relevant lines covered (25.06%)

172.88 hits per line

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

78.33
/server/src/hardware/decoder/decoderfunction.cpp
1
/**
2
 * server/src/hardware/decoder/decoderfunction.cpp
3
 *
4
 * Copyright (C) 2019-2021 Reinder Feenstra <reinderfeenstra@gmail.com>
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
 */
20

21
#include "decoderfunction.hpp"
22
#include "decoder.hpp"
23
#include "decoderchangeflags.hpp"
24
#include "../../world/world.hpp"
25
#include "../../core/attributes.hpp"
26
#include "../../core/objectproperty.tpp"
27
#include "../../utils/displayname.hpp"
28
#include "../../log/logmessageexception.hpp"
29

30
const std::shared_ptr<DecoderFunction> DecoderFunction::null;
31

32
DecoderFunction::DecoderFunction(Decoder& decoder, uint8_t _number) :
48✔
33
  m_decoder{decoder},
48✔
34
  number{this, "number", _number, PropertyFlags::ReadWrite | PropertyFlags::Store, nullptr,
96✔
35
    [this](const uint8_t& fn)
48✔
36
    {
37
      if(m_decoder.hasFunction(fn))
×
38
        throw LogMessageException(LogMessage::E2012_FUNCTION_NUMBER_ALREADY_IN_USE);
×
NEW
39
      m_decoder.functionsChanged();
×
UNCOV
40
      return true;
×
41
    }},
42
  name{this, "name", "", PropertyFlags::ReadWrite | PropertyFlags::Store},
96✔
43
  type{this, "type", DecoderFunctionType::OnOff, PropertyFlags::ReadWrite | PropertyFlags::Store,
96✔
44
    [this](DecoderFunctionType /*type*/)
48✔
45
    {
46
      typeChanged();
×
47
    }},
×
48
  function{this, "function", DecoderFunctionFunction::Generic, PropertyFlags::ReadWrite | PropertyFlags::Store},
48✔
49
  value{this, "value", false, PropertyFlags::ReadWrite | PropertyFlags::StoreState,
96✔
50
    [this](bool /*newValue*/)
48✔
51
    {
52
      m_decoder.changed(DecoderChangeFlags::FunctionValue, number);
×
53
    }}
48✔
54
{
55
  const bool editable = contains(decoder.world().state.value(), WorldState::Edit);
48✔
56

57
  Attributes::addEnabled(number, editable);
48✔
58
  m_interfaceItems.add(number);
48✔
59
  Attributes::addDisplayName(name, DisplayName::Object::name);
48✔
60
  Attributes::addEnabled(name, editable);
48✔
61
  m_interfaceItems.add(name);
48✔
62
  Attributes::addEnabled(type, editable);
48✔
63
  Attributes::addValues(type, decoderFunctionTypeValues);
48✔
64
  m_interfaceItems.add(type);
48✔
65
  Attributes::addEnabled(function, editable);
48✔
66
  Attributes::addValues(function, decoderFunctionFunctionValues);
48✔
67
  m_interfaceItems.add(function);
48✔
68
  Attributes::addEnabled(value, true);
48✔
69
  Attributes::addObjectEditor(value, false);
48✔
70
  m_interfaceItems.add(value);
48✔
71
}
48✔
72

73
std::string DecoderFunction::getObjectId() const
2✔
74
{
75
  return m_decoder.functions->getObjectId().append(".").append(m_decoder.functions->items.name()).append(".f").append(std::to_string(number.value()));
2✔
76
}
77

78
void DecoderFunction::loaded()
1✔
79
{
80
  Object::loaded();
1✔
81
  typeChanged();
1✔
82
}
1✔
83

84
void DecoderFunction::worldEvent(WorldState state, WorldEvent event)
7✔
85
{
86
  Object::worldEvent(state, event);
7✔
87

88
  const bool editable = contains(state, WorldState::Edit);
7✔
89

90
  Attributes::setEnabled(number, editable);
7✔
91
  Attributes::setEnabled(name, editable);
7✔
92
  Attributes::setEnabled(type, editable);
7✔
93
  Attributes::setEnabled(function, editable);
7✔
94
}
7✔
95

96
void DecoderFunction::typeChanged()
1✔
97
{
98
  switch(type)
1✔
99
  {
100
    case DecoderFunctionType::AlwaysOff:
×
101
      value = false;
×
102
      break;
×
103

104
    case DecoderFunctionType::AlwaysOn:
×
105
      value = true;
×
106
      break;
×
107

108
    case DecoderFunctionType::OnOff:
1✔
109
    case DecoderFunctionType::Hold:
110
    case DecoderFunctionType::Momentary:
111
      break;
1✔
112
  }
113
  Attributes::setEnabled(value, !isAlwaysOffOrOn(type));
1✔
114
}
1✔
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