From d3963ea04e3482329f23a6e7f58cd0be03cb7231 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Sun, 14 Feb 2016 00:12:10 +0000 Subject: [PATCH 1/5] RDM code tidying --- common/rdm/RDMCommand.cpp | 71 ++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/common/rdm/RDMCommand.cpp b/common/rdm/RDMCommand.cpp index eb5ab0dfab..3ca4765481 100644 --- a/common/rdm/RDMCommand.cpp +++ b/common/rdm/RDMCommand.cpp @@ -111,15 +111,15 @@ RDMCommand::~RDMCommand() { string RDMCommand::ToString() const { std::ostringstream str; - str << m_source << " -> " << m_destination << ", Trans # " << - static_cast(m_transaction_number) << ", Port ID " << - static_cast(m_port_id) << ", Msg Cnt " << - static_cast(m_message_count) << ", SubDevice " << m_sub_device - << ", Cmd Class " << CommandClass() << ", Param ID " << m_param_id - << ", Data Len " << m_data_length; + str << m_source << " -> " << m_destination << ", Trans # " + << static_cast(m_transaction_number) << ", Port ID " + << static_cast(m_port_id) << ", Msg Cnt " + << static_cast(m_message_count) << ", SubDevice " << m_sub_device + << ", Cmd Class " << CommandClass() << ", Param ID " << m_param_id + << ", Data Len " << m_data_length; str << ", Data "; for (unsigned int i = 0 ; i < m_data_length; i++) { - str << std::hex << std::setw(2) << static_cast(m_data[i]) << " "; + str << ToHex(m_data[i], false) << " "; } return str.str(); } @@ -171,8 +171,9 @@ uint8_t RDMCommand::MessageLength() const { void RDMCommand::SetParamData(const uint8_t *data, unsigned int length) { m_data_length = length; if (m_data_length > 0 && data != NULL) { - if (m_data) + if (m_data) { delete[] m_data; + } m_data = new uint8_t[m_data_length]; memcpy(m_data, data, m_data_length); @@ -192,8 +193,8 @@ RDMStatusCode RDMCommand::VerifyData(const uint8_t *data, size_t length, RDMCommandHeader *command_header) { if (length < sizeof(RDMCommandHeader)) { - OLA_WARN << "RDM message is too small, needs to be at least " << - sizeof(RDMCommandHeader) << ", was " << length; + OLA_WARN << "RDM message is too small, needs to be at least " + << sizeof(RDMCommandHeader) << ", was " << length; return RDM_PACKET_TOO_SHORT; } @@ -207,35 +208,35 @@ RDMStatusCode RDMCommand::VerifyData(const uint8_t *data, sizeof(*command_header)); if (command_header->sub_start_code != SUB_START_CODE) { - OLA_WARN << "Sub start code mis match, was 0x" << std::hex << - static_cast(command_header->sub_start_code) << ", required 0x" - << static_cast(SUB_START_CODE); + OLA_WARN << "Sub start code mis match, was " + << ToHex(command_header->sub_start_code) << ", required " + << ToHex(SUB_START_CODE); return RDM_WRONG_SUB_START_CODE; } unsigned int message_length = command_header->message_length; if (length < message_length + 1) { - OLA_WARN << "RDM message is too small, needs to be " << - message_length + 1 << ", was " << length; + OLA_WARN << "RDM message is too small, needs to be " + << message_length + 1 << ", was " << length; return RDM_PACKET_LENGTH_MISMATCH; } uint16_t checksum = CalculateChecksum(data, message_length - 1); - uint16_t actual_checksum = (data[message_length - 1] << 8) + - data[message_length]; + uint16_t actual_checksum = JoinUInt8(data[message_length - 1], + data[message_length]); if (actual_checksum != checksum) { - OLA_WARN << "RDM checksum mismatch, was " << actual_checksum << - " but was supposed to be " << checksum; + OLA_WARN << "RDM checksum mismatch, was " << actual_checksum + << " but was supposed to be " << checksum; return RDM_CHECKSUM_INCORRECT; } // check param length is valid here unsigned int block_size = length - sizeof(RDMCommandHeader) - 2; if (command_header->param_data_length > block_size) { - OLA_WARN << "Param length " << - static_cast(command_header->param_data_length) << - " exceeds remaining RDM message size of " << block_size; + OLA_WARN << "Param length " + << static_cast(command_header->param_data_length) + << " exceeds remaining RDM message size of " << block_size; return RDM_PARAM_LENGTH_MISMATCH; } return RDM_COMPLETED_OK; @@ -248,8 +249,9 @@ RDMStatusCode RDMCommand::VerifyData(const uint8_t *data, uint16_t RDMCommand::CalculateChecksum(const uint8_t *data, unsigned int packet_length) { unsigned int checksum_value = START_CODE; - for (unsigned int i = 0; i < packet_length; i++) + for (unsigned int i = 0; i < packet_length; i++) { checksum_value += data[i]; + } return static_cast(checksum_value); } @@ -387,8 +389,8 @@ RDMResponse* RDMResponse::InflateFromData(const uint8_t *data, UID source_uid(command_message.source_uid); UID destination_uid(command_message.destination_uid); - uint16_t sub_device = ((command_message.sub_device[0] << 8) + - command_message.sub_device[1]); + uint16_t sub_device = JoinUInt8(command_message.sub_device[0], + command_message.sub_device[1]); RDMCommandClass command_class = ConvertCommandClass( command_message.command_class); @@ -520,7 +522,7 @@ RDMResponse* RDMResponse::CombineResponses(const RDMResponse *response1, // do some sort of checking if (combined_length > MAX_OVERFLOW_SIZE) { OLA_WARN << "ACK_OVERFLOW buffer size hit! Limit is " << MAX_OVERFLOW_SIZE - << ", request size is " << combined_length; + << ", request size is " << combined_length; return NULL; } else if (response1->SourceUID() != response2->SourceUID()) { OLA_WARN << "Source UIDs don't match"; @@ -559,8 +561,8 @@ RDMResponse* RDMResponse::CombineResponses(const RDMResponse *response1, combined_data, combined_length); } else { - OLA_WARN << "Expected a RDM request command but got " << - std::hex << response1->CommandClass(); + OLA_WARN << "Expected a RDM request command but got " + << ToHex(response1->CommandClass()); } delete[] combined_data; return response; @@ -754,16 +756,17 @@ RDMDiscoveryResponse* RDMDiscoveryResponse::InflateFromData( unsigned int length) { RDMCommandHeader command_message; RDMStatusCode code = VerifyData(data, length, &command_message); - if (code != RDM_COMPLETED_OK) + if (code != RDM_COMPLETED_OK) { return NULL; + } - uint16_t sub_device = ((command_message.sub_device[0] << 8) + - command_message.sub_device[1]); - uint16_t param_id = ((command_message.param_id[0] << 8) + - command_message.param_id[1]); + uint16_t sub_device = JoinUInt8(command_message.sub_device[0], + command_message.sub_device[1]); + uint16_t param_id = JoinUInt8(command_message.param_id[0], + command_message.param_id[1]); RDMCommandClass command_class = ConvertCommandClass( - command_message.command_class); + command_message.command_class); if (command_class == DISCOVER_COMMAND_RESPONSE) { return new RDMDiscoveryResponse( From dabca271a7711a22b66d58e68c1afc1b261f017d Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Sun, 14 Feb 2016 19:46:35 +0000 Subject: [PATCH 2/5] More Doxygen cleanup --- common/base/SysExits.cpp | 2 +- doxygen/namespaces.dox | 21 +++++++++++++++------ include/ola/base/SysExits.h | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/common/base/SysExits.cpp b/common/base/SysExits.cpp index 483bdab0e9..0563a23f50 100644 --- a/common/base/SysExits.cpp +++ b/common/base/SysExits.cpp @@ -56,7 +56,7 @@ #define EX_NOHOST 68 /**< @brief host name unknown */ #define EX_UNAVAILABLE 69 /**< @brief service unavailable */ #define EX_SOFTWARE 70 /**< @brief internal software error */ -#define EX_OSERR 71 /**< @brief system error (e.g., can't fork) */ +#define EX_OSERR 71 /**< @brief system error (e.g. can't fork) */ #define EX_OSFILE 72 /**< @brief critical OS file missing */ #define EX_CANTCREAT 73 /**< @brief can't create (user) output file */ #define EX_IOERR 74 /**< @brief input/output error */ diff --git a/doxygen/namespaces.dox b/doxygen/namespaces.dox index 9c07c9e65d..61afa4051b 100644 --- a/doxygen/namespaces.dox +++ b/doxygen/namespaces.dox @@ -14,6 +14,9 @@ * @namespace ola::e133 * @brief E1.33 (RDMNet) * + * @namespace ola::file + * @brief File helper functions. + * * @namespace ola::io * @brief Classes for general I/O and event handling. * @@ -95,9 +98,6 @@ * @namespace ola::plugin::usbdmx * @brief The plugin for hardware using libusb. * - * @namespace ola::plugin::usbdmx::jarule - * @brief Ja Rule code. - * * @namespace ola::plugin::usbpro * @brief Code for Enttec USB Pro devices and others using the same protocol. * @@ -110,6 +110,12 @@ * @namespace ola::stl * @brief STL Helper functions. * + * @namespace ola::strings + * @brief String helper and formatting functions. + * + * @namespace ola::system + * @brief System helper functions (Load Average). + * * @namespace ola::testing * @brief Code used for unit testing. * @@ -119,9 +125,12 @@ * @namespace ola::timecode * @brief Timecode * + * @namespace ola::usb + * @brief USB %device drivers. + * + * @namespace ola::utils + * @brief General numeric helper functions. + * * @namespace ola::web * @brief Classes to deal with web services. - * - * @namespace ola::usb - * @brief USB Device drivers. */ diff --git a/include/ola/base/SysExits.h b/include/ola/base/SysExits.h index 6ac61bfc45..39914efaa9 100644 --- a/include/ola/base/SysExits.h +++ b/include/ola/base/SysExits.h @@ -24,7 +24,7 @@ /** * @defgroup sysexit System Exit Values * @brief Exit codes - * @details Some platforms (android) don't provide sysexits.h. To work around + * @details Some platforms (Android) don't provide sysexits.h. To work around * this we define our own exit codes, which use the system values if provided * or otherwise our default values. */ From a471d5b6fdcd138310c5403217a08862630c4b4d Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Sun, 14 Feb 2016 20:25:55 +0000 Subject: [PATCH 3/5] Move common device info to device description, rather than ports --- plugins/usbpro/UsbProDevice.cpp | 10 ++++++---- plugins/usbpro/UsbProDevice.h | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/usbpro/UsbProDevice.cpp b/plugins/usbpro/UsbProDevice.cpp index 7905d64e72..877c37a7f9 100644 --- a/plugins/usbpro/UsbProDevice.cpp +++ b/plugins/usbpro/UsbProDevice.cpp @@ -60,8 +60,9 @@ UsbProDevice::UsbProDevice(ola::PluginAdaptor *plugin_adaptor, m_pro_widget(widget), m_serial(SerialToString(serial)) { ostringstream str; - str << "Serial #: " << m_serial << ", firmware " + str << name << ", Serial #: " << m_serial << ", firmware " << (firmware_version >> 8) << "." << (firmware_version & 0xff); + SetName(str.str()); for (unsigned int i = 0; i < widget->PortCount(); i++) { EnttecPort *enttec_port = widget->GetPort(i); @@ -71,14 +72,14 @@ UsbProDevice::UsbProDevice(ola::PluginAdaptor *plugin_adaptor, } UsbProInputPort *input_port = new UsbProInputPort( - this, enttec_port, i, plugin_adaptor, str.str()); + this, enttec_port, i, plugin_adaptor); enttec_port->SetDMXCallback( NewCallback(static_cast(input_port), &InputPort::DmxChanged)); AddPort(input_port); OutputPort *output_port = new UsbProOutputPort( - this, enttec_port, i, str.str(), + this, enttec_port, i, "", plugin_adaptor->WakeUpTime(), 5, // allow up to 5 burst frames fps_limit); // 200 frames per second seems to be the limit @@ -140,8 +141,9 @@ void UsbProDevice::Configure(RpcController *controller, */ void UsbProDevice::UpdateParams(unsigned int port_id, bool status, const usb_pro_parameters ¶ms) { - if (port_id >= m_port_params.size()) + if (port_id >= m_port_params.size()) { return; + } if (status) { PortParams &port_params = m_port_params[port_id]; diff --git a/plugins/usbpro/UsbProDevice.h b/plugins/usbpro/UsbProDevice.h index 420fce9549..184bf842de 100644 --- a/plugins/usbpro/UsbProDevice.h +++ b/plugins/usbpro/UsbProDevice.h @@ -119,7 +119,7 @@ class UsbProInputPort: public BasicInputPort { EnttecPort *port, unsigned int id, ola::PluginAdaptor *plugin_adaptor, - const std::string &description) + const std::string &description = "") : BasicInputPort(parent, id, plugin_adaptor), m_description(description), m_port(port) {} @@ -156,16 +156,18 @@ class UsbProOutputPort: public BasicOutputPort { m_wake_time(wake_time) {} bool WriteDMX(const DmxBuffer &buffer, uint8_t) { - if (m_bucket.GetToken(*m_wake_time)) + if (m_bucket.GetToken(*m_wake_time)) { return m_port->SendDMX(buffer); - else + } else { OLA_INFO << "Port rated limited, dropping frame"; + } return true; } void PostSetUniverse(Universe*, Universe *new_universe) { - if (!new_universe) + if (!new_universe) { m_port->ChangeToReceiveMode(false); + } } void SendRDMRequest(ola::rdm::RDMRequest *request, From e13cc0c32235805d0fa06e27e970594366c344e7 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Mon, 15 Feb 2016 02:44:59 +0000 Subject: [PATCH 4/5] Move common device info to device description, rather than ports for SPI devices --- plugins/spi/SPIDevice.cpp | 4 ++++ plugins/spi/SPIOutput.cpp | 18 +++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/plugins/spi/SPIDevice.cpp b/plugins/spi/SPIDevice.cpp index 12dfc9feb3..b46dad6de6 100644 --- a/plugins/spi/SPIDevice.cpp +++ b/plugins/spi/SPIDevice.cpp @@ -63,6 +63,10 @@ SPIDevice::SPIDevice(SPIPlugin *owner, m_spi_device_name(spi_device) { m_spi_device_name = ola::file::FilenameFromPathOrPath(m_spi_device_name); + ostringstream str; + str << SPI_DEVICE_NAME << " " << m_spi_device_name; + SetName(str.str()); + SetDefaults(); unsigned int port_count = 0; diff --git a/plugins/spi/SPIOutput.cpp b/plugins/spi/SPIOutput.cpp index 203289d6b2..a662c03650 100644 --- a/plugins/spi/SPIOutput.cpp +++ b/plugins/spi/SPIOutput.cpp @@ -251,8 +251,7 @@ bool SPIOutput::SetStartAddress(uint16_t address) { string SPIOutput::Description() const { std::ostringstream str; - str << m_spi_device_name << ", output " - << static_cast(m_output_number) << ", " + str << "Output " << static_cast(m_output_number) << ", " << m_personality_manager->ActivePersonalityDescription() << ", " << m_personality_manager->ActivePersonalityFootprint() << " slots @ " << m_start_address << ". (" << m_uid << ")"; @@ -263,8 +262,9 @@ string SPIOutput::Description() const { * Send DMX data over SPI. */ bool SPIOutput::WriteDMX(const DmxBuffer &buffer) { - if (m_identify_mode) + if (m_identify_mode) { return true; + } return InternalWriteDMX(buffer); } @@ -327,8 +327,9 @@ void SPIOutput::IndividualWS2801Control(const DmxBuffer &buffer) { // for part of it const unsigned int output_length = m_pixel_count * LPD8806_SLOTS_PER_PIXEL; uint8_t *output = m_backend->Checkout(m_output_number, output_length); - if (!output) + if (!output) { return; + } unsigned int new_length = output_length; buffer.GetRange(m_start_address - 1, output, &new_length); @@ -347,8 +348,9 @@ void SPIOutput::CombinedWS2801Control(const DmxBuffer &buffer) { const unsigned int length = m_pixel_count * WS2801_SLOTS_PER_PIXEL; uint8_t *output = m_backend->Checkout(m_output_number, length); - if (!output) + if (!output) { return; + } for (unsigned int i = 0; i < m_pixel_count; i++) { memcpy(output + (i * WS2801_SLOTS_PER_PIXEL), pixel_data, @@ -435,8 +437,9 @@ void SPIOutput::IndividualP9813Control(const DmxBuffer &buffer) { uint8_t *output = m_backend->Checkout(m_output_number, output_length, latch_bytes); - if (!output) + if (!output) { return; + } for (unsigned int i = 0; i < m_pixel_count; i++) { // Convert RGB to P9813 Pixel @@ -479,8 +482,9 @@ void SPIOutput::CombinedP9813Control(const DmxBuffer &buffer) { const unsigned int length = m_pixel_count * P9813_SPI_BYTES_PER_PIXEL; uint8_t *output = m_backend->Checkout(m_output_number, length, latch_bytes); - if (!output) + if (!output) { return; + } for (unsigned int i = 0; i < m_pixel_count; i++) { memcpy(&output[(i + 1) * P9813_SPI_BYTES_PER_PIXEL], pixel_data, From 587ec4ec6af8f1eeebfaf156b3f608cd66368267 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Mon, 15 Feb 2016 12:51:48 +0000 Subject: [PATCH 5/5] Fix the broken test --- plugins/spi/SPIOutputTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/spi/SPIOutputTest.cpp b/plugins/spi/SPIOutputTest.cpp index 061b4345dd..ea93d8bf23 100644 --- a/plugins/spi/SPIOutputTest.cpp +++ b/plugins/spi/SPIOutputTest.cpp @@ -88,13 +88,13 @@ void SPIOutputTest::testDescription() { SPIOutput output2(m_uid, &backend, options); OLA_ASSERT_EQ( - string("test, output 0, WS2801 Individual Control, 75 slots @ 1." + string("Output 0, WS2801 Individual Control, 75 slots @ 1." " (707a:00000000)"), output1.Description()); OLA_ASSERT_EQ(static_cast(1), output1.GetStartAddress()); OLA_ASSERT_EQ(static_cast(1), output1.GetPersonality()); OLA_ASSERT_EQ( - string("test, output 1, WS2801 Individual Control, 96 slots @ 1." + string("Output 1, WS2801 Individual Control, 96 slots @ 1." " (707a:00000000)"), output2.Description()); @@ -102,7 +102,7 @@ void SPIOutputTest::testDescription() { output1.SetStartAddress(10); output1.SetPersonality(3); OLA_ASSERT_EQ( - string("test, output 0, LPD8806 Individual Control, 75 slots @ 10." + string("Output 0, LPD8806 Individual Control, 75 slots @ 10." " (707a:00000000)"), output1.Description()); OLA_ASSERT_EQ(static_cast(10), output1.GetStartAddress());