pending_train(0),
arrived(false)
{
+ train.signal_advanced.connect(sigc::mem_fun(this, &Timetable::train_advanced));
train.signal_arrived.connect(sigc::mem_fun(this, &Timetable::train_arrived));
- train.get_layout().get_driver().signal_sensor.connect(sigc::mem_fun(this, &Timetable::sensor_event));
+ Layout &layout = train.get_layout();
+ layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Timetable::sensor_event));
+ layout.signal_block_reserved.connect(sigc::mem_fun(this, &Timetable::block_reserved));
}
void Timetable::set_enabled(bool e)
if(!train.go_to(get_zone(row.get_param<string>(0))))
set_enabled(false);
break;
- case TRAVEL:
+ case TRAVEL_TO:
pending_block = &get_sensor(row.get_param<unsigned>(0)).get_block();
pending_train = &train;
executing = false;
break;
+ case TRAVEL_PAST:
+ pending_block = &get_turnout(row.get_param<unsigned>(0)).get_block();
+ pending_train = (pending_block->get_train()==&train ? 0 : &train);
+ executing = false;
+ break;
case WAIT_TIME:
wait_timeout = t+row.get_param<unsigned>(0)*Time::sec;
executing = false;
return **block.get_tracks().begin();
}
+Track &Timetable::get_turnout(unsigned id)
+{
+ Block &block = train.get_layout().get_block(id|0x2000);
+ return **block.get_tracks().begin();
+}
+
Zone &Timetable::get_zone(const string &name)
{
string::size_type space = name.rfind(' ');
}
}
+void Timetable::block_reserved(Block &block, Train *trn)
+{
+ if(&block==pending_block && trn==pending_train)
+ {
+ Row &row = rows[current_row];
+ if(row.type==TRAVEL_PAST && !pending_train)
+ {
+ pending_block = 0;
+ current_row = (current_row+1)%rows.size();
+ executing = true;
+ }
+ }
+}
+
+void Timetable::train_advanced(Block &block)
+{
+ Row &row = rows[current_row];
+ if(row.type==TRAVEL_PAST && &block==pending_block && pending_train)
+ pending_train = 0;
+}
+
void Timetable::train_arrived()
{
Row &row = rows[current_row];
return "set route to sensor "+get_param<unsigned>(0);
case GOTO_ZONE:
return "set route to "+get_param<string>(0);
- case TRAVEL:
+ case TRAVEL_TO:
return format("travel to sensor %d", get_param<unsigned>(0));
+ case TRAVEL_PAST:
+ return format("travel past turnout %d", get_param<unsigned>(0));
case WAIT_TIME:
return format("wait for %d seconds", get_param<unsigned>(0));
case WAIT_UNTIL:
return DataFile::Statement("goto_sensor"), get_param<unsigned>(0);
case GOTO_ZONE:
return DataFile::Statement("goto_zone"), get_param<string>(0);
- case TRAVEL:
- return DataFile::Statement("travel"), get_param<unsigned>(0);
+ case TRAVEL_TO:
+ return DataFile::Statement("travel_to"), get_param<unsigned>(0);
+ case TRAVEL_PAST:
+ return DataFile::Statement("travel_past"), get_param<unsigned>(0);
case WAIT_TIME:
return DataFile::Statement("wait"), get_param<unsigned>(0);
case WAIT_UNTIL:
if(!s.compare(0, 7, "travel "))
{
if(!s.compare(7, 10, "to sensor "))
- return Row(TRAVEL, lexical_cast<unsigned>(s.substr(17)));
+ return Row(TRAVEL_TO, lexical_cast<unsigned>(s.substr(17)));
+ else if(!s.compare(7, 13, "past turnout "))
+ return Row(TRAVEL_PAST, lexical_cast<unsigned>(s.substr(20)));
else if(!s.compare(7, string::npos, "until arrival"))
return Row(ARRIVE);
}
DataFile::ObjectLoader<Timetable>(tt)
{
add("arrive", &Loader::arrive);
- add("goto_sensor", static_cast<void (Loader::*)(unsigned)>(&Loader::goto_sensor));
+ add("goto_sensor", &Loader::goto_sensor);
add("goto_zone", &Loader::goto_zone);
add("route", &Loader::route);
add("speed", &Loader::speed);
add("reverse", &Loader::reverse);
- add("travel", &Loader::travel);
+ add("travel_to", &Loader::travel_to);
+ add("travel_past", &Loader::travel_past);
add("wait", &Loader::wait);
add("wait_train", &Loader::wait_train);
add("wait_until", &Loader::wait_until);
// Deprecated alias
- add("goto", static_cast<void (Loader::*)(const string &)>(&Loader::goto_sensor));
+ add("goto", &Loader::goto_sensor_str);
+ add("travel", &Loader::travel_to);
}
void Timetable::Loader::arrive()
obj.rows.push_back(Row(GOTO_SENSOR, s));
}
-void Timetable::Loader::goto_sensor(const string &s)
+void Timetable::Loader::goto_sensor_str(const string &s)
{
if(!s.compare(0, 7, "sensor "))
obj.rows.push_back(Row(GOTO_SENSOR, lexical_cast<unsigned>(s.substr(7))));
obj.rows.push_back(Row(SPEED, s));
}
-void Timetable::Loader::travel(unsigned s)
+void Timetable::Loader::travel_to(unsigned s)
+{
+ obj.rows.push_back(Row(TRAVEL_TO, s));
+}
+
+void Timetable::Loader::travel_past(unsigned s)
{
- obj.rows.push_back(Row(TRAVEL, s));
+ obj.rows.push_back(Row(TRAVEL_PAST, s));
}
void Timetable::Loader::wait(unsigned t)