Open Lighting Architecture  0.9.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  return true;
164  }
165 
166  void PostSetUniverse(Universe*, Universe *new_universe) {
167  if (!new_universe)
168  m_port->ChangeToReceiveMode(false);
169  }
170 
172  ola::rdm::RDMCallback *callback) {
173  m_port->SendRDMRequest(request, callback);
174  }
175 
177  m_port->RunFullDiscovery(callback);
178  }
179 
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_