Ursprung
b773187c9b
Commit
14f5fb1ab7
@ -28,7 +28,10 @@
|
||||
#include "../protocol/marklincan/iohandler/simulationiohandler.hpp"
|
||||
#include "../protocol/marklincan/iohandler/tcpiohandler.hpp"
|
||||
#include "../protocol/marklincan/iohandler/udpiohandler.hpp"
|
||||
#include "../protocol/marklincan/kernel.hpp"
|
||||
#include "../protocol/marklincan/settings.hpp"
|
||||
#include "../../core/attributes.hpp"
|
||||
#include "../../core/objectproperty.tpp"
|
||||
#include "../../log/log.hpp"
|
||||
#include "../../log/logmessageexception.hpp"
|
||||
#include "../../utils/displayname.hpp"
|
||||
@ -42,8 +45,10 @@ MarklinCANInterface::MarklinCANInterface(World& world, std::string_view _id)
|
||||
, InputController(static_cast<IdObject&>(*this))
|
||||
, type{this, "type", MarklinCANInterfaceType::NetworkTCP, PropertyFlags::ReadWrite | PropertyFlags::Store}
|
||||
, hostname{this, "hostname", "", PropertyFlags::ReadWrite | PropertyFlags::Store}
|
||||
, marklinCAN{this, "marklin_can", nullptr, PropertyFlags::ReadOnly | PropertyFlags::Store | PropertyFlags::SubObject}
|
||||
{
|
||||
name = "M\u00E4rklin CAN";
|
||||
marklinCAN.setValueInternal(std::make_shared<MarklinCAN::Settings>(*this, marklinCAN.name()));
|
||||
|
||||
Attributes::addDisplayName(type, DisplayName::Interface::type);
|
||||
Attributes::addEnabled(type, !online);
|
||||
@ -54,6 +59,9 @@ MarklinCANInterface::MarklinCANInterface(World& world, std::string_view _id)
|
||||
Attributes::addEnabled(hostname, !online);
|
||||
m_interfaceItems.insertBefore(hostname, notes);
|
||||
|
||||
Attributes::addDisplayName(marklinCAN, DisplayName::Hardware::marklinCAN);
|
||||
m_interfaceItems.insertBefore(marklinCAN, notes);
|
||||
|
||||
m_interfaceItems.insertBefore(decoders, notes);
|
||||
|
||||
m_interfaceItems.insertBefore(inputs, notes);
|
||||
@ -96,22 +104,20 @@ bool MarklinCANInterface::setOnline(bool& value, bool simulation)
|
||||
{
|
||||
try
|
||||
{
|
||||
const MarklinCAN::Config config{true};
|
||||
|
||||
if(simulation)
|
||||
{
|
||||
m_kernel = MarklinCAN::Kernel::create<MarklinCAN::SimulationIOHandler>(config);
|
||||
m_kernel = MarklinCAN::Kernel::create<MarklinCAN::SimulationIOHandler>(marklinCAN->config());
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(type.value())
|
||||
{
|
||||
case MarklinCANInterfaceType::NetworkTCP:
|
||||
m_kernel = MarklinCAN::Kernel::create<MarklinCAN::TCPIOHandler>(config, hostname.value());
|
||||
m_kernel = MarklinCAN::Kernel::create<MarklinCAN::TCPIOHandler>(marklinCAN->config(), hostname.value());
|
||||
break;
|
||||
|
||||
case MarklinCANInterfaceType::NetworkUDP:
|
||||
m_kernel = MarklinCAN::Kernel::create<MarklinCAN::UDPIOHandler>(config, hostname.value());
|
||||
m_kernel = MarklinCAN::Kernel::create<MarklinCAN::UDPIOHandler>(marklinCAN->config(), hostname.value());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -132,6 +138,12 @@ bool MarklinCANInterface::setOnline(bool& value, bool simulation)
|
||||
|
||||
m_kernel->start();
|
||||
|
||||
m_marklinCANPropertyChanged = marklinCAN->propertyChanged.connect(
|
||||
[this](BaseProperty& /*property*/)
|
||||
{
|
||||
m_kernel->setConfig(marklinCAN->config());
|
||||
});
|
||||
|
||||
Attributes::setEnabled({type, hostname}, false);
|
||||
}
|
||||
catch(const LogMessageException& e)
|
||||
@ -145,6 +157,8 @@ bool MarklinCANInterface::setOnline(bool& value, bool simulation)
|
||||
{
|
||||
Attributes::setEnabled({type, hostname}, true);
|
||||
|
||||
m_marklinCANPropertyChanged.disconnect();
|
||||
|
||||
m_kernel->stop();
|
||||
m_kernel.reset();
|
||||
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
#include "../decoder/decodercontroller.hpp"
|
||||
#include "../input/inputcontroller.hpp"
|
||||
#include "../protocol/marklincan/kernel.hpp"
|
||||
#include "../protocol/marklincan/settings.hpp"
|
||||
|
||||
/**
|
||||
* @brief Märklin CAN hardware interface
|
||||
@ -43,6 +44,7 @@ class MarklinCANInterface final
|
||||
|
||||
private:
|
||||
std::unique_ptr<MarklinCAN::Kernel> m_kernel;
|
||||
boost::signals2::connection m_marklinCANPropertyChanged;
|
||||
|
||||
void addToWorld() final;
|
||||
void destroying() final;
|
||||
@ -56,6 +58,7 @@ class MarklinCANInterface final
|
||||
public:
|
||||
Property<MarklinCANInterfaceType> type;
|
||||
Property<std::string> hostname;
|
||||
ObjectProperty<MarklinCAN::Settings> marklinCAN;
|
||||
|
||||
MarklinCANInterface(World& world, std::string_view _id);
|
||||
|
||||
|
||||
46
server/src/hardware/protocol/marklincan/settings.cpp
Normale Datei
46
server/src/hardware/protocol/marklincan/settings.cpp
Normale Datei
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* server/src/hardware/protocol/marklincan/settings.cpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2023 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "settings.hpp"
|
||||
#include "../../../core/attributes.hpp"
|
||||
#include "../../../utils/displayname.hpp"
|
||||
|
||||
namespace MarklinCAN {
|
||||
|
||||
Settings::Settings(Object& _parent, std::string_view parentPropertyName)
|
||||
: SubObject(_parent, parentPropertyName)
|
||||
, debugLogRXTX{this, "debug_log_rx_tx", false, PropertyFlags::ReadWrite | PropertyFlags::Store}
|
||||
{
|
||||
Attributes::addDisplayName(debugLogRXTX, DisplayName::Hardware::debugLogRXTX);
|
||||
m_interfaceItems.add(debugLogRXTX);
|
||||
}
|
||||
|
||||
Config Settings::config() const
|
||||
{
|
||||
Config config;
|
||||
|
||||
config.debugLogRXTX = debugLogRXTX;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
46
server/src/hardware/protocol/marklincan/settings.hpp
Normale Datei
46
server/src/hardware/protocol/marklincan/settings.hpp
Normale Datei
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* server/src/hardware/protocol/marklincan/settings.hpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2023 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef TRAINTASTIC_SERVER_HARDWARE_PROTOCOL_MARKLINCAN_SETTINGS_HPP
|
||||
#define TRAINTASTIC_SERVER_HARDWARE_PROTOCOL_MARKLINCAN_SETTINGS_HPP
|
||||
|
||||
#include "../../../core/subobject.hpp"
|
||||
#include "../../../core/property.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
namespace MarklinCAN {
|
||||
|
||||
class Settings final : public SubObject
|
||||
{
|
||||
public:
|
||||
CLASS_ID("marklincan_settings")
|
||||
|
||||
Property<bool> debugLogRXTX;
|
||||
|
||||
Settings(Object& _parent, std::string_view parentPropertyName);
|
||||
|
||||
Config config() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2021-2022 Reinder Feenstra
|
||||
* Copyright (C) 2021-2023 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -53,6 +53,7 @@ namespace DisplayName
|
||||
constexpr std::string_view inputs = "hardware:inputs";
|
||||
constexpr std::string_view interface = "hardware:interface";
|
||||
constexpr std::string_view loconet = "hardware:loconet";
|
||||
constexpr std::string_view marklinCAN = "hardware:marklin_can";
|
||||
constexpr std::string_view outputKeyboard = "hardware:output_keyboard";
|
||||
constexpr std::string_view outputs = "hardware:outputs";
|
||||
constexpr std::string_view speedSteps = "hardware:speed_steps";
|
||||
|
||||
@ -358,5 +358,9 @@
|
||||
{
|
||||
"term": "decoder_protocol:selectrix",
|
||||
"definition": "Selectrix"
|
||||
},
|
||||
{
|
||||
"term": "hardware:marklin_can",
|
||||
"definition": "Märklin CAN"
|
||||
}
|
||||
]
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren