Open Lighting Architecture  Latest Git
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  void operator=(const RobeWidgetInformation& other) {
60  uid = other.uid;
61  hardware_version = other.hardware_version;
62  software_version = other.software_version;
63  eeprom_version = other.eeprom_version;
64  }
65 };
66 
67 
68 /*
69  * Handles widget discovery for Robe devices.
70  */
72  public:
73  typedef ola::Callback2<void,
76  typedef ola::Callback1<void,
77  ola::io::ConnectedDescriptor*> FailureHandler;
78 
81  SuccessHandler *on_success,
82  FailureHandler *on_failure,
83  unsigned int timeout = 200);
85 
86  bool Discover(ola::io::ConnectedDescriptor *descriptor);
87 
88  private:
89  // Hold the discovery state for a widget
90  class DiscoveryState {
91  public:
92  DiscoveryState():
93  discovery_state(INFO_SENT),
94  timeout_id(ola::thread::INVALID_TIMEOUT) {
95  }
96  ~DiscoveryState() {}
97 
98  typedef enum {
99  INFO_SENT,
100  UID_SENT,
101  } widget_state;
102 
103  RobeWidgetInformation information;
104  widget_state discovery_state;
105  ola::thread::timeout_id timeout_id;
106  };
107 
109  const unsigned int m_timeout_ms;
110  std::auto_ptr<SuccessHandler> m_callback;
111  std::auto_ptr<FailureHandler> m_failure_callback;
112 
113  typedef std::map<DispatchingRobeWidget*, DiscoveryState> WidgetStateMap;
114  WidgetStateMap m_widgets;
115 
116  void HandleMessage(DispatchingRobeWidget *widget,
117  uint8_t label,
118  const uint8_t *data,
119  unsigned int length);
120  void HandleInfoMessage(DispatchingRobeWidget *widget,
121  const uint8_t *data,
122  unsigned int length);
123  void HandleUidMessage(DispatchingRobeWidget *widget,
124  const uint8_t *data,
125  unsigned int length);
126  void WidgetRemoved(DispatchingRobeWidget *widget);
127  void FailWidget(DispatchingRobeWidget *widget);
128  void CleanupWidget(DispatchingRobeWidget *widget);
129  void DispatchWidget(DispatchingRobeWidget *widget,
130  const RobeWidgetInformation *info);
131  void RemoveTimeout(DiscoveryState *discovery_state);
132  void SetupTimeout(DispatchingRobeWidget *widget,
133  DiscoveryState *discovery_state);
134  bool IsUnlocked(const RobeWidgetInformation &info);
135 
136  static const uint32_t MODEL_MASK = 0xffff0000;
137  static const uint32_t RUI_DEVICE_PREFIX = 0x01000000;
138  static const uint32_t WTX_DEVICE_PREFIX = 0x02000000;
139  // 0x14 is good, 0xe is bad. actual version is probably somewhere in
140  // between.
141  static const uint8_t RUI_MIN_UNLOCKED_SOFTWARE_VERSION = 0x14;
142  // we need at least v 11 for decent RDM support
143  static const uint8_t WTX_MIN_SOFTWARE_VERSION = 0x0b;
144 };
145 } // namespace usbpro
146 } // namespace plugin
147 } // namespace ola
148 #endif // PLUGINS_USBPRO_ROBEWIDGETDETECTOR_H_
static const timeout_id INVALID_TIMEOUT
An invalid / uninitialized timeout_id.
Definition: SchedulerInterface.h:39
Combines the ExecutorInterface and the SchedulerInterface.
Definition: SchedulingExecutorInterface.h:33
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
A RDM unique identifier (UID).
void * timeout_id
A timeout handle which can later be used to cancel a timeout.
Definition: SchedulerInterface.h:34
Definition: RobeWidgetDetector.h:40
Definition: WidgetDetectorInterface.h:39
A 2 argument callback which can be called multiple times.
Definition: Callback.h:1895
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: BaseRobeWidget.h:105
Definition: RobeWidgetDetector.h:71
A 1 argument callback which can be called multiple times.
Definition: Callback.h:992