Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RobeWidgetDetector.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * RobeWidgetDetector.h
17  * Runs the Robe discovery routine.
18  * Copyright (C) 2011 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBPRO_ROBEWIDGETDETECTOR_H_
22 #define PLUGINS_USBPRO_ROBEWIDGETDETECTOR_H_
23 
24 #include <ola/Callback.h>
25 #include <ola/rdm/UID.h>
26 #include <ola/thread/SchedulingExecutorInterface.h>
27 #include <memory>
28 #include <map>
29 #include <string>
30 #include "plugins/usbpro/BaseRobeWidget.h"
31 #include "plugins/usbpro/WidgetDetectorInterface.h"
32 
33 namespace ola {
34 namespace plugin {
35 namespace usbpro {
36 
37 using std::auto_ptr;
38 
39 /*
40  * Contains information about the Robe USB device.
41 */
43  public:
45  : uid(0, 0),
46  hardware_version(0),
47  software_version(0),
48  eeprom_version(0) {
49  }
51  uid(other.uid),
52  hardware_version(other.hardware_version),
53  software_version(other.software_version),
54  eeprom_version(other.eeprom_version) {
55  }
56 
57  ola::rdm::UID uid;
58  uint8_t hardware_version;
59  uint8_t software_version;
60  uint8_t eeprom_version;
61 };
62 
63 
64 /*
65  * Handles widget discovery for Robe devices.
66  */
68  public:
69  typedef ola::Callback2<void,
72  typedef ola::Callback1<void,
74 
77  SuccessHandler *on_success,
78  FailureHandler *on_failure,
79  unsigned int timeout = 200);
81 
82  bool Discover(ola::io::ConnectedDescriptor *descriptor);
83 
84  private:
85  // Hold the discovery state for a widget
86  class DiscoveryState {
87  public:
88  DiscoveryState():
89  discovery_state(INFO_SENT),
90  timeout_id(ola::thread::INVALID_TIMEOUT) {
91  }
92  ~DiscoveryState() {}
93 
94  typedef enum {
95  INFO_SENT,
96  UID_SENT,
97  } widget_state;
98 
99  RobeWidgetInformation information;
100  widget_state discovery_state;
101  ola::thread::timeout_id timeout_id;
102  };
103 
105  const unsigned int m_timeout_ms;
106  auto_ptr<SuccessHandler> m_callback;
107  auto_ptr<FailureHandler> m_failure_callback;
108 
109  typedef std::map<DispatchingRobeWidget*, DiscoveryState> WidgetStateMap;
110  WidgetStateMap m_widgets;
111 
112  void HandleMessage(DispatchingRobeWidget *widget,
113  uint8_t label,
114  const uint8_t *data,
115  unsigned int length);
116  void HandleInfoMessage(DispatchingRobeWidget *widget,
117  const uint8_t *data,
118  unsigned int length);
119  void HandleUidMessage(DispatchingRobeWidget *widget,
120  const uint8_t *data,
121  unsigned int length);
122  void WidgetRemoved(DispatchingRobeWidget *widget);
123  void FailWidget(DispatchingRobeWidget *widget);
124  void CleanupWidget(DispatchingRobeWidget *widget);
125  void DispatchWidget(DispatchingRobeWidget *widget,
126  const RobeWidgetInformation *info);
127  void RemoveTimeout(DiscoveryState *discovery_state);
128  void SetupTimeout(DispatchingRobeWidget *widget,
129  DiscoveryState *discovery_state);
130  bool IsUnlocked(const RobeWidgetInformation &info);
131 
132  static const uint32_t MODEL_MASK = 0xffff0000;
133  static const uint32_t RUI_DEVICE_PREFIX = 0x01000000;
134  static const uint32_t WTX_DEVICE_PREFIX = 0x02000000;
135  // 0x14 is good, 0xe is bad. actual version is probably somewhere in
136  // between.
137  static const uint8_t RUI_MIN_UNLOCKED_SOFTWARE_VERSION = 0x14;
138  // we need at least v 11 for decent RDM support
139  static const uint8_t WTX_MIN_SOFTWARE_VERSION = 0x0b;
140 };
141 } // namespace usbpro
142 } // namespace plugin
143 } // namespace ola
144 #endif // PLUGINS_USBPRO_ROBEWIDGETDETECTOR_H_