Debian Codegraph @

Hardware/HardwareInterface.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 <map>
24 #include <string>
25 #include <vector>
26
27 #include "DataModel/AccessoryBase.h"
28 #include "DataModel/Loco.h"
29 #include "DataTypes.h"
30 #include "Hardware/AccessoryCache.h"
31 #include "Hardware/Capabilities.h"
32 #include "Hardware/LocoCache.h"
33 #include "Manager.h"
34 #include "Utils/Utils.h"
35
36 namespace Hardware
37 {
38 class HardwareInterface
39 {
40 public:
41 HardwareInterface() = delete;
42 HardwareInterface(const HardwareInterface&) = delete;
43 HardwareInterface& operator=(const HardwareInterface&) = delete;
44
45 // non virtual constructor is needed to prevent polymorphism
46 inline HardwareInterface(Manager* manager,
47 const ControlID controlID,
48 const std::string& fullName,
49 const std::string& shortName)
50 : manager(manager),
51 controlID(controlID),
52 logger(Logger::Logger::GetLogger(shortName)),
53 fullName(fullName),
54 shortName(shortName)
55 {
56 }
57
58 virtual ~HardwareInterface()
59 {
60 }
61
62 virtual void Start()
63 {
64 }
65
66 // get the full name of the hardware
67 inline const std::string& GetFullName() const
68 {
69 return fullName;
70 }
71
72 // get the short name of the hardware
73 inline const std::string& GetShortName() const
74 {
75 return shortName;
76 }
77
78 // get hardware capabilities
79 virtual Hardware::Capabilities GetCapabilities() const
80 {
81 return Hardware::CapabilityNone;
82 }
83
84 // get available loco protocols of this control
85 virtual void GetLocoProtocols(__attribute__((unused)) std::vector<Protocol>& protocols) const
86 {
87 }
88
89 // is given loco protocol supported
90 virtual bool LocoProtocolSupported(__attribute__((unused)) const Protocol protocol) const
91 {
92 return false;
93 }
94
95 // get available accessory protocols of this control
96 virtual void GetAccessoryProtocols(__attribute__((unused)) std::vector<Protocol>& protocols) const
97 {
98 }
99
100 // is given accessory protocol supported
101 virtual bool AccessoryProtocolSupported(__attribute__((unused)) const Protocol protocol) const
102 {
103 return false;
104 }
105
106 // turn booster on or off
107 virtual void Booster(__attribute__((unused)) const BoosterState status)
108 {
109 }
110
111 // set loco speed
112 virtual void LocoSpeed(__attribute__((unused)) const Protocol protocol,
113 __attribute__((unused)) const Address address,
114 __attribute__((unused)) const Speed speed)
115 {
116 }
117
118 // set loco orientation
119 virtual void LocoOrientation(__attribute__((unused)) const Protocol protocol,
120 __attribute__((unused)) const Address address,
121 __attribute__((unused)) const Orientation orientation)
122 {
123 }
124
125 // set loco function
126 virtual void LocoFunction(__attribute__((unused)) const Protocol protocol,
127 __attribute__((unused)) const Address address,
128 __attribute__((unused)) const DataModel::LocoFunctionNr function,
129 __attribute__((unused)) const DataModel::LocoFunctionState on)
130 {
131 }
132
133 // set loco
134 virtual void LocoSpeedOrientationFunctions(const Protocol protocol,
135 const Address address,
136 const Speed speed,
137 const Orientation orientation,
138 std::vector<DataModel::LocoFunctionEntry>& functions)
139 {
140 // sleeps are necessary to prevent command overflow in command stations (especially Märklin Gleisbox)
141 LocoSpeed(protocol, address, speed);
142 Utils::Utils::SleepForMilliseconds(25);
143 LocoOrientation(protocol, address, orientation);
144 Utils::Utils::SleepForMilliseconds(25);
145 for (const DataModel::LocoFunctionEntry& functionEntry : functions)
146 {
147 LocoFunction(protocol, address, functionEntry.nr, functionEntry.state);
148 Utils::Utils::SleepForMilliseconds(25);
149 }
150 }
151
152 // accessory command
153 virtual void Accessory(__attribute__((unused)) const Protocol protocol,
154 __attribute__((unused)) const Address address,
155 __attribute__((unused)) const DataModel::AccessoryState state,
156 __attribute__((unused)) const bool on,
157 __attribute__((unused)) const DataModel::AccessoryPulseDuration duration)
158 {
159 }
160
161 // read CV value
162 virtual void ProgramRead(__attribute__((unused)) const ProgramMode mode,
163 __attribute__((unused)) const Address address,
164 __attribute__((unused)) const CvNumber cv)
165 {
166 }
167
168 // write CV value
169 virtual void ProgramWrite(__attribute__((unused)) const ProgramMode mode,
170 __attribute__((unused)) const Address address,
171 __attribute__((unused)) const CvNumber cv,
172 __attribute__((unused)) const CvValue value)
173 {
174 }
175
176 virtual const std::map<std::string,Hardware::LocoCacheEntry>& GetLocoDatabase() const
177 {
178 return emptyLocoDatabase;
179 }
180
181 virtual DataModel::LocoConfig GetLocoByMatchKey(__attribute__((unused)) const std::string& matchKey) const
182 {
183 return DataModel::LocoConfig(LocoTypeLoco);
184 }
185
186 virtual DataModel::LocoConfig GetMultipleUnitByMatchKey(__attribute__((unused)) const std::string& matchKey) const
187 {
188 return DataModel::LocoConfig(LocoTypeMultipleUnit);
189 }
190
191 virtual void SetLocoIdOfMatchKey(__attribute__((unused)) const LocoID locoId,
192 __attribute__((unused)) const std::string& matchKey)
193 {
194 }
195
196 virtual void SetMultipleUnitIdOfMatchKey(__attribute__((unused)) const LocoID locoId,
197 __attribute__((unused)) const std::string& matchKey)
198 {
199 }
200
201 virtual const std::map<std::string,Hardware::AccessoryCacheEntry>& GetAccessoryDatabase() const
202 {
203 return emptyAccessoryDatabase;
204 }
205
206 virtual DataModel::AccessoryConfig GetAccessoryByMatchKey(__attribute__((unused)) const std::string& matchKey) const
207 {
208 return DataModel::AccessoryConfig();
209 }
210
211 virtual void SetAccessoryIdentifierOfMatchKey(__attribute__((unused)) const DataModel::ObjectIdentifier objectIdentifier,
212 __attribute__((unused)) const std::string& matchKey)
213 {
214 }
215
216 virtual const std::map<std::string,Hardware::FeedbackCacheEntry>& GetFeedbackDatabase() const
217 {
218 return emptyFeedbackDatabase;
219 }
220
221 virtual DataModel::FeedbackConfig GetFeedbackByMatchKey(__attribute__((unused)) const std::string& matchKey) const
222 {
223 return DataModel::FeedbackConfig();
224 }
225
226 virtual void SetFeedbackIdOfMatchKey(__attribute__((unused)) const FeedbackID feedbackId,
227 __attribute__((unused)) const std::string& matchKey)
228 {
229 }
230
231 virtual void FeedbackDelete(__attribute__((unused)) const FeedbackID feedbackID,
232 __attribute__((unused)) const std::string& name)
233 {
234 }
235
236 virtual void FeedbackSettings(__attribute__((unused)) const FeedbackID feedbackID,
237 __attribute__((unused)) const std::string& name)
238 {
239 }
240
241 protected:
242 Manager* const manager;
243 const ControlID controlID;
244 Logger::Logger* const logger;
245
246 private:
247 const std::string fullName;
248 const std::string shortName;
249 std::map<std::string,Hardware::LocoCacheEntry> emptyLocoDatabase;
250 std::map<std::string,Hardware::AccessoryCacheEntry> emptyAccessoryDatabase;
251 std::map<std::string,Hardware::FeedbackCacheEntry> emptyFeedbackDatabase;
252 };
253 } // namespace
254