Skip to content

Commit 41d4201

Browse files
authored
Merge pull request #1561 from kecramer/fix-get-dimmer-max
Fix Getting Dimmer Max Value
2 parents c6c3842 + de24dd6 commit 41d4201

File tree

2 files changed

+115
-137
lines changed

2 files changed

+115
-137
lines changed

common/rdm/RDMAPI.cpp

Lines changed: 96 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,23 +1195,13 @@ bool RDMAPI::GetDMXAddress(
11951195
const ResponseStatus&,
11961196
uint16_t> *callback,
11971197
string *error) {
1198-
if (CheckCallback(error, callback))
1199-
return false;
1200-
if (CheckNotBroadcast(uid, error, callback))
1201-
return false;
1202-
if (CheckValidSubDevice(sub_device, false, error, callback))
1203-
return false;
12041198

1205-
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
1206-
this,
1207-
&RDMAPI::_HandleGetDMXAddress,
1208-
callback);
1209-
return CheckReturnStatus(
1210-
m_impl->RDMGet(cb,
1211-
universe,
1212-
uid,
1213-
sub_device,
1214-
PID_DMX_START_ADDRESS),
1199+
return GenericGetU16(
1200+
universe,
1201+
uid,
1202+
sub_device,
1203+
callback,
1204+
PID_DMX_START_ADDRESS,
12151205
error);
12161206
}
12171207

@@ -1233,24 +1223,14 @@ bool RDMAPI::SetDMXAddress(
12331223
uint16_t start_address,
12341224
SingleUseCallback1<void, const ResponseStatus&> *callback,
12351225
string *error) {
1236-
if (CheckCallback(error, callback))
1237-
return false;
1238-
if (CheckValidSubDevice(sub_device, true, error, callback))
1239-
return false;
12401226

1241-
start_address = HostToNetwork(start_address);
1242-
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
1243-
this,
1244-
&RDMAPI::_HandleEmptyResponse,
1245-
callback);
1246-
return CheckReturnStatus(
1247-
m_impl->RDMSet(cb,
1248-
universe,
1249-
uid,
1250-
sub_device,
1251-
PID_DMX_START_ADDRESS,
1252-
reinterpret_cast<const uint8_t*>(&start_address),
1253-
sizeof(start_address)),
1227+
return GenericSetU16(
1228+
universe,
1229+
uid,
1230+
sub_device,
1231+
start_address,
1232+
callback,
1233+
PID_DMX_START_ADDRESS,
12541234
error);
12551235
}
12561236

@@ -2908,32 +2888,15 @@ bool RDMAPI::GetDimmerMaximumLevel(
29082888
unsigned int universe,
29092889
const UID &uid,
29102890
uint16_t sub_device,
2911-
SingleUseCallback2<void,
2912-
const ResponseStatus&,
2913-
uint16_t> *callback,
2891+
SingleUseCallback2<void, const ResponseStatus&, uint16_t> *callback,
29142892
string *error) {
2915-
if (CheckCallback(error, callback)) {
2916-
return false;
2917-
}
2918-
2919-
if (CheckNotBroadcast(uid, error, callback)) {
2920-
return false;
2921-
}
2922-
2923-
if (CheckValidSubDevice(sub_device, false, error, callback)) {
2924-
return false;
2925-
}
29262893

2927-
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
2928-
this,
2929-
&RDMAPI::_HandleGetDimmerMaximumLevel,
2930-
callback);
2931-
return CheckReturnStatus(
2932-
m_impl->RDMGet(cb,
2933-
universe,
2934-
uid,
2935-
sub_device,
2936-
PID_MAXIMUM_LEVEL),
2894+
return GenericGetU16(
2895+
universe,
2896+
uid,
2897+
sub_device,
2898+
callback,
2899+
PID_MAXIMUM_LEVEL,
29372900
error);
29382901
}
29392902

@@ -2954,28 +2917,15 @@ bool RDMAPI::SetDimmerMaximumLevel(
29542917
uint16_t maximum_level,
29552918
SingleUseCallback1<void, const ResponseStatus&> *callback,
29562919
string *error) {
2957-
if (CheckCallback(error, callback)) {
2958-
return false;
2959-
}
2960-
2961-
if (CheckValidSubDevice(sub_device, true, error, callback)) {
2962-
return false;
2963-
}
29642920

2965-
maximum_level = HostToNetwork(maximum_level);
2966-
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
2967-
this,
2968-
&RDMAPI::_HandleEmptyResponse,
2969-
callback);
2970-
return CheckReturnStatus(
2971-
m_impl->RDMSet(cb,
2972-
universe,
2973-
uid,
2974-
sub_device,
2975-
PID_MAXIMUM_LEVEL,
2976-
reinterpret_cast<const uint8_t*>(&maximum_level),
2977-
sizeof(maximum_level)),
2978-
error);
2921+
return GenericSetU16(
2922+
universe,
2923+
uid,
2924+
sub_device,
2925+
maximum_level,
2926+
callback,
2927+
PID_MAXIMUM_LEVEL,
2928+
error);
29792929
}
29802930

29812931
/*
@@ -3904,30 +3854,6 @@ void RDMAPI::_HandleGetDMXPersonalityDescription(
39043854
}
39053855

39063856

3907-
/*
3908-
* @brief Handle a get DMX_START_ADDRESS response
3909-
*/
3910-
void RDMAPI::_HandleGetDMXAddress(
3911-
SingleUseCallback2<void,
3912-
const ResponseStatus&,
3913-
uint16_t> *callback,
3914-
const ResponseStatus &status,
3915-
const string &data) {
3916-
ResponseStatus response_status = status;
3917-
static const unsigned int DATA_SIZE = 2;
3918-
uint16_t start_address = 0;
3919-
if (response_status.WasAcked()) {
3920-
if (data.size() != DATA_SIZE) {
3921-
SetIncorrectPDL(&response_status, data.size(), DATA_SIZE);
3922-
} else {
3923-
start_address = *(reinterpret_cast<const uint16_t*>(data.data()));
3924-
start_address = NetworkToHost(start_address);
3925-
}
3926-
}
3927-
callback->Run(response_status, start_address);
3928-
}
3929-
3930-
39313857
/*
39323858
* @brief Handle a get SLOT_INFO response
39333859
*/
@@ -4397,27 +4323,6 @@ void RDMAPI::_HandleGetDimmerMinimumLevels(
43974323
callback->Run(response_status, dimmer_mins);
43984324
}
43994325

4400-
/*
4401-
* @brief Handle a get MAXIMUM_LEVEL response
4402-
*/
4403-
void RDMAPI::_HandleGetDimmerMaximumLevel(
4404-
SingleUseCallback2<void,
4405-
const ResponseStatus&,
4406-
uint16_t> *callback,
4407-
const ResponseStatus &status,
4408-
const string &data) {
4409-
ResponseStatus response_status = status;
4410-
static const unsigned int DATA_SIZE = 2;
4411-
uint16_t maximum_level = 0;
4412-
if (response_status.WasAcked()) {
4413-
if (data.size() != DATA_SIZE) {
4414-
SetIncorrectPDL(&response_status, data.size(), DATA_SIZE);
4415-
} else {
4416-
maximum_level = data[0];
4417-
}
4418-
}
4419-
callback->Run(response_status, maximum_level);
4420-
}
44214326

