Skip to content

Commit ec76778

Browse files
authored
Merge pull request #1999 from peternewman/plugfest
More RDM Responder tests
2 parents 1995016 + 42c7f44 commit ec76778

17 files changed

Lines changed: 1360 additions & 97 deletions

common/rdm/DummyResponder.cpp

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ const ResponderOps<DummyResponder>::ParamHandler
172172
{ PID_TEST_DATA,
173173
&DummyResponder::GetTestData,
174174
&DummyResponder::SetTestData},
175+
{ PID_METADATA_PARAMETER_VERSION,
176+
&DummyResponder::GetMetadataParameterVersion,
177+
NULL},
178+
{ PID_METADATA_JSON,
179+
&DummyResponder::GetMetadataJSON,
180+
NULL},
181+
{ PID_METADATA_JSON_URL,
182+
&DummyResponder::GetMetadataJSONURL,
183+
NULL},
175184
{ OLA_MANUFACTURER_PID_CODE_VERSION,
176185
&DummyResponder::GetOlaCodeVersion,
177186
NULL},
@@ -460,7 +469,7 @@ RDMResponse *DummyResponder::GetProductURL(
460469
request,
461470
"https://openlighting.org/rdm-tools/dummy-responders/",
462471
0,
463-
UINT8_MAX); // TODO(Peter): This field's length isn't limited in the spec
472+
UINT8_MAX); // TODO(Peter): This field's length isn't limited in the spec
464473
}
465474

466475
RDMResponse *DummyResponder::GetFirmwareURL(
@@ -469,7 +478,7 @@ RDMResponse *DummyResponder::GetFirmwareURL(
469478
request,
470479
"https://github.com/OpenLightingProject/ola",
471480
0,
472-
UINT8_MAX); // TODO(Peter): This field's length isn't limited in the spec
481+
UINT8_MAX); // TODO(Peter): This field's length isn't limited in the spec
473482
}
474483

