• 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/cbuscanusbiohandler.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 "cbuscanusbiohandler.hpp"
23
#include <boost/asio/write.hpp>
24
#include "../cbuskernel.hpp"
25
#include "../../../../core/eventloop.hpp"
26
#include "../../../../log/log.hpp"
27
#include "../../../../utils/serialport.hpp"
28

29
namespace CBUS {
30

NEW
31
CANUSBIOHandler::CANUSBIOHandler(Kernel& kernel, const std::string& device)
×
32
  : ASCIIIOHandler(kernel)
NEW
33
  , m_serialPort{m_kernel.ioContext()}
×
34
{
35
  // FIXME: check serial settings, just a guess, if more settings are needed add them to the interface
NEW
36
  SerialPort::open(m_serialPort, device, 115'200, 8, SerialParity::None, SerialStopBits::One, SerialFlowControl::None);
×
NEW
37
}
×
38

NEW
39
CANUSBIOHandler::~CANUSBIOHandler()
×
40
{
NEW
41
  if(m_serialPort.is_open())
×
42
  {
NEW
43
    boost::system::error_code ec;
×
NEW
44
    m_serialPort.close(ec);
×
45
    // ignore the error
46
  }
NEW
47
}
×
48

NEW
49
void CANUSBIOHandler::start()
×
50
{
NEW
51
  read();
×
NEW
52
  m_kernel.started();
×
NEW
53
}
×
54

NEW
55
void CANUSBIOHandler::stop()
×
56
{
NEW
57
  m_serialPort.close();
×
NEW
58
}
×
59

NEW
60
void CANUSBIOHandler::read()
×
61
{
NEW
62
  m_serialPort.async_read_some(boost::asio::buffer(m_readBuffer.data() + m_readBufferOffset, m_readBuffer.size() - m_readBufferOffset),
×
NEW
63
    [this](const boost::system::error_code& ec, std::size_t bytesTransferred)
×
64
    {
NEW
65
      if(!ec)
×
66
      {
NEW
67
        processRead(bytesTransferred);
×
NEW
68
        read();
×
69
      }
NEW
70
      else if(ec != boost::asio::error::operation_aborted)
×
71
      {
NEW
72
        EventLoop::call(
×
NEW
73
          [this, ec]()
×
74
          {
NEW
75
            Log::log(m_kernel.logId, LogMessage::E2002_SERIAL_READ_FAILED_X, ec);
×
NEW
76
            m_kernel.error();
×
NEW
77
          });
×
78
      }
NEW
79
    });
×
NEW
80
}
×
81

NEW
82
void CANUSBIOHandler::write()
×
83
{
NEW
84
  assert(!m_writeQueue.empty());
×
NEW
85
  const auto& message = m_writeQueue.front();
×
NEW
86
  boost::asio::async_write(m_serialPort, boost::asio::buffer(message.data(), message.size()),
×
NEW
87
    [this](const boost::system::error_code& ec, std::size_t /*bytesTransferred*/)
×
88
    {
NEW
89
      if(!ec)
×
90
      {
NEW
91
        m_writeQueue.pop();
×
NEW
92
        if(!m_writeQueue.empty())
×
93
        {
NEW
94
          write();
×
95
        }
96
      }
NEW
97
      else if(ec != boost::asio::error::operation_aborted)
×
98
      {
NEW
99
        EventLoop::call(
×
NEW
100
          [this, ec]()
×
101
          {
NEW
102
            Log::log(m_kernel.logId, LogMessage::E2001_SERIAL_WRITE_FAILED_X, ec);
×
NEW
103
            m_kernel.error();
×
NEW
104
          });
×
105
      }
NEW
106
    });
×
NEW
107
}
×
108

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