📄 usbpp.h
字号:
* \brief OS representation of filename for this device * * libusb++ provides a uniform way of accessing USB * devices irrespective of the underlying Operation System * representation. If you want to map the libusb++ representation * to the Operating System representation, you can do this * with filename(). * * On Linux, the filename is usually something like 002, which * represents the second device (usually the first real device, * after the root hub pseudo-device) on the bus. * * \see Bus::directoryName() */ std::string fileName(void); /** * \brief The vendor ID number, as provided by the device. * * This method returns a number containing the vendor * (manufacturer) identification number. These are allocated * by the USB Implementers Forum, and you can construct a * lookup based on the number to get the manufacturer's name, * even if the device does not contain a vendor string. * * \see Vendor() */ u_int16_t idVendor(void); /** * \brief The product ID number, as provided by the device. * * This method returns a number containing the product * identification number. These are allocated * by the manufacturer, and should be different on each device. * * \see Product() */ u_int16_t idProduct(void); /** * \brief The product's revision ID, as provided by the device. * * This method returns a number containing the product's revision. * This revision level is nominally binary coded decimal, but * hexadecimal revision levels are not uncommon. The binary coded * decimal version nominally has a major version in the high byte, * and a minor version in the low byte. */ u_int16_t idRevision(void); /** * \brief The device's USB class, as provided by the device. * * This method returns a number containing the device's class. * These are defined by the USB Implementer's Forum. * * A code of Zero is special (and common) - it means that the * class is found in the Interface descriptor, rather than in the * Device descriptor. * * A code of 0xFF is also special (and far too common) - it means * that the manufacturer didn't conform to one of the defined * class specifications, and chose to implement a vendor specified * protocol. * */ u_int8_t devClass(void); /** * \brief The device's USB subclass, as provided by the device. * * This method returns a number containing the device's subclass. * These subclasses are defined by the USB Implementer's Forum, * and only have meaning in the context of a specified class. */ u_int8_t devSubClass(void); /** * \brief The device's USB protocol, as provided by the device. * * This method returns a number containing the device's protocol. * These protocols are defined by the USB Implementer's Forum, and * only have meaning in the context of a specified class and * subclass. */ u_int8_t devProtocol(void); /** * \brief The vendor name string, as provided by the device. * * This method returns a string containing the name of the * device's vendor (manufacturer), as encoded into the device. * * Note that not all devices contain a vendor name, and also * that under some operating systems you may not be able to * read the vendor name without elevated privledges (typically * root privledges). * * \see idVendor() **/ std::string Vendor(void); /** * \brief The product name string, as provided by the device. * * This method returns a string containing the name of the * device's product name, as encoded into the device. * * Note that not all devices contain a product name, and also * that under some operating systems you may not be able to * read the vendor name without elevated privledges (typically * root privledges). * * \see idProduct() **/ std::string Product(void); /** * \brief The serial number string, as provided by the device. * * This method returns a string containing a serial number for * the device, as encoded into the device. * * Note that few devices contain a serial number string, and also * that under some operating systems you may not be able to * read the serial number without elevated privledges (typically * root privledges). The USB specification requires that serial * numbers are unique if they are provided, but adherence to this * requirement by manufacturers is not universal. **/ std::string SerialNumber(void); /** * \brief Number of Configurations that this device has * * This is a simple accessor method that specifies the number * configurations that this device has. */ u_int8_t numConfigurations(void); /** * \brief fetch an arbitrary string from the device * * \param string the string from the device. You can typically * pass in an empty string for this. * \param index the index of the string required * \param lang the language ID to use. Defaults to using the * first language ID. * * \return length of string, or 0 on error. */ int string(std::string &buf, int index, u_int16_t lang=0); /** * \brief First Configuration for the Device * * This method returns a pointer to the first Configuration * for the Device. * * See nextConfiguration() for an example of how it might be * used. */ Configuration *firstConfiguration(void); /** * \brief Next Configuration for the Device * * This method returns a pointer to the next Configuration * for the Device. * * If you want to iterate through each Configuration on * a device, you can use something like the following: * \code * USB::Configuration *this_Configuration; * this_Configuration = device->firstConfiguration(); * for (i=0; i < device->numConfigurations(); i++) { * // do something with this_Configuration * this_Configuration->nextConfiguration(); * } * \endcode */ Configuration *nextConfiguration(void); /** * \brief Last Configuration for the Device * * This method returns a pointer to the last Configuration * for the Device. * */ Configuration *lastConfiguration(void); /** * \brief USB control transfer * * This method performs a standard control transfer to the default * endpoint. See the USB specification for more details on this. * * \param requestType corresponds to the bmRequestType field * in the transfer * \param request corresponds to the bRequest field in the * transfer * \param value corresponds to the wValue field in the transfer * \param index corresponds to the wIndex field in the transfer * \param length corresponds to the wLength field in the transfer * \param payload corresponds to the data phase of a control * transfer * \param timeout is the timeout period for the control transfer, * in milliseconds * * \return number of bytes sent or received, or a negative number * in case of error. */ int controlTransfer(u_int8_t requestType, u_int8_t request, u_int16_t value, u_int16_t index, u_int16_t length, unsigned char *payload, int timeout = 100); #ifdef USE_UNTESTED_LIBUSBPP_METHODS /** * \brief USB device reset * * This method performs a device reset - see USB Specification * 9.1 for how this changes the device state to the Default state. * * \return 0 on success, or a negative number in case of error. */ int reset(void); /** * \brief Set device configuration * * This method sets the device to a particular Configuration. * * \param configurationNumber the configuration that the device * should be changed to. * * \return 0 on success, or a negative number in case of error. */ int setConfiguration(int configurationNumber);#endif /* USE_UNTESTED_LIBUSBPP_METHODS */ private: std::list<Configuration *>::const_iterator iter; struct usb_dev_handle *handle(); void setFileName(std::string); void setDescriptor(struct usb_device_descriptor); void setVendor(std::string); void setProduct(std::string); void setSerialNumber(std::string); void setDevHandle(struct usb_dev_handle *); std::string m_fileName; std::string m_Vendor; std::string m_Product; std::string m_SerialNumber; struct usb_device *m_dev; struct usb_dev_handle *m_handle; struct usb_device_descriptor m_descriptor; }; /** * \brief Class representing a single bus on the machine * * This class is essentially a list of Device class instances */ class Bus : public std::list<Device *> { /** * Busses is a friend because it fills in the directory name * information on initialisation and rescan. */ friend class Busses; public: Bus() {}; /** * \brief OS representation of directory name for this Bus * * libusb++ provides a uniform way of accessing USB * busses irrespective of the underlying Operation System * representation. If you want to map the libusb++ representation * to the Operating System representation, you can do this * with directory name(). * * On Linux, the directoryname is usually something like 003, which * represents the third bus on the host. * * \see Directory::filename() */ std::string directoryName(void); private: std::list<Device *>::const_iterator iter; void setDirectoryName(std::string); std::string m_directoryName; }; /** * \brief A vendor/product ID pair * * DeviceID provides a list of (vendor, product) identification * pairs. It is intended for use in a list of device numbers to * search for, but there is no reason why it couldn't be used for a * general purpose (vendor,product) tuple if you had some reason for * this. * * The description for Busses::match() provides an example of how * this class might be used. * * \see DeviceIDList, Busses::match() */ class DeviceID { public: DeviceID() {}; /** * \brief Standard constructor * * This constructor takes (vendor, product) tuple, which are * stored away. * * \param vendor the 16 bit vendor number for the device * \param product the 16 bit product number for the device */ DeviceID(u_int16_t vendor, u_int16_t product); /** * \brief vendor number for the device * * This method returns the 16 bit vendor number. */ u_int16_t vendor(void); /** * \brief product number for the device * * This method returns the 16 bit product number. */ u_int16_t product(void); private: u_int16_t m_vendor; u_int16_t m_product; }; /** * \brief A list of vendor/product pairs * * DeviceIDList provides a list of DeviceID classes, which is * essentially a list of (vendor, product) identification pairs. * * \see DeviceID */ typedef std::list<DeviceID> DeviceIDList; /** * \brief Class representing all the busses on the machine * * This class is essentially a list of Bus class instances */ class Busses : public std::list<Bus *> { public: Busses(); /** * \brief Update method * * This method can be called to rescan the various devices * attached to the various busses. You should use it to * update if things change. Unfortunately there is no * way to automatically detect this change in a portable way, * so worst case is that you need to call this using some * kind of timer in the background. */ void rescan(void); /** * \brief find all devices with matching device class designator * * This method searches every device on every bus, and returns a * list of pointers to the devices that have a matching device * class code */ std::list<Device *> match(u_int8_t Class); /** * \brief find all devices with matching device IDs * * This method searches every device on every bus, and returns a * list of pointers to the devices that have a matching device * ID. That is, if the (vendor, product) tuple of a device matches * one of the tuples on the list, then the device will be added to * the list of matches. * * An example of usage is shown below: * \code * USB::Busses buslist; * USB::Device *device; * std::list<USB::Device> miceFound; * USB::DeviceIDList mouseList; * * mouseList.append(USB::DeviceID(VENDOR_LOGITECH, 0xC00E)); // Wheel Mouse Optical * mouseList.append(USB::DeviceID(VENDOR_LOGITECH, 0xC012)); // MouseMan Dual Optical * mouseList.append(USB::DeviceID(VENDOR_LOGITECH, 0xC506)); // MX700 Optical Mouse * * miceFound = buslist.match(mouseList); * * for ( device = miceFound.first(); device; device = miceFound.next() ) { * // do something with each mouse that matched * } * FIXME: This is incorrect now * \endcode */ std::list<Device *> match(DeviceIDList); private: std::list<Bus *>::const_iterator iter; }; class Error { public: private: };}#endif /* __USBPP_HEADER__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -