Open Lighting Architecture  0.9.5
 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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/Callback.h"
26 #include "ola/Constants.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 
35 enum {
36  // port 1 labels
37  GET_PARAMS_1 = 3,
38  SET_PARAMS_1 = 4,
39  RECEIVED_DMX_LABEL_1 = 5,
40  SEND_DMX_1 = 6,
41  SEND_RDM_1 = 7,
42  CHANGE_TO_RX_1 = 8,
43  COS_DMX_1 = 9,
44  RDM_DISCOVERY_1 = 11,
45  RDM_TIMEOUT_1 = 12,
46 
47  // port 2 labels, these are tied to the OLA API key.
48  GET_PARAMS_2 = 137,
49  SET_PARAMS_2 = 180,
50  RECEIVED_DMX_LABEL_2 = 156,
51  SEND_DMX_2 = 135,
52  SEND_RDM_2 = 236,
53  CHANGE_TO_RX_2 = 197,
54  COS_DMX_2 = 164,
55  RDM_DISCOVERY_2 = 196,
56  RDM_TIMEOUT_2 = 201,
57 };
58 
59 // Maps operations to label values
61  uint8_t get_params;
62  uint8_t set_params;
63  uint8_t recv_dmx;
64  uint8_t send_dmx;
65  uint8_t send_rdm;
66  uint8_t change_to_rx_mode;
67  uint8_t cos_dmx;
68  uint8_t rdm_timeout;
69  uint8_t rdm_discovery;
70 
71  static OperationLabels Port1Operations();
72  static OperationLabels Port2Operations();
73 };
74 
75 
82  public:
85 
86  EnttecPortImpl(const OperationLabels &ops, const ola::rdm::UID &uid,
87  SendCallback *send_cb);
88 
89  void Stop();
90 
91  bool SendDMX(const DmxBuffer &buffer);
92  const DmxBuffer &FetchDMX() const { return m_input_buffer; }
93  void SetDMXCallback(ola::Callback0<void> *callback);
94 
95  bool ChangeToReceiveMode(bool change_only);
96  void GetParameters(usb_pro_params_callback *callback);
97  bool SetParameters(uint8_t break_time, uint8_t mab_time, uint8_t rate);
98 
99  // the following are from DiscoverableRDMControllerInterface
100  void SendRDMRequest(const ola::rdm::RDMRequest *request,
101  ola::rdm::RDMCallback *on_complete);
104 
105  // The following are the implementation of DiscoveryTargetInterface
106  void MuteDevice(const ola::rdm::UID &target,
107  MuteDeviceCallback *mute_complete);
108  void UnMuteAll(UnMuteDeviceCallback *unmute_complete);
109  void Branch(const ola::rdm::UID &lower,
110  const ola::rdm::UID &upper,
111  BranchCallback *callback);
112 
113  // Called by the EnttecUsbProWidgetImpl
114  void HandleRDMTimeout(unsigned int length);
115  void HandleParameters(const uint8_t *data, unsigned int length);
116  void HandleIncomingDataMessage(const uint8_t *data, unsigned int length);
117  void HandleDMXDiff(const uint8_t *data, unsigned int length);
118 
119  private:
120  SendCallback *m_send_cb;
121  OperationLabels m_ops;
122  bool m_active;
123 
124  // RX DMX
125  DmxBuffer m_input_buffer;
126  ola::Callback0<void> *m_dmx_callback;
127 
128  // widget params
129  std::deque<usb_pro_params_callback*> m_outstanding_param_callbacks;
130 
131  // RDM send
132  ola::rdm::DiscoveryAgent m_discovery_agent;
133  const ola::rdm::UID m_uid;
134  uint8_t m_transaction_number;
135  ola::rdm::RDMCallback *m_rdm_request_callback;
136  const ola::rdm::RDMRequest *m_pending_request;
137 
138  // RDM Discovery
139  MuteDeviceCallback *m_mute_callback;
140  UnMuteDeviceCallback *m_unmute_callback;
141  BranchCallback *m_branch_callback;
142  // holds the discovery response while we're waiting for the timeout message
143  const uint8_t *m_discovery_response;
144  unsigned int m_discovery_response_size;
145 
146  void HandleDMX(const uint8_t *data, unsigned int length);
147  void DiscoveryComplete(ola::rdm::RDMDiscoveryCallback *callback,
148  bool status,
149  const ola::rdm::UIDSet &uids);
150  bool PackAndSendRDMRequest(uint8_t label,
151  const ola::rdm::RDMRequest *request);
152  bool IsDUBRequest(const ola::rdm::RDMRequest *request);
153 };
154 } // namespace usbpro
155 } // namespace plugin
156 } // namespace ola
157 #endif // PLUGINS_USBPRO_ENTTECUSBPROWIDGETIMPL_H_