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,
99 typedef std::map<unsigned, unsigned> AddressMap;
100 typedef std::map<unsigned, Locomotive> LocoMap;
101 typedef std::map<unsigned, Turnout> TurnoutMap;
102 typedef std::map<unsigned, Sensor> SensorMap;
104 Msp::Net::StreamSocket socket;
105 std::list<std::string> cmd_queue;
106 unsigned pending_commands;
109 std::string in_buffer;
111 AddressMap loco_addr;
114 AddressMap turnout_addr;
115 bool turnouts_synced;
117 std::vector<unsigned> s88;
121 CentralStation(const std::string &);
124 virtual void set_power(bool);
125 virtual bool get_power() const { return power; }
126 virtual void halt(bool);
127 virtual bool is_halted() const { return halted; }
129 virtual const char *enumerate_protocols(unsigned) const;
130 virtual unsigned get_protocol_speed_steps(const std::string &) const;
132 virtual void add_loco(unsigned, const std::string &, const VehicleType &);
133 virtual void set_loco_speed(unsigned, unsigned);
134 virtual void set_loco_reverse(unsigned, bool);
135 virtual void set_loco_function(unsigned, unsigned, bool);
137 virtual void add_turnout(unsigned, const TrackType &);
138 virtual void set_turnout(unsigned, unsigned);
139 virtual unsigned get_turnout(unsigned) const;
141 virtual void add_sensor(unsigned);
142 virtual void set_sensor(unsigned, bool) { }
143 virtual bool get_sensor(unsigned) const;
146 virtual void flush();
149 void command(const std::string &, bool = false);
151 void process_reply(const Message &);
152 void process_event(const Message &);
153 void process_object(unsigned, const Message::AttribMap &);
154 Protocol map_protocol(const std::string &) const;
156 unsigned map_address(const std::map<unsigned, T> &, const AddressMap &, unsigned) const;
157 void skip(std::string::iterator &, const std::string::iterator &, const std::string &) const;
158 std::string parse_token(std::string::iterator &, const std::string::iterator &, const std::string &) const;
159 Tag parse_tag(std::string::iterator &, const std::string::iterator &) const;
160 Message parse_message(std::string::iterator &, const std::string::iterator &) const;