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

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
UsbProDevice.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 * UsbProDevice.h
17 * A Enttec USB Pro device
18 * Copyright (C) 2006 Simon Newton
19 */
20
21#ifndef PLUGINS_USBPRO_USBPRODEVICE_H_
22#define PLUGINS_USBPRO_USBPRODEVICE_H_
23
24#include <string>
25#include <vector>
26#include "ola/DmxBuffer.h"
27#include "olad/TokenBucket.h"
28#include "olad/PluginAdaptor.h"
29#include "olad/Port.h"
30
31#include "plugins/usbpro/EnttecUsbProWidget.h"
32#include "plugins/usbpro/UsbSerialDevice.h"
33#include "plugins/usbpro/messages/UsbProConfigMessages.pb.h"
34
35namespace ola {
36namespace plugin {
37namespace usbpro {
38
39/*
40 * An Enttec Usb Pro device
41 */
42 class UsbProDevice: public UsbSerialDevice {
43 public:
44 UsbProDevice(ola::PluginAdaptor *plugin_adaptor,
45 ola::AbstractPlugin *owner,
46 const std::string &name,
47 EnttecUsbProWidget *widget,
48 uint32_t serial,
49 uint16_t firmware_version,
50 unsigned int fps_limit);
51
52 std::string DeviceId() const { return m_serial; }
53
54 void Configure(ola::rpc::RpcController *controller,
55 const std::string &request,
56 std::string *response,
57 ConfigureCallback *done);
58
59 bool AllowMultiPortPatching() const { return true; }
60
61 protected:
62 void PrePortStop();
63
64 private:
65 struct PortParams {
66 bool got_parameters;
67 uint8_t break_time;
68 uint8_t mab_time;
69 uint8_t rate;
70 };
71
72 void UpdateParams(unsigned int port_id, bool status,
73 const usb_pro_parameters &params);
74
75 void HandleParametersRequest(ola::rpc::RpcController *controller,
76 const ola::plugin::usbpro::Request *request,
77 std::string *response,
78 ConfigureCallback *done);
79
80 void HandleParametersResponse(ola::rpc::RpcController *controller,
81 std::string *response,
82 ConfigureCallback *done,
83 unsigned int port_id,
84 bool status,
85 const usb_pro_parameters &params);
86
87 void HandleSerialRequest(ola::rpc::RpcController *controller,
88 const ola::plugin::usbpro::Request *request,
89 std::string *response,
90 ConfigureCallback *done);
91
92 void HandlePortAssignmentRequest(ola::rpc::RpcController *controller,
93 const ola::plugin::usbpro::Request *request,
94 std::string *response,
95 ConfigureCallback *done);
96
97 void HandlePortAssignmentResponse(ola::rpc::RpcController *controller,
98 std::string *response,
99 ConfigureCallback *done,
100 bool status,
101 uint8_t port1_assignment,
102 uint8_t port2_assignment);
103
104 static std::string SerialToString(uint32_t serial);
105
106 EnttecUsbProWidget *m_pro_widget;
107 std::string m_serial;
108 std::vector<PortParams> m_port_params;
109};
110
111
112/*
113 * The Input port
114 */
115 class UsbProInputPort: public BasicInputPort {
116 public:
117 // The EnttecPort is owner by the caller.
118 UsbProInputPort(UsbProDevice *parent,
119 EnttecPort *port,
120 unsigned int id,
121 ola::PluginAdaptor *plugin_adaptor,
122 const std::string &description)
123 : BasicInputPort(parent, id, plugin_adaptor),
124 m_description(description),
125 m_port(port) {}
126
127 const DmxBuffer &ReadDMX() const {
128 return m_port->FetchDMX();
129 }
130
131 std::string Description() const { return m_description; }
132
133 private:
134 const std::string m_description;
135 EnttecPort *m_port;
136};
137
138
139/*
140 * The output port
141 */
142 class UsbProOutputPort: public BasicOutputPort {
143 public:
144 // The EnttecPort is owner by the caller.
145 UsbProOutputPort(UsbProDevice *parent,
146 EnttecPort *port,
147 unsigned int id,
148 const std::string &description,
149 const TimeStamp *wake_time,
150 unsigned int max_burst,
151 unsigned int rate)
152 : BasicOutputPort(parent, id, port->SupportsRDM(), port->SupportsRDM()),
153 m_description(description),
154 m_port(port),
155 m_bucket(max_burst, rate, max_burst, *wake_time),
156 m_wake_time(wake_time) {}
157
158 bool WriteDMX(const DmxBuffer &buffer, uint8_t) {
159 if (m_bucket.GetToken(*m_wake_time))
160 return m_port->SendDMX(buffer);
161 else
162 OLA_INFO << "Port rated limited, dropping frame";
163 return true;
164 }
165
166 void PostSetUniverse(Universe*, Universe *new_universe) {
167 if (!new_universe)
168 m_port->ChangeToReceiveMode(false);
169 }
170
171 void SendRDMRequest(ola::rdm::RDMRequest *request,
172 ola::rdm::RDMCallback *callback) {
173 m_port->SendRDMRequest(request, callback);
174 }
175
176 void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
177 m_port->RunFullDiscovery(callback);
178 }
179
180 void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
181 m_port->RunIncrementalDiscovery(callback);
182 }
183
184 std::string Description() const { return m_description; }
185
186 private:
187 const std::string m_description;
188 EnttecPort *m_port;
189 TokenBucket m_bucket;
190 const TimeStamp *m_wake_time;
191};
192} // namespace usbpro
193} // namespace plugin
194} // namespace ola
195#endif // PLUGINS_USBPRO_USBPRODEVICE_H_
DmxBuffer.h
A class used to hold a single universe of DMX data.
PluginAdaptor.h
Provides a wrapper for the DeviceManager and SelectServer objects so that the plugins can register de...
ola::AbstractPlugin
Definition Plugin.h:38
ola::BasicInputPort::BasicInputPort
BasicInputPort(AbstractDevice *parent, unsigned int port_id, const PluginAdaptor *plugin_adaptor, bool supports_rdm=false)
Create a new basic input port.
Definition Port.cpp:38
ola::BasicOutputPort::BasicOutputPort
BasicOutputPort(AbstractDevice *parent, unsigned int port_id, bool start_rdm_discovery_on_patch=false, bool supports_rdm=false)
Create a new BasicOutputPort.
Definition Port.cpp:120
ola::DmxBuffer
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
ola::PluginAdaptor
Definition PluginAdaptor.h:41
ola::TimeStamp
Definition Clock.h:179
ola::TokenBucket
Definition TokenBucket.h:29
ola::Universe
Definition Universe.h:46
ola::plugin::usbpro::EnttecPort
Definition EnttecUsbProWidget.h:50
ola::plugin::usbpro::EnttecUsbProWidget
Definition EnttecUsbProWidget.h:83
ola::plugin::usbpro::UsbProDevice
Definition UsbProDevice.h:42
ola::plugin::usbpro::UsbProDevice::DeviceId
std::string DeviceId() const
The device ID.
Definition UsbProDevice.h:52
ola::plugin::usbpro::UsbProInputPort::Description
std::string Description() const
Fetch the string description for a Port.
Definition UsbProDevice.h:131
ola::plugin::usbpro::UsbProOutputPort::SendRDMRequest
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *callback)
Handle an RDMRequest, subclasses can implement this to support RDM.
Definition UsbProDevice.h:171
ola::plugin::usbpro::UsbProOutputPort::RunIncrementalDiscovery
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
This is a noop for ports that don't support RDM.
Definition UsbProDevice.h:180
ola::plugin::usbpro::UsbProOutputPort::RunFullDiscovery
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
This is a noop for ports that don't support RDM.
Definition UsbProDevice.h:176
ola::plugin::usbpro::UsbProOutputPort::Description
std::string Description() const
Fetch the string description for a Port.
Definition UsbProDevice.h:184
ola::plugin::usbpro::UsbProOutputPort::WriteDMX
bool WriteDMX(const DmxBuffer &buffer, uint8_t)
Write DMX data to this port.
Definition UsbProDevice.h:158
ola::rdm::RDMRequest
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition RDMCommand.h:234
ola::rpc::RpcController
A RpcController object is passed every time an RPC is invoked and is used to indicate the success or ...
Definition RpcController.h:42
OLA_INFO
#define OLA_INFO
Definition Logging.h:81
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