summaryrefslogtreecommitdiff
path: root/CDAL/LibusbDevice_win.h
blob: 8ee484e438f199b79fffa0a7d460ed321210d1ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * LibusbDevice_win.h
 *
 * Copyright (C) ST-Ericsson SA 2011
 * Authors: Srimanta Panda <srimanta.panda@stericsson.com>,
 *          Ola Borgelin <ola.borgelin@stericsson.com>,
 *          Karin Hedlund <karin.hedlund@stericsson.com>,
 *          Markus Andersson <markus.m.andersson@stericsson.com> for ST-Ericsson.
 * License terms: 3-clause BSD license
 *
 */

#pragma once
#ifdef _WIN32
#include <usb.h>
#else
#include <libusb.h>
#endif
#include "CommDevice.h"

// Timeout error code for usb transfer
#define USB_TIMEOUT_ERROR -116

class LibusbDevice : public CommDevice
{
public:
    LibusbDevice(struct usb_device* device);
    ~LibusbDevice();

    int read(void* buffer, size_t size);
    int write(void* buffer, size_t size);

    int getVendorId();
    struct usb_device* getPort();

    unsigned long getPhysicalAddress() {
        return 0;
    }
private:
    struct usb_device* device_;
    struct  usb_dev_handle* handle_;
    int interfaceNumber_;
    int outEndpoint_;
    int inEndpoint_;
    bool opened_;
    
    static const int READ_BUFFER_SIZE = 4096;
    char readBuffer_[READ_BUFFER_SIZE];
    char* readBufferHead_;
    size_t readBufferLength_;
};