Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EnttecUsbProWidgetImpl.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * EnttecUsbProWidgetImpl.h
17  * The Enttec USB Pro Widget
18  * Copyright (C) 2013 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBPRO_ENTTECUSBPROWIDGETIMPL_H_
22 #define PLUGINS_USBPRO_ENTTECUSBPROWIDGETIMPL_H_
23 
24 #include <deque>
25 #include "ola/BaseTypes.h"
26 #include "ola/Callback.h"
27 #include "ola/rdm/RDMCommand.h"
28 #include "ola/rdm/UID.h"
29 #include "ola/rdm/UIDSet.h"
30 
31 namespace ola {
32 namespace plugin {
33 namespace usbpro {
34 
36 using ola::rdm::UID;
37 using ola::rdm::UIDSet;
38 
39 
40 enum {
41  // port 1 labels
42  GET_PARAMS_1 = 3,
43  SET_PARAMS_1 = 4,
44  RECEIVED_DMX_LABEL_1 = 5,
45  SEND_DMX_1 = 6,
46  SEND_RDM_1 = 7,
47  CHANGE_TO_RX_1 = 8,
48  COS_DMX_1 = 9,
49  RDM_DISCOVERY_1 = 11,
50  RDM_TIMEOUT_1 = 12,
51 
52  // port 2 labels, these are tied to the OLA API key.
53  GET_PARAMS_2 = 137,
54  SET_PARAMS_2 = 180,
55  RECEIVED_DMX_LABEL_2 = 156,
56  SEND_DMX_2 = 135,
57  SEND_RDM_2 = 236,
58  CHANGE_TO_RX_2 = 197,
59  COS_DMX_2 = 164,
60  RDM_DISCOVERY_2 = 196,
61  RDM_TIMEOUT_2 = 201,
62 };
63 
64 // Maps operations to label values
66  uint8_t get_params;
67  uint8_t set_params;
68  uint8_t recv_dmx;
69  uint8_t send_dmx;
70  uint8_t send_rdm;
71  uint8_t change_to_rx_mode;
72  uint8_t cos_dmx;
73  uint8_t rdm_timeout;
74  uint8_t rdm_discovery;
75 
76  static OperationLabels Port1Operations();
77  static OperationLabels Port2Operations();
78 };
79 
80 
87  public:
90 
91  EnttecPortImpl(const OperationLabels &ops, const UID &uid,
92  SendCallback *send_cb);
93 
94  void Stop();
95 
96  bool SendDMX(const DmxBuffer &buffer);
97  const DmxBuffer &FetchDMX() const { return m_input_buffer; }
98  void SetDMXCallback(ola::Callback0<void> *callback);
99 
100  bool ChangeToReceiveMode(bool change_only);
101  void GetParameters(usb_pro_params_callback *callback);
102  bool SetParameters(uint8_t break_time, uint8_t mab_time, uint8_t rate);
103 
104  // the following are from DiscoverableRDMControllerInterface
105  void SendRDMRequest(const ola::rdm::RDMRequest *request,
106  ola::rdm::RDMCallback *on_complete);
109 
110  // The following are the implementation of DiscoveryTargetInterface
111  void MuteDevice(const ola::rdm::UID &target,
112  MuteDeviceCallback *mute_complete);
113  void UnMuteAll(UnMuteDeviceCallback *unmute_complete);
114  void Branch(const ola::rdm::UID &lower,
115  const ola::rdm::UID &upper,
116  BranchCallback *callback);
117 
118  // Called by the EnttecUsbProWidgetImpl
119  void HandleRDMTimeout(unsigned int length);
120  void HandleParameters(const uint8_t *data, unsigned int length);
121  void HandleIncommingDataMessage(const uint8_t *data, unsigned int length);
122  void HandleDMXDiff(const uint8_t *data, unsigned int length);
123 
124  private:
125  SendCallback *m_send_cb;
126  OperationLabels m_ops;
127  bool m_active;
128 
129  // RX DMX
130  DmxBuffer m_input_buffer;
131  ola::Callback0<void> *m_dmx_callback;
132 
133  // widget params
134  std::deque<usb_pro_params_callback*> m_outstanding_param_callbacks;
135 
136  // RDM send
137  ola::rdm::DiscoveryAgent m_discovery_agent;
138  const ola::rdm::UID m_uid;
139  uint8_t m_transaction_number;
140  ola::rdm::RDMCallback *m_rdm_request_callback;
141  const ola::rdm::RDMRequest *m_pending_request;
142 
143  // RDM Discovery
144  MuteDeviceCallback *m_mute_callback;
145  UnMuteDeviceCallback *m_unmute_callback;
146  BranchCallback *m_branch_callback;
147  // holds the discovery response while we're waiting for the timeout message
148  const uint8_t *m_discovery_response;
149  unsigned int m_discovery_response_size;
150 
151  void HandleDMX(const uint8_t *data, unsigned int length);
152  void DiscoveryComplete(ola::rdm::RDMDiscoveryCallback *callback,
153  bool status,
154  const ola::rdm::UIDSet &uids);
155  bool PackAndSendRDMRequest(uint8_t label,
156  const ola::rdm::RDMRequest *request);
157  bool IsDUBRequest(const ola::rdm::RDMRequest *request);
158 };
159 } // namespace usbpro
160 } // namespace plugin
161 } // namespace ola
162 #endif // PLUGINS_USBPRO_ENTTECUSBPROWIDGETIMPL_H_