]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/train.h
Attempt to estimate the exact positions of trains from measured speed data
[r2c2.git] / source / libmarklin / train.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_TRAIN_H_
9 #define LIBMARKLIN_TRAIN_H_
10
11 #include <sigc++/signal.h>
12 #include <sigc++/trackable.h>
13 #include <msp/time/timestamp.h>
14 #include "block.h"
15
16 namespace Marklin {
17
18 class Locomotive;
19 class Sensor;
20 class TrafficManager;
21
22 class Train: public sigc::trackable
23 {
24 private:
25         struct BlockRef
26         {
27                 Block *block;
28                 unsigned entry;
29
30                 BlockRef(Block *s, unsigned e): block(s), entry(e) { }
31         };
32
33         TrafficManager &trfc_mgr;
34         std::string name;
35         Locomotive &loco;
36         std::list<BlockRef> cur_blocks;
37         std::list<BlockRef> rsv_blocks;
38         unsigned target_speed;
39         Msp::Time::TimeStamp try_reserve;
40         std::string status;
41
42         Msp::Time::TimeStamp last_entry_time;
43         float travel_dist;
44         unsigned travel_speed;
45         bool pure_speed;
46         float speed_scale;
47         float speed_scale_weight;
48
49         Track *cur_track;
50         unsigned cur_track_ep;
51         float offset;
52         Point pos;
53
54 public:
55         sigc::signal<void, const std::string &> signal_name_changed;
56         sigc::signal<void, const std::string &> signal_status_changed;
57
58         Train(TrafficManager &, Locomotive &);
59
60         void set_name(const std::string &);
61         void set_speed(unsigned);
62         const std::string &get_name() const { return name; }
63         Locomotive &get_locomotive() const { return loco; }
64         const std::string &get_status() const { return status; }
65         const Point &get_position() const { return pos; }
66         void place(Block *, unsigned);
67         bool free_block(Block *);
68         void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
69 private:
70         void sensor_event(bool, Sensor *);
71         unsigned reserve_more();
72         void update_speed();
73         void set_status(const std::string &);
74         void set_position(const Block::Endpoint &);
75 };
76
77 } // namespace Marklin
78
79 #endif