Open Lighting Architecture  Latest Git
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 
35 namespace ola {
36 namespace plugin {
37 namespace usbpro {
38 
39 /*
40  * An Enttec Usb Pro device
41  */
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  */
116  public:
117  // The EnttecPort is owner by the caller.
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  */
143  public:
144  // The EnttecPort is owner by the caller.
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  }
164  return true;
165  }
166 
167  void PostSetUniverse(Universe*, Universe *new_universe) {
168  if (!new_universe) {
169  m_port->ChangeToReceiveMode(false);
170  }
171  }
172 
174  ola::rdm::RDMCallback *callback) {
175  m_port->SendRDMRequest(request, callback);
176  }
177 
179  m_port->RunFullDiscovery(callback);
180  }
181 
183  m_port->RunIncrementalDiscovery(callback);
184  }
185 
186  std::string Description() const { return m_description; }
187 
188  private:
189  const std::string m_description;
190  EnttecPort *m_port;
191  TokenBucket m_bucket;
192  const TimeStamp *m_wake_time;
193 };
194 } // namespace usbpro
195 } // namespace plugin
196 } // namespace ola
197 #endif // PLUGINS_USBPRO_USBPRODEVICE_H_
Definition: Universe.h:46
Definition: GenericUsbProWidget.h:36
Definition: UsbProDevice.h:115
Provides a wrapper for the DeviceManager and SelectServer objects so that the plugins can register de...
Definition: UsbProDevice.h:42
bool AllowMultiPortPatching() const
Allow multiple ports of the same type to be patched to the same universe.
Definition: UsbProDevice.h:59
Definition: Port.h:199
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition: RDMCommand.h:234
std::string DeviceId() const
The device ID.
Definition: UsbProDevice.h:52
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
#define OLA_INFO
Definition: Logging.h:83
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
This is a noop for ports that don&#39;t support RDM.
Definition: UsbProDevice.h:182
A class used to hold a single universe of DMX data.
Definition: TokenBucket.h:29
Definition: PluginAdaptor.h:41
Definition: UsbProDevice.h:142
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
This is a noop for ports that don&#39;t support RDM.
Definition: UsbProDevice.h:178
Definition: UsbSerialDevice.h:36
The base class for all 1 argument callbacks.
Definition: Callback.h:982
bool WriteDMX(const DmxBuffer &buffer, uint8_t)
Write DMX data to this port.
Definition: UsbProDevice.h:158
Definition: EnttecUsbProWidget.h:49
Definition: EnttecUsbProWidget.h:83
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *callback)
Handle an RDMRequest, subclasses can implement this to support RDM.
Definition: UsbProDevice.h:173
std::string Description() const
Fetch the string description for a Port.
Definition: UsbProDevice.h:131
A RpcController object is passed every time an RPC is invoked and is used to indicate the success or ...
Definition: RpcController.h:42
Represents a point in time with microsecond accuracy.
Definition: Clock.h:191
Definition: Port.h:282
Definition: Plugin.h:38
void Configure(ola::rpc::RpcController *controller, const std::string &request, std::string *response, ConfigureCallback *done)
Configure this Device.
Definition: UsbProDevice.cpp:116
std::string Description() const
Fetch the string description for a Port.
Definition: UsbProDevice.h:186