当前位置: 首页>>代码示例>>C++>>正文


C++ USBDevice::collectData方法代码示例

本文整理汇总了C++中USBDevice::collectData方法的典型用法代码示例。如果您正苦于以下问题:C++ USBDevice::collectData方法的具体用法?C++ USBDevice::collectData怎么用?C++ USBDevice::collectData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在USBDevice的用法示例。


在下文中一共展示了USBDevice::collectData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: collectData

void USBDevice::collectData( int fd, int level, usb_device_info &di, int parent)
{
	// determine data for this device
	_level        = level;
	_parent       = parent;
	
	_bus          = di.udi_bus;
	_device       = di.udi_addr;
	_product      = QString::fromLatin1(di.udi_product);
	if ( _device == 1 )
		_product += " " + QString::number( _bus );
	_manufacturer = QString::fromLatin1(di.udi_vendor);
	_prodID       = di.udi_productNo;
	_vendorID     = di.udi_vendorNo;
	_class        = di.udi_class;
	_sub          = di.udi_subclass;
	_prot         = di.udi_protocol;
	_power        = di.udi_power;
	_channels     = di.udi_nports;
	
	// determine the speed
#if __FreeBSD_version > 490102
	switch (di.udi_speed) {
		case USB_SPEED_LOW:  _speed = 1.5;   break;
		case USB_SPEED_FULL: _speed = 12.0;  break;
		case USB_SPEED_HIGH: _speed = 480.0; break;
	}
#else
	_speed = di.udi_lowspeed ? 1.5 : 12.0;
#endif

	// Get all attached devicenodes
	for ( int i = 0; i < USB_MAX_DEVNAMES; ++i )
		if ( di.udi_devnames[i][0] )
			_devnodes << di.udi_devnames[i];

	// For compatibility, split the revision number
	sscanf( di.udi_release, "%x.%x", &_revMajor, &_revMinor );

	// Cycle through the attached devices if there are any
	for ( int p = 0; p < di.udi_nports; ++p ) {
		// Get data for device
		struct usb_device_info di2;

		di2.udi_addr = di.udi_ports[p];
		
		if ( di2.udi_addr >= USB_MAX_DEVICES )
			continue;
			
		if ( ioctl(fd, USB_DEVICEINFO, &di2) == -1 )
			continue;

		// Only add the device if we didn't detect it, yet
		if (!find( di2.udi_bus, di2.udi_addr ) )
		{
			USBDevice *device = new USBDevice();
			device->collectData( fd, level + 1, di2, di.udi_addr );
		}
	}
}
开发者ID:,项目名称:,代码行数:60,代码来源:

示例2: parse

bool USBDevice::parse(QString fname)
{
	static bool showErrorMessage = true;
	bool error = false;
	_devices.clear();
	
	QFile controller("/dev/usb0");
	int i = 1;
	while ( controller.exists() )
	{
		// If the devicenode exists, continue with further inspection
		if ( controller.open(IO_ReadOnly) )
		{
			for ( int addr = 1; addr < USB_MAX_DEVICES; ++addr ) 
			{
				struct usb_device_info di;
				
				di.udi_addr = addr;
				if ( ioctl(controller.handle(), USB_DEVICEINFO, &di) != -1 )
				{
					if (!find( di.udi_bus, di.udi_addr ) )
					{
						USBDevice *device = new USBDevice();
						device->collectData( controller.handle(), 0, di, 0);
					}
				}
			}
			controller.close();
		} else {
			error = true;
		}
		controller.setName( QString::fromLocal8Bit("/dev/usb%1").arg(i++) );
	}
	
	if ( showErrorMessage && error ) {
		showErrorMessage = false;
		KMessageBox::error( 0, i18n("Could not open one or more USB controller. Make sure, you have read access to all USB controllers that should be listed here."));
	}
	
	return true;
}
开发者ID:,项目名称:,代码行数:41,代码来源:


注:本文中的USBDevice::collectData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。