1 #ifndef LIBR2C2_CENTRALSTATION_H_
2 #define LIBR2C2_CENTRALSTATION_H_
4 #include <msp/net/streamsocket.h>
5 #include <msp/time/timestamp.h>
10 class CentralStation: public Driver
21 operator bool() const;
26 typedef std::multimap<std::string, std::string> AttribMap;
27 typedef std::map<unsigned, AttribMap> ObjectMap;
33 operator bool() const;
39 NERROR_UNKNOWNCOMMAND = 10,
40 NERROR_UNKNOWNARG = 11,
41 NERROR_UNKNOWNPARAM = 12,
42 NERROR_UNKNOWNID = 15,
44 NERROR_NOTALLOWED = 22,
45 NERROR_NOCONTROL = 25,
97 typedef std::map<unsigned, unsigned> AddressMap;
98 typedef std::map<unsigned, Locomotive> LocoMap;
99 typedef std::map<unsigned, Turnout> TurnoutMap;
100 typedef std::map<unsigned, Sensor> SensorMap;
102 Msp::Net::StreamSocket socket;
103 std::list<std::string> cmd_queue;
104 unsigned pending_commands;
107 std::string in_buffer;
109 AddressMap loco_addr;
112 AddressMap turnout_addr;
113 bool turnouts_synced;
115 std::vector<unsigned> s88;
119 CentralStation(const std::string &);
122 virtual void set_power(bool);
123 virtual bool get_power() const { return power; }
124 virtual void halt(bool);
125 virtual bool is_halted() const { return halted; }
127 virtual const char *enumerate_protocols(unsigned) const;
128 virtual unsigned get_protocol_speed_steps(const std::string &) const;
130 virtual void add_loco(unsigned, const std::string &, const VehicleType &);
131 virtual void set_loco_speed(unsigned, unsigned);
132 virtual void set_loco_reverse(unsigned, bool);
133 virtual void set_loco_function(unsigned, unsigned, bool);
135 virtual void add_turnout(unsigned, const TrackType &);
136 virtual void set_turnout(unsigned, unsigned);
137 virtual unsigned get_turnout(unsigned) const;
139 virtual void add_sensor(unsigned);
140 virtual void set_sensor(unsigned, bool) { }
141 virtual bool get_sensor(unsigned) const;
144 virtual void flush();
147 void command(const std::string &, bool = false);
149 void process_reply(const Message &);
150 void process_event(const Message &);
151 void process_object(unsigned, const Message::AttribMap &);
152 Protocol map_protocol(const std::string &) const;
154 unsigned map_address(const std::map<unsigned, T> &, const AddressMap &, unsigned) const;
155 void skip(std::string::iterator &, const std::string::iterator &, const std::string &) const;
156 std::string parse_token(std::string::iterator &, const std::string::iterator &, const std::string &) const;
157 Tag parse_tag(std::string::iterator &, const std::string::iterator &) const;
158 Message parse_message(std::string::iterator &, const std::string::iterator &) const;