Open Lighting Architecture  Latest Git
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 <memory>
25 #include "ola/io/SelectServerInterface.h"
26 #include "ola/rdm/UID.h"
27 #include "ola/rdm/UIDSet.h"
30 #include "plugins/usbpro/BaseUsbProWidget.h"
31 
32 namespace ola {
33 namespace plugin {
34 namespace usbpro {
35 
36 
37 /*
38  * A DMXter Widget implementation. We separate the Widget from the
39  * implementation so we can leverage the QueueingRDMController.
40  */
43  public:
45  uint16_t esta_id,
46  uint32_t serial);
48 
49  void Stop();
50 
51  void SendRDMRequest(ola::rdm::RDMRequest *request_ptr,
52  ola::rdm::RDMCallback *on_complete);
53 
56 
57  private:
58  ola::rdm::UID m_uid;
59  ola::rdm::UIDSet m_uids;
60  ola::rdm::RDMDiscoveryCallback *m_discovery_callback;
61  std::auto_ptr<const ola::rdm::RDMRequest> m_pending_request;
62  ola::rdm::RDMCallback *m_rdm_request_callback;
63  uint8_t m_transaction_number;
64 
65  void HandleMessage(uint8_t label,
66  const uint8_t *data,
67  unsigned int length);
68  void HandleTodResponse(const uint8_t *data, unsigned int length);
69  void HandleRDMResponse(const uint8_t *data,
70  unsigned int length);
71  void HandleBroadcastRDMResponse(const uint8_t *data, unsigned int length);
72  void HandleShutdown(const uint8_t *data, unsigned int length);
73 
74  static const uint8_t RDM_REQUEST_LABEL;
75  static const uint8_t RDM_BCAST_REQUEST_LABEL;
76  static const uint8_t TOD_LABEL;
77  static const uint8_t DISCOVERY_BRANCH_LABEL;
78  static const uint8_t FULL_DISCOVERY_LABEL;
79  static const uint8_t INCREMENTAL_DISCOVERY_LABEL;
80  static const uint8_t SHUTDOWN_LABAEL;
81 
82  typedef enum {
83  RC_CHECKSUM_ERROR = 1,
84  RC_FRAMING_ERROR = 2,
85  RC_FRAMING_ERROR2 = 3,
86  RC_BAD_STARTCODE = 4,
87  RC_BAD_SUB_STARTCODE = 5,
88  RC_WRONG_PDL = 6,
89  RC_BAD_PDL = 7,
90  RC_PACKET_TOO_SHORT = 8,
91  RC_PACKET_TOO_LONG = 9,
92  RC_PHYSICAL_LENGTH_MISMATCH = 10,
93  RC_PDL_LENGTH_MISMATCH = 11,
94  RC_TRANSACTION_MISMATCH = 12,
95  RC_BAD_RESPONSE_TYPE = 13,
96  RC_GOOD_RESPONSE = 14,
97  RC_ACK_TIMER = 15,
98  RC_ACK_OVERFLOW = 16,
99  RC_TIMED_OUT = 17,
100  RC_IDLE_LEVEL = 18,
101  RC_GOOD_LEVEL = 19,
102  RC_BAD_LEVEL = 20,
103  RC_BROADCAST = 21,
104  RC_VENDORCAST = 22,
105  RC_NACK = 23,
106  RC_NACK_UNKNOWN_PID = 24,
107  RC_NACK_FORMAT_ERROR = 25,
108  RC_NACK_HARDWARE_FAULT = 26,
109  RC_NACK_PROXY_REJECT = 27,
110  RC_NACK_WRITE_PROECT = 28,
111  RC_NACK_COMMAND_CLASS = 29,
112  RC_NACK_DATA_RANGE = 30,
113  RC_NACK_BUFFER_FULL = 31,
114  RC_NACK_PACKET_SIZE = 32,
115  RC_NACK_SUB_DEVICE_RANGE = 33,
116  RC_NACK_PROXY_QUEUE_BUFFER_FULL = 34,
117  RC_DEST_UID_MISMATCH = 40,
118  RC_SRC_UID_MISMATCH = 41,
119  RC_SUBDEVICE_MISMATCH = 42,
120  RC_COMMAND_CLASS_MISMATCH = 43,
121  RC_PARAM_ID_MISMATCH = 44,
122  RC_DATA_RECEIVED_NO_BREAK = 46,
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 
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_
Represents a set of RDM UIDs.
Definition: UIDSet.h:48
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Definition: DmxterWidget.cpp:167
Definitions and Interfaces to implement an RDMController that sends a single message at a time...
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start a full discovery operation.
Definition: DmxterWidget.h:146
void Stop()
Definition: DmxterWidget.cpp:86
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Definition: DmxterWidget.cpp:152
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
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:234
A RDM unique identifier (UID).
Definition: BaseUsbProWidget.h:40
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start an incremental discovery operation.
Definition: DmxterWidget.h:150
A set of UIDs.
~DmxterWidgetImpl()
Definition: DmxterWidget.cpp:78
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Send a RDM command.
Definition: DmxterWidget.h:141
An RDM Controller that queues messages and only sends a single message at a time. ...
Definition: DmxterWidget.h:130
Definition: SerialWidgetInterface.h:38
The base class for all 1 argument callbacks.
Definition: Callback.h:982
Definition: QueueingRDMController.h:88
Definition: DmxterWidget.h:41
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
void SendRDMRequest(ola::rdm::RDMRequest *request_ptr, ola::rdm::RDMCallback *on_complete)
Definition: DmxterWidget.cpp:109