diff --git a/Desktop Interface/Labrador_libusbK.pro.user b/Desktop Interface/Labrador_libusbK.pro.user index 9588c473..2ab9ffba 100644 --- a/Desktop Interface/Labrador_libusbK.pro.user +++ b/Desktop Interface/Labrador_libusbK.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -292,7 +292,7 @@ Labrador_libusbK.pro false - C:/Users/Esposch/Documents/GitHub/Labrador/Desktop Interface/bin + 3768 false true diff --git a/Desktop Interface/bin/Labrador_libusbk.exe b/Desktop Interface/bin/Labrador_libusbk.exe index 308bd6a5..f85196a4 100644 Binary files a/Desktop Interface/bin/Labrador_libusbk.exe and b/Desktop Interface/bin/Labrador_libusbk.exe differ diff --git a/Desktop Interface/isodriver.cpp b/Desktop Interface/isodriver.cpp index c7a8b815..5ab2bced 100644 --- a/Desktop Interface/isodriver.cpp +++ b/Desktop Interface/isodriver.cpp @@ -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); diff --git a/Desktop Interface/isodriver.h b/Desktop Interface/isodriver.h index 0abd1c8f..dc734603 100644 --- a/Desktop Interface/isodriver.h +++ b/Desktop Interface/isodriver.h @@ -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 *doublePtr, int TOP, bool AC); diff --git a/Desktop Interface/release/desktop_settings.obj b/Desktop Interface/release/desktop_settings.obj index 3d74db72..e8332b27 100644 Binary files a/Desktop Interface/release/desktop_settings.obj and b/Desktop Interface/release/desktop_settings.obj differ diff --git a/Desktop Interface/release/isodriver.obj b/Desktop Interface/release/isodriver.obj index 1af2f596..dc56a899 100644 Binary files a/Desktop Interface/release/isodriver.obj and b/Desktop Interface/release/isodriver.obj differ diff --git a/Desktop Interface/release/mainwindow.obj b/Desktop Interface/release/mainwindow.obj index 6356d49f..cbe2923d 100644 Binary files a/Desktop Interface/release/mainwindow.obj and b/Desktop Interface/release/mainwindow.obj differ diff --git a/Desktop Interface/release/moc_isodriver.obj b/Desktop Interface/release/moc_isodriver.obj index 273dd85e..95adc96e 100644 Binary files a/Desktop Interface/release/moc_isodriver.obj and b/Desktop Interface/release/moc_isodriver.obj differ diff --git a/Desktop Interface/release/moc_winusbdriver.obj b/Desktop Interface/release/moc_winusbdriver.obj index 2e615dbd..cb26ddd2 100644 Binary files a/Desktop Interface/release/moc_winusbdriver.obj and b/Desktop Interface/release/moc_winusbdriver.obj differ diff --git a/Desktop Interface/release/winusbdriver.obj b/Desktop Interface/release/winusbdriver.obj index 7f87ec64..e5304a47 100644 Binary files a/Desktop Interface/release/winusbdriver.obj and b/Desktop Interface/release/winusbdriver.obj differ diff --git a/Desktop Interface/winusbdriver.cpp b/Desktop Interface/winusbdriver.cpp index 9299f390..739c5ead 100644 --- a/Desktop Interface/winusbdriver.cpp +++ b/Desktop Interface/winusbdriver.cpp @@ -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;nNumberOfPackets;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; nNumberOfPackets;i++){ - dataBufferOffset = isoCtx[n]->IsoPackets[i].Offset; - //memcpy(&returnBuffer[returnBufferOffset], &dataBuffer[n][dataBufferOffset], isoCtx[n]->IsoPackets[i].Length); - for(int j=0;jIsoPackets[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); } diff --git a/Desktop Interface/winusbdriver.h b/Desktop Interface/winusbdriver.h index 1faeade6..8707cc24 100644 --- a/Desktop Interface/winusbdriver.h +++ b/Desktop Interface/winusbdriver.h @@ -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 #include #include @@ -22,57 +18,43 @@ #include #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);