enabled(false),
current_row(0),
executing(true),
- pending_block(0)
+ pending_block(0),
+ pending_train(0)
{
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));
break;
case TRAVEL:
pending_block = &parse_location(row.get_param<string>(0));
+ pending_train = &train;
executing = false;
break;
- case WAIT:
+ case WAIT_TIME:
wait_timeout = t+row.get_param<unsigned>(0)*Time::sec;
executing = false;
break;
+ case WAIT_TRAIN:
+ pending_train = &train.get_layout().get_train(row.get_param<unsigned>(0));
+ pending_block = &parse_location(row.get_param<string>(1));
+ executing = false;
+ break;
case ARRIVE:
executing = false;
break;
void Timetable::sensor_event(unsigned addr, bool state)
{
- if(pending_block && pending_block->get_train()==&train && addr==pending_block->get_sensor_id() && state)
+ if(pending_block && pending_block->get_train()==pending_train && addr==pending_block->get_sensor_id() && state)
{
pending_block = 0;
current_row = (current_row+1)%rows.size();
return "set route to "+get_param<string>(0);
case TRAVEL:
return "travel to "+get_param<string>(0);
- case WAIT:
+ case WAIT_TIME:
return format("wait for %d seconds", get_param<unsigned>(0));
+ case WAIT_TRAIN:
+ return format("wait for train %d at %s", get_param<unsigned>(0), get_param<string>(1));
case ARRIVE:
return "travel until arrival";
case SPEED:
return DataFile::Statement("goto"), get_param<string>(0);
case TRAVEL:
return DataFile::Statement("travel"), get_param<string>(0);
- case WAIT:
+ case WAIT_TIME:
return DataFile::Statement("wait"), get_param<unsigned>(0);
+ case WAIT_TRAIN:
+ return DataFile::Statement("wait_train"), get_param<unsigned>(0), get_param<string>(1);
case ARRIVE:
return DataFile::Statement("arrive");
case SPEED:
else if(!s.compare(7, string::npos, "until arrival"))
return Row(ARRIVE);
}
- else if(!s.compare(0, 9, "wait for ") && isdigit(s[9]))
+ else if(!s.compare(0, 9, "wait for "))
{
- unsigned nondigit = 10;
- while(nondigit<s.size() && isdigit(s[nondigit]))
- ++nondigit;
- return Row(WAIT, lexical_cast<unsigned>(s.substr(9, nondigit-9)));
+ if(isdigit(s[9]))
+ {
+ unsigned nondigit = 10;
+ while(nondigit<s.size() && isdigit(s[nondigit]))
+ ++nondigit;
+ return Row(WAIT_TIME, lexical_cast<unsigned>(s.substr(9, nondigit-9)));
+ }
+ else if(!s.compare(9, 6, "train "))
+ {
+ string::size_type at = s.find(" at ", 15);
+ if(at!=string::npos)
+ {
+ Row row(WAIT_TRAIN, lexical_cast<unsigned>(s.substr(15, at-15)));
+ row.params.push_back(s.substr(at+4));
+ return row;
+ }
+ }
}
else if(!s.compare(0, 10, "set speed "))
{
add("reverse", &Loader::reverse);
add("travel", &Loader::travel);
add("wait", &Loader::wait);
+ add("wait_train", &Loader::wait_train);
}
void Timetable::Loader::arrive()
void Timetable::Loader::wait(unsigned t)
{
- obj.rows.push_back(Row(WAIT, t));
+ obj.rows.push_back(Row(WAIT_TIME, t));
+}
+
+void Timetable::Loader::wait_train(unsigned t, const string &b)
+{
+ Row row(WAIT_TRAIN, t);
+ row.params.push_back(b);
+ obj.rows.push_back(row);
}
} // namespace Marklin