From f508189682b6fba62e08feeb1596f682bad5fff9 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 24 Feb 2010 18:42:24 +0000 Subject: Added KDE3 version of PikLab git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/common/port/Makefile.am | 7 + src/common/port/parallel.cpp | 247 ++++++++++++++++++++ src/common/port/parallel.h | 70 ++++++ src/common/port/port.cpp | 98 ++++++++ src/common/port/port.h | 56 +++++ src/common/port/port.pro | 10 + src/common/port/port_base.cpp | 127 ++++++++++ src/common/port/port_base.h | 59 +++++ src/common/port/serial.cpp | 523 ++++++++++++++++++++++++++++++++++++++++++ src/common/port/serial.h | 113 +++++++++ src/common/port/usb_port.cpp | 411 +++++++++++++++++++++++++++++++++ src/common/port/usb_port.h | 70 ++++++ 12 files changed, 1791 insertions(+) create mode 100644 src/common/port/Makefile.am create mode 100644 src/common/port/parallel.cpp create mode 100644 src/common/port/parallel.h create mode 100644 src/common/port/port.cpp create mode 100644 src/common/port/port.h create mode 100644 src/common/port/port.pro create mode 100644 src/common/port/port_base.cpp create mode 100644 src/common/port/port_base.h create mode 100644 src/common/port/serial.cpp create mode 100644 src/common/port/serial.h create mode 100644 src/common/port/usb_port.cpp create mode 100644 src/common/port/usb_port.h (limited to 'src/common/port') diff --git a/src/common/port/Makefile.am b/src/common/port/Makefile.am new file mode 100644 index 0000000..d1d2ce8 --- /dev/null +++ b/src/common/port/Makefile.am @@ -0,0 +1,7 @@ +INCLUDES = -I$(top_srcdir)/src $(all_includes) +METASOURCES = AUTO + +noinst_LTLIBRARIES = libport.la +libport_la_SOURCES = parallel.cpp port.cpp serial.cpp usb_port.cpp \ + port_base.cpp +libport_la_LDFLAGS = $(all_libraries) diff --git a/src/common/port/parallel.cpp b/src/common/port/parallel.cpp new file mode 100644 index 0000000..22b6a4c --- /dev/null +++ b/src/common/port/parallel.cpp @@ -0,0 +1,247 @@ +/*************************************************************************** + * Copyright (C) 2005-2007 Nicolas Hadacek * + * Copyright (C) 2003-2004 Alain Gibaud * + * Copyright (C) 2002-2003 Stephen Landamore * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "parallel.h" + +#include "common/global/global.h" +#if defined(HAVE_PPDEV) +# include +# include +# include +# include +# include // needed on some system +# include +#elif defined(HAVE_PPBUS) +# include +# include +# include +# include +# include +# include +# include +#endif +#include "common/common/misc.h" + +//----------------------------------------------------------------------------- +QStringList *Port::Parallel::_list = 0; + +Port::IODirs Port::Parallel::probe(const QString &device) +{ +#if defined(HAVE_PPDEV) + int fd = ::open(device.latin1(), O_RDWR); + if ( fd<0) return NoIO; + if ( ioctl(fd, PPCLAIM)<0 ) { + ::close(fd) ; + return In; + } + ioctl(fd, PPRELEASE); + ::close(fd); + return (In | Out); +#elif defined(HAVE_PPBUS) + int fd = ::open(device.latin1(), O_RDWR); + if ( fd<0 ) return NoIO; + ::close(fd); + return In | Out; // #### can we detect read-only ? +#else + return NoIO; +#endif +} + +QStringList Port::Parallel::deviceList() +{ + QStringList list; +#if defined(HAVE_PPDEV) + // standard parport in user space + for(int i = 0; i<8; ++i) list.append(QString("/dev/parport%1").arg(i)); + // new devfs parport flavour + for(int i = 0; i<8; ++i) list.append(QString("/dev/parports/%1").arg(i)); +#elif defined(HAVE_PPBUS) + // FreeBSD + for(int i = 0; i<8; ++i) list.append(QString("/dev/ppi%1").arg(i)); +#endif + return list; +} + +const QStringList &Port::Parallel::probedDeviceList() +{ + if ( _list==0 ) { + QStringList all = deviceList(); + _list = new QStringList; + for (uint i=0; iappend(all[i]); + } + return *_list; +} + +bool Port::Parallel::isAvailable() +{ +#if defined(HAVE_PPDEV) || defined(HAVE_PPBUS) + return true; +#else + return false; +#endif +} + +//----------------------------------------------------------------------------- +const Port::Parallel::PPinData Port::Parallel::PIN_DATA[Nb_Pins] = { + { Control, 0x01, Out, "/DS" }, // !strobe + { Data, 0x01, Out, "D0" }, // data 0 + { Data, 0x02, Out, "D1" }, // data 1 + { Data, 0x04, Out, "D2" }, // data 2 + { Data, 0x08, Out, "D3" }, // data 3 + { Data, 0x10, Out, "D4" }, // data 4 + { Data, 0x20, Out, "D5" }, // data 5 + { Data, 0x40, Out, "D6" }, // data 6 + { Data, 0x80, Out, "D7" }, // data 7 + { Status, 0x40, In, "/ACK" }, // !ack + { Status, 0x80, In, "BUSY" }, // busy + { Status, 0x20, In, "PAPER" }, // pout + { Status, 0x10, In, "SELin" }, // select + { Control, 0x02, Out, "LF" }, // !feed + { Status, 0x08, In, "/ERROR" }, // !error + { Control, 0x04, Out, "PRIME" }, // !init + { Control, 0x08, Out, "SELout" }, // !si + { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND + { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND + { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND + { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND + { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND + { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND + { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND + { Nb_RequestTypes, 0x00, NoIO, "GND" } // GND +}; + +QValueVector Port::Parallel::pinData(IODir dir) const +{ + QValueVector v; + for (uint i=0; i * + * Copyright (C) 2003-2004 Alain Gibaud * + * Copyright (C) 2002-2003 Stephen Landamore * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef PARALLEL_H +#define PARALLEL_H + +#include "port_base.h" +#if defined(Q_OS_WIN) +# undef ERROR +#endif + +namespace Port +{ + +class Parallel : public Base +{ +public: + Parallel(const QString &device, Log::Base &base); + virtual ~Parallel() { close(); } + virtual Description description() const { return Description(PortType::Parallel, _device); } + + static IODirs probe(const QString &device); + static const QStringList &probedDeviceList(); + static bool isAvailable(); + + enum Pin { DS = 0, D0, D1, D2, D3, D4, D5, D6, D7, ACK, BUSY, PAPER, SELin, + LF, ERROR, PRIME, SELout, P18, P19, P20, P21, P22, P23, P24, P25, + Nb_Pins }; + enum RequestType { Control = 0, Status, Data, Nb_RequestTypes }; + struct PPinData { + RequestType rType; + uchar mask; + IODir dir; + const char *label; + }; + static const PPinData PIN_DATA[Nb_Pins]; + virtual bool setPinOn(uint pin, bool on, LogicType type); + virtual bool readPin(uint pin, LogicType type, bool &value); + virtual QValueVector pinData(IODir dir) const; + virtual bool isGroundPin(uint pin) const; + virtual uint groundPin() const { return P25; } + virtual IODir ioDir(uint pin) const; + +private: + int _fd; + QString _device; + struct RequestData { + int read, write; + }; + static const RequestData REQUEST_DATA[Nb_RequestTypes]; + uchar _images[Nb_RequestTypes]; + + static QStringList *_list; + static QStringList deviceList(); + + virtual bool internalOpen(); + virtual void internalClose(); + virtual void setSystemError(const QString &message); +}; + +} // namespace + +#endif diff --git a/src/common/port/port.cpp b/src/common/port/port.cpp new file mode 100644 index 0000000..c56c120 --- /dev/null +++ b/src/common/port/port.cpp @@ -0,0 +1,98 @@ +/*************************************************************************** + * Copyright (C) 2005-2006 Nicolas Hadacek * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "port.h" + +#if defined(Q_WS_WIN) +# include +#else +# include +#endif + +#include "common/global/global.h" +#include "serial.h" +#include "parallel.h" +#include "usb_port.h" + +//----------------------------------------------------------------------------- +void getTime(int &sec, int &usec) +{ +#if defined (Q_OS_WIN) + struct _timeb tb; + _ftime (&tb); + sec = tb.time; + usec = tb.millitm * 1000 + 500; +#else + struct timeval tv; + gettimeofday(&tv, 0); + usec = tv.tv_usec; + sec = tv.tv_sec; +#endif +} + +void Port::msleep(uint ms) +{ + usleep(ms*1000); +} + +// from Brian C Lane's code +// works better than usleep +void Port::usleep(uint us) +{ + if ( us==0 ) return; + int tsec, tusec; + getTime(tsec, tusec); + int usec = (tusec + us) % 1000000; + int sec = tsec + (tusec + us) / 1000000; + for (;;) { + getTime(tsec, tusec); + if ( tsec>sec ) return; + if ( tsec==sec && tusec>usec ) return; + } +} + +//----------------------------------------------------------------------------- +const PortType::Data PortType::DATA[Nb_Types] = { + { I18N_NOOP("Serial Port"), "serial", true }, + { I18N_NOOP("Parallel Port"), "parallel", true }, + { I18N_NOOP("USB Port"), "usb", false } +}; + +const char * const Port::IO_DIR_NAMES[3] = { "no_io", "in", "out" }; + +QStringList Port::probedDeviceList(PortType type) +{ + if ( !isAvailable(type) ) return QStringList(); + switch (type.type()) { + case PortType::Serial: return Serial::probedDeviceList(); + case PortType::Parallel: return Parallel::probedDeviceList(); + case PortType::USB: return USB::probedDeviceList(); + case PortType::Nb_Types: break; + } + return QStringList(); +} + +bool Port::isAvailable(PortType type) +{ + switch (type.type()) { + case PortType::Serial: return Serial::isAvailable(); + case PortType::Parallel: return Parallel::isAvailable(); + case PortType::USB: return USB::isAvailable(); + case PortType::Nb_Types: break; + } + return false; +} + +PortType Port::findType(const QString &portDevice) +{ + FOR_EACH(PortType, type) { + if ( !type.data().withDevice ) continue; + if ( probedDeviceList(type).contains(portDevice) ) return type; + } + return PortType::Nb_Types; +} diff --git a/src/common/port/port.h b/src/common/port/port.h new file mode 100644 index 0000000..f385deb --- /dev/null +++ b/src/common/port/port.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2005-2006 Nicolas Hadacek * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef PORT_H +#define PORT_H + +#include + +#include "common/global/global.h" +#include "common/common/key_enum.h" + +//----------------------------------------------------------------------------- +struct PortTypeData { + const char *label, *key; + bool withDevice; +}; + +BEGIN_DECLARE_ENUM(PortType) + Serial = 0, Parallel, USB +END_DECLARE_ENUM(PortType, PortTypeData) + +namespace Port +{ +//----------------------------------------------------------------------------- +extern void msleep(uint ms); // in milliseconds +extern void usleep(uint us); // in microseconds + +//----------------------------------------------------------------------------- + class Description { + public: + Description() : type(PortType::Nb_Types) {} + Description(PortType ptype, const QString &pdevice) : type(ptype), device(pdevice) {} + PortType type; + QString device; + }; + + enum IODir { NoIO = 0, In = 1, Out = 2 }; + extern const char * const IO_DIR_NAMES[3]; + Q_DECLARE_FLAGS(IODirs, IODir) + Q_DECLARE_OPERATORS_FOR_FLAGS(IODirs) + extern QStringList probedDeviceList(PortType type); + extern PortType findType(const QString &device); + extern bool isAvailable(PortType type); + struct PinData { + uint pin; + const char *label; + }; + enum LogicType { PositiveLogic, NegativeLogic }; +} // namespace + +#endif diff --git a/src/common/port/port.pro b/src/common/port/port.pro new file mode 100644 index 0000000..f09414b --- /dev/null +++ b/src/common/port/port.pro @@ -0,0 +1,10 @@ +STOPDIR = ../../.. +include($${STOPDIR}/lib.pro) + +TARGET = port +HEADERS += port.h port_base.h parallel.h serial.h usb_port.h +SOURCES += port.cpp port_base.cpp parallel.cpp serial.cpp usb_port.cpp +contains(DEFINES, HAVE_USB) { + win32:INCLUDEPATH += $${LIBUSB_PATH}\include +} + diff --git a/src/common/port/port_base.cpp b/src/common/port/port_base.cpp new file mode 100644 index 0000000..7528eeb --- /dev/null +++ b/src/common/port/port_base.cpp @@ -0,0 +1,127 @@ +/*************************************************************************** + * Copyright (C) 2005-2006 Nicolas Hadacek * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "port_base.h" + +#include "common/global/global.h" +#include "common/common/misc.h" +#include "common/common/number.h" + +bool Port::Base::open() +{ + close(); + resetError(); + _closing = false; + return internalOpen(); +} + +void Port::Base::close() +{ + _closing = true; + internalClose(); +} + +bool Port::Base::send(const char *data, uint size, uint timeout) +{ + log(Log::DebugLevel::LowLevel, QString("Sending: \"%1\"").arg(toPrintable(data, size, PrintAlphaNum))); + return internalSend(data, size, timeout); +} + +bool Port::Base::receive(uint size, QString &s, uint timeout) +{ + QMemArray a; + if ( !receive(size, a, timeout) ) return false; + s.fill(0, size); + for (uint i=0; i &a, uint timeout) +{ + a.resize(size); + bool ok = internalReceive(size, (char *)a.data(), timeout); + if (ok) log(Log::DebugLevel::LowLevel, QString("Received: \"%1\"").arg(toPrintable(a, PrintAlphaNum))); + return ok; +} + +bool Port::Base::receiveChar(char &c, uint timeout) +{ + if ( !internalReceive(1, &c, timeout) ) return false; + log(Log::DebugLevel::LowLevel, QString("Received: \"%1\"").arg(toPrintable(c, PrintAlphaNum))); + return true; +} + +bool Port::Base::setPinOn(uint, bool, LogicType) +{ + qFatal("setPinOn not implemented"); + return false; +} +bool Port::Base::readPin(uint, LogicType, bool &) +{ + qFatal("readPin not implemented"); + return 0; +} +QValueVector Port::Base::pinData(IODir) const +{ + qFatal("pinData not implemented"); + return QValueVector(); +} +bool Port::Base::isGroundPin(uint) const +{ + qFatal("isGroundPin not implemented"); + return false; +} +uint Port::Base::groundPin() const +{ + qFatal("groundPin not implemented"); + return 0; +} +Port::IODir Port::Base::ioDir(uint) const +{ + qFatal("ioType not implemented"); + return NoIO; +} + +void Port::Base::log(Log::LineType lineType, const QString &message) +{ + if ( lineType==Log::LineType::Error && _closing ) return; + Log::Base::log(lineType, description().type.label() + ": " + message); + if ( lineType==Log::LineType::Error ) close(); +} + +void Port::Base::log(Log::DebugLevel level, const QString &message) +{ + Log::Base::log(level, description().type.label() + ": " + message); +} + +void Port::Base::logData(const QString &) +{ +/* + QString vs; + for (uint i=0; i': vs += ">"; break; + default: { + if ( c>=32 && c<=126 ) vs += c; + else { + QString tmp; + tmp.sprintf("\\x%02x", c); + vs += tmp; + } + break; + } + } + } + qDebug("%s", vs.latin1()); +*/ + //log(Log::Debug, vs); +} diff --git a/src/common/port/port_base.h b/src/common/port/port_base.h new file mode 100644 index 0000000..3ae4787 --- /dev/null +++ b/src/common/port/port_base.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2005-2006 Nicolas Hadacek * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef PORT_BASE_H +#define PORT_BASE_H + +#include "port.h" +#include "common/global/log.h" + +namespace Port +{ + +class Base : public Log::Base +{ +public: + Base(Log::Base &base) : Log::Base(&base) {} + virtual PortType type() const { return description().type; } + virtual Description description() const = 0; + bool open(); + void close(); + + virtual void log(Log::LineType kind, const QString &message); + virtual void log(Log::DebugLevel level, const QString &message); + void logData(const QString &s); + + enum { DEFAULT_TIMEOUT = 3000 }; // 3s + bool sendChar(char c, uint timeout = DEFAULT_TIMEOUT) { return send(&c, 1, timeout); } + bool send(const char *data, uint size, uint timeout = DEFAULT_TIMEOUT); + bool send(const QMemArray &a, uint timeout = DEFAULT_TIMEOUT) { return send((const char *)a.data(), a.count(), timeout); } + bool receiveChar(char &c, uint timeout = DEFAULT_TIMEOUT); + bool receive(uint size, QString &s, uint timeout = DEFAULT_TIMEOUT); + bool receive(uint size, QMemArray &a, uint timeout = DEFAULT_TIMEOUT); + + virtual bool setPinOn(uint pin, bool on, LogicType type); + virtual bool readPin(uint pin, LogicType type, bool &value); + virtual QValueVector pinData(IODir dir) const; + virtual bool isGroundPin(uint pin) const; + virtual uint groundPin() const; + virtual IODir ioDir(uint pin) const; + +protected: + virtual bool internalOpen() = 0; + virtual void internalClose() = 0; + virtual bool internalSend(const char *, uint, uint) { qFatal("Not implemented"); return false; } + virtual bool internalReceive(uint, char *, uint) { qFatal("Not implemented"); return false; } + virtual void setSystemError(const QString &message) = 0; + +private: + bool _closing; +}; + +} // namespace + +#endif diff --git a/src/common/port/serial.cpp b/src/common/port/serial.cpp new file mode 100644 index 0000000..b370d22 --- /dev/null +++ b/src/common/port/serial.cpp @@ -0,0 +1,523 @@ +/*************************************************************************** + * Copyright (C) 2005-2006 Nicolas Hadacek * + * Copyright (C) 2003-2004 Alain Gibaud * + * Copyright (C) 2002-2003 Stephen Landamore * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "serial.h" + +#ifdef Q_OS_UNIX +# include +# include +# include +# include +# include +# include +# include +# include // needed on some system +#endif +#include + +//----------------------------------------------------------------------------- +QStringList *Port::Serial::_list = 0; +#if defined(Q_OS_UNIX) +const Port::Serial::Handle Port::Serial::INVALID_HANDLE = -1; +#elif defined(Q_OS_WIN) +const Port::Serial::Handle Port::Serial::INVALID_HANDLE = INVALID_HANDLE_VALUE; +#endif + +Port::Serial::Handle Port::Serial::openHandle(const QString &device, IODirs dirs) +{ +#if defined(Q_OS_UNIX) + // open non blocking: avoid missing DCD (comment from xwisp2) + int mode = O_NOCTTY | O_NONBLOCK; + if ( dirs & In ) { + if ( dirs & Out ) mode |= O_RDWR; + else mode |= O_RDONLY; + } else mode |= O_WRONLY; + return ::open(device.latin1(), mode); +#elif defined(Q_OS_WIN) + int mode = 0; + if ( dirs & In ) mode |= GENERIC_READ; + if ( dirs & Out ) mode |= GENERIC_WRITE; + return CreateFileA(device.latin1(), mode, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); +#endif +} + +void Port::Serial::closeHandle(Handle handle) +{ +#if defined(Q_OS_UNIX) + ::close(handle); +#elif defined(Q_OS_WIN) + CloseHandle(handle); +#endif +} + +Port::IODirs Port::Serial::probe(const QString &device) +{ + Handle handle = openHandle(device, In); + if ( handle==INVALID_HANDLE ) return NoIO; + closeHandle(handle); + handle = openHandle(device, In | Out); + if ( handle==INVALID_HANDLE ) return In; + closeHandle(handle); + return (In | Out); +} + +QStringList Port::Serial::deviceList() +{ + QStringList list; +#if defined(Q_OS_UNIX) + // standard serport in user space + for (uint i=0; i<8; i++) list.append(QString("/dev/ttyS%1").arg(i)); + // new devfs serport flavour + for (uint i=0; i<8; i++) list.append(QString("/dev/tts/%1").arg(i)); + // standard USB serport in user space + for (uint i=0; i<8; i++) list.append(QString("/dev/ttyUSB%1").arg(i)); + // new devfs USB serport flavour + for (uint i=0; i<8; i++) list.append(QString("/dev/usb/tts/%1").arg(i)); + // FreeBSD + for (uint i=0; i<8; i++) list.append(QString("/dev/ttyd%1").arg(i)); + // Slackware 11 devfs USB Serial port support. + for (uint i=0; i<8; i++) list.append(QString("/dev/tts/USB%1").arg(i)); + // MacOSX devfs USB Serial port support. + list.append("/dev/tty.usbserial"); +#elif defined(Q_OS_WIN) + for (uint i=1; i<10; i++) list.append(QString("COM%1").arg(i)); +#endif + return list; +} + +const QStringList &Port::Serial::probedDeviceList() +{ + if ( _list==0 ) { + QStringList all = deviceList(); + _list = new QStringList; + for (uint i=0; iappend(all[i]); + } + return *_list; +} + +//----------------------------------------------------------------------------- +const uint Port::Serial::SPEED_VALUES[Nb_Speeds] = { + 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, + 57600, 115200 +}; +const Port::Serial::SpeedData Port::Serial::SPEED_DATA[Nb_Speeds] = { +#if defined(Q_OS_UNIX) + { true, B0 }, { true, B50 }, { true, B75 }, { true, B110 }, + { true, B134 }, { true, B150 }, { true, B200 }, { true, B300 }, + { true, B600 }, { true, B1200 }, { true, B1800 }, { true, B2400 }, + { true, B4800 }, { true, B9600 }, { true, B19200 }, { true, B38400 }, + { true, B57600 }, { true, B115200 } +#elif defined(Q_OS_WIN) + { false, 0 }, { false, 0 }, { false, 0 }, { true, CBR_110 }, + { false, 0 }, { false, 0 }, { false, 0 }, { true, CBR_300 }, + { true, CBR_600 }, { true, CBR_1200 }, { false, 0 }, { true, CBR_2400 }, + { true, CBR_4800 }, { true, CBR_9600 }, { true, CBR_19200 }, { true, CBR_38400 }, + { true, CBR_57600 }, { true, CBR_115200 } +#endif +}; + +const Port::Serial::SPinData Port::Serial::PIN_DATA[Nb_Pins] = { + { In, "DCD" }, { In, "RX" }, { Out, "TX" }, { Out, "DTR" }, + { NoIO, "GND" }, { In, "DSR" }, { Out, "RTS" }, { In, "CTS" }, + { Out, "RI" } +}; + +QValueVector Port::Serial::pinData(IODir dir) const +{ + QValueVector v; + for (uint i=0; i0 ) todo -= res; + else { + if ( uint(time.elapsed())>timeout ) { + log(Log::LineType::Error, i18n("Timeout sending data (%1/%2 bytes sent).").arg(size-todo).arg(size)); + return false; + } + msleep(1); + } + } + if ( (_properties & NeedDrain) && !drain(timeout) ) return false; + return true; +} + +bool Port::Serial::internalReceive(uint size, char *data, uint timeout) +{ + if ( _fd==INVALID_HANDLE ) return false; + QTime time; + time.start(); + for(uint todo=size; todo!=0; ) { +#if defined(Q_OS_UNIX) + // this help reduce CPU usage. It also prevents blocking if the serial cable is disconnected + fd_set rfd; + FD_ZERO(&rfd); + FD_SET(_fd, &rfd); + struct timeval tv; + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout%1000)*1000; + int res = select(_fd+1, &rfd, 0, 0, &tv); + if ( res<0 ) { + setSystemError(i18n("Error receiving data")); + return false; + } + if ( res==0 ) { + log(Log::LineType::Error, i18n("Timeout waiting for data.")); + return false; + } + res = read(_fd, data+size-todo, todo); + if ( res<0 && errno!=EAGAIN ) { +#elif defined(Q_OS_WIN) + DWORD res = 0; + if ( ReadFile(_fd, data+size-todo, todo, &res, NULL)==0 ) { +#endif + setSystemError(i18n("Error receiving data")); + return false; + } + if ( res>0 ) todo -= res; + else { + if ( uint(time.elapsed())>timeout ) { + log(Log::LineType::Error, i18n("Timeout receiving data (%1/%2 bytes received).").arg(size-todo).arg(size)); + return false; + } + msleep(1); + } + } + return true; +} + +bool Port::Serial::drain(uint timeout) +{ + if ( _fd==INVALID_HANDLE ) return false; +#if defined(Q_OS_UNIX) + // tcdrain will block if the serial cable is disconnected + // so we first check for data in output buffer... + QTime time; + time.start(); + for (;;) { + int nb; + if ( ioctl(_fd, TIOCOUTQ, &nb)==-1 ) { + setSystemError(i18n("Error checking for data in output buffer")); + return false; + } + if ( nb==0 ) break; + if ( uint(time.elapsed())>timeout ) { + _fd = INVALID_HANDLE; // otherwise close blocks... + log(Log::LineType::Error, i18n("Timeout sending data (%1 bytes left).").arg(nb)); + return false; + } + } + if ( tcdrain(_fd)<0 ) { + setSystemError(i18n("Error while draining")); + return false; + } +#endif + return true; +} + +bool Port::Serial::flush(uint timeout) +{ + if ( _fd==INVALID_HANDLE ) return false; + if ( (_properties & NeedDrain) && !drain(timeout) ) return false; +#if defined(Q_OS_UNIX) + if ( tcflush(_fd, TCIFLUSH)<0 ) { +#elif defined(Q_OS_WIN) + if ( FlushFileBuffers(_fd)==0 || PurgeComm(_fd, PURGE_TXABORT)==0 + || PurgeComm(_fd, PURGE_RXABORT)==0 || PurgeComm(_fd, PURGE_TXCLEAR)==0 + || PurgeComm(_fd, PURGE_RXCLEAR)==0 ) { +#endif + setSystemError(i18n("Could not flush device")); + return false; + } + return true; +} + +bool Port::Serial::internalSetPinOn(Pin pin, bool on) +{ +#if defined(Q_OS_UNIX) + int bit = 0; + switch (pin) { + case TX: return ( ioctl(_fd, on ? TIOCSBRK : TIOCCBRK, 0)>=0 ); + case DTR: bit = TIOCM_DTR; break; + case RTS: bit = TIOCM_RTS; break; + case RI: bit = TIOCM_RI; break; + default: Q_ASSERT(false); return false; + } + return ( ioctl(_fd, on ? TIOCMBIS : TIOCMBIC, &bit)>=0 ); +#elif defined(Q_OS_WIN) + DWORD func = 0; + switch (pin) { + case TX: func = (on ? SETBREAK : CLRBREAK); break; + case DTR: func = (on ? SETDTR : CLRDTR); break; + case RTS: func = (on ? SETRTS : CLRRTS); break; + case RI: // #### not possible with Win32 API ?? + default: Q_ASSERT(false); return false; + } + return ( EscapeCommFunction(_fd, func)!=0 ); +#endif +} + +bool Port::Serial::setPinOn(uint pin, bool on, LogicType type) +{ + if ( _fd==INVALID_HANDLE ) return false; + if ( type==NegativeLogic ) on = !on; + Q_ASSERT( pin * + * Copyright (C) 2003-2004 Alain Gibaud * + * Copyright (C) 2002-2003 Stephen Landamore * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef SERIAL_H +#define SERIAL_H + +#include "common/global/global.h" +#ifdef Q_OS_UNIX +# include +#elif defined(Q_OS_WIN) +# include +#endif +#include "port_base.h" + +namespace Port +{ + +class Serial : public Base +{ +public: + enum Speed { S0 = 0, S50, S75, S110, S134, S150, S200, S300, S600, S1200, + S1800, S2400, S4800, S9600, S19200, S38400, S57600, S115200, + Nb_Speeds }; + static const uint SPEED_VALUES[Nb_Speeds]; + struct SpeedData { + bool supported; + uint flag; + }; + static const SpeedData SPEED_DATA[Nb_Speeds]; + + enum Property { NoProperty = 0, NeedDrain = 1, NeedFlush = 2, NeedBreak = 4, + Blocking = 8 }; + Q_DECLARE_FLAGS(Properties, Property) + + Serial(const QString &device, Properties properties, Log::Base &base); + virtual ~Serial() { close(); } + virtual Description description() const { return Description(PortType::Serial, _device); } + + static const QStringList &probedDeviceList(); + static IODirs probe(const QString &device); + static bool isAvailable() { return true; } + + enum InputFlag { NoInputFlag = 0, IgnoreBreak = 1, IgnoreParity = 2 }; + Q_DECLARE_FLAGS(InputFlags, InputFlag) + enum ControlFlag { NoControlFlag = 0, ByteSize8 = 1, HardwareFlowControl = 2, + EnableReceiver = 4, IgnoreControlLines = 8 }; + Q_DECLARE_FLAGS(ControlFlags, ControlFlag) + bool setMode(InputFlags inputFlags, ControlFlags controlFlags, Speed speed, uint readTimeout); // in ms + bool drain(uint timeout); + bool flush(uint timeout); + bool doBreak(uint duration); // in ms + bool setHardwareFlowControl(bool on); + + enum Pin { DCD = 0, RX, TX, DTR, SG, DSR, RTS, CTS, RI, Nb_Pins }; + struct SPinData { + IODir dir; + const char *label; + }; + static const SPinData PIN_DATA[Nb_Pins]; + virtual bool setPinOn(uint pin, bool on, LogicType type); + virtual bool readPin(uint pin, LogicType type, bool &value); + virtual QValueVector pinData(IODir dir) const; + virtual bool isGroundPin(uint pin) const; + virtual uint groundPin() const { return SG; } + virtual IODir ioDir(uint pin) const; + +private: + QString _device; + Properties _properties; +#if defined(Q_OS_UNIX) + typedef int Handle; + typedef termios Parameters; +#elif defined(Q_OS_WIN) + typedef HANDLE Handle; + struct Parameters { + DCB dcb; + COMMTIMEOUTS comtmo; + }; +#endif + Handle _fd; + Parameters _oldParameters; + + bool setParameters(const Parameters ¶meters); + bool getParameters(Parameters ¶meters); + virtual bool internalOpen(); + virtual void internalClose(); + virtual bool internalSend(const char *data, uint size, uint timeout); + virtual bool internalReceive(uint size, char *data, uint timeout); + virtual void setSystemError(const QString &message); + bool internalSetPinOn(Pin pin, bool on); + bool internalReadPin(Pin pin, LogicType type, bool &value); + + static const Handle INVALID_HANDLE; + static Handle openHandle(const QString &device, IODirs dirs); + static void closeHandle(Handle handle); + static QStringList *_list; + static QStringList deviceList(); + static void setHardwareFlowControl(Parameters ¶meters, bool on); +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(Serial::Properties) +Q_DECLARE_OPERATORS_FOR_FLAGS(Serial::InputFlags) +Q_DECLARE_OPERATORS_FOR_FLAGS(Serial::ControlFlags) + +} // namespace + +#endif diff --git a/src/common/port/usb_port.cpp b/src/common/port/usb_port.cpp new file mode 100644 index 0000000..392b483 --- /dev/null +++ b/src/common/port/usb_port.cpp @@ -0,0 +1,411 @@ +/*************************************************************************** + * Copyright (C) 2005 Lorenz Mösenlechner & Matthias Kranz * + * * + * Copyright (C) 2003-2005 Orion Sky Lawlor * + * Copyright (C) 2005-2007 Nicolas Hadacek * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "usb_port.h" + +#ifdef HAVE_USB +# include +#endif +#include + +#include "common/common/version_data.h" +#include "common/common/number.h" + +//----------------------------------------------------------------------------- +class Port::USB::Private +{ +public: +#ifdef HAVE_USB + Private() : _interface(0) {} + const usb_interface_descriptor *_interface; +#endif +}; + +bool Port::USB::_initialized = false; + +void Port::USB::initialize() +{ + if (_initialized) return; + _initialized = true; +#ifdef HAVE_USB + usb_init(); + VersionData vd = VersionData::fromString(LIBUSB_VERSION); + QString s = QString("libusb %1").arg(vd.pretty()); + if ( vddescriptor.bNumConfigurations); + for (int c=0; cdescriptor.bNumConfigurations; c++) { + qDebug("Looking at configuration %d...This configuration has %d interfaces.", c, dev->config[c].bNumInterfaces); + for(int i=0; iconfig[c].bNumInterfaces; i++) { + qDebug(" Looking at interface %d...This interface has %d altsettings.", i, dev->config[c].interface[i].num_altsetting); + for (int a=0; a < dev->config[c].interface[i].num_altsetting; a++) { + qDebug(" Looking at altsetting %d...This altsetting has %d endpoints.", a, dev->config[c].interface[i].altsetting[a].bNumEndpoints); + for (int e=0; e < dev->config[c].interface[i].altsetting[a].bNumEndpoints; e++) { + QString s; + s.sprintf(" Endpoint %d: Address %02xh, attributes %02xh ", e, dev->config[c].interface[i].altsetting[a].endpoint[e].bEndpointAddress, dev->config[c].interface[i].altsetting[a].endpoint[e].bmAttributes); + uchar attribs = (dev->config[c].interface[i].altsetting[a].endpoint[e].bmAttributes & 3); + switch (attribs) { + case 0: s += "(Control) "; break; + case 1: s += "(Isochronous) "; break; + case 2: s += "(Bulk) "; + /* Found the correct configuration, interface etc... it has bulk endpoints! */ + configuration=c; + interface=i; + altsetting=a; + break; + case 3: s += "(Interrupt) "; break; + default: s += "ERROR! Got an illegal value in endpoint bmAttributes"; + } + if ( attribs!=0 ) { + uchar dir = (dev->config[c].interface[i].altsetting[a].endpoint[e].bEndpointAddress & 0x80); + switch (dir) { + case 0x00: s += "(Out)"; + // Do nothing in this case + break; + case 0x80: s += "(In)"; + if ((dev->config[c].interface[i].altsetting[a].endpoint[e].bmAttributes & 0x03) == 2) /* Make sure it's a *bulk* endpoint */ { + // Found the correct endpoint to use for bulk transfer; use its ADDRESS + bulk_endpoint=dev->config[c].interface[i].altsetting[a].endpoint[e].bEndpointAddress; + } + break; + default: s += "ERROR! Got an illegal value in endpoint bEndpointAddress"; + } + } + qDebug("%s", s.latin1()); + } + } + } + } + if (bulk_endpoint<0) { + qDebug("No valid interface found!"); + return false; + } +#endif + return true; +} + +QStringList Port::USB::probedDeviceList() +{ + initialize(); + QStringList list; +#ifdef HAVE_USB + usb_init(); // needed ? + for (usb_bus *bus=getBusses(); bus; bus=bus->next) { + for (struct usb_device *dev=bus->devices; dev; dev=dev->next) { + if ( dev->descriptor.idVendor==0 ) continue; // controller + list.append(QString("Vendor Id: %1 - Product Id: %2") + .arg(toLabel(NumberBase::Hex, dev->descriptor.idVendor, 4)).arg(toLabel(NumberBase::Hex, dev->descriptor.idProduct, 4))); + } + } +#endif + return list; +} + +struct usb_device *Port::USB::findDevice(uint vendorId, uint productId) +{ + initialize(); +#ifdef HAVE_USB + for (usb_bus *bus=getBusses(); bus; bus=bus->next) { + for (struct usb_device *dev=bus->devices; dev; dev=dev->next) { + if ( dev->descriptor.idVendor==vendorId && dev->descriptor.idProduct==productId ) + return dev; + } + } +#else + Q_UNUSED(vendorId); Q_UNUSED(productId); + qDebug("USB support disabled"); +#endif + return 0; +} + +//----------------------------------------------------------------------------- +const char * const Port::USB::ENDPOINT_MODE_NAMES[Nb_EndpointModes] = { + "bulk", "interrupt", "control", "isochronous" +}; + +Port::USB::USB(Log::Base &base, uint vendorId, uint productId, uint config, uint interface) + : Base(base), _vendorId(vendorId), _productId(productId), + _config(config), _interface(interface), _handle(0), _device(0) +{ + Q_ASSERT( config>=1 ); + _private = new Private; + initialize(); +} + +Port::USB::~USB() +{ + close(); + delete _private; +} + +void Port::USB::setSystemError(const QString &message) +{ +#ifdef HAVE_USB + log(Log::LineType::Error, message + QString(" (err=%1).").arg(usb_strerror())); +#else + log(Log::LineType::Error, message); +#endif +} + +void Port::USB::tryToDetachDriver() +{ + // try to detach an already existing driver... (linux only) +#if defined(LIBUSB_HAS_GET_DRIVER_NP) && LIBUSB_HAS_GET_DRIVER_NP + log(Log::DebugLevel::Extra, "find if there is already an installed driver"); + char dname[256] = ""; + if ( usb_get_driver_np(_handle, _interface, dname, 255)<0 ) return; + log(Log::DebugLevel::Normal, QString(" a driver \"%1\" is already installed...").arg(dname)); +# if defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP) && LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP + usb_detach_kernel_driver_np(_handle, _interface); + log(Log::DebugLevel::Normal, " try to detach it..."); + if ( usb_get_driver_np(_handle, _interface, dname, 255)<0 ) return; + log(Log::DebugLevel::Normal, " failed to detach it"); +# endif +#endif +} + +bool Port::USB::internalOpen() +{ +#ifdef HAVE_USB + _device = findDevice(_vendorId, _productId); + if ( _device==0 ) { + log(Log::LineType::Error, i18n("Could not find USB device (vendor=%1 product=%2).") + .arg(toLabel(NumberBase::Hex, _vendorId, 4)).arg(toLabel(NumberBase::Hex, _productId, 4))); + return false; + } + log(Log::DebugLevel::Extra, QString("found USB device as \"%1\" on bus \"%2\"").arg(_device->filename).arg(_device->bus->dirname)); + _handle = usb_open(_device); + if ( _handle==0 ) { + setSystemError(i18n("Error opening USB device.")); + return false; + } +// windows: usb_reset takes about 7-10 seconds to re-enumerate the device... +// BSD : not implemented in libusb... +# if !defined(Q_OS_BSD4) && !defined(Q_OS_WIN) + if ( usb_reset(_handle)<0 ) { + setSystemError(i18n("Error resetting USB device.")); + return false; + } +# endif + usb_close(_handle); + _handle = usb_open(_device); + if ( _handle==0 ) { + setSystemError(i18n("Error opening USB device.")); + return false; + } + tryToDetachDriver(); + uint i = 0; + for (; i<_device->descriptor.bNumConfigurations; i++) + if ( _config==_device->config[i].bConfigurationValue ) break; + if ( i==_device->descriptor.bNumConfigurations ) { + uint old = _config; + i = 0; + _config = _device->config[i].bConfigurationValue; + log(Log::LineType::Warning, i18n("Configuration %1 not present: using %2").arg(old).arg(_config)); + } + const usb_config_descriptor &configd = _device->config[i]; + if ( usb_set_configuration(_handle, _config)<0 ) { + setSystemError(i18n("Error setting USB configuration %1.").arg(_config)); + return false; + } + for (i=0; i_interface = &(configd.interface[i].altsetting[0]); + if ( usb_claim_interface(_handle, _interface)<0 ) { + setSystemError(i18n("Could not claim USB interface %1").arg(_interface)); + return false; + } + log(Log::DebugLevel::Max, QString("alternate setting is %1").arg(_private->_interface->bAlternateSetting)); + log(Log::DebugLevel::Max, QString("USB bcdDevice: %1").arg(toHexLabel(_device->descriptor.bcdDevice, 4))); + return true; +#else + log(Log::LineType::Error, i18n("USB support disabled")); + return false; +#endif +} + +void Port::USB::internalClose() +{ + if ( _handle==0 ) return; +#ifdef HAVE_USB + usb_release_interface(_handle, _interface); + usb_close(_handle); + _private->_interface = 0; +#endif + _device = 0; + _handle = 0; +} + +bool Port::USB::sendControlMessage(const ControlMessageData &data) +{ + if ( hasError() ) return false; +#ifdef HAVE_USB + QString s = data.bytes; + uint length = strlen(data.bytes) / 2; + QByteArray ba(length); + for (uint i=0; i_interface); + const usb_endpoint_descriptor *ued = _private->_interface->endpoint + index; + Q_ASSERT(ued); + switch (ued->bmAttributes & USB_ENDPOINT_TYPE_MASK) { + case USB_ENDPOINT_TYPE_BULK: return Bulk; + case USB_ENDPOINT_TYPE_INTERRUPT: return Interrupt; + case USB_ENDPOINT_TYPE_ISOCHRONOUS: return Isochronous; + case USB_ENDPOINT_TYPE_CONTROL: return Control; + default: break; + } +#endif + Q_ASSERT(false); + return Nb_EndpointModes; +} + +Port::IODir Port::USB::endpointDir(uint ep) const +{ +#ifdef HAVE_USB + switch (ep & USB_ENDPOINT_DIR_MASK) { + case USB_ENDPOINT_IN: return In; + case USB_ENDPOINT_OUT: return Out; + default: break; + } +#endif + Q_ASSERT(false); + return NoIO; +} + +bool Port::USB::write(uint ep, const char *data, uint size) +{ + if ( hasError() ) return false; +#ifdef HAVE_USB + IODir dir = endpointDir(ep); + EndpointMode mode = endpointMode(ep); + log(Log::DebugLevel::LowLevel, QString("write to endpoint %1 (%2 - %3) %4 chars: \"%5\"") + .arg(toHexLabel(ep, 2)).arg(ENDPOINT_MODE_NAMES[mode]).arg(IO_DIR_NAMES[dir]).arg(size).arg(toPrintable(data, size, PrintEscapeAll))); + Q_ASSERT( dir==Out ); + QTime time; + time.start(); + int todo = size; + for (;;) { + int res = 0; + //qDebug("write ep=%i todo=%i/%i", ep, todo, size); + if ( mode==Interrupt ) res = usb_interrupt_write(_handle, ep, (char *)data + size - todo, todo, timeout(todo)); + else res = usb_bulk_write(_handle, ep, (char *)data + size - todo, todo, timeout(todo)); + //qDebug("res: %i", res); + if ( res==todo ) break; + if ( uint(time.elapsed())>3000 ) { // 3 s + if ( res<0 ) setSystemError(i18n("Error sending data (ep=%1 res=%2)").arg(toHexLabel(ep, 2)).arg(res)); + else log(Log::LineType::Error, i18n("Timeout: only some data sent (%1/%2 bytes).").arg(size-todo).arg(size)); + return false; + } + if ( res==0 ) log(Log::DebugLevel::Normal, i18n("Nothing sent: retrying...")); + if ( res>0 ) todo -= res; + msleep(100); + } +#else + Q_UNUSED(ep); Q_UNUSED(data); Q_UNUSED(size); +#endif + return true; +} + +bool Port::USB::read(uint ep, char *data, uint size, bool *poll) +{ + if ( hasError() ) return false; +#ifdef HAVE_USB + IODir dir = endpointDir(ep); + EndpointMode mode = endpointMode(ep); + log(Log::DebugLevel::LowLevel, QString("read from endpoint %1 (%2 - %3) %4 chars") + .arg(toHexLabel(ep, 2)).arg(ENDPOINT_MODE_NAMES[mode]).arg(IO_DIR_NAMES[dir]).arg(size)); + Q_ASSERT( dir==In ); + QTime time; + time.start(); + int todo = size; + for (;;) { + int res = 0; + //qDebug("read ep=%i size=%i", ep, todo); + if ( mode==Interrupt ) res = usb_interrupt_read(_handle, ep, data + size - todo, todo, timeout(todo)); + else res = usb_bulk_read(_handle, ep, data + size - todo, todo, timeout(todo)); + //qDebug("res: %i", res); + if ( res==todo ) break; + if ( uint(time.elapsed())>3000 ) { // 3 s: seems to help icd2 in some case (?) + if ( res<0 ) setSystemError(i18n("Error receiving data (ep=%1 res=%2)").arg(toHexLabel(ep, 2)).arg(res)); + else log(Log::LineType::Error, i18n("Timeout: only some data received (%1/%2 bytes).").arg(size-todo).arg(size)); + return false; + } + if ( res==0 ) { + if (poll) { + *poll = false; + return true; + } else log(Log::DebugLevel::Normal, i18n("Nothing received: retrying...")); + } + if ( res>0 ) todo -= res; + msleep(100); + } + if (poll) *poll = true; +#else + Q_UNUSED(ep); Q_UNUSED(data); Q_UNUSED(size); +#endif + return true; +} diff --git a/src/common/port/usb_port.h b/src/common/port/usb_port.h new file mode 100644 index 0000000..73961cc --- /dev/null +++ b/src/common/port/usb_port.h @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (C) 2005 Lorenz Mösenlechner & Matthias Kranz * + * * + * Copyright (C) 2005 Nicolas Hadacek * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef USB_PORT_H +#define USB_PORT_H + +#include "port_base.h" +#if defined(Q_OS_WIN) +#undef interface +#endif +struct usb_dev_handle; +struct usb_device; +struct usb_bus; + +namespace Port +{ + +class USB : public Base +{ +public: + USB(Log::Base &base, uint vendorId, uint productId, uint config, uint interface); + virtual ~USB(); + virtual Description description() const { return Description(PortType::USB, QString::null); } + + static struct usb_device *findDevice(uint vendorId, uint productId); + static bool isAvailable(); + static QStringList probedDeviceList(); + + struct ControlMessageData { + int type, request, value; + const char *bytes; + }; + bool sendControlMessage(const ControlMessageData &data); + enum EndpointMode { Bulk = 0, Interrupt, Control, Isochronous, Nb_EndpointModes }; + static const char * const ENDPOINT_MODE_NAMES[Nb_EndpointModes]; + EndpointMode endpointMode(uint ep) const; + IODir endpointDir(uint ep) const; + +protected: + bool write(uint endPoint, const char *data, uint size); + bool read(uint endPoint, char *data, uint size, bool *poll = 0); + +private: + class Private; + Private *_private; + uint _vendorId, _productId, _config, _interface; + usb_dev_handle *_handle; + usb_device *_device; + + virtual bool internalOpen(); + virtual void internalClose(); + virtual void setSystemError(const QString &message); + void tryToDetachDriver(); + + static bool _initialized; + static void initialize(); + static usb_bus *getBusses(); + static bool findBulk(const struct usb_device *device); +}; + +} // namespace + +#endif -- cgit v1.2.1