Debian Codegraph @

DataModel/AccessoryBase.h

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
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 <cstdint>
24 #include <ctime>
25 #include <map>
26 #include <string>
27
28 #include "DataModel/HardwareHandle.h"
29 #include "Hardware/AccessoryCache.h"
30
31 namespace DataModel
32 {
33 enum AccessoryType : uint8_t
34 {
35 // 2 MSB are functional type (on-on, on push, on-off)
36 AccessoryTypeOnOn = 0x00,
37 AccessoryTypeOnPush = 0x40,
38 AccessoryTypeOnOff = 0x80,
39 AccessoryTypeConnectionMask = 0xC0,
40
41 // 6 LSB are display type (default, straight, turn, ...)
42 AccessoryTypeDefault = 0x00,
43 AccessoryTypeStraight = 0x01,
44 AccessoryTypeTurn = 0x02,
45 AccessoryTypeDecoupler = 0x03,
46 AccessoryTypeLight = 0x04,
47 AccessoryTypeLightInhouse = 0x05,
48 AccessoryTypeLightStreet = 0x06,
49 AccessoryTypeMask = 0x3F,
50
51 SignalTypeSimpleLeft = 0,
52 SignalTypeSimpleRight = 1,
53 SignalTypeChDwarf = 10,
54 SignalTypeChLMain = 11,
55 SignalTypeChLDistant = 12,
56 SignalTypeChLCombined = 13,
57 SignalTypeChNMain = 14,
58 SignalTypeChNDistant = 15,
59 SignalTypeDeCombined = 20,
60 SignalTypeDeHVMain = 21,
61 SignalTypeDeHVDistant = 22,
62 SignalTypeDeBlock = 23,
63
64 SwitchTypeLeft = 0,
65 SwitchTypeRight = 1,
66 SwitchTypeThreeWay = 2,
67 SwitchTypeMaerklinLeft = 3,
68 SwitchTypeMaerklinRight = 4
69 };
70
71 enum AccessoryState : uint8_t
72 {
73 DefaultState = 0,
74
75 AccessoryStateOff = 0,
76 AccessoryStateOn = 1,
77
78 SignalStateStop = 0,
79 SignalStateClear,
80 SignalStateAspect2,
81 SignalStateAspect3,
82 SignalStateAspect4,
83 SignalStateAspect5,
84 SignalStateAspect6,
85 SignalStateAspect7,
86 SignalStateAspect8,
87 SignalStateAspect9,
88 SignalStateAspect10,
89 SignalStateDark = 0x1F,
90 SignalStateStopExpected = SignalStateStop + 0x20,
91 SignalStateClearExpected,
92 SignalStateAspect2Expected,
93 SignalStateAspect3Expected,
94 SignalStateAspect4Expected,
95 SignalStateAspect5Expected,
96 SignalStateAspect6Expected,
97 SignalStateAspect7Expected,
98 SignalStateAspect8Expected,
99 SignalStateAspect9Expected,
100 SignalStateAspect10Expected,
101 SignalStateMax = SignalStateAspect10Expected,
102
103 SwitchStateTurnout = 0,
104 SwitchStateStraight = 1,
105 SwitchStateThird = 2,
106
107 InvalidState = 0xFF
108 };
109
110 typedef signed char AddressOffset;
111
112 typedef unsigned short AccessoryPulseDuration;
113 static const AccessoryPulseDuration DefaultAccessoryPulseDuration = 100;
114
115 class AccessoryBase : public HardwareHandle
116 {
117 public:
•118 inline AccessoryBase()
119 : HardwareHandle(),
120 accessoryType(AccessoryTypeDefault),
121 accessoryState(AccessoryStateOff),
122 duration(0),
123 inverted(false),
124 lastUsed(0),
125 counter(0),
126 matchKey("")
127 {
128 }
129
130 virtual ~AccessoryBase() {}
131
132 inline AccessoryType GetAccessoryType() const
133 {
134 return accessoryType;
135 }
136
137 virtual inline void SetAccessoryType(AccessoryType accessoryType)
138 {
139 this->accessoryType = accessoryType;
140 }
141
142 inline AccessoryState GetAccessoryState() const
143 {
144 return accessoryState;
145 }
146
147 AccessoryState CalculateInvertedAccessoryState(const AccessoryState state) const;
148
149 inline AccessoryState GetInvertedAccessoryState() const
150 {
151 return CalculateInvertedAccessoryState(accessoryState);
152 }
153
154 inline void SetAccessoryState(const AccessoryState state)
155 {
156 this->accessoryState = state;
157 lastUsed = std::time(nullptr);
158 ++counter;
159 }
160
161 inline AccessoryPulseDuration GetAccessoryPulseDuration() const
162 {
163 return duration;
164 }
165
166 inline void SetAccessoryPulseDuration(const AccessoryPulseDuration duration)
167 {
168 this->duration = duration;
169 }
170
171 inline bool GetInverted() const
172 {
173 return inverted;
174 }
175
176 inline void SetInverted(const bool inverted)
177 {
178 this->inverted = inverted;
179 }
180
181 inline time_t GetLastUsed() const
182 {
183 return lastUsed;
184 }
185
186
187 inline void SetMatchKey(const std::string& matchKey)
188 {
189 this->matchKey = matchKey;
190 }
191
192 inline void ClearMatchKey()
193 {
194 matchKey.clear();
195 }
196
197 inline std::string GetMatchKey() const
198 {
199 return matchKey;
200 }
201
202 protected:
203 virtual std::string Serialize() const;
•204 virtual void Deserialize(const std::map<std::string,std::string>& arguments);
205
206 private:
207 AccessoryType accessoryType;
208 AccessoryState accessoryState;
209 AccessoryPulseDuration duration; // duration in ms after which the accessory command will be turned off on rails. 0 = no turn off / turn off must be made manually
210 bool inverted;
211
212 time_t lastUsed;
213 unsigned int counter;
214
215 std::string matchKey;
216 };
217 } // namespace DataModel
218