loconet: added settings
- echo timeout - response timeout - locomotive slots
Dieser Commit ist enthalten in:
Ursprung
0995c879da
Commit
914157cc47
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* server/src/enum/loconetcommandstation.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_LOCONETCOMMANDSTATION_HPP
|
||||
#define TRAINTASTIC_SERVER_ENUM_LOCONETCOMMANDSTATION_HPP
|
||||
|
||||
#include <traintastic/enum/loconetcommandstation.hpp>
|
||||
#include <array>
|
||||
|
||||
inline constexpr std::array<LocoNetCommandStation, 3> LocoNetCommandStationValues{{
|
||||
LocoNetCommandStation::Custom,
|
||||
LocoNetCommandStation::DigikeijsDR5000,
|
||||
LocoNetCommandStation::UhlenbrockIntellibox,
|
||||
}};
|
||||
|
||||
#endif
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2021 Reinder Feenstra
|
||||
* Copyright (C) 2021-2022 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -23,14 +23,19 @@
|
||||
#ifndef TRAINTASTIC_SERVER_HARDWARE_PROTOCOL_LOCONET_CONFIG_HPP
|
||||
#define TRAINTASTIC_SERVER_HARDWARE_PROTOCOL_LOCONET_CONFIG_HPP
|
||||
|
||||
#include "../../../enum/loconetcommandstation.hpp"
|
||||
#include <traintastic/enum/loconetcommandstation.hpp>
|
||||
|
||||
namespace LocoNet {
|
||||
|
||||
struct Config
|
||||
{
|
||||
static constexpr uint16_t echoTimeout = 500; //!< Wait for echo timeout in milliseconds
|
||||
static constexpr uint16_t responseTimeout = 500; //!< Wait for response timeout in milliseconds
|
||||
static constexpr uint16_t timeoutMin = 100; //!< Minimum timeout in milliseconds
|
||||
static constexpr uint16_t timeoutMax = 10000; //!< Maximum timeout in milliseconds
|
||||
|
||||
uint16_t echoTimeout; //!< Wait for echo timeout in milliseconds
|
||||
uint16_t responseTimeout; //!< Wait for response timeout in milliseconds
|
||||
|
||||
uint8_t locomotiveSlots; //!< Number of available locomotive slots, defaults to #SLOT_LOCO_MAX
|
||||
|
||||
bool fastClockSyncEnabled;
|
||||
uint8_t fastClockSyncInterval; //!< Fast clock sync interval in seconds
|
||||
|
||||
@ -161,7 +161,7 @@ void Kernel::start()
|
||||
if(m_config.fastClockSyncEnabled)
|
||||
startFastClockSyncTimer();
|
||||
|
||||
for(uint8_t slot = SLOT_LOCO_MIN; slot <= SLOT_LOCO_MAX; slot++)
|
||||
for(uint8_t slot = SLOT_LOCO_MIN; slot <= m_config.locomotiveSlots; slot++)
|
||||
send(RequestSlotData(slot), LowPriority);
|
||||
|
||||
if(m_onStarted)
|
||||
@ -1014,13 +1014,13 @@ void Kernel::sendNextMessage()
|
||||
m_sentMessagePriority = static_cast<Priority>(priority);
|
||||
|
||||
m_waitingForEcho = true;
|
||||
m_waitingForEchoTimer.expires_after(boost::asio::chrono::milliseconds(Config::echoTimeout));
|
||||
m_waitingForEchoTimer.expires_after(boost::asio::chrono::milliseconds(m_config.echoTimeout));
|
||||
m_waitingForEchoTimer.async_wait(std::bind(&Kernel::waitingForEchoTimerExpired, this, std::placeholders::_1));
|
||||
|
||||
m_waitingForResponse = hasResponse(message);
|
||||
if(m_waitingForResponse)
|
||||
{
|
||||
m_waitingForResponseTimer.expires_after(boost::asio::chrono::milliseconds(Config::responseTimeout));
|
||||
m_waitingForResponseTimer.expires_after(boost::asio::chrono::milliseconds(m_config.responseTimeout));
|
||||
m_waitingForResponseTimer.async_wait(std::bind(&Kernel::waitingForResponseTimerExpired, this, std::placeholders::_1));
|
||||
}
|
||||
}
|
||||
@ -1039,7 +1039,7 @@ void Kernel::waitingForEchoTimerExpired(const boost::system::error_code& ec)
|
||||
EventLoop::call(
|
||||
[this]()
|
||||
{
|
||||
Log::log(m_logId, LogMessage::E2018_TIMEOUT_NO_ECHO_WITHIN_X_MS, Config::echoTimeout);
|
||||
Log::log(m_logId, LogMessage::W2018_TIMEOUT_NO_ECHO_WITHIN_X_MS, m_config.echoTimeout);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "settings.hpp"
|
||||
#include "messages.hpp"
|
||||
#include "../../../core/attributes.hpp"
|
||||
#include "../../../utils/displayname.hpp"
|
||||
|
||||
@ -28,21 +29,10 @@ namespace LocoNet {
|
||||
|
||||
Settings::Settings(Object& _parent, std::string_view parentPropertyName)
|
||||
: SubObject(_parent, parentPropertyName)
|
||||
, commandStation{this, "command_station", LocoNetCommandStation::Custom, PropertyFlags::ReadWrite | PropertyFlags::Store,
|
||||
[](LocoNetCommandStation value)
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case LocoNetCommandStation::Custom:
|
||||
break;
|
||||
|
||||
case LocoNetCommandStation::DigikeijsDR5000:
|
||||
break;
|
||||
|
||||
case LocoNetCommandStation::UhlenbrockIntellibox:
|
||||
break;
|
||||
}
|
||||
}}
|
||||
, commandStation{this, "command_station", LocoNetCommandStation::Custom, PropertyFlags::ReadWrite | PropertyFlags::Store, std::bind(&Settings::commandStationChanged, this, std::placeholders::_1)}
|
||||
, echoTimeout{this, "echo_timeout", 250, PropertyFlags::ReadWrite | PropertyFlags::Store}
|
||||
, responseTimeout{this, "response_timeout", 1000, PropertyFlags::ReadWrite | PropertyFlags::Store}
|
||||
, locomotiveSlots{this, "locomotive_slots", SLOT_LOCO_MAX, PropertyFlags::ReadWrite | PropertyFlags::Store}
|
||||
, fastClockSyncEnabled{this, "fast_clock_sync_enabled", false, PropertyFlags::ReadWrite | PropertyFlags::Store,
|
||||
[this](bool value)
|
||||
{
|
||||
@ -57,6 +47,16 @@ Settings::Settings(Object& _parent, std::string_view parentPropertyName)
|
||||
Attributes::addValues(commandStation, LocoNetCommandStationValues);
|
||||
m_interfaceItems.add(commandStation);
|
||||
|
||||
Attributes::addMinMax(echoTimeout, Config::timeoutMin, Config::timeoutMax);
|
||||
m_interfaceItems.add(echoTimeout);
|
||||
|
||||
Attributes::addMinMax(responseTimeout, Config::timeoutMin, Config::timeoutMax);
|
||||
m_interfaceItems.add(responseTimeout);
|
||||
|
||||
Attributes::addEnabled(locomotiveSlots, true);
|
||||
Attributes::addMinMax(locomotiveSlots, SLOT_LOCO_MIN, SLOT_LOCO_MAX);
|
||||
m_interfaceItems.add(locomotiveSlots);
|
||||
|
||||
//Attributes::addGroup(fastClockSyncEnabled, Group::fastClockSync);
|
||||
m_interfaceItems.add(fastClockSyncEnabled);
|
||||
|
||||
@ -81,6 +81,11 @@ Config Settings::config() const
|
||||
{
|
||||
Config config;
|
||||
|
||||
config.echoTimeout = echoTimeout;
|
||||
config.responseTimeout = responseTimeout;
|
||||
|
||||
config.locomotiveSlots = locomotiveSlots;
|
||||
|
||||
config.fastClockSyncEnabled = fastClockSyncEnabled;
|
||||
config.fastClockSyncInterval = fastClockSyncInterval;
|
||||
|
||||
@ -96,6 +101,30 @@ void Settings::loaded()
|
||||
SubObject::loaded();
|
||||
|
||||
Attributes::setEnabled(fastClockSyncInterval, fastClockSyncEnabled);
|
||||
|
||||
commandStationChanged(commandStation);
|
||||
}
|
||||
|
||||
void Settings::commandStationChanged(LocoNetCommandStation value)
|
||||
{
|
||||
const bool isCustom = (value == LocoNetCommandStation::Custom);
|
||||
|
||||
switch(value)
|
||||
{
|
||||
case LocoNetCommandStation::Custom:
|
||||
break;
|
||||
|
||||
case LocoNetCommandStation::DigikeijsDR5000:
|
||||
locomotiveSlots = SLOT_LOCO_MAX;
|
||||
break;
|
||||
|
||||
case LocoNetCommandStation::UhlenbrockIntellibox:
|
||||
case LocoNetCommandStation::UhlenbrockIBCOM:
|
||||
locomotiveSlots = 32;
|
||||
break;
|
||||
}
|
||||
|
||||
Attributes::setEnabled(locomotiveSlots, isCustom);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2019-2021 Reinder Feenstra
|
||||
* Copyright (C) 2019-2022 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -31,13 +31,19 @@ namespace LocoNet {
|
||||
|
||||
class Settings final : public SubObject
|
||||
{
|
||||
CLASS_ID("loconet_settings")
|
||||
|
||||
private:
|
||||
void commandStationChanged(LocoNetCommandStation value);
|
||||
|
||||
protected:
|
||||
void loaded() final;
|
||||
|
||||
public:
|
||||
CLASS_ID("loconet_settings")
|
||||
|
||||
Property<LocoNetCommandStation> commandStation;
|
||||
Property<uint16_t> echoTimeout;
|
||||
Property<uint16_t> responseTimeout;
|
||||
Property<uint8_t> locomotiveSlots;
|
||||
Property<bool> fastClockSyncEnabled;
|
||||
Property<uint8_t> fastClockSyncInterval; //!< Fast clock sync interval in seconds
|
||||
Property<bool> debugLogInput;
|
||||
|
||||
@ -24,21 +24,30 @@
|
||||
#define TRAINTASTIC_SHARED_TRAINTASTIC_ENUM_LOCONETCOMMANDSTATION_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include "enum.hpp"
|
||||
#include <frozen/map.h>
|
||||
|
||||
enum class LocoNetCommandStation : uint16_t
|
||||
{
|
||||
Custom = 0,
|
||||
UhlenbrockIntellibox = 1,
|
||||
DigikeijsDR5000 = 2,
|
||||
UhlenbrockIBCOM = 3,
|
||||
};
|
||||
|
||||
TRAINTASTIC_ENUM(LocoNetCommandStation, "loconet_command_station", 3,
|
||||
TRAINTASTIC_ENUM(LocoNetCommandStation, "loconet_command_station", 4,
|
||||
{
|
||||
{LocoNetCommandStation::Custom, "custom"},
|
||||
{LocoNetCommandStation::UhlenbrockIntellibox, "uhlenbrock_intellibox"},
|
||||
{LocoNetCommandStation::DigikeijsDR5000, "digikeijs_dr5000"},
|
||||
{LocoNetCommandStation::UhlenbrockIBCOM, "uhlenbrock_ibcom"},
|
||||
});
|
||||
|
||||
inline constexpr std::array<LocoNetCommandStation, 4> LocoNetCommandStationValues{{
|
||||
LocoNetCommandStation::Custom,
|
||||
LocoNetCommandStation::DigikeijsDR5000,
|
||||
LocoNetCommandStation::UhlenbrockIntellibox,
|
||||
LocoNetCommandStation::UhlenbrockIBCOM,
|
||||
}};
|
||||
|
||||
#endif
|
||||
|
||||
@ -122,6 +122,7 @@ enum class LogMessage : uint32_t
|
||||
W2003_COMMAND_STATION_DOESNT_SUPPORT_X_SPEEDSTEPS_USING_X = LogMessageOffset::warning + 2003,
|
||||
W2004_INPUT_ADDRESS_X_IS_INVALID = LogMessageOffset::warning + 2004,
|
||||
W2005_OUTPUT_ADDRESS_X_IS_INVALID = LogMessageOffset::warning + 2005,
|
||||
W2018_TIMEOUT_NO_ECHO_WITHIN_X_MS = LogMessageOffset::warning + 2018,
|
||||
W9999_X = LogMessageOffset::warning + 9999,
|
||||
|
||||
// Error:
|
||||
|
||||
@ -229,6 +229,7 @@ list:remove=Remove
|
||||
|
||||
loconet_command_station:custom=Custom
|
||||
loconet_command_station:digikeijs_dr5000=Digikeijs DR5000
|
||||
loconet_command_station:uhlenbrock_ibcom=Uhlenbrock IB-Com
|
||||
loconet_command_station:uhlenbrock_intellibox=Uhlenbrock Intellibox
|
||||
|
||||
loconet_interface_type:lbserver=LBServer
|
||||
@ -241,8 +242,11 @@ loconet_serial_interface:digikeijs_dr5000=Digikeijs DR5000
|
||||
loconet_serial_interface:rosoft_loconet_interface=RoSoft LocoNet interface
|
||||
|
||||
loconet_settings:command_station=Command station
|
||||
loconet_settings:echo_timeout=Echo timeout
|
||||
loconet_settings:fast_clock_sync_enabled=Fast clock sync enabled
|
||||
loconet_settings:fast_clock_sync_interval=Fast clock sync interval
|
||||
loconet_settings:locomotive_slots=Locomotive slots
|
||||
loconet_settings:response_timeout=Response timeout
|
||||
|
||||
lua.script:disabled=Disabled
|
||||
lua.script:start=Start
|
||||
@ -382,6 +386,7 @@ message:W2002=Command station doesn't support functions above F%1
|
||||
message:W2003=Command station doesn't support %1 speedsteps using %2
|
||||
message:W2004=Input address %1 is invalid
|
||||
message:W2005=Output address %1 is invalid
|
||||
message:W2018=Timeout, no echo within %1ms
|
||||
message:W9999=%1
|
||||
|
||||
object:id=Id
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren