21 #ifndef PLUGINS_E131_E131_DMPADDRESS_H_
22 #define PLUGINS_E131_E131_DMPADDRESS_H_
26 #include "ola/io/OutputStream.h"
27 #include "ola/network/NetworkUtils.h"
49 static const unsigned int MAX_TWO_BYTE = 0xffff;
50 static const unsigned int MAX_ONE_BYTE = 0xff;
56 template <
typename type>
57 dmp_address_size TypeToDMPSize() {
58 switch (
sizeof(type)) {
74 unsigned int DMPSizeToByteSize(dmp_address_size size);
88 virtual unsigned int Start()
const = 0;
90 virtual unsigned int Increment()
const = 0;
92 virtual unsigned int Number()
const = 0;
95 virtual unsigned int Size()
const {
96 return (IsRange() ? 3 : 1) * BaseSize();
99 virtual dmp_address_size AddressSize()
const = 0;
102 virtual bool Pack(uint8_t *data,
unsigned int *length)
const = 0;
108 virtual bool IsRange()
const = 0;
111 virtual unsigned int BaseSize()
const = 0;
118 template<
typename type>
125 unsigned int Start()
const {
return m_start; }
126 unsigned int Increment()
const {
return 0; }
127 unsigned int Number()
const {
return 1; }
128 dmp_address_size AddressSize()
const {
return TypeToDMPSize<type>(); }
130 bool Pack(uint8_t *data,
unsigned int *length)
const {
131 if (*length < Size()) {
135 type field = ola::network::HostToNetwork(m_start);
136 memcpy(data, &field, BaseSize());
142 *stream << ola::network::HostToNetwork(m_start);
145 bool IsRange()
const {
return false; }
148 unsigned int BaseSize()
const {
return sizeof(type); }
168 template <
typename type>
176 m_increment(increment),
178 unsigned int Start()
const {
return m_start; }
179 unsigned int Increment()
const {
return m_increment; }
180 unsigned int Number()
const {
return m_number; }
181 dmp_address_size AddressSize()
const {
return TypeToDMPSize<type>(); }
183 bool Pack(uint8_t *data,
unsigned int *length)
const {
184 if (*length < Size()) {
189 field[0] = ola::network::HostToNetwork(m_start);
190 field[1] = ola::network::HostToNetwork(m_increment);
191 field[2] = ola::network::HostToNetwork(m_number);
192 memcpy(data, &field, Size());
199 field[0] = ola::network::HostToNetwork(m_start);
200 field[1] = ola::network::HostToNetwork(m_increment);
201 field[2] = ola::network::HostToNetwork(m_number);
202 stream->Write(reinterpret_cast<uint8_t*>(&field), Size());
205 bool IsRange()
const {
return true; }
208 unsigned int BaseSize()
const {
return sizeof(type); }
211 type m_start, m_increment, m_number;
224 unsigned int increment,
225 unsigned int number);
231 dmp_address_type type,
233 unsigned int *length);
240 template <
typename type>
245 unsigned int length):
250 const type *Address()
const {
return m_address; }
251 const uint8_t *Data()
const {
return m_data; }
252 unsigned int Size()
const {
return m_address->Size() + m_length; }
255 bool Pack(uint8_t *data,
unsigned int *length)
const {
259 unsigned int total = *length;
260 if (!m_address->Pack(data, length)) {
264 if (total - *length < m_length) {
268 memcpy(data + *length, m_data, m_length);
277 m_address->Write(stream);
278 stream->Write(m_data, m_length);
282 const type *m_address;
283 const uint8_t *m_data;
284 unsigned int m_length;
289 #endif // PLUGINS_E131_E131_DMPADDRESS_H_