Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions common/rdm/RDMCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,22 @@ RDMResponse *NackWithReason(const RDMRequest *request,
outstanding_messages);
}

RDMResponse *NackWithReason(const RDMResponse *response,
rdm_nack_reason reason_enum) {
uint16_t reason = ola::network::HostToNetwork(
static_cast<uint16_t>(reason_enum));
return new RDMResponse(response->SourceUID(),
response->DestinationUID(),
response->TransactionNumber(),
RDM_NACK_REASON,
response->MessageCount(),
response->SubDevice(),
response->CommandClass(),
response->ParamId(),
reinterpret_cast<uint8_t*>(&reason),
sizeof(reason));
}

RDMResponse *GetResponseFromData(const RDMRequest *request,
const uint8_t *data,
unsigned int length,
Expand Down
27 changes: 27 additions & 0 deletions common/rdm/RDMCommandTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,33 @@ void RDMCommandTest::testNackWithReason() {
OLA_ASSERT_EQ(2u, response->ParamDataSize());
OLA_ASSERT_EQ((uint16_t) ola::rdm::NR_WRITE_PROTECT,
NackReasonFromResponse(response.get()));

RDMResponse get_command_response(source,
destination,
0, // transaction #
ola::rdm::RDM_ACK, // response type
5, // message count
10, // sub device
RDMCommand::GET_COMMAND_RESPONSE,
296, // param id
NULL, // data
0); // data length

response.reset(NackWithReason(&get_command_response,
ola::rdm::NR_DATA_OUT_OF_RANGE));
OLA_ASSERT_NOT_NULL(response.get());
// Comparing response to response, so no flipping of UIDs
OLA_ASSERT_EQ(source, response->SourceUID());
OLA_ASSERT_EQ(destination, response->DestinationUID());
OLA_ASSERT_EQ((uint8_t) 0, response->TransactionNumber());
OLA_ASSERT_EQ((uint8_t) ola::rdm::RDM_NACK_REASON, response->ResponseType());
OLA_ASSERT_EQ((uint8_t) 5, response->MessageCount());
OLA_ASSERT_EQ((uint16_t) 10, response->SubDevice());
OLA_ASSERT_EQ(RDMCommand::GET_COMMAND_RESPONSE, response->CommandClass());
OLA_ASSERT_EQ((uint16_t) 296, response->ParamId());
OLA_ASSERT_EQ(2u, response->ParamDataSize());
OLA_ASSERT_EQ((uint16_t) ola::rdm::NR_DATA_OUT_OF_RANGE,
NackReasonFromResponse(response.get()));
}


Expand Down
8 changes: 8 additions & 0 deletions include/ola/rdm/RDMCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,14 @@ typedef BaseRDMResponse<RDMCommand::SET_COMMAND_RESPONSE> RDMSetResponse;
RDMResponse *NackWithReason(const RDMRequest *request,
rdm_nack_reason reason,
uint8_t outstanding_messages = 0);

/**
* @brief Make a NACK response with a reason code based on an existing
* RDMResponse
*/
RDMResponse *NackWithReason(const RDMResponse *response,
rdm_nack_reason reason);

/**
* @brief Generate an ACK Response with some data
*/
Expand Down