removed namespace stuff
Dieser Commit ist enthalten in:
Ursprung
2e84170dc7
Commit
71ba4a87fb
@ -23,7 +23,7 @@
|
||||
#include "commandstationproperty.hpp"
|
||||
#include "../hardware/commandstation/commandstation.hpp"
|
||||
|
||||
using T = Hardware::CommandStation::CommandStation;
|
||||
using T = CommandStation;
|
||||
|
||||
CommandStationProperty::CommandStationProperty(Object* object, const std::string& name, const std::shared_ptr<T>& value, PropertyFlags flags) :
|
||||
AbstractObjectProperty(object, name, flags),
|
||||
|
||||
@ -26,40 +26,38 @@
|
||||
#include "abstractobjectproperty.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
class CommandStation;
|
||||
}
|
||||
|
||||
//! workaround for ObjectProperty<Hardware::CommandStation::CommandStation>
|
||||
//! workaround for ObjectProperty<CommandStation>
|
||||
class CommandStationProperty : public AbstractObjectProperty
|
||||
{
|
||||
public:
|
||||
using OnSet = std::function<bool(const std::shared_ptr<Hardware::CommandStation::CommandStation>& value)>;
|
||||
using OnSet = std::function<bool(const std::shared_ptr<CommandStation>& value)>;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Hardware::CommandStation::CommandStation> m_value;
|
||||
std::shared_ptr<CommandStation> m_value;
|
||||
OnSet m_onSet;
|
||||
|
||||
public:
|
||||
CommandStationProperty(Object* object, const std::string& name, const std::shared_ptr<Hardware::CommandStation::CommandStation>& value, PropertyFlags flags);
|
||||
CommandStationProperty(Object* object, const std::string& name, const std::shared_ptr<CommandStation>& value, PropertyFlags flags);
|
||||
CommandStationProperty(Object* object, const std::string& name, nullptr_t, PropertyFlags flags);
|
||||
CommandStationProperty(Object* object, const std::string& name, const std::shared_ptr<Hardware::CommandStation::CommandStation>& value, PropertyFlags flags, OnSet onSet);
|
||||
CommandStationProperty(Object* object, const std::string& name, const std::shared_ptr<CommandStation>& value, PropertyFlags flags, OnSet onSet);
|
||||
CommandStationProperty(Object* object, const std::string& name, nullptr_t, PropertyFlags flags, OnSet onSet);
|
||||
|
||||
const std::shared_ptr<Hardware::CommandStation::CommandStation>& value() const;
|
||||
const std::shared_ptr<CommandStation>& value() const;
|
||||
|
||||
void setValue(const std::shared_ptr<Hardware::CommandStation::CommandStation>& value);
|
||||
void setValueInternal(const std::shared_ptr<Hardware::CommandStation::CommandStation>& value);
|
||||
void setValue(const std::shared_ptr<CommandStation>& value);
|
||||
void setValueInternal(const std::shared_ptr<CommandStation>& value);
|
||||
|
||||
const Hardware::CommandStation::CommandStation* operator ->() const;
|
||||
Hardware::CommandStation::CommandStation* operator ->();
|
||||
const CommandStation* operator ->() const;
|
||||
CommandStation* operator ->();
|
||||
|
||||
const Hardware::CommandStation::CommandStation& operator *() const;
|
||||
Hardware::CommandStation::CommandStation& operator *();
|
||||
const CommandStation& operator *() const;
|
||||
CommandStation& operator *();
|
||||
|
||||
operator bool();
|
||||
|
||||
CommandStationProperty& operator =(const std::shared_ptr<Hardware::CommandStation::CommandStation>& value);
|
||||
CommandStationProperty& operator =(const std::shared_ptr<CommandStation>& value);
|
||||
|
||||
ObjectPtr toObject() const final;
|
||||
void fromObject(const ObjectPtr& value) final;
|
||||
|
||||
@ -28,8 +28,6 @@
|
||||
#include "../decoder/decoder.hpp"
|
||||
#include "../decoder/decoderlist.hpp"
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
CommandStation::CommandStation(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
IdObject(world, _id),
|
||||
name{this, "name", "", PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||
@ -97,7 +95,7 @@ void CommandStation::worldEvent(WorldState state, WorldEvent event)
|
||||
trackVoltageOff = false;
|
||||
}
|
||||
|
||||
const std::shared_ptr<Hardware::Decoder>& CommandStation::getDecoder(DecoderProtocol protocol, uint16_t address, bool longAddress) const
|
||||
const std::shared_ptr<::Decoder>& CommandStation::getDecoder(DecoderProtocol protocol, uint16_t address, bool longAddress) const
|
||||
{
|
||||
auto it = std::find_if(decoders->begin(), decoders->end(), [=](auto& decoder){ return decoder->protocol.value() == protocol && decoder->address.value() == address && decoder->longAddress == longAddress; });
|
||||
if(it != decoders->end())
|
||||
@ -117,11 +115,8 @@ void CommandStation::trackVoltageOffChanged(bool value)
|
||||
controller->trackPowerChanged(!value);
|
||||
}
|
||||
|
||||
void CommandStation::decoderChanged(const Hardware::Decoder& decoder, Hardware::DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
void CommandStation::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
{
|
||||
for(auto& controller : *controllers)
|
||||
controller->decoderChanged(decoder, changes, functionNumber);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -29,16 +29,12 @@
|
||||
#include "../decoder/decoderlist.hpp"
|
||||
#include "../controller/controllerlist.hpp"
|
||||
|
||||
namespace Hardware {
|
||||
class Decoder;
|
||||
enum class DecoderChangeFlags;
|
||||
}
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
class CommandStation : public IdObject
|
||||
{
|
||||
friend class ::Hardware::Decoder;
|
||||
friend class ::Decoder;
|
||||
|
||||
protected:
|
||||
void addToWorld() final;
|
||||
@ -48,7 +44,7 @@ class CommandStation : public IdObject
|
||||
virtual void emergencyStopChanged(bool value);
|
||||
virtual void trackVoltageOffChanged(bool value);
|
||||
//virtual bool isDecoderSupported(Decoder& decoder) const = 0;
|
||||
virtual void decoderChanged(const Hardware::Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber);
|
||||
virtual void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber);
|
||||
|
||||
public:
|
||||
CommandStation(const std::weak_ptr<World>& world, std::string_view _id);
|
||||
@ -61,9 +57,7 @@ class CommandStation : public IdObject
|
||||
ObjectProperty<ControllerList> controllers;
|
||||
Property<std::string> notes;
|
||||
|
||||
const std::shared_ptr<Hardware::Decoder>& getDecoder(DecoderProtocol protocol, uint16_t address, bool longAddress = false) const;
|
||||
const std::shared_ptr<Decoder>& getDecoder(DecoderProtocol protocol, uint16_t address, bool longAddress = false) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -22,12 +22,10 @@
|
||||
|
||||
#include "commandstationlist.hpp"
|
||||
#include "commandstationlisttablemodel.hpp"
|
||||
#include "create.hpp"
|
||||
#include "commandstations.hpp"
|
||||
#include "../../world/world.hpp"
|
||||
#include "../../world/getworld.hpp"
|
||||
|
||||
using Hardware::CommandStation::CommandStation;
|
||||
|
||||
CommandStationList::CommandStationList(Object& _parent, const std::string& parentPropertyName) :
|
||||
ObjectList<CommandStation>(_parent, parentPropertyName),
|
||||
add{*this, "add",
|
||||
@ -36,7 +34,7 @@ CommandStationList::CommandStationList(Object& _parent, const std::string& paren
|
||||
auto world = getWorld(this);
|
||||
if(!world)
|
||||
return std::shared_ptr<CommandStation>();
|
||||
return Hardware::CommandStation::create(world, classId, world->getUniqueId("cs"));
|
||||
return CommandStations::create(world, classId, world->getUniqueId("cs"));
|
||||
}},
|
||||
remove{*this, "remove",
|
||||
[this](const std::shared_ptr<CommandStation>& object)
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
#include "../../core/objectlist.hpp"
|
||||
#include "commandstation.hpp"
|
||||
|
||||
class CommandStationList : public ObjectList<Hardware::CommandStation::CommandStation>
|
||||
class CommandStationList : public ObjectList<CommandStation>
|
||||
{
|
||||
protected:
|
||||
void worldEvent(WorldState state, WorldEvent event) final;
|
||||
@ -35,8 +35,8 @@ class CommandStationList : public ObjectList<Hardware::CommandStation::CommandSt
|
||||
public:
|
||||
CLASS_ID("command_station_list")
|
||||
|
||||
Method<std::shared_ptr<Hardware::CommandStation::CommandStation>(std::string_view classId)> add;
|
||||
Method<void(const std::shared_ptr<Hardware::CommandStation::CommandStation>&)> remove;
|
||||
Method<std::shared_ptr<CommandStation>(std::string_view classId)> add;
|
||||
Method<void(const std::shared_ptr<CommandStation>&)> remove;
|
||||
|
||||
CommandStationList(Object& _parent, const std::string& parentPropertyName);
|
||||
|
||||
|
||||
@ -24,8 +24,6 @@
|
||||
#include "commandstationlist.hpp"
|
||||
#include "../../utils/utf8.hpp"
|
||||
|
||||
using Hardware::CommandStation::CommandStation;
|
||||
|
||||
constexpr uint32_t columnId = 0;
|
||||
constexpr uint32_t columnName = 1;
|
||||
constexpr uint32_t columnOnline = 2;
|
||||
@ -46,11 +44,11 @@ CommandStationListTableModel::CommandStationListTableModel(CommandStationList& l
|
||||
ObjectListTableModel<CommandStation>(list)
|
||||
{
|
||||
setColumnHeaders({
|
||||
"hardware.command_station:id",
|
||||
"hardware.command_station:name",
|
||||
"hardware.command_station:online",
|
||||
"hardware.command_station:emergency_stop",
|
||||
"hardware.command_station:track_power"});
|
||||
"command_station:id",
|
||||
"command_station:name",
|
||||
"command_station:online",
|
||||
"command_station:emergency_stop",
|
||||
"command_station:track_power"});
|
||||
}
|
||||
|
||||
std::string CommandStationListTableModel::getText(uint32_t column, uint32_t row) const
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
class CommandStationList;
|
||||
|
||||
class CommandStationListTableModel : public ObjectListTableModel<Hardware::CommandStation::CommandStation>
|
||||
class CommandStationListTableModel : public ObjectListTableModel<CommandStation>
|
||||
{
|
||||
friend class CommandStationList;
|
||||
|
||||
|
||||
@ -20,17 +20,15 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "create.hpp"
|
||||
#include "commandstations.hpp"
|
||||
#include "li10x.hpp"
|
||||
#include "loconetserial.hpp"
|
||||
#ifndef DISABLE_USB_XPRESSNET_INTERFACE
|
||||
#include "usbxpressnetinterface.hpp"
|
||||
#endif
|
||||
#include "z21.hpp"
|
||||
#include "rocoz21.hpp"
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
const std::vector<std::string_view>& classList()
|
||||
const std::vector<std::string_view>& CommandStations::classList()
|
||||
{
|
||||
static std::vector<std::string_view> list({
|
||||
LI10x::classId,
|
||||
@ -38,12 +36,12 @@ const std::vector<std::string_view>& classList()
|
||||
#ifndef DISABLE_USB_XPRESSNET_INTERFACE
|
||||
USBXpressNetInterface::classId,
|
||||
#endif
|
||||
Z21::classId,
|
||||
RocoZ21::classId,
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
std::shared_ptr<CommandStation> create(const std::weak_ptr<World>& world, std::string_view classId, std::string_view id)
|
||||
std::shared_ptr<CommandStation> CommandStations::create(const std::weak_ptr<World>& world, std::string_view classId, std::string_view id)
|
||||
{
|
||||
if(classId == LI10x::classId)
|
||||
return LI10x::create(world, id);
|
||||
@ -53,10 +51,8 @@ std::shared_ptr<CommandStation> create(const std::weak_ptr<World>& world, std::s
|
||||
else if(classId == USBXpressNetInterface::classId)
|
||||
return USBXpressNetInterface::create(world, id);
|
||||
#endif
|
||||
else if(classId == Z21::classId)
|
||||
return Z21::create(world, id);
|
||||
else if(classId == RocoZ21::classId)
|
||||
return RocoZ21::create(world, id);
|
||||
else
|
||||
return std::shared_ptr<CommandStation>();
|
||||
}
|
||||
|
||||
}
|
||||
@ -25,14 +25,13 @@
|
||||
|
||||
#include "commandstation.hpp"
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
struct CommandStations
|
||||
{
|
||||
static constexpr std::string_view classIdPrefix = "command_station.";
|
||||
|
||||
static constexpr std::string_view classIdPrefix = "hardware.command_station.";
|
||||
static const std::vector<std::string_view>& classList();
|
||||
|
||||
const std::vector<std::string_view>& classList();
|
||||
|
||||
std::shared_ptr<CommandStation> create(const std::weak_ptr<World>& world, std::string_view classId, std::string_view id);
|
||||
|
||||
}
|
||||
static std::shared_ptr<CommandStation> create(const std::weak_ptr<World>& world, std::string_view classId, std::string_view id);
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -25,8 +25,6 @@
|
||||
#include "../../core/traintastic.hpp"
|
||||
#include "../../core/eventloop.hpp"
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
LI10x::LI10x(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
CommandStation(world, _id),
|
||||
m_serialPort{Traintastic::instance->ioContext()},
|
||||
@ -35,7 +33,7 @@ LI10x::LI10x(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
xpressnet{this, "xpressnet", nullptr, PropertyFlags::ReadOnly | PropertyFlags::Store | PropertyFlags::SubObject}
|
||||
{
|
||||
name = "LI10x";
|
||||
xpressnet.setValueInternal(std::make_shared<::Protocol::XpressNet>(*this, xpressnet.name(), std::bind(&LI10x::send, this, std::placeholders::_1)));
|
||||
xpressnet.setValueInternal(std::make_shared<XpressNet>(*this, xpressnet.name(), std::bind(&LI10x::send, this, std::placeholders::_1)));
|
||||
|
||||
m_interfaceItems.insertBefore(port, notes);
|
||||
m_interfaceItems.insertBefore(baudrate, notes);
|
||||
@ -64,9 +62,9 @@ void LI10x::emergencyStopChanged(bool value)
|
||||
CommandStation::emergencyStopChanged(value);
|
||||
|
||||
if(value)
|
||||
send(Protocol::XpressNet::EmergencyStop());
|
||||
send(XpressNet::EmergencyStop());
|
||||
else if(!trackVoltageOff)
|
||||
send(Protocol::XpressNet::NormalOperationResumed());
|
||||
send(XpressNet::NormalOperationResumed());
|
||||
}
|
||||
|
||||
void LI10x::trackVoltageOffChanged(bool value)
|
||||
@ -74,13 +72,13 @@ void LI10x::trackVoltageOffChanged(bool value)
|
||||
CommandStation::trackVoltageOffChanged(value);
|
||||
|
||||
if(!value)
|
||||
send(Protocol::XpressNet::NormalOperationResumed());
|
||||
send(XpressNet::NormalOperationResumed());
|
||||
else
|
||||
send(Protocol::XpressNet::TrackPowerOff());
|
||||
send(XpressNet::TrackPowerOff());
|
||||
|
||||
}
|
||||
|
||||
void LI10x::decoderChanged(const Hardware::Decoder& decoder, Hardware::DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
void LI10x::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
{
|
||||
CommandStation::decoderChanged(decoder, changes, functionNumber);
|
||||
|
||||
@ -113,9 +111,9 @@ void LI10x::stop()
|
||||
m_serialPort.close();
|
||||
}
|
||||
|
||||
bool LI10x::send(const Protocol::XpressNet::Message& msg)
|
||||
bool LI10x::send(const XpressNet::Message& msg)
|
||||
{
|
||||
assert(Protocol::XpressNet::isChecksumValid(msg));
|
||||
assert(XpressNet::isChecksumValid(msg));
|
||||
if(!m_serialPort.is_open())
|
||||
return false;
|
||||
boost::system::error_code ec;
|
||||
@ -217,5 +215,3 @@ void LI10x::read()
|
||||
EventLoop::call([this, ec](){ logError("async_read_some: " + ec.message()); });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -29,8 +29,6 @@
|
||||
//#include "../../core/objectproperty.hpp"
|
||||
//#include "protocol/xpressnet.hpp"
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
class LI10x : public CommandStation
|
||||
{
|
||||
protected:
|
||||
@ -47,22 +45,20 @@ class LI10x : public CommandStation
|
||||
|
||||
bool start();
|
||||
void stop();
|
||||
bool send(const Protocol::XpressNet::Message& msg);
|
||||
bool send(const XpressNet::Message& msg);
|
||||
void receive(std::unique_ptr<uint8_t[]> message);
|
||||
void read();
|
||||
|
||||
public:
|
||||
CLASS_ID("hardware.command_station.li10x")
|
||||
CLASS_ID("command_station.li10x")
|
||||
CREATE(LI10x)
|
||||
|
||||
Property<std::string> port;
|
||||
Property<uint32_t> baudrate;
|
||||
//Property<bool> useCTS;
|
||||
ObjectProperty<::Protocol::XpressNet> xpressnet;
|
||||
ObjectProperty<XpressNet> xpressnet;
|
||||
|
||||
LI10x(const std::weak_ptr<World>& world, std::string_view _id);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -25,10 +25,6 @@
|
||||
#include "../../core/traintastic.hpp"
|
||||
#include "../../core/eventloop.hpp"
|
||||
|
||||
using namespace Protocol::LocoNet;
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
LocoNetSerial::LocoNetSerial(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
CommandStation(world, _id),
|
||||
m_serialPort{Traintastic::instance->ioContext()},
|
||||
@ -66,7 +62,7 @@ LocoNetSerial::LocoNetSerial(const std::weak_ptr<World>& world, std::string_view
|
||||
loconet{this, "loconet", nullptr, PropertyFlags::ReadOnly | PropertyFlags::Store | PropertyFlags::SubObject}
|
||||
{
|
||||
name = "LocoNet (serial)";
|
||||
loconet.setValueInternal(std::make_shared<LocoNet>(*this, loconet.name(), std::bind(&LocoNetSerial::send, this, std::placeholders::_1)));
|
||||
loconet.setValueInternal(std::make_shared<LocoNet::LocoNet>(*this, loconet.name(), std::bind(&LocoNetSerial::send, this, std::placeholders::_1)));
|
||||
|
||||
port.addAttributeEnabled(!online);
|
||||
interface.addAttributeEnabled(!online);
|
||||
@ -116,7 +112,7 @@ void LocoNetSerial::trackVoltageOffChanged(bool value)
|
||||
loconet->trackVoltageOffChanged(value);
|
||||
}
|
||||
|
||||
void LocoNetSerial::decoderChanged(const Hardware::Decoder& decoder, Hardware::DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
void LocoNetSerial::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
{
|
||||
CommandStation::decoderChanged(decoder, changes, functionNumber);
|
||||
|
||||
@ -157,7 +153,7 @@ void LocoNetSerial::stop()
|
||||
m_serialPort.close();
|
||||
}
|
||||
|
||||
bool LocoNetSerial::send(const Protocol::LocoNet::Message& message)
|
||||
bool LocoNetSerial::send(const LocoNet::Message& message)
|
||||
{
|
||||
if(!m_serialPort.is_open())
|
||||
return false;
|
||||
@ -183,15 +179,15 @@ void LocoNetSerial::read()
|
||||
|
||||
while(bytesTransferred > 1)
|
||||
{
|
||||
const Protocol::LocoNet::Message* message = reinterpret_cast<const Protocol::LocoNet::Message*>(pos);
|
||||
const LocoNet::Message* message = reinterpret_cast<const LocoNet::Message*>(pos);
|
||||
|
||||
size_t drop = 0;
|
||||
while((message->size() == 0 || (message->size() <= bytesTransferred && !Protocol::LocoNet::isValid(*message))) && drop < bytesTransferred)
|
||||
while((message->size() == 0 || (message->size() <= bytesTransferred && !LocoNet::isValid(*message))) && drop < bytesTransferred)
|
||||
{
|
||||
drop++;
|
||||
pos++;
|
||||
bytesTransferred--;
|
||||
message = reinterpret_cast<const Protocol::LocoNet::Message*>(pos);
|
||||
message = reinterpret_cast<const LocoNet::Message*>(pos);
|
||||
}
|
||||
|
||||
if(drop != 0)
|
||||
@ -227,5 +223,3 @@ void LocoNetSerial::read()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -29,8 +29,6 @@
|
||||
#include "../../enum/serialflowcontrol.hpp"
|
||||
#include <boost/asio/serial_port.hpp>
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
class LocoNetSerial : public CommandStation
|
||||
{
|
||||
protected:
|
||||
@ -45,22 +43,21 @@ class LocoNetSerial : public CommandStation
|
||||
|
||||
bool start();
|
||||
void stop();
|
||||
bool send(const Protocol::LocoNet::Message& msg);
|
||||
bool send(const LocoNet::Message& msg);
|
||||
void read();
|
||||
|
||||
public:
|
||||
CLASS_ID("hardware.command_station.loconet_serial")
|
||||
CLASS_ID("command_station.loconet_serial")
|
||||
CREATE(LocoNetSerial)
|
||||
|
||||
Property<std::string> port;
|
||||
Property<LocoNetSerialInterface> interface;
|
||||
Property<uint32_t> baudrate;
|
||||
Property<SerialFlowControl> flowControl;
|
||||
ObjectProperty<::Protocol::LocoNet::LocoNet> loconet;
|
||||
ObjectProperty<LocoNet::LocoNet> loconet;
|
||||
|
||||
LocoNetSerial(const std::weak_ptr<World>& world, std::string_view _id);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -53,7 +53,7 @@
|
||||
#include "../../../core/traintastic.hpp"
|
||||
|
||||
|
||||
namespace Hardware::CommandStation::Protocol {
|
||||
namespace Protocol {
|
||||
|
||||
inline void addressLowHigh(uint16_t address, uint8_t& addressLow, uint8_t& addressHigh)
|
||||
{
|
||||
|
||||
@ -56,7 +56,7 @@ class XpressNet : public IdObject
|
||||
void sendRocoSetFunctionStateF13F20(const Decoder& decoder);
|
||||
|
||||
public:
|
||||
CLASS_ID("hardware.command_station.protocol.xpressnet")
|
||||
CLASS_ID("command_station.protocol.xpressnet")
|
||||
|
||||
static uint8_t calcChecksum(const void* cmd);
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "z21.hpp"
|
||||
#include "rocoz21.hpp"
|
||||
#include "../../core/traintastic.hpp"
|
||||
#include "../../world/world.hpp"
|
||||
#include "../../core/eventloop.hpp"
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ namespace Hardware::CommandStation {
|
||||
|
||||
|
||||
|
||||
Z21::Z21(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
RocoZ21::RocoZ21(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
CommandStation(world, _id),
|
||||
m_socket{Traintastic::instance->ioContext()},
|
||||
hostname{this, "hostname", "", PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||
@ -82,8 +82,8 @@ Z21::Z21(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
shortCircutExternal{this, "short_circut_external", false, PropertyFlags::ReadOnly}
|
||||
{
|
||||
name = "Z21";
|
||||
loconet.setValueInternal(std::make_shared<::Protocol::LocoNet::LocoNet>(*this, loconet.name(),
|
||||
[/*this*/](const ::Protocol::LocoNet::Message& /*msg*/)
|
||||
loconet.setValueInternal(std::make_shared<LocoNet::LocoNet>(*this, loconet.name(),
|
||||
[/*this*/](const ::LocoNet::Message& /*msg*/)
|
||||
{
|
||||
return false;
|
||||
}));
|
||||
@ -125,13 +125,13 @@ Z21::Z21(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
.addAttributeCategory(Category::Info);
|
||||
}
|
||||
|
||||
void Z21::emergencyStopChanged(bool value)
|
||||
void RocoZ21::emergencyStopChanged(bool value)
|
||||
{
|
||||
if(online && value)
|
||||
send(z21_lan_x_set_stop());
|
||||
}
|
||||
|
||||
void Z21::trackVoltageOffChanged(bool value)
|
||||
void RocoZ21::trackVoltageOffChanged(bool value)
|
||||
{
|
||||
if(online)
|
||||
{
|
||||
@ -143,7 +143,7 @@ void Z21::trackVoltageOffChanged(bool value)
|
||||
}
|
||||
|
||||
/*
|
||||
bool Z21::isDecoderSupported(Decoder& decoder) const
|
||||
bool RocoZ21::isDecoderSupported(Decoder& decoder) const
|
||||
{
|
||||
return
|
||||
decoder.protocol == DecoderProtocol::DCC &&
|
||||
@ -155,7 +155,7 @@ bool Z21::isDecoderSupported(Decoder& decoder) const
|
||||
|
||||
|
||||
|
||||
void Z21::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
void RocoZ21::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
{
|
||||
if(has(changes, DecoderChangeFlags::EmergencyStop | DecoderChangeFlags::Direction | DecoderChangeFlags::SpeedStep | DecoderChangeFlags::SpeedSteps))
|
||||
{
|
||||
@ -201,7 +201,7 @@ void Z21::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uin
|
||||
if(decoder.direction.value() == Direction::Forward)
|
||||
cmd.speedAndDirection |= 0x80;
|
||||
|
||||
cmd.checksum = Protocol::XpressNet::calcChecksum(&cmd.xheader);
|
||||
cmd.checksum = XpressNet::calcChecksum(&cmd.xheader);
|
||||
send(&cmd);
|
||||
}
|
||||
else if(has(changes, DecoderChangeFlags::FunctionValue))
|
||||
@ -215,14 +215,14 @@ void Z21::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uin
|
||||
cmd.header = Z21_LAN_X;
|
||||
SET_ADDRESS;
|
||||
cmd.db3 = (f->value ? 0x40 : 0x00) | static_cast<uint8_t>(functionNumber);
|
||||
cmd.checksum = Protocol::XpressNet::calcChecksum(&cmd.xheader);
|
||||
cmd.checksum = XpressNet::calcChecksum(&cmd.xheader);
|
||||
send(&cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Z21::setOnline(bool& value)
|
||||
bool RocoZ21::setOnline(bool& value)
|
||||
{
|
||||
if(!m_socket.is_open() && value)
|
||||
{
|
||||
@ -254,7 +254,7 @@ bool Z21::setOnline(bool& value)
|
||||
|
||||
// try to communicate with Z21
|
||||
|
||||
send(Protocol::Z21::LanGetSerialNumber());
|
||||
send(Z21::LanGetSerialNumber());
|
||||
send(z21_lan_get_hwinfo());
|
||||
send(z21_lan_get_broadcastflags());
|
||||
send(z21_lan_systemstate_getdata());
|
||||
@ -280,7 +280,7 @@ bool Z21::setOnline(bool& value)
|
||||
return true;
|
||||
}
|
||||
|
||||
void Z21::receive()
|
||||
void RocoZ21::receive()
|
||||
{
|
||||
m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_receiveEndpoint,
|
||||
[this](const boost::system::error_code& ec, std::size_t bytesReceived)
|
||||
@ -290,15 +290,15 @@ void Z21::receive()
|
||||
if((bytesReceived >= sizeof(z21_lan_header)))
|
||||
{
|
||||
bool unknownMessage = false;
|
||||
const Protocol::Z21::Message* message = reinterpret_cast<const Protocol::Z21::Message*>(m_receiveBuffer.data());
|
||||
const Z21::Message* message = reinterpret_cast<const Z21::Message*>(m_receiveBuffer.data());
|
||||
const z21_lan_header* cmd = reinterpret_cast<const z21_lan_header*>(m_receiveBuffer.data());
|
||||
switch(cmd->header)
|
||||
{
|
||||
case Z21_LAN_GET_SERIAL_NUMBER:
|
||||
if(message->dataLen() == sizeof(Protocol::Z21::LanGetSerialNumberReply))
|
||||
if(message->dataLen() == sizeof(Z21::LanGetSerialNumberReply))
|
||||
{
|
||||
EventLoop::call(
|
||||
[this, value=std::to_string(static_cast<const Protocol::Z21::LanGetSerialNumberReply*>(message)->serialNumber())]()
|
||||
[this, value=std::to_string(static_cast<const Z21::LanGetSerialNumberReply*>(message)->serialNumber())]()
|
||||
{
|
||||
serialNumber.setValueInternal(value);
|
||||
});
|
||||
@ -431,11 +431,11 @@ void Z21::receive()
|
||||
case Z21_LAN_LOCONET_Z21_RX:
|
||||
//case Z21_LAN_LOCONET_Z21_TX:
|
||||
//case Z21_LAN_LOCONET_Z21_LAN:
|
||||
loconet->receive(*reinterpret_cast<const ::Protocol::LocoNet::Message*>(m_receiveBuffer.data() + sizeof(z21_lan_header)));
|
||||
loconet->receive(*reinterpret_cast<const ::LocoNet::Message*>(m_receiveBuffer.data() + sizeof(z21_lan_header)));
|
||||
break;
|
||||
/*
|
||||
|
||||
using LocoNet = Protocol::LocoNet;
|
||||
using LocoNet = LocoNet;
|
||||
|
||||
const LocoNet::Header* message = reinterpret_cast<const LocoNet::Header*>(m_receiveBuffer.data() + sizeof(z21_lan_header));
|
||||
|
||||
@ -495,7 +495,7 @@ void Z21::receive()
|
||||
});
|
||||
}
|
||||
|
||||
void Z21::send(const Protocol::Z21::Message& message)
|
||||
void RocoZ21::send(const Z21::Message& message)
|
||||
{
|
||||
// TODO async
|
||||
|
||||
@ -514,7 +514,7 @@ void Z21::send(const Protocol::Z21::Message& message)
|
||||
});*/
|
||||
}
|
||||
|
||||
void Z21::send(const z21_lan_header* data)
|
||||
void RocoZ21::send(const z21_lan_header* data)
|
||||
{
|
||||
logDebug("z21_lan_header->dataLen = " + std::to_string(data->dataLen));
|
||||
|
||||
@ -532,5 +532,3 @@ void Z21::send(const z21_lan_header* data)
|
||||
EventLoop::call([this, ec](){ logError(id, "socket.async_send_to: " + ec.message()); });
|
||||
});*/
|
||||
}
|
||||
|
||||
}
|
||||
@ -26,18 +26,15 @@
|
||||
#include "commandstation.hpp"
|
||||
#include <boost/asio.hpp>
|
||||
#include "../../core/objectproperty.hpp"
|
||||
//#include "protocol/xpressnet.hpp"
|
||||
#include "../protocol/loconet/loconet.hpp"
|
||||
|
||||
struct z21_lan_header;
|
||||
|
||||
namespace Protocol::Z21 {
|
||||
namespace Z21 {
|
||||
class Message;
|
||||
}
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
class Z21 : public CommandStation
|
||||
class RocoZ21 : public CommandStation
|
||||
{
|
||||
protected:
|
||||
boost::asio::ip::udp::socket m_socket;
|
||||
@ -52,19 +49,19 @@ class Z21 : public CommandStation
|
||||
void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber) final;
|
||||
|
||||
void receive();
|
||||
void send(const Protocol::Z21::Message& message);
|
||||
void send(const Z21::Message& message);
|
||||
void send(const z21_lan_header* msg);
|
||||
inline void send(const z21_lan_header& msg) { send(&msg); }
|
||||
|
||||
public:
|
||||
CLASS_ID("hardware.command_station.z21")
|
||||
CREATE(Z21)
|
||||
CLASS_ID("command_station.z21")
|
||||
CREATE(RocoZ21)
|
||||
|
||||
Z21(const std::weak_ptr<World>& world, std::string_view _id);
|
||||
RocoZ21(const std::weak_ptr<World>& world, std::string_view _id);
|
||||
|
||||
Property<std::string> hostname;
|
||||
Property<uint16_t> port;
|
||||
ObjectProperty<::Protocol::LocoNet::LocoNet> loconet;
|
||||
ObjectProperty<LocoNet::LocoNet> loconet;
|
||||
Property<std::string> serialNumber;
|
||||
Property<std::string> hardwareType;
|
||||
Property<std::string> firmwareVersion;
|
||||
@ -84,6 +81,4 @@ class Z21 : public CommandStation
|
||||
Property<bool> shortCircutExternal;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -22,8 +22,6 @@
|
||||
#include "../../core/traintastic.hpp"
|
||||
#include "../../world/world.hpp"
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
USBXpressNetInterface::USBXpressNetInterface(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
CommandStation(world, _id),
|
||||
m_handle{nullptr},
|
||||
@ -32,7 +30,7 @@ USBXpressNetInterface::USBXpressNetInterface(const std::weak_ptr<World>& world,
|
||||
xpressnet{this, "xpressnet", nullptr, PropertyFlags::ReadOnly | PropertyFlags::Store | PropertyFlags::SubObject}
|
||||
{
|
||||
name = "USB XpressNet interface";
|
||||
xpressnet.setValueInternal(std::make_shared<::Protocol::XpressNet>(*this, xpressnet.name(), std::bind(&USBXpressNetInterface::send, this, std::placeholders::_1)));
|
||||
xpressnet.setValueInternal(std::make_shared<XpressNet>(*this, xpressnet.name(), std::bind(&USBXpressNetInterface::send, this, std::placeholders::_1)));
|
||||
|
||||
m_interfaceItems.insertBefore(serial, notes);
|
||||
m_interfaceItems.insertBefore(address, notes);
|
||||
@ -99,9 +97,9 @@ void USBXpressNetInterface::decoderChanged(const Decoder& decoder, DecoderChange
|
||||
xpressnet->decoderChanged(decoder, changes, functionNumber);
|
||||
}
|
||||
|
||||
bool USBXpressNetInterface::send(const Protocol::XpressNet::Message& msg)
|
||||
bool USBXpressNetInterface::send(const XpressNet::Message& msg)
|
||||
{
|
||||
assert(Protocol::XpressNet::isChecksumValid(msg));
|
||||
assert(XpressNet::isChecksumValid(msg));
|
||||
if(!m_handle)
|
||||
return false;
|
||||
usbxpressnet_status status;
|
||||
@ -112,5 +110,3 @@ bool USBXpressNetInterface::send(const Protocol::XpressNet::Message& msg)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -27,8 +27,6 @@
|
||||
#include "../protocol/xpressnet.hpp"
|
||||
#include <usbxpressnet.h>
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
|
||||
class USBXpressNetInterface : public CommandStation
|
||||
{
|
||||
protected:
|
||||
@ -42,20 +40,18 @@ class USBXpressNetInterface : public CommandStation
|
||||
void trackVoltageOffChanged(bool value) final;
|
||||
void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber) final;
|
||||
|
||||
bool send(const Protocol::XpressNet::Message& msg);
|
||||
bool send(const XpressNet::Message& msg);
|
||||
|
||||
public:
|
||||
CLASS_ID("hardware.command_station.usb_xpressnet_interface")
|
||||
CLASS_ID("command_station.usb_xpressnet_interface")
|
||||
CREATE(USBXpressNetInterface)
|
||||
|
||||
Property<std::string> serial;
|
||||
Property<uint8_t> address;
|
||||
ObjectProperty<::Protocol::XpressNet> xpressnet;
|
||||
ObjectProperty<::XpressNet> xpressnet;
|
||||
|
||||
USBXpressNetInterface(const std::weak_ptr<World>& world, std::string_view _id);
|
||||
~USBXpressNetInterface() final;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
#include "../../decoder/decoderlist.hpp"
|
||||
#include "../../decoder/decoderchangeflags.hpp"
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
namespace CommandStation {
|
||||
|
||||
XpressNet::XpressNet(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
CommandStation(world, _id),
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
#include "../../protocol/xpressnet.hpp"
|
||||
#include "../../../enum/xpressnetcommandstation.hpp"
|
||||
|
||||
namespace Hardware::CommandStation {
|
||||
namespace CommandStation {
|
||||
|
||||
class XpressNet : public CommandStation
|
||||
{
|
||||
|
||||
@ -30,7 +30,7 @@ Controller::Controller(const std::weak_ptr<World>& _world, std::string_view _id)
|
||||
IdObject(_world, _id),
|
||||
name{this, "name", "", PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||
commandStation{this, "command_station", nullptr, PropertyFlags::ReadWrite | PropertyFlags::Store,
|
||||
[this](const std::shared_ptr<Hardware::CommandStation::CommandStation>& value)
|
||||
[this](const std::shared_ptr<CommandStation>& value)
|
||||
{
|
||||
std::shared_ptr<Controller> controller = shared_ptr<Controller>();
|
||||
assert(controller);
|
||||
|
||||
@ -29,14 +29,12 @@
|
||||
#include "../../core/objectproperty.hpp"
|
||||
#include "../../core/commandstationproperty.hpp"
|
||||
|
||||
namespace Hardware {
|
||||
class Decoder;
|
||||
enum class DecoderChangeFlags;
|
||||
}
|
||||
|
||||
class Controller : public IdObject
|
||||
{
|
||||
friend class Hardware::CommandStation::CommandStation;
|
||||
friend class CommandStation;
|
||||
|
||||
protected:
|
||||
void addToWorld() final;
|
||||
@ -46,7 +44,7 @@ class Controller : public IdObject
|
||||
|
||||
virtual void emergencyStopChanged(bool value) = 0;
|
||||
virtual void trackPowerChanged(bool value) = 0;
|
||||
virtual void decoderChanged(const Hardware::Decoder& decoder, Hardware::DecoderChangeFlags changes, uint32_t functionNumber) = 0;
|
||||
virtual void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber) = 0;
|
||||
|
||||
public:
|
||||
Property<std::string> name;
|
||||
|
||||
@ -26,8 +26,6 @@
|
||||
#include "../commandstation/commandstation.hpp"
|
||||
#include "../../world/getworld.hpp"
|
||||
|
||||
using Hardware::CommandStation::CommandStation;
|
||||
|
||||
ControllerList::ControllerList(Object& _parent, const std::string& parentPropertyName) :
|
||||
ObjectList<Controller>(_parent, parentPropertyName),
|
||||
add{*this, "add",
|
||||
@ -36,7 +34,7 @@ ControllerList::ControllerList(Object& _parent, const std::string& parentPropert
|
||||
auto world = getWorld(&this->parent());
|
||||
if(!world)
|
||||
return std::shared_ptr<Controller>();
|
||||
auto controller = Controllers::create(world, "hardware.controller.wlanmaus", world->getUniqueId("controller"));
|
||||
auto controller = Controllers::create(world, "controller.wlanmaus", world->getUniqueId("controller"));
|
||||
if(auto* cs = dynamic_cast<CommandStation*>(&this->parent()))
|
||||
controller->commandStation = cs->shared_ptr<CommandStation>();
|
||||
//else if(world->commandStations->length() == 1)
|
||||
|
||||
@ -39,9 +39,9 @@ ControllerListTableModel::ControllerListTableModel(ControllerList& list) :
|
||||
ObjectListTableModel<Controller>(list)
|
||||
{
|
||||
setColumnHeaders({
|
||||
"hardware.controller:id",
|
||||
"hardware.controller:name",
|
||||
"hardware.controller:active"});
|
||||
"controller:id",
|
||||
"controller:name",
|
||||
"controller:active"});
|
||||
}
|
||||
|
||||
std::string ControllerListTableModel::getText(uint32_t column, uint32_t row) const
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
struct Controllers
|
||||
{
|
||||
static constexpr std::string_view classIdPrefix = "hardware.controller.";
|
||||
static constexpr std::string_view classIdPrefix = "controller.";
|
||||
|
||||
static const std::vector<std::string_view>& classList();
|
||||
|
||||
|
||||
@ -77,14 +77,14 @@ void WLANmaus::emergencyStopChanged(bool value)
|
||||
{
|
||||
const z21_lan_x_bc_stopped message;
|
||||
for(auto it : m_clients)
|
||||
if(it.second.broadcastFlags & Protocol::Z21::PowerLocoTurnout)
|
||||
if(it.second.broadcastFlags & Z21::PowerLocoTurnout)
|
||||
sendTo(message, it.first);
|
||||
}
|
||||
else if(commandStation && !commandStation->trackVoltageOff) // send z21_lan_x_bc_track_power_on if power is on
|
||||
{
|
||||
const z21_lan_x_bc_track_power_on message;
|
||||
for(auto it : m_clients)
|
||||
if(it.second.broadcastFlags & Protocol::Z21::PowerLocoTurnout)
|
||||
if(it.second.broadcastFlags & Z21::PowerLocoTurnout)
|
||||
sendTo(message, it.first);
|
||||
}
|
||||
}
|
||||
@ -95,19 +95,19 @@ void WLANmaus::trackPowerChanged(bool value)
|
||||
{
|
||||
const z21_lan_x_bc_track_power_on message;
|
||||
for(auto it : m_clients)
|
||||
if(it.second.broadcastFlags & Protocol::Z21::PowerLocoTurnout)
|
||||
if(it.second.broadcastFlags & Z21::PowerLocoTurnout)
|
||||
sendTo(message, it.first);
|
||||
}
|
||||
else
|
||||
{
|
||||
const z21_lan_x_bc_track_power_off message;
|
||||
for(auto it : m_clients)
|
||||
if(it.second.broadcastFlags & Protocol::Z21::PowerLocoTurnout)
|
||||
if(it.second.broadcastFlags & Z21::PowerLocoTurnout)
|
||||
sendTo(message, it.first);
|
||||
}
|
||||
}
|
||||
|
||||
void WLANmaus::decoderChanged(const Hardware::Decoder& decoder, Hardware::DecoderChangeFlags, uint32_t)
|
||||
void WLANmaus::decoderChanged(const Decoder& decoder, DecoderChangeFlags, uint32_t)
|
||||
{
|
||||
if(&decoder == m_blockLocoInfo)
|
||||
return;
|
||||
@ -115,7 +115,7 @@ void WLANmaus::decoderChanged(const Hardware::Decoder& decoder, Hardware::Decode
|
||||
//logDebug("loco info: speedStep=" + std::to_string(decoder.speedStep.value()));
|
||||
|
||||
EventLoop::call(
|
||||
[this, dec=decoder.shared_ptr_c<const Hardware::Decoder>()]()
|
||||
[this, dec=decoder.shared_ptr_c<const Decoder>()]()
|
||||
{
|
||||
broadcastLocoInfo(*dec);
|
||||
});
|
||||
@ -128,14 +128,14 @@ void WLANmaus::receive()
|
||||
{
|
||||
if(!ec)
|
||||
{
|
||||
if((bytesReceived >= sizeof(Protocol::Z21::Message)))
|
||||
if((bytesReceived >= sizeof(Z21::Message)))
|
||||
{
|
||||
bool unknownMessage = false;
|
||||
const Protocol::Z21::Message* message = reinterpret_cast<const Protocol::Z21::Message*>(m_receiveBuffer.data());
|
||||
const Z21::Message* message = reinterpret_cast<const Z21::Message*>(m_receiveBuffer.data());
|
||||
/*[[deprecated]]*/ const z21_lan_header* cmd = reinterpret_cast<const z21_lan_header*>(m_receiveBuffer.data());
|
||||
switch(message->header())
|
||||
{
|
||||
case Protocol::Z21::LAN_X:
|
||||
case Z21::LAN_X:
|
||||
{
|
||||
// TODO check XOR
|
||||
const uint8_t xheader = static_cast<const z21_lan_x*>(cmd)->xheader;
|
||||
@ -315,22 +315,22 @@ void WLANmaus::receive()
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Protocol::Z21::LAN_GET_LOCO_MODE:
|
||||
if(message->dataLen() == sizeof(Protocol::Z21::LanGetLocoMode))
|
||||
case Z21::LAN_GET_LOCO_MODE:
|
||||
if(message->dataLen() == sizeof(Z21::LanGetLocoMode))
|
||||
{
|
||||
// TODO: reply without invoking event loop
|
||||
EventLoop::call(
|
||||
[this, address=static_cast<const Protocol::Z21::LanGetLocoMode*>(message)->address(), endpoint=m_receiveEndpoint]()
|
||||
[this, address=static_cast<const Z21::LanGetLocoMode*>(message)->address(), endpoint=m_receiveEndpoint]()
|
||||
{
|
||||
sendTo(Protocol::Z21::LanGetLocoModeReply(address, Protocol::Z21::LocoMode::DCC), endpoint);
|
||||
sendTo(Z21::LanGetLocoModeReply(address, Z21::LocoMode::DCC), endpoint);
|
||||
});
|
||||
}
|
||||
else
|
||||
unknownMessage = true;
|
||||
break;
|
||||
|
||||
case Protocol::Z21::LAN_SET_LOCO_MODE:
|
||||
if(message->dataLen() == sizeof(Protocol::Z21::LanSetLocoMode))
|
||||
case Z21::LAN_SET_LOCO_MODE:
|
||||
if(message->dataLen() == sizeof(Z21::LanSetLocoMode))
|
||||
{
|
||||
// ignore, we always report DCC
|
||||
}
|
||||
@ -338,20 +338,20 @@ void WLANmaus::receive()
|
||||
unknownMessage = true;
|
||||
break;
|
||||
|
||||
case Protocol::Z21::LAN_GET_SERIAL_NUMBER:
|
||||
if(message->dataLen() == sizeof(Protocol::Z21::LanGetSerialNumber))
|
||||
case Z21::LAN_GET_SERIAL_NUMBER:
|
||||
if(message->dataLen() == sizeof(Z21::LanGetSerialNumber))
|
||||
{
|
||||
EventLoop::call(
|
||||
[this, endpoint=m_receiveEndpoint]()
|
||||
{
|
||||
sendTo(Protocol::Z21::LanGetSerialNumberReply(123456789), endpoint);
|
||||
sendTo(Z21::LanGetSerialNumberReply(123456789), endpoint);
|
||||
});
|
||||
}
|
||||
else
|
||||
unknownMessage = true;
|
||||
break;
|
||||
|
||||
case Protocol::Z21::LAN_GET_HWINFO:
|
||||
case Z21::LAN_GET_HWINFO:
|
||||
if(cmd->dataLen == sizeof(z21_lan_get_hwinfo))
|
||||
{
|
||||
EventLoop::call(
|
||||
@ -364,7 +364,7 @@ void WLANmaus::receive()
|
||||
unknownMessage = true;
|
||||
break;
|
||||
|
||||
case Protocol::Z21::LAN_SET_BROADCASTFLAGS:
|
||||
case Z21::LAN_SET_BROADCASTFLAGS:
|
||||
if(message->dataLen() == sizeof(z21_lan_set_broadcastflags))
|
||||
{
|
||||
EventLoop::call(
|
||||
@ -377,7 +377,7 @@ void WLANmaus::receive()
|
||||
unknownMessage = true;
|
||||
break;
|
||||
|
||||
case Protocol::Z21::LAN_SYSTEMSTATE_GETDATA:
|
||||
case Z21::LAN_SYSTEMSTATE_GETDATA:
|
||||
if(message->dataLen() == sizeof(z21_lan_systemstate_getdata))
|
||||
{
|
||||
EventLoop::call(
|
||||
@ -397,8 +397,8 @@ void WLANmaus::receive()
|
||||
unknownMessage = true;
|
||||
break;
|
||||
|
||||
case Protocol::Z21::LAN_LOGOFF:
|
||||
if(message->dataLen() == sizeof(Protocol::Z21::LanLogoff))
|
||||
case Z21::LAN_LOGOFF:
|
||||
if(message->dataLen() == sizeof(Z21::LanLogoff))
|
||||
{
|
||||
EventLoop::call(
|
||||
[this, endpoint=m_receiveEndpoint]()
|
||||
@ -456,7 +456,7 @@ void WLANmaus::sendTo(const z21_lan_header& msg, const boost::asio::ip::udp::end
|
||||
*/
|
||||
}
|
||||
|
||||
void WLANmaus::sendTo(const Protocol::Z21::Message& message, const boost::asio::ip::udp::endpoint& endpoint)
|
||||
void WLANmaus::sendTo(const Z21::Message& message, const boost::asio::ip::udp::endpoint& endpoint)
|
||||
{
|
||||
// TODO: add to queue, send async
|
||||
|
||||
@ -474,7 +474,7 @@ void WLANmaus::sendTo(const Protocol::Z21::Message& message, const boost::asio::
|
||||
*/
|
||||
}
|
||||
|
||||
void WLANmaus::broadcastLocoInfo(const Hardware::Decoder& decoder)
|
||||
void WLANmaus::broadcastLocoInfo(const Decoder& decoder)
|
||||
{
|
||||
const uint16_t key = locoInfoKey(decoder.address, decoder.longAddress);
|
||||
const z21_lan_x_loco_info message(decoder);
|
||||
@ -482,7 +482,7 @@ void WLANmaus::broadcastLocoInfo(const Hardware::Decoder& decoder)
|
||||
//logDebug("z21_lan_x_loco_info.speedAndDirection=" + std::to_string(message.speedAndDirection));
|
||||
|
||||
for(auto it : m_clients)
|
||||
if(it.second.broadcastFlags & Protocol::Z21::PowerLocoTurnout)
|
||||
if(it.second.broadcastFlags & Z21::PowerLocoTurnout)
|
||||
if(it.second.locoInfo.count(key))
|
||||
sendTo(message, it.first);
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
|
||||
struct z21_lan_header;
|
||||
|
||||
namespace Protocol::Z21 {
|
||||
namespace Z21 {
|
||||
enum BroadcastFlags : uint32_t;
|
||||
class Message;
|
||||
}
|
||||
@ -40,7 +40,7 @@ class WLANmaus : public Controller
|
||||
protected:
|
||||
struct Client
|
||||
{
|
||||
Protocol::Z21::BroadcastFlags broadcastFlags = static_cast<Protocol::Z21::BroadcastFlags>(0);
|
||||
Z21::BroadcastFlags broadcastFlags = static_cast<Z21::BroadcastFlags>(0);
|
||||
std::set<uint16_t> locoInfo;
|
||||
};
|
||||
|
||||
@ -48,7 +48,7 @@ class WLANmaus : public Controller
|
||||
boost::asio::ip::udp::endpoint m_receiveEndpoint;
|
||||
std::array<uint8_t,64> m_receiveBuffer;
|
||||
std::map<boost::asio::ip::udp::endpoint, Client> m_clients;
|
||||
Hardware::Decoder* m_blockLocoInfo;
|
||||
Decoder* m_blockLocoInfo;
|
||||
|
||||
constexpr uint16_t locoInfoKey(uint16_t address, bool longAddress)
|
||||
{
|
||||
@ -62,15 +62,15 @@ class WLANmaus : public Controller
|
||||
|
||||
void emergencyStopChanged(bool value) final;
|
||||
void trackPowerChanged(bool value) final;
|
||||
void decoderChanged(const Hardware::Decoder& decoder, Hardware::DecoderChangeFlags, uint32_t) final;
|
||||
void decoderChanged(const Decoder& decoder, DecoderChangeFlags, uint32_t) final;
|
||||
|
||||
void receive();
|
||||
/*[[deprecated]]*/ void sendTo(const z21_lan_header& msg, const boost::asio::ip::udp::endpoint& endpoint);
|
||||
void sendTo(const Protocol::Z21::Message& message, const boost::asio::ip::udp::endpoint& endpoint);
|
||||
void broadcastLocoInfo(const Hardware::Decoder& decoder);
|
||||
void sendTo(const Z21::Message& message, const boost::asio::ip::udp::endpoint& endpoint);
|
||||
void broadcastLocoInfo(const Decoder& decoder);
|
||||
|
||||
public:
|
||||
CLASS_ID("hardware.controller.wlanmaus")
|
||||
CLASS_ID("controller.wlanmaus")
|
||||
CREATE(WLANmaus);
|
||||
|
||||
Property<uint16_t> port;
|
||||
|
||||
@ -29,8 +29,6 @@
|
||||
#include "../../world/world.hpp"
|
||||
#include "../commandstation/commandstation.hpp"
|
||||
|
||||
namespace Hardware {
|
||||
|
||||
//constexpr uint16_t addressDCCMin = 1;
|
||||
constexpr uint16_t addressDCCShortMax = 127;
|
||||
|
||||
@ -40,7 +38,7 @@ Decoder::Decoder(const std::weak_ptr<World>& world, std::string_view _id) :
|
||||
IdObject(world, _id),
|
||||
name{this, "name", "", PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||
commandStation{this, "command_station", nullptr, PropertyFlags::ReadWrite | PropertyFlags::Store,
|
||||
[this](const std::shared_ptr<CommandStation::CommandStation>& value)
|
||||
[this](const std::shared_ptr<CommandStation>& value)
|
||||
{
|
||||
std::shared_ptr<Decoder> decoder = std::dynamic_pointer_cast<Decoder>(shared_from_this());
|
||||
assert(decoder);
|
||||
@ -184,5 +182,3 @@ void Decoder::changed(DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
if(commandStation)
|
||||
commandStation->decoderChanged(*this, changes, functionNumber);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -31,8 +31,6 @@
|
||||
#include "../../enum/direction.hpp"
|
||||
#include "decoderfunctionlist.hpp"
|
||||
|
||||
namespace Hardware {
|
||||
|
||||
enum class DecoderChangeFlags;
|
||||
class DecoderFunction;
|
||||
|
||||
@ -47,7 +45,7 @@ class Decoder : public IdObject
|
||||
void changed(DecoderChangeFlags changes, uint32_t functionNumber = 0);
|
||||
|
||||
public:
|
||||
CLASS_ID("hardware.decoder")
|
||||
CLASS_ID("decoder")
|
||||
CREATE(Decoder)
|
||||
|
||||
static const std::shared_ptr<Decoder> null;
|
||||
@ -72,6 +70,4 @@ class Decoder : public IdObject
|
||||
void setFunctionValue(uint32_t number, bool value);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -23,8 +23,6 @@
|
||||
#ifndef TRAINTASTIC_SERVER_HARDWARE_DECODER_DECODERCHANGEFLAGS_HPP
|
||||
#define TRAINTASTIC_SERVER_HARDWARE_DECODER_DECODERCHANGEFLAGS_HPP
|
||||
|
||||
namespace Hardware {
|
||||
|
||||
enum class DecoderChangeFlags
|
||||
{
|
||||
EmergencyStop = 1 << 0,
|
||||
@ -45,6 +43,4 @@ constexpr bool has(const DecoderChangeFlags& value, const DecoderChangeFlags& ma
|
||||
return (static_cast<std::underlying_type_t<DecoderChangeFlags>>(value) & static_cast<std::underlying_type_t<DecoderChangeFlags>>(mask)) != 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -23,8 +23,6 @@
|
||||
#include "decoderchangeflags.hpp"
|
||||
#include "../../world/world.hpp"
|
||||
|
||||
namespace Hardware {
|
||||
|
||||
const std::shared_ptr<DecoderFunction> DecoderFunction::null;
|
||||
|
||||
std::shared_ptr<DecoderFunction> DecoderFunction::create(Decoder& decoder, std::string_view _id)
|
||||
@ -38,8 +36,7 @@ DecoderFunction::DecoderFunction(Decoder& decoder, std::string_view _id) :
|
||||
Output(decoder.world(), _id),
|
||||
m_decoder{decoder},
|
||||
number{this, "number", 0, PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||
name{this, "name", "", PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||
momentary{this, "momentary", false, PropertyFlags::ReadWrite | PropertyFlags::Store}
|
||||
name{this, "name", "", PropertyFlags::ReadWrite | PropertyFlags::Store}
|
||||
{
|
||||
auto w = decoder.world().lock();
|
||||
const bool editable = w && contains(w->state.value(), WorldState::Edit);
|
||||
@ -48,8 +45,6 @@ DecoderFunction::DecoderFunction(Decoder& decoder, std::string_view _id) :
|
||||
.addAttributeEnabled(editable);
|
||||
m_interfaceItems.add(name)
|
||||
.addAttributeEnabled(editable);
|
||||
m_interfaceItems.add(momentary)
|
||||
.addAttributeEnabled(editable);
|
||||
}
|
||||
|
||||
void DecoderFunction::worldEvent(WorldState state, WorldEvent event)
|
||||
@ -60,7 +55,6 @@ void DecoderFunction::worldEvent(WorldState state, WorldEvent event)
|
||||
|
||||
number.setAttributeEnabled(editable);
|
||||
name.setAttributeEnabled(editable);
|
||||
momentary.setAttributeEnabled(editable);
|
||||
}
|
||||
|
||||
bool DecoderFunction::setValue(bool& value)
|
||||
@ -72,5 +66,3 @@ void DecoderFunction::valueChanged(bool)
|
||||
{
|
||||
m_decoder.changed(DecoderChangeFlags::FunctionValue, number);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,9 +25,6 @@
|
||||
|
||||
#include "../../core/output.hpp"
|
||||
#include "../../core/objectproperty.hpp"
|
||||
//#include "../commandstation/commandstation.hpp"
|
||||
|
||||
namespace Hardware {
|
||||
|
||||
class Decoder;
|
||||
|
||||
@ -44,7 +41,7 @@ class DecoderFunction : public Output
|
||||
void valueChanged(bool) final;
|
||||
|
||||
public:
|
||||
CLASS_ID("hardware.decoder_function")
|
||||
CLASS_ID("decoder_function")
|
||||
|
||||
static const std::shared_ptr<DecoderFunction> null;
|
||||
static std::shared_ptr<DecoderFunction> create(Decoder& decoder, std::string_view _id);
|
||||
@ -53,11 +50,8 @@ class DecoderFunction : public Output
|
||||
|
||||
Property<uint8_t> number;
|
||||
Property<std::string> name;
|
||||
Property<bool> momentary;
|
||||
|
||||
Decoder& decoder() { return m_decoder; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -25,9 +25,6 @@
|
||||
#include "decoder.hpp"
|
||||
#include "../../world/getworld.hpp"
|
||||
|
||||
using Hardware::Decoder;
|
||||
using Hardware::DecoderFunction;
|
||||
|
||||
DecoderFunctionList::DecoderFunctionList(Object& _parent, const std::string& parentPropertyName) :
|
||||
ObjectList<DecoderFunction>(_parent, parentPropertyName),
|
||||
add{*this, "add",
|
||||
@ -71,7 +68,7 @@ TableModelPtr DecoderFunctionList::getModel()
|
||||
|
||||
void DecoderFunctionList::worldEvent(WorldState state, WorldEvent event)
|
||||
{
|
||||
ObjectList<Hardware::DecoderFunction>::worldEvent(state, event);
|
||||
ObjectList<DecoderFunction>::worldEvent(state, event);
|
||||
|
||||
const bool editable = contains(state, WorldState::Edit);
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
#include "../../core/method.hpp"
|
||||
#include "decoderfunction.hpp"
|
||||
|
||||
class DecoderFunctionList : public ObjectList<Hardware::DecoderFunction>
|
||||
class DecoderFunctionList : public ObjectList<DecoderFunction>
|
||||
{
|
||||
protected:
|
||||
void worldEvent(WorldState state, WorldEvent event) final;
|
||||
@ -37,7 +37,7 @@ class DecoderFunctionList : public ObjectList<Hardware::DecoderFunction>
|
||||
public:
|
||||
CLASS_ID("decoder_function_list")
|
||||
|
||||
Method<std::shared_ptr<Hardware::DecoderFunction>()> add;
|
||||
Method<std::shared_ptr<DecoderFunction>()> add;
|
||||
|
||||
DecoderFunctionList(Object& _parent, const std::string& parentPropertyName);
|
||||
|
||||
|
||||
@ -23,8 +23,6 @@
|
||||
#include "decoderfunctionlisttablemodel.hpp"
|
||||
#include "decoderfunctionlist.hpp"
|
||||
|
||||
using Hardware::DecoderFunction;
|
||||
|
||||
constexpr uint32_t columnId = 0;
|
||||
constexpr uint32_t columnNumber = 1;
|
||||
constexpr uint32_t columnName = 2;
|
||||
@ -40,7 +38,10 @@ bool DecoderFunctionListTableModel::isListedProperty(const std::string& name)
|
||||
DecoderFunctionListTableModel::DecoderFunctionListTableModel(DecoderFunctionList& list) :
|
||||
ObjectListTableModel<DecoderFunction>(list)
|
||||
{
|
||||
setColumnHeaders({"hardware.decoder_function:id", "hardware.decoder_function_list:f_hash", "hardware.decoder_function:name"});
|
||||
setColumnHeaders({
|
||||
"decoder_function:id",
|
||||
"decoder_function_list:f_hash",
|
||||
"decoder_function:name"});
|
||||
}
|
||||
|
||||
std::string DecoderFunctionListTableModel::getText(uint32_t column, uint32_t row) const
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
class DecoderFunctionList;
|
||||
|
||||
class DecoderFunctionListTableModel : public ObjectListTableModel<Hardware::DecoderFunction>
|
||||
class DecoderFunctionListTableModel : public ObjectListTableModel<DecoderFunction>
|
||||
{
|
||||
friend class DecoderList;
|
||||
|
||||
|
||||
@ -25,9 +25,6 @@
|
||||
#include "../commandstation/commandstation.hpp"
|
||||
#include "../../world/getworld.hpp"
|
||||
|
||||
using Hardware::Decoder;
|
||||
using Hardware::CommandStation::CommandStation;
|
||||
|
||||
DecoderList::DecoderList(Object& _parent, const std::string& parentPropertyName) :
|
||||
ObjectList<Decoder>(_parent, parentPropertyName),
|
||||
add{*this, "add",
|
||||
@ -59,7 +56,7 @@ TableModelPtr DecoderList::getModel()
|
||||
|
||||
void DecoderList::worldEvent(WorldState state, WorldEvent event)
|
||||
{
|
||||
ObjectList<Hardware::Decoder>::worldEvent(state, event);
|
||||
ObjectList<Decoder>::worldEvent(state, event);
|
||||
|
||||
const bool editable = contains(state, WorldState::Edit);
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
#include "../../core/objectlist.hpp"
|
||||
#include "decoder.hpp"
|
||||
|
||||
class DecoderList : public ObjectList<Hardware::Decoder>
|
||||
class DecoderList : public ObjectList<Decoder>
|
||||
{
|
||||
protected:
|
||||
void worldEvent(WorldState state, WorldEvent event) final;
|
||||
@ -36,7 +36,7 @@ class DecoderList : public ObjectList<Hardware::Decoder>
|
||||
public:
|
||||
CLASS_ID("decoder_list")
|
||||
|
||||
Method<std::shared_ptr<Hardware::Decoder>()> add;
|
||||
Method<std::shared_ptr<Decoder>()> add;
|
||||
|
||||
DecoderList(Object& _parent, const std::string& parentPropertyName);
|
||||
|
||||
|
||||
@ -23,8 +23,6 @@
|
||||
#include "decoderlisttablemodel.hpp"
|
||||
#include "decoderlist.hpp"
|
||||
|
||||
using Hardware::Decoder;
|
||||
|
||||
constexpr uint32_t columnId = 0;
|
||||
constexpr uint32_t columnName = 1;
|
||||
constexpr uint32_t columnAddress = 2;
|
||||
@ -41,9 +39,9 @@ DecoderListTableModel::DecoderListTableModel(DecoderList& list) :
|
||||
ObjectListTableModel<Decoder>(list)
|
||||
{
|
||||
setColumnHeaders({
|
||||
"hardware.decoder:id",
|
||||
"hardware.decoder:name",
|
||||
"hardware.decoder:address"});
|
||||
"decoder:id",
|
||||
"decoder:name",
|
||||
"decoder:address"});
|
||||
}
|
||||
|
||||
std::string DecoderListTableModel::getText(uint32_t column, uint32_t row) const
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
class DecoderList;
|
||||
|
||||
class DecoderListTableModel : public ObjectListTableModel<Hardware::Decoder>
|
||||
class DecoderListTableModel : public ObjectListTableModel<Decoder>
|
||||
{
|
||||
friend class DecoderList;
|
||||
|
||||
|
||||
@ -22,12 +22,10 @@
|
||||
|
||||
#include "loconetinput.hpp"
|
||||
|
||||
using namespace Protocol::LocoNet;
|
||||
|
||||
LocoNetInput::LocoNetInput(const std::weak_ptr<World> world, std::string_view _id) :
|
||||
Input(world, _id),
|
||||
loconet{this, "loconet", nullptr, PropertyFlags::ReadWrite | PropertyFlags::Store,
|
||||
[this](const std::shared_ptr<LocoNet>& value)
|
||||
[this](const std::shared_ptr<LocoNet::LocoNet>& value)
|
||||
{
|
||||
if(!value || value->addInput(shared_ptr<LocoNetInput>()))
|
||||
{
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
class LocoNetInput : public Input
|
||||
{
|
||||
friend class Protocol::LocoNet::LocoNet;
|
||||
friend class LocoNet::LocoNet;
|
||||
|
||||
protected:
|
||||
void worldEvent(WorldState state, WorldEvent event) final;
|
||||
@ -40,7 +40,7 @@ class LocoNetInput : public Input
|
||||
CLASS_ID("input.loconet")
|
||||
CREATE(LocoNetInput)
|
||||
|
||||
ObjectProperty<Protocol::LocoNet::LocoNet> loconet;
|
||||
ObjectProperty<LocoNet::LocoNet> loconet;
|
||||
Property<uint16_t> address;
|
||||
|
||||
LocoNetInput(const std::weak_ptr<World> world, std::string_view _id);
|
||||
|
||||
@ -28,9 +28,9 @@
|
||||
#include "../../commandstation/commandstation.hpp"
|
||||
#include "../../input/loconetinput.hpp"
|
||||
|
||||
namespace Protocol::LocoNet {
|
||||
namespace LocoNet {
|
||||
|
||||
void updateDecoderSpeed(const std::shared_ptr<Hardware::Decoder>& decoder, uint8_t speed)
|
||||
void updateDecoderSpeed(const std::shared_ptr<Decoder>& decoder, uint8_t speed)
|
||||
{
|
||||
decoder->emergencyStop.setValueInternal(speed == SPEED_ESTOP);
|
||||
|
||||
@ -42,7 +42,7 @@ void updateDecoderSpeed(const std::shared_ptr<Hardware::Decoder>& decoder, uint8
|
||||
|
||||
LocoNet::LocoNet(Object& _parent, const std::string& parentPropertyName, std::function<bool(const Message&)> send) :
|
||||
SubObject(_parent, parentPropertyName),
|
||||
m_commandStation{dynamic_cast<Hardware::CommandStation::CommandStation*>(&_parent)},
|
||||
m_commandStation{dynamic_cast<CommandStation*>(&_parent)},
|
||||
m_send{std::move(send)},
|
||||
m_debugLog{true/*false*/},
|
||||
m_queryLocoSlots{SLOT_UNKNOWN},
|
||||
@ -265,10 +265,8 @@ void LocoNet::trackVoltageOffChanged(bool value)
|
||||
send(GlobalPowerOff());
|
||||
}
|
||||
|
||||
void LocoNet::decoderChanged(const Hardware::Decoder& decoder, Hardware::DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
void LocoNet::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
{
|
||||
using namespace Hardware;
|
||||
|
||||
logDebug("LocoNet::decoderChanged");
|
||||
|
||||
if(has(changes, DecoderChangeFlags::EmergencyStop | DecoderChangeFlags::SpeedStep))
|
||||
@ -350,7 +348,7 @@ void LocoNet::queryLocoSlots()
|
||||
send(RequestSlotData(m_queryLocoSlots));
|
||||
}
|
||||
|
||||
std::shared_ptr<Hardware::Decoder> LocoNet::getDecoder(uint8_t slot, bool request)
|
||||
std::shared_ptr<Decoder> LocoNet::getDecoder(uint8_t slot, bool request)
|
||||
{
|
||||
if(slot < SLOT_LOCO_MIN || slot > SLOT_LOCO_MAX)
|
||||
return nullptr;
|
||||
|
||||
@ -39,16 +39,11 @@
|
||||
#include "../../../hardware/decoder/decoderchangeflags.hpp"
|
||||
#include "messages.hpp"
|
||||
|
||||
namespace Hardware {
|
||||
namespace CommandStation {
|
||||
class CommandStation;
|
||||
}
|
||||
class Decoder;
|
||||
}
|
||||
|
||||
class LocoNetInput;
|
||||
|
||||
namespace Protocol::LocoNet {
|
||||
namespace LocoNet {
|
||||
|
||||
class LocoNet : public SubObject
|
||||
{
|
||||
@ -95,7 +90,7 @@ class LocoNet : public SubObject
|
||||
}
|
||||
};
|
||||
|
||||
Hardware::CommandStation::CommandStation* m_commandStation; // valid if parent is command station, else nullptr
|
||||
CommandStation* m_commandStation; // valid if parent is command station, else nullptr
|
||||
std::function<bool(const Message&)> m_send;
|
||||
std::atomic_bool m_debugLog;
|
||||
Slots m_slots;
|
||||
@ -103,7 +98,7 @@ class LocoNet : public SubObject
|
||||
uint8_t m_queryLocoSlots;
|
||||
std::unordered_map<uint16_t, std::shared_ptr<LocoNetInput>> m_inputs;
|
||||
|
||||
std::shared_ptr<Hardware::Decoder> getDecoder(uint8_t slot, bool request = true);
|
||||
std::shared_ptr<Decoder> getDecoder(uint8_t slot, bool request = true);
|
||||
|
||||
void send(uint16_t address, Message& message, uint8_t& slot);
|
||||
template<typename T>
|
||||
@ -130,7 +125,7 @@ class LocoNet : public SubObject
|
||||
|
||||
void emergencyStopChanged(bool value);
|
||||
void trackVoltageOffChanged(bool value);
|
||||
void decoderChanged(const Hardware::Decoder& decoder, Hardware::DecoderChangeFlags changes, uint32_t functionNumber);
|
||||
void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber);
|
||||
|
||||
void queryLocoSlots();
|
||||
};
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
#include "messages.hpp"
|
||||
#include "../../../utils/to_hex.hpp"
|
||||
|
||||
namespace Protocol::LocoNet {
|
||||
namespace LocoNet {
|
||||
|
||||
uint8_t calcChecksum(const Message& message)
|
||||
{
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
#include <traintastic/enum/direction.hpp>
|
||||
#include "opcode.hpp"
|
||||
|
||||
namespace Protocol::LocoNet {
|
||||
namespace LocoNet {
|
||||
|
||||
struct Message;
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
namespace Protocol::LocoNet {
|
||||
namespace LocoNet {
|
||||
|
||||
enum OpCode : uint8_t
|
||||
{
|
||||
|
||||
@ -24,8 +24,6 @@
|
||||
#include "../../core/traintastic.hpp"
|
||||
#include "../decoder/decoder.hpp"
|
||||
|
||||
namespace Protocol {
|
||||
|
||||
uint8_t XpressNet::calcChecksum(const void* msg)
|
||||
{
|
||||
assert(msg);
|
||||
@ -103,10 +101,8 @@ void XpressNet::worldEvent(WorldState state, WorldEvent event)
|
||||
useRocoF13F20Command.setAttributeEnabled(editable);
|
||||
}
|
||||
|
||||
void XpressNet::decoderChanged(const Hardware::Decoder& decoder, Hardware::DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
void XpressNet::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
{
|
||||
using namespace Hardware;
|
||||
|
||||
logDebug("XpressNet::decoderChanged");
|
||||
|
||||
if(useEmergencyStopLocomotiveCommand && changes == DecoderChangeFlags::EmergencyStop && decoder.emergencyStop)
|
||||
@ -203,5 +199,3 @@ void XpressNet::decoderChanged(const Hardware::Decoder& decoder, Hardware::Decod
|
||||
logWarning("Function F" + std::to_string(functionNumber) + " not supported");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -29,11 +29,7 @@
|
||||
#include "../../enum/xpressnetcommandstation.hpp"
|
||||
#include "../../hardware/decoder/decoderchangeflags.hpp"
|
||||
|
||||
namespace Hardware {
|
||||
class Decoder;
|
||||
}
|
||||
|
||||
namespace Protocol {
|
||||
|
||||
class XpressNet : public SubObject
|
||||
{
|
||||
@ -331,7 +327,7 @@ class XpressNet : public SubObject
|
||||
};
|
||||
|
||||
protected:
|
||||
static bool getFunctionValue(const Hardware::Decoder& decoder, uint32_t number);
|
||||
static bool getFunctionValue(const Decoder& decoder, uint32_t number);
|
||||
|
||||
std::function<bool(const Message&)> m_send;
|
||||
|
||||
@ -350,9 +346,7 @@ class XpressNet : public SubObject
|
||||
bool send(const Message& msg) { return m_send(msg); }
|
||||
void receive(const Message& msg);
|
||||
|
||||
void decoderChanged(const Hardware::Decoder& decoder, Hardware::DecoderChangeFlags changes, uint32_t functionNumber);
|
||||
void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -23,9 +23,9 @@
|
||||
#include "z21.hpp"
|
||||
#include "../decoder/decoder.hpp"
|
||||
|
||||
//namespace Protocol::Z21 {
|
||||
//namespace Z21 {
|
||||
|
||||
z21_lan_x_loco_info::z21_lan_x_loco_info(const Hardware::Decoder& decoder) :
|
||||
z21_lan_x_loco_info::z21_lan_x_loco_info(const Decoder& decoder) :
|
||||
z21_lan_x_loco_info()
|
||||
{
|
||||
setAddress(decoder.address, decoder.longAddress);
|
||||
|
||||
@ -30,11 +30,9 @@
|
||||
#include "../../utils/endian.hpp"
|
||||
#include "../../utils/packed.hpp"
|
||||
|
||||
namespace Hardware {
|
||||
class Decoder;
|
||||
}
|
||||
|
||||
namespace Protocol::Z21 {
|
||||
namespace Z21 {
|
||||
|
||||
namespace Utils {
|
||||
|
||||
@ -421,7 +419,7 @@ struct z21_lan_get_hwinfo_reply : z21_lan_header
|
||||
|
||||
z21_lan_get_hwinfo_reply(uint32_t _hardwareType = 0, uint8_t _firmwareVersionMajor = 0, uint8_t _firmwareVersionMinor = 0) :
|
||||
hardwareType{host_to_le(_hardwareType)},
|
||||
firmwareVersion{host_to_le(static_cast<uint32_t>(Protocol::Z21::Utils::toBCD(_firmwareVersionMajor)) << 8 | Protocol::Z21::Utils::toBCD(_firmwareVersionMinor))}
|
||||
firmwareVersion{host_to_le(static_cast<uint32_t>(Z21::Utils::toBCD(_firmwareVersionMajor)) << 8 | Z21::Utils::toBCD(_firmwareVersionMinor))}
|
||||
{
|
||||
dataLen = sizeof(z21_lan_get_hwinfo_reply);
|
||||
header = Z21_LAN_GET_HWINFO;
|
||||
@ -502,24 +500,24 @@ struct z21_lan_x_get_firmware_version_reply : z21_lan_x
|
||||
|
||||
inline uint8_t versionMajor() const
|
||||
{
|
||||
return Protocol::Z21::Utils::fromBCD(majorBCD);
|
||||
return Z21::Utils::fromBCD(majorBCD);
|
||||
}
|
||||
|
||||
inline uint8_t versionMinor() const
|
||||
{
|
||||
return Protocol::Z21::Utils::fromBCD(minorBCD);
|
||||
return Z21::Utils::fromBCD(minorBCD);
|
||||
}
|
||||
|
||||
inline void setVersionMajor(uint8_t value)
|
||||
{
|
||||
assert(value < 100);
|
||||
majorBCD = Protocol::Z21::Utils::toBCD(value);
|
||||
majorBCD = Z21::Utils::toBCD(value);
|
||||
}
|
||||
|
||||
inline void setVersionMinor(uint8_t value)
|
||||
{
|
||||
assert(value < 100);
|
||||
minorBCD = Protocol::Z21::Utils::toBCD(value);
|
||||
minorBCD = Z21::Utils::toBCD(value);
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(z21_lan_x_get_firmware_version_reply) == 9);
|
||||
@ -709,7 +707,7 @@ struct z21_lan_x_loco_info : z21_lan_x
|
||||
xheader = 0xEF;
|
||||
}
|
||||
|
||||
z21_lan_x_loco_info(const Hardware::Decoder& decoder);
|
||||
z21_lan_x_loco_info(const Decoder& decoder);
|
||||
|
||||
inline uint16_t address() const
|
||||
{
|
||||
@ -764,32 +762,32 @@ struct z21_lan_x_loco_info : z21_lan_x
|
||||
|
||||
inline Direction direction() const
|
||||
{
|
||||
return Protocol::Z21::Utils::getDirection(speedAndDirection);
|
||||
return Z21::Utils::getDirection(speedAndDirection);
|
||||
}
|
||||
|
||||
inline void setDirection(Direction value)
|
||||
{
|
||||
Protocol::Z21::Utils::setDirection(speedAndDirection, value);
|
||||
Z21::Utils::setDirection(speedAndDirection, value);
|
||||
}
|
||||
|
||||
inline bool isEmergencyStop() const
|
||||
{
|
||||
return Protocol::Z21::Utils::isEmergencyStop(speedAndDirection, speedSteps());
|
||||
return Z21::Utils::isEmergencyStop(speedAndDirection, speedSteps());
|
||||
}
|
||||
|
||||
inline void setEmergencyStop()
|
||||
{
|
||||
Protocol::Z21::Utils::setEmergencyStop(speedAndDirection);
|
||||
Z21::Utils::setEmergencyStop(speedAndDirection);
|
||||
}
|
||||
|
||||
inline uint8_t speedStep() const
|
||||
{
|
||||
return Protocol::Z21::Utils::getSpeedStep(speedAndDirection, speedSteps());
|
||||
return Z21::Utils::getSpeedStep(speedAndDirection, speedSteps());
|
||||
}
|
||||
|
||||
inline void setSpeedStep(uint8_t value)
|
||||
{
|
||||
Protocol::Z21::Utils::setSpeedStep(speedAndDirection, speedSteps(), value);
|
||||
Z21::Utils::setSpeedStep(speedAndDirection, speedSteps(), value);
|
||||
}
|
||||
|
||||
bool getFunction(uint8_t index)
|
||||
@ -893,32 +891,32 @@ struct z21_lan_x_set_loco_drive : z21_lan_header
|
||||
|
||||
inline Direction direction() const
|
||||
{
|
||||
return Protocol::Z21::Utils::getDirection(speedAndDirection);
|
||||
return Z21::Utils::getDirection(speedAndDirection);
|
||||
}
|
||||
|
||||
inline void setDirection(Direction value)
|
||||
{
|
||||
Protocol::Z21::Utils::setDirection(speedAndDirection, value);
|
||||
Z21::Utils::setDirection(speedAndDirection, value);
|
||||
}
|
||||
|
||||
inline bool isEmergencyStop() const
|
||||
{
|
||||
return Protocol::Z21::Utils::isEmergencyStop(speedAndDirection, speedSteps());
|
||||
return Z21::Utils::isEmergencyStop(speedAndDirection, speedSteps());
|
||||
}
|
||||
|
||||
inline void setEmergencyStop()
|
||||
{
|
||||
Protocol::Z21::Utils::setEmergencyStop(speedAndDirection);
|
||||
Z21::Utils::setEmergencyStop(speedAndDirection);
|
||||
}
|
||||
|
||||
inline uint8_t speedStep() const
|
||||
{
|
||||
return Protocol::Z21::Utils::getSpeedStep(speedAndDirection, speedSteps());
|
||||
return Z21::Utils::getSpeedStep(speedAndDirection, speedSteps());
|
||||
}
|
||||
|
||||
inline void setSpeedStep(uint8_t value)
|
||||
{
|
||||
Protocol::Z21::Utils::setSpeedStep(speedAndDirection, speedSteps(), value);
|
||||
Z21::Utils::setSpeedStep(speedAndDirection, speedSteps(), value);
|
||||
}
|
||||
} ATTRIBUTE_PACKED;
|
||||
static_assert(sizeof(z21_lan_x_set_loco_drive) == 0x0a);
|
||||
@ -974,7 +972,7 @@ static_assert(sizeof(z21_lan_systemstate_getdata) == 0x04);
|
||||
|
||||
struct z21_lan_set_broadcastflags : z21_lan_header
|
||||
{
|
||||
Protocol::Z21::BroadcastFlags broadcastFlags; // LE
|
||||
Z21::BroadcastFlags broadcastFlags; // LE
|
||||
|
||||
z21_lan_set_broadcastflags(uint32_t _broadcastFlags = 0) :
|
||||
broadcastFlags{_broadcastFlags}
|
||||
@ -1028,7 +1026,7 @@ inline bool operator ==(const z21_lan_header& lhs, const z21_lan_header& rhs)
|
||||
|
||||
|
||||
|
||||
inline bool operator ==(const Protocol::Z21::Message& lhs, const Protocol::Z21::Message& rhs)
|
||||
inline bool operator ==(const Z21::Message& lhs, const Z21::Message& rhs)
|
||||
{
|
||||
return lhs.dataLen() == rhs.dataLen() && std::memcmp(&lhs, &rhs, lhs.dataLen()) == 0;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ class RailVehicle : public Vehicle
|
||||
void addToWorld() override;
|
||||
|
||||
public:
|
||||
ObjectProperty<Hardware::Decoder> decoder;
|
||||
ObjectProperty<Decoder> decoder;
|
||||
LengthProperty lob;
|
||||
WeightProperty weight;
|
||||
|
||||
|
||||
@ -205,7 +205,7 @@ void World::load()
|
||||
std::weak_ptr<World> w = shared_ptr<World>();
|
||||
|
||||
#if 0
|
||||
auto cs = Hardware::CommandStation::Z21::create(w, "cs1");
|
||||
auto cs = Z21::create(w, "cs1");
|
||||
//cs->hostname = "192.168.1.2";
|
||||
cs->hostname = "192.168.16.254";
|
||||
/ *
|
||||
@ -220,10 +220,10 @@ void World::load()
|
||||
|
||||
#else
|
||||
#if 1
|
||||
auto cs = Hardware::CommandStation::LI10x::create(w, "cs1");
|
||||
auto cs = LI10x::create(w, "cs1");
|
||||
cs->port = "/dev/ttyUSB0";
|
||||
#else
|
||||
auto cs = Hardware::CommandStation::USBXpressNetInterface::create(w, "cs1");
|
||||
auto cs = USBXpressNetInterface::create(w, "cs1");
|
||||
#endif
|
||||
cs->xpressnet->commandStation = XpressNetCommandStation::Roco10764;
|
||||
#endif
|
||||
@ -231,7 +231,7 @@ void World::load()
|
||||
|
||||
|
||||
{
|
||||
auto dec = Hardware::Decoder::create(w, "dec_acts6701");
|
||||
auto dec = Decoder::create(w, "dec_acts6701");
|
||||
dec->name = "ACTS 6701";
|
||||
dec->commandStation = cs;
|
||||
dec->protocol = DecoderProtocol::DCC;
|
||||
@ -239,7 +239,7 @@ void World::load()
|
||||
dec->speedSteps = 126;
|
||||
}
|
||||
{
|
||||
auto dec = Hardware::Decoder::create(w, "dec_acts6703");
|
||||
auto dec = Decoder::create(w, "dec_acts6703");
|
||||
dec->name = "ACTS 6703";
|
||||
dec->commandStation = cs;
|
||||
dec->protocol = DecoderProtocol::DCC;
|
||||
@ -247,7 +247,7 @@ void World::load()
|
||||
dec->speedSteps = 126;
|
||||
}
|
||||
{
|
||||
auto dec = Hardware::Decoder::create(w, "dec_acts6705");
|
||||
auto dec = Decoder::create(w, "dec_acts6705");
|
||||
dec->name = "ACTS 6705";
|
||||
dec->commandStation = cs;
|
||||
dec->protocol = DecoderProtocol::DCC;
|
||||
@ -255,7 +255,7 @@ void World::load()
|
||||
dec->speedSteps = 126;
|
||||
}
|
||||
{
|
||||
auto dec = Hardware::Decoder::create(w, "dec_g2000");
|
||||
auto dec = Decoder::create(w, "dec_g2000");
|
||||
dec->name = "G2000";
|
||||
dec->commandStation = cs;
|
||||
dec->protocol = DecoderProtocol::DCC;
|
||||
@ -264,14 +264,14 @@ void World::load()
|
||||
dec->speedSteps = 126;
|
||||
/ *
|
||||
{
|
||||
auto f = Hardware::DecoderFunction::create(*dec, "dec_g2000_f0");
|
||||
auto f = DecoderFunction::create(*dec, "dec_g2000_f0");
|
||||
f->number = 0;
|
||||
dec->functions->add(f);
|
||||
f->m_decoder = dec.get();
|
||||
}
|
||||
|
||||
{
|
||||
auto f = Hardware::DecoderFunction::create(*dec, "dec_g2000_f2");
|
||||
auto f = DecoderFunction::create(*dec, "dec_g2000_f2");
|
||||
f->number = 2;
|
||||
f->momentary = true;
|
||||
dec->functions->add(f);
|
||||
@ -279,7 +279,7 @@ void World::load()
|
||||
}* /
|
||||
}
|
||||
{
|
||||
auto dec = Hardware::Decoder::create(w, "dec_br211");
|
||||
auto dec = Decoder::create(w, "dec_br211");
|
||||
dec->name = "BR211";
|
||||
dec->commandStation = cs;
|
||||
dec->protocol = DecoderProtocol::DCC;
|
||||
@ -344,7 +344,7 @@ void World::load()
|
||||
#endif
|
||||
|
||||
{
|
||||
auto z21app = Hardware::Controller::Z21App::create(w, "z21app");
|
||||
auto z21app = Controller::Z21App::create(w, "z21app");
|
||||
z21app->commandStation = cs;
|
||||
z21app->active = true;
|
||||
controllers->addObject(z21app);
|
||||
@ -365,7 +365,7 @@ json World::saveObject(const ObjectPtr& object)
|
||||
|
||||
objectData["class_id"] = object->getClassId();
|
||||
|
||||
if(Hardware::DecoderFunction* function = dynamic_cast<Hardware::DecoderFunction*>(object.get()))
|
||||
if(DecoderFunction* function = dynamic_cast<DecoderFunction*>(object.get()))
|
||||
objectData["decoder"] = function->decoder().id.toJSON();
|
||||
|
||||
for(auto& item : object->interfaceItems())
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
#include "world.hpp"
|
||||
#include "../utils/string.hpp"
|
||||
|
||||
#include "../hardware/commandstation/create.hpp"
|
||||
#include "../hardware/commandstation/commandstations.hpp"
|
||||
#include "../hardware/controller/controllers.hpp"
|
||||
#include "../hardware/decoder/decoder.hpp"
|
||||
#include "../hardware/decoder/decoderfunction.hpp"
|
||||
@ -88,17 +88,17 @@ void WorldLoader::createObject(ObjectData& objectData)
|
||||
std::string_view classId = objectData.json["class_id"];
|
||||
std::string_view id = objectData.json["id"];
|
||||
|
||||
if(startsWith(classId, Hardware::CommandStation::classIdPrefix))
|
||||
objectData.object = Hardware::CommandStation::create(m_world, classId, id);
|
||||
if(startsWith(classId, CommandStations::classIdPrefix))
|
||||
objectData.object = CommandStations::create(m_world, classId, id);
|
||||
else if(startsWith(classId, Controllers::classIdPrefix))
|
||||
objectData.object = Controllers::create(m_world, classId, id);
|
||||
else if(classId == Hardware::Decoder::classId)
|
||||
objectData.object = Hardware::Decoder::create(m_world, id);
|
||||
else if(classId == Hardware::DecoderFunction::classId)
|
||||
else if(classId == Decoder::classId)
|
||||
objectData.object = Decoder::create(m_world, id);
|
||||
else if(classId == DecoderFunction::classId)
|
||||
{
|
||||
const std::string_view decoderId = objectData.json["decoder"];
|
||||
if(std::shared_ptr<Hardware::Decoder> decoder = std::dynamic_pointer_cast<Hardware::Decoder>(getObject(decoderId)))
|
||||
objectData.object = Hardware::DecoderFunction::create(*decoder, id);
|
||||
if(std::shared_ptr<Decoder> decoder = std::dynamic_pointer_cast<Decoder>(getObject(decoderId)))
|
||||
objectData.object = DecoderFunction::create(*decoder, id);
|
||||
}
|
||||
else if(startsWith(classId, RailVehicles::classIdPrefix))
|
||||
objectData.object = RailVehicles::create(m_world, classId, id);
|
||||
|
||||
@ -72,7 +72,7 @@ json WorldSaver::saveObject(const ObjectPtr& object)
|
||||
assert(false);
|
||||
objectData["objects"] = objects;
|
||||
}
|
||||
else if(Hardware::DecoderFunction* function = dynamic_cast<Hardware::DecoderFunction*>(object.get()))
|
||||
else if(DecoderFunction* function = dynamic_cast<DecoderFunction*>(object.get()))
|
||||
objectData["decoder"] = function->decoder().id.toJSON();
|
||||
|
||||
for(auto& item : object->interfaceItems())
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren