Linux version up and running, with autorecover!

Hopefully the Windows compile hasn't been broken.  Fingers crossed!
This commit is contained in:
esposch 2016-10-24 11:27:19 +11:00
parent 4509c31f55
commit 8b99289369
10 changed files with 136 additions and 36 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.1.0, 2016-10-21T13:09:33. -->
<!-- Written by QtCreator 4.1.0, 2016-10-24T11:24:04. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -1166,6 +1166,7 @@ moc_mainwindow.cpp: ../../../Qt/5.7/gcc_64/include/QtWidgets/QMainWindow \
../../../Qt/5.7/gcc_64/include/QtPrintSupport/qtprintsupportversion.h \
build_linux/platformspecific.h \
gahnooslashlinuxusbdriver.h \
../../../Qt/5.7/gcc_64/include/QtCore/QMutex \
genericusbdriver.h \
../../../Qt/5.7/gcc_64/include/QtWidgets/QLabel \
../../../Qt/5.7/gcc_64/include/QtCore/QTimer \
@ -1173,6 +1174,7 @@ moc_mainwindow.cpp: ../../../Qt/5.7/gcc_64/include/QtWidgets/QMainWindow \
xmega.h \
desktop_settings.h \
buffercontrol.h \
build_linux/libusb/libusb.h \
ui_mainwindow.h \
scoperangeenterdialog.h \
../../../Qt/5.7/gcc_64/include/QtWidgets/QDialog \
@ -3547,6 +3549,9 @@ moc_gahnooslashlinuxusbdriver.cpp: ../../../Qt/5.7/gcc_64/include/QtWidgets/QWid
../../../Qt/5.7/gcc_64/include/QtCore/qfiledevice.h \
../../../Qt/5.7/gcc_64/include/QtGui/qvector2d.h \
../../../Qt/5.7/gcc_64/include/QtGui/qtouchdevice.h \
../../../Qt/5.7/gcc_64/include/QtCore/QThread \
../../../Qt/5.7/gcc_64/include/QtCore/qthread.h \
../../../Qt/5.7/gcc_64/include/QtCore/QMutex \
genericusbdriver.h \
../../../Qt/5.7/gcc_64/include/QtWidgets/QLabel \
../../../Qt/5.7/gcc_64/include/QtWidgets/qlabel.h \
@ -3555,8 +3560,6 @@ moc_gahnooslashlinuxusbdriver.cpp: ../../../Qt/5.7/gcc_64/include/QtWidgets/QWid
../../../Qt/5.7/gcc_64/include/QtCore/QTimer \
../../../Qt/5.7/gcc_64/include/QtCore/qtimer.h \
../../../Qt/5.7/gcc_64/include/QtCore/qbasictimer.h \
../../../Qt/5.7/gcc_64/include/QtCore/QThread \
../../../Qt/5.7/gcc_64/include/QtCore/qthread.h \
functiongencontrol.h \
../../../Qt/5.7/gcc_64/include/QtCore/QDir \
../../../Qt/5.7/gcc_64/include/QtCore/qdir.h \
@ -3565,6 +3568,7 @@ moc_gahnooslashlinuxusbdriver.cpp: ../../../Qt/5.7/gcc_64/include/QtWidgets/QWid
xmega.h \
desktop_settings.h \
buffercontrol.h \
build_linux/libusb/libusb.h \
gahnooslashlinuxusbdriver.h \
../../../Qt/5.7/gcc_64/bin/moc
/home/esposch/Qt/5.7/gcc_64/bin/moc $(DEFINES) -I/home/esposch/Qt/5.7/gcc_64/mkspecs/linux-g++ -I'/home/esposch/git/Labrador/Desktop Interface' -I'/home/esposch/git/Labrador/Desktop Interface/build_linux' -I'/home/esposch/git/Labrador/Desktop Interface/build_linux/libusb' -I/home/esposch/Qt/5.7/gcc_64/include -I/home/esposch/Qt/5.7/gcc_64/include/QtPrintSupport -I/home/esposch/Qt/5.7/gcc_64/include/QtWidgets -I/home/esposch/Qt/5.7/gcc_64/include/QtGui -I/home/esposch/Qt/5.7/gcc_64/include/QtCore -I/usr/include/c++/5 -I/usr/include/x86_64-linux-gnu/c++/5 -I/usr/include/c++/5/backward -I/usr/lib/gcc/x86_64-linux-gnu/5/include -I/usr/local/include -I/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed -I/usr/include/x86_64-linux-gnu -I/usr/include gahnooslashlinuxusbdriver.h -o moc_gahnooslashlinuxusbdriver.cpp
@ -6086,6 +6090,7 @@ main.o: main.cpp mainwindow.h \
../../../Qt/5.7/gcc_64/include/QtPrintSupport/qtprintsupportversion.h \
build_linux/platformspecific.h \
gahnooslashlinuxusbdriver.h \
../../../Qt/5.7/gcc_64/include/QtCore/QMutex \
genericusbdriver.h \
../../../Qt/5.7/gcc_64/include/QtWidgets/QLabel \
../../../Qt/5.7/gcc_64/include/QtCore/QTimer \
@ -6093,6 +6098,7 @@ main.o: main.cpp mainwindow.h \
xmega.h \
desktop_settings.h \
buffercontrol.h \
build_linux/libusb/libusb.h \
ui_mainwindow.h \
scoperangeenterdialog.h \
../../../Qt/5.7/gcc_64/include/QtWidgets/QDialog \
@ -6586,6 +6592,7 @@ mainwindow.o: mainwindow.cpp mainwindow.h \
../../../Qt/5.7/gcc_64/include/QtPrintSupport/qtprintsupportversion.h \
build_linux/platformspecific.h \
gahnooslashlinuxusbdriver.h \
../../../Qt/5.7/gcc_64/include/QtCore/QMutex \
genericusbdriver.h \
../../../Qt/5.7/gcc_64/include/QtWidgets/QLabel \
../../../Qt/5.7/gcc_64/include/QtCore/QTimer \
@ -6593,6 +6600,7 @@ mainwindow.o: mainwindow.cpp mainwindow.h \
xmega.h \
desktop_settings.h \
buffercontrol.h \
build_linux/libusb/libusb.h \
ui_mainwindow.h \
scoperangeenterdialog.h \
../../../Qt/5.7/gcc_64/include/QtWidgets/QDialog \
@ -9511,6 +9519,9 @@ gahnooslashlinuxusbdriver.o: gahnooslashlinuxusbdriver.cpp gahnooslashlinuxusbdr
../../../Qt/5.7/gcc_64/include/QtCore/qfiledevice.h \
../../../Qt/5.7/gcc_64/include/QtGui/qvector2d.h \
../../../Qt/5.7/gcc_64/include/QtGui/qtouchdevice.h \
../../../Qt/5.7/gcc_64/include/QtCore/QThread \
../../../Qt/5.7/gcc_64/include/QtCore/qthread.h \
../../../Qt/5.7/gcc_64/include/QtCore/QMutex \
genericusbdriver.h \
../../../Qt/5.7/gcc_64/include/QtWidgets/QLabel \
../../../Qt/5.7/gcc_64/include/QtWidgets/qlabel.h \
@ -9519,8 +9530,6 @@ gahnooslashlinuxusbdriver.o: gahnooslashlinuxusbdriver.cpp gahnooslashlinuxusbdr
../../../Qt/5.7/gcc_64/include/QtCore/QTimer \
../../../Qt/5.7/gcc_64/include/QtCore/qtimer.h \
../../../Qt/5.7/gcc_64/include/QtCore/qbasictimer.h \
../../../Qt/5.7/gcc_64/include/QtCore/QThread \
../../../Qt/5.7/gcc_64/include/QtCore/qthread.h \
functiongencontrol.h \
../../../Qt/5.7/gcc_64/include/QtCore/QDir \
../../../Qt/5.7/gcc_64/include/QtCore/qdir.h \
@ -9528,7 +9537,8 @@ gahnooslashlinuxusbdriver.o: gahnooslashlinuxusbdriver.cpp gahnooslashlinuxusbdr
../../../Qt/5.7/gcc_64/include/QtCore/QFile \
xmega.h \
desktop_settings.h \
buffercontrol.h
buffercontrol.h \
build_linux/libusb/libusb.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o gahnooslashlinuxusbdriver.o gahnooslashlinuxusbdriver.cpp
qrc_resources.o: qrc_resources.cpp

