• 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/cbusasciiiohandler.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 "cbusasciiiohandler.hpp"
23
#include "../cbuscanmessageascii.hpp"
24
#include "../cbuskernel.hpp"
25
#include "../messages/cbusmessage.hpp"
26
#include "../../../../core/eventloop.hpp"
27
#include "../../../../log/log.hpp"
28

29
namespace CBUS {
30

NEW
31
ASCIIIOHandler::ASCIIIOHandler(Kernel& kernel)
×
NEW
32
  : IOHandler(kernel)
×
33
{
NEW
34
}
×
35

NEW
36
std::error_code ASCIIIOHandler::send(const CAN::Message& canMessage)
×
37
{
NEW
38
  const bool wasEmpty = m_writeQueue.empty();
×
39

NEW
40
  std::string frame;
×
NEW
41
  frame.resize(32);
×
NEW
42
  frame.resize(toAscii(canMessage, frame));
×
NEW
43
  if(frame.empty()) [[unlikely]]
×
44
  {
NEW
45
    return std::make_error_code(std::errc::bad_message);
×
46
  }
47

NEW
48
  m_writeQueue.emplace(std::move(frame));
×
49

NEW
50
  if(wasEmpty)
×
51
  {
NEW
52
    write();
×
53
  }
54

NEW
55
  return {};
×
NEW
56
}
×
57

NEW
58
void ASCIIIOHandler::processRead(std::size_t bytesTransferred)
×
59
{
NEW
60
  std::string_view buffer{m_readBuffer.data(), m_readBufferOffset + bytesTransferred};
×
61

NEW
62
  while(!buffer.empty())
×
63
  {
64
    CAN::Message canMessage;
NEW
65
    size_t drop = 0;
×
66

NEW
67
    const auto consumed = fromAscii(buffer, canMessage, drop);
×
NEW
68
    if(drop != 0)
×
69
    {
NEW
70
      EventLoop::call(
×
NEW
71
        [this, drop]()
×
72
        {
NEW
73
          Log::log(m_kernel.logId, LogMessage::W2001_RECEIVED_MALFORMED_DATA_DROPPED_X_BYTES, drop);
×
NEW
74
        });
×
75
    }
NEW
76
    if(consumed == 0)
×
77
    {
NEW
78
      break; // wait for more data
×
79
    }
NEW
80
    if(drop < consumed)
×
81
    {
NEW
82
      assert(onReceive);
×
NEW
83
      onReceive(canMessage);
×
84
    }
NEW
85
    buffer.remove_prefix(consumed);
×
86
  }
87

NEW
88
  if(buffer.size() != 0)
×
89
  {
NEW
90
    memmove(m_readBuffer.data(), buffer.data(), buffer.size());
×
91
  }
NEW
92
  m_readBufferOffset = buffer.size();
×
NEW
93
}
×
94

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