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 9286b1ff6..5f1df1274 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..e53cbf199 100644 --- a/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h +++ b/ground/openpilotgcs/src/plugins/ophid/inc/ophid_const.h @@ -27,9 +27,9 @@ #ifndef OPHID_CONST_H #define OPHID_CONST_H -#include "QtDebug" -#define OPHID_DEBUG_ON 1 +#include + #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) @@ -42,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/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/ophid.pro b/ground/openpilotgcs/src/plugins/ophid/ophid.pro index f882d9198..bfa9e2c3a 100644 --- a/ground/openpilotgcs/src/plugins/ophid/ophid.pro +++ b/ground/openpilotgcs/src/plugins/ophid/ophid.pro @@ -1,24 +1,31 @@ TEMPLATE = lib TARGET = opHID +DEFINES += OPHID_LIBRARY + +//DEFINES += OPHID_DEBUG_ON + 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 +33,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 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..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 8e08dd916..6a2cefbe5 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" @@ -41,6 +40,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)); @@ -73,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("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_mac.cpp b/ground/openpilotgcs/src/plugins/ophid/src/ophid_usbmon_mac.cpp index ca907a301..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 7a6eac89a..1d94efcc3 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,11 +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 (%d) devices that are tracked:", knowndevices.length()); foreach(USBPortInfo info, knowndevices /*thePortsWeWant*/) { - qDebug() << "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) && @@ -249,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: %s", qPrintable(deviceID)); bool rc; SP_DEVINFO_DATA spDevInfoData; DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : 0 /*DIGCF_ALLCLASSES*/; @@ -263,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: %s", qPrintable(TCHARToQString(buf))); if (rc && deviceID.contains(TCHARToQString(buf))) { - qDebug() << "[MATCH] " << TCHARToQString(buf); + OPHID_DEBUG("[MATCH] %s", qPrintable(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; @@ -290,18 +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: %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); - qDebug() << "[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; @@ -362,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"); } @@ -429,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: %s", qPrintable(qDevicePath)); h = CreateFile(details->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, @@ -449,8 +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: %s", qPrintable(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..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(); } }