RDMnet  0.3.0
Implementation of ANSI E1.33 (RDMnet)
View other versions:
rdm_command.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_RDM_COMMAND_H_
24 #define RDMNET_CPP_MESSAGE_TYPES_RDM_COMMAND_H_
25 
26 #include <cstdint>
27 #include "etcpal/common.h"
28 #include "rdm/cpp/message.h"
29 #include "rdm/cpp/uid.h"
30 #include "rdmnet/defs.h"
31 #include "rdmnet/message.h"
32 
33 namespace rdmnet
34 {
35 class SavedRdmCommand;
36 
43 {
44 public:
46  RdmCommand() = delete;
48  RdmCommand(const RdmCommand& other) = delete;
50  RdmCommand& operator=(const RdmCommand& other) = delete;
51 
52  constexpr RdmCommand(const RdmnetRdmCommand& c_cmd) noexcept;
53 
54  constexpr rdm::Uid rdmnet_source_uid() const noexcept;
55  constexpr uint16_t dest_endpoint() const noexcept;
56  constexpr uint32_t seq_num() const noexcept;
57 
58  constexpr rdm::Uid rdm_source_uid() const noexcept;
59  constexpr rdm::Uid rdm_dest_uid() const noexcept;
60  constexpr uint16_t subdevice() const noexcept;
61  constexpr rdm_command_class_t command_class() const noexcept;
62  constexpr uint16_t param_id() const noexcept;
63 
64  constexpr rdm::CommandHeader rdm_header() const noexcept;
65 
66  constexpr const uint8_t* data() const noexcept;
67  constexpr uint8_t data_len() const noexcept;
68 
69  constexpr bool HasData() const noexcept;
70  constexpr bool IsToDefaultResponder() const noexcept;
71 
72  constexpr bool IsGet() const noexcept;
73  constexpr bool IsSet() const noexcept;
74 
75  constexpr const RdmnetRdmCommand& get() const noexcept;
76 
77  rdm::Command ToRdm() const;
78  SavedRdmCommand Save() const;
79 
80 private:
81  const RdmnetRdmCommand& cmd_;
82 };
83 
87 {
88 public:
90  SavedRdmCommand() = default;
91  constexpr SavedRdmCommand(const RdmnetSavedRdmCommand& c_cmd) noexcept;
92  SavedRdmCommand& operator=(const RdmnetSavedRdmCommand& c_cmd) noexcept;
93  SavedRdmCommand(const RdmCommand& command) noexcept;
94  SavedRdmCommand& operator=(const RdmCommand& command) noexcept;
95 
96  constexpr rdm::Uid rdmnet_source_uid() const noexcept;
97  constexpr uint16_t dest_endpoint() const noexcept;
98  constexpr uint32_t seq_num() const noexcept;
99 
100  constexpr rdm::Uid rdm_source_uid() const noexcept;
101  constexpr rdm::Uid rdm_dest_uid() const noexcept;
102  constexpr uint16_t subdevice() const noexcept;
103  constexpr rdm_command_class_t command_class() const noexcept;
104  constexpr uint16_t param_id() const noexcept;
105 
106  constexpr rdm::CommandHeader rdm_header() const noexcept;
107 
108  constexpr const uint8_t* data() const noexcept;
109  constexpr uint8_t data_len() const noexcept;
110 
111  bool IsValid() const noexcept;
112  constexpr bool HasData() const noexcept;
113  constexpr bool IsToDefaultResponder() const noexcept;
114 
115  constexpr bool IsGet() const noexcept;
116  constexpr bool IsSet() const noexcept;
117 
118  ETCPAL_CONSTEXPR_14 RdmnetSavedRdmCommand& get() noexcept;
119  constexpr const RdmnetSavedRdmCommand& get() const noexcept;
120 
121  rdm::Command ToRdm() const;
122 
123 private:
124  RdmnetSavedRdmCommand cmd_{};
125 };
126 
128 // RdmCommand function definitions
130 
132 constexpr RdmCommand::RdmCommand(const RdmnetRdmCommand& c_cmd) noexcept : cmd_(c_cmd)
133 {
134 }
135 
137 constexpr rdm::Uid RdmCommand::rdmnet_source_uid() const noexcept
138 {
139  return cmd_.rdmnet_source_uid;
140 }
141 
143 constexpr uint16_t RdmCommand::dest_endpoint() const noexcept
144 {
145  return cmd_.dest_endpoint;
146 }
147 
149 constexpr uint32_t RdmCommand::seq_num() const noexcept
150 {
151  return cmd_.seq_num;
152 }
153 
155 constexpr rdm::Uid RdmCommand::rdm_source_uid() const noexcept
156 {
157  return cmd_.rdm_header.source_uid;
158 }
159 
161 constexpr rdm::Uid RdmCommand::rdm_dest_uid() const noexcept
162 {
163  return cmd_.rdm_header.dest_uid;
164 }
165 
167 constexpr uint16_t RdmCommand::subdevice() const noexcept
168 {
169  return cmd_.rdm_header.subdevice;
170 }
171 
173 constexpr rdm_command_class_t RdmCommand::command_class() const noexcept
174 {
175  return cmd_.rdm_header.command_class;
176 }
177 
179 constexpr uint16_t RdmCommand::param_id() const noexcept
180 {
181  return cmd_.rdm_header.param_id;
182 }
183 
185 constexpr rdm::CommandHeader RdmCommand::rdm_header() const noexcept
186 {
187  return cmd_.rdm_header;
188 }
189 
191 constexpr const uint8_t* RdmCommand::data() const noexcept
192 {
193  return cmd_.data;
194 }
195 
197 constexpr uint8_t RdmCommand::data_len() const noexcept
198 {
199  return cmd_.data_len;
200 }
201 
203 constexpr bool RdmCommand::HasData() const noexcept
204 {
205  return (data_len() != 0);
206 }
207 
209 constexpr bool RdmCommand::IsGet() const noexcept
210 {
211  return (cmd_.rdm_header.command_class == kRdmCCGetCommand);
212 }
213 
215 constexpr bool RdmCommand::IsSet() const noexcept
216 {
217  return (cmd_.rdm_header.command_class == kRdmCCSetCommand);
218 }
219 
222 constexpr bool RdmCommand::IsToDefaultResponder() const noexcept
223 {
224  return (cmd_.dest_endpoint == E133_NULL_ENDPOINT);
225 }
226 
228 constexpr const RdmnetRdmCommand& RdmCommand::get() const noexcept
229 {
230  return cmd_;
231 }
232 
234 inline rdm::Command RdmCommand::ToRdm() const
235 {
236  return rdm::Command(cmd_.rdm_header, cmd_.data, cmd_.data_len);
237 }
238 
242 {
243  return SavedRdmCommand(*this);
244 }
245 
247 // SavedRdmCommand function definitions
249 
251 constexpr SavedRdmCommand::SavedRdmCommand(const RdmnetSavedRdmCommand& c_cmd) noexcept : cmd_(c_cmd)
252 {
253 }
254 
257 {
258  cmd_ = c_cmd;
259  return *this;
260 }
261 
263 inline SavedRdmCommand::SavedRdmCommand(const RdmCommand& command) noexcept
264 {
265  rdmnet_save_rdm_command(&command.get(), &cmd_);
266 }
267 
269 inline SavedRdmCommand& SavedRdmCommand::operator=(const RdmCommand& command) noexcept
270 {
271  rdmnet_save_rdm_command(&command.get(), &cmd_);
272  return *this;
273 }
274 
276 constexpr rdm::Uid SavedRdmCommand::rdmnet_source_uid() const noexcept
277 {
278  return cmd_.rdmnet_source_uid;
279 }
280 
282 constexpr uint16_t SavedRdmCommand::dest_endpoint() const noexcept
283 {
284  return cmd_.dest_endpoint;
285 }
286 
288 constexpr uint32_t SavedRdmCommand::seq_num() const noexcept
289 {
290  return cmd_.seq_num;
291 }
292 
294 constexpr rdm::Uid SavedRdmCommand::rdm_source_uid() const noexcept
295 {
296  return cmd_.rdm_header.source_uid;
297 }
298 
300 constexpr rdm::Uid SavedRdmCommand::rdm_dest_uid() const noexcept
301 {
302  return cmd_.rdm_header.dest_uid;
303 }
304 
306 constexpr uint16_t SavedRdmCommand::subdevice() const noexcept
307 {
308  return cmd_.rdm_header.subdevice;
309 }
310 
312 constexpr rdm_command_class_t SavedRdmCommand::command_class() const noexcept
313 {
314  return cmd_.rdm_header.command_class;
315 }
316 
318 constexpr uint16_t SavedRdmCommand::param_id() const noexcept
319 {
320  return cmd_.rdm_header.param_id;
321 }
322 
324 constexpr rdm::CommandHeader SavedRdmCommand::rdm_header() const noexcept
325 {
326  return cmd_.rdm_header;
327 }
328 
330 constexpr const uint8_t* SavedRdmCommand::data() const noexcept
331 {
332  return cmd_.data;
333 }
334 
336 constexpr uint8_t SavedRdmCommand::data_len() const noexcept
337 {
338  return cmd_.data_len;
339 }
340 
343 inline bool SavedRdmCommand::IsValid() const noexcept
344 {
345  return rdm_command_header_is_valid(&cmd_.rdm_header);
346 }
347 
349 constexpr bool SavedRdmCommand::HasData() const noexcept
350 {
351  return (data_len() != 0);
352 }
353 
356 constexpr bool SavedRdmCommand::IsToDefaultResponder() const noexcept
357 {
358  return (cmd_.dest_endpoint == E133_NULL_ENDPOINT);
359 }
360 
362 constexpr bool SavedRdmCommand::IsGet() const noexcept
363 {
364  return (cmd_.rdm_header.command_class == kRdmCCGetCommand);
365 }
366 
368 constexpr bool SavedRdmCommand::IsSet() const noexcept
369 {
370  return (cmd_.rdm_header.command_class == kRdmCCSetCommand);
371 }
372 
375 {
376  return cmd_;
377 }
378 
380 constexpr const RdmnetSavedRdmCommand& SavedRdmCommand::get() const noexcept
381 {
382  return cmd_;
383 }
384 
386 inline rdm::Command SavedRdmCommand::ToRdm() const
387 {
388  return rdm::Command(cmd_.rdm_header, cmd_.data, cmd_.data_len);
389 }
390 }; // namespace rdmnet
391 
392 #endif // RDMNET_CPP_MESSAGE_TYPES_RDM_COMMAND_H_
An RDM command received over RDMnet and delivered to an RDMnet callback function.
Definition: rdm_command.h:43
constexpr uint8_t data_len() const noexcept
Get the length of the RDM parameter data contained within this command.
Definition: rdm_command.h:197
RdmCommand(const RdmCommand &other)=delete
Not copyable - use Save() to create a copyable version.
constexpr uint16_t subdevice() const noexcept
Get the RDM subdevice to which this command is addressed (0 means the root device).
Definition: rdm_command.h:167
RdmCommand & operator=(const RdmCommand &other)=delete
Not copyable - use Save() to create a copyable version.
constexpr bool IsToDefaultResponder() const noexcept
Whether this command is addressed to the RDMnet default responder.
Definition: rdm_command.h:222
constexpr bool IsSet() const noexcept
Whether this command is an RDM SET command.
Definition: rdm_command.h:215
RdmCommand()=delete
Not default-constructible.
constexpr uint32_t seq_num() const noexcept
Get the RDMnet sequence number of this command.
Definition: rdm_command.h:149
constexpr uint16_t param_id() const noexcept
Get the RDM parameter ID (PID) of this command.
Definition: rdm_command.h:179
constexpr bool HasData() const noexcept
Whether this command has any associated RDM parameter data.
Definition: rdm_command.h:203
constexpr rdm::Uid rdm_dest_uid() const noexcept
Get the UID of the RDM responder to which this command is addressed.
Definition: rdm_command.h:161
SavedRdmCommand Save() const
Save the data in this command for later use with API functions from a different context.
Definition: rdm_command.h:241
rdm::Command ToRdm() const
Convert the RDM data in this command to an RDM command type.
Definition: rdm_command.h:234
constexpr rdm::Uid rdm_source_uid() const noexcept
Get the UID of the RDM controller that has sent this command.
Definition: rdm_command.h:155
constexpr uint16_t dest_endpoint() const noexcept
Get the endpoint to which this command is addressed.
Definition: rdm_command.h:143
constexpr rdm::CommandHeader rdm_header() const noexcept
Get the RDM protocol header contained within this command.
Definition: rdm_command.h:185
constexpr bool IsGet() const noexcept
Whether this command is an RDM GET command.
Definition: rdm_command.h:209
constexpr const RdmnetRdmCommand & get() const noexcept
Get a const reference to the underlying C type.
Definition: rdm_command.h:228
constexpr rdm_command_class_t command_class() const noexcept
Get the RDM command class of this command.
Definition: rdm_command.h:173
constexpr const uint8_t * data() const noexcept
Get a pointer to the RDM parameter data buffer contained within this command.
Definition: rdm_command.h:191
constexpr rdm::Uid rdmnet_source_uid() const noexcept
Get the UID of the RDMnet controller that sent this command.
Definition: rdm_command.h:137
An RDM command received over RDMnet by a local component and saved for a later response.
Definition: rdm_command.h:87
constexpr uint8_t data_len() const noexcept
Get the length of the RDM parameter data contained within this command.
Definition: rdm_command.h:336
constexpr bool IsToDefaultResponder() const noexcept
Whether this command is addressed to the RDMnet default responder.
Definition: rdm_command.h:356
constexpr uint16_t subdevice() const noexcept
Get the RDM subdevice to which this command is addressed (0 means the root device).
Definition: rdm_command.h:306
constexpr const uint8_t * data() const noexcept
Get a pointer to the RDM parameter data buffer contained within this command.
Definition: rdm_command.h:330
SavedRdmCommand & operator=(const RdmnetSavedRdmCommand &c_cmd) noexcept
Assign an instance of the C RdmnetSavedRdmCommand type to an instance of this class.
Definition: rdm_command.h:256
constexpr uint16_t param_id() const noexcept
Get the RDM parameter ID (PID) of this command.
Definition: rdm_command.h:318
constexpr rdm_command_class_t command_class() const noexcept
Get the RDM command class of this command.
Definition: rdm_command.h:312
constexpr rdm::CommandHeader rdm_header() const noexcept
Get the RDM protocol header contained within this command.
Definition: rdm_command.h:324
constexpr rdm::Uid rdm_source_uid() const noexcept
Get the UID of the RDM controller that sent this command.
Definition: rdm_command.h:294
constexpr bool HasData() const noexcept
Whether this command has any associated RDM parameter data.
Definition: rdm_command.h:349
rdm::Command ToRdm() const
Convert the RDM data in this command to an RDM command type.
Definition: rdm_command.h:386
constexpr bool IsGet() const noexcept
Whether this command is an RDM GET command.
Definition: rdm_command.h:362
constexpr rdm::Uid rdmnet_source_uid() const noexcept
Get the UID of the RDMnet controller that sent this command.
Definition: rdm_command.h:276
constexpr rdm::Uid rdm_dest_uid() const noexcept
Get the UID of the RDM responder to which this command is addressed.
Definition: rdm_command.h:300
constexpr bool IsSet() const noexcept
Whether this command is an RDM SET command.
Definition: rdm_command.h:368
constexpr uint32_t seq_num() const noexcept
Get the RDMnet sequence number of this command.
Definition: rdm_command.h:288
ETCPAL_CONSTEXPR_14 RdmnetSavedRdmCommand & get() noexcept
Get a mutable reference to the underlying C type.
Definition: rdm_command.h:374
SavedRdmCommand()=default
Construct an empty, invalid SavedRdmCommand by default.
bool IsValid() const noexcept
Whether the values contained in this command are valid for an RDM command.
Definition: rdm_command.h:343
constexpr uint16_t dest_endpoint() const noexcept
Get the endpoint to which this command is addressed.
Definition: rdm_command.h:282
#define ETCPAL_CONSTEXPR_14_OR_INLINE
etcpal_error_t rdmnet_save_rdm_command(const RdmnetRdmCommand *command, RdmnetSavedRdmCommand *saved_command)
Save the data in a received RDM command for later use with API functions from a different context.
Definition: message.c:70
Basic types for parsed RDMnet messages.
A namespace which contains all C++ language definitions in the RDMnet library.
Definition: broker.h:45
An RDMnet RDM command received by this component.
Definition: message.h:53
uint8_t data_len
The length of any associated RDM parameter data.
Definition: message.h:65
uint16_t dest_endpoint
The local endpoint to which this command is addressed.
Definition: message.h:57
RdmCommandHeader rdm_header
The header information from the encapsulated RDM command.
Definition: message.h:61
uint32_t seq_num
The command's sequence number, to be echoed in its response.
Definition: message.h:59
const uint8_t * data
Pointer to buffer containing any associated RDM parameter data.
Definition: message.h:63
RdmUid rdmnet_source_uid
The UID of the component that sent this command.
Definition: message.h:55
An RDM command received by this component and saved for a later response.
Definition: message.h:73