Open Lighting Architecture  Latest Git
EnttecUsbProWidgetImpl.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  * EnttecUsbProWidgetImpl.h
17  * The Enttec USB Pro Widget
18  * Copyright (C) 2013 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBPRO_ENTTECUSBPROWIDGETIMPL_H_
22 #define PLUGINS_USBPRO_ENTTECUSBPROWIDGETIMPL_H_
23 
24 #include <deque>
25 #include <memory>
26 #include "ola/Callback.h"
27 #include "ola/Constants.h"
28 #include "ola/rdm/RDMCommand.h"
29 #include "ola/rdm/UID.h"
30 #include "ola/rdm/UIDSet.h"
31 #include "ola/util/Watchdog.h"
32 
33 namespace ola {
34 namespace plugin {
35 namespace usbpro {
36 
37 enum {
38  // port 1 labels
39  GET_PARAMS_1 = 3,
40  SET_PARAMS_1 = 4,
41  RECEIVED_DMX_LABEL_1 = 5,
42  SEND_DMX_1 = 6,
43  SEND_RDM_1 = 7,
44  CHANGE_TO_RX_1 = 8,
45  COS_DMX_1 = 9,
46  RDM_DISCOVERY_1 = 11,
47  RDM_TIMEOUT_1 = 12,
48 
49  // port 2 labels, these are tied to the OLA API key.
50  GET_PARAMS_2 = 137,
51  SET_PARAMS_2 = 180,
52  RECEIVED_DMX_LABEL_2 = 156,
53  SEND_DMX_2 = 135,
54  SEND_RDM_2 = 236,
55  CHANGE_TO_RX_2 = 197,
56  COS_DMX_2 = 164,
57  RDM_DISCOVERY_2 = 196,
58  RDM_TIMEOUT_2 = 201,
59 };
60 
61 // Maps operations to label values
63  uint8_t get_params;
64  uint8_t set_params;
65  uint8_t recv_dmx;
66  uint8_t send_dmx;
67  uint8_t send_rdm;
68  uint8_t change_to_rx_mode;
69  uint8_t cos_dmx;
70  uint8_t rdm_timeout;
71  uint8_t rdm_discovery;
72 
73  static OperationLabels Port1Operations();
74  static OperationLabels Port2Operations();
75 };
76 
77 
84  public:
87 
88  EnttecPortImpl(const OperationLabels &ops, const ola::rdm::UID &uid,
89  SendCallback *send_cb, bool no_rdm_dub_timeout = false);
90 
91  void Stop();
92 
93  bool SendDMX(const DmxBuffer &buffer);
94  const DmxBuffer &FetchDMX() const { return m_input_buffer; }
95  void SetDMXCallback(ola::Callback0<void> *callback);
96 
97  bool ChangeToReceiveMode(bool change_only);
98  void GetParameters(usb_pro_params_callback *callback);
99  bool SetParameters(uint8_t break_time, uint8_t mab_time, uint8_t rate);
100 
101  // the following are from DiscoverableRDMControllerInterface
102  void SendRDMRequest(ola::rdm::RDMRequest *request,
103  ola::rdm::RDMCallback *on_complete);
104  void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback);
105  void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback);
106 
107  // The following are the implementation of DiscoveryTargetInterface
108  void MuteDevice(const ola::rdm::UID &target,
109  MuteDeviceCallback *mute_complete);
110  void UnMuteAll(UnMuteDeviceCallback *unmute_complete);
111  void Branch(const ola::rdm::UID &lower,
112  const ola::rdm::UID &upper,
113  BranchCallback *callback);
114 
115  // Called by the EnttecUsbProWidgetImpl
116  void HandleRDMTimeout(unsigned int length);
117  void HandleParameters(const uint8_t *data, unsigned int length);
118  void HandleIncomingDataMessage(const uint8_t *data, unsigned int length);
119  void HandleDMXDiff(const uint8_t *data, unsigned int length);
120 
121  void ClockWatchdog();
122  void WatchdogFired();
123 
124  private:
125  SendCallback *m_send_cb;
126  OperationLabels m_ops;
127  bool m_active;
128  Watchdog m_watchdog;
129 
130  // RX DMX
131  DmxBuffer m_input_buffer;
132  std::auto_ptr<ola::Callback0<void> > m_dmx_callback;
133 
134  // widget params
135  std::deque<usb_pro_params_callback*> m_outstanding_param_callbacks;
136 
137  // RDM send
138  ola::rdm::DiscoveryAgent m_discovery_agent;
139  const ola::rdm::UID m_uid;
140  uint8_t m_transaction_number;
141  ola::rdm::RDMCallback *m_rdm_request_callback;
142  std::auto_ptr<const ola::rdm::RDMRequest> m_pending_request;
143 
144  // RDM Discovery
145  MuteDeviceCallback *m_mute_callback;
146  UnMuteDeviceCallback *m_unmute_callback;
147  BranchCallback *m_branch_callback;
148  // holds the discovery response while we're waiting for the timeout message
149  const uint8_t *m_discovery_response;
150  unsigned int m_discovery_response_size;
151  bool m_no_rdm_dub_timeout;
152 
153  void HandleDMX(const uint8_t *data, unsigned int length);
154  void DiscoveryComplete(ola::rdm::RDMDiscoveryCallback *callback,
155  bool status,
156  const ola::rdm::UIDSet &uids);
157  bool PackAndSendRDMRequest(uint8_t label,
158  const ola::rdm::RDMRequest *request);
159  bool IsDUBRequest(const ola::rdm::RDMRequest *request);
160 
161  static const unsigned int PORT_ID = 1;
162  // This gives a limit between 1 and 2s.
163  static const unsigned int WATCHDOG_LIMIT = 2;
164 };
165 } // namespace usbpro
166 } // namespace plugin
167 } // namespace ola
168 #endif // PLUGINS_USBPRO_ENTTECUSBPROWIDGETIMPL_H_
Represents a set of RDM UIDs.
Definition: UIDSet.h:48
The interface that can send RDM commands, as well as perform discovery operations.
Definition: RDMControllerInterface.h:104
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition: RDMCommand.h:234
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A RDM unique identifier (UID).
Constants used throughout OLA.
A set of UIDs.
Definition: EnttecUsbProWidgetImpl.h:81
A 3 argument callback which can be called multiple times.
Definition: Callback.h:2838
The base class for all 1 argument callbacks.
Definition: Callback.h:982
An asynchronous RDM Discovery algorithm.
Definition: DiscoveryAgent.h:135
Definition: EnttecUsbProWidgetImpl.h:62
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
The base class for all 2 argument callbacks.
Definition: Callback.h:1885
Detects if an operation stalls.
Definition: Watchdog.h:70
The interface used by the DiscoveryTarget to send RDM commands.
Definition: DiscoveryAgent.h:53
A 2 argument callback which deletes itself after it&#39;s run.
Definition: Callback.h:1907
Classes that represent RDM commands.