Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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"
31 #include "ola/rdm/RDMCommand.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  */
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 
61  ola::rdm::RDMCallback *on_complete);
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  std::auto_ptr<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  */
117  public:
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 
134  ola::rdm::RDMCallback *on_complete) {
135  m_controller->SendRDMRequest(request, on_complete);
136  }
137 
139  m_impl->RunFullDiscovery(callback);
140  }
141 
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;
166 };
167 } // namespace usbpro
168 } // namespace plugin
169 } // namespace ola
170 #endif // PLUGINS_USBPRO_ROBEWIDGET_H_
Represents a set of RDM UIDs.
Definition: UIDSet.h:48
Definitions and Interfaces to implement an RDMController that sends a single message at a time...
void MuteDevice(const ola::rdm::UID &target, MuteDeviceCallback *mute_complete)
Definition: RobeWidget.cpp:198
bool ChangeToReceiveMode()
Definition: RobeWidget.cpp:181
void SendRDMRequest(RDMRequest *request, RDMCallback *on_complete)
Definition: QueueingRDMController.cpp:96
ola::BaseCallback2< void, const uint8_t *, unsigned int > BranchCallback
The callback run when a DUB command completes.
Definition: DiscoveryAgent.h:73
Definition: RobeWidget.h:48
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
void UnMuteAll(UnMuteDeviceCallback *unmute_complete)
Definition: RobeWidget.cpp:215
ola::BaseCallback1< void, bool > MuteDeviceCallback
The callback run when a mute command completes.
Definition: DiscoveryAgent.h:60
void Stop()
Definition: RobeWidget.cpp:73
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Definition: RobeWidget.cpp:103
Definition: RobeWidget.h:115
The interface that can send RDM commands, as well as perform discovery operations.
Definition: RDMControllerInterface.h:104
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition: RDMCommand.h:233
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A RDM unique identifier (UID).
RobeWidget(ola::io::ConnectedDescriptor *descriptor, const ola::rdm::UID &uid, unsigned int queue_size=20)
Definition: RobeWidget.cpp:396
A set of UIDs.
A class used to hold a single universe of DMX data.
ola::BaseCallback0< void > UnMuteDeviceCallback
The callback run when an unmute command completes.
Definition: DiscoveryAgent.h:65
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Send a RDM command.
Definition: RobeWidget.h:133
An RDM Controller that queues messages and only sends a single message at a time. ...
Definition: SerialWidgetInterface.h:38
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Definition: RobeWidget.cpp:168
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start an incremental discovery operation.
Definition: RobeWidget.h:142
The base class for all 1 argument callbacks.
Definition: Callback.h:982
An asyncronous RDM Discovery algorithm.
Definition: DiscoveryAgent.h:135
Definition: QueueingRDMController.h:88
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Implements the RDM Discovery algorithm.
Definition: BaseRobeWidget.h:38
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start a full discovery operation.
Definition: RobeWidget.h:138
void Branch(const ola::rdm::UID &lower, const ola::rdm::UID &upper, BranchCallback *callback)
Definition: RobeWidget.cpp:233
bool SendDMX(const DmxBuffer &buffer)
Definition: RobeWidget.cpp:88
The interface used by the DiscoveryTarget to send RDM commands.
Definition: DiscoveryAgent.h:53
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Definition: RobeWidget.cpp:155
Classes that represent RDM commands.