44224327
//-----------------------------------------------------------------------------
44234328
// Private methods follow
@@ -4434,6 +4339,8 @@ bool RDMAPI::GenericGetU8(
44344339
return false;
44354340
if (CheckValidSubDevice(sub_device, false, error, callback))
44364341
return false;
4342+
if (CheckCallback(error, callback))
4343+
return false;
44374344

44384345
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
44394346
this,
@@ -4460,6 +4367,8 @@ bool RDMAPI::GenericSetU8(
44604367
string *error) {
44614368
if (CheckValidSubDevice(sub_device, true, error, callback))
44624369
return false;
4370+
if (CheckCallback(error, callback))
4371+
return false;
44634372

44644373
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
44654374
this,
@@ -4477,6 +4386,66 @@ bool RDMAPI::GenericSetU8(
44774386
}
44784387

44794388

4389+
// @brief get a 16 bit value
4390+
bool RDMAPI::GenericGetU16(
4391+
unsigned int universe,
4392+
const UID &uid,
4393+
uint16_t sub_device,
4394+
SingleUseCallback2<void, const ResponseStatus&, uint16_t> *callback,
4395+
uint16_t pid,
4396+
string *error) {
4397+
if (CheckNotBroadcast(uid, error, callback))
4398+
return false;
4399+
if (CheckValidSubDevice(sub_device, false, error, callback))
4400+
return false;
4401+
if (CheckCallback(error, callback))
4402+
return false;
4403+
4404+
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
4405+
this,
4406+
&RDMAPI::_HandleU16Response,
4407+
callback);
4408+
return CheckReturnStatus(
4409+
m_impl->RDMGet(cb,
4410+
universe,
4411+
uid,
4412+
sub_device,
4413+
pid),
4414+
error);
4415+
}
4416+
4417+
4418+
// @brief set a 16 bit value
4419+
bool RDMAPI::GenericSetU16(
4420+
unsigned int universe,
4421+
const UID &uid,
4422+
uint16_t sub_device,
4423+
uint16_t value,
4424+
SingleUseCallback1<void, const ResponseStatus&> *callback,
4425+
uint16_t pid,
4426+
string *error) {
4427+
if (CheckValidSubDevice(sub_device, true, error, callback))
4428+
return false;
4429+
if (CheckCallback(error, callback))
4430+
return false;
4431+
4432+
value = HostToNetwork(value);
4433+
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
4434+
this,
4435+
&RDMAPI::_HandleEmptyResponse,
4436+
callback);
4437+
return CheckReturnStatus(
4438+
m_impl->RDMSet(cb,
4439+
universe,
4440+
uid,
4441+
sub_device,
4442+
pid,
4443+
reinterpret_cast<const uint8_t*>(&value),
4444+
sizeof(value)),
4445+
error);
4446+
}
4447+
4448+
44804449
// @brief get a 32 bit value
44814450
bool RDMAPI::GenericGetU32(
44824451
unsigned int universe,
@@ -4489,6 +4458,8 @@ bool RDMAPI::GenericGetU32(
44894458
return false;
44904459
if (CheckValidSubDevice(sub_device, false, error, callback))
44914460
return false;
4461+
if (CheckCallback(error, callback))
4462+
return false;
44924463

44934464
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(
44944465
this,
@@ -4515,6 +4486,8 @@ bool RDMAPI::GenericSetU32(
45154486
string *error) {
45164487
if (CheckValidSubDevice(sub_device, true, error, callback))
45174488
return false;
4489+
if (CheckCallback(error, callback))
4490+
return false;
45184491

45194492
value = HostToNetwork(value);
45204493
RDMAPIImplInterface::rdm_callback *cb = NewSingleCallback(

include/ola/rdm/RDMAPI.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,13 +1240,6 @@ class RDMAPI {
12401240
const ResponseStatus &status,
12411241
const std::string &data);
12421242

1243-
void _HandleGetDMXAddress(
1244-
ola::SingleUseCallback2<void,
1245-
const ResponseStatus&,
1246-
uint16_t> *callback,
1247-
const ResponseStatus &status,
1248-
const std::string &data);
1249-
12501243
void _HandleGetSlotInfo(
12511244
ola::SingleUseCallback2<void,
12521245
const ResponseStatus&,
@@ -1336,13 +1329,6 @@ class RDMAPI {
13361329
const ResponseStatus &status,
13371330
const std::string &data);
13381331

1339-
void _HandleGetDimmerMaximumLevel(
1340-
ola::SingleUseCallback2<void,
1341-
const ResponseStatus&,
1342-
uint16_t> *callback,
1343-
const ResponseStatus &status,
1344-
const std::string &data);
1345-
13461332
private:
13471333
class RDMAPIImplInterface *m_impl;
13481334
std::map<UID, uint8_t> m_outstanding_messages;
@@ -1364,6 +1350,25 @@ class RDMAPI {
13641350
uint16_t pid,
13651351
std::string *error);
13661352

1353+
bool GenericGetU16(
1354+
unsigned int universe,
1355+
const UID &uid,
1356+
uint16_t sub_device,
1357+
ola::SingleUseCallback2<void,
1358+
const ResponseStatus&,
1359+
uint16_t> *callback,
1360+
uint16_t pid,
1361+
std::string *error);
1362+
1363+
bool GenericSetU16(
1364+
unsigned int universe,
1365+
const UID &uid,
1366+
uint16_t sub_device,
1367+
uint16_t value,
1368+
ola::SingleUseCallback1<void, const ResponseStatus&> *callback,
1369+
uint16_t pid,
1370+
std::string *error);
1371+
13671372
bool GenericGetU32(
13681373
unsigned int universe,
13691374
const UID &uid,

0 commit comments

Comments
 (0)