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"
33 using ola::network::HostToNetwork;
51 static const unsigned int MAX_TWO_BYTE = 0xffff;
52 static const unsigned int MAX_ONE_BYTE = 0xff;
58 template <
typename type>
59 dmp_address_size TypeToDMPSize() {
60 switch (
sizeof(type)) {
76 unsigned int DMPSizeToByteSize(dmp_address_size size);
90 virtual unsigned int Start()
const = 0;
92 virtual unsigned int Increment()
const = 0;
94 virtual unsigned int Number()
const = 0;
97 virtual unsigned int Size()
const {
98 return (IsRange() ? 3 : 1) * BaseSize();
101 virtual dmp_address_size AddressSize()
const = 0;
104 virtual bool Pack(uint8_t *data,
unsigned int *length)
const = 0;
110 virtual bool IsRange()
const = 0;
113 virtual unsigned int BaseSize()
const = 0;
120 template<
typename type>
127 unsigned int Start()
const {
return m_start; }
128 unsigned int Increment()
const {
return 0; }
129 unsigned int Number()
const {
return 1; }
130 dmp_address_size AddressSize()
const {
return TypeToDMPSize<type>(); }
132 bool Pack(uint8_t *data,
unsigned int *length)
const {
133 if (*length < Size()) {
137 type field = HostToNetwork(m_start);
138 memcpy(data, &field, BaseSize());
144 *stream << HostToNetwork(m_start);
147 bool IsRange()
const {
return false; }
150 unsigned int BaseSize()
const {
return sizeof(type); }
170 template <
typename type>
178 m_increment(increment),
180 unsigned int Start()
const {
return m_start; }
181 unsigned int Increment()
const {
return m_increment; }
182 unsigned int Number()
const {
return m_number; }
183 dmp_address_size AddressSize()
const {
return TypeToDMPSize<type>(); }
185 bool Pack(uint8_t *data,
unsigned int *length)
const {
186 if (*length < Size()) {
191 field[0] = HostToNetwork(m_start);
192 field[1] = HostToNetwork(m_increment);
193 field[2] = HostToNetwork(m_number);
194 memcpy(data, &field, Size());
201 field[0] = HostToNetwork(m_start);
202 field[1] = HostToNetwork(m_increment);
203 field[2] = HostToNetwork(m_number);
204 stream->Write(reinterpret_cast<uint8_t*>(&field), Size());
207 bool IsRange()
const {
return true; }
210 unsigned int BaseSize()
const {
return sizeof(type); }
213 type m_start, m_increment, m_number;
226 unsigned int increment,
227 unsigned int number);
233 dmp_address_type type,
235 unsigned int &length);
242 template <
typename type>
247 unsigned int length):
252 const type *Address()
const {
return m_address; }
253 const uint8_t *Data()
const {
return m_data; }
254 unsigned int Size()
const {
return m_address->Size() + m_length; }
257 bool Pack(uint8_t *data,
unsigned int *length)
const {
261 unsigned int total = *length;
262 if (!m_address->Pack(data, length)) {
266 if (total - *length < m_length) {
270 memcpy(data + *length, m_data, m_length);
279 m_address->Write(stream);
280 stream->Write(m_data, m_length);
284 const type *m_address;
285 const uint8_t *m_data;
286 unsigned int m_length;
291 #endif // PLUGINS_E131_E131_DMPADDRESS_H_