21 #ifndef LIBS_ACN_DMPADDRESS_H_
22 #define LIBS_ACN_DMPADDRESS_H_
26 #include "ola/io/OutputStream.h"
27 #include "ola/network/NetworkUtils.h"
48 static const unsigned int MAX_TWO_BYTE = 0xffff;
49 static const unsigned int MAX_ONE_BYTE = 0xff;
55 template <
typename type>
56 dmp_address_size TypeToDMPSize() {
57 switch (
sizeof(type)) {
73 unsigned int DMPSizeToByteSize(dmp_address_size size);
87 virtual unsigned int Start()
const = 0;
89 virtual unsigned int Increment()
const = 0;
91 virtual unsigned int Number()
const = 0;
94 virtual unsigned int Size()
const {
95 return (IsRange() ? 3 : 1) * BaseSize();
98 virtual dmp_address_size AddressSize()
const = 0;
101 virtual bool Pack(uint8_t *data,
unsigned int *length)
const = 0;
107 virtual bool IsRange()
const = 0;
110 virtual unsigned int BaseSize()
const = 0;
117 template<
typename type>
124 unsigned int Start()
const {
return m_start; }
125 unsigned int Increment()
const {
return 0; }
126 unsigned int Number()
const {
return 1; }
127 dmp_address_size AddressSize()
const {
return TypeToDMPSize<type>(); }
129 bool Pack(uint8_t *data,
unsigned int *length)
const {
130 if (*length < Size()) {
135 memcpy(data, &field, BaseSize());
144 bool IsRange()
const {
return false; }
147 unsigned int BaseSize()
const {
return sizeof(type); }
167 template <
typename type>
175 m_increment(increment),
177 unsigned int Start()
const {
return m_start; }
178 unsigned int Increment()
const {
return m_increment; }
179 unsigned int Number()
const {
return m_number; }
180 dmp_address_size AddressSize()
const {
return TypeToDMPSize<type>(); }
182 bool Pack(uint8_t *data,
unsigned int *length)
const {
183 if (*length < Size()) {
191 memcpy(data, &field, Size());
201 stream->Write(reinterpret_cast<uint8_t*>(&field), Size());
204 bool IsRange()
const {
return true; }
207 unsigned int BaseSize()
const {
return sizeof(type); }
210 type m_start, m_increment, m_number;
223 unsigned int increment,
224 unsigned int number);
230 dmp_address_type type,
232 unsigned int *length);
239 template <
typename type>
244 unsigned int length):
249 const type *Address()
const {
return m_address; }
250 const uint8_t *Data()
const {
return m_data; }
251 unsigned int Size()
const {
return m_address->Size() + m_length; }
254 bool Pack(uint8_t *data,
unsigned int *length)
const {
258 unsigned int total = *length;
259 if (!m_address->Pack(data, length)) {
263 if (total - *length < m_length) {
267 memcpy(data + *length, m_data, m_length);
276 m_address->Write(stream);
277 stream->Write(m_data, m_length);
281 const type *m_address;
282 const uint8_t *m_data;
283 unsigned int m_length;
287 #endif // LIBS_ACN_DMPADDRESS_H_
uint16_t HostToNetwork(uint16_t value)
16-bit unsigned host to network conversion.
Definition: NetworkUtils.cpp:155
Definition: OutputStream.h:53
Definition: DMPAddress.h:240
Definition: DMPAddress.h:81
Definition: DMPAddress.h:168
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: DMPAddress.h:118