mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-06 21:54:15 +01:00
OP GCS - sorry made a mess dealing with conflicts
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2916 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
0c2a563c34
commit
b8a5249246
@ -162,6 +162,7 @@ public:
|
|||||||
QString getserial(int num);
|
QString getserial(int num);
|
||||||
void mytest(int num);
|
void mytest(int num);
|
||||||
signals:
|
signals:
|
||||||
|
void deviceUnplugged(int);//just to make pips changes compile
|
||||||
/*!
|
/*!
|
||||||
A new device has been connected to the system.
|
A new device has been connected to the system.
|
||||||
|
|
||||||
@ -208,7 +209,7 @@ private:
|
|||||||
hid_t * get_hid(int num);
|
hid_t * get_hid(int num);
|
||||||
void free_all_hid(void);
|
void free_all_hid(void);
|
||||||
void hid_close(hid_t *hid);
|
void hid_close(hid_t *hid);
|
||||||
void print_win32_err(void);
|
void print_win32_err(DWORD err);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -67,592 +67,424 @@ pjrc_rawhid::~pjrc_rawhid()
|
|||||||
// open - open 1 or more devices
|
// open - open 1 or more devices
|
||||||
//
|
//
|
||||||
// Inputs:
|
// Inputs:
|
||||||
// max = maximum number of devices to open
|
// max = maximum number of devices to open
|
||||||
// vid = Vendor ID, or -1 if any
|
// vid = Vendor ID, or -1 if any
|
||||||
// pid = Product ID, or -1 if any
|
// pid = Product ID, or -1 if any
|
||||||
// usage_page = top level usage page, or -1 if any
|
// usage_page = top level usage page, or -1 if any
|
||||||
// usage = top level usage number, or -1 if any
|
// usage = top level usage number, or -1 if any
|
||||||
// Output:
|
// Output:
|
||||||
// actual number of devices opened
|
// actual number of devices opened
|
||||||
//
|
//
|
||||||
int pjrc_rawhid::open(int max, int vid, int pid, int usage_page, int usage)
|
int pjrc_rawhid::open(int max, int vid, int pid, int usage_page, int usage)
|
||||||
{
|
{
|
||||||
GUID guid;
|
GUID guid;
|
||||||
HDEVINFO info;
|
HDEVINFO info;
|
||||||
DWORD index=0, reqd_size;
|
DWORD index=0, reqd_size;
|
||||||
SP_DEVICE_INTERFACE_DATA iface;
|
SP_DEVICE_INTERFACE_DATA iface;
|
||||||
SP_DEVICE_INTERFACE_DETAIL_DATA *details;
|
SP_DEVICE_INTERFACE_DETAIL_DATA *details;
|
||||||
HIDD_ATTRIBUTES attrib;
|
HIDD_ATTRIBUTES attrib;
|
||||||
PHIDP_PREPARSED_DATA hid_data;
|
PHIDP_PREPARSED_DATA hid_data;
|
||||||
HIDP_CAPS capabilities;
|
HIDP_CAPS capabilities;
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
hid_t *hid;
|
hid_t *hid;
|
||||||
|
|
||||||
int count=0;
|
int count=0;
|
||||||
|
|
||||||
if (first_hid) free_all_hid();
|
if (first_hid) free_all_hid();
|
||||||
|
|
||||||
if (max < 1) return 0;
|
if (max < 1) return 0;
|
||||||
|
|
||||||
if (!rx_event)
|
if (!rx_event)
|
||||||
{
|
{
|
||||||
rx_event = CreateEvent(NULL, TRUE, TRUE, NULL);
|
rx_event = CreateEvent(NULL, TRUE, TRUE, NULL);
|
||||||
tx_event = CreateEvent(NULL, TRUE, TRUE, NULL);
|
tx_event = CreateEvent(NULL, TRUE, TRUE, NULL);
|
||||||
InitializeCriticalSection(&rx_mutex);
|
InitializeCriticalSection(&rx_mutex);
|
||||||
InitializeCriticalSection(&tx_mutex);
|
InitializeCriticalSection(&tx_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
HidD_GetHidGuid(&guid);
|
HidD_GetHidGuid(&guid);
|
||||||
|
|
||||||
info = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
|
info = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
|
||||||
if (info == INVALID_HANDLE_VALUE) return 0;
|
if (info == INVALID_HANDLE_VALUE) return 0;
|
||||||
|
|
||||||
for (index=0; 1 ;index++)
|
for (index=0; 1 ;index++)
|
||||||
{
|
|
||||||
iface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
|
|
||||||
ret = SetupDiEnumDeviceInterfaces(info, NULL, &guid, index, &iface);
|
|
||||||
if (!ret) return count;
|
|
||||||
|
|
||||||
SetupDiGetInterfaceDeviceDetail(info, &iface, NULL, 0, &reqd_size, NULL);
|
|
||||||
details = (SP_DEVICE_INTERFACE_DETAIL_DATA *)malloc(reqd_size);
|
|
||||||
if (details == NULL) continue;
|
|
||||||
|
|
||||||
memset(details, 0, reqd_size);
|
|
||||||
details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
|
||||||
ret = SetupDiGetDeviceInterfaceDetail(info, &iface, details, reqd_size, NULL, NULL);
|
|
||||||
if (!ret)
|
|
||||||
{
|
{
|
||||||
free(details);
|
iface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
|
||||||
continue;
|
ret = SetupDiEnumDeviceInterfaces(info, NULL, &guid, index, &iface);
|
||||||
}
|
if (!ret) return count;
|
||||||
|
|
||||||
|
SetupDiGetInterfaceDeviceDetail(info, &iface, NULL, 0, &reqd_size, NULL);
|
||||||
|
details = (SP_DEVICE_INTERFACE_DETAIL_DATA *)malloc(reqd_size);
|
||||||
|
if (details == NULL) continue;
|
||||||
|
|
||||||
|
memset(details, 0, reqd_size);
|
||||||
|
details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
||||||
|
ret = SetupDiGetDeviceInterfaceDetail(info, &iface, details, reqd_size, NULL, NULL);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
free(details);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
h = CreateFile(details->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||||
|
if (h == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
DWORD err = GetLastError();
|
||||||
|
|
||||||
|
// I get ERROR_ACCESS_DENIED with most/all my input devices (mice/trackballs/tablet).
|
||||||
|
// Let's not log it :)
|
||||||
|
if (err == ERROR_ACCESS_DENIED)
|
||||||
|
{
|
||||||
|
free(details);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// qDebug wipes the GetLastError() it seems, so do that after print_win32_err().
|
||||||
|
print_win32_err(err);
|
||||||
|
qDebug() << "Problem opening handle, path: " << QString().fromWCharArray(details->DevicePath);
|
||||||
|
|
||||||
|
free(details);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
<<<<<<< .mine
|
|
||||||
h = CreateFile(details->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
|
||||||
if (h == INVALID_HANDLE_VALUE)
|
|
||||||
{
|
|
||||||
// I get ERROR_ACCESS_DENIED with most/all my input devices (mice/trackballs/tablet).
|
|
||||||
// Let's not log it :)
|
|
||||||
if (GetLastError() == ERROR_ACCESS_DENIED)
|
|
||||||
{
|
|
||||||
free(details);
|
free(details);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
=======
|
|
||||||
h = CreateFile(details->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
|
||||||
if (h == INVALID_HANDLE_VALUE)
|
|
||||||
{
|
|
||||||
DWORD err = GetLastError();
|
|
||||||
|
|
||||||
// I get ERROR_ACCESS_DENIED with most/all my input devices (mice/trackballs/tablet).
|
attrib.Size = sizeof(HIDD_ATTRIBUTES);
|
||||||
// Let's not log it :)
|
ret = HidD_GetAttributes(h, &attrib);
|
||||||
if (err == ERROR_ACCESS_DENIED)
|
//printf("vid: %4x\n", attrib.VendorID);
|
||||||
{
|
if (!ret || (vid > 0 && attrib.VendorID != vid) ||
|
||||||
free(details);
|
(pid > 0 && attrib.ProductID != pid) ||
|
||||||
continue;
|
!HidD_GetPreparsedData(h, &hid_data))
|
||||||
}
|
{
|
||||||
>>>>>>> .r2914
|
CloseHandle(h);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
<<<<<<< .mine
|
if (!HidP_GetCaps(hid_data, &capabilities) ||
|
||||||
// qDebug wipes the GetLastError() it seems, so do that after print_win32_err().
|
(usage_page > 0 && capabilities.UsagePage != usage_page) ||
|
||||||
print_win32_err();
|
(usage > 0 && capabilities.Usage != usage))
|
||||||
qDebug() << "Problem opening handle, path: " << QString().fromWCharArray(details->DevicePath);
|
{
|
||||||
=======
|
HidD_FreePreparsedData(hid_data);
|
||||||
// qDebug wipes the GetLastError() it seems, so do that after print_win32_err().
|
CloseHandle(h);
|
||||||
print_win32_err(err);
|
continue;
|
||||||
qDebug() << "Problem opening handle, path: " << QString().fromWCharArray(details->DevicePath);
|
}
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
free(details);
|
HidD_FreePreparsedData(hid_data);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(details);
|
hid = (struct hid_struct *)malloc(sizeof(struct hid_struct));
|
||||||
|
if (!hid)
|
||||||
|
{
|
||||||
|
CloseHandle(h);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
attrib.Size = sizeof(HIDD_ATTRIBUTES);
|
// COMMTIMEOUTS CommTimeouts;
|
||||||
ret = HidD_GetAttributes(h, &attrib);
|
// CommTimeouts.ReadIntervalTimeout = 100; // 100ms
|
||||||
//printf("vid: %4x\n", attrib.VendorID);
|
// CommTimeouts.ReadTotalTimeoutConstant = 5; // ms
|
||||||
if (!ret || (vid > 0 && attrib.VendorID != vid) ||
|
// CommTimeouts.ReadTotalTimeoutMultiplier = 1; //
|
||||||
(pid > 0 && attrib.ProductID != pid) ||
|
// CommTimeouts.WriteTotalTimeoutConstant = 5; // ms
|
||||||
!HidD_GetPreparsedData(h, &hid_data))
|
// CommTimeouts.WriteTotalTimeoutMultiplier = 1; //
|
||||||
{
|
// if (!SetCommTimeouts(h, &CommTimeouts))
|
||||||
CloseHandle(h);
|
// {
|
||||||
continue;
|
//// DWORD err = GetLastError();
|
||||||
}
|
|
||||||
|
|
||||||
if (!HidP_GetCaps(hid_data, &capabilities) ||
|
|
||||||
(usage_page > 0 && capabilities.UsagePage != usage_page) ||
|
|
||||||
(usage > 0 && capabilities.Usage != usage))
|
|
||||||
{
|
|
||||||
HidD_FreePreparsedData(hid_data);
|
|
||||||
CloseHandle(h);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
HidD_FreePreparsedData(hid_data);
|
|
||||||
|
|
||||||
hid = (struct hid_struct *)malloc(sizeof(struct hid_struct));
|
|
||||||
if (!hid)
|
|
||||||
{
|
|
||||||
CloseHandle(h);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
<<<<<<< .mine
|
|
||||||
qDebug("Open: Handle address: %li for num: %i", (long int) h, count);
|
|
||||||
=======
|
|
||||||
// COMMTIMEOUTS CommTimeouts;
|
|
||||||
// CommTimeouts.ReadIntervalTimeout = 100; // 100ms
|
|
||||||
// CommTimeouts.ReadTotalTimeoutConstant = 5; // ms
|
|
||||||
// CommTimeouts.ReadTotalTimeoutMultiplier = 1; //
|
|
||||||
// CommTimeouts.WriteTotalTimeoutConstant = 5; // ms
|
|
||||||
// CommTimeouts.WriteTotalTimeoutMultiplier = 1; //
|
|
||||||
// if (!SetCommTimeouts(h, &CommTimeouts))
|
|
||||||
// {
|
|
||||||
//// DWORD err = GetLastError();
|
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
qDebug("Open: Handle address: %li for num: %i", (long int) h, count);
|
qDebug("Open: Handle address: %li for num: %i", (long int) h, count);
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
<<<<<<< .mine
|
hid->handle = h;
|
||||||
hid->handle = h;
|
add_hid(hid);
|
||||||
hid->open = 1;
|
|
||||||
add_hid(hid);
|
|
||||||
=======
|
|
||||||
hid->handle = h;
|
|
||||||
add_hid(hid);
|
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
if (count >= max) return count;
|
if (count >= max) return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// recveive - receive a packet
|
// recveive - receive a packet
|
||||||
// Inputs:
|
// Inputs:
|
||||||
// num = device to receive from (zero based)
|
// num = device to receive from (zero based)
|
||||||
// buf = buffer to receive packet
|
// buf = buffer to receive packet
|
||||||
// len = buffer's size
|
// len = buffer's size
|
||||||
// timeout = time to wait, in milliseconds
|
// timeout = time to wait, in milliseconds
|
||||||
// Output:
|
// Output:
|
||||||
// number of bytes received, or -1 on error
|
// number of bytes received, or -1 on error
|
||||||
//
|
//
|
||||||
int pjrc_rawhid::receive(int num, void *buf, int len, int timeout)
|
int pjrc_rawhid::receive(int num, void *buf, int len, int timeout)
|
||||||
{
|
{
|
||||||
OVERLAPPED ov;
|
OVERLAPPED ov;
|
||||||
DWORD n;
|
DWORD n;
|
||||||
|
|
||||||
<<<<<<< .mine
|
hid_t *hid = get_hid(num);
|
||||||
hid_t *hid = get_hid(num);
|
if (!hid)
|
||||||
if (!hid || !hid->open) return -1;
|
return -1;
|
||||||
=======
|
if (!hid->handle)
|
||||||
hid_t *hid = get_hid(num);
|
return -1;
|
||||||
if (!hid)
|
|
||||||
return -1;
|
|
||||||
if (!hid->handle)
|
|
||||||
return -1;
|
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
EnterCriticalSection(&rx_mutex);
|
EnterCriticalSection(&rx_mutex);
|
||||||
|
|
||||||
ResetEvent(&rx_event);
|
ResetEvent(&rx_event);
|
||||||
|
|
||||||
memset(&ov, 0, sizeof(ov));
|
memset(&ov, 0, sizeof(ov));
|
||||||
ov.hEvent = rx_event;
|
ov.hEvent = rx_event;
|
||||||
|
|
||||||
<<<<<<< .mine
|
if (!ReadFile(hid->handle, buf, len, NULL, &ov))
|
||||||
if (!ReadFile(hid->handle, buf, len, NULL, &ov))
|
|
||||||
{
|
|
||||||
if (GetLastError() != ERROR_IO_PENDING)
|
|
||||||
{
|
{
|
||||||
print_win32_err();
|
DWORD err = GetLastError();
|
||||||
LeaveCriticalSection(&rx_mutex);
|
|
||||||
return -1;
|
if (err == ERROR_DEVICE_NOT_CONNECTED)
|
||||||
|
{ // the device has been unplugged
|
||||||
|
print_win32_err(err);
|
||||||
|
hid_close(hid);
|
||||||
|
LeaveCriticalSection(&rx_mutex);
|
||||||
|
emit deviceUnplugged(num);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err != ERROR_IO_PENDING)
|
||||||
|
{
|
||||||
|
print_win32_err(err);
|
||||||
|
LeaveCriticalSection(&rx_mutex);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD r = WaitForSingleObject(rx_event, timeout);
|
||||||
|
if (r == WAIT_TIMEOUT)
|
||||||
|
{
|
||||||
|
CancelIo(hid->handle);
|
||||||
|
LeaveCriticalSection(&rx_mutex);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (r != WAIT_OBJECT_0)
|
||||||
|
{
|
||||||
|
DWORD err = GetLastError();
|
||||||
|
print_win32_err(err);
|
||||||
|
LeaveCriticalSection(&rx_mutex);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
=======
|
|
||||||
if (!ReadFile(hid->handle, buf, len, NULL, &ov))
|
|
||||||
{
|
|
||||||
DWORD err = GetLastError();
|
|
||||||
|
|
||||||
if (err == ERROR_DEVICE_NOT_CONNECTED)
|
if (!GetOverlappedResult(hid->handle, &ov, &n, FALSE))
|
||||||
{ // the device has been unplugged
|
|
||||||
print_win32_err(err);
|
|
||||||
hid_close(hid);
|
|
||||||
LeaveCriticalSection(&rx_mutex);
|
|
||||||
emit deviceUnplugged(num);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err != ERROR_IO_PENDING)
|
|
||||||
{
|
|
||||||
print_win32_err(err);
|
|
||||||
LeaveCriticalSection(&rx_mutex);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
<<<<<<< .mine
|
|
||||||
DWORD r = WaitForSingleObject(rx_event, timeout);
|
|
||||||
if (r == WAIT_TIMEOUT)
|
|
||||||
{
|
{
|
||||||
CancelIo(hid->handle);
|
DWORD err = GetLastError();
|
||||||
LeaveCriticalSection(&rx_mutex);
|
print_win32_err(err);
|
||||||
return 0;
|
|
||||||
}
|
if (err == ERROR_DEVICE_NOT_CONNECTED)
|
||||||
if (r != WAIT_OBJECT_0)
|
{ // the device has been unplugged
|
||||||
{
|
hid_close(hid);
|
||||||
print_win32_err();
|
LeaveCriticalSection(&rx_mutex);
|
||||||
LeaveCriticalSection(&rx_mutex);
|
emit deviceUnplugged(num);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
=======
|
LeaveCriticalSection(&rx_mutex);
|
||||||
DWORD r = WaitForSingleObject(rx_event, timeout);
|
return -1;
|
||||||
if (r == WAIT_TIMEOUT)
|
}
|
||||||
{
|
|
||||||
CancelIo(hid->handle);
|
|
||||||
LeaveCriticalSection(&rx_mutex);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (r != WAIT_OBJECT_0)
|
|
||||||
{
|
|
||||||
DWORD err = GetLastError();
|
|
||||||
print_win32_err(err);
|
|
||||||
LeaveCriticalSection(&rx_mutex);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
<<<<<<< .mine
|
|
||||||
if (!GetOverlappedResult(hid->handle, &ov, &n, FALSE))
|
|
||||||
{
|
|
||||||
print_win32_err();
|
|
||||||
LeaveCriticalSection(&rx_mutex);
|
LeaveCriticalSection(&rx_mutex);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
=======
|
|
||||||
if (!GetOverlappedResult(hid->handle, &ov, &n, FALSE))
|
|
||||||
{
|
|
||||||
DWORD err = GetLastError();
|
|
||||||
print_win32_err(err);
|
|
||||||
|
|
||||||
if (err == ERROR_DEVICE_NOT_CONNECTED)
|
if (n <= 0) return -1;
|
||||||
{ // the device has been unplugged
|
|
||||||
hid_close(hid);
|
|
||||||
LeaveCriticalSection(&rx_mutex);
|
|
||||||
emit deviceUnplugged(num);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
LeaveCriticalSection(&rx_mutex);
|
// qDebug("Received %i bytes, first %x, second %x", len, *((char *) buf),*((char *)buf + 1));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
LeaveCriticalSection(&rx_mutex);
|
if ((int)n > len) n = len;
|
||||||
|
return n;
|
||||||
if (n <= 0) return -1;
|
|
||||||
|
|
||||||
// qDebug("Received %i bytes, first %x, second %x", len, *((char *) buf),*((char *)buf + 1));
|
|
||||||
|
|
||||||
if ((int)n > len) n = len;
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send - send a packet
|
// send - send a packet
|
||||||
// Inputs:
|
// Inputs:
|
||||||
// num = device to transmit to (zero based)
|
// num = device to transmit to (zero based)
|
||||||
// buf = buffer containing packet to send
|
// buf = buffer containing packet to send
|
||||||
// len = number of bytes to transmit
|
// len = number of bytes to transmit
|
||||||
// timeout = time to wait, in milliseconds
|
// timeout = time to wait, in milliseconds
|
||||||
// Output:
|
// Output:
|
||||||
// number of bytes sent, or -1 on error
|
// number of bytes sent, or -1 on error
|
||||||
//
|
//
|
||||||
int pjrc_rawhid::send(int num, void *buf, int len, int timeout)
|
int pjrc_rawhid::send(int num, void *buf, int len, int timeout)
|
||||||
{
|
{
|
||||||
OVERLAPPED ov;
|
OVERLAPPED ov;
|
||||||
DWORD n, r;
|
DWORD n, r;
|
||||||
|
|
||||||
<<<<<<< .mine
|
hid_t *hid = get_hid(num);
|
||||||
hid_t *hid = get_hid(num);
|
if (!hid)
|
||||||
if (!hid || !hid->open) return -1;
|
|
||||||
=======
|
|
||||||
hid_t *hid = get_hid(num);
|
|
||||||
if (!hid)
|
|
||||||
return -1;
|
|
||||||
if (!hid->handle)
|
|
||||||
return -1;
|
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
// qDebug("Send: Handle address: %li for num: %i", (long int) hid->handle, num);
|
|
||||||
|
|
||||||
EnterCriticalSection(&tx_mutex);
|
|
||||||
|
|
||||||
ResetEvent(&tx_event);
|
|
||||||
|
|
||||||
memset(&ov, 0, sizeof(ov));
|
|
||||||
ov.hEvent = tx_event;
|
|
||||||
|
|
||||||
// qDebug("Trying to write %u bytes. First %x second %x",len, *((char *) buf), *((char *)buf + 1));
|
|
||||||
|
|
||||||
<<<<<<< .mine
|
|
||||||
if (!WriteFile(hid->handle, buf, len, NULL, &ov))
|
|
||||||
{
|
|
||||||
DWORD err = GetLastError();
|
|
||||||
if ( err == ERROR_SUCCESS || err == ERROR_IO_PENDING )
|
|
||||||
{
|
|
||||||
// qDebug("Waiting for write to finish");
|
|
||||||
r = WaitForSingleObject(tx_event, timeout);
|
|
||||||
if (r == WAIT_TIMEOUT)
|
|
||||||
{
|
|
||||||
CancelIo(hid->handle);
|
|
||||||
LeaveCriticalSection(&tx_mutex);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (r != WAIT_OBJECT_0)
|
|
||||||
{
|
|
||||||
print_win32_err();
|
|
||||||
LeaveCriticalSection(&tx_mutex);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
if (!hid->handle)
|
||||||
}
|
return -1;
|
||||||
else
|
|
||||||
|
// qDebug("Send: Handle address: %li for num: %i", (long int) hid->handle, num);
|
||||||
|
|
||||||
|
EnterCriticalSection(&tx_mutex);
|
||||||
|
|
||||||
|
ResetEvent(&tx_event);
|
||||||
|
|
||||||
|
memset(&ov, 0, sizeof(ov));
|
||||||
|
ov.hEvent = tx_event;
|
||||||
|
|
||||||
|
// qDebug("Trying to write %u bytes. First %x second %x",len, *((char *) buf), *((char *)buf + 1));
|
||||||
|
|
||||||
|
if (!WriteFile(hid->handle, buf, len, NULL, &ov))
|
||||||
{
|
{
|
||||||
// qDebug("Error writing to file");
|
DWORD err = GetLastError();
|
||||||
print_win32_err();
|
|
||||||
LeaveCriticalSection(&tx_mutex);
|
if (err == ERROR_DEVICE_NOT_CONNECTED)
|
||||||
return -1;
|
{ // the device has been unplugged
|
||||||
|
hid_close(hid);
|
||||||
|
LeaveCriticalSection(&tx_mutex);
|
||||||
|
emit deviceUnplugged(num);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err == ERROR_SUCCESS || err == ERROR_IO_PENDING)
|
||||||
|
{
|
||||||
|
// qDebug("Waiting for write to finish");
|
||||||
|
r = WaitForSingleObject(tx_event, timeout);
|
||||||
|
if (r == WAIT_TIMEOUT)
|
||||||
|
{
|
||||||
|
CancelIo(hid->handle);
|
||||||
|
LeaveCriticalSection(&tx_mutex);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (r != WAIT_OBJECT_0)
|
||||||
|
{
|
||||||
|
DWORD err = GetLastError();
|
||||||
|
print_win32_err(err);
|
||||||
|
LeaveCriticalSection(&tx_mutex);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// qDebug("Error writing to file");
|
||||||
|
print_win32_err(err);
|
||||||
|
LeaveCriticalSection(&tx_mutex);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
=======
|
|
||||||
if (!WriteFile(hid->handle, buf, len, NULL, &ov))
|
|
||||||
{
|
|
||||||
DWORD err = GetLastError();
|
|
||||||
|
|
||||||
if (err == ERROR_DEVICE_NOT_CONNECTED)
|
if (!GetOverlappedResult(hid->handle, &ov, &n, FALSE))
|
||||||
{ // the device has been unplugged
|
{
|
||||||
hid_close(hid);
|
DWORD err = GetLastError();
|
||||||
LeaveCriticalSection(&tx_mutex);
|
|
||||||
emit deviceUnplugged(num);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err == ERROR_SUCCESS || err == ERROR_IO_PENDING)
|
qDebug("Problem getting overlapped result");
|
||||||
{
|
print_win32_err(err);
|
||||||
// qDebug("Waiting for write to finish");
|
|
||||||
r = WaitForSingleObject(tx_event, timeout);
|
|
||||||
if (r == WAIT_TIMEOUT)
|
|
||||||
{
|
|
||||||
CancelIo(hid->handle);
|
|
||||||
LeaveCriticalSection(&tx_mutex);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (r != WAIT_OBJECT_0)
|
|
||||||
{
|
|
||||||
DWORD err = GetLastError();
|
|
||||||
print_win32_err(err);
|
|
||||||
LeaveCriticalSection(&tx_mutex);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// qDebug("Error writing to file");
|
|
||||||
print_win32_err(err);
|
|
||||||
LeaveCriticalSection(&tx_mutex);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
<<<<<<< .mine
|
if (err == ERROR_DEVICE_NOT_CONNECTED)
|
||||||
if (!GetOverlappedResult(hid->handle, &ov, &n, FALSE))
|
{ // the device has been unplugged
|
||||||
{
|
hid_close(hid);
|
||||||
qDebug("Problem getting overlapped result");
|
LeaveCriticalSection(&tx_mutex);
|
||||||
print_win32_err();
|
emit deviceUnplugged(num);
|
||||||
}
|
return -1;
|
||||||
=======
|
}
|
||||||
if (!GetOverlappedResult(hid->handle, &ov, &n, FALSE))
|
}
|
||||||
{
|
|
||||||
DWORD err = GetLastError();
|
|
||||||
|
|
||||||
qDebug("Problem getting overlapped result");
|
LeaveCriticalSection(&tx_mutex);
|
||||||
print_win32_err(err);
|
|
||||||
|
|
||||||
if (err == ERROR_DEVICE_NOT_CONNECTED)
|
if (n <= 0) return -1;
|
||||||
{ // the device has been unplugged
|
return n;
|
||||||
hid_close(hid);
|
|
||||||
LeaveCriticalSection(&tx_mutex);
|
|
||||||
emit deviceUnplugged(num);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
LeaveCriticalSection(&tx_mutex);
|
|
||||||
|
|
||||||
if (n <= 0) return -1;
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString pjrc_rawhid::getserial(int num)
|
QString pjrc_rawhid::getserial(int num)
|
||||||
{
|
{
|
||||||
<<<<<<< .mine
|
hid_t *hid = get_hid(num);
|
||||||
hid_t *hid = get_hid(num);
|
if (!hid)
|
||||||
if (!hid || !hid->open)
|
return "";
|
||||||
return "";
|
if (!hid->handle)
|
||||||
=======
|
return "";
|
||||||
hid_t *hid = get_hid(num);
|
|
||||||
if (!hid)
|
|
||||||
return "";
|
|
||||||
>>>>>>> .r2914
|
|
||||||
if (!hid->handle)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
<<<<<<< .mine
|
// Should we do some "critical section" stuff here??
|
||||||
// Should we do some "critical section" stuff here??
|
char temp[126];
|
||||||
char temp[126];
|
if (!HidD_GetSerialNumberString(hid->handle, temp, sizeof(temp)))
|
||||||
if (!HidD_GetSerialNumberString(hid->handle, temp, sizeof(temp)))
|
{
|
||||||
{
|
DWORD err = GetLastError();
|
||||||
print_win32_err();
|
print_win32_err(err);
|
||||||
return QString("Error");
|
|
||||||
}
|
|
||||||
=======
|
|
||||||
// Should we do some "critical section" stuff here??
|
|
||||||
char temp[126];
|
|
||||||
if (!HidD_GetSerialNumberString(hid->handle, temp, sizeof(temp)))
|
|
||||||
{
|
|
||||||
DWORD err = GetLastError();
|
|
||||||
print_win32_err(err);
|
|
||||||
|
|
||||||
if (err == ERROR_DEVICE_NOT_CONNECTED)
|
if (err == ERROR_DEVICE_NOT_CONNECTED)
|
||||||
{ // the device has been unplugged
|
{ // the device has been unplugged
|
||||||
hid_close(hid);
|
hid_close(hid);
|
||||||
emit deviceUnplugged(num);
|
emit deviceUnplugged(num);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString("Error");
|
return QString("Error");
|
||||||
}
|
}
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
return QString().fromUtf16((ushort*)temp,-1);
|
return QString().fromUtf16((ushort*)temp,-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// close - close a device
|
// close - close a device
|
||||||
//
|
//
|
||||||
// Inputs:
|
// Inputs:
|
||||||
// num = device to close (zero based)
|
// num = device to close (zero based)
|
||||||
// Output
|
// Output
|
||||||
// (nothing)
|
// (nothing)
|
||||||
//
|
//
|
||||||
void pjrc_rawhid::close(int num)
|
void pjrc_rawhid::close(int num)
|
||||||
{
|
{
|
||||||
<<<<<<< .mine
|
hid_close(get_hid(num));
|
||||||
hid_t *hid = get_hid(num);
|
|
||||||
if (hid && hid->open)
|
|
||||||
hid_close(hid);
|
|
||||||
=======
|
|
||||||
hid_close(get_hid(num));
|
|
||||||
>>>>>>> .r2914
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pjrc_rawhid::add_hid(hid_t *h)
|
void pjrc_rawhid::add_hid(hid_t *h)
|
||||||
{
|
{
|
||||||
if (!h) return;
|
if (!h) return;
|
||||||
|
|
||||||
<<<<<<< .mine
|
if (!first_hid || !last_hid)
|
||||||
if (!first_hid || !last_hid)
|
{
|
||||||
{
|
first_hid = last_hid = h;
|
||||||
first_hid = last_hid = h;
|
h->next = h->prev = NULL;
|
||||||
h->next = h->prev = NULL;
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
last_hid->next = h;
|
|
||||||
h->prev = last_hid;
|
|
||||||
h->next = NULL;
|
|
||||||
last_hid = h;
|
|
||||||
=======
|
|
||||||
if (!first_hid || !last_hid)
|
|
||||||
{
|
|
||||||
first_hid = last_hid = h;
|
|
||||||
h->next = h->prev = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_hid->next = h;
|
last_hid->next = h;
|
||||||
h->prev = last_hid;
|
h->prev = last_hid;
|
||||||
h->next = NULL;
|
h->next = NULL;
|
||||||
last_hid = h;
|
last_hid = h;
|
||||||
>>>>>>> .r2914
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hid_t * pjrc_rawhid::get_hid(int num)
|
hid_t * pjrc_rawhid::get_hid(int num)
|
||||||
{
|
{
|
||||||
hid_t *p;
|
hid_t *p;
|
||||||
for (p = first_hid; p && num > 0; p = p->next, num--) ;
|
for (p = first_hid; p && num > 0; p = p->next, num--) ;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pjrc_rawhid::free_all_hid(void)
|
void pjrc_rawhid::free_all_hid(void)
|
||||||
{
|
{
|
||||||
for (hid_t *p = first_hid; p; p = p->next)
|
for (hid_t *p = first_hid; p; p = p->next)
|
||||||
hid_close(p);
|
hid_close(p);
|
||||||
|
|
||||||
hid_t *p = first_hid;
|
hid_t *p = first_hid;
|
||||||
while (p)
|
while (p)
|
||||||
{
|
{
|
||||||
hid_t *q = p;
|
hid_t *q = p;
|
||||||
p = p->next;
|
p = p->next;
|
||||||
free(q);
|
free(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
first_hid = last_hid = NULL;
|
first_hid = last_hid = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pjrc_rawhid::hid_close(hid_t *hid)
|
void pjrc_rawhid::hid_close(hid_t *hid)
|
||||||
{
|
{
|
||||||
if (!hid) return;
|
if (!hid) return;
|
||||||
if (!hid->handle) return;
|
if (!hid->handle) return;
|
||||||
|
|
||||||
<<<<<<< .mine
|
|
||||||
if (hid->handle)
|
|
||||||
{
|
|
||||||
CloseHandle(hid->handle);
|
CloseHandle(hid->handle);
|
||||||
hid->handle = NULL;
|
hid->handle = NULL;
|
||||||
}
|
|
||||||
=======
|
|
||||||
CloseHandle(hid->handle);
|
|
||||||
hid->handle = NULL;
|
|
||||||
>>>>>>> .r2914
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pjrc_rawhid::print_win32_err(DWORD err)
|
void pjrc_rawhid::print_win32_err(DWORD err)
|
||||||
{
|
{
|
||||||
<<<<<<< .mine
|
char buf[256];
|
||||||
char buf[256];
|
char temp[256];
|
||||||
char temp[256];
|
|
||||||
DWORD err;
|
|
||||||
=======
|
|
||||||
char buf[256];
|
|
||||||
char temp[256];
|
|
||||||
>>>>>>> .r2914
|
|
||||||
|
|
||||||
<<<<<<< .mine
|
//FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, (WCHAR*)buf, sizeof(buf), NULL);
|
||||||
err = GetLastError();
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), (WCHAR*)buf, sizeof(buf), NULL);
|
||||||
|
WideCharToMultiByte( CP_ACP, 0, (WCHAR*)buf, sizeof(buf), temp, sizeof(temp), NULL, NULL );
|
||||||
=======
|
printf("err %ld: %s\n", err, temp);
|
||||||
>>>>>>> .r2914
|
|
||||||
//FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, (WCHAR*)buf, sizeof(buf), NULL);
|
|
||||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), (WCHAR*)buf, sizeof(buf), NULL);
|
|
||||||
WideCharToMultiByte( CP_ACP, 0, (WCHAR*)buf, sizeof(buf), temp, sizeof(temp), NULL, NULL );
|
|
||||||
printf("err %ld: %s\n", err, temp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// see http://msdn.microsoft.com/en-us/library/ms791134.aspx for list of GUID classes
|
// see http://msdn.microsoft.com/en-us/library/ms791134.aspx for list of GUID classes
|
||||||
#ifndef GUID_DEVCLASS_PORTS
|
#ifndef GUID_DEVCLASS_PORTS
|
||||||
DEFINE_GUID(GUID_DEVCLASS_PORTS, 0x4d1e55b2, 0xf16f, 0x11cf, 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30);
|
DEFINE_GUID(GUID_DEVCLASS_PORTS, 0x4d1e55b2, 0xf16f, 0x11cf, 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user