mirror of https://github.com/EspoTek/Labrador.git
Removed autorecover
Now crashes instead. Will put back properly when new driver done.
This commit is contained in:
parent
2e8277c392
commit
c720b6ee39
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!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>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
@ -292,7 +292,7 @@
|
|||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">Labrador_libusbK.pro</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.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="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
|
|
Binary file not shown.
|
@ -53,12 +53,9 @@ void isoDriver::timerTick(void){
|
|||
firstFrame = false;
|
||||
}
|
||||
|
||||
isoTemp = driver->isoRead();
|
||||
isoTemp = driver->isoRead(TIMER_PERIOD*ADC_SPF*2);
|
||||
length = *((PUINT)isoTemp);
|
||||
qDebug() << "READING IN" << length;
|
||||
total_read += length;
|
||||
qDebug() << "TOTAL READ" << total_read;
|
||||
|
||||
|
||||
if (length==0){
|
||||
free(isoTemp);
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
private:
|
||||
QCustomPlot *axes;
|
||||
double windowAtPause = 0.01;
|
||||
QTimer* isoTimer = NULL, *recoveryTimer = NULL, *slowTimer = NULL;
|
||||
QTimer* isoTimer = NULL, *slowTimer = NULL;
|
||||
short *readData375_CH1, *readData375_CH2, *readData750;
|
||||
long total_read = 0;
|
||||
void analogConvert(short *shortPtr, QVector<double> *doublePtr, int TOP, bool AC);
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -5,11 +5,13 @@ winUsbDriver::winUsbDriver(QWidget *parent) : QLabel(parent)
|
|||
qDebug() << "Making USB Driver invisible!!";
|
||||
this->hide();
|
||||
//Load stack so that reset signal can be sent
|
||||
|
||||
usbInit(0x03eb, 0xa000);
|
||||
setDeviceMode(deviceMode);
|
||||
newDig(digitalPinState);
|
||||
usbIsoInit();
|
||||
|
||||
|
||||
psuTimer = new QTimer();
|
||||
psuTimer->setTimerType(Qt::PreciseTimer);
|
||||
psuTimer->start(PSU_PERIOD);
|
||||
|
@ -261,121 +263,52 @@ void winUsbDriver::newDig(int digState){
|
|||
}
|
||||
|
||||
unsigned char winUsbDriver::usbIsoInit(void){
|
||||
int n;
|
||||
bool success;
|
||||
unsigned char success;
|
||||
unsigned int transferred;
|
||||
DWORD errorCode = ERROR_SUCCESS;
|
||||
|
||||
success = OvlK_Init(&ovlPool, handle, MAX_OVERLAP, (KOVL_POOL_FLAG) 0);
|
||||
if(!success){
|
||||
errorCode = GetLastError();
|
||||
qDebug() << "OvlK_Init failed with error code" << errorCode;
|
||||
return 0;
|
||||
}
|
||||
success = UsbK_ResetPipe(handle, pipeID);
|
||||
if(!success){
|
||||
errorCode = GetLastError();
|
||||
qDebug() << "UsbK_ResetPipe failed with error code" << errorCode;
|
||||
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){
|
||||
success = StmK_Init(
|
||||
&stm_handle,
|
||||
handle,
|
||||
pipeID,
|
||||
MAX_TRANSFER_SIZE,
|
||||
MAX_PENDING_TRANSFERS,
|
||||
MAX_PENDING_IO,
|
||||
NULL,
|
||||
KSTM_FLAG_NONE);
|
||||
if (!success){
|
||||
errorCode = GetLastError();
|
||||
qDebug() << "IsoK_Init failed with error code" << errorCode;
|
||||
qDebug() << "n =" << n;
|
||||
qDebug("StmK_Init failed. ErrorCode: %08Xh\n", errorCode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
success = IsoK_SetPackets(isoCtx[n], ISO_PACKET_SIZE);
|
||||
if(!success){
|
||||
success = StmK_Start(stm_handle);
|
||||
if (!success){
|
||||
errorCode = GetLastError();
|
||||
qDebug() << "IsoK_SetPackets failed with error code" << errorCode;
|
||||
qDebug() << "n =" << n;
|
||||
qDebug("StmK_Start failed. ErrorCode: %08Xh\n", errorCode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
success = OvlK_Acquire(&ovlkHandle[n], ovlPool);
|
||||
if(!success){
|
||||
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;
|
||||
qDebug("[Start Stream] successful!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *winUsbDriver::isoRead(){
|
||||
char *winUsbDriver::isoRead(int numSamples){
|
||||
unsigned char *returnBuffer;
|
||||
|
||||
bool success;
|
||||
unsigned char 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
|
||||
for (n=0; n<NUM_FUTURE_CTX; n++){
|
||||
if(OvlK_IsComplete(ovlkHandle[n])){
|
||||
for(i=0;i<isoCtx[n]->NumberOfPackets;i++){
|
||||
allocBytes +=isoCtx[n]->IsoPackets[i].Length;
|
||||
}
|
||||
}
|
||||
returnBuffer = (unsigned char *) malloc(numSamples + 8); //8-byte header contains (unsigned long) length
|
||||
|
||||
success = StmK_Read(stm_handle, returnBuffer+8, 0, numSamples, (PUINT) returnBuffer);
|
||||
//qDebug("%d bytes copied, out of a possible %d\n", *((PUINT)returnBuffer), numSamples);
|
||||
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;
|
||||
}
|
||||
|
@ -385,6 +318,21 @@ winUsbDriver::~winUsbDriver(void){
|
|||
unsigned char 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
#ifndef 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 <QLabel>
|
||||
#include <QDebug>
|
||||
|
@ -22,57 +18,43 @@
|
|||
#include <conio.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
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//Generic vars
|
||||
explicit winUsbDriver(QWidget *parent = 0);
|
||||
char *isoRead(int numSamples);
|
||||
~winUsbDriver();
|
||||
int deviceMode = INIT_DEVICE_MODE;
|
||||
void setBufferPtr(bufferControl *newPtr);
|
||||
double scopeGain = 0.5;
|
||||
int dutyTemp = 0;
|
||||
//Generic Functions
|
||||
explicit winUsbDriver(QWidget *parent = 0);
|
||||
char *isoRead();
|
||||
~winUsbDriver();
|
||||
void setBufferPtr(bufferControl *newPtr);
|
||||
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;
|
||||
KUSB_HANDLE handle = NULL;
|
||||
unsigned short gainMask = 2056;
|
||||
int fGenChannel;
|
||||
int dutyPsu = 0;
|
||||
double currentPsuVoltage;
|
||||
int digitalPinState = 0;
|
||||
//Generic vars
|
||||
functionGenControl *fGenPtr_CH1 = NULL, *fGenPtr_CH2 = NULL;
|
||||
bufferControl *bufferPtr = NULL;
|
||||
QTimer *psuTimer;
|
||||
//Generic Functions
|
||||
KSTM_HANDLE stm_handle = NULL;
|
||||
unsigned char pipeID = 0x83;
|
||||
unsigned char usbInit(ULONG VIDin, ULONG PIDin);
|
||||
void usbSendControl(int RequestType, int Request, int Value, int Index, int Length, unsigned char *LDATA);
|
||||
void xmegaBreak(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:
|
||||
void sendClearBuffer(bool ch3751, bool ch3752, bool ch750);
|
||||
void setVisible_CH2(bool visible);
|
||||
|
|
Loading…
Reference in New Issue