Skip to content
Permalink
Browse files

Use generics for simple 16 bit values

  • Loading branch information...
kecramer committed Jun 18, 2019
1 parent 004dede commit b1056197a1be286a5c085fc700bb8e62c19abfaa
Showing with 108 additions and 121 deletions.
  1. +89 −107 common/rdm/RDMAPI.cpp
  2. +19 −14 include/ola/rdm/RDMAPI.h
@@ -1195,23 +1195,13 @@ bool RDMAPI::GetDMXAddress(
const ResponseStatus&,
uint16_t> *callback,
string *error) {
if (CheckCallback(error, callback))
return false;
if (CheckNotBroadcast(uid, error, callback))
return false;
if (CheckValidSubDevice(sub_device, false, error, callback))
return false;

RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
this,
&RDMAPI::_HandleGetDMXAddress,
callback);
return CheckReturnStatus(
m_impl->RDMGet(cb,
universe,
uid,
sub_device,
PID_DMX_START_ADDRESS),
return GenericGetU16(
universe,
uid,
sub_device,
callback,
PID_DMX_START_ADDRESS,
error);
}

@@ -2908,32 +2898,15 @@ bool RDMAPI::GetDimmerMaximumLevel(
unsigned int universe,
const UID &uid,
uint16_t sub_device,
SingleUseCallback2<void,
const ResponseStatus&,
uint16_t> *callback,
SingleUseCallback2<void, const ResponseStatus&, uint16_t> *callback,
string *error) {
if (CheckCallback(error, callback)) {
return false;
}

if (CheckNotBroadcast(uid, error, callback)) {
return false;
}

if (CheckValidSubDevice(sub_device, false, error, callback)) {
return false;
}

RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
this,
&RDMAPI::_HandleGetDimmerMaximumLevel,
callback);
return CheckReturnStatus(
m_impl->RDMGet(cb,
universe,
uid,
sub_device,
PID_MAXIMUM_LEVEL),
return GenericGetU16(
universe,
uid,
sub_device,
callback,
PID_MAXIMUM_LEVEL,
error);
}

@@ -2954,28 +2927,15 @@ bool RDMAPI::SetDimmerMaximumLevel(
uint16_t maximum_level,
SingleUseCallback1<void, const ResponseStatus&> *callback,
string *error) {
if (CheckCallback(error, callback)) {
return false;
}

if (CheckValidSubDevice(sub_device, true, error, callback)) {
return false;
}

maximum_level = HostToNetwork(maximum_level);
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
this,
&RDMAPI::_HandleEmptyResponse,
callback);
return CheckReturnStatus(
m_impl->RDMSet(cb,
universe,
uid,
sub_device,
PID_MAXIMUM_LEVEL,
reinterpret_cast<const uint8_t*>(&maximum_level),
sizeof(maximum_level)),
error);
return GenericSetU16(
universe,
uid,
sub_device,
maximum_level,
callback,
PID_MAXIMUM_LEVEL,
error);
}

/*
@@ -3904,30 +3864,6 @@ void RDMAPI::_HandleGetDMXPersonalityDescription(
}


/*
* @brief Handle a get DMX_START_ADDRESS response
*/
void RDMAPI::_HandleGetDMXAddress(
SingleUseCallback2<void,
const ResponseStatus&,
uint16_t> *callback,
const ResponseStatus &status,
const string &data) {
ResponseStatus response_status = status;
static const unsigned int DATA_SIZE = 2;
uint16_t start_address = 0;
if (response_status.WasAcked()) {
if (data.size() != DATA_SIZE) {
SetIncorrectPDL(&response_status, data.size(), DATA_SIZE);
} else {
start_address = *(reinterpret_cast<const uint16_t*>(data.data()));
start_address = NetworkToHost(start_address);
}
}
callback->Run(response_status, start_address);
}


/*
* @brief Handle a get SLOT_INFO response
*/
@@ -4397,28 +4333,6 @@ void RDMAPI::_HandleGetDimmerMinimumLevels(
callback->Run(response_status, dimmer_mins);
}

/*
* @brief Handle a get MAXIMUM_LEVEL response
*/
void RDMAPI::_HandleGetDimmerMaximumLevel(
SingleUseCallback2<void,
const ResponseStatus&,
uint16_t> *callback,
const ResponseStatus &status,
const string &data) {
ResponseStatus response_status = status;
static const unsigned int DATA_SIZE = 2;
uint16_t maximum_level = 0;
if (response_status.WasAcked()) {
if (data.size() != DATA_SIZE) {
SetIncorrectPDL(&response_status, data.size(), DATA_SIZE);
} else {
maximum_level = *(reinterpret_cast<const uint16_t*>(data.data()));
maximum_level = NetworkToHost(maximum_level);
}
}
callback->Run(response_status, maximum_level);
}

