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

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
RobeWidget.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 * RobeWidget.h
17 * Read and Write to a USB Widget.
18 * Copyright (C) 2011 Simon Newton
19 */
20
21#ifndef PLUGINS_USBPRO_ROBEWIDGET_H_
22#define PLUGINS_USBPRO_ROBEWIDGET_H_
23
24#include <stdint.h>
25#include <memory>
26#include "ola/Callback.h"
27#include "ola/DmxBuffer.h"
28#include "ola/io/Descriptor.h"
29#include "ola/rdm/DiscoveryAgent.h"
30#include "ola/rdm/QueueingRDMController.h"
31#include "ola/rdm/RDMCommand.h"
32#include "ola/rdm/RDMControllerInterface.h"
33#include "ola/rdm/UID.h"
34#include "ola/rdm/UIDSet.h"
35#include "ola/thread/SchedulingExecutorInterface.h"
36#include "plugins/usbpro/BaseRobeWidget.h"
37
38class RobeWidgetTest;
39
40
41namespace ola {
42namespace plugin {
43namespace usbpro {
44
45/*
46 * A Robe USB Widget implementation.
47 */
48 class RobeWidgetImpl: public BaseRobeWidget,
49 public ola::rdm::DiscoverableRDMControllerInterface,
50 public ola::rdm::DiscoveryTargetInterface {
51 public:
52 explicit RobeWidgetImpl(ola::io::ConnectedDescriptor *descriptor,
53 const ola::rdm::UID &uid);
54 ~RobeWidgetImpl() {}
55
56 void Stop();
57
58 bool SendDMX(const DmxBuffer &buffer);
59
60 void SendRDMRequest(ola::rdm::RDMRequest *request,
61 ola::rdm::RDMCallback *on_complete);
62 void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback);
63 void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback);
64
65 // incoming DMX methods
66 bool ChangeToReceiveMode();
67 // ownership of the callback is transferred
68 void SetDmxCallback(Callback0<void> *callback);
69 const DmxBuffer &FetchDMX() {
70 return m_buffer;
71 }
72
73 // The following are the implementation of DiscoveryTargetInterface
74 void MuteDevice(const ola::rdm::UID &target,
75 MuteDeviceCallback *mute_complete);
76 void UnMuteAll(UnMuteDeviceCallback *unmute_complete);
77 void Branch(const ola::rdm::UID &lower,
78 const ola::rdm::UID &upper,
79 BranchCallback *callback);
80
81 static const int DMX_FRAME_DATA_SIZE;
82
83 private:
84 ola::rdm::RDMCallback *m_rdm_request_callback;
85 MuteDeviceCallback *m_mute_callback;
86 UnMuteDeviceCallback *m_unmute_callback;
87 BranchCallback *m_branch_callback;
88 ola::rdm::DiscoveryAgent m_discovery_agent;
89 std::auto_ptr<Callback0<void> > m_dmx_callback;
90 DmxBuffer m_buffer;
91 std::auto_ptr<const ola::rdm::RDMRequest> m_pending_request;
92 const ola::rdm::UID m_uid;
93 uint8_t m_transaction_number;
94
95 void HandleMessage(uint8_t label,
96 const uint8_t *data,
97 unsigned int length);
98 void HandleRDMResponse(const uint8_t *data,
99 unsigned int length);
100 void HandleDiscoveryResponse(const uint8_t *data,
101 unsigned int length);
102 void DiscoveryComplete(ola::rdm::RDMDiscoveryCallback *callback,
103 bool status,
104 const ola::rdm::UIDSet &uids);
105 void HandleDmxFrame(const uint8_t *data, unsigned int length);
106 bool PackAndSendRDMRequest(uint8_t label,
107 const ola::rdm::RDMRequest *request);
108 static const unsigned int RDM_PADDING_BYTES = 4;
109};
110
111
112/*
113 * A Robe Widget. This mostly just wraps the implementation.
114 */
115 class RobeWidget: public SerialWidgetInterface,
116 public ola::rdm::DiscoverableRDMControllerInterface {
117 public:
118 RobeWidget(ola::io::ConnectedDescriptor *descriptor,
119 const ola::rdm::UID &uid,
120 unsigned int queue_size = 20);
121 ~RobeWidget();
122
123 void Stop() { m_impl->Stop(); }
124
125 ola::io::ConnectedDescriptor *GetDescriptor() const {
126 return m_impl->GetDescriptor();
127 }
128
129 bool SendDMX(const DmxBuffer &buffer) {
130 return m_impl->SendDMX(buffer);
131 }
132
133 void SendRDMRequest(ola::rdm::RDMRequest *request,
134 ola::rdm::RDMCallback *on_complete) {
135 m_controller->SendRDMRequest(request, on_complete);
136 }
137
138 void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
139 m_impl->RunFullDiscovery(callback);
140 }
141
142 void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
143 m_impl->RunIncrementalDiscovery(callback);
144 }
145
146 bool ChangeToReceiveMode() {
147 return m_impl->ChangeToReceiveMode();
148 }
149
150 void SetDmxCallback(Callback0<void> *callback) {
151 m_impl->SetDmxCallback(callback);
152 }
153
154 const DmxBuffer& FetchDMX() {
155 return m_impl->FetchDMX();
156 }
157
158 // the tests access the implementation directly.
159 friend class ::RobeWidgetTest;
160
161 private:
162 // we need to control the order of construction & destruction here so these
163 // are pointers.
164 RobeWidgetImpl *m_impl;
165 ola::rdm::DiscoverableQueueingRDMController *m_controller;
166};
167} // namespace usbpro
168} // namespace plugin
169} // namespace ola
170#endif // PLUGINS_USBPRO_ROBEWIDGET_H_
Callback.h
DmxBuffer.h
A class used to hold a single universe of DMX data.
QueueingRDMController.h
An RDM Controller that queues messages and only sends a single message at a time.
RDMCommand.h
Classes that represent RDM commands.
RDMControllerInterface.h
Definitions and Interfaces to implement an RDMController that sends a single message at a time.
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::DmxBuffer
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
ola::io::ConnectedDescriptor
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition Descriptor.h:283
ola::plugin::usbpro::RobeWidget::SendRDMRequest
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Send a RDM command.
Definition RobeWidget.h:133
ola::plugin::usbpro::RobeWidget::RunFullDiscovery
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start a full discovery operation.
Definition RobeWidget.h:138
ola::plugin::usbpro::RobeWidget::RunIncrementalDiscovery
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start an incremental discovery operation.
Definition RobeWidget.h:142
ola::plugin::usbpro::RobeWidget::RobeWidget
RobeWidget(ola::io::ConnectedDescriptor *descriptor, const ola::rdm::UID &uid, unsigned int queue_size=20)
Definition RobeWidget.cpp:396
ola::plugin::usbpro::RobeWidgetImpl::Branch
void Branch(const ola::rdm::UID &lower, const ola::rdm::UID &upper, BranchCallback *callback)
Definition RobeWidget.cpp:233
ola::plugin::usbpro::RobeWidgetImpl::MuteDevice
void MuteDevice(const ola::rdm::UID &target, MuteDeviceCallback *mute_complete)
Definition RobeWidget.cpp:198
ola::plugin::usbpro::RobeWidgetImpl::SendRDMRequest
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Definition RobeWidget.cpp:103
ola::plugin::usbpro::RobeWidgetImpl::Stop
void Stop()
Definition RobeWidget.cpp:73
ola::plugin::usbpro::RobeWidgetImpl::RunIncrementalDiscovery
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Definition RobeWidget.cpp:168
ola::plugin::usbpro::RobeWidgetImpl::ChangeToReceiveMode
bool ChangeToReceiveMode()
Definition RobeWidget.cpp:181
ola::plugin::usbpro::RobeWidgetImpl::UnMuteAll
void UnMuteAll(UnMuteDeviceCallback *unmute_complete)
Definition RobeWidget.cpp:215
ola::plugin::usbpro::RobeWidgetImpl::RunFullDiscovery
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Definition RobeWidget.cpp:155
ola::plugin::usbpro::RobeWidgetImpl::SendDMX
bool SendDMX(const DmxBuffer &buffer)
Definition RobeWidget.cpp:88
ola::rdm::DiscoverableQueueingRDMController
Definition QueueingRDMController.h:88
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
DiscoveryAgent.h
Implements the RDM Discovery algorithm.
Descriptor.h
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