Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 57 additions & 38 deletions common/rdm/CommandPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace rdm {
using ola::messaging::Descriptor;
using ola::messaging::Message;
using ola::network::NetworkToHost;
using ola::strings::ToHex;
using std::auto_ptr;
using std::endl;
using std::string;
Expand Down Expand Up @@ -110,13 +111,12 @@ void CommandPrinter::DisplayRequest(const RDMRequest *request,
AppendPortId(request);
AppendHeaderFields(request, (is_get ? "GET" : "SET"));

*m_output << " Param ID : 0x" << std::setfill('0') << std::setw(4)
<< std::hex << request->ParamId();
if (descriptor)
*m_output << " Param ID : " << ToHex(request->ParamId());
if (descriptor) {
*m_output << " (" << descriptor->Name() << ")";
}
*m_output << endl;
*m_output << " Param data len : " << std::dec << request->ParamDataSize()
<< endl;
*m_output << " Param data len : " << request->ParamDataSize() << endl;
DisplayParamData(descriptor,
unpack_param_data,
true,
Expand Down Expand Up @@ -154,12 +154,12 @@ void CommandPrinter::DisplayResponse(const RDMResponse *response,
AppendVerboseResponseType(response);
AppendHeaderFields(response, (is_get ? "GET_RESPONSE" : "SET_RESPONSE"));

*m_output << " Param ID : 0x" << std::setfill('0') << std::setw(4)
<< std::hex << response->ParamId();
if (descriptor)
*m_output << " Param ID : " << ToHex(response->ParamId());
if (descriptor) {
*m_output << " (" << descriptor->Name() << ")";
}
*m_output << endl;
*m_output << " Param data len : " << std::dec << response->ParamDataSize()
*m_output << " Param data len : " << response->ParamDataSize()
<< endl;
DisplayParamData(descriptor,
unpack_param_data,
Expand All @@ -182,6 +182,8 @@ void CommandPrinter::DisplayDiscoveryRequest(
const RDMDiscoveryRequest *request,
bool summarize,
bool unpack_param_data) {
// We can't just get a descriptor here like the other code as we don't store
// them for discovery commands
string param_name;
switch (request->ParamId()) {
case ola::rdm::PID_DISC_UNIQUE_BRANCH:
Expand All @@ -197,8 +199,7 @@ void CommandPrinter::DisplayDiscoveryRequest(

if (summarize) {
AppendUIDsAndType(request, "DISCOVERY_COMMAND");
*m_output << ", PID 0x" << std::hex << std::setfill('0') << std::setw(4) <<
request->ParamId();
*m_output << ", PID " << ToHex(request->ParamId());
if (!param_name.empty())
*m_output << " (" << param_name << ")";
if (request->ParamId() == ola::rdm::PID_DISC_UNIQUE_BRANCH &&
Expand All @@ -216,19 +217,28 @@ void CommandPrinter::DisplayDiscoveryRequest(
AppendPortId(request);
AppendHeaderFields(request, "DISCOVERY_COMMAND");

*m_output << " Param ID : 0x" << std::setfill('0') << std::setw(4)
<< std::hex << request->ParamId();
if (!param_name.empty())
*m_output << " Param ID : " << ToHex(request->ParamId());
if (!param_name.empty()) {
*m_output << " (" << param_name << ")";
}
*m_output << endl;
*m_output << " Param data len : " << std::dec << request->ParamDataSize()
<< endl;
DisplayParamData(NULL,
unpack_param_data,
true,
false,
request->ParamData(),
request->ParamDataSize());
<< endl;
if (request->ParamId() == ola::rdm::PID_DISC_UNIQUE_BRANCH &&
request->ParamDataSize() == 2 * UID::UID_SIZE) {
const uint8_t *param_data = request->ParamData();
UID lower(param_data);
UID upper(param_data + UID::UID_SIZE);
*m_output << " Lower UID : " << lower << endl;
*m_output << " Upper UID : " << upper << endl;
} else {
DisplayParamData(NULL,
unpack_param_data,
true,
false,
request->ParamData(),
request->ParamDataSize());
}
}
}

Expand All @@ -244,6 +254,8 @@ void CommandPrinter::DisplayDiscoveryResponse(
const RDMDiscoveryResponse *response,
bool summarize,
bool unpack_param_data) {
// We can't just get a descriptor here like the other code as we don't store
// them for discovery commands
string param_name;
switch (response->ParamId()) {
case ola::rdm::PID_DISC_UNIQUE_BRANCH:
Expand All @@ -259,32 +271,32 @@ void CommandPrinter::DisplayDiscoveryResponse(

if (summarize) {
AppendUIDsAndType(response, "DISCOVERY_COMMAND_RESPONSE");
*m_output << ", PID 0x" << std::hex << std::setfill('0') << std::setw(4) <<
response->ParamId();
if (!param_name.empty())
*m_output << ", PID " << ToHex(response->ParamId());
if (!param_name.empty()) {
*m_output << " (" << param_name << ")";
}
if (response->ParamId() == ola::rdm::PID_DISC_UNIQUE_BRANCH &&
response->ParamDataSize() == 2 * UID::UID_SIZE) {
const uint8_t *param_data = response->ParamData();
UID lower(param_data);
UID upper(param_data + UID::UID_SIZE);
*m_output << ", (" << lower << ", " << upper << ")";
} else {
*m_output << ", pdl: " << std::dec << response->ParamDataSize();
*m_output << ", pdl: " << response->ParamDataSize();
}
*m_output << endl;
} else {
AppendVerboseUIDs(response);
AppendVerboseResponseType(response);
AppendHeaderFields(response, "DISCOVERY_COMMAND_RESPONSE");

*m_output << " Param ID : 0x" << std::setfill('0') << std::setw(4)
<< std::hex << response->ParamId();
if (!param_name.empty())
*m_output << " Param ID : " << ToHex(response->ParamId());
if (!param_name.empty()) {
*m_output << " (" << param_name << ")";
}
*m_output << endl;
*m_output << " Param data len : " << std::dec << response->ParamDataSize()
<< endl;
*m_output << " Param data len : " << response->ParamDataSize()
<< endl;
DisplayParamData(NULL,
unpack_param_data,
true,
Expand Down Expand Up @@ -313,6 +325,12 @@ void CommandPrinter::AppendPortId(const class RDMRequest *request) {
}


void CommandPrinter::AppendMessageLength(const class RDMRequest *request) {
*m_output << " Message Length : " << std::dec <<
static_cast<unsigned int>(request->MessageLength()) << endl;
}


void CommandPrinter::AppendVerboseUIDs(const class RDMCommand *command) {
*m_output << " Source UID : " << command->SourceUID() << endl;
*m_output << " Dest UID : " << command->DestinationUID() << endl;
Expand Down Expand Up @@ -357,10 +375,11 @@ void CommandPrinter::AppendVerboseResponseType(
void CommandPrinter::AppendHeaderFields(
const RDMCommand *command,
const char *command_class) {
*m_output << " Message count : " << std::dec <<
static_cast<unsigned int>(command->MessageCount()) << endl;
*m_output << " Sub device : " << std::dec << command->SubDevice()
<< endl;
*m_output << " Message count : "
<< static_cast<unsigned int>(command->MessageCount()) << endl;
*m_output << " Sub device : " << command->SubDevice() << endl;
*m_output << " Message length : "
<< static_cast<unsigned int>(command->MessageLength()) << endl;
*m_output << " Command class : " << command_class << endl;
}

Expand All @@ -370,11 +389,11 @@ void CommandPrinter::AppendHeaderFields(
*/
void CommandPrinter::AppendPidString(const RDMCommand *command,
const PidDescriptor *descriptor) {
*m_output << "PID 0x" << std::hex << std::setfill('0') << std::setw(4) <<
command->ParamId();
if (descriptor)
*m_output << "PID " << ToHex(command->ParamId());
if (descriptor) {
*m_output << " (" << descriptor->Name() << ")";
*m_output << ", pdl: " << std::dec << command->ParamDataSize() << endl;
}
*m_output << ", pdl: " << command->ParamDataSize() << endl;
}


Expand Down
1 change: 1 addition & 0 deletions include/ola/rdm/CommandPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class CommandPrinter {
void AppendUIDsAndType(const class RDMCommand *command,
const char *message_type);
void AppendPortId(const class RDMRequest *request);
void AppendMessageLength(const class RDMRequest *request);
void AppendVerboseUIDs(const class RDMCommand *command);
void AppendPidString(const class RDMCommand *command,
const class PidDescriptor *pid_descriptor);
Expand Down
6 changes: 4 additions & 2 deletions tools/logic/logic-rdm-sniffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <ola/rdm/RDMHelper.h>
#include <ola/rdm/RDMResponseCodes.h>
#include <ola/rdm/UID.h>
#include <ola/StringUtils.h>

#include <iostream>
#include <fstream>
Expand All @@ -69,6 +70,7 @@ using ola::rdm::CommandPrinter;
using ola::rdm::PidStoreHelper;
using ola::rdm::RDMCommand;
using ola::rdm::UID;
using ola::strings::ToHex;


using ola::thread::Mutex;
Expand Down Expand Up @@ -292,8 +294,8 @@ void LogicReader::DisplayAlternateFrame(const uint8_t *data,
return;

unsigned int slot_count = length - 1;
cout << "SC 0x" << std::hex << std::setw(2) << static_cast<int>(data[0])
<< " " << std::dec << slot_count << ":" << std::hex;
cout << "SC " << ToHex(static_cast<int>(data[0]))
<< " " << slot_count << ":";
DisplayRawData(data + 1, slot_count);
}

Expand Down