Debian Codegraph @

Hardware/CcSchnitte.cpp

raw symbols SCIP
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #include "Hardware/CcSchnitte.h"
22 #include "Utils/Utils.h"
23
24 // OS X does not define B500000
25 #ifdef __APPLE__
26 #ifndef B500000
27 #define B500000 500000
28 #endif
29 #endif
30
31 namespace Hardware
32 {
33 CcSchnitte::CcSchnitte(const HardwareParams* params)
34 : MaerklinCAN(params,
35 "CC-Schnitte / " + params->GetName() + " at serial port " + params->GetArg1(),
36 params->GetName()),
37 serialLine(HardwareInterface::logger, params->GetArg1(), B500000, 8, 'N', 1, true)
38 {
39 HardwareInterface::logger->Info(Languages::TextStarting, GetFullName());
40
41 Init();
42 }
43
44 void CcSchnitte::Send(const unsigned char* buffer)
45 {
46 if (!serialLine.IsConnected())
47 {
48 return;
49 }
50 if (serialLine.Send(buffer, CANCommandBufferLength) == -1)
51 {
52 HardwareInterface::logger->Error(Languages::TextUnableToSendDataToControl);
53 }
54 }
55
56 void CcSchnitte::Receiver()
57 {
58 while (run)
59 {
60 if (!serialLine.IsConnected())
61 {
62 HardwareInterface::logger->Error(Languages::TextUnableToReceiveData);
63 return;
64 }
65 unsigned char buffer[CANCommandBufferLength];
66 ssize_t datalen = serialLine.ReceiveExact(buffer, sizeof(buffer));
67 if (!run)
68 {
69 break;
70 }
71 if (datalen == 0)
72 {
73 // no data received
74 continue;
75 }
76 if (datalen != sizeof(buffer))
77 {
78 HardwareInterface::logger->Error(Languages::TextInvalidDataReceived);
79 continue;
80 }
81 Parse(buffer);
82 }
83 }
84 } // namespace