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

traintastic / traintastic / 24288605255

11 Apr 2026 06:17PM UTC coverage: 25.599% (-2.4%) from 27.99%
24288605255

push

github

web-flow
Merge pull request #222 from traintastic/cbus

Added CBUS/VLCB hardware support

169 of 3369 new or added lines in 99 files covered. (5.02%)

5 existing lines in 4 files now uncovered.

8300 of 32423 relevant lines covered (25.6%)

178.31 hits per line

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

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

22
#include "cbussessionlisttablemodel.hpp"
23
#include "cbussessionlist.hpp"
24
#include "../../../compat/stdformat.hpp"
25
#include "../../../utils/utf8.hpp"
26

27
constexpr uint32_t columnSession = 0;
28
constexpr uint32_t columnAddress = 1;
29
constexpr uint32_t columnLong = 2;
30
constexpr uint32_t columnSpeed = 3;
31
constexpr uint32_t columnDirection = 4;
32
constexpr uint32_t columnF0 = 5;
33
constexpr uint32_t columnF1 = 6;
34
constexpr uint32_t columnF2 = 7;
35
constexpr uint32_t columnF3 = 8;
36
constexpr uint32_t columnF4 = 9;
37
constexpr uint32_t columnF5 = 10;
38
constexpr uint32_t columnF6 = 11;
39
constexpr uint32_t columnF7 = 12;
40
constexpr uint32_t columnF8 = 13;
41
constexpr uint32_t columnF9 = 14;
42
constexpr uint32_t columnF10 = 15;
43
constexpr uint32_t columnF11 = 16;
44
constexpr uint32_t columnF12 = 17;
45
constexpr uint32_t columnF13 = 18;
46
constexpr uint32_t columnF14 = 19;
47
constexpr uint32_t columnF15 = 20;
48
constexpr uint32_t columnF16 = 21;
49
constexpr uint32_t columnF17 = 22;
50
constexpr uint32_t columnF18 = 23;
51
constexpr uint32_t columnF19 = 24;
52
constexpr uint32_t columnF20 = 25;
53
constexpr uint32_t columnF21 = 26;
54
constexpr uint32_t columnF22 = 27;
55
constexpr uint32_t columnF23 = 28;
56
constexpr uint32_t columnF24 = 29;
57
constexpr uint32_t columnF25 = 30;
58
constexpr uint32_t columnF26 = 31;
59
constexpr uint32_t columnF27 = 32;
60
constexpr uint32_t columnF28 = 33;
61
constexpr uint32_t columnSteps = 34;
62

NEW
63
CBUSSessionListTableModel::CBUSSessionListTableModel(CBUSSessionList& list)
×
NEW
64
  : m_list{list.shared_ptr<CBUSSessionList>()}
×
65
{
NEW
66
  assert(m_list);
×
NEW
67
  m_list->m_models.push_back(this);
×
68

NEW
69
  setColumnHeaders({
×
70
    std::string_view{"cbus_session_list:session"},
71
    std::string_view{"hardware:address"},
72
    std::string_view{"cbus_session_list:long"},
73
    std::string_view{"cbus_session_list:speed"},
74
    std::string_view{"cbus_session_list:direction"},
75
    std::string_view{"function:f0"},
76
    std::string_view{"function:f1"},
77
    std::string_view{"function:f2"},
78
    std::string_view{"function:f3"},
79
    std::string_view{"function:f4"},
80
    std::string_view{"function:f5"},
81
    std::string_view{"function:f6"},
82
    std::string_view{"function:f7"},
83
    std::string_view{"function:f8"},
84
    std::string_view{"function:f9"},
85
    std::string_view{"function:f10"},
86
    std::string_view{"function:f11"},
87
    std::string_view{"function:f12"},
88
    std::string_view{"function:f13"},
89
    std::string_view{"function:f14"},
90
    std::string_view{"function:f15"},
91
    std::string_view{"function:f16"},
92
    std::string_view{"function:f17"},
93
    std::string_view{"function:f18"},
94
    std::string_view{"function:f19"},
95
    std::string_view{"function:f20"},
96
    std::string_view{"function:f21"},
97
    std::string_view{"function:f22"},
98
    std::string_view{"function:f23"},
99
    std::string_view{"function:f24"},
100
    std::string_view{"function:f25"},
101
    std::string_view{"function:f26"},
102
    std::string_view{"function:f27"},
103
    std::string_view{"function:f28"},
104
    std::string_view{"hardware:speed_steps"}
105
  });
106

NEW
107
  setRowCount(m_list->m_sessions.size());
×
NEW
108
}
×
109

