From: Mikko Rasa Date: Tue, 8 Apr 2014 18:33:40 +0000 (+0300) Subject: Include block in the emergency signal X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9cb5f9ef3c0eaac499ef5d045c513116d6809e56;p=r2c2.git Include block in the emergency signal --- diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 789c605..cc604d3 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -77,7 +77,7 @@ Engineer::Engineer(int argc, char **argv): if(layout.has_driver()) layout.get_driver().signal_locomotive_detected.connect(sigc::mem_fun(this, &Engineer::locomotive_detected)); layout.signal_train_added.connect(sigc::mem_fun(this, &Engineer::train_added)); - layout.signal_emergency.connect(sigc::mem_fun(this, &Engineer::set_status)); + layout.signal_emergency.connect(sigc::mem_fun(this, &Engineer::emergency)); const set &blocks = layout.get_all(); for(set::const_iterator i=blocks.begin(); i!=blocks.end(); ++i) if(TrackCircuit *tc = (*i)->get_sensor()) @@ -299,6 +299,11 @@ Object *Engineer::pick_object(const Vector &p) return layout.pick(Ray(start, Vector(ray))); } +void Engineer::emergency(Block *, const string &msg) +{ + set_status(msg); +} + void Engineer::locomotive_detected(const Driver::DetectedLocomotive &loco) { if(!import_active) diff --git a/source/engineer/engineer.h b/source/engineer/engineer.h index d821e05..7cf1cfc 100644 --- a/source/engineer/engineer.h +++ b/source/engineer/engineer.h @@ -71,9 +71,8 @@ private: void button_press(unsigned); void axis_motion(unsigned, float, float); void view_all(); - void sensor_event(unsigned, bool); - void block_reserved(const R2C2::Block &, const R2C2::Train *); R2C2::Object *pick_object(const R2C2::Vector &); + void emergency(R2C2::Block *, const std::string &); void locomotive_detected(const R2C2::Driver::DetectedLocomotive &); void import_finished(int); void train_added(R2C2::Train &); diff --git a/source/libr2c2/blockallocator.cpp b/source/libr2c2/blockallocator.cpp index 5a410ff..ed32193 100644 --- a/source/libr2c2/blockallocator.cpp +++ b/source/libr2c2/blockallocator.cpp @@ -505,7 +505,7 @@ void BlockAllocator::sensor_state_changed(Sensor &sensor, Sensor::State state) reserve_more(); } else if(!is_block_current(*block)) - train.get_layout().emergency("Sensor for "+train.get_name()+" triggered out of order"); + train.get_layout().emergency(block, "Sensor for "+train.get_name()+" triggered out of order"); } else if(state==Sensor::INACTIVE) advance_back(); diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index b4eb8fa..a6abc50 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -396,12 +396,15 @@ void Layout::tick() i->second->tick(dt); } -void Layout::emergency(const string &msg) +void Layout::emergency(Block *block, const string &msg) { if(driver) driver->halt(true); - IO::print("Emergency: %s\n", msg); - signal_emergency.emit(msg); + if(block) + IO::print("Emergency at %s: %s\n", block->get_name(), msg); + else + IO::print("Emergency: %s\n", msg); + signal_emergency.emit(block, msg); } void Layout::save(const string &fn) const @@ -500,7 +503,7 @@ void Layout::sensor_state_changed(Sensor &sensor, Sensor::State state) { Block *block = sensor.get_block(); if(block && !block->get_train()) - emergency(format("Unreserved sensor %d triggered", sensor.get_address())); + emergency(block, "Unreserved sensor triggered"); } } diff --git a/source/libr2c2/layout.h b/source/libr2c2/layout.h index 44c4cde..41de73d 100644 --- a/source/libr2c2/layout.h +++ b/source/libr2c2/layout.h @@ -78,7 +78,7 @@ public: sigc::signal signal_train_removed; sigc::signal signal_block_reserved; sigc::signal signal_sensor_state_changed; - sigc::signal signal_emergency; + sigc::signal signal_emergency; private: Catalogue &catalogue; @@ -139,7 +139,7 @@ public: void remove_train(Train &); void tick(); - void emergency(const std::string &); + void emergency(Block *, const std::string &); void save(const std::string &) const; void save_dynamic(const std::string &) const; diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 2ad3b53..0df1f40 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -428,7 +428,7 @@ void Track::turnout_failed(unsigned id) if(id==turnout_id) { path_changing = false; - layout.emergency(format("Turnout %d failed", turnout_addr)); + layout.emergency(block, "Turnout failed"); } } diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 8e10026..78137b8 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -358,7 +358,8 @@ void Train::tick(const Time::TimeDelta &dt) Vehicle &vehicle = *(reverse ? vehicles.back() : vehicles.front()); float d = speed*(dt/Time::sec); - if(allocator.is_block_current(vehicle.get_placement().get_position(reverse ? VehiclePlacement::BACK_AXLE : VehiclePlacement::FRONT_AXLE)->get_block())) + Block &block = vehicle.get_placement().get_position(reverse ? VehiclePlacement::BACK_AXLE : VehiclePlacement::FRONT_AXLE)->get_block(); + if(allocator.is_block_current(block)) { SetFlag setf(advancing); vehicle.advance(reverse ? -d : d); @@ -368,7 +369,7 @@ void Train::tick(const Time::TimeDelta &dt) overshoot_dist += d; if(overshoot_dist>40*layout.get_catalogue().get_scale()) { - layout.emergency(name+" has not arrived at sensor"); + layout.emergency(&block, name+" has not arrived at sensor"); accurate_position = false; } } diff --git a/source/network/server.cpp b/source/network/server.cpp index 951fb9d..aced6f7 100644 --- a/source/network/server.cpp +++ b/source/network/server.cpp @@ -59,7 +59,7 @@ void Server::driver_state_changed() send(pkt); } -void Server::emergency(const string &msg) +void Server::emergency(Block *, const string &msg) { EmergencyPacket pkt; pkt.message = msg; diff --git a/source/network/server.h b/source/network/server.h index efb3b3a..7063b86 100644 --- a/source/network/server.h +++ b/source/network/server.h @@ -52,7 +52,7 @@ private: void incoming_connection(); void driver_state_changed(); - void emergency(const std::string &); + void emergency(Block *, const std::string &); void train_added(Train &); void train_control_changed(const Train &, const std::string &, float); void train_function_changed(const Train &, unsigned, bool);