Debian Codegraph @

Hardware/Protocols/LocoNetLocoCache.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 <cstdint>
24
25 #include "DataTypes.h"
26
27 namespace Hardware
28 {
29 namespace Protocols
30 {
31 class LocoNetLocoCacheEntry
32 {
33 public:
34 inline LocoNetLocoCacheEntry()
35 : address(0),
36 orientationF0F4(0),
37 f5F8(0),
38 f9F12(0),
39 f13F44(0)
40 {
41 }
42
43 inline void SetAddress(const Address address)
44 {
45 this->address = address;
46 }
47
48 inline Address GetAddress() const
49 {
50 return address;
51 }
52
53 inline void SetOrientationF0F4(const uint8_t orientationF0F4)
54 {
55 this->orientationF0F4 = orientationF0F4;
56 }
57
58 inline uint8_t GetOrientationF0F4()
59 {
60 return orientationF0F4;
61 }
62
63 inline void SetF5F8(const uint8_t f5F8)
64 {
65 this->f5F8 = f5F8;
66 }
67
68 inline unsigned char GetF5F8()
69 {
70 return f5F8;
71 }
72
73 inline void SetF9F12(const uint8_t f9F12)
74 {
75 this->f9F12 = f9F12;
76 }
77
78 inline uint8_t GetF9F12()
79 {
80 return f9F12;
81 }
82
83 inline void SetF13F44(const uint32_t f13F44)
84 {
85 this->f13F44 = f13F44;
86 }
87
88 inline uint32_t GetF13F44()
89 {
90 return f13F44;
91 }
92
93 Address address;
94 uint8_t orientationF0F4;
95 uint8_t f5F8;
96 uint8_t f9F12;
97 uint32_t f13F44;
98 };
99
100 class LocoNetLocoCache
101 {
102 public:
103 LocoNetLocoCache(const LocoNetLocoCache&) = delete;
104 LocoNetLocoCache& operator=(const LocoNetLocoCache&) = delete;
105
106 LocoNetLocoCache()
107 {
108 }
109
110 virtual ~LocoNetLocoCache()
111 {
112 }
113
114 inline void SetAddress(const unsigned char slot, const Address address)
115 {
116 if (slot == 0 || slot > MaxLocoNetSlot)
117 {
118 return;
119 }
120 entries[slot].SetAddress(address);
121 }
122
123 inline unsigned char GetSlotOfAddress(const Address address)
124 {
125 for (unsigned char slot = MinLocoNetSlot; slot <= MaxLocoNetSlot; ++slot)
126 {
127 if (address == entries[slot].GetAddress())
128 {
129 return slot;
130 }
131 }
132 return 0;
133 }
134
135 inline Address GetAddressOfSlot(unsigned char slot)
136 {
137 if (slot == 0 || slot > MaxLocoNetSlot)
138 {
139 return 0;
140 }
141 return entries[slot].GetAddress();
142 }
143
144 inline void SetOrientationF0F4(const unsigned char slot, const uint8_t orientationF0F4)
145 {
146 if (slot == 0 || slot > MaxLocoNetSlot)
147 {
148 return;
149 }
150 entries[slot].SetOrientationF0F4(orientationF0F4);
151 }
152
153 inline uint8_t GetOrientationF0F4(const unsigned char slot)
154 {
155 if (slot == 0 || slot > MaxLocoNetSlot)
156 {
157 return 0;
158 }
159 return entries[slot].GetOrientationF0F4();
160 }
161
162 inline void SetF5F8(const unsigned char slot, const uint8_t f5F8)
163 {
164 if (slot == 0 || slot > MaxLocoNetSlot)
165 {
166 return;
167 }
168 entries[slot].SetF5F8(f5F8);
169 }
170
171 inline uint8_t GetF5F8(const unsigned char slot)
172 {
173 if (slot == 0 || slot > MaxLocoNetSlot)
174 {
175 return 0;
176 }
177 return entries[slot].GetF5F8();
178 }
179
180 inline void SetF9F12(const unsigned char slot, const uint8_t f9F12)
181 {
182 if (slot == 0 || slot > MaxLocoNetSlot)
183 {
184 return;
185 }
186 entries[slot].SetF9F12(f9F12);
187 }
188
189 inline uint8_t GetF9F12(const unsigned char slot)
190 {
191 if (slot == 0 || slot > MaxLocoNetSlot)
192 {
193 return 0;
194 }
195 return entries[slot].GetF9F12();
196 }
197
198 inline void SetF13F44(const unsigned char slot, const uint32_t f13F44)
199 {
200 if (slot == 0 || slot > MaxLocoNetSlot)
201 {
202 return;
203 }
204 entries[slot].SetF13F44(f13F44);
205 }
206
207 inline uint32_t GetF13F44(const unsigned char slot)
208 {
209 if (slot == 0 || slot > MaxLocoNetSlot)
210 {
211 return 0;
212 }
213 return entries[slot].GetF13F44();
214 }
215
216 static const unsigned char MinLocoNetSlot = 1;
217 static const unsigned char MaxLocoNetSlot = 119;
218
219 private:
220 LocoNetLocoCacheEntry entries[MaxLocoNetSlot + 1];
221
222 };
223 } // namespace
224 } // namespace
225