#include <list>
#include <string>
+#include <msp/time/timer.h>
#include <msp/time/timestamp.h>
#include "constants.h"
#include "sensor.h"
class Control
{
+private:
+ int serial_fd;
+ bool p50_enabled;
+ bool power;
+ std::list<Command> queue;
+ std::map<unsigned, Turnout *> turnouts;
+ std::map<unsigned, Locomotive *> locomotives;
+ std::map<unsigned, Sensor *> sensors;
+ Msp::Time::TimeStamp next_event_query;
+ bool poll_sensors;
+ bool debug;
+ Msp::Time::Timer timer;
+
public:
sigc::signal<void, unsigned, bool> signal_turnout_event;
sigc::signal<void, unsigned, bool> signal_sensor_event;
Control();
void set_power(bool);
- void set_debug(bool d) { debug=d; }
bool get_power() const { return power; }
- const TurnoutMap &get_turnouts() const { return turnouts; }
- Turnout *get_turnout(unsigned) const;
- Locomotive *get_locomotive(unsigned) const;
- Sensor *get_sensor(unsigned) const;
+ void set_debug(bool d) { debug=d; }
+ //const TurnoutMap &get_turnouts() const { return turnouts; }
+ const std::map<unsigned, Sensor *> &get_sensors() const { return sensors; }
unsigned get_queue_length() const { return queue.size(); }
void open(const std::string &);
Command &command(const std::string &);
- void add_turnout(Turnout *);
- void add_locomotive(Locomotive *);
- void add_sensor(Sensor *);
+ void add_turnout(Turnout &);
+ Turnout &get_turnout(unsigned) const;
+ void add_locomotive(Locomotive &);
+ Locomotive &get_locomotive(unsigned) const;
+ void add_sensor(Sensor &);
+ Sensor &get_sensor(unsigned) const;
void tick();
+ Msp::Time::Timer::Slot &set_timer(const Msp::Time::TimeDelta &);
~Control();
private:
- int serial_fd;
- bool p50_enabled;
- bool power;
- std::list<Command> queue;
- TurnoutMap turnouts;
- LocomotiveSeq locomotives;
- SensorMap sensors;
- Msp::Time::TimeStamp next_event_query;
- bool poll_sensors;
- bool debug;
-
void read_all(int, char *, int);
std::string read_reply(Cmd);
void event_query_done(Error, const std::string &);