]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/locomotive.h
Add networking library and a remote control program
[r2c2.git] / source / libmarklin / locomotive.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_LOCOMOTIVE_H_
9 #define LIBMARKLIN_LOCOMOTIVE_H_
10
11 #include <list>
12 #include <string>
13 #include <sigc++/signal.h>
14 #include "constants.h"
15
16 namespace Marklin {
17
18 class Control;
19 class LocoType;
20 class Reply;
21
22 class Locomotive
23 {
24 public:
25         sigc::signal<void, unsigned> signal_speed_changing;
26         sigc::signal<void, unsigned> signal_speed_changed;
27         sigc::signal<void, bool> signal_reverse_changed;
28         sigc::signal<void, unsigned, bool> signal_function_changed;
29
30 private:
31         const LocoType &type;
32         Control &control;
33         unsigned addr;
34         unsigned speed;
35         bool reverse;
36         unsigned funcs;
37
38 public:
39         Locomotive(const LocoType &, Control &, unsigned);
40
41         const LocoType &get_type() const { return type; }
42         unsigned get_address() const { return addr; }
43         void set_speed(unsigned);
44         void set_reverse(bool);
45         void set_function(unsigned, bool);
46         unsigned get_speed() const { return speed; }
47         bool get_reverse() const { return reverse; }
48         bool get_function(unsigned f) const { return (funcs>>f)&1; }
49         unsigned get_functions() const { return funcs; }
50         void refresh_status();
51 private:
52         void send_command(bool);
53         void status_reply(const Reply &);
54         bool reverse_timeout();
55 };
56
57 } // namespace Marklin
58
59 #endif