#include "winusbdriver.h" #include #include #include #define SLEEP_DIVIDER 16 winUsbDriver::winUsbDriver(QWidget *parent) : genericUsbDriver(parent) { } winUsbDriver::~winUsbDriver(void){ //Like any decent destructor, this just frees resources qDebug() << "\n\nwinUsbDriver destructor ran!"; for (unsigned char k=0; k 10)) strcpy(subString, "th"); //qDebug("\n\nThis is the %d%s Tick!", timerCount, subString); bool success; DWORD errorCode = ERROR_SUCCESS; int n, earliest = MAX_OVERLAP; unsigned int minFrame = 4294967295; unsigned int dataBufferOffset; unsigned int packetLength = 0; //Getting earliest transfer number. for (n=0; nStartFrame < minFrame){ minFrame = isoCtx[0][n]->StartFrame; earliest = n; } } } //qDebug() << n << "is the earliest!"; if (earliest == MAX_OVERLAP){ return; } //Copy the tranfer data into buffer for(int i=0;iNumberOfPackets;i++){ for(unsigned char k=0; kIsoPackets[i].Offset; memcpy(&(outBuffers[currentWriteBuffer][packetLength]), &dataBuffer[k][earliest][dataBufferOffset], isoCtx[k][earliest]->IsoPackets[i].Length); packetLength += isoCtx[k][earliest]->IsoPackets[i].Length; } } //Get the data for isoRead() ready and swap buffers bufferLengths[currentWriteBuffer] = packetLength; currentWriteBuffer = !currentWriteBuffer; //Check for incorrect setup and kill if that were the case. UINT ep0frame = isoCtx[0][earliest]->StartFrame; UINT epkframe = isoCtx[NUM_ISO_ENDPOINTS-1][earliest]->StartFrame; UINT framePhaseError = epkframe - ep0frame; if(framePhaseError){ #ifndef WINDOWS_32_BIT qDebug("Frame phase error of %d", framePhaseError); killMe(); #endif } UINT oldStart; //Setup transfer for resubmission for(unsigned char k=0; kStartFrame; success = IsoK_ReUse(isoCtx[k][earliest]); if(!success){ errorCode = GetLastError(); qDebug() << "IsoK_Init failed with error code" << errorCode; qDebug() << "n =" << n; return; } isoCtx[k][earliest]->StartFrame = 0; success = OvlK_ReUse(ovlkHandle[k][earliest]); if(!success){ errorCode = GetLastError(); qDebug() << "OvlK_ReUse failed with error code" << errorCode; qDebug() << "n =" << n; return; }*/ //Resubmit the transfer success = UsbK_IsoReadPipe(handle, pipeID[k], dataBuffer[k][earliest], sizeof(dataBuffer[k][earliest]), (LPOVERLAPPED) ovlkHandle[k][earliest], isoCtx[k][earliest]); } //qDebug() << "Resubmitted Ctx #"<< earliest; //Signal to isoDriver that it can draw a new frame. upTick(); return; } char *winUsbDriver::isoRead(unsigned int *newLength){ //This will be called almost immediately after the upTick() signal is sent. Make sure bufferLengths[] abd outBuffers[] are ready! *(newLength) = bufferLengths[!currentWriteBuffer]; return (char*) outBuffers[(unsigned char) !currentWriteBuffer]; } bool winUsbDriver::allEndpointsComplete(int n){ //Just tells you if transfers have completed on _all_ iso endpoints for a given value of n. for (unsigned char k=0;k