+#include <cstdlib>
#include <msp/strings/utils.h>
#include <msp/time/utils.h>
#include "dummy.h"
Dummy::Dummy(const Options &opts):
power(true),
- turnout_delay(opts.get("turnout_delay", 0.0f)*Time::sec)
+ turnout_delay(opts.get("turnout_delay", 0.0f)*Time::sec),
+ turnout_fail_rate(opts.get("turnout_fail_rate", 0.0f)*RAND_MAX)
{ }
void Dummy::set_power(bool p)
turnout.timeout = Time::now()+turnout_delay;
else
{
- turnout.state = state;
+ if(!turnout_fail_rate || rand()>=turnout_fail_rate)
+ turnout.state = state;
signal_turnout.emit(addr, state);
}
}
{
if(i->second.timeout && t>=i->second.timeout)
{
+ if(turnout_fail_rate && rand()<turnout_fail_rate)
+ {
+ signal_turnout_failed.emit(i->first);
+ i->second.pending = i->second.state;
+ }
i->second.state = i->second.pending;
i->second.timeout = Time::TimeStamp();
signal_turnout.emit(i->first, i->second.state);
std::map<unsigned, LocoState> locos;
std::map<unsigned, bool> sensors;
Msp::Time::TimeDelta turnout_delay;
+ int turnout_fail_rate;
public:
Dummy(const Options &);