traintasticdiy: added startup delay, default = 500ms

some devices reset on connect, give them some time to boot
Dieser Commit ist enthalten in:
Reinder Feenstra 2023-12-06 00:12:16 +01:00
Ursprung 3a3bee66ba
Commit cb23c99940
6 geänderte Dateien mit 35 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -30,6 +30,7 @@ namespace TraintasticDIY {
struct Config
{
std::chrono::milliseconds heartbeatTimeout;
std::chrono::milliseconds startupDelay;
bool debugLogRXTX;
bool debugLogHeartbeat;

Datei anzeigen

@ -75,6 +75,7 @@ Kernel::Kernel(std::string logId_, World& world, const Config& config, bool simu
: KernelBase(std::move(logId_))
, m_world{world}
, m_simulation{simulation}
, m_startupDelayTimer{m_ioContext}
, m_heartbeatTimeout{m_ioContext}
, m_inputController{nullptr}
, m_outputController{nullptr}
@ -132,12 +133,8 @@ void Kernel::start()
return;
}
send(GetInfo());
send(GetFeatures());
restartHeartbeatTimeout();
started();
m_startupDelayTimer.expires_after(boost::asio::chrono::milliseconds(m_config.startupDelay));
m_startupDelayTimer.async_wait(std::bind(&Kernel::startupDelayExpired, this, std::placeholders::_1));
});
#ifndef NDEBUG
@ -461,6 +458,19 @@ void Kernel::send(const Message& message)
{} // log message and go to error state
}
void Kernel::startupDelayExpired(const boost::system::error_code& ec)
{
if(ec)
return;
send(GetInfo());
send(GetFeatures());
restartHeartbeatTimeout();
started();
}
void Kernel::restartHeartbeatTimeout()
{
m_heartbeatTimeout.expires_after(m_config.heartbeatTimeout);

Datei anzeigen

@ -59,6 +59,7 @@ class Kernel : public ::KernelBase
std::unique_ptr<IOHandler> m_ioHandler;
const bool m_simulation;
std::string m_logId;
boost::asio::steady_timer m_startupDelayTimer;
boost::asio::steady_timer m_heartbeatTimeout;
bool m_featureFlagsSet;
@ -98,6 +99,8 @@ class Kernel : public ::KernelBase
inline bool hasFeatureOutput() const { return contains(m_featureFlags1, FeatureFlags1::Output); }
inline bool hasFeatureThrottle() const { return contains(m_featureFlags1, FeatureFlags1::Throttle); }
void startupDelayExpired(const boost::system::error_code& ec);
void restartHeartbeatTimeout();
void heartbeatTimeoutExpired(const boost::system::error_code& ec);

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2022 Reinder Feenstra
* Copyright (C) 2022-2023 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -28,10 +28,14 @@ namespace TraintasticDIY {
Settings::Settings(Object& _parent, std::string_view parentPropertyName)
: SubObject(_parent, parentPropertyName)
, startupDelay{this, "startup_delay", startupDelayDefault, PropertyFlags::ReadWrite | PropertyFlags::Store}
, heartbeatTimeout{this, "heartbeat_timeout", heartbeatTimeoutDefault, PropertyFlags::ReadWrite | PropertyFlags::Store}
, debugLogRXTX{this, "debug_log_rx_tx", false, PropertyFlags::ReadWrite | PropertyFlags::Store}
, debugLogHeartbeat{this, "debug_log_heartbeat", false, PropertyFlags::ReadWrite | PropertyFlags::Store}
{
Attributes::addMinMax(startupDelay, startupDelayMin, startupDelayMax);
m_interfaceItems.add(startupDelay);
Attributes::addMinMax(heartbeatTimeout, heartbeatTimeoutMin, heartbeatTimeoutMax);
m_interfaceItems.add(heartbeatTimeout);
@ -45,6 +49,7 @@ Config Settings::config() const
{
Config config;
config.startupDelay = std::chrono::milliseconds(startupDelay);
config.heartbeatTimeout = std::chrono::milliseconds(heartbeatTimeout);
config.debugLogRXTX = debugLogRXTX;

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2022 Reinder Feenstra
* Copyright (C) 2022-2023 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -34,11 +34,15 @@ class Settings final : public SubObject
CLASS_ID("traintastic_diy_settings")
private:
static constexpr uint16_t startupDelayMin = 0;
static constexpr uint16_t startupDelayDefault = 500;
static constexpr uint16_t startupDelayMax = 60'000;
static constexpr uint16_t heartbeatTimeoutMin = 100;
static constexpr uint16_t heartbeatTimeoutDefault = 1'000;
static constexpr uint16_t heartbeatTimeoutMax = 60'000;
public:
Property<uint16_t> startupDelay;
Property<uint16_t> heartbeatTimeout;
Property<bool> debugLogRXTX;
Property<bool> debugLogHeartbeat;

Datei anzeigen

@ -4378,5 +4378,9 @@
{
"term": "board_tile.rail.signal_3_aspect:require_reservation",
"definition": "Require reservation"
},
{
"term": "traintastic_diy_settings:startup_delay",
"definition": "Startup delay"
}
]