NEW
110
CBUSSessionListTableModel::~CBUSSessionListTableModel()
×
111
{
NEW
112
  auto it = std::find(m_list->m_models.begin(), m_list->m_models.end(), this);
×
NEW
113
  assert(it != m_list->m_models.end());
×
NEW
114
  m_list->m_models.erase(it);
×
NEW
115
}
×
116

NEW
117
std::string CBUSSessionListTableModel::getText(uint32_t column, uint32_t row) const
×
118
{
NEW
119
  if(row < m_list->m_sessions.size())
×
120
  {
NEW
121
    const auto& session = m_list->m_sessions[row];
×
122

NEW
123
    switch(column)
×
124
    {
NEW
125
      case columnSession:
×
NEW
126
        if(session.session)
×
127
        {
NEW
128
          return std::to_string(*session.session);
×
129
        }
NEW
130
        break;
×
131

NEW
132
      case columnAddress:
×
NEW
133
        return std::to_string(session.address);
×
134

NEW
135
      case columnLong:
×
NEW
136
        return session.isLongAddress ? UTF8_CHECKMARK : "";
×
137

NEW
138
      case columnSpeed:
×
NEW
139
        if(session.speed)
×
140
        {
NEW
141
          if(*session.speed == 0)
×
142
          {
NEW
143
            return "$throttle.stop$";
×
144
          }
NEW
145
          if(*session.speed == 1)
×
146
          {
NEW
147
            return "$throttle.estop$";
×
148
          }
NEW
149
          return std::to_string(*session.speed - 1);
×
150
        }
NEW
151
        break;
×
152

NEW
153
      case columnDirection:
×
NEW
154
        if(session.direction != Direction::Unknown)
×
155
        {
NEW
156
          if(const auto* it = EnumValues<Direction>::value.find(session.direction); it != EnumValues<Direction>::value.end()) [[likely]]
×
157
          {
NEW
158
            return std::format("${}:{}$", EnumName<Direction>::value, it->second);
×
159
          }
160
        }
NEW
161
        break;
×
162

NEW
163
      case columnF0:
×
164
      case columnF1:
165
      case columnF2:
166
      case columnF3:
167
      case columnF4:
168
      case columnF5:
169
      case columnF6:
170
      case columnF7:
171
      case columnF8:
172
      case columnF9:
173
      case columnF10:
174
      case columnF11:
175
      case columnF12:
176
      case columnF13:
177
      case columnF14:
178
      case columnF15:
179
      case columnF16:
180
      case columnF17:
181
      case columnF18:
182
      case columnF19:
183
      case columnF20:
184
      case columnF21:
185
      case columnF22:
186
      case columnF23:
187
      case columnF24:
188
      case columnF25:
189
      case columnF26:
190
      case columnF27:
191
      case columnF28:
NEW
192
        switch(session.functions[column - columnF0])
×
193
        {
194
          using enum TriState;
195

NEW
196
          case False:
×
NEW
197
            return "$function:off$";
×
198

NEW
199
          case True:
×
NEW
200
            return "$function:on$";
×
201

NEW
202
          case Undefined:
×
NEW
203
            break;
×
204
        };
NEW
205
        break;
×
206

NEW
207
      case columnSteps:
×
NEW
208
        return std::to_string(session.steps);
×
209
    }
210
  }
NEW
211
  return {};
×
212
}
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