//-----------------------------------------------------------------------------
// Private methods follow
@@ -4435,6 +4349,8 @@ bool RDMAPI::GenericGetU8(
return false;
if (CheckValidSubDevice(sub_device, false, error, callback))
return false;
if (CheckCallback(error, callback))
return false;

RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
this,
@@ -4461,6 +4377,8 @@ bool RDMAPI::GenericSetU8(
string *error) {
if (CheckValidSubDevice(sub_device, true, error, callback))
return false;
if (CheckCallback(error, callback))
return false;

RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
this,
@@ -4478,6 +4396,66 @@ bool RDMAPI::GenericSetU8(
}


// @brief get a 16 bit value
bool RDMAPI::GenericGetU16(
unsigned int universe,
const UID &uid,
uint16_t sub_device,
SingleUseCallback2<void, const ResponseStatus&, uint16_t> *callback,
uint16_t pid,
string *error) {
if (CheckNotBroadcast(uid, error, callback))
return false;
if (CheckValidSubDevice(sub_device, false, error, callback))
return false;
if (CheckCallback(error, callback))
return false;

RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
this,
&RDMAPI::_HandleU16Response,
callback);
return CheckReturnStatus(
m_impl->RDMGet(cb,
universe,
uid,
sub_device,
pid),
error);
}


// @brief set a 16 bit value
bool RDMAPI::GenericSetU16(
unsigned int universe,
const UID &uid,
uint16_t sub_device,
uint16_t value,
SingleUseCallback1<void, const ResponseStatus&> *callback,
uint16_t pid,
string *error) {
if (CheckValidSubDevice(sub_device, true, error, callback))
return false;
if (CheckCallback(error, callback))
return false;

value = HostToNetwork(value);
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
this,
&RDMAPI::_HandleEmptyResponse,
callback);
return CheckReturnStatus(
m_impl->RDMSet(cb,
universe,
uid,
sub_device,
pid,
reinterpret_cast<const uint8_t*>(&value),
sizeof(value)),
error);
}


// @brief get a 32 bit value
bool RDMAPI::GenericGetU32(
unsigned int universe,
@@ -4490,6 +4468,8 @@ bool RDMAPI::GenericGetU32(
return false;
if (CheckValidSubDevice(sub_device, false, error, callback))
return false;
if (CheckCallback(error, callback))
return false;

RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
this,
@@ -4516,6 +4496,8 @@ bool RDMAPI::GenericSetU32(
string *error) {
if (CheckValidSubDevice(sub_device, true, error, callback))
return false;
if (CheckCallback(error, callback))
return false;

value = HostToNetwork(value);
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
@@ -1240,13 +1240,6 @@ class RDMAPI {
const ResponseStatus &status,
const std::string &data);

void _HandleGetDMXAddress(
ola::SingleUseCallback2<void,
const ResponseStatus&,
uint16_t> *callback,
const ResponseStatus &status,
const std::string &data);

void _HandleGetSlotInfo(
ola::SingleUseCallback2<void,
const ResponseStatus&,
@@ -1336,13 +1329,6 @@ class RDMAPI {
const ResponseStatus &status,
const std::string &data);

void _HandleGetDimmerMaximumLevel(
ola::SingleUseCallback2<void,
const ResponseStatus&,
uint16_t> *callback,
const ResponseStatus &status,
const std::string &data);

private:
class RDMAPIImplInterface *m_impl;
std::map<UID, uint8_t> m_outstanding_messages;
@@ -1364,6 +1350,25 @@ class RDMAPI {
uint16_t pid,
std::string *error);

bool GenericGetU16(
unsigned int universe,
const UID &uid,
uint16_t sub_device,
ola::SingleUseCallback2<void,
const ResponseStatus&,
uint16_t> *callback,
uint16_t pid,
std::string *error);

bool GenericSetU16(
unsigned int universe,
const UID &uid,
uint16_t sub_device,
uint16_t value,
ola::SingleUseCallback1<void, const ResponseStatus&> *callback,
uint16_t pid,
std::string *error);

bool GenericGetU32(
unsigned int universe,
const UID &uid,

0 comments on commit b105619

Please sign in to comment.
You can’t perform that action at this time.