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


C++ TimeStamp::TimeRemaining方法代码示例

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


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

示例1: GetFeatureReport

//-----------------------------------------------------------------------------
// <HidController::Read>
// Read data from the HID port
//-----------------------------------------------------------------------------
void HidController::Read
(
)
{
	uint8 buffer[FEATURE_REPORT_LENGTH];
	int bytesRead = 0;
	uint8 inputReport[INPUT_REPORT_LENGTH];
	TimeStamp readTimer;

 	while( true )
	{
		// Rx feature report buffer should contain
		// [0]      - 0x05 (rx feature report ID)
		// [1]      - length of rx data (or 0x00 and no further bytes if no rx data waiting)
		// [2]...   - rx data
	  	// We poll this waiting for data.
		bytesRead = GetFeatureReport(FEATURE_REPORT_LENGTH, 0x5, buffer);
		CHECK_HIDAPI_RESULT(bytesRead, HidPortError);
		if( bytesRead >= 2 )
		{

			if( buffer[1] > 0 )
			{
				string tmp = "";
				for (int i = 0; i < buffer[1]; i++)
				{
					char bstr[16];
					snprintf( bstr, sizeof(bstr), "0x%.2x ", buffer[2+i] );
					tmp += bstr;
				}
				Log::Write( LogLevel_Detail, "hid report read=%d ID=%d len=%d %s", bytesRead, buffer[0], buffer[1], tmp.c_str() );
			}

			if( buffer[1] > 0 )
			{
				Put( &buffer[2], buffer[1] );
			}
		}
		if( readTimer.TimeRemaining() <= 0 )
		{
			// Hang a hid_read to acknowledge receipt. Seems the response is conveying
			// transaction status.
			// Wayne-Dalton input report data is structured as follows (best guess):
			// [0] 0x03      - input report ID
			// [1] 0x01      - ??? never changes
			// [2] 0xNN      - if 0x01, no feature reports waiting
			//                 if 0x02, feature report ID 0x05 is waiting to be retrieved
			// [3,4] 0xNNNN  - Number of ZWave messages?

			int hidApiResult = hid_read( m_hHidController, inputReport, INPUT_REPORT_LENGTH );
			//if( hidApiResult != 0 )
			//{
			//	string tmp = "";
			//	for( int i = 0; i < INPUT_REPORT_LENGTH; i++ )
			//	{
			//		char bstr[16];
			//		snprintf(bstr, sizeof(bstr), "%02x ", inputReport[i] );
			//		tmp += bstr;
			//	}
			//	Log::Write( LogLevel_Detail, "hid read %d %s", hidApiResult, tmp.c_str() );
			//}

			if( hidApiResult == -1 )
			{
				const wchar_t* errString = hid_error(m_hHidController);
				Log::Write( LogLevel_Warning, "Error: HID port returned error reading input bytes: 0x%08hx, HIDAPI error string: %ls", hidApiResult, errString );
			}
			readTimer.SetTime( 100 );
		}
		m_thread->Sleep(10);
	}

HidPortError:
	Log::Write( LogLevel_Warning, "Error: HID port returned error reading rest of packet: 0x%08hx, HIDAPI error string:", bytesRead );
	Log::Write( LogLevel_Warning, "%ls", hid_error(m_hHidController));
}
开发者ID:FrozenCow,项目名称:node-openzwave,代码行数:80,代码来源:HidController.cpp


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