]> git.tdb.fi Git - r2c2.git/commitdiff
Include block in the emergency signal
authorMikko Rasa <tdb@tdb.fi>
Tue, 8 Apr 2014 18:33:40 +0000 (21:33 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 8 Apr 2014 18:33:40 +0000 (21:33 +0300)
source/engineer/engineer.cpp
source/engineer/engineer.h
source/libr2c2/blockallocator.cpp
source/libr2c2/layout.cpp
source/libr2c2/layout.h
source/libr2c2/track.cpp
source/libr2c2/train.cpp
source/network/server.cpp
source/network/server.h

index 789c6055cd699ce621a8c7f137a113bbacc4eb4b..cc604d3254bf747a150035b5b2c6dd52255d579e 100644 (file)
@@ -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<Block *> &blocks = layout.get_all<Block>();
        for(set<Block *>::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<Track>(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)
index d821e0581127ad28c315b4d6e61f8c47b02c653d..7cf1cfcf475377bafc3a886e6cddee368997681f 100644 (file)
@@ -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 &);
index 5a410ff20de0af908df94952d6d2bdb46348e14f..ed32193f3e1d116b65b557d9bb8619f82dc0bf41 100644 (file)
@@ -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();
index b4eb8faacdbdb52d5d4786fe8495c747762c1c6a..a6abc500448782341378376a83bf35c6500325ff 100644 (file)
@@ -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");
        }
 }
 
index 44c4cde42efd861b804c3008525bc33ee62d0ef5..41de73d7dc11f9b46e3e209c318ff801a6c69851 100644 (file)
@@ -78,7 +78,7 @@ public:
        sigc::signal<void, Train &> signal_train_removed;
        sigc::signal<void, Block &, Train *> signal_block_reserved;
        sigc::signal<void, Sensor &, Sensor::State> signal_sensor_state_changed;
-       sigc::signal<void, const std::string &> signal_emergency;
+       sigc::signal<void, Block *, const std::string &> 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;
index 2ad3b53dcffe2779d611aa43b4f5a6acab2a3482..0df1f40b03141c60febd73c237148a2d97656709 100644 (file)
@@ -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");
        }
 }
 
index 8e10026f182bee49987318eb0daee177ad679873..78137b8703ddfc7162ec173f83046ff31bfe877b 100644 (file)
@@ -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;
                        }
                }
index 951fb9d4be658c4ee480d8a3088749f7fdeca65f..aced6f7202f2e6dc894af1ec686fb4fb51a1c72f 100644 (file)
@@ -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;
index efb3b3a2472726ab8bfdce9ac5427c35a9825402..7063b861bbf66011bc12fad43050a60aa735cbef 100644 (file)
@@ -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);