475484
RDMResponse *DummyResponder::GetTestData(const RDMRequest *request) {
@@ -480,6 +489,58 @@ RDMResponse *DummyResponder::SetTestData(const RDMRequest *request) {
480489
return ResponderHelper::SetTestData(request);
481490
}
482491

492+
RDMResponse *DummyResponder::GetMetadataParameterVersion(
493+
const RDMRequest *request) {
494+
// Check that it's OLA_MANUFACTURER_PID_CODE_VERSION being requested
495+
uint16_t parameter_id;
496+
if (!ResponderHelper::ExtractUInt16(request, &parameter_id)) {
497+
return NackWithReason(request, NR_FORMAT_ERROR);
498+
}
499+
500+
if (parameter_id != OLA_MANUFACTURER_PID_CODE_VERSION) {
501+
OLA_WARN << "Dummy responder received metadata parameter version request "
502+
<< "with unknown PID, expected "
503+
<< OLA_MANUFACTURER_PID_CODE_VERSION << ", got " << parameter_id;
504+
return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
505+
} else {
506+
return ResponderHelper::GetMetadataParameterVersion(
507+
request,
508+
OLA_MANUFACTURER_PID_CODE_VERSION,
509+
OLA_MANUFACTURER_PID_JSON_VERSION_CODE_VERSION);
510+
}
511+
}
512+
513+
RDMResponse *DummyResponder::GetMetadataJSON(
514+
const RDMRequest *request) {
515+
// Check that it's OLA_MANUFACTURER_PID_CODE_VERSION being requested
516+
uint16_t parameter_id;
517+
if (!ResponderHelper::ExtractUInt16(request, &parameter_id)) {
518+
return NackWithReason(request, NR_FORMAT_ERROR);
519+
}
520+
521+
if (parameter_id != OLA_MANUFACTURER_PID_CODE_VERSION) {
522+
OLA_WARN << "Dummy responder received metadata JSON request with unknown "
523+
<< "PID, expected "
524+
<< OLA_MANUFACTURER_PID_CODE_VERSION << ", got " << parameter_id;
525+
return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
526+
} else {
527+
return ResponderHelper::GetMetadataJSON(
528+
request,
529+
OLA_MANUFACTURER_PID_CODE_VERSION,
530+
OLA_MANUFACTURER_PID_JSON_CODE_VERSION);
531+
}
532+
}
533+
534+
RDMResponse *DummyResponder::GetMetadataJSONURL(
535+
const RDMRequest *request) {
536+
return ResponderHelper::GetString(
537+
request,
538+
// TODO(Peter): Consider what this should actually be permanently
539+
"https://docs.openlighting.org/ola/json/latest/metadata/0x0001.json",
540+
0,
541+
UINT8_MAX); // TODO(Peter): This field's length isn't limited in the spec
542+
}
543+
483544
RDMResponse *DummyResponder::GetOlaCodeVersion(
484545
const RDMRequest *request) {
485546
return ResponderHelper::GetString(request, VERSION);

common/rdm/OpenLightingEnums.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@ namespace rdm {
2424

2525
const char OLA_MANUFACTURER_LABEL[] = "Open Lighting Project";
2626
const char OLA_MANUFACTURER_URL[] = "https://openlighting.org/";
27+
28+
const char OLA_MANUFACTURER_PID_JSON_CODE_VERSION[] = "{\"name\":"
29+
"\"CODE_VERSION\",\"manufacturer_id\":31344,\"pid\":32769,\"version\":1,"
30+
"\"get_request_subdevice_range\":[\"root\",\"subdevices\"],"
31+
"\"get_request\":[],\"get_response\":[{\"name\":\"code_version\","
32+
"\"type\":\"string\",""\"maxLength\":32,\"restrictToASCII\":true}]}";
2733
} // namespace rdm
2834
} // namespace ola

common/rdm/ResponderHelper.cpp

Lines changed: 187 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "ola/network/MACAddress.h"
3535
#include "ola/network/NetworkUtils.h"
3636
#include "ola/rdm/RDMEnums.h"
37+
#include "ola/rdm/ResponderEndpointManager.h"
3738
#include "ola/rdm/ResponderHelper.h"
3839
#include "ola/rdm/ResponderSensor.h"
3940
#include "ola/strings/Utils.h"
@@ -81,7 +82,7 @@ bool ResponderHelper::ExtractUInt32(const RDMRequest *request,
8182
}
8283

8384
bool ResponderHelper::ExtractString(const RDMRequest *request,
84-
std::string *output,
85+
string *output,
8586
uint8_t max_length) {
8687
if (request->ParamDataSize() > max_length) {
8788
return false;
@@ -965,7 +966,7 @@ RDMResponse *ResponderHelper::GetParamDescription(
965966
uint32_t min_value,
966967
uint32_t default_value,
967968
uint32_t max_value,
968-
string description,
969+
const string &description,
969970
uint8_t queued_message_count) {
970971
PACK(
971972
struct parameter_description_s {
@@ -1016,11 +1017,11 @@ RDMResponse *ResponderHelper::GetParamDescription(
10161017
}
10171018

10181019
RDMResponse *ResponderHelper::GetASCIIParamDescription(
1019-
const RDMRequest *request,
1020-
uint16_t pid,
1021-
rdm_command_class command_class,
1022-
string description,
1023-
uint8_t queued_message_count) {
1020+
const RDMRequest *request,
1021+
uint16_t pid,
1022+
rdm_command_class command_class,
1023+
const string &description,
1024+
uint8_t queued_message_count) {
10241025
return GetParamDescription(
10251026
request,
10261027
pid,
@@ -1037,12 +1038,12 @@ RDMResponse *ResponderHelper::GetASCIIParamDescription(
10371038
}
10381039

10391040
RDMResponse *ResponderHelper::GetBitFieldParamDescription(
1040-
const RDMRequest *request,
1041-
uint16_t pid,
1042-
uint8_t pdl_size,
1043-
rdm_command_class command_class,
1044-
string description,
1045-
uint8_t queued_message_count) {
1041+
const RDMRequest *request,
1042+
uint16_t pid,
1043+
uint8_t pdl_size,
1044+
rdm_command_class command_class,
1045+
const string &description,
1046+
uint8_t queued_message_count) {
10461047
return GetParamDescription(
10471048
request,
10481049
pid,
@@ -1110,6 +1111,65 @@ RDMResponse *ResponderHelper::SetTestData(
11101111
queued_message_count);
11111112
}
11121113

1114+
/**
1115+
* Get NSC comms status
1116+
*/
1117+
RDMResponse *ResponderHelper::GetCommsStatusNSC(
1118+
const RDMRequest *request,
1119+
const NSCStatus *status,
1120+
uint8_t queued_message_count) {
1121+
if (request->ParamDataSize()) {
1122+
return NackWithReason(request, NR_FORMAT_ERROR, queued_message_count);
1123+
}
1124+
1125+
PACK(
1126+
struct comms_status_nsc_s {
1127+
uint8_t supported_fields;
1128+
uint32_t additive_checksum;
1129+
uint32_t packet_count;
1130+
uint16_t most_recent_slot_count;
1131+
uint16_t min_slot_count;
1132+
uint16_t max_slot_count;
1133+
uint32_t packet_error_count;
1134+
});
1135+
STATIC_ASSERT(sizeof(comms_status_nsc_s) == 19);
1136+
1137+
struct comms_status_nsc_s comms_status_nsc;
1138+
comms_status_nsc.supported_fields = status->SupportedFieldsBitMask();
1139+
comms_status_nsc.additive_checksum = HostToNetwork(
1140+
status->AdditiveChecksum());
1141+
comms_status_nsc.packet_count = HostToNetwork(status->PacketCount());
1142+
comms_status_nsc.most_recent_slot_count = HostToNetwork(
1143+
status->MostRecentSlotCount());
1144+
comms_status_nsc.min_slot_count = HostToNetwork(status->MinSlotCount());
1145+
comms_status_nsc.max_slot_count = HostToNetwork(status->MaxSlotCount());
1146+
comms_status_nsc.packet_error_count = HostToNetwork(
1147+
status->PacketErrorCount());
1148+
return GetResponseFromData(
1149+
request,
1150+
reinterpret_cast<const uint8_t*>(&comms_status_nsc),
1151+
sizeof(comms_status_nsc),
1152+
RDM_ACK,
1153+
queued_message_count);
1154+
}
1155+
1156+
/**
1157+
* Set NSC comms status
1158+
*/
1159+
RDMResponse *ResponderHelper::SetCommsStatusNSC(
1160+
const RDMRequest *request,
1161+
NSCStatus *status,
1162+
uint8_t queued_message_count) {
1163+
if (request->ParamDataSize()) {
1164+
return NackWithReason(request, NR_FORMAT_ERROR, queued_message_count);
1165+
}
1166+
1167+
// Reset the counts...
1168+
status->Reset();
1169+
1170+
return GetResponseFromData(request, NULL, queued_message_count);
1171+
}
1172+
11131173
RDMResponse *ResponderHelper::GetListTags(
11141174
const RDMRequest *request,
11151175
const TagSet *tag_set,
@@ -1187,6 +1247,112 @@ RDMResponse *ResponderHelper::SetClearTags(
11871247
return ResponderHelper::EmptySetResponse(request, queued_message_count);
11881248
}
11891249

1250+
RDMResponse *ResponderHelper::GetMetadataParameterVersion(
1251+
const RDMRequest *request,
1252+
uint16_t pid,
1253+
uint16_t version,
1254+
uint8_t queued_message_count) {
1255+
PACK(
1256+
struct metadata_parameter_version_s {
1257+
uint16_t pid;
1258+
uint16_t version;
1259+
});
1260+
STATIC_ASSERT(sizeof(metadata_parameter_version_s) == 4);
1261+
1262+
struct metadata_parameter_version_s metadata_param_version;
1263+
metadata_param_version.pid = HostToNetwork(pid);
1264+
metadata_param_version.version = HostToNetwork(version);
1265+
1266+
return GetResponseFromData(
1267+
request,
1268+
reinterpret_cast<uint8_t*>(&metadata_param_version),
1269+
sizeof(metadata_parameter_version_s),
1270+
RDM_ACK,
1271+
queued_message_count);
1272+
}
1273+
1274+
RDMResponse *ResponderHelper::GetMetadataJSON(
1275+
const RDMRequest *request,
1276+
uint16_t pid,
1277+
const string &json,
1278+
uint8_t queued_message_count) {
1279+
PACK(
1280+
struct metadata_json_s {
1281+
uint16_t pid;
1282+
// TODO(Peter): This should effectively be unlimited...?
1283+
char json[(UINT8_MAX - 2)];
1284+
});
1285+
STATIC_ASSERT(sizeof(metadata_json_s) == UINT8_MAX);
1286+
1287+
struct metadata_json_s metadata_json;
1288+
metadata_json.pid = HostToNetwork(pid);
1289+
1290+
size_t str_len = min(json.size(),
1291+
sizeof(metadata_json.json));
1292+
strncpy(metadata_json.json, json.c_str(), str_len);
1293+
1294+
unsigned int param_data_size = (
1295+
sizeof(metadata_json) -
1296+
sizeof(metadata_json.json) + str_len);
1297+
1298+
return GetResponseFromData(
1299+
request,
1300+
reinterpret_cast<uint8_t*>(&metadata_json),
1301+
param_data_size,
1302+
RDM_ACK,
1303+
queued_message_count);
1304+
}
1305+
1306+
RDMResponse *ResponderHelper::GetEndpointList(
1307+
const RDMRequest *request,
1308+
const ola::rdm::EndpointManager *endpoint_manager,
1309+
uint8_t queued_message_count) {
1310+
PACK(
1311+
struct endpoint_info_s {
1312+
uint16_t endpoint_id;
1313+
uint8_t endpoint_type;
1314+
});
1315+
STATIC_ASSERT(sizeof(endpoint_info_s) == 3);
1316+
1317+
PACK(
1318+
struct endpoint_list_s {
1319+
uint32_t list_change_number;
1320+
endpoint_info_s endpoints[5];
1321+
});
1322+
STATIC_ASSERT(sizeof(endpoint_list_s) == (4 + (sizeof(endpoint_info_s) * 5)));
1323+
1324+
struct endpoint_list_s endpoint_list;
1325+
endpoint_list.list_change_number = HostToNetwork(endpoint_manager->list_change_number());
1326+
1327+
vector<uint16_t> endpoints;
1328+
1329+
endpoint_manager->EndpointIDs(&endpoints);
1330+
for (unsigned int i = 0; i < endpoints.size(); i++) {
1331+
endpoint_list.endpoints[i].endpoint_id = HostToNetwork(endpoints[i]);
1332+
}
1333+
1334+
unsigned int param_data_size = (
1335+
sizeof(endpoint_list) -
1336+
sizeof(endpoint_list.endpoints) + (sizeof(endpoint_info_s) * endpoints.size()));
1337+
1338+
return GetResponseFromData(
1339+
request,
1340+
reinterpret_cast<uint8_t*>(&endpoint_list),
1341+
param_data_size,
1342+
RDM_ACK,
1343+
queued_message_count);
1344+
}
1345+
1346+
RDMResponse *ResponderHelper::GetEndpointListChange(
1347+
const RDMRequest *request,
1348+
const ola::rdm::EndpointManager *endpoint_manager,
1349+
uint8_t queued_message_count) {
1350+
return GetUInt32Value(request,
1351+
NetworkToHost(endpoint_manager->list_change_number()),
1352+
queued_message_count);
1353+
}
1354+
1355+
11901356
/**
11911357
* @brief Handle a request that returns a string
11921358
* @note this truncates the string to max_length
@@ -1245,8 +1411,8 @@ RDMResponse *ResponderHelper::SetString(
12451411
}
12461412

12471413
RDMResponse *ResponderHelper::GetBoolValue(const RDMRequest *request,
1248-
bool value,
1249-
uint8_t queued_message_count) {
1414+
bool value,
1415+
uint8_t queued_message_count) {
12501416
if (request->ParamDataSize()) {
12511417
return NackWithReason(request, NR_FORMAT_ERROR, queued_message_count);
12521418
}
@@ -1257,8 +1423,8 @@ RDMResponse *ResponderHelper::GetBoolValue(const RDMRequest *request,
12571423
}
12581424

12591425
RDMResponse *ResponderHelper::SetBoolValue(const RDMRequest *request,
1260-
bool *value,
1261-
uint8_t queued_message_count) {
1426+
bool *value,
1427+
uint8_t queued_message_count) {
12621428
uint8_t arg;
12631429
if (!ResponderHelper::ExtractUInt8(request, &arg)) {
12641430
return NackWithReason(request, NR_FORMAT_ERROR, queued_message_count);
@@ -1274,8 +1440,8 @@ RDMResponse *ResponderHelper::SetBoolValue(const RDMRequest *request,
12741440

12751441
template<typename T>
12761442
static RDMResponse *GenericGetIntValue(const RDMRequest *request,
1277-
T value,
1278-
uint8_t queued_message_count = 0) {
1443+
T value,
1444+
uint8_t queued_message_count = 0) {
12791445
if (request->ParamDataSize()) {
12801446
return NackWithReason(request, NR_FORMAT_ERROR, queued_message_count);
12811447
}
@@ -1311,8 +1477,8 @@ RDMResponse *ResponderHelper::GetUInt32Value(
13111477

13121478
template<typename T>
13131479
static RDMResponse *GenericSetIntValue(const RDMRequest *request,
1314-
T *value,
1315-
uint8_t queued_message_count = 0) {
1480+
T *value,
1481+
uint8_t queued_message_count = 0) {
13161482
if (!GenericExtractValue(request, value)) {
13171483
return NackWithReason(request, NR_FORMAT_ERROR, queued_message_count);
13181484
}

0 commit comments

Comments
 (0)