| 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 "DataModel/Loco.h" |
| 22 | #include "DataModel/LocoFunctions.h" |
| 23 | #include "DataTypes.h" |
| 24 | #include "Logger/Logger.h" |
| 25 | #include "Hardware/CS1.h" |
| 26 | #include "Hardware/CS2Udp.h" |
| 27 | #include "Hardware/CS2Tcp.h" |
| 28 | #include "Hardware/CcSchnitte.h" |
| 29 | #include "Hardware/DR5000.h" |
| 30 | #include "Hardware/DccPpExSerial.h" |
| 31 | #include "Hardware/DccPpExTcp.h" |
| 32 | #include "Hardware/Ecos.h" |
| 33 | #include "Hardware/HardwareHandler.h" |
| 34 | #include "Hardware/Hsi88.h" |
| 35 | #include "Hardware/Intellibox.h" |
| 36 | #include "Hardware/Intellibox2.h" |
| 37 | #include "Hardware/LocoNetAdapter63120.h" |
| 38 | #include "Hardware/LocoNetAdapter63820.h" |
| 39 | #include "Hardware/M6051.h" |
| 40 | #include "Hardware/MasterControl.h" |
| 41 | #include "Hardware/MasterControl2.h" |
| 42 | #include "Hardware/OpenDcc.h" |
| 43 | #include "Hardware/RedBox.h" |
| 44 | #include "Hardware/Rektor.h" |
| 45 | #include "Hardware/SystemControl7.h" |
| 46 | #include "Hardware/TwinCenter.h" |
| 47 | #include "Hardware/Virtual.h" |
| 48 | #include "Hardware/Z21.h" |
| 49 | #include "Utils/Utils.h" |
| 50 | |
| 51 | using std::string; |
| 52 | |
| 53 | namespace Hardware |
| 54 | { |
| 55 | const std::string HardwareHandler::Unknown = Languages::GetText(Languages::TextUnknownHardware); |
| 56 | |
| 57 | void HardwareHandler::Init(const HardwareParams* params) |
| 58 | { |
| 59 | this->params = params; |
| 60 | HardwareType type = params->GetHardwareType(); |
| 61 | |
| 62 | switch(type) |
| 63 | { |
| 64 | case HardwareTypeNone: |
| 65 | instance = nullptr; |
| 66 | return; |
| 67 | |
| 68 | case HardwareTypeVirtual: |
| 69 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new Virtual(params)); |
| 70 | return; |
| 71 | |
| 72 | case HardwareTypeCS2Udp: |
| 73 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new CS2Udp(params)); |
| 74 | return; |
| 75 | |
| 76 | case HardwareTypeM6051: |
| 77 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new M6051(params)); |
| 78 | return; |
| 79 | |
| 80 | case HardwareTypeOpenDcc: |
| 81 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new OpenDcc(params)); |
| 82 | return; |
| 83 | |
| 84 | case HardwareTypeHsi88: |
| 85 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new Hsi88(params)); |
| 86 | return; |
| 87 | |
| 88 | case HardwareTypeZ21: |
| 89 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new Z21(params)); |
| 90 | return; |
| 91 | |
| 92 | case HardwareTypeCcSchnitte: |
| 93 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new CcSchnitte(params)); |
| 94 | return; |
| 95 | |
| 96 | case HardwareTypeEcos: |
| 97 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new Ecos(params)); |
| 98 | return; |
| 99 | |
| 100 | case HardwareTypeCS2Tcp: |
| 101 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new CS2Tcp(params)); |
| 102 | return; |
| 103 | |
| 104 | case HardwareTypeIntellibox: |
| 105 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new Intellibox(params)); |
| 106 | break; |
| 107 | |
| 108 | case HardwareTypeMasterControl: |
| 109 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new MasterControl(params)); |
| 110 | break; |
| 111 | |
| 112 | case HardwareTypeTwinCenter: |
| 113 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new TwinCenter(params)); |
| 114 | break; |
| 115 | |
| 116 | case HardwareTypeMasterControl2: |
| 117 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new MasterControl2(params)); |
| 118 | break; |
| 119 | |
| 120 | case HardwareTypeRedBox: |
| 121 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new RedBox(params)); |
| 122 | break; |
| 123 | |
| 124 | case HardwareTypeRektor: |
| 125 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new Rektor(params)); |
| 126 | return; |
| 127 | |
| 128 | case HardwareTypeDR5000: |
| 129 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new DR5000(params)); |
| 130 | return; |
| 131 | |
| 132 | case HardwareTypeCS1: |
| 133 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new CS1(params)); |
| 134 | return; |
| 135 | |
| 136 | case HardwareTypeDccPpExTcp: |
| 137 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new DccPpExTcp(params)); |
| 138 | return; |
| 139 | |
| 140 | case HardwareTypeDccPpExSerial: |
| 141 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new DccPpExSerial(params)); |
| 142 | return; |
| 143 | |
| 144 | case HardwareTypeIntellibox2: |
| 145 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new Intellibox2(params)); |
| 146 | break; |
| 147 | |
| 148 | case HardwareTypeLocoNetAdapter63120: |
| 149 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new LocoNetAdapter63120(params)); |
| 150 | break; |
| 151 | |
| 152 | case HardwareTypeLocoNetAdapter63820: |
| 153 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new LocoNetAdapter63820(params)); |
| 154 | break; |
| 155 | |
| 156 | case HardwareTypeSystemControl7: |
| 157 | instance = reinterpret_cast<Hardware::HardwareInterface*>(new SystemControl7(params)); |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void HardwareHandler::Close() |
| 163 | { |
| 164 | delete(instance); |
| 165 | instance = nullptr; |
| 166 | params = nullptr; |
| 167 | } |
| 168 | |
| 169 | const std::string& HardwareHandler::GetName() const |
| 170 | { |
| 171 | if (!instance) |
| 172 | { |
| 173 | return Unknown; |
| 174 | } |
| 175 | return instance->GetFullName(); |
| 176 | } |
| 177 | |
| 178 | const std::string& HardwareHandler::GetShortName() const |
| 179 | { |
| 180 | if (!instance) |
| 181 | { |
| 182 | return Unknown; |
| 183 | } |
| 184 | return instance->GetShortName(); |
| 185 | } |
| 186 | |
| 187 | Hardware::Capabilities HardwareHandler::GetCapabilities() const |
| 188 | { |
| 189 | if (!instance) |
| 190 | { |
| 191 | return Hardware::CapabilityNone; |
| 192 | } |
| 193 | |
| 194 | return instance->GetCapabilities(); |
| 195 | } |
| 196 | |
| 197 | void HardwareHandler::LocoProtocols(std::vector<Protocol>& protocols) const |
| 198 | { |
| 199 | if (!instance) |
| 200 | { |
| 201 | protocols.push_back(ProtocolNone); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | instance->GetLocoProtocols(protocols); |
| 206 | } |
| 207 | |
| 208 | bool HardwareHandler::LocoProtocolSupported(Protocol protocol) const |
| 209 | { |
| 210 | if (!instance) |
| 211 | { |
| 212 | return false; |
| 213 | } |
| 214 | return instance->LocoProtocolSupported(protocol); |
| 215 | } |
| 216 | |
| 217 | void HardwareHandler::AccessoryProtocols(std::vector<Protocol>& protocols) const |
| 218 | { |
| 219 | if (!instance) |
| 220 | { |
| 221 | protocols.push_back(ProtocolNone); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | instance->GetAccessoryProtocols(protocols); |
| 226 | } |
| 227 | |
| 228 | bool HardwareHandler::AccessoryProtocolSupported(Protocol protocol) const |
| 229 | { |
| 230 | if (!instance) |
| 231 | { |
| 232 | return false; |
| 233 | } |
| 234 | return instance->AccessoryProtocolSupported(protocol); |
| 235 | } |
| 236 | |
| 237 | void HardwareHandler::Booster(const ControlType controlType, const BoosterState status) |
| 238 | { |
| 239 | if (controlType == ControlTypeHardware || !instance) |
| 240 | { |
| 241 | return; |
| 242 | } |
| 243 | instance->Booster(status); |
| 244 | } |
| 245 | |
| 246 | void HardwareHandler::LocoBaseSpeed(const ControlType controlType, |
| 247 | const DataModel::LocoBase* loco, |
| 248 | const Speed speed) |
| 249 | { |
| 250 | if (controlType == ControlTypeHardware || !instance || loco->GetControlID() != GetControlID()) |
| 251 | { |
| 252 | return; |
| 253 | } |
| 254 | instance->LocoSpeed(loco->GetProtocol(), loco->GetAddress(), speed); |
| 255 | } |
| 256 | |
| 257 | void HardwareHandler::LocoBaseOrientation(const ControlType controlType, |
| 258 | const DataModel::LocoBase* loco, |
| 259 | const Orientation orientation) |
| 260 | { |
| 261 | if (controlType == ControlTypeHardware || !instance || loco->GetControlID() != GetControlID()) |
| 262 | { |
| 263 | return; |
| 264 | } |
| 265 | instance->LocoOrientation(loco->GetProtocol(), loco->GetAddress(), orientation); |
| 266 | } |
| 267 | |
| 268 | void HardwareHandler::LocoBaseFunction(const ControlType controlType, |
| 269 | const DataModel::LocoBase* loco, |
| 270 | const DataModel::LocoFunctionNr function, |
| 271 | const DataModel::LocoFunctionState on) |
| 272 | { |
| 273 | if (controlType == ControlTypeHardware || !instance || loco->GetControlID() != GetControlID()) |
| 274 | { |
| 275 | return; |
| 276 | } |
| 277 | instance->LocoFunction(loco->GetProtocol(), loco->GetAddress(), function, on); |
| 278 | } |
| 279 | |
| 280 | void HardwareHandler::LocoBaseSpeedOrientationFunctions(const DataModel::LocoBase* loco, |
| 281 | const Speed speed, |
| 282 | const Orientation orientation, |
| 283 | std::vector<DataModel::LocoFunctionEntry>& functions) |
| 284 | { |
| 285 | if (!instance || loco->GetControlID() != GetControlID()) |
| 286 | { |
| 287 | return; |
| 288 | } |
| 289 | instance->LocoSpeedOrientationFunctions(loco->GetProtocol(), loco->GetAddress(), speed, orientation, functions); |
| 290 | } |
| 291 | |
| 292 | void HardwareHandler::LocoSettings(const LocoID locoId, |
| 293 | __attribute__((unused)) const std::string& name, |
| 294 | const std::string& matchKey) |
| 295 | { |
| 296 | if (!instance) |
| 297 | { |
| 298 | return; |
| 299 | } |
| 300 | instance->SetLocoIdOfMatchKey(locoId, matchKey); |
| 301 | } |
| 302 | |
| 303 | void HardwareHandler::LocoDelete(__attribute__((unused)) const LocoID locoID, |
| 304 | __attribute__((unused)) const std::string& name, |
| 305 | const std::string& matchKey) |
| 306 | { |
| 307 | if (!instance) |
| 308 | { |
| 309 | return; |
| 310 | } |
| 311 | instance->SetLocoIdOfMatchKey(LocoNone, matchKey); |
| 312 | } |
| 313 | |
| 314 | void HardwareHandler::AccessorySettings(const AccessoryID accessoryId, |
| 315 | __attribute__((unused)) const std::string& name, |
| 316 | const std::string& matchKey) |
| 317 | { |
| 318 | if (!instance) |
| 319 | { |
| 320 | return; |
| 321 | } |
| 322 | instance->SetAccessoryIdentifierOfMatchKey(DataModel::ObjectIdentifier(ObjectTypeAccessory, accessoryId), matchKey); |
| 323 | } |
| 324 | |
| 325 | void HardwareHandler::AccessoryDelete(__attribute__((unused)) const AccessoryID accessoryId, |
| 326 | __attribute__((unused)) const std::string& name, |
| 327 | const std::string& matchKey) |
| 328 | { |
| 329 | if (!instance) |
| 330 | { |
| 331 | return; |
| 332 | } |
| 333 | instance->SetAccessoryIdentifierOfMatchKey(DataModel::ObjectIdentifier(ObjectTypeNone, ObjectNone), matchKey); |
| 334 | } |
| 335 | |
| 336 | void HardwareHandler::AccessoryState(const ControlType controlType, const DataModel::Accessory* accessory) |
| 337 | { |
| 338 | if (controlType == ControlTypeHardware |
| 339 | || !instance |
| 340 | || !accessory |
| 341 | || accessory->GetControlID() != this->GetControlID()) |
| 342 | { |
| 343 | return; |
| 344 | } |
| 345 | const Protocol protocol = accessory->GetProtocol(); |
| 346 | const Address address = accessory->GetAddress(); |
| 347 | const DataModel::AccessoryState state = accessory->GetInvertedAccessoryState(); |
| 348 | const DataModel::AccessoryPulseDuration duration = accessory->GetAccessoryPulseDuration(); |
| 349 | switch (accessory->GetAccessoryType() & DataModel::AccessoryTypeConnectionMask) |
| 350 | { |
| 351 | case DataModel::AccessoryTypeOnOn: |
| 352 | { |
| 353 | AccessoryBaseState(protocol, address, state, duration); |
| 354 | break; |
| 355 | } |
| 356 | |
| 357 | case DataModel::AccessoryTypeOnPush: |
| 358 | case DataModel::AccessoryTypeOnOff: |
| 359 | { |
| 360 | const AddressPort port = accessory->GetPort(); |
| 361 | const DataModel::AccessoryState portAsState = static_cast<DataModel::AccessoryState>(port); |
| 362 | if (state == DataModel::AccessoryStateOn) |
| 363 | { |
| 364 | instance->Accessory(protocol, address, portAsState, true, duration); |
| 365 | } |
| 366 | else |
| 367 | { |
| 368 | instance->Accessory(protocol, address, portAsState, false, 0); |
| 369 | } |
| 370 | break; |
| 371 | } |
| 372 | |
| 373 | default: |
| 374 | break; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | void HardwareHandler::AccessoryBaseState(const Protocol protocol, |
| 379 | const Address address, |
| 380 | const DataModel::AccessoryState state, |
| 381 | const DataModel::AccessoryPulseDuration duration) |
| 382 | { |
| 383 | instance->Accessory(protocol, address, state, true, duration); |
| 384 | __attribute((unused)) auto r = std::async(std::launch::async, AccessoryBaseStateStatic, instance, protocol, address, state, duration); |
| 385 | } |
| 386 | |
| 387 | void HardwareHandler::SwitchSettings(const SwitchID switchId, |
| 388 | __attribute__((unused)) const std::string& name, |
| 389 | const std::string& matchKey) |
| 390 | { |
| 391 | if (!instance) |
| 392 | { |
| 393 | return; |
| 394 | } |
| 395 | instance->SetAccessoryIdentifierOfMatchKey(DataModel::ObjectIdentifier(ObjectTypeSwitch, switchId), matchKey); |
| 396 | } |
| 397 | |
| 398 | void HardwareHandler::SwitchDelete(__attribute__((unused)) const SwitchID switchId, |
| 399 | __attribute__((unused)) const std::string& name, |
| 400 | const std::string& matchKey) |
| 401 | { |
| 402 | if (!instance) |
| 403 | { |
| 404 | return; |
| 405 | } |
| 406 | instance->SetAccessoryIdentifierOfMatchKey(DataModel::ObjectIdentifier(ObjectTypeNone, ObjectNone), matchKey); |
| 407 | } |
| 408 | |
| 409 | void HardwareHandler::SwitchState(const ControlType controlType, const DataModel::Switch* mySwitch) |
| 410 | { |
| 411 | if (controlType == ControlTypeHardware |
| 412 | || !instance |
| 413 | || !mySwitch |
| 414 | || mySwitch->GetControlID() != this->GetControlID()) |
| 415 | { |
| 416 | return; |
| 417 | } |
| 418 | |
| 419 | const Protocol protocol = mySwitch->GetProtocol(); |
| 420 | const Address address = mySwitch->GetAddress(); |
| 421 | const DataModel::AccessoryPulseDuration duration = mySwitch->GetAccessoryPulseDuration(); |
| 422 | if (mySwitch->GetAccessoryType() != DataModel::SwitchTypeThreeWay) |
| 423 | { |
| 424 | AccessoryBaseState(protocol, address, mySwitch->GetInvertedAccessoryState(), duration); |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | switch (mySwitch->GetAccessoryState()) |
| 429 | { |
| 430 | case DataModel::SwitchStateTurnout: |
| 431 | AccessoryBaseState(protocol, address + 1, mySwitch->CalculateInvertedAccessoryState(DataModel::SwitchStateStraight), duration); |
| 432 | AccessoryBaseState(protocol, address, mySwitch->CalculateInvertedAccessoryState(DataModel::SwitchStateTurnout), duration); |
| 433 | break; |
| 434 | |
| 435 | case DataModel::SwitchStateStraight: |
| 436 | AccessoryBaseState(protocol, address, mySwitch->CalculateInvertedAccessoryState(DataModel::SwitchStateStraight), duration); |
| 437 | AccessoryBaseState(protocol, address + 1, mySwitch->CalculateInvertedAccessoryState(DataModel::SwitchStateStraight), duration); |
| 438 | break; |
| 439 | |
| 440 | case DataModel::SwitchStateThird: |
| 441 | AccessoryBaseState(protocol, address, mySwitch->CalculateInvertedAccessoryState(DataModel::SwitchStateStraight), duration); |
| 442 | AccessoryBaseState(protocol, address + 1, mySwitch->CalculateInvertedAccessoryState(DataModel::SwitchStateTurnout), duration); |
| 443 | break; |
| 444 | |
| 445 | default: |
| 446 | break; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | void HardwareHandler::SignalSettings(const SignalID signalId, |
| 451 | __attribute__((unused)) const std::string& name, |
| 452 | const std::string& matchKey) |
| 453 | { |
| 454 | if (!instance) |
| 455 | { |
| 456 | return; |
| 457 | } |
| 458 | instance->SetAccessoryIdentifierOfMatchKey(DataModel::ObjectIdentifier(ObjectTypeSignal, signalId), matchKey); |
| 459 | } |
| 460 | |
| 461 | void HardwareHandler::SignalDelete(__attribute__((unused)) const SignalID signalId, |
| 462 | __attribute__((unused)) const std::string& name, |
| 463 | const std::string& matchKey) |
| 464 | { |
| 465 | if (!instance) |
| 466 | { |
| 467 | return; |
| 468 | } |
| 469 | instance->SetAccessoryIdentifierOfMatchKey(DataModel::ObjectIdentifier(ObjectTypeNone, ObjectNone), matchKey); |
| 470 | } |
| 471 | |
| 472 | void HardwareHandler::SignalState(const ControlType controlType, const DataModel::Signal* signal) |
| 473 | { |
| 474 | if (controlType == ControlTypeHardware |
| 475 | || !instance |
| 476 | || !signal |
| 477 | || signal->GetControlID() != this->GetControlID()) |
| 478 | { |
| 479 | return; |
| 480 | } |
| 481 | const Address address = signal->GetMappedAddress(); |
| 482 | if (address == 0) |
| 483 | { |
| 484 | return; |
| 485 | } |
| 486 | const DataModel::AccessoryState state = signal->GetMappedAccessoryState(); |
| 487 | AccessoryBaseState(signal->GetProtocol(), address, state, signal->GetAccessoryPulseDuration()); |
| 488 | } |
| 489 | |
| 490 | bool HardwareHandler::ProgramCheckValues(const ProgramMode mode, const CvNumber cv, const CvValue value) |
| 491 | { |
| 492 | if (cv == 0) |
| 493 | { |
| 494 | // CVs are one based, so CV zero is not allowed |
| 495 | return false; |
| 496 | } |
| 497 | if (cv == 1 && value == 0) |
| 498 | { |
| 499 | // loco/accessory address zero is not allowed for DCC decoders and can not be undone. |
| 500 | // It would destroy some DCC decoders. Therefore we do not allow this. |
| 501 | return false; |
| 502 | } |
| 503 | CvNumber maxCv; |
| 504 | switch (mode) |
| 505 | { |
| 506 | case ProgramModeMm: |
| 507 | case ProgramModeMmPom: |
| 508 | maxCv = 0x100; |
| 509 | break; |
| 510 | |
| 511 | case ProgramModeDccRegister: |
| 512 | case ProgramModeDccPage: |
| 513 | case ProgramModeDccDirect: |
| 514 | case ProgramModeDccPomLoco: |
| 515 | case ProgramModeDccPomAccessory: |
| 516 | maxCv = 0x400; |
| 517 | break; |
| 518 | |
| 519 | case ProgramModeMfx: |
| 520 | maxCv = 0x4000; |
| 521 | break; |
| 522 | |
| 523 | default: |
| 524 | return false; |
| 525 | } |
| 526 | return (cv <= maxCv); |
| 527 | } |
| 528 | |
| 529 | void HardwareHandler::ProgramRead(const ProgramMode mode, const Address address, const CvNumber cv) |
| 530 | { |
| 531 | if (!ProgramCheckValues(mode, cv)) |
| 532 | { |
| 533 | return; |
| 534 | } |
| 535 | if (!instance) |
| 536 | { |
| 537 | return; |
| 538 | } |
| 539 | |
| 540 | instance->ProgramRead(mode, address, cv); |
| 541 | } |
| 542 | |
| 543 | void HardwareHandler::ProgramWrite(const ProgramMode mode, const Address address, const CvNumber cv, const CvValue value) |
| 544 | { |
| 545 | if (!ProgramCheckValues(mode, cv, value)) |
| 546 | { |
| 547 | return; |
| 548 | } |
| 549 | if (!instance) |
| 550 | { |
| 551 | return; |
| 552 | } |
| 553 | instance->ProgramWrite(mode, address, cv, value); |
| 554 | } |
| 555 | |
| 556 | void HardwareHandler::FeedbackDelete(const FeedbackID feedbackID, const std::string& name) |
| 557 | { |
| 558 | if (!instance) |
| 559 | { |
| 560 | return; |
| 561 | } |
| 562 | instance->FeedbackDelete(feedbackID, name); |
| 563 | } |
| 564 | |
| 565 | void HardwareHandler::FeedbackSettings(const FeedbackID feedbackID, const std::string& name) |
| 566 | { |
| 567 | if (!instance) |
| 568 | { |
| 569 | return; |
| 570 | } |
| 571 | instance->FeedbackSettings(feedbackID, name); |
| 572 | } |
| 573 | |
| 574 | void HardwareHandler::AddUnmatchedLocos(std::map<std::string,DataModel::LocoConfig>& list) const |
| 575 | { |
| 576 | if (!instance) |
| 577 | { |
| 578 | return; |
| 579 | } |
| 580 | |
| 581 | const std::map<std::string,Hardware::LocoCacheEntry>& database = instance->GetLocoDatabase(); |
| 582 | for (auto& entry : database) |
| 583 | { |
| 584 | const Hardware::LocoCacheEntry& loco = entry.second; |
| 585 | if (loco.GetLocoID() != LocoNone) |
| 586 | { |
| 587 | continue; |
| 588 | } |
| 589 | if (loco.GetType() != LocoTypeLoco) |
| 590 | { |
| 591 | continue; |
| 592 | } |
| 593 | list[loco.GetName() + " (" + instance->GetShortName() + ")"] = loco; |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | std::map<std::string,DataModel::LocoConfig> HardwareHandler::GetUnmatchedLocos(const std::string& matchKey) const |
| 598 | { |
| 599 | std::map<std::string,DataModel::LocoConfig> out; |
| 600 | if (!instance) |
| 601 | { |
| 602 | return out; |
| 603 | } |
| 604 | |
| 605 | const std::map<std::string,Hardware::LocoCacheEntry>& database = instance->GetLocoDatabase(); |
| 606 | for (auto& entry : database) |
| 607 | { |
| 608 | const Hardware::LocoCacheEntry& loco = entry.second; |
| 609 | if ((loco.GetType() != LocoTypeLoco) |
| 610 | && (loco.GetLocoID() != LocoNone) |
| 611 | && (loco.GetMatchKey().size()) |
| 612 | && (loco.GetMatchKey() != matchKey)) |
| 613 | { |
| 614 | continue; |
| 615 | } |
| 616 | out[loco.GetName()] = loco; |
| 617 | } |
| 618 | return out; |
| 619 | } |
| 620 | |
| 621 | DataModel::LocoConfig HardwareHandler::GetLocoByMatchKey(const std::string& match) const |
| 622 | { |
| 623 | if (!instance) |
| 624 | { |
| 625 | return DataModel::LocoConfig(LocoTypeLoco); |
| 626 | } |
| 627 | return instance->GetLocoByMatchKey(match); |
| 628 | } |
| 629 | |
| 630 | void HardwareHandler::AddUnmatchedMultipleUnits(std::map<std::string,DataModel::LocoConfig>& list) const |
| 631 | { |
| 632 | if (!instance) |
| 633 | { |
| 634 | return; |
| 635 | } |
| 636 | |
| 637 | const std::map<std::string,Hardware::LocoCacheEntry>& database = instance->GetLocoDatabase(); |
| 638 | for (auto& entry : database) |
| 639 | { |
| 640 | const Hardware::LocoCacheEntry& loco = entry.second; |
| 641 | if (loco.GetLocoID() != LocoNone) |
| 642 | { |
| 643 | continue; |
| 644 | } |
| 645 | if (loco.GetType() != LocoTypeMultipleUnit) |
| 646 | { |
| 647 | continue; |
| 648 | } |
| 649 | list[loco.GetName() + " (" + instance->GetShortName() + ")"] = loco; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | std::map<std::string,DataModel::LocoConfig> HardwareHandler::GetUnmatchedMultipleUnits(const std::string& matchKey) const |
| 654 | { |
| 655 | std::map<std::string,DataModel::LocoConfig> out; |
| 656 | if (!instance) |
| 657 | { |
| 658 | return out; |
| 659 | } |
| 660 | |
| 661 | const std::map<std::string,Hardware::LocoCacheEntry>& database = instance->GetLocoDatabase(); |
| 662 | for (auto& entry : database) |
| 663 | { |
| 664 | const Hardware::LocoCacheEntry& loco = entry.second; |
| 665 | if ((loco.GetType() != LocoTypeMultipleUnit) |
| 666 | && (loco.GetLocoID() != LocoNone) |
| 667 | && (loco.GetMatchKey().size()) |
| 668 | && (loco.GetMatchKey() != matchKey)) |
| 669 | { |
| 670 | continue; |
| 671 | } |
| 672 | out[loco.GetName()] = loco; |
| 673 | } |
| 674 | return out; |
| 675 | } |
| 676 | |
| 677 | DataModel::LocoConfig HardwareHandler::GetMultipleUnitByMatchKey(const std::string& match) const |
| 678 | { |
| 679 | if (!instance) |
| 680 | { |
| 681 | return DataModel::LocoConfig(LocoTypeMultipleUnit); |
| 682 | } |
| 683 | return instance->GetMultipleUnitByMatchKey(match); |
| 684 | } |
| 685 | |
| 686 | void HardwareHandler::AddUnmatchedAccessories(std::map<std::string,DataModel::AccessoryConfig>& list) const |
| 687 | { |
| 688 | if (!instance) |
| 689 | { |
| 690 | return; |
| 691 | } |
| 692 | |
| 693 | const std::map<std::string,Hardware::AccessoryCacheEntry>& database = instance->GetAccessoryDatabase(); |
| 694 | for (auto& entry : database) |
| 695 | { |
| 696 | const Hardware::AccessoryCacheEntry& accessory = entry.second; |
| 697 | const DataModel::ObjectIdentifier objectIdentifier = accessory.GetObjectIdentifier(); |
| 698 | if (objectIdentifier.GetObjectType() != ObjectTypeNone) |
| 699 | { |
| 700 | continue; |
| 701 | } |
| 702 | list[accessory.GetName() + " (" + instance->GetShortName() + ")"] = accessory; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | std::map<std::string,DataModel::AccessoryConfig> HardwareHandler::GetUnmatchedAccessories(const std::string& matchKey) const |
| 707 | { |
| 708 | std::map<std::string,DataModel::AccessoryConfig> out; |
| 709 | if (!instance) |
| 710 | { |
| 711 | return out; |
| 712 | } |
| 713 | |
| 714 | const std::map<std::string,Hardware::AccessoryCacheEntry>& database = instance->GetAccessoryDatabase(); |
| 715 | for (auto& entry : database) |
| 716 | { |
| 717 | const Hardware::AccessoryCacheEntry& accessory = entry.second; |
| 718 | if (accessory.GetObjectIdentifier().GetObjectID() != ObjectNone |
| 719 | && accessory.GetMatchKey().size() |
| 720 | && accessory.GetMatchKey() != matchKey) |
| 721 | { |
| 722 | continue; |
| 723 | } |
| 724 | out[accessory.GetName()] = accessory; |
| 725 | } |
| 726 | return out; |
| 727 | } |
| 728 | |
| 729 | DataModel::AccessoryConfig HardwareHandler::GetAccessoryByMatchKey(const std::string& match) const |
| 730 | { |
| 731 | if (!instance) |
| 732 | { |
| 733 | return DataModel::AccessoryConfig(); |
| 734 | } |
| 735 | return instance->GetAccessoryByMatchKey(match); |
| 736 | } |
| 737 | |
| 738 | void HardwareHandler::AddUnmatchedFeedbacks(std::map<std::string,DataModel::FeedbackConfig>& list) const |
| 739 | { |
| 740 | if (!instance) |
| 741 | { |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | const std::map<std::string,Hardware::FeedbackCacheEntry>& database = instance->GetFeedbackDatabase(); |
| 746 | for (auto& entry : database) |
| 747 | { |
| 748 | const Hardware::FeedbackCacheEntry& feedback = entry.second; |
| 749 | if (feedback.GetFeedbackID() != FeedbackNone) |
| 750 | { |
| 751 | continue; |
| 752 | } |
| 753 | list[feedback.GetName() + " (" + instance->GetShortName() + ")"] = feedback; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | std::map<std::string,DataModel::FeedbackConfig> HardwareHandler::GetUnmatchedFeedbacks(const std::string& matchKey) const |
| 758 | { |
| 759 | std::map<std::string,DataModel::FeedbackConfig> out; |
| 760 | if (!instance) |
| 761 | { |
| 762 | return out; |
| 763 | } |
| 764 | |
| 765 | const std::map<std::string,Hardware::FeedbackCacheEntry>& database = instance->GetFeedbackDatabase(); |
| 766 | for (auto& entry : database) |
| 767 | { |
| 768 | const Hardware::FeedbackCacheEntry& feedback = entry.second; |
| 769 | if (feedback.GetFeedbackID() != FeedbackNone && feedback.GetMatchKey().size() && feedback.GetMatchKey() != matchKey) |
| 770 | { |
| 771 | continue; |
| 772 | } |
| 773 | out[feedback.GetName()] = feedback; |
| 774 | } |
| 775 | return out; |
| 776 | } |
| 777 | |
| 778 | DataModel::FeedbackConfig HardwareHandler::GetFeedbackByMatchKey(const std::string& match) const |
| 779 | { |
| 780 | if (!instance) |
| 781 | { |
| 782 | return DataModel::FeedbackConfig(); |
| 783 | } |
| 784 | return instance->GetFeedbackByMatchKey(match); |
| 785 | } |
| 786 | |
| 787 | void HardwareHandler::ArgumentTypesOfHardwareTypeAndHint(const HardwareType hardwareType, std::map<unsigned char,ArgumentType>& arguments, std::string& hint) |
| 788 | { |
| 789 | switch (hardwareType) |
| 790 | { |
| 791 | case HardwareTypeNone: |
| 792 | hint = ""; |
| 793 | return; |
| 794 | |
| 795 | case HardwareTypeVirtual: |
| 796 | Hardware::Virtual::GetHint(hint); |
| 797 | return; |
| 798 | |
| 799 | case HardwareTypeCS2Udp: |
| 800 | Hardware::CS2Udp::GetArgumentTypesAndHint(arguments, hint); |
| 801 | return; |
| 802 | |
| 803 | case HardwareTypeM6051: |
| 804 | Hardware::M6051::GetArgumentTypesAndHint(arguments, hint); |
| 805 | return; |
| 806 | |
| 807 | case HardwareTypeOpenDcc: |
| 808 | Hardware::OpenDcc::GetArgumentTypesAndHint(arguments, hint); |
| 809 | return; |
| 810 | |
| 811 | case HardwareTypeHsi88: |
| 812 | Hardware::Hsi88::GetArgumentTypesAndHint(arguments, hint); |
| 813 | return; |
| 814 | |
| 815 | case HardwareTypeDR5000: |
| 816 | case HardwareTypeRektor: |
| 817 | case HardwareTypeZ21: |
| 818 | Hardware::Protocols::Z21::GetArgumentTypesAndHint(arguments, hint); |
| 819 | return; |
| 820 | |
| 821 | case HardwareTypeCcSchnitte: |
| 822 | Hardware::CcSchnitte::GetArgumentTypesAndHint(arguments, hint); |
| 823 | return; |
| 824 | |
| 825 | case HardwareTypeEcos: |
| 826 | Hardware::Protocols::EsuCAN::GetArgumentTypesAndHint(arguments, hint); |
| 827 | return; |
| 828 | |
| 829 | case HardwareTypeCS2Tcp: |
| 830 | Hardware::CS2Tcp::GetArgumentTypesAndHint(arguments, hint); |
| 831 | return; |
| 832 | |
| 833 | case HardwareTypeIntellibox: |
| 834 | Hardware::Intellibox::GetArgumentTypesAndHint(arguments, hint); |
| 835 | return; |
| 836 | |
| 837 | case HardwareTypeMasterControl: |
| 838 | Hardware::MasterControl::GetArgumentTypesAndHint(arguments, hint); |
| 839 | return; |
| 840 | |
| 841 | case HardwareTypeTwinCenter: |
| 842 | Hardware::TwinCenter::GetArgumentTypesAndHint(arguments, hint); |
| 843 | return; |
| 844 | |
| 845 | case HardwareTypeMasterControl2: |
| 846 | Hardware::MasterControl2::GetArgumentTypesAndHint(arguments, hint); |
| 847 | return; |
| 848 | |
| 849 | case HardwareTypeRedBox: |
| 850 | Hardware::RedBox::GetArgumentTypesAndHint(arguments, hint); |
| 851 | return; |
| 852 | |
| 853 | case HardwareTypeCS1: |
| 854 | Hardware::Protocols::EsuCAN::GetArgumentTypesAndHint(arguments, hint); |
| 855 | return; |
| 856 | |
| 857 | case HardwareTypeDccPpExTcp: |
| 858 | Hardware::DccPpExTcp::GetArgumentTypesAndHint(arguments, hint); |
| 859 | return; |
| 860 | |
| 861 | case HardwareTypeDccPpExSerial: |
| 862 | Hardware::DccPpExSerial::GetArgumentTypesAndHint(arguments, hint); |
| 863 | return; |
| 864 | |
| 865 | case HardwareTypeIntellibox2: |
| 866 | Hardware::Intellibox2::GetArgumentTypesAndHint(arguments, hint); |
| 867 | return; |
| 868 | |
| 869 | case HardwareTypeLocoNetAdapter63120: |
| 870 | Hardware::LocoNetAdapter63120::GetArgumentTypesAndHint(arguments, hint); |
| 871 | return; |
| 872 | |
| 873 | case HardwareTypeLocoNetAdapter63820: |
| 874 | Hardware::LocoNetAdapter63820::GetArgumentTypesAndHint(arguments, hint); |
| 875 | return; |
| 876 | |
| 877 | case HardwareTypeSystemControl7: |
| 878 | Hardware::SystemControl7::GetArgumentTypesAndHint(arguments, hint); |
| 879 | return; |
| 880 | } |
| 881 | } |
| 882 | } // namespace Hardware |