RDMnet  0.3.0
Implementation of ANSI E1.33 (RDMnet)
View other versions:
llrp_rdm_response.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2020 ETC Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************
16  * This file is a part of RDMnet. For more information, go to:
17  * https://github.com/ETCLabs/RDMnet
18  *****************************************************************************/
19 
22 
23 #ifndef RDMNET_CPP_MESSAGE_TYPES_LLRP_RDM_RESPONSE_H_
24 #define RDMNET_CPP_MESSAGE_TYPES_LLRP_RDM_RESPONSE_H_
25 
26 #include <cstdint>
27 #include "etcpal/cpp/error.h"
28 #include "etcpal/cpp/uuid.h"
29 #include "rdm/cpp/message.h"
30 #include "rdm/cpp/uid.h"
31 #include "rdmnet/message.h"
32 
33 namespace rdmnet
34 {
35 namespace llrp
36 {
37 class SavedRdmResponse;
38 
45 {
46 public:
48  RdmResponse() = delete;
50  RdmResponse(const RdmResponse& other) = delete;
52  RdmResponse& operator=(const RdmResponse& other) = delete;
53 
54  constexpr RdmResponse(const LlrpRdmResponse& c_resp) noexcept;
55 
56  constexpr etcpal::Uuid source_cid() const noexcept;
57  constexpr uint32_t seq_num() const noexcept;
58 
59  constexpr rdm::Uid source_uid() const noexcept;
60  constexpr rdm::Uid dest_uid() const noexcept;
61  constexpr rdm_response_type_t response_type() const noexcept;
62  constexpr uint16_t subdevice() const noexcept;
63  constexpr rdm_command_class_t command_class() const noexcept;
64  constexpr uint16_t param_id() const noexcept;
65  constexpr rdm::ResponseHeader rdm_header() const noexcept;
66  constexpr const uint8_t* data() const noexcept;
67  constexpr uint8_t data_len() const noexcept;
68 
69  constexpr bool HasData() const noexcept;
70 
71  constexpr bool IsAck() const noexcept;
72  constexpr bool IsNack() const noexcept;
73 
74  constexpr bool IsGetResponse() const noexcept;
75  constexpr bool IsSetResponse() const noexcept;
76 
77  constexpr const LlrpRdmResponse& get() const noexcept;
78 
79  etcpal::Expected<rdm::NackReason> GetNackReason() const noexcept;
80 
81  rdm::Response ToRdm() const;
82  SavedRdmResponse Save() const;
83 
84 private:
85  const LlrpRdmResponse& resp_;
86 };
87 
95 {
96 public:
98  SavedRdmResponse() = default;
101  SavedRdmResponse(const RdmResponse& resp);
102  SavedRdmResponse& operator=(const RdmResponse& resp);
103 
104  const etcpal::Uuid& source_cid() const noexcept;
105  uint32_t seq_num() const noexcept;
106 
107  rdm::Uid source_uid() const noexcept;
108  rdm::Uid dest_uid() const noexcept;
109  rdm_response_type_t response_type() const noexcept;
110  uint16_t subdevice() const noexcept;
111  rdm_command_class_t command_class() const noexcept;
112  uint16_t param_id() const noexcept;
113  const rdm::ResponseHeader& rdm_header() const noexcept;
114  const uint8_t* data() const noexcept;
115  uint8_t data_len() const noexcept;
116  const rdm::Response& rdm() const noexcept;
117 
118  bool IsValid() const noexcept;
119  bool HasData() const noexcept;
120 
121  bool IsAck() const noexcept;
122  bool IsNack() const noexcept;
123 
124  bool IsGetResponse() const noexcept;
125  bool IsSetResponse() const noexcept;
126 
127  etcpal::Expected<rdm::NackReason> GetNackReason() const noexcept;
128 
129 private:
130  etcpal::Uuid source_cid_;
131  uint32_t seq_num_;
132  rdm::Response rdm_;
133 };
134 
136 // llrp::RdmResponse function definitions
138 
140 constexpr RdmResponse::RdmResponse(const LlrpRdmResponse& c_resp) noexcept : resp_(c_resp)
141 {
142 }
143 
145 constexpr etcpal::Uuid RdmResponse::source_cid() const noexcept
146 {
147  return resp_.source_cid;
148 }
149 
151 constexpr uint32_t RdmResponse::seq_num() const noexcept
152 {
153  return resp_.seq_num;
154 }
155 
157 constexpr rdm::Uid RdmResponse::source_uid() const noexcept
158 {
159  return resp_.rdm_header.source_uid;
160 }
161 
163 constexpr rdm::Uid RdmResponse::dest_uid() const noexcept
164 {
165  return resp_.rdm_header.dest_uid;
166 }
167 
169 constexpr rdm_response_type_t RdmResponse::response_type() const noexcept
170 {
171  return resp_.rdm_header.resp_type;
172 }
173 
175 constexpr uint16_t RdmResponse::subdevice() const noexcept
176 {
177  return resp_.rdm_header.subdevice;
178 }
179 
181 constexpr rdm_command_class_t RdmResponse::command_class() const noexcept
182 {
183  return resp_.rdm_header.command_class;
184 }
185 
187 constexpr uint16_t RdmResponse::param_id() const noexcept
188 {
189  return resp_.rdm_header.param_id;
190 }
191 
193 constexpr rdm::ResponseHeader RdmResponse::rdm_header() const noexcept
194 {
195  return resp_.rdm_header;
196 }
197 
199 constexpr const uint8_t* RdmResponse::data() const noexcept
200 {
201  return resp_.rdm_data;
202 }
203 
205 constexpr uint8_t RdmResponse::data_len() const noexcept
206 {
207  return resp_.rdm_data_len;
208 }
209 
211 constexpr bool RdmResponse::HasData() const noexcept
212 {
213  return (data_len() != 0);
214 }
215 
220 constexpr bool RdmResponse::IsAck() const noexcept
221 {
222  return (resp_.rdm_header.resp_type == kRdmResponseTypeAck);
223 }
224 
229 constexpr bool RdmResponse::IsNack() const noexcept
230 {
231  return (resp_.rdm_header.resp_type == kRdmResponseTypeNackReason);
232 }
233 
235 constexpr bool RdmResponse::IsGetResponse() const noexcept
236 {
237  return (resp_.rdm_header.command_class == kRdmCCGetCommandResponse);
238 }
239 
241 constexpr bool RdmResponse::IsSetResponse() const noexcept
242 {
243  return (resp_.rdm_header.command_class == kRdmCCSetCommandResponse);
244 }
245 
250 {
251  if (IsNack() && data_len() >= 2)
252  return etcpal_unpack_u16b(data());
253  else
254  return kEtcPalErrInvalid;
255 }
256 
258 constexpr const LlrpRdmResponse& RdmResponse::get() const noexcept
259 {
260  return resp_;
261 }
262 
264 inline rdm::Response RdmResponse::ToRdm() const
265 {
266  return rdm::Response(resp_.rdm_header, resp_.rdm_data, resp_.rdm_data_len);
267 }
268 
272 {
273  return SavedRdmResponse(*this);
274 }
275 
277 // llrp::SavedRdmResponse function definitions
279 
282  : source_cid_(c_resp.source_cid)
283  , seq_num_(c_resp.seq_num)
284  , rdm_(c_resp.rdm_header, c_resp.rdm_data, c_resp.rdm_data_len)
285 {
286 }
287 
290 {
291  source_cid_ = c_resp.source_cid;
292  seq_num_ = c_resp.seq_num;
293  rdm_ = rdm::Response(c_resp.rdm_header, c_resp.rdm_data, c_resp.rdm_data_len);
294  return *this;
295 }
296 
299  : source_cid_(resp.source_cid()), seq_num_(resp.seq_num()), rdm_(resp.ToRdm())
300 {
301 }
302 
305 {
306  source_cid_ = resp.source_cid();
307  seq_num_ = resp.seq_num();
308  rdm_ = resp.ToRdm();
309  return *this;
310 }
311 
313 inline const etcpal::Uuid& SavedRdmResponse::source_cid() const noexcept
314 {
315  return source_cid_;
316 }
317 
319 inline uint32_t SavedRdmResponse::seq_num() const noexcept
320 {
321  return seq_num_;
322 }
323 
325 inline rdm::Uid SavedRdmResponse::source_uid() const noexcept
326 {
327  return rdm_.source_uid();
328 }
329 
331 inline rdm::Uid SavedRdmResponse::dest_uid() const noexcept
332 {
333  return rdm_.dest_uid();
334 }
335 
337 inline rdm_response_type_t SavedRdmResponse::response_type() const noexcept
338 {
339  return rdm_.response_type();
340 }
341 
343 inline uint16_t SavedRdmResponse::subdevice() const noexcept
344 {
345  return rdm_.subdevice();
346 }
347 
349 inline rdm_command_class_t SavedRdmResponse::command_class() const noexcept
350 {
351  return rdm_.command_class();
352 }
353 
355 inline uint16_t SavedRdmResponse::param_id() const noexcept
356 {
357  return rdm_.param_id();
358 }
359 
361 inline const rdm::ResponseHeader& SavedRdmResponse::rdm_header() const noexcept
362 {
363  return rdm_.header();
364 }
365 
367 inline const uint8_t* SavedRdmResponse::data() const noexcept
368 {
369  return rdm_.data();
370 }
371 
373 inline uint8_t SavedRdmResponse::data_len() const noexcept
374 {
375  return static_cast<uint8_t>(rdm_.data_len());
376 }
377 
379 inline const rdm::Response& SavedRdmResponse::rdm() const noexcept
380 {
381  return rdm_;
382 }
383 
386 inline bool SavedRdmResponse::IsValid() const noexcept
387 {
388  return rdm_.IsValid();
389 }
390 
392 inline bool SavedRdmResponse::HasData() const noexcept
393 {
394  return rdm_.HasData();
395 }
396 
401 inline bool SavedRdmResponse::IsAck() const noexcept
402 {
403  return rdm_.IsAck();
404 }
405 
410 inline bool SavedRdmResponse::IsNack() const noexcept
411 {
412  return rdm_.IsNack();
413 }
414 
416 inline bool SavedRdmResponse::IsGetResponse() const noexcept
417 {
418  return rdm_.IsGetResponse();
419 }
420 
422 inline bool SavedRdmResponse::IsSetResponse() const noexcept
423 {
424  return rdm_.IsSetResponse();
425 }
426 
431 {
432  return rdm_.GetNackReason();
433 }
434 
435 }; // namespace llrp
436 }; // namespace rdmnet
437 
438 #endif // RDMNET_CPP_MESSAGE_TYPES_LLRP_RDM_RESPONSE_H_
An RDM response received over LLRP and delivered to an RDMnet callback function.
Definition: llrp_rdm_response.h:45
RdmResponse & operator=(const RdmResponse &other)=delete
Not copyable - use Save() to create a copyable version.
constexpr rdm::ResponseHeader rdm_header() const noexcept
Get the RDM protocol header contained within this response.
Definition: llrp_rdm_response.h:193
constexpr uint16_t param_id() const noexcept
Get the RDM parameter ID (PID) of this response.
Definition: llrp_rdm_response.h:187
constexpr bool IsNack() const noexcept
Whether this response has an RDM response type of NACK_REASON.
Definition: llrp_rdm_response.h:229
constexpr etcpal::Uuid source_cid() const noexcept
Get the CID of the LLRP target that sent this response.
Definition: llrp_rdm_response.h:145
constexpr uint8_t data_len() const noexcept
Get the length of the RDM parameter data contained within this response.
Definition: llrp_rdm_response.h:205
rdm::Response ToRdm() const
Convert the RDM data in this response to an RDM response type.
Definition: llrp_rdm_response.h:264
constexpr bool IsAck() const noexcept
Whether this response has an RDM response type of ACK.
Definition: llrp_rdm_response.h:220
constexpr rdm_command_class_t command_class() const noexcept
Get the RDM response class of this response.
Definition: llrp_rdm_response.h:181
constexpr const uint8_t * data() const noexcept
Get a pointer to the RDM parameter data buffer contained within this response.
Definition: llrp_rdm_response.h:199
constexpr rdm::Uid source_uid() const noexcept
Get the UID of the LLRP target that sent this response.
Definition: llrp_rdm_response.h:157
SavedRdmResponse Save() const
Save the data in this response for later use from a different context.
Definition: llrp_rdm_response.h:271
constexpr rdm_response_type_t response_type() const noexcept
Get the RDM response type of this response.
Definition: llrp_rdm_response.h:169
constexpr uint16_t subdevice() const noexcept
Get the RDM subdevice from which this response originated (0 means the root device).
Definition: llrp_rdm_response.h:175
RdmResponse()=delete
Not default-constructible.
constexpr uint32_t seq_num() const noexcept
Get the LLRP sequence number of this response, for matching with a corresponding command.
Definition: llrp_rdm_response.h:151
constexpr rdm::Uid dest_uid() const noexcept
Get the UID of the LLRP manager to which this response is addressed.
Definition: llrp_rdm_response.h:163
constexpr bool IsSetResponse() const noexcept
Whether this response is an RDM SET response.
Definition: llrp_rdm_response.h:241
RdmResponse(const RdmResponse &other)=delete
Not copyable - use Save() to create a copyable version.
constexpr bool HasData() const noexcept
Whether this RDM response includes any RDM parameter data.
Definition: llrp_rdm_response.h:211
constexpr const LlrpRdmResponse & get() const noexcept
Get a const reference to the underlying C type.
Definition: llrp_rdm_response.h:258
etcpal::Expected< rdm::NackReason > GetNackReason() const noexcept
Get the NACK reason code of this RDM response.
Definition: llrp_rdm_response.h:249
constexpr bool IsGetResponse() const noexcept
Whether this response is an RDM GET response.
Definition: llrp_rdm_response.h:235
An RDM response received over LLRP and saved for later processing.
Definition: llrp_rdm_response.h:95
bool HasData() const noexcept
Whether this RDM response includes any RDM parameter data.
Definition: llrp_rdm_response.h:392
const etcpal::Uuid & source_cid() const noexcept
Get the CID of the LLRP target that sent this response.
Definition: llrp_rdm_response.h:313
bool IsSetResponse() const noexcept
Whether this response is an RDM SET response.
Definition: llrp_rdm_response.h:422
bool IsAck() const noexcept
Whether this response has an RDM response type of ACK.
Definition: llrp_rdm_response.h:401
uint16_t subdevice() const noexcept
Get the RDM subdevice from which this response originated (0 means the root device).
Definition: llrp_rdm_response.h:343
etcpal::Expected< rdm::NackReason > GetNackReason() const noexcept
Get the NACK reason code of this RDM response.
Definition: llrp_rdm_response.h:430
const rdm::Response & rdm() const noexcept
Get the RDM data in this response as an RDM response type.
Definition: llrp_rdm_response.h:379
bool IsValid() const noexcept
Whether the values contained in this response are valid for an RDM response.
Definition: llrp_rdm_response.h:386
const rdm::ResponseHeader & rdm_header() const noexcept
Get the RDM protocol header contained within this response.
Definition: llrp_rdm_response.h:361
uint32_t seq_num() const noexcept
Get the LLRP sequence number of this response, for matching with a corresponding command.
Definition: llrp_rdm_response.h:319
SavedRdmResponse & operator=(const LlrpSavedRdmResponse &c_resp)
Assign an instance of the C LlrpSavedRdmResponse type to an instance of this class.
Definition: llrp_rdm_response.h:289
rdm_response_type_t response_type() const noexcept
Get the RDM response type of this response.
Definition: llrp_rdm_response.h:337
rdm::Uid dest_uid() const noexcept
Get the UID of the LLRP manager to which this response is addressed.
Definition: llrp_rdm_response.h:331
uint8_t data_len() const noexcept
Get the length of the RDM parameter data contained within this response.
Definition: llrp_rdm_response.h:373
rdm_command_class_t command_class() const noexcept
Get the RDM response class of this response.
Definition: llrp_rdm_response.h:349
bool IsGetResponse() const noexcept
Whether this response is an RDM GET response.
Definition: llrp_rdm_response.h:416
uint16_t param_id() const noexcept
Get the RDM parameter ID (PID) of this response.
Definition: llrp_rdm_response.h:355
rdm::Uid source_uid() const noexcept
Get the UID of the LLRP target that sent this response.
Definition: llrp_rdm_response.h:325
SavedRdmResponse()=default
Constructs an empty, invalid RDM response by default.
bool IsNack() const noexcept
Whether this response has an RDM response type of NACK_REASON.
Definition: llrp_rdm_response.h:410
const uint8_t * data() const noexcept
Get a pointer to the RDM parameter data buffer contained within this response.
Definition: llrp_rdm_response.h:367
kEtcPalErrInvalid
uint16_t etcpal_unpack_u16b(const uint8_t *buf)
Basic types for parsed RDMnet messages.
A namespace which contains all C++ language definitions in the RDMnet library.
Definition: broker.h:45
An RDM response received from a remote LLRP Target.
Definition: message.h:479
An RDM command received from a remote LLRP Manager.
Definition: message.h:494
uint32_t seq_num
The sequence number of this response (to be associated with a previously-sent command).
Definition: message.h:498
uint8_t rdm_data_len
The length of the parameter data associated with the RDM response.
Definition: message.h:504
uint8_t rdm_data[RDM_MAX_PDL]
Any parameter data associated with the RDM response.
Definition: message.h:502
EtcPalUuid source_cid
The CID of the LLRP Target from which this command was received.
Definition: message.h:496
RdmResponseHeader rdm_header
The header information from the encapsulated RDM response.
Definition: message.h:500