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,
78 Msp::Time::TimeStamp off_timeout;
86 Msp::Time::TimeStamp off_timeout;
95 unsigned char data[8];
102 std::map<unsigned, Locomotive> locos;
103 std::map<unsigned, Turnout> turnouts;
104 std::map<unsigned, Sensor> sensors;
106 std::list<CommandSlot> queue;
108 Msp::Time::TimeStamp next_event_query;
111 Intellibox(const std::string &);
113 virtual void set_power(bool);
114 virtual bool get_power() const { return power; }
115 virtual void halt(bool);
116 virtual bool is_halted() const { return halted; }
118 virtual void add_loco(unsigned);
119 virtual void set_loco_speed(unsigned, unsigned);
120 virtual void set_loco_reverse(unsigned, bool);
121 virtual void set_loco_function(unsigned, unsigned, bool);
123 virtual void add_turnout(unsigned);
124 virtual void set_turnout(unsigned, bool);
125 virtual bool get_turnout(unsigned) const;
127 virtual void add_sensor(unsigned);
128 virtual void set_sensor(unsigned, bool) { }
129 virtual bool get_sensor(unsigned) const;
132 virtual void flush();
135 void command(Command);
136 void command(Command, const unsigned char *, unsigned);
137 void command(Command, unsigned, const unsigned char *, unsigned);
138 void loco_command(unsigned, unsigned, bool, unsigned);
139 void turnout_command(unsigned, bool, bool);
140 void process_reply(const Msp::Time::TimeStamp &);
141 unsigned read_all(unsigned char *, unsigned);
142 unsigned read_status(Error *);
143 void error(Command, Error);
146 } // namespace Marklin