Open Lighting Architecture: plugins/usbpro/EnttecUsbProWidgetImpl.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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
33namespace ola {
34namespace plugin {
35namespace usbpro {
36
37enum {
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
62 struct OperationLabels {
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
81 class EnttecPortImpl
82 : public ola::rdm::DiscoverableRDMControllerInterface,
83 public ola::rdm::DiscoveryTargetInterface {
84 public:
85 typedef ola::Callback3<bool, uint8_t, const uint8_t*, unsigned int>
86 SendCallback;
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_
Callback.h
Constants.h
Constants used throughout OLA.
RDMCommand.h
Classes that represent RDM commands.
UID.h
A RDM unique identifier (UID).
UIDSet.h
A set of UIDs.
ola::Callback0
A 0 argument callback which can be called multiple times.
Definition Callback.h:129
ola::Callback3
A 3 argument callback which can be called multiple times.
Definition Callback.h:2838
ola::DmxBuffer
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
ola::Watchdog
Detects if an operation stalls.
Definition Watchdog.h:70
ola::plugin::usbpro::EnttecPortImpl::SendDMX
bool SendDMX(const DmxBuffer &buffer)
Definition EnttecUsbProWidget.cpp:135
ola::plugin::usbpro::EnttecPortImpl::HandleIncomingDataMessage
void HandleIncomingDataMessage(const uint8_t *data, unsigned int length)
Definition EnttecUsbProWidget.cpp:432
ola::plugin::usbpro::EnttecPortImpl::UnMuteAll
void UnMuteAll(UnMuteDeviceCallback *unmute_complete)
Definition EnttecUsbProWidget.cpp:307
ola::plugin::usbpro::EnttecPortImpl::SendRDMRequest
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Definition EnttecUsbProWidget.cpp:231
ola::plugin::usbpro::EnttecPortImpl::SetDMXCallback
void SetDMXCallback(ola::Callback0< void > *callback)
Definition EnttecUsbProWidget.cpp:152
ola::plugin::usbpro::EnttecPortImpl::RunFullDiscovery
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Definition EnttecUsbProWidget.cpp:263
ola::plugin::usbpro::EnttecPortImpl::HandleRDMTimeout
void HandleRDMTimeout(unsigned int length)
Definition EnttecUsbProWidget.cpp:355
ola::plugin::usbpro::EnttecPortImpl::SetParameters
bool SetParameters(uint8_t break_time, uint8_t mab_time, uint8_t rate)
Definition EnttecUsbProWidget.cpp:199
ola::plugin::usbpro::EnttecPortImpl::Branch
void Branch(const ola::rdm::UID &lower, const ola::rdm::UID &upper, BranchCallback *callback)
Definition EnttecUsbProWidget.cpp:325
ola::plugin::usbpro::EnttecPortImpl::MuteDevice
void MuteDevice(const ola::rdm::UID &target, MuteDeviceCallback *mute_complete)
Definition EnttecUsbProWidget.cpp:288
ola::plugin::usbpro::EnttecPortImpl::RunIncrementalDiscovery
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Definition EnttecUsbProWidget.cpp:274
ola::plugin::usbpro::EnttecPortImpl::GetParameters
void GetParameters(usb_pro_params_callback *callback)
Definition EnttecUsbProWidget.cpp:178
ola::rdm::DiscoverableRDMControllerInterface
The interface that can send RDM commands, as well as perform discovery operations.
Definition RDMControllerInterface.h:104
ola::rdm::DiscoveryAgent
An asynchronous RDM Discovery algorithm.
Definition DiscoveryAgent.h:135
ola::rdm::DiscoveryTargetInterface
The interface used by the DiscoveryTarget to send RDM commands.
Definition DiscoveryAgent.h:53
ola::rdm::DiscoveryTargetInterface::MuteDeviceCallback
ola::BaseCallback1< void, bool > MuteDeviceCallback
The callback run when a mute command completes.
Definition DiscoveryAgent.h:60
ola::rdm::DiscoveryTargetInterface::BranchCallback
ola::BaseCallback2< void, const uint8_t *, unsigned int > BranchCallback
The callback run when a DUB command completes.
Definition DiscoveryAgent.h:73
ola::rdm::DiscoveryTargetInterface::UnMuteDeviceCallback
ola::BaseCallback0< void > UnMuteDeviceCallback
The callback run when an unmute command completes.
Definition DiscoveryAgent.h:65
ola::rdm::RDMRequest
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition RDMCommand.h:234
ola::rdm::UID
Represents a RDM UID.
Definition UID.h:57
ola::rdm::UIDSet
Represents a set of RDM UIDs.
Definition UIDSet.h:48
ola::plugin::usbpro
Code for Enttec USB Pro devices and others using the same protocol.
ola::plugin
Code for supported devices and protocols.
ola::rdm::RDMCallback
ola::BaseCallback1< void, RDMReply * > RDMCallback
The callback run when a RDM request completes.
Definition RDMControllerInterface.h:52
ola::rdm::RDMDiscoveryCallback
ola::BaseCallback1< void, const ola::rdm::UIDSet & > RDMDiscoveryCallback
The callback run when a discovery operation completes.
Definition RDMControllerInterface.h:68
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::plugin::usbpro::OperationLabels
Definition EnttecUsbProWidgetImpl.h:62