NEW DRIVER CODE WORKING!!!

WOOO!!!!!

(Just make sure not to change the FPS.  It's still nowhere near
perfect.)
This commit is contained in:
EspoTek 2016-10-14 10:27:17 +11:00
parent be1668ba46
commit 4ae84d893c
11 changed files with 54 additions and 50 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.1.0, 2016-10-14T08:41:58. -->
<!-- Written by QtCreator 4.1.0, 2016-10-14T10:07:27. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -48,17 +48,18 @@ void isoDriver::setWindow(int newWindow){
}
void isoDriver::timerTick(void){
qDebug() << "isoDriver SEZ Tick!";
if(firstFrame){
autoGain();
firstFrame = false;
}
isoTemp = driver->isoRead(TIMER_PERIOD*ADC_SPF*2);
length = *((PUINT)isoTemp);
isoTemp = driver->isoRead(&length);
qDebug() << length << "read in!!";
total_read += length;
if (length==0){
free(isoTemp);
//free(isoTemp);
return;
}
@ -101,7 +102,7 @@ void isoDriver::timerTick(void){
default:
qFatal("Error in isoDriver::timerTick. Invalid device mode.");
}
free(isoTemp);
//free(isoTemp);
}
void isoDriver::analogConvert(short *shortPtr, QVector<double> *doublePtr, int TOP, bool AC){
@ -474,11 +475,11 @@ int isoDriver::trigger(void){
//qDebug() << isoTemp_short[i+4];
if(isoTemp_short[i+4] >= target){
if(isoTemp_short[i] >= target){
triggerCountSeeking = (triggerType % 2) ? 0 : triggerCountSeeking + 1;
triggerCountNotSeeking = (triggerType % 2) ? triggerCountNotSeeking + 1 : 0;
}
else if (isoTemp_short[i+4] < lowThresh){
else if (isoTemp_short[i] < lowThresh){
triggerCountNotSeeking = (triggerType % 2) ? 0 : triggerCountNotSeeking + 1;
triggerCountSeeking = (triggerType % 2) ? triggerCountSeeking + 1 : 0;
}
@ -506,11 +507,11 @@ int isoDriver::trigger(void){
//A bit of thresholding...
//Gives DAT STABILITY
if(isoTemp[i+8] >= target){
if(isoTemp[i] >= target){
triggerCountSeeking = (triggerType % 2) ? 0 : triggerCountSeeking + 1;
triggerCountNotSeeking = (triggerType % 2) ? triggerCountNotSeeking + 1 : 0;
}
else if (isoTemp[i+8] < lowThresh){
else if (isoTemp[i] < lowThresh){
triggerCountNotSeeking = (triggerType % 2) ? 0 : triggerCountNotSeeking + 1;
triggerCountSeeking = (triggerType % 2) ? triggerCountSeeking + 1 : 0;
}
@ -583,19 +584,19 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) //0 for off, 1
{
if(!paused_CH1 && CH1_mode == - 1){
for (int i=0;i<(length/ADC_SPF);i++){
internalBuffer750->writeBuffer_char(&isoTemp[ADC_SPF*i+8], ADC_SPF-2); //Offset because the first 8 bytes of the array contain the length (no samples!!)!
internalBuffer750->writeBuffer_char(&isoTemp[ADC_SPF*i], ADC_SPF-2); //Offset because the first 8 bytes of the array contain the length (no samples!!)!
}
}
if(!paused_CH1 && CH1_mode > 0){
for (int i=0;i<(length/ADC_SPF);i++){
internalBuffer375_CH1->writeBuffer_char(&isoTemp[ADC_SPF*i+8], ADC_SPF/2-1); //Offset because the first 8 bytes of the array contain the length (no samples!!)!
internalBuffer375_CH1->writeBuffer_char(&isoTemp[ADC_SPF*i], ADC_SPF/2-1); //Offset because the first 8 bytes of the array contain the length (no samples!!)!
}
}
if(!paused_CH2 && CH2_mode > 0){
for (int i=0;i<(length/ADC_SPF);i++){
internalBuffer375_CH2->writeBuffer_char(&isoTemp[ADC_SPF*i+8+ADC_SPF/2], ADC_SPF/2-1); //+375 to get the second half of the packet
internalBuffer375_CH2->writeBuffer_char(&isoTemp[ADC_SPF*i+ADC_SPF/2], ADC_SPF/2-1); //+375 to get the second half of the packet
}
}
@ -724,7 +725,7 @@ void isoDriver::multimeterAction(){
isoTemp_short = (short *)isoTemp;
if(!paused_multimeter){
for (int i=0;i<(length/ADC_SPF);i++){
internalBuffer375_CH1->writeBuffer_short(&isoTemp_short[ADC_SPF/2*i+(8/sizeof(short))], ADC_SPF/2-1); //Offset because the first 8 bytes of the array contain the length (no samples!!)!
internalBuffer375_CH1->writeBuffer_short(&isoTemp_short[ADC_SPF/2*i], ADC_SPF/2-1); //Offset because the first 8 bytes of the array contain the length (no samples!!)!
}
}

View File

@ -54,7 +54,7 @@ private:
double triggerLevel = 0;
enum triggerType_enum {rising_ch1 = 0, falling_ch1 = 1, rising_ch2 = 2, falling_ch2 = 3};
triggerType_enum triggerType = rising_ch1;
int length;
unsigned int length;
siprint *v0, *v1, *dv, *t0, *t1, *dt, *f;
bool singleShotEnabled = false;
double triggerDelay;

View File

@ -6,6 +6,12 @@ winUsbDriver::winUsbDriver(QWidget *parent) : QLabel(parent)
this->hide();
//Load stack so that reset signal can be sent
outBuffers[0] = (unsigned char *) calloc(ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX + 8, 1);
outBuffers[1] = (unsigned char *) calloc(ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX + 8, 1);
bufferLengths[0] = 0;
bufferLengths[1] = 0;
usbInit(0x03eb, 0xa000);
setDeviceMode(deviceMode);
newDig(digitalPinState);
@ -263,12 +269,6 @@ void winUsbDriver::newDig(int digState){
}
unsigned char winUsbDriver::usbIsoInit(void){
//Setup the output file
qDebug() << "Creating output.csv";
outputFile = new QFile("output.csv");
outputFile->open(QIODevice::WriteOnly);
outputStream = new QTextStream(outputFile);
//Setup the iso stack
int n;
bool success;
@ -324,11 +324,14 @@ unsigned char winUsbDriver::usbIsoInit(void){
return 1;
}
char *winUsbDriver::isoRead(int numSamples){
unsigned char *returnBuffer;
returnBuffer = (unsigned char *) malloc(numSamples + 8); //8-byte header contains (unsigned long) length
((unsigned int *)returnBuffer)[0] = 0;
return (char*) returnBuffer;
char *winUsbDriver::isoRead(unsigned int *newLength){
//unsigned char *returnBuffer;
//returnBuffer = (unsigned char *) malloc(numSamples + 8); //8-byte header contains (unsigned long) length
//((unsigned int *)returnBuffer)[0] = 0;
//return (char*) returnBuffer;
qDebug() << (unsigned char) !currentWriteBuffer;
*(newLength) = bufferLengths[!currentWriteBuffer];
return (char*) outBuffers[(unsigned char) !currentWriteBuffer];
}
winUsbDriver::~winUsbDriver(void){
@ -466,28 +469,26 @@ void winUsbDriver::isoTimerTick(void){
bool success;
DWORD errorCode = ERROR_SUCCESS;
unsigned int mallocBytes = 8;
int n, i, j, k;
unsigned int dataBufferOffset;
unsigned int packetLength = 0;
for (int n=0; n<NUM_FUTURE_CTX; n++){
for (n=0; n<NUM_FUTURE_CTX; n++){
if(OvlK_IsComplete(ovlkHandle[n])){
qDebug("Transfer %d is complete!!", n);
for(int iter=0;iter<isoCtx[n]->NumberOfPackets;iter++){
mallocBytes +=isoCtx[n]->IsoPackets[iter].Length;
}
//Write the iso data to file
unsigned int offset;
char currentString[8];
for(int i=0;i<ISO_PACKETS_PER_CTX;i++){
offset = isoCtx[n]->IsoPackets[i].Offset;
for(int j=0;j<MAX_VALID_INDEX;j++){
sprintf(currentString, "%d\n", (char)dataBuffer[n][offset+j]);
*(outputStream) << currentString;
//*(outputStream) << dataBuffer[n][offset+j] << "\n";
}
//*(outputStream) << "\n";
//qDebug() << "Max =" << ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX + 8;
//Copy iso data into buffer
for(int i=0;i<isoCtx[n]->NumberOfPackets;i++){
dataBufferOffset = isoCtx[n]->IsoPackets[i].Offset;
//qDebug() << packetLength;
memcpy(&(outBuffers[currentWriteBuffer][packetLength]), &dataBuffer[n][dataBufferOffset], isoCtx[n]->IsoPackets[i].Length);
packetLength += isoCtx[n]->IsoPackets[i].Length;
}
//Control data for isoDriver
qDebug() << packetLength;
bufferLengths[currentWriteBuffer] = packetLength;
currentWriteBuffer = !currentWriteBuffer;
//Setup next transfer
UINT oldStart = isoCtx[n]->StartFrame;
@ -499,8 +500,8 @@ void winUsbDriver::isoTimerTick(void){
return;
}
isoCtx[n]->StartFrame = oldStart + ISO_PACKETS_PER_CTX*NUM_FUTURE_CTX;
qDebug() << oldStart;
qDebug() << isoCtx[n]->StartFrame;
//qDebug() << oldStart;
//qDebug() << isoCtx[n]->StartFrame;
success = OvlK_ReUse(ovlkHandle[n]);
if(!success){
@ -510,7 +511,8 @@ void winUsbDriver::isoTimerTick(void){
return;
}
success = UsbK_IsoReadPipe(handle, pipeID, dataBuffer[n], sizeof(dataBuffer[n]), (LPOVERLAPPED) ovlkHandle[n], isoCtx[n]);
qDebug("%d bytes will go to isoDriver", packetLength);
return;
}
}
qDebug("%d bytes need to be allocated", mallocBytes);
}

View File

@ -19,10 +19,10 @@
#include "libusbk.h"
#define ISO_PACKET_SIZE 1023
#define ISO_PACKETS_PER_CTX 50
#define ISO_PACKETS_PER_CTX 30
#define NUM_FUTURE_CTX 4
#define MAX_OVERLAP NUM_FUTURE_CTX+1
#define ISO_TIMER_PERIOD 30
#define ISO_TIMER_PERIOD 8
#define MAX_VALID_INDEX 374
class winUsbDriver : public QLabel
@ -30,12 +30,14 @@ class winUsbDriver : public QLabel
Q_OBJECT
public:
explicit winUsbDriver(QWidget *parent = 0);
char *isoRead(int numSamples);
char *isoRead(unsigned int *newLength);
~winUsbDriver();
int deviceMode = INIT_DEVICE_MODE;
void setBufferPtr(bufferControl *newPtr);
double scopeGain = 0.5;
int dutyTemp = 0;
unsigned char *outBuffers[2];
unsigned int bufferLengths[2];
private:
//
PKISO_CONTEXT isoCtx[NUM_FUTURE_CTX];
@ -43,10 +45,9 @@ private:
KOVL_POOL_HANDLE ovlPool;
unsigned char dataBuffer[NUM_FUTURE_CTX][ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX];
QTimer *isoTimer;
unsigned char currentWriteBuffer = 0;
//
unsigned long timerCount = 0;
QFile *outputFile = NULL;
QTextStream *outputStream = NULL;
//
unsigned char fGenTriple=0;
KUSB_HANDLE handle = NULL;