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) {
263 Stream() << EncodeString(*iter) << std::endl;
267 std::set<std::string> m_languages;
278 m_year = message->Value();
282 if (m_offset < CLOCK_FIELDS)
283 m_fields[m_offset] = message->Value();
287 void PostStringHook() {
288 if (m_offset != CLOCK_FIELDS) {
289 Stream() <<
"Malformed packet";
291 Stream() << std::setfill(
'0') << std::setw(2) <<
292 static_cast<int>(m_fields[1]) <<
"/" <<
293 static_cast<int>(m_fields[0]) <<
"/" <<
295 static_cast<int>(m_fields[2]) <<
":" <<
296 static_cast<int>(m_fields[3]) <<
":" <<
297 static_cast<int>(m_fields[4]) << std::endl;
301 enum { CLOCK_FIELDS = 5};
303 uint8_t m_fields[CLOCK_FIELDS];
304 unsigned int m_offset;
313 if (m_slot_info.empty())
315 m_slot_info.back().type = field->Value();
316 m_slot_info.back().type_defined =
true;
320 if (m_slot_info.empty())
322 if (!m_slot_info.back().offset_defined) {
323 m_slot_info.back().offset = field->Value();
324 m_slot_info.back().offset_defined =
true;
326 m_slot_info.back().label = field->Value();
327 m_slot_info.back().label_defined =
true;
333 m_slot_info.push_back(slot);
337 void PostStringHook() {
338 std::vector<slot_info>::const_iterator iter = m_slot_info.begin();
339 for (; iter != m_slot_info.end(); ++iter) {
340 if (!iter->offset_defined ||
341 !iter->type_defined ||
342 !iter->label_defined) {
350 Stream() <<
" offset: " <<
351 iter->offset <<
", type: " << iter->type <<
352 ", label: " << iter->label << std::endl;
354 Stream() <<
"Slot offset " << iter->offset <<
": " << slot << std::endl;
369 slot_info() : offset(0), offset_defined(
false), type(0),
370 type_defined(
false), label(0), label_defined(
false) {}
372 std::vector<slot_info> m_slot_info;
382 const std::string name = message->GetDescriptor()->Name();
383 if (name ==
"type") {
384 Stream() << TransformLabel(name) <<
": " <<
386 }
else if (name ==
"unit") {
387 Stream() << TransformLabel(name) <<
": ";
388 if (message->Value() == UNITS_NONE) {
393 Stream() << std::endl;
394 }
else if (name ==
"prefix") {
395 Stream() << TransformLabel(name) <<
": ";
396 if (message->Value() == PREFIX_NONE) {
401 Stream() << std::endl;
402 }
else if (name ==
"supports_recording") {
403 Stream() << TransformLabel(name) <<
": ";
404 std::string supports_recording =
406 if (supports_recording.empty()) {
409 Stream() << supports_recording;
411 Stream() << std::endl;
413 ola::messaging::GenericMessagePrinter::Visit(message);
418 std::string TransformLabel(
const std::string &label) {
419 std::string new_label = label;
426 #endif // INCLUDE_OLA_RDM_RDMMESSAGEPRINTERS_H_