Open Lighting Architecture  0.9.3
 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 /*
38  * Contains information about the Robe USB device.
39 */
41  public:
43  : uid(0, 0),
44  hardware_version(0),
45  software_version(0),
46  eeprom_version(0) {
47  }
49  uid(other.uid),
50  hardware_version(other.hardware_version),
51  software_version(other.software_version),
52  eeprom_version(other.eeprom_version) {
53  }
54 
55  ola::rdm::UID uid;
56  uint8_t hardware_version;
57  uint8_t software_version;
58  uint8_t eeprom_version;
59 };
60 
61 
62 /*
63  * Handles widget discovery for Robe devices.
64  */
66  public:
67  typedef ola::Callback2<void,
70  typedef ola::Callback1<void,
72 
75  SuccessHandler *on_success,
76  FailureHandler *on_failure,
77  unsigned int timeout = 200);
79 
80  bool Discover(ola::io::ConnectedDescriptor *descriptor);
81 
82  private:
83  // Hold the discovery state for a widget
84  class DiscoveryState {
85  public:
86  DiscoveryState():
87  discovery_state(INFO_SENT),
88  timeout_id(ola::thread::INVALID_TIMEOUT) {
89  }
90  ~DiscoveryState() {}
91 
92  typedef enum {
93  INFO_SENT,
94  UID_SENT,
95  } widget_state;
96 
97  RobeWidgetInformation information;
98  widget_state discovery_state;
99  ola::thread::timeout_id timeout_id;
100  };
101 
103  const unsigned int m_timeout_ms;
104  std::auto_ptr<SuccessHandler> m_callback;
105  std::auto_ptr<FailureHandler> m_failure_callback;
106 
107  typedef std::map<DispatchingRobeWidget*, DiscoveryState> WidgetStateMap;
108  WidgetStateMap m_widgets;
109 
110  void HandleMessage(DispatchingRobeWidget *widget,
111  uint8_t label,
112  const uint8_t *data,
113  unsigned int length);
114  void HandleInfoMessage(DispatchingRobeWidget *widget,
115  const uint8_t *data,
116  unsigned int length);
117  void HandleUidMessage(DispatchingRobeWidget *widget,
118  const uint8_t *data,
119  unsigned int length);
120  void WidgetRemoved(DispatchingRobeWidget *widget);
121  void FailWidget(DispatchingRobeWidget *widget);
122  void CleanupWidget(DispatchingRobeWidget *widget);
123  void DispatchWidget(DispatchingRobeWidget *widget,
124  const RobeWidgetInformation *info);
125  void RemoveTimeout(DiscoveryState *discovery_state);
126  void SetupTimeout(DispatchingRobeWidget *widget,
127  DiscoveryState *discovery_state);
128  bool IsUnlocked(const RobeWidgetInformation &info);
129 
130  static const uint32_t MODEL_MASK = 0xffff0000;
131  static const uint32_t RUI_DEVICE_PREFIX = 0x01000000;
132  static const uint32_t WTX_DEVICE_PREFIX = 0x02000000;
133  // 0x14 is good, 0xe is bad. actual version is probably somewhere in
134  // between.
135  static const uint8_t RUI_MIN_UNLOCKED_SOFTWARE_VERSION = 0x14;
136  // we need at least v 11 for decent RDM support
137  static const uint8_t WTX_MIN_SOFTWARE_VERSION = 0x0b;
138 };
139 } // namespace usbpro
140 } // namespace plugin
141 } // namespace ola
142 #endif // PLUGINS_USBPRO_ROBEWIDGETDETECTOR_H_