Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
UltraDMXProDevice.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  * UltraDMXProDevice.h
17  * A DMX King Ultra DMX Pro Device
18  * Copyright (C) 2011 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBPRO_ULTRADMXPRODEVICE_H_
22 #define PLUGINS_USBPRO_ULTRADMXPRODEVICE_H_
23 
24 #include <string>
25 #include <sstream>
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/UltraDMXProWidget.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 Ultra DMX Pro device
41  */
43  public:
44  UltraDMXProDevice(ola::PluginAdaptor *plugin_adaptor,
45  ola::AbstractPlugin *owner,
46  const std::string &name,
47  UltraDMXProWidget *widget,
48  uint16_t esta_id,
49  uint16_t device_id,
50  uint32_t serial,
51  uint16_t firmware_version,
52  unsigned int fps_limit);
53 
54  std::string DeviceId() const { return m_serial; }
55  // both output ports can be bound to the same universe
56  bool AllowMultiPortPatching() const { return true; }
57 
58  void Configure(ola::rpc::RpcController *controller,
59  const std::string &request,
60  std::string *response,
61  ConfigureCallback *done);
62 
63  protected:
64  void PrePortStop();
65 
66  private:
67  void UpdateParams(bool status, const usb_pro_parameters &params);
68 
69  void HandleParametersRequest(ola::rpc::RpcController *controller,
70  const ola::plugin::usbpro::Request *request,
71  std::string *response,
72  ConfigureCallback *done);
73 
74  void HandleParametersResponse(ola::rpc::RpcController *controller,
75  std::string *response,
76  ConfigureCallback *done,
77  bool status,
78  const usb_pro_parameters &params);
79 
80  void HandleSerialRequest(ola::rpc::RpcController *controller,
81  const ola::plugin::usbpro::Request *request,
82  std::string *response,
83  ConfigureCallback *done);
84 
85  UltraDMXProWidget *m_ultra_widget;
86  std::string m_serial;
87 
88  bool m_got_parameters;
89  uint8_t m_break_time;
90  uint8_t m_mab_time;
91  uint8_t m_rate;
92 };
93 
94 
95 /*
96  * The Input port
97  */
99  public:
101  UltraDMXProWidget *widget,
102  unsigned int id,
103  ola::PluginAdaptor *plugin_adaptor,
104  const std::string &description)
105  : BasicInputPort(parent, id, plugin_adaptor),
106  m_description(description),
107  m_widget(widget) {}
108 
109  const DmxBuffer &ReadDMX() const {
110  return m_widget->FetchDMX();
111  }
112 
113  std::string Description() const { return m_description; }
114 
115  private:
116  const std::string m_description;
117  UltraDMXProWidget *m_widget;
118 };
119 
120 
121 /*
122  * The output port, we have two of these per device.
123  */
125  public:
127  UltraDMXProWidget *widget,
128  unsigned int id,
129  const std::string &description,
130  const TimeStamp *wake_time,
131  unsigned int max_burst,
132  unsigned int rate,
133  bool primary)
134  : BasicOutputPort(parent, id),
135  m_description(description),
136  m_widget(widget),
137  m_bucket(max_burst, rate, max_burst, *wake_time),
138  m_wake_time(wake_time),
139  m_primary(primary) {}
140 
141  bool WriteDMX(const DmxBuffer &buffer, OLA_UNUSED uint8_t priority) {
142  if (m_bucket.GetToken(*m_wake_time)) {
143  return m_primary ? m_widget->SendDMX(buffer)
144  : m_widget->SendSecondaryDMX(buffer);
145  } else {
146  OLA_INFO << "Port rated limited, dropping frame";
147  }
148  return true;
149  }
150 
151  std::string Description() const { return m_description; }
152 
153  private:
154  const std::string m_description;
155  UltraDMXProWidget *m_widget;
156  TokenBucket m_bucket;
157  const TimeStamp *m_wake_time;
158  bool m_primary;
159 };
160 } // namespace usbpro
161 } // namespace plugin
162 } // namespace ola
163 #endif // PLUGINS_USBPRO_ULTRADMXPRODEVICE_H_
std::string Description() const
Fetch the string description for a Port.
Definition: UltraDMXProDevice.h:151
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
Provides a wrapper for the DeviceManager and SelectServer objects so that the plugins can register de...
Definition: UltraDMXProDevice.h:124
const DmxBuffer & FetchDMX() const
Definition: GenericUsbProWidget.cpp:119
Definition: UltraDMXProDevice.h:98
Definition: Port.h:199
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
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
#define OLA_INFO
Definition: Logging.h:81
A class used to hold a single universe of DMX data.
Definition: TokenBucket.h:29
std::string DeviceId() const
The device ID.
Definition: UltraDMXProDevice.h:54
std::string Description() const
Fetch the string description for a Port.
Definition: UltraDMXProDevice.h:113
#define OLA_UNUSED
Mark unused arguments & types.
Definition: Macro.h:62
Definition: PluginAdaptor.h:41
Definition: UltraDMXProWidget.h:38
Definition: UsbSerialDevice.h:36
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
A RpcController object is passed every time an RPC is invoked and is used to indicate the success or ...
Definition: RpcController.h:42
Definition: Clock.h:171
Definition: Port.h:282
Definition: Plugin.h:38
bool WriteDMX(const DmxBuffer &buffer, uint8_t priority)
Write DMX data to this port.
Definition: UltraDMXProDevice.h:141
Definition: UltraDMXProDevice.h:42