Skip to content

Commit 36e021c

Browse files
committed
Merge branch 'plugfest-pre-ci-break' of https://github.com/peternewman/ola into master-resync
2 parents 9e926f0 + e5bf604 commit 36e021c

17 files changed

Lines changed: 1280 additions & 79 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: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ RDMResponse *ResponderHelper::GetParamDescription(
965965
uint32_t min_value,
966966
uint32_t default_value,
967967
uint32_t max_value,
968-
string description,
968+
const string description,
969969
uint8_t queued_message_count) {
970970
PACK(
971971
struct parameter_description_s {
@@ -1019,7 +1019,7 @@ RDMResponse *ResponderHelper::GetASCIIParamDescription(
10191019
const RDMRequest *request,
10201020
uint16_t pid,
10211021
rdm_command_class command_class,
1022-
string description,
1022+
const string description,
10231023
uint8_t queued_message_count) {
10241024
return GetParamDescription(
10251025
request,
@@ -1041,7 +1041,7 @@ RDMResponse *ResponderHelper::GetBitFieldParamDescription(
10411041
uint16_t pid,
10421042
uint8_t pdl_size,
10431043
rdm_command_class command_class,
1044-
string description,
1044+
const string description,
10451045
uint8_t queued_message_count) {
10461046
return GetParamDescription(
10471047
request,
@@ -1110,6 +1110,65 @@ RDMResponse *ResponderHelper::SetTestData(
11101110
queued_message_count);
11111111
}
11121112

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

1249+
RDMResponse *ResponderHelper::GetMetadataParameterVersion(
1250+
const RDMRequest *request,
1251+
uint16_t pid,
1252+
uint16_t version,
1253+
uint8_t queued_message_count) {
1254+
PACK(
1255+
struct metadata_parameter_version_s {
1256+
uint16_t pid;
1257+
uint16_t version;
1258+
});
1259+
STATIC_ASSERT(sizeof(metadata_parameter_version_s) == 4);
1260+
1261+
struct metadata_parameter_version_s metadata_param_version;
1262+
metadata_param_version.pid = HostToNetwork(pid);
1263+
metadata_param_version.version = HostToNetwork(version);
1264+
1265+
return GetResponseFromData(
1266+
request,
1267+
reinterpret_cast<uint8_t*>(&metadata_param_version),
1268+
sizeof(metadata_parameter_version_s),
1269+
RDM_ACK,
1270+
queued_message_count);
1271+
}
1272+
1273+
RDMResponse *ResponderHelper::GetMetadataJSON(
1274+
const RDMRequest *request,
1275+
uint16_t pid,
1276+
const string json,
1277+
uint8_t queued_message_count) {
1278+
PACK(
1279+
struct metadata_json_s {
1280+
uint16_t pid;
1281+
// TODO(Peter): This should effectively be unlimited...?
1282+
char json[(UINT8_MAX - 2)];
1283+
});
1284+
STATIC_ASSERT(sizeof(metadata_json_s) == UINT8_MAX);
1285+
1286+
struct metadata_json_s metadata_json;
1287+
metadata_json.pid = HostToNetwork(pid);
1288+
1289+
size_t str_len = min(json.size(),
1290+
sizeof(metadata_json.json));
1291+
strncpy(metadata_json.json, json.c_str(), str_len);
1292+
1293+
unsigned int param_data_size = (
1294+
sizeof(metadata_json) -
1295+
sizeof(metadata_json.json) + str_len);
1296+
1297+
return GetResponseFromData(
1298+
request,
1299+
reinterpret_cast<uint8_t*>(&metadata_json),
1300+
param_data_size,
1301+
RDM_ACK,
1302+
queued_message_count);
1303+
}
1304+
1305+
11901306
/**
11911307
* @brief Handle a request that returns a string
11921308
* @note this truncates the string to max_length

common/utils/DmxBuffer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ bool DmxBuffer::operator!=(const DmxBuffer &other) const {
110110
}
111111

112112

113+
unsigned int DmxBuffer::AdditiveChecksum() const {
114+
unsigned int checksum = 0;
115+
for (unsigned int i = 0; i < Size(); i++) {
116+
checksum += m_data[i];
117+
}
118+
return checksum;
119+
}
120+
121+
113122
bool DmxBuffer::HTPMerge(const DmxBuffer &other) {
114123
if (!m_data) {
115124
if (!Init())

common/utils/DmxBufferTest.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class DmxBufferTest: public CppUnit::TestFixture {
3737
CPPUNIT_TEST(testStringGetSet);
3838
CPPUNIT_TEST(testAssign);
3939
CPPUNIT_TEST(testCopy);
40+
CPPUNIT_TEST(testAdditiveChecksum);
4041
CPPUNIT_TEST(testMerge);
4142
CPPUNIT_TEST(testStringToDmx);
4243
CPPUNIT_TEST(testCopyOnWrite);
@@ -52,6 +53,7 @@ class DmxBufferTest: public CppUnit::TestFixture {
5253
void testAssign();
5354
void testStringGetSet();
5455
void testCopy();
56+
void testAdditiveChecksum();
5557
void testMerge();
5658
void testStringToDmx();
5759
void testCopyOnWrite();
@@ -261,6 +263,21 @@ void DmxBufferTest::testCopy() {
261263
}
262264

263265

266+
/*
267+
* Check that the additive checksum works
268+
*/
269+
void DmxBufferTest::testAdditiveChecksum() {
270+
DmxBuffer buffer1(TEST_DATA, sizeof(TEST_DATA));
271+
OLA_ASSERT_EQ(15u, buffer1.AdditiveChecksum());
272+
273+
DmxBuffer buffer2(TEST_DATA2, sizeof(TEST_DATA2));
274+
OLA_ASSERT_EQ(45u, buffer2.AdditiveChecksum());
275+
276+
DmxBuffer buffer3(TEST_DATA3, sizeof(TEST_DATA3));
277+
OLA_ASSERT_EQ(33u, buffer3.AdditiveChecksum());
278+
}
279+
280+
264281
/*
265282
* Check that HTP Merging works
266283
*/

include/ola/DmxBuffer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class DmxBuffer {
110110
*/
111111
unsigned int Size() const { return m_length; }
112112

113+
/**
114+
* @brief Additive checksum of DmxBuffer
115+
* @return the additive checksum of slots in the buffer.
116+
*/
117+
unsigned int AdditiveChecksum() const;
118+
113119
/**
114120
* @brief HTP Merge from another DmxBuffer.
115121
* @param other the DmxBuffer to HTP merge into this one

include/ola/rdm/DummyResponder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class DummyResponder: public RDMControllerInterface {
135135
RDMResponse *GetFirmwareURL(const RDMRequest *request);
136136
RDMResponse *GetTestData(const RDMRequest *request);
137137
RDMResponse *SetTestData(const RDMRequest *request);
138+
RDMResponse *GetMetadataParameterVersion(const RDMRequest *request);
139+
RDMResponse *GetMetadataJSON(const RDMRequest *request);
140+
RDMResponse *GetMetadataJSONURL(const RDMRequest *request);
138141

139142
static const ResponderOps<DummyResponder>::ParamHandler PARAM_HANDLERS[];
140143
static const uint8_t DEFAULT_PERSONALITY = 2;

include/ola/rdm/Makefile.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ olardminclude_HEADERS = \
3434
include/ola/rdm/RDMReply.h \
3535
include/ola/rdm/ResponderHelper.h \
3636
include/ola/rdm/ResponderLoadSensor.h \
37+
include/ola/rdm/ResponderNSCStatus.h \
3738
include/ola/rdm/ResponderOps.h \
3839
include/ola/rdm/ResponderOpsPrivate.h \
3940
include/ola/rdm/ResponderPersonality.h \

include/ola/rdm/OpenLightingEnums.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ typedef enum {
5050
OLA_MANUFACTURER_PID_CODE_VERSION = 0x8001,
5151
} rdm_ola_manufacturer_pid;
5252

53+
// TODO(Peter): Some sort of vector against rdm_ola_manufacturer_pid or
54+
// something nicer?
55+
typedef enum {
56+
OLA_MANUFACTURER_PID_JSON_VERSION_SERIAL_NUMBER = 1,
57+
OLA_MANUFACTURER_PID_JSON_VERSION_CODE_VERSION = 1,
58+
} rdm_ola_manufacturer_pid_json_version;
59+
5360
/**
5461
* Also see the list here
5562
* https://wiki.openlighting.org/index.php/Open_Lighting_Allocations#RDM_Model_Numbers
@@ -77,6 +84,7 @@ typedef enum {
7784

7885
extern const char OLA_MANUFACTURER_LABEL[];
7986
extern const char OLA_MANUFACTURER_URL[];
87+
extern const char OLA_MANUFACTURER_PID_JSON_CODE_VERSION[];
8088
} // namespace rdm
8189
} // namespace ola
8290
#endif // INCLUDE_OLA_RDM_OPENLIGHTINGENUMS_H_

include/ola/rdm/RDMEnums.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,29 @@ static const uint8_t DNS_NAME_SERVER_MAX_INDEX = 2;
824824
// Consts for E1.37-5
825825
static const uint16_t MAX_RDM_TEST_DATA_PATTERN_LENGTH = 4096;
826826

827+
// bit masks for NSC status
828+
static const uint8_t NSC_STATUS_ADDITIVE_CHECKSUM_SUPPORTED_VALUE = 0x01;
829+
static const uint8_t NSC_STATUS_PACKET_COUNT_SUPPORTED_VALUE = 0x02;
830+
static const uint8_t NSC_STATUS_MOST_RECENT_SLOT_COUNT_SUPPORTED_VALUE = 0x04;
831+
static const uint8_t NSC_STATUS_MIN_SLOT_COUNT_SUPPORTED_VALUE = 0x08;
832+
static const uint8_t NSC_STATUS_MAX_SLOT_COUNT_SUPPORTED_VALUE = 0x10;
833+
static const uint8_t NSC_STATUS_PACKET_ERROR_COUNT_SUPPORTED_VALUE = 0x20;
834+
835+
// Consts for NSC status when unsupported
836+
static const uint32_t NSC_STATUS_ADDITIVE_CHECKSUM_UNSUPPORTED = 0xFFFFFFFF;
837+
static const uint32_t NSC_STATUS_PACKET_COUNT_UNSUPPORTED = 0xFFFFFFFF;
838+
static const uint16_t NSC_STATUS_MOST_RECENT_SLOT_COUNT_UNSUPPORTED = 0xFFFF;
839+
static const uint16_t NSC_STATUS_MIN_SLOT_COUNT_UNSUPPORTED = 0xFFFF;
840+
static const uint16_t NSC_STATUS_MAX_SLOT_COUNT_UNSUPPORTED = 0xFFFF;
841+
static const uint32_t NSC_STATUS_PACKET_ERROR_COUNT_UNSUPPORTED = 0xFFFFFFFF;
842+
843+
// Consts for NSC status max range
844+
static const uint32_t NSC_STATUS_PACKET_COUNT_MAX = 0xFFFFFFFE;
845+
static const uint16_t NSC_STATUS_MOST_RECENT_SLOT_COUNT_MAX = 0xFFFE;
846+
static const uint16_t NSC_STATUS_MIN_SLOT_COUNT_MAX = 0xFFFE;
847+
static const uint16_t NSC_STATUS_MAX_SLOT_COUNT_MAX = 0xFFFE;
848+
static const uint32_t NSC_STATUS_PACKET_ERROR_COUNT_MAX = 0xFFFFFFFE;
849+
827850
// The shipping lock states
828851
typedef enum {
829852
SHIPPING_LOCK_STATE_UNLOCKED = 0x00,

0 commit comments

Comments
 (0)