1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Merge branch 'filnet/OP_1798_gcs_ophid_is_too_verbose' into next

This commit is contained in:
Philippe Renon 2015-03-26 21:57:18 +01:00
commit c84849fa4b
12 changed files with 68 additions and 62 deletions

View File

@ -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; return NULL;
} }

View File

@ -166,6 +166,7 @@ static void free_hid_device(hid_device *dev)
static void register_error(hid_device *device, const char *op) static void register_error(hid_device *device, const char *op)
{ {
(void)op; // avoid unused arg warning
WCHAR *ptr, *msg; WCHAR *ptr, *msg;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
@ -232,7 +233,7 @@ static HANDLE open_device(const char *path, BOOL enumerate)
OPEN_EXISTING, OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,/*FILE_ATTRIBUTE_NORMAL,*/ FILE_FLAG_OVERLAPPED,/*FILE_ATTRIBUTE_NORMAL,*/
0); 0);
DWORD error = GetLastError(); /*DWORD error =*/ GetLastError();
return handle; return handle;
} }

View File

@ -27,9 +27,9 @@
#ifndef OPHID_CONST_H #ifndef OPHID_CONST_H
#define OPHID_CONST_H #define OPHID_CONST_H
#include "QtDebug"
#define OPHID_DEBUG_ON 1 #include <QDebug>
#ifdef OPHID_DEBUG_ON #ifdef OPHID_DEBUG_ON
#define OPHID_DEBUG(fmt, args ...) qDebug("[DEBUG] "fmt,##args) #define OPHID_DEBUG(fmt, args ...) qDebug("[DEBUG] "fmt,##args)
#define OPHID_TRACE(fmt, args ...) qDebug("[TRACE] %s:%s:%d: "fmt, __FILE__, __func__, __LINE__,##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 ...) #define OPHID_WARNING(fmt, args ...)
#endif #endif
// USB // USB
#define USB_MAX_DEVICES 10 #define USB_MAX_DEVICES 10
#define USB_VID 0x20A0 #define USB_VID 0x20A0

View File

@ -30,7 +30,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <QDebug>
#include <QString> #include <QString>
#include <QMutex> #include <QMutex>
#include "../hidapi/hidapi.h" #include "../hidapi/hidapi.h"

View File

