Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JaRuleWidgetImpl.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  * JaRuleWidgetImpl.h
17  * The implementation of the Ja Rule Widget.
18  * Copyright (C) 2015 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBDMX_JARULEWIDGETIMPL_H_
22 #define PLUGINS_USBDMX_JARULEWIDGETIMPL_H_
23 
24 #include <ola/base/Macro.h>
25 #include <ola/io/ByteString.h>
26 #include <ola/rdm/DiscoveryAgent.h>
28 #include <ola/rdm/RDMCommand.h>
30 #include <ola/rdm/UID.h>
31 #include <ola/util/SequenceNumber.h>
32 
33 #include "plugins/usbdmx/JaRuleEndpoint.h"
34 #include "plugins/usbdmx/JaRuleWidget.h"
35 #include "plugins/usbdmx/LibUsbAdaptor.h"
36 
37 namespace ola {
38 namespace plugin {
39 namespace usbdmx {
40 
46  public:
56  AsyncronousLibUsbAdaptor *adaptor,
57  libusb_device *device,
58  const ola::rdm::UID &controller_uid);
59 
61 
66  bool Init();
67 
68  // From DiscoverableRDMControllerInterface
72  ola::rdm::RDMCallback *on_complete);
73 
74  // From DiscoveryTargetInterface
75  void MuteDevice(const ola::rdm::UID &target,
76  MuteDeviceCallback *mute_complete);
77  void UnMuteAll(UnMuteDeviceCallback *unmute_complete);
78  void Branch(const ola::rdm::UID &lower,
79  const ola::rdm::UID &upper,
80  BranchCallback *branch_complete);
81 
87  bool SendDMX(const DmxBuffer &buffer);
88 
92  void ResetDevice();
93 
94  private:
95  typedef enum {
96  RC_OK,
97  RC_UNKNOWN,
98  RC_BUFFER_FULL,
99  RC_BAD_PARAM,
100  RC_TX_ERROR,
101  RC_RDM_TIMEOUT,
102  RC_RDM_BCAST_RESPONSE,
103  RC_RDM_INVALID_RESPONSE,
104  } JaRuleReturnCode;
105 
106  PACK(
107  struct DUBTiming {
108  uint16_t start;
109  uint16_t end;
110  });
111 
112  PACK(
113  struct GetSetTiming {
114  uint16_t break_start;
115  uint16_t mark_start;
116  uint16_t mark_end;
117  });
118 
119  JaRuleEndpoint m_endpoint;
120  bool m_in_shutdown;
121 
122  // DMX members
123  DmxBuffer m_dmx;
124  bool m_dmx_in_progress;
125  bool m_dmx_queued;
127 
128  // RDM members
129  ola::rdm::DiscoveryAgent m_discovery_agent;
130  const ola::rdm::UID m_our_uid;
131  ola::SequenceNumber<uint8_t> m_transaction_number;
132  ola::rdm::UIDSet m_uids;
133 
134  void CheckStatusFlags(uint8_t flags);
135  void DMXComplete(JaRuleEndpoint::CommandResult result, uint8_t return_code,
136  uint8_t status_flags, const ola::io::ByteString &payload);
137  void MuteDeviceComplete(MuteDeviceCallback *mute_complete,
139  uint8_t return_code,
140  uint8_t status_flags,
141  const ola::io::ByteString &payload);
142  void UnMuteDeviceComplete(UnMuteDeviceCallback *unmute_complete,
144  uint8_t return_code,
145  uint8_t status_flags,
146  const ola::io::ByteString &payload);
147  void DUBComplete(BranchCallback *callback,
149  uint8_t return_code,
150  uint8_t status_flags,
151  const ola::io::ByteString &payload);
152  void RDMComplete(const ola::rdm::RDMRequest *request,
153  ola::rdm::RDMCallback *m_rdm_callback,
155  uint8_t return_code,
156  uint8_t status_flags,
157  const ola::io::ByteString &payload);
158  ola::rdm::RDMResponse* UnpackRDMResponse(
159  const ola::rdm::RDMRequest *request,
160  const ola::io::ByteString &payload,
161  ola::rdm::RDMStatusCode *status_code);
162  void DiscoveryComplete(ola::rdm::RDMDiscoveryCallback *callback,
163  OLA_UNUSED bool ok,
164  const ola::rdm::UIDSet &uids);
165  JaRuleEndpoint::CommandClass GetCommandFromRequest(
166  const ola::rdm::RDMRequest *request);
167 
168  DISALLOW_COPY_AND_ASSIGN(JaRuleWidgetImpl);
169 };
170 } // namespace usbdmx
171 } // namespace plugin
172 } // namespace ola
173 #endif // PLUGINS_USBDMX_JARULEWIDGETIMPL_H_