Removed autorecover

Now crashes instead.  Will put back properly when new driver done.
This commit is contained in:
EspoTek 2016-10-14 08:46:24 +11:00
parent 2e8277c392
commit c720b6ee39
12 changed files with 73 additions and 146 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.1.0, 2016-10-14T08:15:47. --> <!-- Written by QtCreator 4.1.0, 2016-10-14T08:41:58. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -292,7 +292,7 @@
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">Labrador_libusbK.pro</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">Labrador_libusbK.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">C:/Users/Esposch/Documents/GitHub/Labrador/Desktop Interface/bin</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default"></value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>

View File

@ -53,12 +53,9 @@ void isoDriver::timerTick(void){
firstFrame = false; firstFrame = false;
} }
isoTemp = driver->isoRead(); isoTemp = driver->isoRead(TIMER_PERIOD*ADC_SPF*2);
length = *((PUINT)isoTemp); length = *((PUINT)isoTemp);
qDebug() << "READING IN" << length;
total_read += length; total_read += length;
qDebug() << "TOTAL READ" << total_read;
if (length==0){ if (length==0){
free(isoTemp); free(isoTemp);

View File

@ -32,7 +32,7 @@ public:
private: private:
QCustomPlot *axes; QCustomPlot *axes;
double windowAtPause = 0.01; double windowAtPause = 0.01;
QTimer* isoTimer = NULL, *recoveryTimer = NULL, *slowTimer = NULL; QTimer* isoTimer = NULL, *slowTimer = NULL;
short *readData375_CH1, *readData375_CH2, *readData750; short *readData375_CH1, *readData375_CH2, *readData750;
long total_read = 0; long total_read = 0;
void analogConvert(short *shortPtr, QVector<double> *doublePtr, int TOP, bool AC); void analogConvert(short *shortPtr, QVector<double> *doublePtr, int TOP, bool AC);

View File

@ -5,11 +5,13 @@ winUsbDriver::winUsbDriver(QWidget *parent) : QLabel(parent)
qDebug() << "Making USB Driver invisible!!"; qDebug() << "Making USB Driver invisible!!";
this->hide(); this->hide();
//Load stack so that reset signal can be sent //Load stack so that reset signal can be sent
usbInit(0x03eb, 0xa000); usbInit(0x03eb, 0xa000);
setDeviceMode(deviceMode); setDeviceMode(deviceMode);
newDig(digitalPinState); newDig(digitalPinState);
usbIsoInit(); usbIsoInit();
psuTimer = new QTimer(); psuTimer = new QTimer();
psuTimer->setTimerType(Qt::PreciseTimer); psuTimer->setTimerType(Qt::PreciseTimer);
psuTimer->start(PSU_PERIOD); psuTimer->start(PSU_PERIOD);
@ -261,121 +263,52 @@ void winUsbDriver::newDig(int digState){
} }
unsigned char winUsbDriver::usbIsoInit(void){ unsigned char winUsbDriver::usbIsoInit(void){
int n; unsigned char success;
bool success; unsigned int transferred;
DWORD errorCode = ERROR_SUCCESS; DWORD errorCode = ERROR_SUCCESS;
success = OvlK_Init(&ovlPool, handle, MAX_OVERLAP, (KOVL_POOL_FLAG) 0); success = StmK_Init(
if(!success){ &stm_handle,
errorCode = GetLastError(); handle,
qDebug() << "OvlK_Init failed with error code" << errorCode; pipeID,
return 0; MAX_TRANSFER_SIZE,
} MAX_PENDING_TRANSFERS,
success = UsbK_ResetPipe(handle, pipeID); MAX_PENDING_IO,
if(!success){ NULL,
errorCode = GetLastError(); KSTM_FLAG_NONE);
qDebug() << "UsbK_ResetPipe failed with error code" << errorCode; if (!success){
return 0;
}
for(n=0;n<NUM_FUTURE_CTX;n++){
success = IsoK_Init(&isoCtx[n], ISO_PACKETS_PER_CTX, n*ISO_PACKETS_PER_CTX);
if(!success){
errorCode = GetLastError(); errorCode = GetLastError();
qDebug() << "IsoK_Init failed with error code" << errorCode; qDebug("StmK_Init failed. ErrorCode: %08Xh\n", errorCode);
qDebug() << "n =" << n;
return 0; return 0;
} }
success = IsoK_SetPackets(isoCtx[n], ISO_PACKET_SIZE); success = StmK_Start(stm_handle);
if(!success){ if (!success){
errorCode = GetLastError(); errorCode = GetLastError();
qDebug() << "IsoK_SetPackets failed with error code" << errorCode; qDebug("StmK_Start failed. ErrorCode: %08Xh\n", errorCode);
qDebug() << "n =" << n;
return 0; return 0;
} }
success = OvlK_Acquire(&ovlkHandle[n], ovlPool); qDebug("[Start Stream] successful!\n");
if(!success){ return 1;
errorCode = GetLastError();
qDebug() << "OvlK_Acquire failed with error code" << errorCode;
qDebug() << "n =" << n;
return 0;
}
success = UsbK_IsoReadPipe(handle, pipeID, dataBuffer[n], sizeof(dataBuffer[n]), (LPOVERLAPPED) ovlkHandle[n], isoCtx[n]);
}
qDebug() << "Iso Setup Successful";
return 1;
} }
char *winUsbDriver::isoRead(){ char *winUsbDriver::isoRead(int numSamples){
unsigned char *returnBuffer; unsigned char *returnBuffer;
unsigned char success;
bool success;
DWORD errorCode = ERROR_SUCCESS; DWORD errorCode = ERROR_SUCCESS;
unsigned int allocBytes = 0;
int n, i, j;
unsigned int returnBufferOffset = 8;
unsigned int dataBufferOffset;
//Calculate how much data needs to be allocated returnBuffer = (unsigned char *) malloc(numSamples + 8); //8-byte header contains (unsigned long) length
for (n=0; n<NUM_FUTURE_CTX; n++){
if(OvlK_IsComplete(ovlkHandle[n])){ success = StmK_Read(stm_handle, returnBuffer+8, 0, numSamples, (PUINT) returnBuffer);
for(i=0;i<isoCtx[n]->NumberOfPackets;i++){ //qDebug("%d bytes copied, out of a possible %d\n", *((PUINT)returnBuffer), numSamples);
allocBytes +=isoCtx[n]->IsoPackets[i].Length; if (!success) {
} errorCode = GetLastError();
} qDebug("StmkK_Read failed. ErrorCode: %08Xh\n", errorCode);
free(returnBuffer);
return (char*) malloc(numSamples + 8);
//printf("No more items = %08Xh\n", ERROR_NO_MORE_ITEMS);
} }
//Allocate it (why am I allocating a new buffer every time?)
returnBuffer = (unsigned char *) malloc(allocBytes + 8); //Extra 8 bytes for the "header" that contains length of "packet" as unsigned int.
((unsigned int *) returnBuffer)[0] = allocBytes;
//Fill the memory with the relevant samples
//Note that this will return garbage if more than one isoCtx has completed.
//The above condition should only ever occur if the polling rate is slower than ISO_PACKETS_PER_CTX, though.
//(Or if some heinous external force stops the polling and gives it a long "temporary period"!!)
for (n=0; n<NUM_FUTURE_CTX; n++){
if(OvlK_IsComplete(ovlkHandle[n])){
//qDebug("Transfer %d is complete!!", n);
//Copy the iso packet
char currentString[8];
for(i=0;i<isoCtx[n]->NumberOfPackets;i++){
dataBufferOffset = isoCtx[n]->IsoPackets[i].Offset;
//memcpy(&returnBuffer[returnBufferOffset], &dataBuffer[n][dataBufferOffset], isoCtx[n]->IsoPackets[i].Length);
for(int j=0;j<isoCtx[n]->IsoPackets[i].Length;j++){
returnBuffer[returnBufferOffset+j] = dataBuffer[n][dataBufferOffset+j];
}
returnBufferOffset += isoCtx[n]->IsoPackets[i].Length;
}
}
//Setup next transfer
UINT oldStart = isoCtx[n]->StartFrame;
success = IsoK_ReUse(isoCtx[n]);
if(!success){
errorCode = GetLastError();
qDebug() << "IsoK_Init failed with error code" << errorCode;
qDebug() << "n =" << n;
return (char*) returnBuffer;
}
isoCtx[n]->StartFrame = oldStart + ISO_PACKETS_PER_CTX*NUM_FUTURE_CTX;
//qDebug() << oldStart;
//qDebug() << isoCtx[n]->StartFrame;
//qDebug() << handle;
success = OvlK_ReUse(ovlkHandle[n]);
if(!success){
errorCode = GetLastError();
qDebug() << "OvlK_ReUse failed with error code" << errorCode;
qDebug() << "n =" << n;
return (char*) returnBuffer;
}
success = UsbK_IsoReadPipe(handle, pipeID, dataBuffer[n], sizeof(dataBuffer[n]), (LPOVERLAPPED) ovlkHandle[n], isoCtx[n]);
}
//qDebug("%d bytes need to be allocated", allocBytes);
return (char*) returnBuffer; return (char*) returnBuffer;
} }
@ -385,6 +318,21 @@ winUsbDriver::~winUsbDriver(void){
unsigned char success; unsigned char success;
DWORD errorCode = ERROR_SUCCESS; DWORD errorCode = ERROR_SUCCESS;
success = StmK_Stop(stm_handle, 0);
if (!success)
{
errorCode = GetLastError();
qDebug("StmK_Stop failed. ErrorCode: %08Xh\n", errorCode);
}
qDebug("[Stop Stream] successful!\n");
success = StmK_Free(stm_handle);
if (!success)
{
errorCode = GetLastError();
qDebug("StmK_Free failed. ErrorCode: %08Xh\n", errorCode);
}
UsbK_Free(handle); UsbK_Free(handle);
} }