@ -1,24 +1,31 @@
TEMPLATE = lib TEMPLATE = lib
TARGET = opHID TARGET = opHID
DEFINES += OPHID_LIBRARY
//DEFINES += OPHID_DEBUG_ON
include(../../openpilotgcsplugin.pri) include(../../openpilotgcsplugin.pri)
include(ophid_dependencies.pri) include(ophid_dependencies.pri)
HEADERS += inc/ophid_global.h \ HEADERS += \
inc/ophid_plugin.h \ inc/ophid_global.h \
inc/ophid.h \ inc/ophid_plugin.h \
inc/ophid_hidapi.h \ inc/ophid.h \
inc/ophid_const.h \ inc/ophid_hidapi.h \
inc/ophid_usbmon.h \ inc/ophid_const.h \
inc/ophid_usbsignal.h \ inc/ophid_usbmon.h \
hidapi/hidapi.h inc/ophid_usbsignal.h \
SOURCES += src/ophid_plugin.cpp \ hidapi/hidapi.h
src/ophid.cpp \
src/ophid_usbsignal.cpp \ SOURCES += \
src/ophid_hidapi.cpp src/ophid_plugin.cpp \
src/ophid.cpp \
src/ophid_usbsignal.cpp \
src/ophid_hidapi.cpp
FORMS += FORMS +=
RESOURCES += RESOURCES +=
DEFINES += OPHID_LIBRARY
OTHER_FILES += opHID.pluginspec OTHER_FILES += opHID.pluginspec
INCLUDEPATH += ./inc INCLUDEPATH += ./inc
@ -26,25 +33,30 @@ INCLUDEPATH += ./inc
# Platform Specific # Platform Specific
win32 { win32 {
SOURCES += src/ophid_usbmon_win.cpp \ SOURCES += \
hidapi/windows/hid.c src/ophid_usbmon_win.cpp \
hidapi/windows/hid.c
LIBS += -lhid -lsetupapi LIBS += -lhid -lsetupapi
} }
macx { macx {
SOURCES += src/ophid_usbmon_mac.cpp \ SOURCES += \
hidapi/mac/hid.c src/ophid_usbmon_mac.cpp \
LIBS += -framework CoreFoundation \ hidapi/mac/hid.c
-framework IOKit
LIBS += -framework CoreFoundation -framework IOKit
} }
linux { linux {
SOURCES += src/ophid_usbmon_linux.cpp SOURCES += \
src/ophid_usbmon_linux.cpp
LIBS += -ludev -lrt -lpthread LIBS += -ludev -lrt -lpthread
# hidapi library # hidapi library
## rawhid ## rawhid
# SOURCES += hidapi/linux/hid.c #SOURCES += hidapi/linux/hid.c
## libusb ## libusb
SOURCES += hidapi/libusb/hid.c SOURCES += hidapi/libusb/hid.c

View File

@ -146,7 +146,7 @@ RawHIDReadThread::~RawHIDReadThread()
m_running = false; m_running = false;
// wait for the thread to terminate // wait for the thread to terminate
if (wait(10000) == false) { if (wait(10000) == false) {
qDebug() << "Cannot terminate RawHIDReadThread"; qWarning() << "Cannot terminate RawHIDReadThread";
} }
} }
@ -219,7 +219,7 @@ RawHIDWriteThread::~RawHIDWriteThread()
m_running = false; m_running = false;
// wait for the thread to terminate // wait for the thread to terminate
if (wait(10000) == false) { 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 } else if (ret < 0) { // < 0 => error
// TODO! make proper error handling, this only quick hack for unplug freeze // TODO! make proper error handling, this only quick hack for unplug freeze
m_running = false; m_running = false;
qDebug() << "Error writing to device (" << ret << ")"; qCritical() << "Error writing to device (" << ret << ")";
} else { } else {
qDebug() << "No data written to device ??"; qCritical() << "No data written to device ??";
} }
} }
} }

View File

@ -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) 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; int devices_found = false;
struct hid_device_info *current_device_ptr = NULL; struct hid_device_info *current_device_ptr = NULL;
struct hid_device_info *tmp_device_ptr = NULL; struct hid_device_info *tmp_device_ptr = NULL;

View File