Binary file not shown.

View File

@ -1,5 +1,7 @@
#include "gahnooslashlinuxusbdriver.h"
QMutex tcBlockMutex;
gahnooSlashLinuxUsbDriver::gahnooSlashLinuxUsbDriver(QWidget *parent) : genericUsbDriver(parent)
{
qDebug() << "Making USB Driver invisible!!";
@ -20,17 +22,24 @@ gahnooSlashLinuxUsbDriver::gahnooSlashLinuxUsbDriver(QWidget *parent) : genericU
newDig(digitalPinState);
usbIsoInit();
psuTimer = new QTimer();
psuTimer->setTimerType(Qt::PreciseTimer);
psuTimer->start(PSU_PERIOD);
connect(psuTimer, SIGNAL(timeout()), this, SLOT(psuTick()));
recoveryTimer = new QTimer();
recoveryTimer->setTimerType(Qt::PreciseTimer);
recoveryTimer->start(RECOVERY_PERIOD);
connect(recoveryTimer, SIGNAL(timeout()), this, SLOT(recoveryTick()));
}
gahnooSlashLinuxUsbDriver::~gahnooSlashLinuxUsbDriver(void){
qDebug() << "\n\ngahnooSlashLinuxUsbDriver destructor ran!";
workerThread->quit();
workerThread->wait();
workerThread->deleteLater();
delete(isoHandler);
delete(psuTimer);
delete(recoveryTimer);
delete(isoTimer);
libusb_release_interface(handle, 0);
libusb_exit(ctx);
}
@ -73,6 +82,10 @@ void gahnooSlashLinuxUsbDriver::usbSendControl(uint8_t RequestType, uint8_t Requ
if(error){
qDebug("gahnooSlashLinuxUsbDriver::usbSendControl FAILED with error %s", libusb_error_name(error));
} else qDebug() << "gahnooSlashLinuxUsbDriver::usbSendControl SUCCESS";
if(error == LIBUSB_ERROR_NO_DEVICE){
qDebug() << "Device not found. Becoming an hero.";
killMe();
}
return;
}
@ -81,7 +94,9 @@ unsigned char gahnooSlashLinuxUsbDriver::usbIsoInit(void){
for(int n=0;n<NUM_FUTURE_CTX;n++){
isoCtx[n] = libusb_alloc_transfer(ISO_PACKETS_PER_CTX);
libusb_fill_iso_transfer(isoCtx[n], handle, pipeID, dataBuffer[n], ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX, ISO_PACKETS_PER_CTX, isoCallback, (void*)n, 4000);
transferCompleted[n].number = n;
transferCompleted[n].completed = false;
libusb_fill_iso_transfer(isoCtx[n], handle, pipeID, dataBuffer[n], ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX, ISO_PACKETS_PER_CTX, isoCallback, (void*)&transferCompleted[n], 4000);
libusb_set_iso_packet_lengths(isoCtx[n], ISO_PACKET_SIZE);
error = libusb_submit_transfer(isoCtx[n]);
if(error){
@ -102,8 +117,12 @@ unsigned char gahnooSlashLinuxUsbDriver::usbIsoInit(void){
isoHandler->ctx = ctx;
isoHandler->moveToThread(workerThread);
connect(workerThread, SIGNAL(started()), isoHandler, SLOT(handle()));
//workerThread->start();
workerThread->start();
qDebug() << "MAIN THREAD ID" << QThread::currentThreadId();
//QThread::sleep(1);
qDebug() << "Iso Stack initialised!";
return 1;
}
@ -117,23 +136,75 @@ void gahnooSlashLinuxUsbDriver::isoTimerTick(void){
if((timerCount<20) && (timerCount > 10)) strcpy(subString, "th");
//qDebug("\n\nThis is the %d%s Tick!", timerCount, subString);
return;
int n;
int n, error, earliest = MAX_OVERLAP;
qint64 minFrame = 9223372036854775807; //max value for 64 bit signed
unsigned int i, packetLength = 0;
unsigned char* packetPointer;
tcBlockMutex.lock();
for (n=0; n<NUM_FUTURE_CTX; n++){
if(isoCtx[n]->status==LIBUSB_TRANSFER_COMPLETED){
qDebug("Transfer %d is complete!!", n);
if(transferCompleted[n].completed){
//qDebug("Transfer %d is complete!!", n);
if(transferCompleted[n].timeReceived < minFrame){
minFrame = transferCompleted[n].timeReceived;
earliest = n;
}
}
}
if (earliest == MAX_OVERLAP){
tcBlockMutex.unlock();
return;
}
//Copy iso data into buffer
for(i=0;i<isoCtx[earliest]->num_iso_packets;i++){
packetPointer = libusb_get_iso_packet_buffer_simple(isoCtx[earliest], i);
//qDebug() << packetLength;
memcpy(&(outBuffers[currentWriteBuffer][packetLength]), packetPointer, isoCtx[earliest]->iso_packet_desc[i].actual_length);
packetLength += isoCtx[earliest]->iso_packet_desc[i].actual_length;
}
//Control data for isoDriver
bufferLengths[currentWriteBuffer] = packetLength;
currentWriteBuffer = !currentWriteBuffer;
//Setup next transfer
transferCompleted[earliest].completed = false;
error = libusb_submit_transfer(isoCtx[earliest]);
if(error){
qDebug() << "libusb_submit_transfer FAILED";
qDebug() << "ERROR" << libusb_error_name(error);
} //else qDebug() << "isoCtx submitted successfully!";
tcBlockMutex.unlock();
upTick();
return;
}
char *gahnooSlashLinuxUsbDriver::isoRead(unsigned int *newLength){
*(newLength) = 0;
return (char*) NULL;
//*(newLength) = 0;
//return (char*) NULL;
qDebug() << "gahnooSlashLinuxUsbDriver::isoRead";
*(newLength) = bufferLengths[!currentWriteBuffer];
return (char*) outBuffers[(unsigned char) !currentWriteBuffer];
}
void gahnooSlashLinuxUsbDriver::recoveryTick(void){
avrDebug();
}
static void LIBUSB_CALL isoCallback(struct libusb_transfer * transfer){
qDebug() << "CALLBACK" << (long) transfer->user_data;
tcBlockMutex.lock();
//int number = ((tcBlock *)transfer->user_data)->number;
//bool completed = ((tcBlock *)transfer->user_data)->completed;
//qDebug() << "CALLBACK" << number;
//qDebug() << completed;
((tcBlock *)transfer->user_data)->completed = true;
((tcBlock *)transfer->user_data)->timeReceived = QDateTime::currentMSecsSinceEpoch();
//qDebug() << ((tcBlock *)transfer->user_data)->timeReceived;
tcBlockMutex.unlock();
return;
}

View File

@ -3,17 +3,21 @@
#include <QWidget>
#include <QThread>
#include <QMutex>
#include <QDateTime>
#include "genericusbdriver.h"
#include "libusb.h"
/*while(1){
if(libusb_event_handling_ok(ctx)){
libusb_handle_events(ctx);
qDebug() << "HANDLED";
}
}*/
#define RECOVERY_PERIOD 250
typedef struct tcBlock{
int number;
bool completed;
qint64 timeReceived;
} tcBlock;
extern QMutex tcBlockMutex;
class worker : public QObject
{
@ -25,7 +29,13 @@ public:
libusb_context *ctx;
public slots:
void handle(){
while(1);
qDebug() << "SUB THREAD ID" << QThread::currentThreadId();
while(1){
if(libusb_event_handling_ok(ctx)){
libusb_handle_events(ctx);
//qDebug() << "HANDLED";
}
}
}
};
@ -42,8 +52,10 @@ private:
libusb_context *ctx;
libusb_device_handle *handle = NULL;
unsigned char pipeID = 0x83;
QTimer *recoveryTimer;
//USBIso Vars
libusb_transfer *isoCtx[NUM_FUTURE_CTX];
tcBlock transferCompleted[NUM_FUTURE_CTX];
unsigned char dataBuffer[NUM_FUTURE_CTX][ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX];
QTimer *isoTimer;
unsigned char currentWriteBuffer = 0;
@ -56,6 +68,7 @@ private:
signals:
public slots:
void isoTimerTick(void);
void recoveryTick(void);
};
static void LIBUSB_CALL isoCallback(struct libusb_transfer *transfer);

View File

@ -58,7 +58,9 @@ void isoDriver::timerTick(void){
total_read += length;
if (length==0){
//free(isoTemp);
//Zero length packet means something's gone wrong. Probably a disconnect.
//qDebug() << "Zero length iso packet. An hero!";
//driver->killMe();
return;
}

Binary file not shown.

View File

@ -109,8 +109,8 @@ int worker::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
return _id;
}
struct qt_meta_stringdata_gahnooSlashLinuxUsbDriver_t {
QByteArrayData data[3];
char stringdata0[40];
QByteArrayData data[4];
char stringdata0[53];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@ -121,11 +121,12 @@ static const qt_meta_stringdata_gahnooSlashLinuxUsbDriver_t qt_meta_stringdata_g
{
QT_MOC_LITERAL(0, 0, 25), // "gahnooSlashLinuxUsbDriver"
QT_MOC_LITERAL(1, 26, 12), // "isoTimerTick"
QT_MOC_LITERAL(2, 39, 0) // ""
QT_MOC_LITERAL(2, 39, 0), // ""
QT_MOC_LITERAL(3, 40, 12) // "recoveryTick"
},
"gahnooSlashLinuxUsbDriver\0isoTimerTick\0"
""
"\0recoveryTick"
};
#undef QT_MOC_LITERAL
@ -135,7 +136,7 @@ static const uint qt_meta_data_gahnooSlashLinuxUsbDriver[] = {
7, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
2, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
@ -143,9 +144,11 @@ static const uint qt_meta_data_gahnooSlashLinuxUsbDriver[] = {
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 0, 19, 2, 0x0a /* Public */,
1, 0, 24, 2, 0x0a /* Public */,
3, 0, 25, 2, 0x0a /* Public */,
// slots: parameters
QMetaType::Void,
QMetaType::Void,
0 // eod
@ -158,6 +161,7 @@ void gahnooSlashLinuxUsbDriver::qt_static_metacall(QObject *_o, QMetaObject::Cal
Q_UNUSED(_t)
switch (_id) {
case 0: _t->isoTimerTick(); break;
case 1: _t->recoveryTick(); break;
default: ;
}
}
@ -189,13 +193,13 @@ int gahnooSlashLinuxUsbDriver::qt_metacall(QMetaObject::Call _c, int _id, void *
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
if (_id < 2)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
_id -= 2;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1)
if (_id < 2)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 1;
_id -= 2;
}
return _id;
}