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,
71 struct MagnetAccessory
84 TURNOUT_DOUBLESLIP = 3,
86 TURNOUT_CURVED_LEFT = 21,
87 TURNOUT_CURVED_RIGHT = 22
107 typedef std::map<unsigned, unsigned> AddressMap;
108 typedef std::map<unsigned, Locomotive> LocoMap;
109 typedef std::map<unsigned, MagnetAccessory> AccessoryMap;
110 typedef std::map<unsigned, Sensor> SensorMap;
112 Msp::Net::StreamSocket socket;
113 std::list<std::string> cmd_queue;
114 unsigned pending_commands;
117 std::string in_buffer;
119 AddressMap loco_addr;
121 AccessoryMap accessories;
122 AddressMap accessory_addr;
123 bool accessories_synced;
125 std::vector<unsigned> s88;
129 CentralStation(const std::string &);
132 virtual void set_power(bool);
133 virtual bool get_power() const { return power; }
134 virtual void halt(bool);
135 virtual bool is_halted() const { return halted; }
137 virtual const char *enumerate_protocols(unsigned) const;
138 virtual unsigned get_protocol_speed_steps(const std::string &) const;
140 virtual unsigned add_loco(unsigned, const std::string &, const VehicleType &);
141 virtual void remove_loco(unsigned);
142 virtual void set_loco_speed(unsigned, unsigned);
143 virtual void set_loco_reverse(unsigned, bool);
144 virtual void set_loco_function(unsigned, unsigned, bool);
146 virtual unsigned add_turnout(unsigned, const TrackType &);
147 virtual void remove_turnout(unsigned);
148 virtual void set_turnout(unsigned, unsigned);
149 virtual unsigned get_turnout(unsigned) const;
151 virtual unsigned add_signal(unsigned, const SignalType &);
152 virtual void remove_signal(unsigned);
153 virtual void set_signal(unsigned, unsigned);
154 virtual unsigned get_signal(unsigned) const;
157 MagnetAccessory &add_accessory(unsigned, MagnetAccessory::Type, MagnetAccessory::Symbol);
158 void remove_accessory(unsigned);
159 void set_accessory_state(unsigned, MagnetAccessory::Type, unsigned);
160 unsigned get_accessory_state(unsigned, MagnetAccessory::Type) const;
161 void accessory_state_changed(const MagnetAccessory &) const;
164 virtual unsigned add_sensor(unsigned);
165 virtual void remove_sensor(unsigned);
166 virtual void set_sensor(unsigned, bool) { }
167 virtual bool get_sensor(unsigned) const;
170 virtual void flush();
173 void command(const std::string &, bool = false);
175 void process_reply(const Message &);
176 void process_event(const Message &);
177 void process_object(unsigned, const Message::AttribMap &);
178 Protocol map_protocol(const std::string &) const;
180 unsigned map_address(const std::map<unsigned, T> &, const AddressMap &, unsigned) const;
181 void skip(std::string::iterator &, const std::string::iterator &, const std::string &) const;
182 std::string parse_token(std::string::iterator &, const std::string::iterator &, const std::string &) const;
183 Tag parse_tag(std::string::iterator &, const std::string::iterator &) const;
184 Message parse_message(std::string::iterator &, const std::string::iterator &) const;