Line 1... |
Line 1... |
// $Id: RlinkPortCuff.cpp 584 2014-08-22 19:38:12Z mueller $
|
// $Id: RlinkPortCuff.cpp 632 2015-01-11 12:30:03Z mueller $
|
//
|
//
|
// Copyright 2012-2014 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
// Copyright 2012-2014 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
//
|
//
|
// This program is free software; you may redistribute and/or modify it under
|
// This program is free software; you may redistribute and/or modify it under
|
// the terms of the GNU General Public License as published by the Free
|
// the terms of the GNU General Public License as published by the Free
|
Line 22... |
Line 22... |
// 2012-12-26 465 1.0 Initial version
|
// 2012-12-26 465 1.0 Initial version
|
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
|
|
/*!
|
/*!
|
\file
|
\file
|
\version $Id: RlinkPortCuff.cpp 584 2014-08-22 19:38:12Z mueller $
|
\version $Id: RlinkPortCuff.cpp 632 2015-01-11 12:30:03Z mueller $
|
\brief Implemenation of RlinkPortCuff.
|
\brief Implemenation of RlinkPortCuff.
|
*/
|
*/
|
|
|
#include <errno.h>
|
#include <errno.h>
|
#include <unistd.h>
|
#include <unistd.h>
|
Line 66... |
Line 66... |
|
|
RlinkPortCuff::RlinkPortCuff()
|
RlinkPortCuff::RlinkPortCuff()
|
: RlinkPort(),
|
: RlinkPort(),
|
fFdReadDriver(-1),
|
fFdReadDriver(-1),
|
fFdWriteDriver(-1),
|
fFdWriteDriver(-1),
|
fpUsbContext(0),
|
fpUsbContext(nullptr),
|
fpUsbDevList(0),
|
fpUsbDevList(nullptr),
|
fUsbDevCount(0),
|
fUsbDevCount(0),
|
fpUsbDevHdl(0),
|
fpUsbDevHdl(nullptr),
|
fLoopState(kLoopStateStopped)
|
fLoopState(kLoopStateStopped)
|
{
|
{
|
fStats.Define(kStatNPollAddCB, "kStatNPollAddCB", "USB poll add cb");
|
fStats.Define(kStatNPollAddCB, "kStatNPollAddCB", "USB poll add cb");
|
fStats.Define(kStatNPollRemoveCB, "kStatNPollRemoveCB", "USB poll remove cb");
|
fStats.Define(kStatNPollRemoveCB, "kStatNPollRemoveCB", "USB poll remove cb");
|
fStats.Define(kStatNUSBWrite, "kStatNUSBWrite", "USB write done");
|
fStats.Define(kStatNUSBWrite, "kStatNUSBWrite", "USB write done");
|
Line 137... |
Line 137... |
return false;
|
return false;
|
}
|
}
|
}
|
}
|
|
|
// connect to USB device
|
// connect to USB device
|
libusb_device* mydev = 0;
|
libusb_device* mydev = nullptr;
|
// path syntax: /bus/dev
|
// path syntax: /bus/dev
|
if (fUrl.Path().length()==8 && fUrl.Path()[0]=='/' && fUrl.Path()[4]=='/') {
|
if (fUrl.Path().length()==8 && fUrl.Path()[0]=='/' && fUrl.Path()[4]=='/') {
|
string busnam = fUrl.Path().substr(1,3);
|
string busnam = fUrl.Path().substr(1,3);
|
string devnam = fUrl.Path().substr(5,3);
|
string devnam = fUrl.Path().substr(5,3);
|
unsigned long busnum;
|
unsigned long busnum;
|
Line 183... |
Line 183... |
"', not '/bus/dev' or 'vend:prod'");
|
"', not '/bus/dev' or 'vend:prod'");
|
Cleanup();
|
Cleanup();
|
return false;
|
return false;
|
}
|
}
|
|
|
if (mydev == 0) {
|
if (mydev == nullptr) {
|
emsg.Init("RlinkPortCuff::Open()",
|
emsg.Init("RlinkPortCuff::Open()",
|
string("no usb device '") + fUrl.Path() + "', found'");
|
string("no usb device '") + fUrl.Path() + "', found'");
|
Cleanup();
|
Cleanup();
|
return false;
|
return false;
|
}
|
}
|
|
|
irc = libusb_open(mydev, &fpUsbDevHdl);
|
irc = libusb_open(mydev, &fpUsbDevHdl);
|
if (irc) {
|
if (irc) {
|
fpUsbDevHdl = 0;
|
fpUsbDevHdl = nullptr;
|
emsg.Init("RlinkPortCuff::Open()",
|
emsg.Init("RlinkPortCuff::Open()",
|
string("opening usb device '") + fUrl.Path() + "', failed: " +
|
string("opening usb device '") + fUrl.Path() + "', failed: " +
|
string(USBErrorName(irc)));
|
string(USBErrorName(irc)));
|
Cleanup();
|
Cleanup();
|
return false;
|
return false;
|
Line 286... |
Line 286... |
// cleanup USB context
|
// cleanup USB context
|
if (fpUsbContext) {
|
if (fpUsbContext) {
|
if (fpUsbDevHdl) {
|
if (fpUsbDevHdl) {
|
libusb_release_interface(fpUsbDevHdl, 0);
|
libusb_release_interface(fpUsbDevHdl, 0);
|
libusb_close(fpUsbDevHdl);
|
libusb_close(fpUsbDevHdl);
|
fpUsbDevHdl = 0;
|
fpUsbDevHdl = nullptr;
|
}
|
}
|
if (fpUsbDevList) {
|
if (fpUsbDevList) {
|
libusb_free_device_list(fpUsbDevList, 1);
|
libusb_free_device_list(fpUsbDevList, 1);
|
fpUsbDevList = 0;
|
fpUsbDevList = nullptr;
|
}
|
}
|
libusb_set_pollfd_notifiers(fpUsbContext, nullptr, nullptr, nullptr);
|
libusb_set_pollfd_notifiers(fpUsbContext, nullptr, nullptr, nullptr);
|
libusb_exit(fpUsbContext);
|
libusb_exit(fpUsbContext);
|
fpUsbContext = 0;
|
fpUsbContext = nullptr;
|
}
|
}
|
|
|
fPollFds.clear();
|
fPollFds.clear();
|
|
|
return;
|
return;
|
Line 460... |
Line 460... |
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
libusb_transfer* RlinkPortCuff::NewWriteTransfer()
|
libusb_transfer* RlinkPortCuff::NewWriteTransfer()
|
{
|
{
|
libusb_transfer* t = 0;
|
libusb_transfer* t = nullptr;
|
if (!fWriteQueueFree.empty()) {
|
if (!fWriteQueueFree.empty()) {
|
t = fWriteQueueFree.front();
|
t = fWriteQueueFree.front();
|
fWriteQueueFree.pop_front();
|
fWriteQueueFree.pop_front();
|
} else {
|
} else {
|
t = libusb_alloc_transfer(0);
|
t = libusb_alloc_transfer(0);
|
Line 529... |
Line 529... |
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
void RlinkPortCuff::CheckUSBTransfer(const char* meth, libusb_transfer *t)
|
void RlinkPortCuff::CheckUSBTransfer(const char* meth, libusb_transfer *t)
|
{
|
{
|
const char* etext = 0;
|
const char* etext = nullptr;
|
|
|
if (t->status == LIBUSB_TRANSFER_ERROR) etext = "ERROR";
|
if (t->status == LIBUSB_TRANSFER_ERROR) etext = "ERROR";
|
if (t->status == LIBUSB_TRANSFER_STALL) etext = "STALL";
|
if (t->status == LIBUSB_TRANSFER_STALL) etext = "STALL";
|
if (t->status == LIBUSB_TRANSFER_NO_DEVICE) etext = "NO_DEVICE";
|
if (t->status == LIBUSB_TRANSFER_NO_DEVICE) etext = "NO_DEVICE";
|
if (t->status == LIBUSB_TRANSFER_OVERFLOW) etext = "OVERFLOW";
|
if (t->status == LIBUSB_TRANSFER_OVERFLOW) etext = "OVERFLOW";
|