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"
31#include "ola/rdm/RDMCommand.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 */
51 public:
53 const ola::rdm::UID &uid);
55
56 void Stop();
57
58 bool SendDMX(const DmxBuffer &buffer);
59
61 ola::rdm::RDMCallback *on_complete);
64
65 // incoming DMX methods
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 */
117 public:
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
134 ola::rdm::RDMCallback *on_complete) {
135 m_controller->SendRDMRequest(request, on_complete);
136 }
137
139 m_impl->RunFullDiscovery(callback);
140 }
141
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;
166};
167} // namespace usbpro
168} // namespace plugin
169} // namespace ola
170#endif // PLUGINS_USBPRO_ROBEWIDGET_H_
A class used to hold a single universe of DMX data.
An RDM Controller that queues messages and only sends a single message at a time.
Classes that represent RDM commands.
Definitions and Interfaces to implement an RDMController that sends a single message at a time.
A RDM unique identifier (UID).
A set of UIDs.
The base class for all 1 argument callbacks.
Definition Callback.h:982
The base class for all 2 argument callbacks.
Definition Callback.h:1885
A 0 argument callback which can be called multiple times.
Definition Callback.h:129
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition Descriptor.h:283
Definition BaseRobeWidget.h:38
Definition RobeWidget.h:116
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Send a RDM command.
Definition RobeWidget.h:133
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start a full discovery operation.
Definition RobeWidget.h:138
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start an incremental discovery operation.
Definition RobeWidget.h:142
RobeWidget(ola::io::ConnectedDescriptor *descriptor, const ola::rdm::UID &uid, unsigned int queue_size=20)
Definition RobeWidget.cpp:396
Definition RobeWidget.h:50
void Branch(const ola::rdm::UID &lower, const ola::rdm::UID &upper, BranchCallback *callback)
Definition RobeWidget.cpp:233
void MuteDevice(const ola::rdm::UID &target, MuteDeviceCallback *mute_complete)
Definition RobeWidget.cpp:198
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Definition RobeWidget.cpp:103
void Stop()
Definition RobeWidget.cpp:73
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Definition RobeWidget.cpp:168
bool ChangeToReceiveMode()
Definition RobeWidget.cpp:181
void UnMuteAll(UnMuteDeviceCallback *unmute_complete)
Definition RobeWidget.cpp:215
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Definition RobeWidget.cpp:155
bool SendDMX(const DmxBuffer &buffer)
Definition RobeWidget.cpp:88
Definition SerialWidgetInterface.h:38
Definition QueueingRDMController.h:88
The interface that can send RDM commands, as well as perform discovery operations.
Definition RDMControllerInterface.h:104
An asynchronous RDM Discovery algorithm.
Definition DiscoveryAgent.h:135
The interface used by the DiscoveryTarget to send RDM commands.
Definition DiscoveryAgent.h:53
void SendRDMRequest(RDMRequest *request, RDMCallback *on_complete)
Definition QueueingRDMController.cpp:96
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition RDMCommand.h:234
Represents a RDM UID.
Definition UID.h:57
Represents a set of RDM UIDs.
Definition UIDSet.h:48
Implements the RDM Discovery algorithm.
The namespace containing all OLA symbols.
Definition Credentials.cpp:44