• 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/protocol/cbus/iohandler/cbussocketcaniohandler.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 "cbussocketcaniohandler.hpp"
23
#include "../cbusgetminorpriority.hpp"
24
#include "../cbuskernel.hpp"
25
#include "../messages/cbusmessage.hpp"
26

27
namespace {
28

29
std::array<CAN::SocketCANIOHandler::Filter, 1> filter{{
30
  // only standard non RTR frames
31
  {
32
          .can_id = 0,
33
          .can_mask = (CAN_EFF_FLAG | CAN_RTR_FLAG),
34
  }
35
}};
36

37
}
38

39
namespace CBUS {
40

NEW
41
SocketCANIOHandler::SocketCANIOHandler(Kernel& kernel, const std::string& interface)
×
42
  : IOHandler(kernel)
NEW
43
  , m_socketCAN{kernel.ioContext(), interface, m_kernel.logId,
×
NEW
44
      [this](const CAN::SocketCANIOHandler::Frame& frame)
×
45
      {
NEW
46
        if(frame.can_dlc >= 1) // only with minimal 1 data byte
×
47
        {
48
          CAN::Message canMessage;
NEW
49
          canMessage.id = frame.can_id & CAN_EFF_MASK;
×
NEW
50
          canMessage.rtr = (frame.can_id & CAN_RTR_FLAG) != 0;
×
NEW
51
          canMessage.extended = (frame.can_id & CAN_EFF_FLAG) != 0;
×
NEW
52
          std::memcpy(canMessage.data, frame.data, frame.can_dlc);
×
NEW
53
          assert(onReceive);
×
NEW
54
          onReceive(canMessage);
×
55
        }
NEW
56
      },
×
NEW
57
      std::bind(&Kernel::error, &m_kernel),
×
NEW
58
      filter}
×
59
{
NEW
60
}
×
61

NEW
62
void SocketCANIOHandler::start()
×
63
{
NEW
64
  m_socketCAN.start();
×
NEW
65
  m_kernel.started();
×
NEW
66
}
×
67

NEW
68
void SocketCANIOHandler::stop()
×
69
{
NEW
70
  m_socketCAN.stop();
×
NEW
71
}
×
72

NEW
73
std::error_code SocketCANIOHandler::send(const CAN::Message& canMessage)
×
74
{
75
  CAN::SocketCANIOHandler::Frame frame;
NEW
76
  frame.can_id = canMessage.id;
×
NEW
77
  if(canMessage.rtr)
×
78
  {
NEW
79
    frame.can_id |= CAN_RTR_FLAG;
×
80
  }
NEW
81
  if(canMessage.extended)
×
82
  {
NEW
83
    frame.can_id |= CAN_RTR_FLAG;
×
84
  }
NEW
85
  frame.can_dlc = canMessage.dlc;
×
NEW
86
  std::memcpy(frame.data, &canMessage.data, canMessage.dlc);
×
NEW
87
  if(!m_socketCAN.send(frame))
×
88
  {
NEW
89
    return std::make_error_code(std::errc::no_buffer_space);
×
90
  }
NEW
91
  return {};
×
92
}
93

94
}
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