Debian Codegraph @

Hardware/M6051.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 <string>
24
25 #include "HardwareInterface.h"
26 #include "HardwareParams.h"
27 #include "Logger/Logger.h"
28 #include "Network/Serial.h"
29
30 namespace Hardware
31 {
32 class M6051 : HardwareInterface
33 {
34 public:
35 M6051() = delete;
36 M6051(const M6051&) = delete;
37 M6051& operator=(const M6051&) = delete;
38
39 M6051(const HardwareParams* params);
40 ~M6051();
41
42 inline Hardware::Capabilities GetCapabilities() const override
43 {
44 return Hardware::CapabilityLoco
45 | Hardware::CapabilityAccessory
46 | Hardware::CapabilityFeedback;
47 }
48
49 void GetLocoProtocols(std::vector<Protocol>& protocols) const override { protocols.push_back(ProtocolMM2); }
50
51 bool LocoProtocolSupported(Protocol protocol) const override { return (protocol == ProtocolMM2); }
52
53 void GetAccessoryProtocols(std::vector<Protocol>& protocols) const override { protocols.push_back(ProtocolMM2); }
54
55 bool AccessoryProtocolSupported(Protocol protocol) const override { return (protocol == ProtocolMM2); }
56
57 static void GetArgumentTypesAndHint(std::map<unsigned char,ArgumentType>& argumentTypes, std::string& hint)
58 {
59 argumentTypes[1] = ArgumentTypeSerialPort;
60 argumentTypes[2] = ArgumentTypeS88Modules;
61 hint = Languages::GetText(Languages::TextHintM6051);
62 }
63
64 void Booster(const BoosterState status) override;
65 void LocoSpeed(const Protocol protocol, const Address address, const Speed speed) override;
66 void LocoOrientation(const Protocol protocol, const Address address, const Orientation orientation) override;
67
68 void LocoFunction(const Protocol protocol,
69 const Address address,
70 const DataModel::LocoFunctionNr function,
71 const DataModel::LocoFunctionState on) override;
72
73 void Accessory(const Protocol protocol,
74 const Address address,
75 const DataModel::AccessoryState state,
76 const bool on,
77 const DataModel::AccessoryPulseDuration duration) override;
78
79 private:
80 static const unsigned char MaxS88Modules = 62;
81 Network::Serial serialLine;
82 volatile bool run;
83 unsigned char s88Modules;
84 std::thread s88Thread;
85 unsigned char s88Memory[MaxS88Modules];
86 std::map<Address, unsigned char> speedMap;
87 std::map<Address, unsigned char> functionMap;
88
89 unsigned char GetSpeedMapEntry(Address address)
90 {
91 return speedMap.count(address) == 0 ? 0 : speedMap[address];
92 }
93
94 unsigned char GetFunctionMapEntry(Address address)
95 {
96 return functionMap.count(address) == 0 ? 0 : functionMap[address];
97 }
98
99 void SendTwoBytes(const unsigned char byte1, const unsigned char byte2)
100 {
101 char dataArray[2];
102 dataArray[0] = byte1;
103 dataArray[1] = byte2;
104 std::string data(dataArray, 2);
105 serialLine.Send(data);
106 }
107
108 void S88Worker();
109 };
110 } // namespace
111