3 This file is part of the MSP Märklin suite
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #ifndef LIBMARKLIN_INTELLIBOX_H_
9 #define LIBMARKLIN_INTELLIBOX_H_
12 #include <msp/time/timestamp.h>
17 class Intellibox: public Driver
28 CMD_TURNOUT_FREE=0x93,
29 CMD_TURNOUT_STATUS=0x94,
30 CMD_TURNOUT_GROUP_STATUS=0x95,
31 CMD_SENSOR_STATUS=0x98,
32 CMD_SENSOR_REPORT=0x99,
33 CMD_SENSOR_PARAM_SET=0x9D,
40 CMD_EVENT_TURNOUT=0xCA,
50 ERR_NO_LOK_SPACE=0x8, // No space in lok command buffer
51 ERR_NO_TURNOUT_SPACE, // No space in turnout command buffer
52 ERR_NO_DATA, // "no Lok status available (Lok is not in a slot)"
53 ERR_NO_SLOT, // "there is no slot available"
59 ERR_LOW_TURNOUT_SPACE=0x40,
79 Msp::Time::TimeStamp off_timeout;
87 Msp::Time::TimeStamp off_timeout;
96 unsigned char data[8];
103 std::map<unsigned, Locomotive> locos;
104 std::map<unsigned, Turnout> turnouts;
105 std::map<unsigned, Sensor> sensors;
107 std::list<CommandSlot> queue;
109 Msp::Time::TimeStamp next_event_query;
112 Intellibox(const std::string &);
114 virtual void set_power(bool);
115 virtual bool get_power() const { return power; }
116 virtual void halt(bool);
117 virtual bool is_halted() const { return halted; }
119 virtual const char *enumerate_protocols(unsigned) const;
120 virtual unsigned get_protocol_speed_steps(const std::string &) const;
121 virtual void add_loco(unsigned, const std::string &);
122 virtual void set_loco_speed(unsigned, unsigned);
123 virtual void set_loco_reverse(unsigned, bool);
124 virtual void set_loco_function(unsigned, unsigned, bool);
126 virtual void add_turnout(unsigned);
127 virtual void set_turnout(unsigned, bool);
128 virtual bool get_turnout(unsigned) const;
130 virtual void add_sensor(unsigned);
131 virtual void set_sensor(unsigned, bool) { }
132 virtual bool get_sensor(unsigned) const;
135 virtual void flush();
138 void command(Command);
139 void command(Command, const unsigned char *, unsigned);
140 void command(Command, unsigned, const unsigned char *, unsigned);
141 void loco_command(unsigned, unsigned, bool, unsigned);
142 void turnout_command(unsigned, bool, bool);
143 void process_reply(const Msp::Time::TimeStamp &);
144 unsigned read_all(unsigned char *, unsigned);
145 unsigned read_status(Error *);
146 void error(Command, Error);
149 } // namespace Marklin