intel realsense usb列舉,讀寫資料解析

smilestone322發表於2017-09-25
0)intel realsense列舉裝置的呼叫堆疊如下:
   rs_create_context--->
   rs_context* rs_context_base::acquire_instance(),首先呼叫query_devices 獲取裝置資訊;呼叫的是windows的Media Foundation 列舉音訊,視訊捕獲裝置。


   通過獲取vid,判斷是不是intel的裝置,通過獲取pid判斷是intel的哪種型別的裝置,sr300,f200等等,然後呼叫相應的函式獲取rs_device
          switch(get_product_id(*device))
        {
            case R200_PRODUCT_ID:  rs_dev = rsimpl::make_r200_device(device); break;
            case LR200_PRODUCT_ID: rs_dev = rsimpl::make_lr200_device(device); break;
            case ZR300_PRODUCT_ID: rs_dev = rsimpl::make_zr300_device(device); break;
            case F200_PRODUCT_ID:  rs_dev = rsimpl::make_f200_device(device); break;
            case SR300_PRODUCT_ID: rs_dev = rsimpl::make_sr300_device(device); break;        //sr300裝置
        }

      

        將裝置加入到裝置列表:
        if (rs_dev && is_compatible(rs_dev))
        {
            devices.push_back(rs_dev);
        }


   其中:    std::shared_ptr<rs_device> make_sr300_device(std::shared_ptr<uvc::device> device)實現的功能如下:
     0.1)ivcam::claim_ivcam_interface(*device);----》claim_interface---》open_win_usb

     0.2)  auto calib = sr300::read_sr300_calibration(*device, mutex); //讀取標定的SR300的資料
  



1)windows下列舉裝置的程式碼在uvc-wmf.cpp 的open_win_usb函式如下:
   void open_win_usb(int vid, int pid, std::string unique_id, const guid & interface_guid, int interface_number)
引數說明:
    vid,pid:供應商ID(VID)和產品識別碼(PID);
    unique_id:
    interface_guid:介面的GUID
    interface_number:介面號

    列舉過程:
    1.1)首先呼叫SetupDiGetClassDevs函式,通過interface_guid列舉device_info;
    1.2)然後通過device_info和interface_guid, 列舉所有的裝置介面;
    1.3)Check if this is our device
       通過比較vid,pid,unique_id,interface_number,判斷是否是我們的裝置;
    1.4)通過DevicePath建立檔案控制程式碼;(DevicePath = 0x00000193760cadf4 L"\\\\?\\usb#vid_8086&pid_0aa5&mi_04#7&6d10b2e&0&0004#{175695cd-30d9-4f87-8be3-5a8270f49a31}")
    *file_handle = CreateFile(detail_data->DevicePath, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, nullptr);
                    if (*file_handle == INVALID_HANDLE_VALUE) throw std::runtime_error("CreateFile(...) failed");
    1.5)The WinUsb_Initialize function creates a WinUSB handle for the device specified by a file handle.
        WinUsb_Initialize
 WinUsb_Initialize call queries the underlying USB stack for various descriptors and allocates enough memory to store the retrieved descriptor data.
        WinUsb_Initialize first retrieves the device descriptor and then gets the associated configuration descriptor.
        From the configuration descriptor, the call derives the associated interface descriptors and stores them in an array.
        The interfaces in the array are identified by zero-based indexes. An index value of 0 indicates the first interface (the default interface),
        a value of 1 indicates the second associated interface, and so on.
        WinUsb_Initialize parses the default interface descriptor for the endpoint descriptors and caches information such as the associated pipes or state specific data.
        The handle received in the InterfaceHandle parameter is a pointer to the memory block allocated for the first interface in the array.



    1.6)開啟裝置後,進行讀寫,windows下讀寫的程式碼都在uvc_wmf.cpp裡面,linux下的讀寫程式碼在uvc-libuvc.cpp 和uvc-v4L2.cpp裡面。




相關文章