Open Lighting Architecture
0.9.3
Main Page
Modules
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
plugins
usbpro
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
38
class
RobeWidgetTest;
39
40
41
namespace
ola {
42
namespace
plugin {
43
namespace
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
(
const
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
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
(
const
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_
Generated on Sun Nov 16 2014 15:43:11 for Open Lighting Architecture by
1.8.1.2