20.10.2013 - Modified PIObject - virtual debugName() for macro piCoutObj, improved timer measurements and timers on Windows

This commit is contained in:
peri4
2013-10-20 17:41:55 +04:00
parent 0f1b528ac6
commit ec5530053a
32 changed files with 2196 additions and 1331 deletions

View File

@@ -1,4 +1,5 @@
#include "piusb.h"
#include "piconfig.h"
#ifdef PIP_USB
# ifdef WINDOWS
@@ -68,7 +69,7 @@ bool PIUSB::setConfiguration(uchar value) {
piForeachC (Configuration & c, desc_.configurations)
if (c.value_to_select == value) {found = true; conf_ = c; break;}
if (!found) {
piCoutObj << "[PIUSB] Can`t find configuration with \"value_to_select\" =" << value;
piCoutObj << "Can`t find configuration with \"value_to_select\" =" << value;
return false;
}
if (interface_claimed >= 0)
@@ -88,14 +89,14 @@ bool PIUSB::setInterface(uchar value) {
piForeachC (Interface & i, conf_.interfaces)
if (i.value_to_select == value) {found = true; iface_ = i; break;}
if (!found) {
piCoutObj << "[PIUSB] Can`t find interface with \"value_to_select\" =" << value;
piCoutObj << "Can`t find interface with \"value_to_select\" =" << value;
return false;
}
if (interface_claimed >= 0)
usb_release_interface(hdev, interface_claimed);
interface_claimed = -1;
if (usb_claim_interface(hdev, iface_.value_to_select) < 0) {
piCoutObj << "[PIUSB] Error: Cant`t claim interface!";
piCoutObj << "Error: Cant`t claim interface!";
return false;
}
eps.clear();
@@ -115,6 +116,33 @@ bool PIUSB::setInterface(uchar value) {
}
bool PIUSB::configureDevice(const void * e_main, const void * e_parent) {
#ifdef PIP_USB
PIConfig::Entry * em = (PIConfig::Entry * )e_main;
PIConfig::Entry * ep = (PIConfig::Entry * )e_parent;
PIString vp = readDeviceSetting<PIString>("device", "", em, ep);
ushort v, p;
if (vp.isEmpty()) {
v = readDeviceSetting<ushort>("vid", vendorID(), em, ep);
p = readDeviceSetting<ushort>("pid", productID(), em, ep);
} else {
v = vp.left(vp.find(":")).toInt(16);
p = vp.right(vp.length() - vp.find(":") - 1).toInt(16);
}
setVendorID(v);
setProductID(p);
setDeviceNumber(readDeviceSetting<int>("deviceNumber", deviceNumber(), em, ep));
setConfiguration(readDeviceSetting<ushort>("configuration", currentConfiguration().value_to_select, em, ep));
setInterface(readDeviceSetting<ushort>("interface", currentInterface().value_to_select, em, ep));
setEndpointRead(Endpoint(readDeviceSetting<ushort>("endpointRead", endpointRead().address, em, ep)));
setEndpointWrite(Endpoint(readDeviceSetting<ushort>("endpointWrite", endpointWrite().address, em, ep)));
return true;
#else
return false;
#endif
}
bool PIUSB::openDevice() {
#ifdef PIP_USB
if (path_.size_s() >= 8) {
@@ -128,15 +156,15 @@ bool PIUSB::openDevice() {
usb_init();
//usb_set_debug(4);
if (usb_find_busses() < 0) {
piCoutObj << "[PIUSB] Error: Cant`t find busses!";
piCoutObj << "Error: Cant`t find busses!";
return false;
}
if (usb_find_devices() < 0) {
piCoutObj << "[PIUSB] Error: Cant`t find devices!";
piCoutObj << "Error: Cant`t find devices!";
return false;
}
//piCoutObj << "[PIUSB] Search for device ... " << flush;
//piCoutObj << "Search for device ... " << flush;
int cur_num = 1;
bool found = false;
struct usb_device * dev;
@@ -196,11 +224,11 @@ bool PIUSB::openDevice() {
eps << Endpoint(is->endpoint[i].bEndpointAddress,
is->endpoint[i].bmAttributes,
is->endpoint[i].wMaxPacketSize);
if (eps.back().direction == Endpoint::Write && ep_write.address == 0) ep_write = eps.back();
if (eps.back().direction == Endpoint::Read && ep_read.address == 0) ep_read = eps.back();
if (eps.back().direction == Endpoint::Write && (eps.back().address == ep_write.address || ep_write.address == 0)) ep_write = eps.back();
if (eps.back().direction == Endpoint::Read && (eps.back().address == ep_read.address || ep_read.address == 0)) ep_read = eps.back();
}
//piCoutObj << "[PIUSB] Device found at address:" << "Bus: " << dev->bus->dirname << ", Device: " << dev->filename;
//piCoutObj << "Device found at address:" << "Bus: " << dev->bus->dirname << ", Device: " << dev->filename;
found = true;
break;
} else cur_num++;
@@ -209,15 +237,15 @@ bool PIUSB::openDevice() {
if (found) break;
}
if (!found) {
piCoutObj << "[PIUSB] Error: Cant`t find device!";
piCoutObj << "Error: Cant`t find device!";
return false;
}
//piCoutObj << "[PIUSB] Open ... " << flush;
//piCoutObj << "Open ... " << flush;
hdev = usb_open(dev);
if (hdev == 0) {
piCoutObj << "[PIUSB] Error: Cant`t open device:" << usb_strerror();
piCoutObj << "Error: Cant`t open device:" << usb_strerror();
return false;
}// else piCoutObj << "[PIUSB] ok";
}// else piCoutObj << "ok";
//usb_reset(hdev);
//usb_set_configuration(hdev, 1);
@@ -225,22 +253,22 @@ bool PIUSB::openDevice() {
# ifndef WINDOWS
char tbuff[256];
//piCoutObj << "[PIUSB] Check for bounded driver ... " << flush;
//piCoutObj << "Check for bounded driver ... " << flush;
if (usb_get_driver_np(hdev, intefrace_, tbuff, sizeof(tbuff) - 1) >= 0) {
//piCoutObj << "[PIUSB] yes" << "Found driver: " << tbuff;
//piCoutObj << "[PIUSB] Detach driver ... " << flush;
//piCoutObj << "yes" << "Found driver: " << tbuff;
//piCoutObj << "Detach driver ... " << flush;
if (usb_detach_kernel_driver_np(hdev, intefrace_)< 0) {
piCoutObj << "[PIUSB] Error: Cant`t detach bounded driver!";
piCoutObj << "Error: Cant`t detach bounded driver!";
return false;
}// else piCoutObj << "[PIUSB] ok";
}// else piCoutObj << "[PIUSB] no";
}// else piCoutObj << "ok";
}// else piCoutObj << "no";
# endif
//piCoutObj << "[PIUSB] Claim interface ... " << flush;
//piCoutObj << "Claim interface ... " << flush;
if (usb_claim_interface(hdev, intefrace_) < 0) {
piCoutObj << "[PIUSB] Error: Cant`t claim interface:" << usb_strerror();
piCoutObj << "Error: Cant`t claim interface:" << usb_strerror();
return false;
} // else piCoutObj << "[PIUSB] ok";
} // else piCoutObj << "ok";
interface_claimed = intefrace_;
return true;