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

traintastic / traintastic / 23681802330

28 Mar 2026 08:58AM UTC coverage: 26.146% (-0.004%) from 26.15%
23681802330

push

github

reinder
[cbus] socketcan: use kernel filtering, only accept standard non rtr frames

0 of 3 new or added lines in 1 file covered. (0.0%)

120 existing lines in 3 files now uncovered.

8256 of 31576 relevant lines covered (26.15%)

182.19 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

41
SocketCANIOHandler::SocketCANIOHandler(Kernel& kernel, const std::string& interface, uint8_t canId)
×
42
  : IOHandler(kernel)
43
  , m_canId{canId}
×
44
  , m_socketCAN{kernel.ioContext(), interface, m_kernel.logId,
×
45
      [this](const CAN::SocketCANIOHandler::Frame& frame)
×
46
      {
NEW
47
        if(frame.can_dlc >= 1) // only with minimal 1 data byte
×
48
        {
49
          m_kernel.receive(static_cast<uint8_t>(frame.can_id & 0x7F), *reinterpret_cast<const Message*>(frame.data));
×
50
        }
51
      },
×
NEW
52
      std::bind(&Kernel::error, &m_kernel),
×
NEW
53
      filter}
×
54
{
UNCOV
55
}
×
56

57
void SocketCANIOHandler::start()
×
58
{
59
  m_socketCAN.start();
×
60
  m_kernel.started();
×
61
}
×
62

63
void SocketCANIOHandler::stop()
×
64
{
65
  m_socketCAN.stop();
×
66
}
×
67

68
std::error_code SocketCANIOHandler::send(const Message& message)
×
69
{
70
  CAN::SocketCANIOHandler::Frame frame;
71
  frame.can_id =
×
72
    (static_cast<canid_t>(MajorPriority::Lowest) << 9) |
73
    (static_cast<canid_t>(getMinorPriority(message.opCode)) << 7) |
×
74
    m_canId;
×
75
  frame.can_dlc = message.size();
×
76
  std::memcpy(frame.data, &message, message.size());
×
77
  if(!m_socketCAN.send(frame))
×
78
  {
79
    return std::make_error_code(std::errc::no_buffer_space);
×
80
  }
81
  return {};
×
82
}
83

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