29 #ifndef INCLUDE_OLA_RDM_RDMMESSAGEPRINTERS_H_
30 #define INCLUDE_OLA_RDM_RDMMESSAGEPRINTERS_H_
34 #include <ola/messaging/MessagePrinter.h>
54 ola::messaging::GenericMessagePrinter::DEFAULT_INDENT,
58 std::string TransformLabel(
const std::string &label) {
59 std::string new_label = label;
72 Stream() << field->Value() << std::endl;
83 if (m_messages.empty())
85 m_messages.back().status_type = field->Value();
86 m_messages.back().status_type_defined =
true;
90 if (m_messages.empty())
92 status_message &message = m_messages.back();
93 if (message.int_offset < MAX_INT_FIELDS)
94 message.int16_fields[message.int_offset++] = field->Value();
98 if (m_messages.empty())
100 status_message &message = m_messages.back();
101 if (message.uint_offset < MAX_UINT_FIELDS)
102 message.uint16_fields[message.uint_offset++] = field->Value();
106 status_message message;
107 m_messages.push_back(message);
111 void PostStringHook() {
112 std::vector<status_message>::const_iterator iter = m_messages.begin();
113 for (; iter != m_messages.end(); ++iter) {
114 if (!iter->status_type_defined ||
115 iter->uint_offset != MAX_UINT_FIELDS ||
116 iter->int_offset != MAX_INT_FIELDS) {
117 OLA_WARN <<
"Invalid status message";
122 iter->uint16_fields[1],
123 iter->int16_fields[0],
124 iter->int16_fields[1]);
127 if (iter->uint16_fields[0])
128 Stream() <<
"Sub-device " << iter->uint16_fields[0] <<
": ";
130 if (message.empty()) {
131 Stream() <<
" message-id: " <<
132 iter->uint16_fields[1] <<
", data1: " << iter->int16_fields[0] <<
133 ", data2: " << iter->int16_fields[1] << std::endl;
135 Stream() << message << std::endl;
141 enum { MAX_INT_FIELDS = 2 };
142 enum { MAX_UINT_FIELDS = 2 };
143 struct status_message {
145 uint16_t uint16_fields[MAX_UINT_FIELDS];
146 int16_t int16_fields[MAX_INT_FIELDS];
150 bool status_type_defined;
152 status_message() : uint_offset(0), int_offset(0), status_type(0),
153 status_type_defined(
false) {}
155 std::vector<status_message> m_messages;
166 : m_manufacturer_id(manufacturer_id),
167 m_root_store(root_store) {}
170 m_pids.insert(message->Value());
174 void PostStringHook() {
175 std::set<uint16_t>::const_iterator iter = m_pids.begin();
176 for (; iter != m_pids.end(); ++iter) {
177 Stream() <<
" 0x" << std::hex << *iter;
179 *iter, m_manufacturer_id);
181 std::string name = descriptor->Name();
183 Stream() <<
" (" << name <<
")";
185 Stream() << std::endl;
190 std::set<uint16_t> m_pids;
191 uint16_t m_manufacturer_id;
202 const std::string name = message->GetDescriptor()->Name();
203 if (name ==
"product_category")
204 Stream() << TransformLabel(name) <<
": " <<
207 ola::messaging::GenericMessagePrinter::Visit(message);
211 std::string TransformLabel(
const std::string &label) {
212 std::string new_label = label;
225 Stream() <<
EncodeString(message->Value()) << std::endl;
236 m_product_ids.insert(message->Value());
239 void PostStringHook() {
240 std::set<uint16_t>::const_iterator iter = m_product_ids.begin();
241 for (; iter != m_product_ids.end(); ++iter) {
247 std::set<uint16_t> m_product_ids;
257 m_languages.insert(message->Value());
260 void PostStringHook() {
261 std::set<std::string>::const_iterator iter = m_languages.begin();
262 for (; iter != m_languages.end(); ++iter) {
267 std::set<std::string> m_languages;
281 m_year = message->Value();
285 if (m_offset < CLOCK_FIELDS)
286 m_fields[m_offset] = message->Value();
290 void PostStringHook() {
291 if (m_offset != CLOCK_FIELDS) {
292 Stream() <<
"Malformed packet";
294 Stream() << std::setfill(
'0') << std::setw(2) <<
295 static_cast<int>(m_fields[1]) <<
"/" <<
296 static_cast<int>(m_fields[0]) <<
"/" <<
298 static_cast<int>(m_fields[2]) <<
":" <<
299 static_cast<int>(m_fields[3]) <<
":" <<
300 static_cast<int>(m_fields[4]) << std::endl;
304 enum { CLOCK_FIELDS = 5};
306 uint8_t m_fields[CLOCK_FIELDS];
307 unsigned int m_offset;
316 if (m_slot_info.empty())
318 m_slot_info.back().type = field->Value();
319 m_slot_info.back().type_defined =
true;
323 if (m_slot_info.empty())
325 if (!m_slot_info.back().offset_defined) {
326 m_slot_info.back().offset = field->Value();
327 m_slot_info.back().offset_defined =
true;
329 m_slot_info.back().label = field->Value();
330 m_slot_info.back().label_defined =
true;
336 m_slot_info.push_back(slot);
340 void PostStringHook() {
341 std::vector<slot_info>::const_iterator iter = m_slot_info.begin();
342 for (; iter != m_slot_info.end(); ++iter) {
343 if (!iter->offset_defined ||
344 !iter->type_defined ||
345 !iter->label_defined) {
353 Stream() <<
" offset: " <<
354 iter->offset <<
", type: " << iter->type <<
355 ", label: " << iter->label << std::endl;
357 Stream() <<
"Slot offset " << iter->offset <<
": " << slot << std::endl;
372 slot_info() : offset(0), offset_defined(
false), type(0),
373 type_defined(
false), label(0), label_defined(
false) {}
375 std::vector<slot_info> m_slot_info;
385 const std::string name = message->GetDescriptor()->Name();
386 if (name ==
"type") {
387 Stream() << TransformLabel(name) <<
": " <<
389 }
else if (name ==
"unit") {
390 Stream() << TransformLabel(name) <<
": ";
391 if (message->Value() == UNITS_NONE) {
396 Stream() << std::endl;
397 }
else if (name ==
"prefix") {
398 Stream() << TransformLabel(name) <<
": ";
399 if (message->Value() == PREFIX_NONE) {
404 Stream() << std::endl;
405 }
else if (name ==
"supports_recording") {
406 Stream() << TransformLabel(name) <<
": ";
407 std::string supports_recording =
409 if (supports_recording.empty()) {
412 Stream() << supports_recording;
414 Stream() << std::endl;
416 ola::messaging::GenericMessagePrinter::Visit(message);
421 std::string TransformLabel(
const std::string &label) {
422 std::string new_label = label;
429 #endif // INCLUDE_OLA_RDM_RDMMESSAGEPRINTERS_H_