View File

@ -1,10 +1,6 @@
#ifndef WINUSBDRIVER_H #ifndef WINUSBDRIVER_H
#define WINUSBDRIVER_H #define WINUSBDRIVER_H
//Note that big parts of this were adapted from the LibusbK example code by Travis Robinson and Xiaofan Chen.
//Actually, I'm not sure how much input Xiaofan had on the example code, but he maintains LibusbK now and deserves a lot of credit for that!
//Thanks guys!
#include <QWidget> #include <QWidget>
#include <QLabel> #include <QLabel>
#include <QDebug> #include <QDebug>
@ -22,57 +18,43 @@
#include <conio.h> #include <conio.h>
#include "libusbk.h" #include "libusbk.h"
#define ISO_PACKET_SIZE 1023
#define ISO_PACKETS_PER_CTX 18
#define NUM_FUTURE_CTX 4
#define MAX_OVERLAP NUM_FUTURE_CTX+1
class winUsbDriver : public QLabel class winUsbDriver : public QLabel
{ {
Q_OBJECT Q_OBJECT
public: public:
//Generic vars explicit winUsbDriver(QWidget *parent = 0);
char *isoRead(int numSamples);
~winUsbDriver();
int deviceMode = INIT_DEVICE_MODE; int deviceMode = INIT_DEVICE_MODE;
void setBufferPtr(bufferControl *newPtr);
double scopeGain = 0.5; double scopeGain = 0.5;
int dutyTemp = 0; int dutyTemp = 0;
//Generic Functions
explicit winUsbDriver(QWidget *parent = 0);
char *isoRead();
~winUsbDriver();
void setBufferPtr(bufferControl *newPtr);
private: private:
//Libusbk
//GENERIC
KUSB_HANDLE handle = NULL;
unsigned char pipeID = 0x83;
DWORD ec = ERROR_SUCCESS;
//INIT
KLST_DEVINFO_HANDLE deviceInfo = NULL;
WINUSB_PIPE_INFORMATION pipeInfo;
UINT deviceCount = 0;
UCHAR pipeIndex = 0;
KLST_HANDLE deviceList = NULL;
//ISO
PKISO_CONTEXT isoCtx[NUM_FUTURE_CTX];
KOVL_HANDLE ovlkHandle[NUM_FUTURE_CTX];
KOVL_POOL_HANDLE ovlPool;
unsigned char dataBuffer[NUM_FUTURE_CTX][ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX];
//Labrador Board state data (mostly)
unsigned char fGenTriple=0; unsigned char fGenTriple=0;
KUSB_HANDLE handle = NULL;
unsigned short gainMask = 2056; unsigned short gainMask = 2056;
int fGenChannel; KSTM_HANDLE stm_handle = NULL;
int dutyPsu = 0; unsigned char pipeID = 0x83;
double currentPsuVoltage;
int digitalPinState = 0;
//Generic vars
functionGenControl *fGenPtr_CH1 = NULL, *fGenPtr_CH2 = NULL;
bufferControl *bufferPtr = NULL;
QTimer *psuTimer;
//Generic Functions
unsigned char usbInit(ULONG VIDin, ULONG PIDin); unsigned char usbInit(ULONG VIDin, ULONG PIDin);
void usbSendControl(int RequestType, int Request, int Value, int Index, int Length, unsigned char *LDATA); void usbSendControl(int RequestType, int Request, int Value, int Index, int Length, unsigned char *LDATA);
void xmegaBreak(void); void xmegaBreak(void);
unsigned char usbIsoInit(void); unsigned char usbIsoInit(void);
int fGenChannel;
functionGenControl *fGenPtr_CH1 = NULL, *fGenPtr_CH2 = NULL;
bufferControl *bufferPtr = NULL;
int dutyPsu = 0;
QTimer *psuTimer;
bool firstConnect = false;
double currentPsuVoltage;
KLST_DEVINFO_HANDLE deviceInfo = NULL;
WINUSB_PIPE_INFORMATION pipeInfo;
UINT deviceCount = 0;
UCHAR pipeIndex = 0;
DWORD ec = ERROR_SUCCESS;
KLST_HANDLE deviceList = NULL;
int digitalPinState = 0;
signals: signals:
void sendClearBuffer(bool ch3751, bool ch3752, bool ch750); void sendClearBuffer(bool ch3751, bool ch3752, bool ch750);
void setVisible_CH2(bool visible); void setVisible_CH2(bool visible);