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

traintastic / traintastic / 23671871465

27 Mar 2026 11:30PM UTC coverage: 26.15% (-0.05%) from 26.198%
23671871465

push

github

reinder
[cbus] added SocketCAN io handler

0 of 47 new or added lines in 2 files covered. (0.0%)

16 existing lines in 2 files now uncovered.

8256 of 31572 relevant lines covered (26.15%)

182.21 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 CBUS {
28

NEW
29
SocketCANIOHandler::SocketCANIOHandler(Kernel& kernel, const std::string& interface, uint8_t canId)
×
30
  : IOHandler(kernel)
NEW
31
  , m_canId{canId}
×
NEW
32
  , m_socketCAN{kernel.ioContext(), interface, m_kernel.logId,
×
NEW
33
      [this](const CAN::SocketCANIOHandler::Frame& frame)
×
34
      {
NEW
35
        if((frame.can_id & CAN_EFF_FLAG) == 0 && frame.can_dlc >= 1) // only standard frames with minimal 1 data byte
×
36
        {
NEW
37
          m_kernel.receive(static_cast<uint8_t>(frame.can_id & 0x7F), *reinterpret_cast<const Message*>(frame.data));
×
38
        }
NEW
39
      },
×
NEW
40
      std::bind(&Kernel::error, &m_kernel)}
×
41
{
42
  // FIXME: set SocketCAN filter, then kernel can filter
NEW
43
}
×
44

NEW
45
void SocketCANIOHandler::start()
×
46
{
NEW
47
  m_socketCAN.start();
×
NEW
48
  m_kernel.started();
×
NEW
49
}
×
50

NEW
51
void SocketCANIOHandler::stop()
×
52
{
NEW
53
  m_socketCAN.stop();
×
NEW
54
}
×
55

NEW
56
std::error_code SocketCANIOHandler::send(const Message& message)
×
57
{
58
  CAN::SocketCANIOHandler::Frame frame;
NEW
59
  frame.can_id =
×
60
    (static_cast<canid_t>(MajorPriority::Lowest) << 9) |
NEW
61
    (static_cast<canid_t>(getMinorPriority(message.opCode)) << 7) |
×
NEW
62
    m_canId;
×
NEW
63
  frame.can_dlc = message.size();
×
NEW
64
  std::memcpy(frame.data, &message, message.size());
×
NEW
65
  if(!m_socketCAN.send(frame))
×
66
  {
NEW
67
    return std::make_error_code(std::errc::no_buffer_space);
×
68
  }
NEW
69
  return {};
×
70
}
71

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