Debian Codegraph @

Hardware/Protocols/DccPpEx.h

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 #pragma once
22
23 #include "Hardware/Capabilities.h"
24 #include "Hardware/HardwareInterface.h"
25 #include "Hardware/HardwareParams.h"
26 #include "Hardware/Protocols/DccPpExLocoCache.h"
27 #include "Logger/Logger.h"
28
29 namespace Hardware
30 {
31 namespace Protocols
32 {
33 class DccPpEx: protected HardwareInterface
34 {
35 public:
36 DccPpEx() = delete;
37 DccPpEx(const DccPpEx&) = delete;
38 DccPpEx& operator=(const DccPpEx&) = delete;
39
40 inline Hardware::Capabilities GetCapabilities() const override
41 {
42 return CapabilityLoco
43 | CapabilityAccessory
44 | CapabilityFeedback
45 | CapabilityProgram
46 | CapabilityProgramDccDirectWrite
47 | CapabilityProgramDccDirectRead
48 | CapabilityProgramDccPomLocoWrite;
49 }
50
51 void GetLocoProtocols(std::vector<Protocol>& protocols) const override
52 {
53 protocols.push_back(ProtocolDCC128);
54 }
55
56 inline bool LocoProtocolSupported(Protocol protocol) const override
57 {
58 return (protocol == ProtocolDCC128);
59 }
60
61 inline void GetAccessoryProtocols(std::vector<Protocol>& protocols) const override
62 {
63 protocols.push_back(ProtocolDCC);
64 }
65
66 inline bool AccessoryProtocolSupported(Protocol protocol) const override
67 {
68 return (protocol == ProtocolDCC);
69 }
70
71 void Booster(const BoosterState status) override;
72
73 void LocoSpeed(const Protocol protocol,
74 const Address address,
75 const Speed speed) override;
76
77 void LocoOrientation(const Protocol protocol,
78 const Address address,
79 const Orientation orientation)
80 override;
81
82 void LocoFunction(const Protocol protocol,
83 const Address address,
84 const DataModel::LocoFunctionNr function,
85 const DataModel::LocoFunctionState on) override;
86
87 void Accessory(const Protocol protocol,
88 const Address address,
89 const DataModel::AccessoryState state,
90 const bool on,
91 const DataModel::AccessoryPulseDuration duration) override;
92
93 void ProgramWrite(const ProgramMode mode,
94 const Address address,
95 const CvNumber cv,
96 const CvValue value) override;
97
98 void ProgramRead(const ProgramMode mode,
99 const Address address,
100 const CvNumber cv) override;
101
102 protected:
103 inline DccPpEx(const HardwareParams* params,
104 const std::string& fullName,
105 const std::string& shortName)
106 : HardwareInterface(params->GetManager(),
107 params->GetControlID(),
108 fullName,
109 shortName),
110 run(true)
111 {
112 }
113
114 inline void Init()
115 {
116 receiverThread = std::thread(&DccPpEx::Receiver, this);
117 }
118
119 virtual ~DccPpEx()
120 {
121 run = false;
122 receiverThread.join();
123 }
124
125 private:
126 void LocoSpeedOrientation(const Address address,
127 const Speed speed,
128 const Orientation orientation);
129
130 void ProgramWriteMain(const Address address,
131 const CvNumber cv,
132 const CvValue value);
133
134 void ProgramWriteProgram(const CvNumber cv,
135 const CvValue value);
136
137 void ProgramReadProgram(const CvNumber cv);
138
139 inline bool SendInternal(const std::string& buffer)
140 {
141 logger->HexOut(buffer);
142 return Send(buffer);
143 }
144
145 bool ReceiveInternal(std::string& buffer);
146
147 virtual bool Send(const std::string& buffer) = 0;
148
149 virtual bool Receive(std::string& buffer) = 0;
150
151 void Receiver();
152
153 void Parse(const std::string& buffer);
154
155 int ParseInt(const std::string& buffer, unsigned int& pos);
156
157 void ParseSpace(const std::string& buffer, unsigned int& pos);
158
159 bool ParsePipe(const std::string& buffer, unsigned int& pos);
160
161 DccPpExLocoCache locoCache;
162
163 volatile bool run;
164 std::thread receiverThread;
165 };
166 } // namespace
167 } // namespace