added usb xpressnet controller base

Dieser Commit ist enthalten in:
Reinder Feenstra 2020-09-29 23:19:31 +02:00
Ursprung cf0a0cc65d
Commit 98d662fdf6
9 geänderte Dateien mit 244 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -69,8 +69,8 @@ else()
message(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
#set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
target_link_libraries(traintastic-server pthread stdc++fs)
endif()
@ -89,8 +89,8 @@ else()
add_definitions(-DDISABLE_LUA_SCRIPTING)
endif()
option(ENABLE_USB_XPRESSNET_INTERFACE "USB XpressNet interface support" ON)
message(STATUS "USB XpressNet interface support: ${ENABLE_USB_XPRESSNET_INTERFACE}")
option(USB_XPRESSNET "USB XpressNet interface/controller support" ON)
message(STATUS "USB XpressNet interface/controller support: ${USB_XPRESSNET}")
if(ENABLE_USB_XPRESSNET_INTERFACE)
#pkg_check_modules(USBXPRESSNET REQUIRED IMPORTED_TARGET usbxpressnet)
find_path(USBXPRESSNET_INCLUDE_DIR usbxpressnet.h)
@ -101,11 +101,11 @@ if(ENABLE_USB_XPRESSNET_INTERFACE)
# message(FATAL_ERROR "usbxpressnet library not found")
#endif()
add_definitions(-DUSB_XPRESSNET)
target_include_directories(traintastic-server PRIVATE ${USBXPRESSNET_INCLUDE_DIR})
target_link_libraries(traintastic-server ${USBXPRESSNET_LIB})
else()
add_definitions(-DDISABLE_USB_XPRESSNET_INTERFACE)
list(FILTER SOURCES EXCLUDE REGEX ".*usbxpressnetinterface\.(hpp|cpp)$")
list(FILTER SOURCES EXCLUDE REGEX ".*usbxpressnet(interface|controller)\.(hpp|cpp)$")
endif()
### OPTIONS END ###

Datei anzeigen

@ -0,0 +1,33 @@
/**
* server/src/enum/usbxpressnetcontrollermode.hpp
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2019-2020 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_ENUM_USBXPRESSNETCONTROLLERMODE_HPP
#define TRAINTASTIC_SERVER_ENUM_USBXPRESSNETCONTROLLERMODE_HPP
#include <traintastic/enum/usbxpressnetcontrollermode.hpp>
inline constexpr std::array<USBXpressNetControllerMode, 2> USBXpressNetControllerModeValues{{
USBXpressNetControllerMode::Direct,
USBXpressNetControllerMode::Virtual,
}};
#endif

Datei anzeigen

@ -26,7 +26,7 @@ std::shared_ptr<CommandStation> CommandStations::create(const std::weak_ptr<Worl
{
if(classId == LocoNetSerial::classId)
return LocoNetSerial::create(world, id);
#ifndef DISABLE_USB_XPRESSNET_INTERFACE
#ifdef USB_XPRESSNET
else if(classId == USBXpressNetInterface::classId)
return USBXpressNetInterface::create(world, id);
#endif

Datei anzeigen

@ -27,7 +27,7 @@
#include "../../utils/makearray.hpp"
#include "loconetserial.hpp"
#ifndef DISABLE_USB_XPRESSNET_INTERFACE
#ifdef USB_XPRESSNET
#include "usbxpressnetinterface.hpp"
#endif
#include "xpressnetserial.hpp"
@ -40,7 +40,7 @@ struct CommandStations
static constexpr auto classList = makeArray(
LocoNetSerial::classId,
#ifndef DISABLE_USB_XPRESSNET_INTERFACE
#ifdef USB_XPRESSNET
USBXpressNetInterface::classId,
#endif
XpressNetSerial::classId,

Datei anzeigen

@ -26,6 +26,10 @@ std::shared_ptr<Controller> Controllers::create(const std::weak_ptr<World>& worl
{
if(classId == WLANmaus::classId)
return WLANmaus::create(world, id);
#ifdef USB_XPRESSNET
else if(classId == USBXpressNetController::classId)
return USBXpressNetController::create(world, id);
#endif
else
return std::shared_ptr<Controller>();
}

Datei anzeigen

@ -27,12 +27,18 @@
#include "../../utils/makearray.hpp"
#include "wlanmaus.hpp"
#ifdef USB_XPRESSNET
#include "usbxpressnetcontroller.hpp"
#endif
struct Controllers
{
static constexpr std::string_view classIdPrefix = "controller.";
static constexpr auto classList = makeArray(
#ifdef USB_XPRESSNET
USBXpressNetController::classId,
#endif
WLANmaus::classId
);

Datei anzeigen

@ -0,0 +1,96 @@
/**
* server/src/hardware/controller/usbxpressnetcontroller.cpp
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2019-2020 Reinder Feenstra <reinderfeenstra@gmail.com>
*
* 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 "usbxpressnetcontroller.hpp"
#include "../../core/traintastic.hpp"
#include "../../world/world.hpp"
#include "../../core/attributes.hpp"
USBXpressNetController::USBXpressNetController(const std::weak_ptr<World>& world, std::string_view _id) :
Controller(world, _id),
m_handle{nullptr},
serial{this, "serial", "", PropertyFlags::ReadWrite | PropertyFlags::Store},
mode{this, "mode", USBXpressNetControllerMode::Direct, PropertyFlags::ReadWrite | PropertyFlags::Store}
{
name = "USB XpressNet controller";
m_interfaceItems.insertBefore(serial, notes);
Attributes::addValues(mode, USBXpressNetControllerModeValues);
m_interfaceItems.insertBefore(mode, notes);
usbxpressnet_init();
}
USBXpressNetController::~USBXpressNetController()
{
if(m_handle)
{
usbxpressnet_reset(m_handle);
usbxpressnet_close(m_handle);
}
usbxpressnet_fini();
}
bool USBXpressNetController::setActive(bool& value)
{
if(!m_handle && value)
{
usbxpressnet_status status = usbxpressnet_open(!serial.value().empty() ? serial.value().c_str() : nullptr, &m_handle);
if(status != USBXPRESSNET_STATUS_SUCCESS)
{
logError(std::string("usbxpressnet_open: ") + usbxpressnet_status_str(status));
return false;
}
status = usbxpressnet_reset(m_handle);
if(status != USBXPRESSNET_STATUS_SUCCESS)
{
logError(std::string("usbxpressnet_reset: ") + usbxpressnet_status_str(status));
return false;
}
status = usbxpressnet_set_mode(m_handle, USBXPRESSNET_MODE_STATION, 0);
if(status != USBXPRESSNET_STATUS_SUCCESS)
{
logError(std::string("usbxpressnet_set_mode: ") + usbxpressnet_status_str(status));
return false;
}
}
else if(m_handle && !value)
{
usbxpressnet_close(m_handle);
m_handle = nullptr;
}
return true;
}
void USBXpressNetController::emergencyStopChanged(bool value)
{
}
void USBXpressNetController::trackPowerChanged(bool value)
{
}
void USBXpressNetController::decoderChanged(const Decoder& decoder, DecoderChangeFlags, uint32_t)
{
}

Datei anzeigen

@ -0,0 +1,52 @@
/**
* server/src/hardware/controller/usbxpressnetcontroller.hpp
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2019-2020 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_CONTROLLER_USBXPRESSNETCONTROLLER_HPP
#define TRAINTASTIC_SERVER_HARDWARE_CONTROLLER_USBXPRESSNETCONTROLLER_HPP
#include "controller.hpp"
#include <usbxpressnet.h>
#include "../../enum/usbxpressnetcontrollermode.hpp"
class USBXpressNetController : public Controller
{
protected:
usbxpressnet_handle m_handle;
bool setActive(bool& value) final;
void emergencyStopChanged(bool value) final;
void trackPowerChanged(bool value) final;
void decoderChanged(const Decoder& decoder, DecoderChangeFlags, uint32_t) final;
public:
CLASS_ID("controller.usb_xpressnet_controller")
CREATE(USBXpressNetController)
Property<std::string> serial;
Property<USBXpressNetControllerMode> mode;
USBXpressNetController(const std::weak_ptr<World>& world, std::string_view _id);
~USBXpressNetController() final;
};
#endif

Datei anzeigen

@ -0,0 +1,44 @@
/**
* shared/src/enum/usbxpressnetcontrollermode.hpp
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2019-2020 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_SHARED_TRAINTASTIC_ENUM_USBXPRESSNETCONROLLERMODE_HPP
#define TRAINTASTIC_SHARED_TRAINTASTIC_ENUM_USBXPRESSNETCONROLLERMODE_HPP
#include <cstdint>
#include "enum.hpp"
#include <frozen/map.h>
enum class USBXpressNetControllerMode : uint8_t
{
Direct = 0,
Virtual = 1,
};
ENUM_NAME(USBXpressNetControllerMode, "usb_xpressnet_controller_mode")
ENUM_VALUES(USBXpressNetControllerMode, 2,
{
{USBXpressNetControllerMode::Direct, "direct"},
{USBXpressNetControllerMode::Virtual, "virtual"},
})
#endif