mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-16 06:47:14 +02:00
Merge branch 'faststreamer' into 3.0-rc
This commit is contained in:
@ -32,6 +32,7 @@ pthread_mutex_t DataProcessor::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
|
||||
DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dsEnable,
|
||||
uint32_t* freq, uint32_t* timer,
|
||||
void (*dataReadycb)(uint64_t, uint32_t, uint32_t, uint64_t, uint64_t, uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t, uint8_t, uint8_t,
|
||||
char*, uint32_t, void*),
|
||||
void *pDataReadycb) :
|
||||
@ -43,6 +44,9 @@ DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool*
|
||||
dataStreamEnable(dsEnable),
|
||||
fileFormatType(ftype),
|
||||
fileWriteEnable(fwenable),
|
||||
streamingFrequency(freq),
|
||||
streamingTimerInMs(timer),
|
||||
currentFreqCount(0),
|
||||
acquisitionStartedFlag(false),
|
||||
measurementStartedFlag(false),
|
||||
firstAcquisitionIndex(0),
|
||||
@ -61,6 +65,8 @@ DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool*
|
||||
|
||||
NumberofDataProcessors++;
|
||||
FILE_LOG (logDEBUG) << "Number of DataProcessors: " << NumberofDataProcessors;
|
||||
|
||||
memset((void*)&timerBegin, 0, sizeof(timespec));
|
||||
}
|
||||
|
||||
|
||||
@ -289,15 +295,14 @@ void DataProcessor::ThreadExecution() {
|
||||
|
||||
ProcessAnImage(buffer + FIFO_HEADER_NUMBYTES);
|
||||
|
||||
//stream or free
|
||||
if (*dataStreamEnable)
|
||||
//stream (if time/freq to stream) or free
|
||||
if (*dataStreamEnable && SendToStreamer())
|
||||
fifo->PushAddressToStream(buffer);
|
||||
else
|
||||
fifo->FreeAddress(buffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DataProcessor::StopProcessing(char* buf) {
|
||||
#ifdef VERBOSE
|
||||
if (!index)
|
||||
@ -339,6 +344,16 @@ void DataProcessor::ProcessAnImage(char* buf) {
|
||||
if (!index) bprintf(BLUE,"DataProcessing %d: fnum:%lu\n", index, fnum);
|
||||
#endif
|
||||
RecordFirstIndices(fnum);
|
||||
|
||||
if (*dataStreamEnable) {
|
||||
//restart timer
|
||||
clock_gettime(CLOCK_REALTIME, &timerBegin);
|
||||
timerBegin.tv_sec -= (*streamingTimerInMs) / 1000;
|
||||
timerBegin.tv_nsec -= ((*streamingTimerInMs) % 1000) * 1000000;
|
||||
|
||||
//to send first image
|
||||
currentFreqCount = *streamingFrequency;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -367,3 +382,43 @@ void DataProcessor::ProcessAnImage(char* buf) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool DataProcessor::SendToStreamer() {
|
||||
//skip
|
||||
if (!(*streamingFrequency)) {
|
||||
if (!CheckTimer())
|
||||
return false;
|
||||
} else {
|
||||
if (!CheckCount())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DataProcessor::CheckTimer() {
|
||||
struct timespec end;
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
#ifdef VERBOSE
|
||||
bprintf(BLUE,"%d Timer elapsed time:%f seconds\n", index, ( end.tv_sec - timerBegin.tv_sec ) + ( end.tv_nsec - timerBegin.tv_nsec ) / 1000000000.0);
|
||||
#endif
|
||||
//still less than streaming timer, keep waiting
|
||||
if((( end.tv_sec - timerBegin.tv_sec ) + ( end.tv_nsec - timerBegin.tv_nsec ) / 1000000000.0) < ((double)*streamingTimerInMs/1000.00))
|
||||
return false;
|
||||
|
||||
//restart timer
|
||||
clock_gettime(CLOCK_REALTIME, &timerBegin);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DataProcessor::CheckCount() {
|
||||
if (currentFreqCount == *streamingFrequency ) {
|
||||
currentFreqCount = 1;
|
||||
return true;
|
||||
}
|
||||
currentFreqCount++;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -24,16 +24,13 @@ uint64_t DataStreamer::RunningMask(0x0);
|
||||
pthread_mutex_t DataStreamer::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
|
||||
DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, uint32_t* freq, uint32_t* timer, int* sEnable) :
|
||||
DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, int* sEnable) :
|
||||
ThreadObject(NumberofDataStreamers),
|
||||
generalData(0),
|
||||
fifo(f),
|
||||
zmqSocket(0),
|
||||
dynamicRange(dr),
|
||||
shortFrameEnable(sEnable),
|
||||
streamingFrequency(freq),
|
||||
streamingTimerInMs(timer),
|
||||
currentFreqCount(0),
|
||||
acquisitionStartedFlag(false),
|
||||
measurementStartedFlag(false),
|
||||
firstAcquisitionIndex(0),
|
||||
@ -49,7 +46,6 @@ DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, uint32_t* freq, uint32_t* tim
|
||||
NumberofDataStreamers++;
|
||||
FILE_LOG (logDEBUG) << "Number of DataStreamers: " << NumberofDataStreamers;
|
||||
|
||||
memset((void*)&timerBegin, 0, sizeof(timespec));
|
||||
strcpy(fileNametoStream, "");
|
||||
}
|
||||
|
||||
@ -236,19 +232,6 @@ void DataStreamer::ProcessAnImage(char* buf) {
|
||||
if (!index) bprintf(MAGENTA,"DataStreamer %d: fnum:%lu\n", index, fnum);
|
||||
#endif
|
||||
RecordFirstIndices(fnum);
|
||||
//restart timer
|
||||
clock_gettime(CLOCK_REALTIME, &timerBegin);
|
||||
//to send first image
|
||||
currentFreqCount = *streamingFrequency;
|
||||
}
|
||||
|
||||
//skip
|
||||
if (!(*streamingFrequency)) {
|
||||
if (!CheckTimer())
|
||||
return;
|
||||
} else {
|
||||
if (!CheckCount())
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SendHeader(header))
|
||||
@ -272,32 +255,6 @@ void DataStreamer::ProcessAnImage(char* buf) {
|
||||
|
||||
|
||||
|
||||
bool DataStreamer::CheckTimer() {
|
||||
struct timespec end;
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
#ifdef VERBOSE
|
||||
bprintf(BLUE,"%d Timer elapsed time:%f seconds\n", index, ( end.tv_sec - timerBegin.tv_sec ) + ( end.tv_nsec - timerBegin.tv_nsec ) / 1000000000.0);
|
||||
#endif
|
||||
//still less than streaming timer, keep waiting
|
||||
if((( end.tv_sec - timerBegin.tv_sec ) + ( end.tv_nsec - timerBegin.tv_nsec ) / 1000000000.0) < (*streamingTimerInMs/1000))
|
||||
return false;
|
||||
|
||||
//restart timer
|
||||
clock_gettime(CLOCK_REALTIME, &timerBegin);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DataStreamer::CheckCount() {
|
||||
if (currentFreqCount == *streamingFrequency ) {
|
||||
currentFreqCount = 1;
|
||||
return true;
|
||||
}
|
||||
currentFreqCount++;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int DataStreamer::SendHeader(sls_detector_header* header, bool dummy) {
|
||||
|
||||
if (dummy)
|
||||
|
@ -54,6 +54,7 @@ int Fifo::CreateFifos(uint32_t fifoItemSize, uint32_t fifoDepth) {
|
||||
memory = 0;
|
||||
return FAIL;
|
||||
}
|
||||
FILE_LOG (logDEBUG) << "Memory Allocated " << index << ": " << (fifoItemSize * fifoDepth) << " bytes";
|
||||
|
||||
{ //push free addresses into fifoFree fifo
|
||||
char* buffer = memory;
|
||||
@ -66,7 +67,7 @@ int Fifo::CreateFifos(uint32_t fifoItemSize, uint32_t fifoDepth) {
|
||||
buffer += fifoItemSize;
|
||||
}
|
||||
}
|
||||
FILE_LOG (logINFO) << "Fifo Structure " << index << " reconstructed";
|
||||
FILE_LOG (logDEBUG) << "Fifo Reconstructed Depth " << index << ": " << fifoDepth;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ void UDPBaseImplementation::initializeMembers(){
|
||||
//***acquisition parameters***
|
||||
shortFrameEnable = -1;
|
||||
frameToGuiFrequency = 0;
|
||||
frameToGuiTimerinMS = DEFAULT_STREAMING_TIMER;
|
||||
frameToGuiTimerinMS = DEFAULT_STREAMING_TIMER_IN_MS;
|
||||
dataStreamEnable = false;
|
||||
streamingPort = 0;
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ int UDPStandardImplementation::setDataStreamEnable(const bool enable) {\
|
||||
if (enable) {
|
||||
bool error = false;
|
||||
for ( int i = 0; i < numThreads; ++i ) {
|
||||
dataStreamer.push_back(new DataStreamer(fifo[i], &dynamicRange, &frameToGuiFrequency, &frameToGuiTimerinMS, &shortFrameEnable));
|
||||
dataStreamer.push_back(new DataStreamer(fifo[i], &dynamicRange, &shortFrameEnable));
|
||||
dataStreamer[i]->SetGeneralData(generalData);
|
||||
// check again
|
||||
if (streamingPort == 0)
|
||||
@ -314,7 +314,8 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
|
||||
//create threads
|
||||
for ( int i=0; i < numThreads; ++i ) {
|
||||
listener.push_back(new Listener(myDetectorType, fifo[i], &status, &udpPortNum[i], eth, &activated, &numberOfFrames, &dynamicRange));
|
||||
dataProcessor.push_back(new DataProcessor(fifo[i], &fileFormatType, &fileWriteEnable, &dataStreamEnable,
|
||||
dataProcessor.push_back(new DataProcessor(fifo[i], &fileFormatType,
|
||||
&fileWriteEnable, &dataStreamEnable, &frameToGuiFrequency, &frameToGuiTimerinMS,
|
||||
rawDataReadyCallBack,pRawDataReady));
|
||||
if (Listener::GetErrorMask() || DataProcessor::GetErrorMask()) {
|
||||
FILE_LOG (logERROR) << "Error: Could not creates listener/dataprocessor threads (index:" << i << ")";
|
||||
@ -619,7 +620,8 @@ int UDPStandardImplementation::SetupFifoStructure() {
|
||||
if(dataStreamer.size())dataStreamer[i]->SetFifo(fifo[i]);
|
||||
}
|
||||
|
||||
FILE_LOG (logINFO) << "Fifo structure(s) reconstructed with Fifo Depth: " << fifoDepth;
|
||||
FILE_LOG (logINFO) << "Memory Allocated Per Fifo: " << ( ((generalData->imageSize) * numberofJobs + (generalData->fifoBufferHeaderSize)) * fifoDepth) << " bytes" ;
|
||||
FILE_LOG (logINFO) << " Fifo structure(s) reconstructed: " << numThreads;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user