From fc7d3bcaea0921217735e27504a4eb37f7463390 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 1 May 2019 12:10:15 +0200 Subject: [PATCH] ctb callback used --- slsReceiverSoftware/include/DataProcessor.h | 45 ++++++++++++++++++- slsReceiverSoftware/include/slsReceiver.h | 14 ++++++ .../include/slsReceiverImplementation.h | 36 +++++++++++++++ .../include/slsReceiverTCPIPInterface.h | 30 +++++++++++++ .../include/slsReceiverUsers.h | 10 +++++ slsReceiverSoftware/src/DataProcessor.cpp | 27 ++++++++++- slsReceiverSoftware/src/mainCustomized.cpp | 13 +++--- slsReceiverSoftware/src/slsReceiver.cpp | 6 +++ .../src/slsReceiverImplementation.cpp | 20 ++++++++- .../src/slsReceiverTCPIPInterface.cpp | 9 +++- slsReceiverSoftware/src/slsReceiverUsers.cpp | 6 +++ 11 files changed, 204 insertions(+), 12 deletions(-) diff --git a/slsReceiverSoftware/include/DataProcessor.h b/slsReceiverSoftware/include/DataProcessor.h index d36b66712..d30c60c9b 100755 --- a/slsReceiverSoftware/include/DataProcessor.h +++ b/slsReceiverSoftware/include/DataProcessor.h @@ -39,11 +39,15 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { * @param act pointer to activated * @param depaden pointer to deactivated padding enable * @param sm pointer to silent mode + * @param ct pointer to ctb type + * @param cdo pointer to ctb digital offset + * @param cad pointer to ctb analog databytes */ DataProcessor(int ind, detectorType dtype, Fifo* f, fileFormat* ftype, bool fwenable, bool* mfwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr, uint32_t* freq, uint32_t* timer, - bool* fp, bool* act, bool* depaden, bool* sm); + bool* fp, bool* act, bool* depaden, bool* sm, + int* ct, int* cdo, int* cad); /** * Destructor @@ -217,8 +221,21 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { * Can be modified to the new size to be written/streamed. (only smaller value). */ void registerCallBackRawDataModifyReady(void (*func)(char* , - char*, uint32_t &,void*),void *arg); + char*, uint32_t &, void*),void *arg); + /** + * Call back for raw CTB data that will be modified + * args to raw data call back are + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). + * type CTB chip type + * digitalOffset digital offset + * analogdataBytes analog databytes + */ + void registerCallBackCTBReceiverReady(void (*func)(char*, + char*, uint32_t &, int, int, int, void*),void *arg); @@ -387,6 +404,16 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { /** Frame Number of latest processed frame number of an entire Acquisition (including all scans) */ uint64_t currentFrameIndex; + // for ctb call back + /** ctb type*/ + int* ctbType; + /** ctb digital offset */ + int* ctbDigitalOffset; + /** ctb analog databytes */ + int* ctbAnalogDataBytes; + + + //call back /** @@ -409,6 +436,20 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { void (*rawDataModifyReadyCallBack)(char*, char*, uint32_t &, void*); + /** + * Call back for raw CTB data that will be modified + * args to raw data call back are + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). + * type CTB chip type + * digitalOffset digital offset + * analogdataBytes analog databytes + */ + void (*ctbRawDataReadyCallBack)(char*, + char*, uint32_t &, int, int, int, void*); + void *pRawDataReady; diff --git a/slsReceiverSoftware/include/slsReceiver.h b/slsReceiverSoftware/include/slsReceiver.h index 7c5647d39..43e567d6e 100755 --- a/slsReceiverSoftware/include/slsReceiver.h +++ b/slsReceiverSoftware/include/slsReceiver.h @@ -95,6 +95,20 @@ class slsReceiver : private virtual slsDetectorDefs { void registerCallBackRawDataModifyReady(void (*func)(char* , char*, uint32_t &,void*),void *arg); + /** + * Call back for raw CTB data that will be modified + * args to raw data call back are + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). + * type CTB chip type + * digitalOffset digital offset + * analogdataBytes analog databytes + */ + void registerCallBackCTBReceiverReady(void (*func)(char*, + char*, uint32_t &, int, int, int, void*),void *arg); + private: diff --git a/slsReceiverSoftware/include/slsReceiverImplementation.h b/slsReceiverSoftware/include/slsReceiverImplementation.h index dc86a6b8d..8913ea04e 100755 --- a/slsReceiverSoftware/include/slsReceiverImplementation.h +++ b/slsReceiverSoftware/include/slsReceiverImplementation.h @@ -751,6 +751,20 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { void registerCallBackRawDataModifyReady(void (*func)(char* , char*, uint32_t &,void*),void *arg); + /** + * Call back for raw CTB data that will be modified + * args to raw data call back are + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). + * type CTB chip type + * digitalOffset digital offset + * analogdataBytes analog databytes + */ + void registerCallBackCTBReceiverReady(void (*func)(char*, + char*, uint32_t &, int, int, int, void*),void *arg); + private: /** @@ -924,6 +938,13 @@ private: /** Fifo Structure to store addresses of memory writes */ std::vector> fifo; + /** ctb type for callback*/ + int ctbType; + /* ctb digital offset for callback */ + int ctbDigitalOffset; + /* analog data bytes */ + int ctbAnalogDataBytes; + //***callback parameters*** /** * Call back for start acquisition @@ -964,6 +985,21 @@ private: */ void (*rawDataModifyReadyCallBack)(char* , char*, uint32_t &, void*); + + /** + * Call back for raw CTB data that will be modified + * args to raw data call back are + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). + * type CTB chip type + * digitalOffset digital offset + * analogdataBytes analog databytes + */ + void (*ctbRawDataReadyCallBack)(char*, + char*, uint32_t &, int, int, int, void*); + void *pRawDataReady; diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index 113899d25..be1d5a132 100755 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -92,6 +92,21 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs { void registerCallBackRawDataModifyReady(void (*func)(char* , char*, uint32_t &,void*),void *arg); + /** + * Call back for raw CTB data that will be modified + * args to raw data call back are + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). + * type CTB chip type + * digitalOffset digital offset + * analogdataBytes analog databytes + */ + void registerCallBackCTBReceiverReady(void (*func)(char*, + char*, uint32_t &, int, int, int, void*),void *arg); + + private: /** @@ -367,6 +382,21 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs { void (*rawDataModifyReadyCallBack)(char* , char*, uint32_t &, void*); + /** + * Call back for raw CTB data that will be modified + * args to raw data call back are + * args to raw data ready callback are + * sls_receiver_header frame metadata + * dataPointer is the pointer to the data + * revDatasize is the reference of data size in bytes. Can be modified to the new size to be written/streamed. (only smaller value). + * type CTB chip type + * digitalOffset digital offset + * analogdataBytes analog databytes + */ + void (*ctbRawDataReadyCallBack)(char*, + char*, uint32_t &, int, int, int, void*); + + void *pRawDataReady; diff --git a/slsReceiverSoftware/include/slsReceiverUsers.h b/slsReceiverSoftware/include/slsReceiverUsers.h index 39456bd94..a6d0ad513 100755 --- a/slsReceiverSoftware/include/slsReceiverUsers.h +++ b/slsReceiverSoftware/include/slsReceiverUsers.h @@ -87,6 +87,16 @@ public: void registerCallBackRawDataModifyReady(void (*func)(char* header, char* datapointer, uint32_t &revDatasize, void*),void *arg); + /** + @short register callback to be called when CTB data are available in receiver (to process and/or save the data). + \param func raw data ready callback. arguments are sls_receiver_header, dataPointer, revDatasize is the reference of data size in bytes, chip type, digital offset, analog databytes. revDatasize be modified to the new size to be written/streamed. (only smaller value). + \param arg argument + \returns nothing + */ + void registerCallBackCTBReceiverReady(void (*func)(char* header, + char* datapointer, uint32_t &revDatasize, int type, int digitalOffset, int analogDataBytes, void*),void *arg); + + //receiver object std::unique_ptr receiver; }; diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 42ab238e7..c16a8bbba 100755 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -27,7 +27,8 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f, fileFormat* ftype, bool fwenable, bool* mfwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr, uint32_t* freq, uint32_t* timer, - bool* fp, bool* act, bool* depaden, bool* sm) : + bool* fp, bool* act, bool* depaden, bool* sm, + int* ct, int* cdo, int* cad) : ThreadObject(ind), runningFlag(0), @@ -56,8 +57,12 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f, numTotalFramesCaught(0), numFramesCaught(0), currentFrameIndex(0), + ctbType(ct), + ctbDigitalOffset(cdo), + ctbAnalogDataBytes(cad), rawDataReadyCallBack(nullptr), rawDataModifyReadyCallBack(nullptr), + ctbRawDataReadyCallBack(nullptr), pRawDataReady(nullptr) { if(ThreadObject::CreateThread() == FAIL) @@ -370,6 +375,20 @@ void DataProcessor::ProcessAnImage(char* buf) { pRawDataReady); (*((uint32_t*)buf)) = revsize; } + + // ctb call back + else if (ctbRawDataReadyCallBack) { + uint32_t revsize = (uint32_t)(*((uint32_t*)buf)); + ctbRawDataReadyCallBack( + (char*)rheader, + buf + FIFO_HEADER_NUMBYTES + sizeof(sls_receiver_header), + revsize, + *ctbType, + *ctbDigitalOffset, + *ctbAnalogDataBytes, + pRawDataReady); + (*((uint32_t*)buf)) = revsize; + } // write to file @@ -445,7 +464,11 @@ void DataProcessor::registerCallBackRawDataModifyReady(void (*func)(char* , pRawDataReady=arg; } - +void DataProcessor::registerCallBackCTBReceiverReady(void (*func)(char* , + char*, uint32_t&, int, int, int, void*),void *arg) { + ctbRawDataReadyCallBack=func; + pRawDataReady=arg; +} void DataProcessor::PadMissingPackets(char* buf) { FILE_LOG(logDEBUG) << index << ": Padding Missing Packets"; diff --git a/slsReceiverSoftware/src/mainCustomized.cpp b/slsReceiverSoftware/src/mainCustomized.cpp index 092eb1ab9..3d36b6d09 100755 --- a/slsReceiverSoftware/src/mainCustomized.cpp +++ b/slsReceiverSoftware/src/mainCustomized.cpp @@ -26,14 +26,16 @@ void sigInterruptHandler(int p){ #ifdef MYTHEN302 -void GetData(char* metadata, char* datapointer, uint32_t& datasize, void* p) { +void GetData(char* metadata, char* datapointer, uint32_t& datasize, + int ctbType, int ctbDigitalOffset, int ctbAnalogDataBytes, void* p) { + constexpr int dynamicRange = 24; constexpr int numSamples = 32 * 3; // 32 channels * 3 counters = 96 constexpr int numCounters = numSamples * 2; // 2 strips // validate datasize { FILE_LOG(logDEBUG) << "Datasize:" << datasize; - int wordsCaught = (datasize / sizeof(uint64_t)) - ctbOffset; + int wordsCaught = ((datasize - ctbAnalogDataBytes) / sizeof(uint64_t)) - ctbOffset; int expectedWordSize = numSamples * dynamicRange; if (expectedWordSize != wordsCaught) { FILE_LOG(logWARNING) << "Number of words do not match, Expected " @@ -42,7 +44,7 @@ void GetData(char* metadata, char* datapointer, uint32_t& datasize, void* p) { } // source - uint64_t* ptr = (uint64_t*)datapointer; + uint64_t* ptr = (uint64_t*)(datapointer + ctbAnalogDataBytes); // remove the offset from source ptr += ctbOffset; // destination @@ -79,8 +81,9 @@ void GetData(char* metadata, char* datapointer, uint32_t& datasize, void* p) { // update the size to be written to file & overwrite data in memory datasize = numCounters * sizeof(int); - memcpy(datapointer, (char*)result, datasize); + memcpy(datapointer + ctbAnalogDataBytes, (char*)result, datasize); delete[] result; + datasize += ctbAnalogDataBytes; FILE_LOG(logDEBUG) << "Modified Size: " << datasize; } #endif @@ -158,7 +161,7 @@ int main(int argc, char *argv[]) { //register callbacks - receiver->registerCallBackRawDataModifyReady(GetData, NULL); + receiver->registerCallBackCTBReceiverReady(GetData, NULL); //start tcp server thread if (receiver->start() == slsDetectorDefs::FAIL){ diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 5716bf1ff..d6d9ae45b 100755 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -130,3 +130,9 @@ void slsReceiver::registerCallBackRawDataModifyReady(void (*func)(char*, char*, uint32_t &, void*),void *arg){ tcpipInterface->registerCallBackRawDataModifyReady(func,arg); } + + +void slsReceiver::registerCallBackCTBReceiverReady(void (*func)(char* , + char*, uint32_t &, int, int, int, void*),void *arg){ + tcpipInterface->registerCallBackCTBReceiverReady(func,arg); +} diff --git a/slsReceiverSoftware/src/slsReceiverImplementation.cpp b/slsReceiverSoftware/src/slsReceiverImplementation.cpp index 3375d6fc2..030d06608 100755 --- a/slsReceiverSoftware/src/slsReceiverImplementation.cpp +++ b/slsReceiverSoftware/src/slsReceiverImplementation.cpp @@ -120,6 +120,7 @@ void slsReceiverImplementation::InitializeMembers() { pAcquisitionFinished = nullptr; rawDataReadyCallBack = nullptr; rawDataModifyReadyCallBack = nullptr; + ctbRawDataReadyCallBack = nullptr; pRawDataReady = nullptr; } @@ -696,7 +697,8 @@ int slsReceiverImplementation::setNumberofUDPInterfaces(const int n) { dataProcessor.push_back(sls::make_unique(i, myDetectorType, fifo_ptr, &fileFormatType, fileWriteEnable, &masterFileWriteEnable, &dataStreamEnable, &gapPixelsEnable, &dynamicRange, &streamingFrequency, &streamingTimerInMs, - &framePadding, &activated, &deactivatedPaddingEnable, &silentMode)); + &framePadding, &activated, &deactivatedPaddingEnable, &silentMode, + &ctbType, &ctbDigitalOffset, &ctbAnalogDataBytes)); dataProcessor[i]->SetGeneralData(generalData); } catch (...) { @@ -741,6 +743,10 @@ int slsReceiverImplementation::setNumberofUDPInterfaces(const int n) { for (const auto& it : dataProcessor) it->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,pRawDataReady); } + if(ctbRawDataReadyCallBack) { + for (const auto& it : dataProcessor) + it->registerCallBackCTBReceiverReady(ctbRawDataReadyCallBack,pRawDataReady); + } // test socket buffer size with current set up if (setUDPSocketBufferSize(0) == FAIL) { @@ -1136,7 +1142,8 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) { dataProcessor.push_back(sls::make_unique(i, myDetectorType, fifo_ptr, &fileFormatType, fileWriteEnable, &masterFileWriteEnable, &dataStreamEnable, &gapPixelsEnable, &dynamicRange, &streamingFrequency, &streamingTimerInMs, - &framePadding, &activated, &deactivatedPaddingEnable, &silentMode)); + &framePadding, &activated, &deactivatedPaddingEnable, &silentMode, + &ctbType, &ctbDigitalOffset, &ctbAnalogDataBytes)); } catch (...) { FILE_LOG(logERROR) << "Could not create listener/dataprocessor threads (index:" << i << ")"; @@ -1422,6 +1429,15 @@ void slsReceiverImplementation::registerCallBackRawDataModifyReady(void (*func)( } +void slsReceiverImplementation::registerCallBackCTBReceiverReady(void (*func)(char* , + char*, uint32_t&, int, int, int, void*),void *arg) { + ctbRawDataReadyCallBack=func; + pRawDataReady=arg; + for (const auto& it : dataProcessor) + it->registerCallBackCTBReceiverReady(ctbRawDataReadyCallBack,pRawDataReady); +} + + void slsReceiverImplementation::SetLocalNetworkParameters() { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 8575ffb9a..602814fa3 100755 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -53,6 +53,7 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int pn): pAcquisitionFinished = nullptr; rawDataReadyCallBack = nullptr; rawDataModifyReadyCallBack = nullptr; + ctbRawDataReadyCallBack = nullptr; pRawDataReady = nullptr; // create socket @@ -130,7 +131,11 @@ void slsReceiverTCPIPInterface::registerCallBackRawDataModifyReady(void (*func)( pRawDataReady=arg; } - +void slsReceiverTCPIPInterface::registerCallBackCTBReceiverReady(void (*func)(char* , + char*, uint32_t &, int, int, int, void*),void *arg){ + ctbRawDataReadyCallBack=func; + pRawDataReady=arg; +} void* slsReceiverTCPIPInterface::startTCPServerThread(void *this_pointer){ ((slsReceiverTCPIPInterface*)this_pointer)->startTCPServer(); @@ -616,6 +621,8 @@ int slsReceiverTCPIPInterface::set_detector_type(){ receiver->registerCallBackRawDataReady(rawDataReadyCallBack,pRawDataReady); if(rawDataModifyReadyCallBack) receiver->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,pRawDataReady); + if(ctbRawDataReadyCallBack) + receiver->registerCallBackCTBReceiverReady(ctbRawDataReadyCallBack, pRawDataReady); // client has started updating receiver, update ip if (!lockStatus) diff --git a/slsReceiverSoftware/src/slsReceiverUsers.cpp b/slsReceiverSoftware/src/slsReceiverUsers.cpp index 572f5fe22..81343d093 100755 --- a/slsReceiverSoftware/src/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/src/slsReceiverUsers.cpp @@ -45,3 +45,9 @@ void slsReceiverUsers::registerCallBackRawDataModifyReady(void (*func)(char* hea char* datapointer, uint32_t& revDatasize, void*), void *arg){ receiver->registerCallBackRawDataModifyReady(func,arg); } + +void slsReceiverUsers::registerCallBackCTBReceiverReady(void (*func)(char* header, + char* datapointer, uint32_t& revDatasize, + int type, int digitalOffset, int analogDataBytes, void*), void *arg){ + receiver->registerCallBackCTBReceiverReady(func,arg); +}