From: Mikko Rasa Date: Tue, 23 Nov 2010 21:54:33 +0000 (+0000) Subject: Save turnout states and restore them on startup X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6010ad6857ce5690f4053bf8795f2c476daa4694;p=r2c2.git Save turnout states and restore them on startup Don't send turnout commands before establishing sync with the device --- diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 1f3b7dc..8db0be6 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -131,7 +131,7 @@ Engineer::~Engineer() layout.get_driver().flush(); if(!options.simulate) - layout.save_trains(options.state_fn); + layout.save_dynamic(options.state_fn); delete overlay; delete root; diff --git a/source/libr2c2/intellibox.cpp b/source/libr2c2/intellibox.cpp index 7702ed6..84d576b 100644 --- a/source/libr2c2/intellibox.cpp +++ b/source/libr2c2/intellibox.cpp @@ -242,7 +242,7 @@ void Intellibox::set_turnout(unsigned addr, unsigned state) { Turnout &turnout = turnouts[addr]; unsigned mask = (1<::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + if(unsigned tid = (*i)->get_turnout_id()) + writer.write((DataFile::Statement("turnout"), tid, (*i)->get_active_path())); + for(map::const_iterator i=trains.begin(); i!=trains.end(); ++i) { DataFile::Statement st("train"); @@ -351,6 +355,7 @@ Layout::Loader::Loader(Layout &l): add("route", static_cast(&Loader::route)); add("track", static_cast(&Loader::track)); add("train", static_cast(&Loader::train)); + add("turnout", &Loader::turnout); add("zone", &Loader::zone); // Deprecated aliases @@ -404,6 +409,12 @@ void Layout::Loader::train(ArticleNumber art_nr, unsigned addr, const std::strin load_sub(*trn); } +void Layout::Loader::turnout(unsigned addr, unsigned path) +{ + if(obj.driver) + obj.driver->set_turnout(addr, path); +} + void Layout::Loader::zone() { Zone *zne = new Zone(obj); diff --git a/source/libr2c2/layout.h b/source/libr2c2/layout.h index 6ef7e09..8c143ac 100644 --- a/source/libr2c2/layout.h +++ b/source/libr2c2/layout.h @@ -43,6 +43,7 @@ public: void track(ArticleNumber); void train(unsigned, unsigned, const std::string &); void train(ArticleNumber, unsigned, const std::string &); + void turnout(unsigned, unsigned); void zone(); }; @@ -120,7 +121,7 @@ public: void emergency(const std::string &); void save(const std::string &) const; - void save_trains(const std::string &) const; + void save_dynamic(const std::string &) const; private: void sensor_event(unsigned, bool); };