From 96310183208279851543fa878678ca055605772c Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Thu, 19 Mar 2015 09:08:24 +0100 Subject: [PATCH 1/6] OP-1798 reduced verbosity of ophid gcs plugin --- .../src/plugins/ophid/hidapi/windows/hid.c | 3 ++- .../src/plugins/ophid/inc/ophid_const.h | 3 ++- .../src/plugins/ophid/src/ophid.cpp | 8 +++--- .../src/plugins/ophid/src/ophid_hidapi.cpp | 4 +++ .../src/plugins/ophid/src/ophid_plugin.cpp | 2 +- .../plugins/ophid/src/ophid_usbmon_linux.cpp | 2 +- .../plugins/ophid/src/ophid_usbmon_mac.cpp | 8 +++--- .../plugins/ophid/src/ophid_usbmon_win.cpp | 27 +++++++------------ .../src/plugins/ophid/src/ophid_usbsignal.cpp | 2 +- 9 files changed, 29 insertions(+), 30 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/ophid/hidapi/windows/hid.c b/ground/openpilotgcs/src/plugins/ophid/hidapi/windows/hid.c index 9286b1ff6..04102a2e7 100644 --- a/ground/openpilotgcs/src/plugins/ophid/hidapi/windows/hid.c +++ b/ground/openpilotgcs/src/plugins/ophid/hidapi/windows/hid.c @@ -166,6 +166,7 @@ static void free_hid_device(hid_device *dev) static void register_error(hid_device *device, const char *op) { + (void)op; // avoid unused arg warning WCHAR *ptr, *msg; FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | @@ -232,7 +233,7 @@ static HANDLE open_device(const char *path, BOOL enumerate) OPEN_EXISTING, FILE_FLAG_OVERLAPPED,/*FILE_ATTRIBUTE_NORMAL,*/ 0); - DWORD error = GetLastError(); + /*DWORD error =*/ GetLastError(); return handle; } diff --git a/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h b/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h index bd8a429a3..5cb9fa8af 100644 --- a/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h +++ b/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h @@ -29,7 +29,8 @@ #define OPHID_CONST_H #include "QtDebug" -#define OPHID_DEBUG_ON 1 +// #define OPHID_DEBUG_ON 1 + #ifdef OPHID_DEBUG_ON #define OPHID_DEBUG(fmt, args ...) qDebug("[DEBUG] "fmt,##args) #define OPHID_TRACE(fmt, args ...) qDebug("[TRACE] %s:%s:%d: "fmt, __FILE__, __func__, __LINE__,##args) diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid.cpp index 447fa2f98..4b176d8ee 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid.cpp @@ -146,7 +146,7 @@ RawHIDReadThread::~RawHIDReadThread() m_running = false; // wait for the thread to terminate if (wait(10000) == false) { - qDebug() << "Cannot terminate RawHIDReadThread"; + qWarning() << "Cannot terminate RawHIDReadThread"; } } @@ -219,7 +219,7 @@ RawHIDWriteThread::~RawHIDWriteThread() m_running = false; // wait for the thread to terminate if (wait(10000) == false) { - qDebug() << "Cannot terminate RawHIDReadThread"; + qWarning() << "Cannot terminate RawHIDReadThread"; } } @@ -264,9 +264,9 @@ void RawHIDWriteThread::run() } else if (ret < 0) { // < 0 => error // TODO! make proper error handling, this only quick hack for unplug freeze m_running = false; - qDebug() << "Error writing to device (" << ret << ")"; + qCritical() << "Error writing to device (" << ret << ")"; } else { - qDebug() << "No data written to device ??"; + qCritical() << "No data written to device ??"; } } } diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_hidapi.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_hidapi.cpp index 658c1db38..7a8f197ea 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_hidapi.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_hidapi.cpp @@ -129,6 +129,10 @@ int opHID_hidapi::enumerate(struct hid_device_info * *current_device_pptr, int * */ int opHID_hidapi::open(int max, int vid, int pid, int usage_page, int usage) { + Q_UNUSED(max); + Q_UNUSED(usage_page); + Q_UNUSED(usage); + int devices_found = false; struct hid_device_info *current_device_ptr = NULL; struct hid_device_info *tmp_device_ptr = NULL; diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_plugin.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_plugin.cpp index 248f08122..13d72fc09 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_plugin.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_plugin.cpp @@ -95,7 +95,7 @@ void RawHIDConnection::onDeviceConnected() */ void RawHIDConnection::onDeviceDisconnected() { - qDebug() << "onDeviceDisconnected()"; + // qDebug() << "onDeviceDisconnected()"; if (enablePolling) { emit availableDevChanged(this); } diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp index 8e08dd916..74e93d654 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp @@ -73,7 +73,7 @@ void USBMonitor::deviceEventReceived() // this->monitorNotifier->setEnabled(0); QString action = QString(udev_device_get_action(dev)); QString devtype = QString(udev_device_get_devtype(dev)); - qDebug() << "[DEBUG] Action: " << action << " device: " << devtype; + // qDebug() << "[DEBUG] Action: " << action << " device: " << devtype; if (action == "add" && devtype == "usb_device") { printPortInfo(dev); emit deviceDiscovered(makePortInfo(dev)); diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_mac.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_mac.cpp index ca907a301..89e74cd4c 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_mac.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_mac.cpp @@ -72,7 +72,7 @@ USBMonitor::~USBMonitor() */ void USBMonitor::deviceEventReceived() { - qDebug() << "Device event"; + // qDebug() << "Device event"; } /** @@ -119,7 +119,7 @@ void USBMonitor::detach_callback(void *context, IOReturn r, void *hid_mgr, IOHID Q_UNUSED(r); Q_UNUSED(hid_mgr); - qDebug() << "USBMonitor: Device detached event"; + // qDebug() << "USBMonitor: Device detached event"; instance()->removeDevice(dev); } @@ -156,7 +156,7 @@ void USBMonitor::attach_callback(void *context, IOReturn r, void *hid_mgr, IOHID deviceInfo.dev_handle = dev; - qDebug() << "USBMonitor: Device attached event"; + // qDebug() << "USBMonitor: Device attached event"; // Populate the device info structure got_properties &= HID_GetIntProperty(dev, CFSTR(kIOHIDVendorIDKey), &deviceInfo.vendorID); @@ -171,7 +171,7 @@ void USBMonitor::attach_callback(void *context, IOReturn r, void *hid_mgr, IOHID // Currently only enumerating objects that have the complete list of properties if (got_properties) { - qDebug() << "USBMonitor: Adding device"; + // qDebug() << "USBMonitor: Adding device"; instance()->addDevice(deviceInfo); } } diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp index 7a6eac89a..51f5c9065 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp @@ -122,11 +122,9 @@ QList USBMonitor::availableDevices(int vid, int pid, int bcdDeviceM OPHID_TRACE("IN"); // Print the list - qDebug() << "List off (" << knowndevices.length() << ") devices that are tracked:"; + // qDebug() << "List off (" << knowndevices.length() << ") devices that are tracked:"; foreach(USBPortInfo info, knowndevices /*thePortsWeWant*/) { - qDebug() << "product:" << info.product - << " bcdDevice:" << info.bcdDevice - << " devicePath:" << info.devicePath; + // qDebug() << "product:" << info.product << " bcdDevice:" << info.bcdDevice << " devicePath:" << info.devicePath; // Filter to return only the one request (if exists) if ((info.vendorID == vid || vid == -1) && @@ -249,7 +247,7 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G { OPHID_TRACE("IN"); - qDebug() << "[STATUS CHANGE] from device ID: " << deviceID; + // qDebug() << "[STATUS CHANGE] from device ID: " << deviceID; bool rc; SP_DEVINFO_DATA spDevInfoData; DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : 0 /*DIGCF_ALLCLASSES*/; @@ -263,13 +261,13 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G DWORD nSize = 0; TCHAR buf[MAX_PATH]; rc = SetupDiGetDeviceInstanceId(devInfo, &spDevInfoData, buf, MAX_PATH, &nSize); - qDebug() << "Found:" << TCHARToQString(buf); + // qDebug() << "Found:" << TCHARToQString(buf); if (rc && deviceID.contains(TCHARToQString(buf))) { - qDebug() << "[MATCH] " << TCHARToQString(buf); + // qDebug() << "[MATCH] " << TCHARToQString(buf); USBPortInfo info; info.devicePath = deviceID; if (wParam == DBT_DEVICEARRIVAL) { - qDebug() << "[INSERTED]"; + // qDebug() << "[INSERTED]"; if (infoFromHandle(guid, info, devInfo, i) != OPHID_NO_ERROR) { OPHID_ERROR("Not found"); break; @@ -290,18 +288,14 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G break; } knowndevices.append(info); - qDebug() << "[SIGNAL] Device discovered on device:" - << info.product - << info.bcdDevice; + // qDebug() << "[SIGNAL] Device discovered on device:" << info.product << info.bcdDevice; emit deviceDiscovered(info); break; } else if (wParam == DBT_DEVICEREMOVECOMPLETE) { for (int x = 0; x < knowndevices.count(); ++x) { USBPortInfo temp = knowndevices.at(x); knowndevices.removeAt(x); - qDebug() << "[SIGNAL] Device removed on device:" - << temp.product - << temp.bcdDevice; + // qDebug() << "[SIGNAL] Device removed on device:" << temp.product << temp.bcdDevice; } emit deviceRemoved(info); break; @@ -429,7 +423,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO & goto leave; } - qDebug() << "Found device with valid PATH: " << qDevicePath; + // qDebug() << "Found device with valid PATH: " << qDevicePath; h = CreateFile(details->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, @@ -449,8 +443,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO & goto leave; } - qDebug() << "Problem opening handle, path: " - << QString().fromWCharArray(details->DevicePath); + // qDebug() << "Problem opening handle, path: " << QString().fromWCharArray(details->DevicePath); free(details); ret = OPHID_ERROR_RET; diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbsignal.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbsignal.cpp index 6e1335f16..b897a0948 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbsignal.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbsignal.cpp @@ -42,7 +42,7 @@ void USBSignalFilter::m_deviceDiscovered(USBPortInfo port) (port.productID == m_pid || m_pid == -1) && ((port.bcdDevice >> 8) == m_boardModel || m_boardModel == -1) && ((port.bcdDevice & 0x00ff) == m_runState || m_runState == -1)) { - qDebug() << "USBSignalFilter emit device discovered"; + // qDebug() << "USBSignalFilter emit device discovered"; emit deviceDiscovered(); } } From b11bec1b5bb9ad9c46dec8c212fae9eabdd4dd88 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Thu, 19 Mar 2015 22:25:32 +0100 Subject: [PATCH 2/6] OP-1798 fixed unused args warnings in ophid --- ground/openpilotgcs/src/plugins/ophid/hidapi/libusb/hid.c | 3 ++- ground/openpilotgcs/src/plugins/ophid/hidapi/windows/hid.c | 2 +- .../openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/ophid/hidapi/libusb/hid.c b/ground/openpilotgcs/src/plugins/ophid/hidapi/libusb/hid.c index b066dde5f..b812fd670 100644 --- a/ground/openpilotgcs/src/plugins/ophid/hidapi/libusb/hid.c +++ b/ground/openpilotgcs/src/plugins/ophid/hidapi/libusb/hid.c @@ -1296,8 +1296,9 @@ int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index } -HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) +HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) { + (void)dev; // avoid unused arg warning return NULL; } diff --git a/ground/openpilotgcs/src/plugins/ophid/hidapi/windows/hid.c b/ground/openpilotgcs/src/plugins/ophid/hidapi/windows/hid.c index 04102a2e7..5f1df1274 100644 --- a/ground/openpilotgcs/src/plugins/ophid/hidapi/windows/hid.c +++ b/ground/openpilotgcs/src/plugins/ophid/hidapi/windows/hid.c @@ -166,7 +166,7 @@ static void free_hid_device(hid_device *dev) static void register_error(hid_device *device, const char *op) { - (void)op; // avoid unused arg warning + (void)op; // avoid unused arg warning WCHAR *ptr, *msg; FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp index 74e93d654..ec226efc2 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp @@ -41,6 +41,8 @@ */ void printPortInfo(struct udev_device *dev) { + Q_UNUSED(dev); + OPHID_DEBUG(" Node: %s", udev_device_get_devnode(dev)); OPHID_DEBUG(" Subsystem: %s", udev_device_get_subsystem(dev)); OPHID_DEBUG(" Devtype: %s", udev_device_get_devtype(dev)); From a1a225f592380bf7a58730e9c016c5cf062eff07 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 22 Mar 2015 15:43:17 +0100 Subject: [PATCH 3/6] OP-1798 replaced qDebug() with OPHID_DEBUG() --- .../src/plugins/ophid/inc/ophid_const.h | 3 ++- .../src/plugins/ophid/inc/ophid_hidapi.h | 1 - .../src/plugins/ophid/src/ophid_plugin.cpp | 3 +-- .../plugins/ophid/src/ophid_usbmon_linux.cpp | 3 +-- .../plugins/ophid/src/ophid_usbmon_mac.cpp | 9 ++++---- .../plugins/ophid/src/ophid_usbmon_win.cpp | 21 +++++++++---------- .../src/plugins/ophid/src/ophid_usbsignal.cpp | 5 ++--- 7 files changed, 20 insertions(+), 25 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h b/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h index 5cb9fa8af..be29bd97a 100644 --- a/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h +++ b/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h @@ -27,7 +27,8 @@ #ifndef OPHID_CONST_H #define OPHID_CONST_H -#include "QtDebug" + +#include // #define OPHID_DEBUG_ON 1 diff --git a/ground/openpilotgcs/src/plugins/ophid/inc/ophid_hidapi.h b/ground/openpilotgcs/src/plugins/ophid/inc/ophid_hidapi.h index 7828773cd..0b026423d 100644 --- a/ground/openpilotgcs/src/plugins/ophid/inc/ophid_hidapi.h +++ b/ground/openpilotgcs/src/plugins/ophid/inc/ophid_hidapi.h @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include "../hidapi/hidapi.h" diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_plugin.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_plugin.cpp index 13d72fc09..adbc4b703 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_plugin.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_plugin.cpp @@ -35,7 +35,6 @@ #include "ophid_hidapi.h" #include "ophid_const.h" - /** * \brief Constructor * @@ -95,7 +94,7 @@ void RawHIDConnection::onDeviceConnected() */ void RawHIDConnection::onDeviceDisconnected() { - // qDebug() << "onDeviceDisconnected()"; + OPHID_DEBUG("onDeviceDisconnected()"); if (enablePolling) { emit availableDevChanged(this); } diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp index ec226efc2..fc33cdb80 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp @@ -26,7 +26,6 @@ */ #include "ophid_usbmon.h" -#include #include "ophid_const.h" @@ -75,7 +74,7 @@ void USBMonitor::deviceEventReceived() // this->monitorNotifier->setEnabled(0); QString action = QString(udev_device_get_action(dev)); QString devtype = QString(udev_device_get_devtype(dev)); - // qDebug() << "[DEBUG] Action: " << action << " device: " << devtype; + OPHID_DEBUG("[DEBUG] Action: " << action << " device: " << devtype); if (action == "add" && devtype == "usb_device") { printPortInfo(dev); emit deviceDiscovered(makePortInfo(dev)); diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_mac.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_mac.cpp index 89e74cd4c..9fa82f010 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_mac.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_mac.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include "ophid_const.h" // Local helper functions @@ -72,7 +71,7 @@ USBMonitor::~USBMonitor() */ void USBMonitor::deviceEventReceived() { - // qDebug() << "Device event"; + OPHID_DEBUG("Device event"); } /** @@ -119,7 +118,7 @@ void USBMonitor::detach_callback(void *context, IOReturn r, void *hid_mgr, IOHID Q_UNUSED(r); Q_UNUSED(hid_mgr); - // qDebug() << "USBMonitor: Device detached event"; + OPHID_DEBUG("USBMonitor: Device detached event"); instance()->removeDevice(dev); } @@ -156,7 +155,7 @@ void USBMonitor::attach_callback(void *context, IOReturn r, void *hid_mgr, IOHID deviceInfo.dev_handle = dev; - // qDebug() << "USBMonitor: Device attached event"; + OPHID_DEBUG("USBMonitor: Device attached event"); // Populate the device info structure got_properties &= HID_GetIntProperty(dev, CFSTR(kIOHIDVendorIDKey), &deviceInfo.vendorID); @@ -171,7 +170,7 @@ void USBMonitor::attach_callback(void *context, IOReturn r, void *hid_mgr, IOHID // Currently only enumerating objects that have the complete list of properties if (got_properties) { - // qDebug() << "USBMonitor: Adding device"; + OPHID_DEBUG("USBMonitor: Adding device"); instance()->addDevice(deviceInfo); } } diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp index 51f5c9065..314bf24fc 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp @@ -31,7 +31,6 @@ #include #include #include "ophid_usbmon.h" -#include #include "ophid_const.h" /* Gordon Schumacher's macros for TCHAR -> QString conversions and vice versa */ @@ -122,9 +121,9 @@ QList USBMonitor::availableDevices(int vid, int pid, int bcdDeviceM OPHID_TRACE("IN"); // Print the list - // qDebug() << "List off (" << knowndevices.length() << ") devices that are tracked:"; + OPHID_DEBUG("List off (" << knowndevices.length() << ") devices that are tracked:"); foreach(USBPortInfo info, knowndevices /*thePortsWeWant*/) { - // qDebug() << "product:" << info.product << " bcdDevice:" << info.bcdDevice << " devicePath:" << info.devicePath; + OPHID_DEBUG("product:" << info.product << " bcdDevice:" << info.bcdDevice << " devicePath:" << info.devicePath); // Filter to return only the one request (if exists) if ((info.vendorID == vid || vid == -1) && @@ -247,7 +246,7 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G { OPHID_TRACE("IN"); - // qDebug() << "[STATUS CHANGE] from device ID: " << deviceID; + OPHID_DEBUG("[STATUS CHANGE] from device ID: " << deviceID); bool rc; SP_DEVINFO_DATA spDevInfoData; DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : 0 /*DIGCF_ALLCLASSES*/; @@ -261,13 +260,13 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G DWORD nSize = 0; TCHAR buf[MAX_PATH]; rc = SetupDiGetDeviceInstanceId(devInfo, &spDevInfoData, buf, MAX_PATH, &nSize); - // qDebug() << "Found:" << TCHARToQString(buf); + OPHID_DEBUG("Found:" << TCHARToQString(buf)); if (rc && deviceID.contains(TCHARToQString(buf))) { - // qDebug() << "[MATCH] " << TCHARToQString(buf); + OPHID_DEBUG("[MATCH] " << TCHARToQString(buf)); USBPortInfo info; info.devicePath = deviceID; if (wParam == DBT_DEVICEARRIVAL) { - // qDebug() << "[INSERTED]"; + OPHID_DEBUG("[INSERTED]"); if (infoFromHandle(guid, info, devInfo, i) != OPHID_NO_ERROR) { OPHID_ERROR("Not found"); break; @@ -288,14 +287,14 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G break; } knowndevices.append(info); - // qDebug() << "[SIGNAL] Device discovered on device:" << info.product << info.bcdDevice; + OPHID_DEBUG("[SIGNAL] Device discovered on device:" << info.product << info.bcdDevice); emit deviceDiscovered(info); break; } else if (wParam == DBT_DEVICEREMOVECOMPLETE) { for (int x = 0; x < knowndevices.count(); ++x) { USBPortInfo temp = knowndevices.at(x); knowndevices.removeAt(x); - // qDebug() << "[SIGNAL] Device removed on device:" << temp.product << temp.bcdDevice; + OPHID_DEBUG("[SIGNAL] Device removed on device:" << temp.product << temp.bcdDevice); } emit deviceRemoved(info); break; @@ -423,7 +422,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO & goto leave; } - // qDebug() << "Found device with valid PATH: " << qDevicePath; + OPHID_DEBUG("Found device with valid PATH: " << qDevicePath); h = CreateFile(details->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, @@ -443,7 +442,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO & goto leave; } - // qDebug() << "Problem opening handle, path: " << QString().fromWCharArray(details->DevicePath); + OPHID_DEBUG("Problem opening handle, path: " << QString().fromWCharArray(details->DevicePath)); free(details); ret = OPHID_ERROR_RET; diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbsignal.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbsignal.cpp index b897a0948..b7e5f98eb 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbsignal.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbsignal.cpp @@ -26,8 +26,7 @@ */ #include "ophid_usbsignal.h" -#include - +#include "ophid_const.h" /** * \brief trigger device discovered signal @@ -42,7 +41,7 @@ void USBSignalFilter::m_deviceDiscovered(USBPortInfo port) (port.productID == m_pid || m_pid == -1) && ((port.bcdDevice >> 8) == m_boardModel || m_boardModel == -1) && ((port.bcdDevice & 0x00ff) == m_runState || m_runState == -1)) { - // qDebug() << "USBSignalFilter emit device discovered"; + OPHID_DEBUG("USBSignalFilter emit device discovered"); emit deviceDiscovered(); } } From f8b3e6d3b19e0da1d9ea7ce377637d11ad06038a Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 22 Mar 2015 15:44:29 +0100 Subject: [PATCH 4/6] OP-1798 cleaned up ophid.pro --- .../openpilotgcs/src/plugins/ophid/ophid.pro | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/ophid/ophid.pro b/ground/openpilotgcs/src/plugins/ophid/ophid.pro index f882d9198..8686d1bab 100644 --- a/ground/openpilotgcs/src/plugins/ophid/ophid.pro +++ b/ground/openpilotgcs/src/plugins/ophid/ophid.pro @@ -1,24 +1,29 @@ TEMPLATE = lib TARGET = opHID +DEFINES += OPHID_LIBRARY + include(../../openpilotgcsplugin.pri) include(ophid_dependencies.pri) -HEADERS += inc/ophid_global.h \ - inc/ophid_plugin.h \ - inc/ophid.h \ - inc/ophid_hidapi.h \ - inc/ophid_const.h \ - inc/ophid_usbmon.h \ - inc/ophid_usbsignal.h \ - hidapi/hidapi.h -SOURCES += src/ophid_plugin.cpp \ - src/ophid.cpp \ - src/ophid_usbsignal.cpp \ - src/ophid_hidapi.cpp +HEADERS += \ + inc/ophid_global.h \ + inc/ophid_plugin.h \ + inc/ophid.h \ + inc/ophid_hidapi.h \ + inc/ophid_const.h \ + inc/ophid_usbmon.h \ + inc/ophid_usbsignal.h \ + hidapi/hidapi.h + +SOURCES += \ + src/ophid_plugin.cpp \ + src/ophid.cpp \ + src/ophid_usbsignal.cpp \ + src/ophid_hidapi.cpp + FORMS += RESOURCES += -DEFINES += OPHID_LIBRARY OTHER_FILES += opHID.pluginspec INCLUDEPATH += ./inc @@ -26,25 +31,30 @@ INCLUDEPATH += ./inc # Platform Specific win32 { - SOURCES += src/ophid_usbmon_win.cpp \ - hidapi/windows/hid.c + SOURCES += \ + src/ophid_usbmon_win.cpp \ + hidapi/windows/hid.c + LIBS += -lhid -lsetupapi } macx { - SOURCES += src/ophid_usbmon_mac.cpp \ - hidapi/mac/hid.c - LIBS += -framework CoreFoundation \ - -framework IOKit + SOURCES += \ + src/ophid_usbmon_mac.cpp \ + hidapi/mac/hid.c + + LIBS += -framework CoreFoundation -framework IOKit } linux { - SOURCES += src/ophid_usbmon_linux.cpp + SOURCES += \ + src/ophid_usbmon_linux.cpp + LIBS += -ludev -lrt -lpthread # hidapi library ## rawhid - # SOURCES += hidapi/linux/hid.c + #SOURCES += hidapi/linux/hid.c ## libusb SOURCES += hidapi/libusb/hid.c From 0236074de4cef8a9afae053592250ca5f8cd6559 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 22 Mar 2015 15:47:03 +0100 Subject: [PATCH 5/6] OP-1798 moved OPHID_DEBUG_ON define to ophid.pro --- ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h | 3 --- ground/openpilotgcs/src/plugins/ophid/ophid.pro | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h b/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h index be29bd97a..e53cbf199 100644 --- a/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h +++ b/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h @@ -30,8 +30,6 @@ #include -// #define OPHID_DEBUG_ON 1 - #ifdef OPHID_DEBUG_ON #define OPHID_DEBUG(fmt, args ...) qDebug("[DEBUG] "fmt,##args) #define OPHID_TRACE(fmt, args ...) qDebug("[TRACE] %s:%s:%d: "fmt, __FILE__, __func__, __LINE__,##args) @@ -44,7 +42,6 @@ #define OPHID_WARNING(fmt, args ...) #endif - // USB #define USB_MAX_DEVICES 10 #define USB_VID 0x20A0 diff --git a/ground/openpilotgcs/src/plugins/ophid/ophid.pro b/ground/openpilotgcs/src/plugins/ophid/ophid.pro index 8686d1bab..bfa9e2c3a 100644 --- a/ground/openpilotgcs/src/plugins/ophid/ophid.pro +++ b/ground/openpilotgcs/src/plugins/ophid/ophid.pro @@ -3,6 +3,8 @@ TARGET = opHID DEFINES += OPHID_LIBRARY +//DEFINES += OPHID_DEBUG_ON + include(../../openpilotgcsplugin.pri) include(ophid_dependencies.pri) From 0cab4b0016f07a23c9a79c4d5af497937a90dcbb Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 22 Mar 2015 21:04:50 +0100 Subject: [PATCH 6/6] OP-1798 fixed recently converted OPHID_DEBUG taking argument --- .../plugins/ophid/src/ophid_usbmon_linux.cpp | 2 +- .../plugins/ophid/src/ophid_usbmon_win.cpp | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp index fc33cdb80..6a2cefbe5 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_linux.cpp @@ -74,7 +74,7 @@ void USBMonitor::deviceEventReceived() // this->monitorNotifier->setEnabled(0); QString action = QString(udev_device_get_action(dev)); QString devtype = QString(udev_device_get_devtype(dev)); - OPHID_DEBUG("[DEBUG] Action: " << action << " device: " << devtype); + OPHID_DEBUG("Action: %s device: %s", qPrintable(action), qPrintable(devtype)); if (action == "add" && devtype == "usb_device") { printPortInfo(dev); emit deviceDiscovered(makePortInfo(dev)); diff --git a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp index 314bf24fc..1d94efcc3 100644 --- a/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp +++ b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_win.cpp @@ -121,9 +121,9 @@ QList USBMonitor::availableDevices(int vid, int pid, int bcdDeviceM OPHID_TRACE("IN"); // Print the list - OPHID_DEBUG("List off (" << knowndevices.length() << ") devices that are tracked:"); + OPHID_DEBUG("List off (%d) devices that are tracked:", knowndevices.length()); foreach(USBPortInfo info, knowndevices /*thePortsWeWant*/) { - OPHID_DEBUG("product:" << info.product << " bcdDevice:" << info.bcdDevice << " devicePath:" << info.devicePath); + OPHID_DEBUG("product: %s bcdDevice: %d devicePath: %s", qPrintable(info.product), info.bcdDevice, qPrintable(info.devicePath)); // Filter to return only the one request (if exists) if ((info.vendorID == vid || vid == -1) && @@ -246,7 +246,7 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G { OPHID_TRACE("IN"); - OPHID_DEBUG("[STATUS CHANGE] from device ID: " << deviceID); + OPHID_DEBUG("[STATUS CHANGE] from device ID: %s", qPrintable(deviceID)); bool rc; SP_DEVINFO_DATA spDevInfoData; DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : 0 /*DIGCF_ALLCLASSES*/; @@ -260,9 +260,9 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G DWORD nSize = 0; TCHAR buf[MAX_PATH]; rc = SetupDiGetDeviceInstanceId(devInfo, &spDevInfoData, buf, MAX_PATH, &nSize); - OPHID_DEBUG("Found:" << TCHARToQString(buf)); + OPHID_DEBUG("Found: %s", qPrintable(TCHARToQString(buf))); if (rc && deviceID.contains(TCHARToQString(buf))) { - OPHID_DEBUG("[MATCH] " << TCHARToQString(buf)); + OPHID_DEBUG("[MATCH] %s", qPrintable(TCHARToQString(buf))); USBPortInfo info; info.devicePath = deviceID; if (wParam == DBT_DEVICEARRIVAL) { @@ -287,14 +287,14 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G break; } knowndevices.append(info); - OPHID_DEBUG("[SIGNAL] Device discovered on device:" << info.product << info.bcdDevice); + OPHID_DEBUG("[SIGNAL] Device discovered on device: %s %d", qPrintable(info.product), info.bcdDevice); emit deviceDiscovered(info); break; } else if (wParam == DBT_DEVICEREMOVECOMPLETE) { for (int x = 0; x < knowndevices.count(); ++x) { USBPortInfo temp = knowndevices.at(x); knowndevices.removeAt(x); - OPHID_DEBUG("[SIGNAL] Device removed on device:" << temp.product << temp.bcdDevice); + OPHID_DEBUG("[SIGNAL] Device removed on device: %s %d", qPrintable(temp.product), temp.bcdDevice); } emit deviceRemoved(info); break; @@ -355,7 +355,7 @@ void USBMonitor::enumerateDevicesWin(const GUID & guid) } SetupDiDestroyDeviceInfoList(devInfo); } - OPHID_DEBUG("Added %d device(s).", j); + OPHID_DEBUG("Added %lu device(s).", j); OPHID_TRACE("OUT"); } @@ -422,7 +422,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO & goto leave; } - OPHID_DEBUG("Found device with valid PATH: " << qDevicePath); + OPHID_DEBUG("Found device with valid PATH: %s", qPrintable(qDevicePath)); h = CreateFile(details->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, @@ -442,7 +442,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO & goto leave; } - OPHID_DEBUG("Problem opening handle, path: " << QString().fromWCharArray(details->DevicePath)); + OPHID_DEBUG("Problem opening handle, path: %s", qPrintable(QString::fromWCharArray(details->DevicePath))); free(details); ret = OPHID_ERROR_RET;