MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / Read

Method Read

cpp/src/platform/HidController.cpp:377–452  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Read data from the HID port -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

375// Read data from the HID port
376//-----------------------------------------------------------------------------
377void HidController::Read
378(
379)
380{
381 uint8 buffer[FEATURE_REPORT_LENGTH];
382 int bytesRead = 0;
383 uint8 inputReport[INPUT_REPORT_LENGTH];
384 TimeStamp readTimer;
385
386 while( true )
387 {
388 // Rx feature report buffer should contain
389 // [0] - 0x05 (rx feature report ID)
390 // [1] - length of rx data (or 0x00 and no further bytes if no rx data waiting)
391 // [2]... - rx data
392 // We poll this waiting for data.
393 bytesRead = GetFeatureReport(FEATURE_REPORT_LENGTH, 0x5, buffer);
394 CHECK_HIDAPI_RESULT(bytesRead, HidPortError);
395 if( bytesRead >= 2 )
396 {
397
398 if( buffer[1] > 0 )
399 {
400 string tmp = "";
401 for (int i = 0; i < buffer[1]; i++)
402 {
403 char bstr[16];
404 snprintf( bstr, sizeof(bstr), "0x%.2x ", buffer[2+i] );
405 tmp += bstr;
406 }
407 Log::Write( LogLevel_Detail, "hid report read=%d ID=%d len=%d %s", bytesRead, buffer[0], buffer[1], tmp.c_str() );
408 }
409
410 if( buffer[1] > 0 )
411 {
412 Put( &buffer[2], buffer[1] );
413 }
414 }
415 if( readTimer.TimeRemaining() <= 0 )
416 {
417 // Hang a hid_read to acknowledge receipt. Seems the response is conveying
418 // transaction status.
419 // Wayne-Dalton input report data is structured as follows (best guess):
420 // [0] 0x03 - input report ID
421 // [1] 0x01 - ??? never changes
422 // [2] 0xNN - if 0x01, no feature reports waiting
423 // if 0x02, feature report ID 0x05 is waiting to be retrieved
424 // [3,4] 0xNNNN - Number of ZWave messages?
425
426 int hidApiResult = hid_read( m_hHidController, inputReport, INPUT_REPORT_LENGTH );
427 //if( hidApiResult != 0 )
428 //{
429 // string tmp = "";
430 // for( int i = 0; i < INPUT_REPORT_LENGTH; i++ )
431 // {
432 // char bstr[16];
433 // snprintf(bstr, sizeof(bstr), "%02x ", inputReport[i] );
434 // tmp += bstr;

Callers

nothing calls this directly

Calls 7

WriteFunction · 0.85
hid_readFunction · 0.50
hid_errorFunction · 0.50
c_strMethod · 0.45
TimeRemainingMethod · 0.45
SetTimeMethod · 0.45
SleepMethod · 0.45

Tested by

no test coverage detected