29 #ifndef INCLUDE_OLA_RDM_RDMMESSAGEPRINTERS_H_
30 #define INCLUDE_OLA_RDM_RDMMESSAGEPRINTERS_H_
34 #include <ola/messaging/MessagePrinter.h>
74 string TransformLabel(
const string &label) {
75 string new_label = label;
88 Stream() << field->Value() << endl;
98 void Visit(
const UInt8MessageField *field) {
99 if (m_messages.empty())
101 m_messages.back().status_type = field->Value();
102 m_messages.back().status_type_defined =
true;
105 void Visit(
const Int16MessageField *field) {
106 if (m_messages.empty())
108 status_message &message = m_messages.back();
109 if (message.int_offset < MAX_INT_FIELDS)
110 message.int16_fields[message.int_offset++] = field->Value();
113 void Visit(
const UInt16MessageField *field) {
114 if (m_messages.empty())
116 status_message &message = m_messages.back();
117 if (message.uint_offset < MAX_UINT_FIELDS)
118 message.uint16_fields[message.uint_offset++] = field->Value();
122 status_message message;
123 m_messages.push_back(message);
127 void PostStringHook() {
128 vector<status_message>::const_iterator iter = m_messages.begin();
129 for (; iter != m_messages.end(); ++iter) {
130 if (!iter->status_type_defined ||
131 iter->uint_offset != MAX_UINT_FIELDS ||
132 iter->int_offset != MAX_INT_FIELDS) {
133 OLA_WARN <<
"Invalid status message";
138 iter->uint16_fields[1],
139 iter->int16_fields[0],
140 iter->int16_fields[1]);
143 if (iter->uint16_fields[0])
144 Stream() <<
"Sub-device " << iter->uint16_fields[0] <<
": ";
146 if (message.empty()) {
147 Stream() <<
" message-id: " <<
148 iter->uint16_fields[1] <<
", data1: " << iter->int16_fields[0] <<
149 ", data2: " << iter->int16_fields[1] << endl;
151 Stream() << message << endl;
157 enum { MAX_INT_FIELDS = 2 };
158 enum { MAX_UINT_FIELDS = 2 };
159 struct status_message {
161 uint16_t uint16_fields[MAX_UINT_FIELDS];
162 int16_t int16_fields[MAX_INT_FIELDS];
166 bool status_type_defined;
168 status_message() : uint_offset(0), int_offset(0), status_type(0),
169 status_type_defined(
false) {}
171 vector<status_message> m_messages;
182 : m_manufacturer_id(manufacturer_id),
183 m_root_store(root_store) {}
185 void Visit(
const UInt16MessageField *message) {
186 m_pids.insert(message->Value());
190 void PostStringHook() {
191 set<uint16_t>::const_iterator iter = m_pids.begin();
192 for (; iter != m_pids.end(); ++iter) {
193 Stream() <<
" 0x" << std::hex << *iter;
195 *iter, m_manufacturer_id);
197 string name = descriptor->Name();
199 Stream() <<
" (" << name <<
")";
206 set<uint16_t> m_pids;
207 uint16_t m_manufacturer_id;
217 void Visit(
const UInt16MessageField *message) {
218 const string name = message->GetDescriptor()->Name();
219 if (name ==
"product_category")
220 Stream() << TransformLabel(name) <<
": " <<
223 GenericMessagePrinter::Visit(message);
227 string TransformLabel(
const string &label) {
228 string new_label = label;
241 Stream() << message->Value() << endl;
251 void Visit(
const UInt16MessageField *message) {
252 m_product_ids.insert(message->Value());
255 void PostStringHook() {
256 set<uint16_t>::const_iterator iter = m_product_ids.begin();
257 for (; iter != m_product_ids.end(); ++iter) {
262 set<uint16_t> m_product_ids;
272 m_languages.insert(message->Value());
275 void PostStringHook() {
276 set<string>::const_iterator iter = m_languages.begin();
277 for (; iter != m_languages.end(); ++iter) {
278 Stream() << *iter << endl;
282 set<string> m_languages;
292 void Visit(
const UInt16MessageField *message) {
293 m_year = message->Value();
296 void Visit(
const UInt8MessageField *message) {
297 if (m_offset < CLOCK_FIELDS)
298 m_fields[m_offset] = message->Value();
302 void PostStringHook() {
303 if (m_offset != CLOCK_FIELDS) {
304 Stream() <<
"Malformed packet";
306 Stream() << std::setfill(
'0') << std::setw(2) <<
307 static_cast<int>(m_fields[1]) <<
"/" <<
308 static_cast<int>(m_fields[0]) <<
"/" <<
310 static_cast<int>(m_fields[2]) <<
":" <<
311 static_cast<int>(m_fields[3]) <<
":" <<
312 static_cast<int>(m_fields[4]) << endl;
316 enum { CLOCK_FIELDS = 5};
318 uint8_t m_fields[CLOCK_FIELDS];
319 unsigned int m_offset;
327 void Visit(
const UInt8MessageField *field) {
328 if (m_slot_info.empty())
330 m_slot_info.back().type = field->Value();
331 m_slot_info.back().type_defined =
true;
334 void Visit(
const UInt16MessageField *field) {
335 if (m_slot_info.empty())
337 if (!m_slot_info.back().offset_defined) {
338 m_slot_info.back().offset = field->Value();
339 m_slot_info.back().offset_defined =
true;
341 m_slot_info.back().label = field->Value();
342 m_slot_info.back().label_defined =
true;
348 m_slot_info.push_back(slot);
352 void PostStringHook() {
353 vector<slot_info>::const_iterator iter = m_slot_info.begin();
354 for (; iter != m_slot_info.end(); ++iter) {
355 if (!iter->offset_defined ||
356 !iter->type_defined ||
357 !iter->label_defined) {
365 Stream() <<
" offset: " <<
366 iter->offset <<
", type: " << iter->type <<
367 ", label: " << iter->label << endl;
369 Stream() <<
"Slot offset " << iter->offset <<
": " << slot << endl;
384 slot_info() : offset(0), offset_defined(
false), type(0),
385 type_defined(
false), label(0), label_defined(
false) {}
387 vector<slot_info> m_slot_info;
391 #endif // INCLUDE_OLA_RDM_RDMMESSAGEPRINTERS_H_