|
|
|
@ -150,28 +150,68 @@ void Server::SetModeManual() {
|
|
|
|
|
//
|
|
|
|
|
// run a single cycle in reset mode
|
|
|
|
|
// each step will only reset one single step.
|
|
|
|
|
#define INTERFACE_LOCO_TIME 250
|
|
|
|
|
#define INTERFACE_TURN_TIME 750
|
|
|
|
|
void Server::CycleModeReset() {
|
|
|
|
|
JSONParse json;
|
|
|
|
|
list<JSONElement> elements;
|
|
|
|
|
list<JSONElement>::iterator iter;
|
|
|
|
|
json.Clear();
|
|
|
|
|
|
|
|
|
|
debug (0, "* CycleModeReset Step:%d", data_reset.mr_step);
|
|
|
|
|
// debug (0, "* CycleModeReset Step:%d", data_reset.mr_step);
|
|
|
|
|
|
|
|
|
|
if (data_reset.mr_step == SMRESET_STEP_INIT) {
|
|
|
|
|
//
|
|
|
|
|
// init reset
|
|
|
|
|
data_reset.mr_idx = -1;
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
}
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_INTERFACES) {
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_LOCOMOTIVES) {
|
|
|
|
|
//
|
|
|
|
|
// reset interfaces
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
// reset locomotives, cycle 30ms per locomotive
|
|
|
|
|
if (data_reset.mr_idx < 0 || timer_get(&data_reset.mr_timestamp) > INTERFACE_LOCO_TIME) {
|
|
|
|
|
if (data_reset.mr_idx < -1) data_reset.mr_idx = -1;
|
|
|
|
|
|
|
|
|
|
data_reset.mr_idx++;
|
|
|
|
|
data_reset.mr_lastelm = locomotives.GetName(data_reset.mr_idx);
|
|
|
|
|
timer_start (&data_reset.mr_timestamp);
|
|
|
|
|
|
|
|
|
|
if (data_reset.mr_lastelm.length() > 0) {
|
|
|
|
|
debug (0, "* Reset Locomotive %s", data_reset.mr_lastelm.c_str());
|
|
|
|
|
LocomotiveSetReverse(data_reset.mr_lastelm, 0);
|
|
|
|
|
LocomotiveSetSpeed(data_reset.mr_lastelm, 0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
data_reset.mr_idx = -1;
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
data_reset.mr_lastelm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_LOCOMOTIVES) {
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_TURNOUTS) {
|
|
|
|
|
//
|
|
|
|
|
// reset locomotives
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
// reset turnouts
|
|
|
|
|
if (data_reset.mr_idx < 0 || timer_get(&data_reset.mr_timestamp) > INTERFACE_TURN_TIME) {
|
|
|
|
|
int flags, active;
|
|
|
|
|
if (data_reset.mr_idx < -1) data_reset.mr_idx = -1;
|
|
|
|
|
|
|
|
|
|
data_reset.mr_idx++;
|
|
|
|
|
data_reset.mr_lastelm = turnouts.GetName(data_reset.mr_idx);
|
|
|
|
|
flags = turnouts.GetFlags(data_reset.mr_idx);
|
|
|
|
|
if (flags & TURNOUT_F_TURNOUT) active = 1;
|
|
|
|
|
else active = 0;
|
|
|
|
|
timer_start (&data_reset.mr_timestamp);
|
|
|
|
|
|
|
|
|
|
if (data_reset.mr_lastelm.length() > 0) {
|
|
|
|
|
debug (0, "* Reset Turnout %s", data_reset.mr_lastelm.c_str());
|
|
|
|
|
TurnoutSet(data_reset.mr_lastelm, active);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
data_reset.mr_idx = -1;
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
data_reset.mr_lastelm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_SENSORS) {
|
|
|
|
|
//
|
|
|
|
@ -191,11 +231,13 @@ void Server::CycleModeReset() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sensors.GetJSONAll(&json);
|
|
|
|
|
data_reset.mr_idx = -1;
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
}
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_TURNOUTS) {
|
|
|
|
|
else if (data_reset.mr_step == SMRESET_STEP_INTERFACES) {
|
|
|
|
|
//
|
|
|
|
|
// reset turnouts
|
|
|
|
|
// reset interfaces
|
|
|
|
|
data_reset.mr_idx = -1;
|
|
|
|
|
data_reset.mr_step++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|