Open Lighting Architecture  0.9.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DmxterWidget.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  * DmxterWidget.h
17  * The Goddard Design Dmxter RDM and miniDmxter
18  * Copyright (C) 2010 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBPRO_DMXTERWIDGET_H_
22 #define PLUGINS_USBPRO_DMXTERWIDGET_H_
23 
24 #include "ola/io/SelectServerInterface.h"
25 #include "ola/rdm/UID.h"
26 #include "ola/rdm/UIDSet.h"
29 #include "plugins/usbpro/BaseUsbProWidget.h"
30 
31 namespace ola {
32 namespace plugin {
33 namespace usbpro {
34 
35 
36 /*
37  * A DMXter Widget implementation. We separate the Widget from the
38  * implementation so we can leverage the QueueingRDMController.
39  */
42  public:
44  uint16_t esta_id,
45  uint32_t serial);
47 
48  void Stop();
49 
50  void SendRDMRequest(const ola::rdm::RDMRequest *request,
51  ola::rdm::RDMCallback *on_complete);
52 
55 
56  private:
57  ola::rdm::UID m_uid;
58  ola::rdm::UIDSet m_uids;
59  ola::rdm::RDMDiscoveryCallback *m_discovery_callback;
60  const ola::rdm::RDMRequest *m_pending_request;
61  ola::rdm::RDMCallback *m_rdm_request_callback;
62  uint8_t m_transaction_number;
63 
64  void HandleMessage(uint8_t label,
65  const uint8_t *data,
66  unsigned int length);
67  void HandleTodResponse(const uint8_t *data, unsigned int length);
68  void HandleRDMResponse(const uint8_t *data,
69  unsigned int length,
70  bool is_dub = false);
71  void HandleBroadcastRDMResponse(const uint8_t *data, unsigned int length);
72  void HandleShutdown(const uint8_t *data, unsigned int length);
73  bool IsDUBRequest(const ola::rdm::RDMRequest *request);
74 
75  static const uint8_t RDM_REQUEST_LABEL;
76  static const uint8_t RDM_BCAST_REQUEST_LABEL;
77  static const uint8_t TOD_LABEL;
78  static const uint8_t DISCOVERY_BRANCH_LABEL;
79  static const uint8_t FULL_DISCOVERY_LABEL;
80  static const uint8_t INCREMENTAL_DISCOVERY_LABEL;
81  static const uint8_t SHUTDOWN_LABAEL;
82 
83  typedef enum {
84  RC_CHECKSUM_ERROR = 1,
85  RC_FRAMING_ERROR = 2,
86  RC_FRAMING_ERROR2 = 3,
87  RC_BAD_STARTCODE = 4,
88  RC_BAD_SUB_STARTCODE = 5,
89  RC_WRONG_PDL = 6,
90  RC_BAD_PDL = 7,
91  RC_PACKET_TOO_SHORT = 8,
92  RC_PACKET_TOO_LONG = 9,
93  RC_PHYSICAL_LENGTH_MISMATCH = 10,
94  RC_PDL_LENGTH_MISMATCH = 11,
95  RC_TRANSACTION_MISMATCH = 12,
96  RC_BAD_RESPONSE_TYPE = 13,
97  RC_GOOD_RESPONSE = 14,
98  RC_ACK_TIMER = 15,
99  RC_ACK_OVERFLOW = 16,
100  RC_TIMED_OUT = 17,
101  RC_IDLE_LEVEL = 18,
102  RC_GOOD_LEVEL = 19,
103  RC_BAD_LEVEL = 20,
104  RC_BROADCAST = 21,
105  RC_VENDORCAST = 22,
106  RC_NACK = 23,
107  RC_NACK_UNKNOWN_PID = 24,
108  RC_NACK_FORMAT_ERROR = 25,
109  RC_NACK_HARDWARE_FAULT = 26,
110  RC_NACK_PROXY_REJECT = 27,
111  RC_NACK_WRITE_PROECT = 28,
112  RC_NACK_COMMAND_CLASS = 29,
113  RC_NACK_DATA_RANGE = 30,
114  RC_NACK_BUFFER_FULL = 31,
115  RC_NACK_PACKET_SIZE = 32,
116  RC_NACK_SUB_DEVICE_RANGE = 33,
117  RC_NACK_PROXY_QUEUE_BUFFER_FULL = 34,
118  RC_DEST_UID_MISMATCH = 40,
119  RC_SRC_UID_MISMATCH = 41,
120  RC_SUBDEVICE_MISMATCH = 42,
121  RC_COMMAND_CLASS_MISMATCH = 43,
122  RC_PARAM_ID_MISMATCH = 44,
123  } response_code;
124 };
125 
126 
127 /*
128  * A DMXter Widget. This mostly just wraps the implementation.
129  */
132  public:
134  uint16_t esta_id,
135  uint32_t serial,
136  unsigned int queue_size = 20);
137  ~DmxterWidget();
138 
139  void Stop() { m_impl->Stop(); }
140 
142  ola::rdm::RDMCallback *on_complete) {
143  m_controller->SendRDMRequest(request, on_complete);
144  }
145 
147  m_controller->RunFullDiscovery(callback);
148  }
149 
150  void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
151  m_controller->RunIncrementalDiscovery(callback);
152  }
153 
154  ola::io::ConnectedDescriptor *GetDescriptor() const {
155  return m_impl->GetDescriptor();
156  }
157 
158  private:
159  // we need to control the order of construction & destruction here so these
160  // are pointers.
161  DmxterWidgetImpl *m_impl;
163 };
164 } // namespace usbpro
165 } // namespace plugin
166 } // namespace ola
167 #endif // PLUGINS_USBPRO_DMXTERWIDGET_H_