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 void add_loco(unsigned, const std::string &, const VehicleType &);
141 virtual void set_loco_speed(unsigned, unsigned);
142 virtual void set_loco_reverse(unsigned, bool);
143 virtual void set_loco_function(unsigned, unsigned, bool);
145 virtual void add_turnout(unsigned, const TrackType &);
146 virtual void set_turnout(unsigned, unsigned);
147 virtual unsigned get_turnout(unsigned) const;
149 virtual void add_signal(unsigned, const SignalType &);
150 virtual void set_signal(unsigned, unsigned);
151 virtual unsigned get_signal(unsigned) const;
154 MagnetAccessory &add_accessory(unsigned, MagnetAccessory::Type, MagnetAccessory::Symbol);
155 void set_accessory_state(unsigned, MagnetAccessory::Type, unsigned);
156 unsigned get_accessory_state(unsigned, MagnetAccessory::Type) const;
157 void accessory_state_changed(const MagnetAccessory &) const;
160 virtual void add_sensor(unsigned);
161 virtual void set_sensor(unsigned, bool) { }
162 virtual bool get_sensor(unsigned) const;
165 virtual void flush();
168 void command(const std::string &, bool = false);
170 void process_reply(const Message &);
171 void process_event(const Message &);
172 void process_object(unsigned, const Message::AttribMap &);
173 Protocol map_protocol(const std::string &) const;
175 unsigned map_address(const std::map<unsigned, T> &, const AddressMap &, unsigned) const;
176 void skip(std::string::iterator &, const std::string::iterator &, const std::string &) const;
177 std::string parse_token(std::string::iterator &, const std::string::iterator &, const std::string &) const;
178 Tag parse_tag(std::string::iterator &, const std::string::iterator &) const;
179 Message parse_message(std::string::iterator &, const std::string::iterator &) const;