/
DmxterWidget.h
167 lines (147 loc) · 5.43 KB
/
DmxterWidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* DmxterWidget.h
* The Goddard Design Dmxter RDM and miniDmxter
* Copyright (C) 2010 Simon Newton
*/
#ifndef PLUGINS_USBPRO_DMXTERWIDGET_H_
#define PLUGINS_USBPRO_DMXTERWIDGET_H_
#include <memory>
#include "ola/io/SelectServerInterface.h"
#include "ola/rdm/UID.h"
#include "ola/rdm/UIDSet.h"
#include "ola/rdm/RDMControllerInterface.h"
#include "ola/rdm/QueueingRDMController.h"
#include "plugins/usbpro/BaseUsbProWidget.h"
namespace ola {
namespace plugin {
namespace usbpro {
/*
* A DMXter Widget implementation. We separate the Widget from the
* implementation so we can leverage the QueueingRDMController.
*/
class DmxterWidgetImpl: public BaseUsbProWidget,
public ola::rdm::DiscoverableRDMControllerInterface {
public:
DmxterWidgetImpl(ola::io::ConnectedDescriptor *descriptor,
uint16_t esta_id,
uint32_t serial);
~DmxterWidgetImpl();
void Stop();
void SendRDMRequest(ola::rdm::RDMRequest *request_ptr,
ola::rdm::RDMCallback *on_complete);
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback);
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback);
private:
ola::rdm::UID m_uid;
ola::rdm::UIDSet m_uids;
ola::rdm::RDMDiscoveryCallback *m_discovery_callback;
std::auto_ptr<const ola::rdm::RDMRequest> m_pending_request;
ola::rdm::RDMCallback *m_rdm_request_callback;
uint8_t m_transaction_number;
void HandleMessage(uint8_t label,
const uint8_t *data,
unsigned int length);
void HandleTodResponse(const uint8_t *data, unsigned int length);
void HandleRDMResponse(const uint8_t *data,
unsigned int length);
void HandleBroadcastRDMResponse(const uint8_t *data, unsigned int length);
void HandleShutdown(const uint8_t *data, unsigned int length);
static const uint8_t RDM_REQUEST_LABEL;
static const uint8_t RDM_BCAST_REQUEST_LABEL;
static const uint8_t TOD_LABEL;
static const uint8_t DISCOVERY_BRANCH_LABEL;
static const uint8_t FULL_DISCOVERY_LABEL;
static const uint8_t INCREMENTAL_DISCOVERY_LABEL;
static const uint8_t SHUTDOWN_LABEL;
typedef enum {
RC_CHECKSUM_ERROR = 1,
RC_FRAMING_ERROR = 2,
RC_FRAMING_ERROR2 = 3,
RC_BAD_STARTCODE = 4,
RC_BAD_SUB_STARTCODE = 5,
RC_WRONG_PDL = 6,
RC_BAD_PDL = 7,
RC_PACKET_TOO_SHORT = 8,
RC_PACKET_TOO_LONG = 9,
RC_PHYSICAL_LENGTH_MISMATCH = 10,
RC_PDL_LENGTH_MISMATCH = 11,
RC_TRANSACTION_MISMATCH = 12,
RC_BAD_RESPONSE_TYPE = 13,
RC_GOOD_RESPONSE = 14,
RC_ACK_TIMER = 15,
RC_ACK_OVERFLOW = 16,
RC_TIMED_OUT = 17,
RC_IDLE_LEVEL = 18,
RC_GOOD_LEVEL = 19,
RC_BAD_LEVEL = 20,
RC_BROADCAST = 21,
RC_VENDORCAST = 22,
RC_NACK = 23,
RC_NACK_UNKNOWN_PID = 24,
RC_NACK_FORMAT_ERROR = 25,
RC_NACK_HARDWARE_FAULT = 26,
RC_NACK_PROXY_REJECT = 27,
RC_NACK_WRITE_PROTECT = 28,
RC_NACK_COMMAND_CLASS = 29,
RC_NACK_DATA_RANGE = 30,
RC_NACK_BUFFER_FULL = 31,
RC_NACK_PACKET_SIZE = 32,
RC_NACK_SUB_DEVICE_RANGE = 33,
RC_NACK_PROXY_QUEUE_BUFFER_FULL = 34,
RC_DEST_UID_MISMATCH = 40,
RC_SRC_UID_MISMATCH = 41,
RC_SUBDEVICE_MISMATCH = 42,
RC_COMMAND_CLASS_MISMATCH = 43,
RC_PARAM_ID_MISMATCH = 44,
RC_DATA_RECEIVED_NO_BREAK = 46,
} response_code;
};
/*
* A DMXter Widget. This mostly just wraps the implementation.
*/
class DmxterWidget: public SerialWidgetInterface,
public ola::rdm::DiscoverableRDMControllerInterface {
public:
DmxterWidget(ola::io::ConnectedDescriptor *descriptor,
uint16_t esta_id,
uint32_t serial,
unsigned int queue_size = 20);
~DmxterWidget();
void Stop() { m_impl->Stop(); }
void SendRDMRequest(ola::rdm::RDMRequest *request,
ola::rdm::RDMCallback *on_complete) {
m_controller->SendRDMRequest(request, on_complete);
}
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
m_controller->RunFullDiscovery(callback);
}
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
m_controller->RunIncrementalDiscovery(callback);
}
ola::io::ConnectedDescriptor *GetDescriptor() const {
return m_impl->GetDescriptor();
}
private:
// we need to control the order of construction & destruction here so these
// are pointers.
DmxterWidgetImpl *m_impl;
ola::rdm::DiscoverableQueueingRDMController *m_controller;
};
} // namespace usbpro
} // namespace plugin
} // namespace ola
#endif // PLUGINS_USBPRO_DMXTERWIDGET_H_