@ -35,7 +35,6 @@
#include "ophid_hidapi.h" #include "ophid_hidapi.h"
#include "ophid_const.h" #include "ophid_const.h"
/** /**
* \brief Constructor * \brief Constructor
* *
@ -95,7 +94,7 @@ void RawHIDConnection::onDeviceConnected()
*/ */
void RawHIDConnection::onDeviceDisconnected() void RawHIDConnection::onDeviceDisconnected()
{ {
qDebug() << "onDeviceDisconnected()"; OPHID_DEBUG("onDeviceDisconnected()");
if (enablePolling) { if (enablePolling) {
emit availableDevChanged(this); emit availableDevChanged(this);
} }

View File

@ -26,7 +26,6 @@
*/ */
#include "ophid_usbmon.h" #include "ophid_usbmon.h"
#include <QDebug>
#include "ophid_const.h" #include "ophid_const.h"
@ -41,6 +40,8 @@
*/ */
void printPortInfo(struct udev_device *dev) void printPortInfo(struct udev_device *dev)
{ {
Q_UNUSED(dev);
OPHID_DEBUG(" Node: %s", udev_device_get_devnode(dev)); OPHID_DEBUG(" Node: %s", udev_device_get_devnode(dev));
OPHID_DEBUG(" Subsystem: %s", udev_device_get_subsystem(dev)); OPHID_DEBUG(" Subsystem: %s", udev_device_get_subsystem(dev));
OPHID_DEBUG(" Devtype: %s", udev_device_get_devtype(dev)); OPHID_DEBUG(" Devtype: %s", udev_device_get_devtype(dev));
@ -73,7 +74,7 @@ void USBMonitor::deviceEventReceived()
// this->monitorNotifier->setEnabled(0); // this->monitorNotifier->setEnabled(0);
QString action = QString(udev_device_get_action(dev)); QString action = QString(udev_device_get_action(dev));
QString devtype = QString(udev_device_get_devtype(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") { if (action == "add" && devtype == "usb_device") {
printPortInfo(dev); printPortInfo(dev);
emit deviceDiscovered(makePortInfo(dev)); emit deviceDiscovered(makePortInfo(dev));

View File

@ -32,7 +32,6 @@
#include <CoreFoundation/CFString.h> #include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFArray.h> #include <CoreFoundation/CFArray.h>
#include <QMutexLocker> #include <QMutexLocker>
#include <QDebug>
#include "ophid_const.h" #include "ophid_const.h"
// Local helper functions // Local helper functions
@ -72,7 +71,7 @@ USBMonitor::~USBMonitor()
*/ */
void USBMonitor::deviceEventReceived() 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(r);
Q_UNUSED(hid_mgr); Q_UNUSED(hid_mgr);
qDebug() << "USBMonitor: Device detached event"; OPHID_DEBUG("USBMonitor: Device detached event");
instance()->removeDevice(dev); instance()->removeDevice(dev);
} }
@ -156,7 +155,7 @@ void USBMonitor::attach_callback(void *context, IOReturn r, void *hid_mgr, IOHID
deviceInfo.dev_handle = dev; deviceInfo.dev_handle = dev;
qDebug() << "USBMonitor: Device attached event"; OPHID_DEBUG("USBMonitor: Device attached event");
// Populate the device info structure // Populate the device info structure
got_properties &= HID_GetIntProperty(dev, CFSTR(kIOHIDVendorIDKey), &deviceInfo.vendorID); 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 // Currently only enumerating objects that have the complete list of properties
if (got_properties) { if (got_properties) {
qDebug() << "USBMonitor: Adding device"; OPHID_DEBUG("USBMonitor: Adding device");
instance()->addDevice(deviceInfo); instance()->addDevice(deviceInfo);
} }
} }

View File

@ -31,7 +31,6 @@
#include <QEventLoop> #include <QEventLoop>
#include <QTimer> #include <QTimer>
#include "ophid_usbmon.h" #include "ophid_usbmon.h"
#include <QDebug>
#include "ophid_const.h" #include "ophid_const.h"
/* Gordon Schumacher's macros for TCHAR -> QString conversions and vice versa */ /* Gordon Schumacher's macros for TCHAR -> QString conversions and vice versa */
@ -122,11 +121,9 @@ QList<USBPortInfo> USBMonitor::availableDevices(int vid, int pid, int bcdDeviceM
OPHID_TRACE("IN"); OPHID_TRACE("IN");
// Print the list // 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*/) { foreach(USBPortInfo info, knowndevices /*thePortsWeWant*/) {
qDebug() << "product:" << info.product OPHID_DEBUG("product: %s bcdDevice: %d devicePath: %s", qPrintable(info.product), info.bcdDevice, qPrintable(info.devicePath));
<< " bcdDevice:" << info.bcdDevice
<< " devicePath:" << info.devicePath;
// Filter to return only the one request (if exists) // Filter to return only the one request (if exists)
if ((info.vendorID == vid || vid == -1) && if ((info.vendorID == vid || vid == -1) &&
@ -249,7 +246,7 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G
{ {
OPHID_TRACE("IN"); OPHID_TRACE("IN");
qDebug() << "[STATUS CHANGE] from device ID: " << deviceID; OPHID_DEBUG("[STATUS CHANGE] from device ID: %s", qPrintable(deviceID));
bool rc; bool rc;
SP_DEVINFO_DATA spDevInfoData; SP_DEVINFO_DATA spDevInfoData;
DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : 0 /*DIGCF_ALLCLASSES*/; 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; DWORD nSize = 0;
TCHAR buf[MAX_PATH]; TCHAR buf[MAX_PATH];
rc = SetupDiGetDeviceInstanceId(devInfo, &spDevInfoData, buf, MAX_PATH, &nSize); 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))) { if (rc && deviceID.contains(TCHARToQString(buf))) {
qDebug() << "[MATCH] " << TCHARToQString(buf); OPHID_DEBUG("[MATCH] %s", qPrintable(TCHARToQString(buf)));
USBPortInfo info; USBPortInfo info;
info.devicePath = deviceID; info.devicePath = deviceID;
if (wParam == DBT_DEVICEARRIVAL) { if (wParam == DBT_DEVICEARRIVAL) {
qDebug() << "[INSERTED]"; OPHID_DEBUG("[INSERTED]");
if (infoFromHandle(guid, info, devInfo, i) != OPHID_NO_ERROR) { if (infoFromHandle(guid, info, devInfo, i) != OPHID_NO_ERROR) {
OPHID_ERROR("Not found"); OPHID_ERROR("Not found");
break; break;
@ -290,18 +287,14 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G
break; break;
} }
knowndevices.append(info); knowndevices.append(info);
qDebug() << "[SIGNAL] Device discovered on device:" OPHID_DEBUG("[SIGNAL] Device discovered on device: %s %d", qPrintable(info.product), info.bcdDevice);
<< info.product
<< info.bcdDevice;
emit deviceDiscovered(info); emit deviceDiscovered(info);
break; break;
} else if (wParam == DBT_DEVICEREMOVECOMPLETE) { } else if (wParam == DBT_DEVICEREMOVECOMPLETE) {
for (int x = 0; x < knowndevices.count(); ++x) { for (int x = 0; x < knowndevices.count(); ++x) {
USBPortInfo temp = knowndevices.at(x); USBPortInfo temp = knowndevices.at(x);
knowndevices.removeAt(x); knowndevices.removeAt(x);
qDebug() << "[SIGNAL] Device removed on device:" OPHID_DEBUG("[SIGNAL] Device removed on device: %s %d", qPrintable(temp.product), temp.bcdDevice);
<< temp.product
<< temp.bcdDevice;
} }
emit deviceRemoved(info); emit deviceRemoved(info);
break; break;
@ -362,7 +355,7 @@ void USBMonitor::enumerateDevicesWin(const GUID & guid)
} }
SetupDiDestroyDeviceInfoList(devInfo); SetupDiDestroyDeviceInfoList(devInfo);
} }
OPHID_DEBUG("Added %d device(s).", j); OPHID_DEBUG("Added %lu device(s).", j);
OPHID_TRACE("OUT"); OPHID_TRACE("OUT");
} }
@ -429,7 +422,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO &
goto leave; goto leave;
} }
qDebug() << "Found device with valid PATH: " << qDevicePath; OPHID_DEBUG("Found device with valid PATH: %s", qPrintable(qDevicePath));
h = CreateFile(details->DevicePath, h = CreateFile(details->DevicePath,
GENERIC_READ | GENERIC_WRITE, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
@ -449,8 +442,7 @@ int USBMonitor::infoFromHandle(const GUID & guid, USBPortInfo & info, HDEVINFO &
goto leave; goto leave;
} }
qDebug() << "Problem opening handle, path: " OPHID_DEBUG("Problem opening handle, path: %s", qPrintable(QString::fromWCharArray(details->DevicePath)));
<< QString().fromWCharArray(details->DevicePath);
free(details); free(details);
ret = OPHID_ERROR_RET; ret = OPHID_ERROR_RET;

View File

@ -26,8 +26,7 @@
*/ */
#include "ophid_usbsignal.h" #include "ophid_usbsignal.h"
#include <QDebug> #include "ophid_const.h"
/** /**
* \brief trigger device discovered signal * \brief trigger device discovered signal
@ -42,7 +41,7 @@ void USBSignalFilter::m_deviceDiscovered(USBPortInfo port)
(port.productID == m_pid || m_pid == -1) && (port.productID == m_pid || m_pid == -1) &&
((port.bcdDevice >> 8) == m_boardModel || m_boardModel == -1) && ((port.bcdDevice >> 8) == m_boardModel || m_boardModel == -1) &&
((port.bcdDevice & 0x00ff) == m_runState || m_runState == -1)) { ((port.bcdDevice & 0x00ff) == m_runState || m_runState == -1)) {
qDebug() << "USBSignalFilter emit device discovered"; OPHID_DEBUG("USBSignalFilter emit device discovered");
emit deviceDiscovered(); emit deviceDiscovered();
} }
} }