mirror of
https://github.com/EEVengers/ThunderScope.git
synced 2025-04-11 23:19:16 +00:00
Added A couple missing files
This commit is contained in:
parent
88c81660c6
commit
085f6ebf15
BIN
Software/.DS_Store
vendored
BIN
Software/.DS_Store
vendored
Binary file not shown.
150
Software/scope_link/EVDataTransferThread.cpp
Normal file
150
Software/scope_link/EVDataTransferThread.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
//
|
||||
// EVDataTransferThread.cpp
|
||||
// Scope
|
||||
//
|
||||
// Created by Daniel Vasile on 2019-07-30.
|
||||
// Copyright © 2019 EEVengers. All rights reserved.
|
||||
//
|
||||
|
||||
/*
|
||||
Class that runs all data transfers.
|
||||
From FTDI Chip -> DigitalProccesing
|
||||
From DigitalProcessing -> Electron App
|
||||
*/
|
||||
|
||||
#include "EVDataTransferThread.hpp"
|
||||
#include "EVSuperSpeedFIFOBridge.hpp"
|
||||
|
||||
DataTransferHandler::DataTransferHandler()
|
||||
{
|
||||
try {
|
||||
|
||||
killFTDIDataTransferThread = true;
|
||||
InitFTDISuperSpeedChip(&superSpeedFIFOBridgeHandle);
|
||||
|
||||
threadSharedCache = new EVSharedCache(MEDIUM_BUFF_SIZE,10);
|
||||
|
||||
CopyFunc = [](unsigned char* buff, unsigned int& idx, unsigned int size, void* obj){ return; };
|
||||
|
||||
} catch (EVException e) {
|
||||
std::cout << "DataTransferHandler:Constructor - " << e.what << std::endl;
|
||||
assert(false);
|
||||
} catch (std::exception e) {
|
||||
std::cout << "DataTransferHandler:Constructor - " << e.what() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DataTransferHandler::FTDITransferThread(DataTransferHandler* handler)
|
||||
{
|
||||
unsigned int bytesReadFromPipe;
|
||||
unsigned int errorCode;
|
||||
unsigned int asyncBytesRead[handler->numAsyncBuffers];
|
||||
unsigned int copyIdx = 0;
|
||||
OVERLAPPED vOverlapped[handler->numAsyncBuffers];
|
||||
|
||||
|
||||
for(int i = 0; i < handler->numAsyncBuffers; i++) {
|
||||
if(FT_OK != ( errorCode = FT_InitializeOverlapped(handler->superSpeedFIFOBridgeHandle, &(vOverlapped[i])))) {
|
||||
FT_Close(handler->superSpeedFIFOBridgeHandle);
|
||||
EVLogger::Debug( (std::string("FTDI Transfer Thread failed to init overlapped at index ") + std::to_string(i) + std::string(", error code ") + std::to_string(errorCode)).c_str() );
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(FT_OK != (errorCode = FT_SetStreamPipe(handler->superSpeedFIFOBridgeHandle,false,false,0x82,MEDIUM_BUFF_SIZE))) {
|
||||
for(int i = 0; i < handler->numAsyncBuffers;i++) {
|
||||
FT_ReleaseOverlapped(handler->superSpeedFIFOBridgeHandle, vOverlapped + i);
|
||||
}
|
||||
FT_Close(handler->superSpeedFIFOBridgeHandle);
|
||||
EVLogger::Debug( (std::string("FTDI Transfer Thread failed to set stream pipe, error code ") + std::to_string(errorCode)).c_str() );
|
||||
assert(false);
|
||||
}
|
||||
|
||||
//queue up the inital batch
|
||||
for(int i = 0; i < handler->numAsyncBuffers; i++) {
|
||||
if( (FT_OK | FT_IO_PENDING) != (errorCode = FT_ReadPipe(handler->superSpeedFIFOBridgeHandle,0x82,&(handler->asyncDataBuffers[i][0]),MEDIUM_BUFF_SIZE,&(asyncBytesRead[i]),vOverlapped + i))) {
|
||||
for(int i = 0; i < handler->numAsyncBuffers;i++) {
|
||||
FT_ReleaseOverlapped(handler->superSpeedFIFOBridgeHandle, vOverlapped + i);
|
||||
}
|
||||
FT_Close(handler->superSpeedFIFOBridgeHandle);
|
||||
EVLogger::Debug( (std::string("FTDI Transfer Thread failed to que up async read, error code ") + std::to_string(errorCode)).c_str() );
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int idx = 0;
|
||||
|
||||
while(!handler->killFTDIDataTransferThread) {
|
||||
//wait for transfer to finish once this if statment is done, handler->asyncDataBuffers[idx] has valid data
|
||||
if(FT_OK != (errorCode = FT_GetOverlappedResult(handler->superSpeedFIFOBridgeHandle,&vOverlapped[idx],&asyncBytesRead[idx],true))) {
|
||||
for(int i = 0; i < handler->numAsyncBuffers;i++) {
|
||||
FT_ReleaseOverlapped(handler->superSpeedFIFOBridgeHandle, vOverlapped + i);
|
||||
}
|
||||
FT_Close(handler->superSpeedFIFOBridgeHandle);
|
||||
EVLogger::Debug( (std::string("FTDI Transfer Thread failed to wait for overlapped result, error code ") + std::to_string(errorCode)).c_str() );
|
||||
assert(false);
|
||||
}
|
||||
//re-submit the transfer request for continous streaming
|
||||
if( (FT_OK | FT_IO_PENDING) != (errorCode = FT_ReadPipe(handler->superSpeedFIFOBridgeHandle,0x82,&(handler->asyncDataBuffers[idx][0]),MEDIUM_BUFF_SIZE,&(asyncBytesRead[idx]),vOverlapped + idx))) {
|
||||
for(int i = 0; i < handler->numAsyncBuffers;i++) {
|
||||
FT_ReleaseOverlapped(handler->superSpeedFIFOBridgeHandle, vOverlapped + i);
|
||||
}
|
||||
FT_Close(handler->superSpeedFIFOBridgeHandle);
|
||||
EVLogger::Debug( (std::string("FTDI Transfer Thread failed to wait for overlapped result, error code ") + std::to_string(errorCode)).c_str() );
|
||||
assert(false);
|
||||
}
|
||||
//submit data to shared cache
|
||||
handler->lock.lock();
|
||||
handler->CopyFunc(handler->asyncDataBuffers[idx],copyIdx, bytesReadFromPipe, (void*)handler);
|
||||
handler->lock.unlock();
|
||||
//Keep trace of bytes transfered
|
||||
handler->bytesRead += asyncBytesRead[idx];
|
||||
//roll over
|
||||
if(++idx == handler->numAsyncBuffers) {
|
||||
idx = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DataTransferHandler::StartFTDITransferThread()
|
||||
{
|
||||
if(!killFTDIDataTransferThread) {
|
||||
throw EVException(EVErrorCodeServiceAlreadyRunning,"DataTransferHandler:StartFTDITransferThread",nullptr);
|
||||
}
|
||||
|
||||
killFTDIDataTransferThread = false;
|
||||
superSpeedFTDITransferThread = std::thread(DataTransferHandler::FTDITransferThread,this);
|
||||
}
|
||||
|
||||
void DataTransferHandler::StopThread() {
|
||||
killFTDIDataTransferThread = true;
|
||||
}
|
||||
|
||||
void DataTransferHandler::SetCopyFunc(CopyFuncs Func) {
|
||||
lock.lock();
|
||||
switch(Func) {
|
||||
case DataTransferFullBuffRead:
|
||||
CopyFunc = [](unsigned char* buff, unsigned int &idx, unsigned int size, void* obj)
|
||||
{ ((DataTransferHandler*)obj)->threadSharedCache->SetWriteCache(buff); };
|
||||
break;
|
||||
default:
|
||||
throw EVException(EVErrorCodeInvalidValue,"DataTransferHandler::SetCopyFunc()",nullptr);
|
||||
break;
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
DataTransferHandler::~DataTransferHandler()
|
||||
{
|
||||
if(superSpeedFTDITransferThread.joinable())
|
||||
{
|
||||
killFTDIDataTransferThread = true;
|
||||
superSpeedFTDITransferThread.join();
|
||||
}
|
||||
if(superSpeedFIFOBridgeHandle != 0)
|
||||
{
|
||||
FT_Close(superSpeedFIFOBridgeHandle);
|
||||
}
|
||||
}
|
65
Software/scope_link/EVDataTransferThread.hpp
Normal file
65
Software/scope_link/EVDataTransferThread.hpp
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// EVDataTransferThread.hpp
|
||||
// Scope
|
||||
//
|
||||
// Created by Daniel Vasile on 2019-07-30.
|
||||
// Copyright © 2019 EEVengers. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef EVDataTransferThread_hpp
|
||||
#define EVDataTransferThread_hpp
|
||||
|
||||
#include "EVLibrary.hpp"
|
||||
|
||||
enum CopyFuncs
|
||||
{
|
||||
DataTransferFullBuffRead
|
||||
};
|
||||
|
||||
/*
|
||||
Container class that encapsulates all data transfers that occur in this program.
|
||||
FTDIChip -> DataHandler
|
||||
DataHandler -> DigitalProcessingHandler
|
||||
DigitalProcessingHandler -> Electron app
|
||||
*/
|
||||
class DataTransferHandler
|
||||
{
|
||||
public:
|
||||
|
||||
DataTransferHandler();
|
||||
|
||||
void StartFTDITransferThread();
|
||||
void SetFTDITransferCopyFunction();
|
||||
void SetCopyFunc(CopyFuncs Func);
|
||||
void StopThread();
|
||||
|
||||
unsigned int bytesRead;//used for testing
|
||||
|
||||
EVSharedCache* threadSharedCache;
|
||||
|
||||
~DataTransferHandler();
|
||||
|
||||
private:
|
||||
|
||||
static void FTDITransferThread(DataTransferHandler* handler);
|
||||
|
||||
FT_HANDLE superSpeedFIFOBridgeHandle;
|
||||
|
||||
void (*CopyFunc)(unsigned char* buff, unsigned int& idx, unsigned int size, void* obj);
|
||||
|
||||
|
||||
bool killFTDIDataTransferThread;
|
||||
bool killDigitalProcessingTransferThread;
|
||||
bool killElectronTransferThread;
|
||||
|
||||
std::thread superSpeedFTDITransferThread;
|
||||
|
||||
protected:
|
||||
std::mutex lock;
|
||||
|
||||
const static unsigned int numAsyncBuffers = 16;
|
||||
|
||||
unsigned char asyncDataBuffers[numAsyncBuffers][MEDIUM_BUFF_SIZE];
|
||||
};
|
||||
|
||||
#endif /* EVDataTransferThread_hpp */
|
98
Software/scope_link/EVTester.cpp
Normal file
98
Software/scope_link/EVTester.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
|
||||
|
||||
#include "EVTester.hpp"
|
||||
#include "EVMath.hpp"
|
||||
#include "EVDigitalProcessing.hpp"
|
||||
#include "EVDataTransferThread.hpp"
|
||||
|
||||
void TestSincInterpolation() {
|
||||
|
||||
int numInterpolatedPoints;
|
||||
int numOriginalPoints = 300;
|
||||
DataPoint* testPoints = (DataPoint*)malloc(numOriginalPoints * sizeof(DataPoint));
|
||||
std::ofstream myFile;
|
||||
|
||||
|
||||
for(int i = 0; i < numOriginalPoints; i++) {
|
||||
testPoints[i].value = sin(double(10 * i) * 0.05) + (2 * sin(double(3 * i) * 0.05));
|
||||
testPoints[i].time = double(10 * i) * 0.05;
|
||||
}
|
||||
|
||||
DataPoint* points = SincInterpolate(testPoints, numOriginalPoints, &numInterpolatedPoints, 3, 20);
|
||||
|
||||
myFile.open("InterpolatedPoints.csv");
|
||||
for(int i = 0; i < numInterpolatedPoints; i++) {
|
||||
myFile << points[i].time;
|
||||
myFile << ",";
|
||||
myFile << points[i].value;
|
||||
myFile << "\n";
|
||||
}
|
||||
myFile.close();
|
||||
|
||||
myFile.open("OriginalValues.csv");
|
||||
for(int i = 0; i < numOriginalPoints; i++) {
|
||||
myFile << testPoints[i].time;
|
||||
myFile << ",";
|
||||
myFile << testPoints[i].value;
|
||||
myFile << "\n";
|
||||
}
|
||||
|
||||
myFile.close();
|
||||
}
|
||||
|
||||
void TestDataThroughPut() {
|
||||
unsigned int bytesProcessed = 0;
|
||||
unsigned int bytesRead = 0;
|
||||
int numDigitalProcessors = 5;
|
||||
|
||||
//create a transfer thread and 3 risingEdgeTrigger DataProccessing Threads
|
||||
DataTransferHandler* dataExchanger;
|
||||
DigitalProcessor* digitalProcessor[numDigitalProcessors];
|
||||
|
||||
dataExchanger = new DataTransferHandler();
|
||||
dataExchanger->SetCopyFunc(DataTransferFullBuffRead);
|
||||
|
||||
for(int i = 0; i < numDigitalProcessors; i++) {
|
||||
digitalProcessor[i] = new DigitalProcessor();
|
||||
digitalProcessor[i]->SetSharedCache(dataExchanger->threadSharedCache);
|
||||
}
|
||||
|
||||
//start a timer
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
//start the DataProcessing Threads
|
||||
for(int i = 0; i < numDigitalProcessors; i++) {
|
||||
digitalProcessor[i]->StartRisingEdgeTriggerThread();
|
||||
}
|
||||
|
||||
//start the transfer thread
|
||||
dataExchanger->StartFTDITransferThread();
|
||||
|
||||
//run for 1 minute
|
||||
std::this_thread::sleep_for(std::chrono::seconds(60));
|
||||
|
||||
//end process and print out Bytes processed / second
|
||||
|
||||
for(int i = 0; i < numDigitalProcessors; i++) {
|
||||
digitalProcessor[i]->StopThread();
|
||||
}
|
||||
dataExchanger->StopThread();
|
||||
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto timeElapsed = end - start;
|
||||
|
||||
bytesRead = dataExchanger->bytesRead;
|
||||
delete dataExchanger;
|
||||
for(int i = 0; i < numDigitalProcessors; i++) {
|
||||
bytesProcessed += digitalProcessor[i]->bytesProcessed;
|
||||
delete digitalProcessor[i];
|
||||
}
|
||||
std::cout << "Time Elapsed: " << timeElapsed.count() << "ms" << std::endl;
|
||||
std::cout << "Bytes Read: " << bytesRead << "B" << std::endl;
|
||||
std::cout << "Bytes Processed: " << bytesProcessed << std::endl;
|
||||
std::cout << "B/s: " << bytesProcessed / 60 << std::endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
16
Software/scope_link/EVTester.hpp
Normal file
16
Software/scope_link/EVTester.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
#ifndef EVTester_hpp
|
||||
#define EVTester_hpp
|
||||
|
||||
#include "EVLibrary.hpp"
|
||||
|
||||
|
||||
void TestSincInterpolation();
|
||||
|
||||
void TestDataThroughPut();
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user