| 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 | #include <future> |
| 22 | #include <sstream> |
| 23 | #include <string> |
| 24 | |
| 25 | #include "Hardware/Virtual.h" |
| 26 | #include "Manager.h" |
| 27 | #include "Utils/Utils.h" |
| 28 | |
| 29 | namespace Hardware |
| 30 | { |
| 31 | Virtual::Virtual(const HardwareParams* params) |
| 32 | : HardwareInterface(params->GetManager(), |
| 33 | params->GetControlID(), |
| 34 | "Virtual Command Station / " + params->GetName(), |
| 35 | params->GetName()) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | // turn booster on or off |
| 40 | void Virtual::Booster(const BoosterState status) |
| 41 | { |
| 42 | logger->Info(status ? Languages::TextTurningBoosterOn : Languages::TextTurningBoosterOff); |
| 43 | } |
| 44 | |
| 45 | // set loco speed |
| 46 | void Virtual::LocoSpeed(const Protocol protocol, const Address address, const Speed speed) |
| 47 | { |
| 48 | logger->Info(Languages::TextSettingSpeedWithProtocol, Utils::Utils::ProtocolToString(protocol), address, speed); |
| 49 | } |
| 50 | |
| 51 | // set the direction of a loco |
| 52 | void Virtual::LocoOrientation(const Protocol protocol, const Address address, const Orientation orientation) |
| 53 | { |
| 54 | logger->Info(Languages::TextSettingDirectionOfTravelWithProtocol, Utils::Utils::ProtocolToString(protocol), address, Languages::GetLeftRight(orientation)); |
| 55 | } |
| 56 | |
| 57 | // set loco function |
| 58 | void Virtual::LocoFunction(const Protocol protocol, |
| 59 | const Address address, |
| 60 | const DataModel::LocoFunctionNr function, |
| 61 | const DataModel::LocoFunctionState on) |
| 62 | { |
| 63 | logger->Info(Languages::TextSettingFunctionWithProtocol, static_cast<int>(function), Utils::Utils::ProtocolToString(protocol), address, Languages::GetOnOff(on)); |
| 64 | } |
| 65 | |
| 66 | // accessory command |
| 67 | void Virtual::Accessory(const Protocol protocol, |
| 68 | const Address address, |
| 69 | const DataModel::AccessoryState state, |
| 70 | const bool on, |
| 71 | __attribute__((unused)) const DataModel::AccessoryPulseDuration duration) |
| 72 | { |
| 73 | logger->Info(Languages::TextSettingAccessoryWithProtocol, Utils::Utils::ProtocolToString(protocol), address, Languages::GetGreenRed(state), Languages::GetOnOff(on)); |
| 74 | } |
| 75 | |
| 76 | // read CV value |
| 77 | void Virtual::ProgramRead(const ProgramMode mode, const Address address, const CvNumber cv) |
| 78 | { |
| 79 | switch (mode) |
| 80 | { |
| 81 | case ProgramModeMfx: |
| 82 | logger->Info(Languages::TextProgramMfxRead, address, cv); |
| 83 | break; |
| 84 | |
| 85 | case ProgramModeDccRegister: |
| 86 | logger->Info(Languages::TextProgramDccRegisterRead, cv); |
| 87 | break; |
| 88 | |
| 89 | case ProgramModeDccPage: |
| 90 | logger->Info(Languages::TextProgramDccPageRead, cv); |
| 91 | break; |
| 92 | |
| 93 | case ProgramModeDccDirect: |
| 94 | logger->Info(Languages::TextProgramDccDirectRead, cv); |
| 95 | break; |
| 96 | |
| 97 | case ProgramModeDccPomLoco: |
| 98 | logger->Info(Languages::TextProgramDccPomLocoRead, address, cv); |
| 99 | break; |
| 100 | |
| 101 | case ProgramModeDccPomAccessory: |
| 102 | logger->Info(Languages::TextProgramDccPomAccessoryRead, address, cv); |
| 103 | break; |
| 104 | |
| 105 | default: |
| 106 | return; |
| 107 | } |
| 108 | __attribute__((unused)) auto r = std::async(std::launch::async, Manager::ProgramDccValueStatic, manager, cv, cv & 0xFF); |
| 109 | } |
| 110 | |
| 111 | // write DCC CV value |
| 112 | void Virtual::ProgramWrite(const ProgramMode mode, const Address address, const CvNumber cv, const CvValue value) |
| 113 | { |
| 114 | switch (mode) |
| 115 | { |
| 116 | case ProgramModeMm: |
| 117 | logger->Info(Languages::TextProgramMm, cv, value); |
| 118 | break; |
| 119 | |
| 120 | case ProgramModeMmPom: |
| 121 | logger->Info(Languages::TextProgramMmPom, address, cv, value); |
| 122 | break; |
| 123 | |
| 124 | case ProgramModeMfx: |
| 125 | logger->Info(Languages::TextProgramMfxWrite, address, cv, value); |
| 126 | break; |
| 127 | |
| 128 | case ProgramModeDccRegister: |
| 129 | logger->Info(Languages::TextProgramDccRegisterWrite, cv, value); |
| 130 | break; |
| 131 | |
| 132 | case ProgramModeDccPage: |
| 133 | logger->Info(Languages::TextProgramDccPageWrite, cv, value); |
| 134 | break; |
| 135 | |
| 136 | case ProgramModeDccDirect: |
| 137 | logger->Info(Languages::TextProgramDccDirectWrite, cv, value); |
| 138 | break; |
| 139 | |
| 140 | case ProgramModeDccPomLoco: |
| 141 | logger->Info(Languages::TextProgramDccPomLocoWrite, address, cv, value); |
| 142 | break; |
| 143 | |
| 144 | case ProgramModeDccPomAccessory: |
| 145 | logger->Info(Languages::TextProgramDccPomAccessoryWrite, address, cv, value); |
| 146 | break; |
| 147 | |
| 148 | default: |
| 149 | return; |
| 150 | } |
| 151 | } |
| 152 | } // namespace |