receiver compiles

This commit is contained in:
2018-10-09 18:02:47 +02:00
parent 7d5b24fe33
commit 8151f1d5fe
16 changed files with 866 additions and 2284 deletions

View File

@ -1,825 +0,0 @@
//#ifdef SLS_RECEIVER_UDP_FUNCTIONS
/********************************************//**
* @file UDPBaseImplementation.cpp
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
***********************************************/
#include "UDPBaseImplementation.h"
#include <sys/stat.h> // stat
#include <iostream>
#include <string.h>
/*************************************************************************
* Constructor & Destructor **********************************************
* They access local cache of configuration or detector parameters *******
*************************************************************************/
UDPBaseImplementation::UDPBaseImplementation(){
FILE_LOG(logDEBUG) << __AT__ << " starting";
initializeMembers();
//***callback parameters***
startAcquisitionCallBack = NULL;
pStartAcquisition = NULL;
acquisitionFinishedCallBack = NULL;
pAcquisitionFinished = NULL;
rawDataReadyCallBack = NULL;
rawDataModifyReadyCallBack = NULL;
pRawDataReady = NULL;
}
void UDPBaseImplementation::initializeMembers(){
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG(logDEBUG) << "Info: Initializing base members";
//**detector parameters***
for (int i = 0; i < MAX_DIMENSIONS; ++i)
numDet[i] = 0;
detID = 0;
myDetectorType = GENERIC;
strcpy(detHostname,"");
acquisitionPeriod = 0;
acquisitionTime = 0;
subExpTime = 0;
subPeriod = 0;
numberOfFrames = 0;
numberOfSamples = 0;
dynamicRange = 16;
tengigaEnable = false;
fifoDepth = 0;
flippedData[0] = 0;
flippedData[1] = 0;
gapPixelsEnable = false;
//***receiver parameters***
status = IDLE;
activated = true;
deactivatedPaddingEnable = true;
frameDiscardMode = NO_DISCARD;
framePadding = false;
//***connection parameters***
strcpy(eth,"");
for(int i=0;i<MAX_NUMBER_OF_LISTENING_THREADS;i++){
udpPortNum[i] = DEFAULT_UDP_PORTNO + i;
}
udpSocketBufferSize = 0;
actualUDPSocketBufferSize = 0;
//***file parameters***
fileFormatType = BINARY;
strcpy(fileName,"run");
strcpy(filePath,"");
fileIndex = 0;
framesPerFile = 0;
scanTag = 0;
fileWriteEnable = true;
overwriteEnable = true;
dataCompressionEnable = false;
//***acquisition parameters***
roi.clear();
frameToGuiFrequency = 0;
frameToGuiTimerinMS = DEFAULT_STREAMING_TIMER_IN_MS;
dataStreamEnable = false;
streamingPort = 0;
memset(streamingSrcIP, 0, sizeof(streamingSrcIP));
memset(additionalJsonHeader, 0, sizeof(additionalJsonHeader));
//***receiver parameters***
silentMode = false;
}
UDPBaseImplementation::~UDPBaseImplementation(){}
/*************************************************************************
* Getters ***************************************************************
* They access local cache of configuration or detector parameters *******
*************************************************************************/
/**initial parameters***/
int* UDPBaseImplementation::getMultiDetectorSize() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return (int*) numDet;
}
int UDPBaseImplementation::getDetectorPositionId() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return detID;
}
char *UDPBaseImplementation::getDetectorHostname() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(detHostname))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,detHostname);
//freed by calling function
return output;
}
int UDPBaseImplementation::getFlippedData(int axis) const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(axis<0 || axis > 1) return -1;
return flippedData[axis];
}
bool UDPBaseImplementation::getGapPixelsEnable() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
return gapPixelsEnable;
}
/***file parameters***/
slsReceiverDefs::fileFormat UDPBaseImplementation::getFileFormat() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileFormatType;
}
char *UDPBaseImplementation::getFileName() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(fileName))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,fileName);
//freed by calling function
return output;
}
char *UDPBaseImplementation::getFilePath() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(filePath))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,filePath);
//freed by calling function
return output;
}
uint64_t UDPBaseImplementation::getFileIndex() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileIndex;
}
uint32_t UDPBaseImplementation::getFramesPerFile() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return framesPerFile;
}
slsReceiverDefs::frameDiscardPolicy UDPBaseImplementation::getFrameDiscardPolicy() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return frameDiscardMode;
}
bool UDPBaseImplementation::getFramePaddingEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return framePadding;
}
int UDPBaseImplementation::getScanTag() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return scanTag;
}
bool UDPBaseImplementation::getFileWriteEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileWriteEnable;
}
bool UDPBaseImplementation::getOverwriteEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return overwriteEnable;
}
bool UDPBaseImplementation::getDataCompressionEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return dataCompressionEnable;
}
/***acquisition count parameters***/
uint64_t UDPBaseImplementation::getTotalFramesCaught() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return 0;
}
uint64_t UDPBaseImplementation::getFramesCaught() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return 0;
}
int64_t UDPBaseImplementation::getAcquisitionIndex() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return -1;
}
/***connection parameters***/
uint32_t UDPBaseImplementation::getUDPPortNumber() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpPortNum[0];
}
uint32_t UDPBaseImplementation::getUDPPortNumber2() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpPortNum[1];
}
char *UDPBaseImplementation::getEthernetInterface() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,eth);
//freed by calling function
return output;
}
/***acquisition parameters***/
std::vector<slsReceiverDefs::ROI> UDPBaseImplementation::getROI() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return roi;
}
uint32_t UDPBaseImplementation::getFrameToGuiFrequency() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return frameToGuiFrequency;
}
uint32_t UDPBaseImplementation::getFrameToGuiTimer() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return frameToGuiTimerinMS;
}
bool UDPBaseImplementation::getDataStreamEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return dataStreamEnable;
}
uint64_t UDPBaseImplementation::getAcquisitionPeriod() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return acquisitionPeriod;
}
uint64_t UDPBaseImplementation::getAcquisitionTime() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return acquisitionTime;
}
uint64_t UDPBaseImplementation::getSubExpTime() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return subExpTime;
}
uint64_t UDPBaseImplementation::getSubPeriod() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return subPeriod;
}
uint64_t UDPBaseImplementation::getNumberOfFrames() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return numberOfFrames;
}
uint64_t UDPBaseImplementation::getNumberofSamples() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return numberOfSamples;
}
uint32_t UDPBaseImplementation::getDynamicRange() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return dynamicRange;}
bool UDPBaseImplementation::getTenGigaEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return tengigaEnable;
}
uint32_t UDPBaseImplementation::getFifoDepth() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fifoDepth;
}
/***receiver status***/
slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return status;}
bool UDPBaseImplementation::getSilentMode() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return silentMode;}
bool UDPBaseImplementation::getActivate() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return activated;
}
bool UDPBaseImplementation::getDeactivatedPadding() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return deactivatedPaddingEnable;
}
uint32_t UDPBaseImplementation::getStreamingPort() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return streamingPort;
}
char *UDPBaseImplementation::getStreamingSourceIP() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,streamingSrcIP);
//freed by calling function
return output;
}
char *UDPBaseImplementation::getAdditionalJsonHeader() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
memset(output, 0, MAX_STR_LENGTH);
strcpy(output,additionalJsonHeader);
//freed by calling function
return output;
}
uint32_t UDPBaseImplementation::getUDPSocketBufferSize() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpSocketBufferSize;
}
uint32_t UDPBaseImplementation::getActualUDPSocketBufferSize() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
return actualUDPSocketBufferSize;
}
/*************************************************************************
* Setters ***************************************************************
* They modify the local cache of configuration or detector parameters ***
*************************************************************************/
/**initial parameters***/
void UDPBaseImplementation::configure(std::map<std::string, std::string> config_map){
FILE_LOG(logERROR) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
}
void UDPBaseImplementation::setMultiDetectorSize(const int* size) {
FILE_LOG(logDEBUG) << __AT__ << " starting";
char message[100];
strcpy(message, "Detector Size: (");
for (int i = 0; i < MAX_DIMENSIONS; ++i) {
if (myDetectorType == EIGER && (!i))
numDet[i] = size[i]*2;
else
numDet[i] = size[i];
sprintf(message,"%s%d",message,numDet[i]);
if (i < MAX_DIMENSIONS-1 )
strcat(message,",");
}
strcat(message,")");
FILE_LOG(logINFO) << message;
}
void UDPBaseImplementation::setFlippedData(int axis, int enable){
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(axis<0 || axis>1) return;
flippedData[axis] = enable==0?0:1;
FILE_LOG(logINFO) << "Flipped Data: " << flippedData[0] << " , " << flippedData[1];
}
int UDPBaseImplementation::setGapPixelsEnable(const bool b) {
FILE_LOG(logDEBUG) << __AT__ << " starting";
gapPixelsEnable = b;
FILE_LOG(logINFO) << "Gap Pixels Enable: " << gapPixelsEnable;
// overridden
return OK;
}
/***file parameters***/
void UDPBaseImplementation::setFileFormat(const fileFormat f){
FILE_LOG(logDEBUG) << __AT__ << " starting";
switch(f){
#ifdef HDF5C
case HDF5:
fileFormatType = HDF5;
break;
#endif
default:
fileFormatType = BINARY;
break;
}
FILE_LOG(logINFO) << "File Format: " << getFileFormatType(fileFormatType);
}
void UDPBaseImplementation::setFileName(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(strlen(c))
strcpy(fileName, c);
FILE_LOG(logINFO) << "File name: " << fileName;
}
void UDPBaseImplementation::setFilePath(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(strlen(c)){
//check if filepath exists
struct stat st;
if(stat(c,&st) == 0)
strcpy(filePath,c);
else
FILE_LOG(logERROR) << "FilePath does not exist: " << filePath;
}
FILE_LOG(logINFO) << "File path: " << filePath;
}
void UDPBaseImplementation::setFileIndex(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
fileIndex = i;
FILE_LOG(logINFO) << "File Index: " << fileIndex;
}
void UDPBaseImplementation::setFramesPerFile(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
framesPerFile = i;
FILE_LOG(logINFO) << "Frames per file: " << framesPerFile;
}
void UDPBaseImplementation::setFrameDiscardPolicy(const frameDiscardPolicy i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
if (i >= 0 && i < NUM_DISCARD_POLICIES)
frameDiscardMode = i;
FILE_LOG(logINFO) << "Frame Discard Policy: " << getFrameDiscardPolicyType(frameDiscardMode);
}
void UDPBaseImplementation::setFramePaddingEnable(const bool i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
framePadding = i;
FILE_LOG(logINFO) << "Frame Padding: " << framePadding;
}
//FIXME: needed?
void UDPBaseImplementation::setScanTag(const int i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
scanTag = i;
FILE_LOG(logINFO) << "Scan Tag: " << scanTag;
}
void UDPBaseImplementation::setFileWriteEnable(const bool b){
FILE_LOG(logDEBUG) << __AT__ << " starting";
fileWriteEnable = b;
FILE_LOG(logINFO) << "File Write Enable: " << stringEnable(fileWriteEnable);
}
void UDPBaseImplementation::setOverwriteEnable(const bool b){
FILE_LOG(logDEBUG) << __AT__ << " starting";
overwriteEnable = b;
FILE_LOG(logINFO) << "Overwrite Enable: " << stringEnable(overwriteEnable);
}
int UDPBaseImplementation::setDataCompressionEnable(const bool b){
FILE_LOG(logDEBUG) << __AT__ << " starting";
dataCompressionEnable = b;
FILE_LOG(logINFO) << "Data Compression : " << stringEnable(dataCompressionEnable);
//overridden methods might return FAIL
return OK;
}
/***connection parameters***/
void UDPBaseImplementation::setUDPPortNumber(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
udpPortNum[0] = i;
FILE_LOG(logINFO) << "UDP Port Number[0]: " << udpPortNum[0];
}
void UDPBaseImplementation::setUDPPortNumber2(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
udpPortNum[1] = i;
FILE_LOG(logINFO) << "UDP Port Number[1]: " << udpPortNum[1];
}
void UDPBaseImplementation::setEthernetInterface(const char* c){
FILE_LOG(logDEBUG) << __AT__ << " starting";
strcpy(eth, c);
FILE_LOG(logINFO) << "Ethernet Interface: " << eth;
}
/***acquisition parameters***/
int UDPBaseImplementation::setROI(const std::vector<slsReceiverDefs::ROI> i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
roi = i;
std::stringstream sstm;
sstm << "ROI: ";
if (!roi.size())
sstm << "0";
else {
for (unsigned int i = 0; i < roi.size(); ++i) {
sstm << "( " <<
roi[i].xmin << ", " <<
roi[i].xmax << ", " <<
roi[i].ymin << ", " <<
roi[i].ymax << " )";
}
}
std::string message = sstm.str();
FILE_LOG(logINFO) << message;
//overrridden child classes might return FAIL
return OK;
}
int UDPBaseImplementation::setFrameToGuiFrequency(const uint32_t freq){
FILE_LOG(logDEBUG) << __AT__ << " starting";
frameToGuiFrequency = freq;
FILE_LOG(logINFO) << "Frame To Gui Frequency: " << frameToGuiFrequency;
//overrridden child classes might return FAIL
return OK;
}
void UDPBaseImplementation::setFrameToGuiTimer(const uint32_t time_in_ms){
FILE_LOG(logDEBUG) << __AT__ << " starting";
frameToGuiTimerinMS = time_in_ms;
FILE_LOG(logINFO) << "Frame To Gui Timer: " << frameToGuiTimerinMS;
}
int UDPBaseImplementation::setDataStreamEnable(const bool enable){
FILE_LOG(logDEBUG) << __AT__ << " starting";
dataStreamEnable = enable;
FILE_LOG(logINFO) << "Streaming Data from Receiver: " << dataStreamEnable;
//overrridden child classes might return FAIL
return OK;
}
int UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
acquisitionPeriod = i;
FILE_LOG(logINFO) << "Acquisition Period: " << (double)acquisitionPeriod/(1E9) << "s";
//overrridden child classes might return FAIL
return OK;
}
int UDPBaseImplementation::setAcquisitionTime(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
acquisitionTime = i;
FILE_LOG(logINFO) << "Acquisition Time: " << (double)acquisitionTime/(1E9) << "s";
//overrridden child classes might return FAIL
return OK;
}
void UDPBaseImplementation::setSubExpTime(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
subExpTime = i;
FILE_LOG(logINFO) << "Sub Exposure Time: " << (double)subExpTime/(1E9) << "s";
}
void UDPBaseImplementation::setSubPeriod(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
subPeriod = i;
FILE_LOG(logINFO) << "Sub Exposure Time: " << (double)subPeriod/(1E9) << "s";
}
int UDPBaseImplementation::setNumberOfFrames(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
numberOfFrames = i;
FILE_LOG(logINFO) << "Number of Frames: " << numberOfFrames;
//overrridden child classes might return FAIL
return OK;
}
int UDPBaseImplementation::setNumberofSamples(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
numberOfSamples = i;
FILE_LOG(logINFO) << "Number of Samples: " << numberOfSamples;
//overrridden child classes might return FAIL
return OK;
}
int UDPBaseImplementation::setDynamicRange(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
dynamicRange = i;
FILE_LOG(logINFO) << "Dynamic Range: " << dynamicRange;
//overrridden child classes might return FAIL
return OK;
}
int UDPBaseImplementation::setTenGigaEnable(const bool b){
FILE_LOG(logDEBUG) << __AT__ << " starting";
tengigaEnable = b;
FILE_LOG(logINFO) << "Ten Giga Enable: " << stringEnable(tengigaEnable);
//overridden functions might return FAIL
return OK;
}
int UDPBaseImplementation::setFifoDepth(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
fifoDepth = i;
FILE_LOG(logINFO) << "Fifo Depth: " << i;
//overridden functions might return FAIL
return OK;
}
/***receiver parameters***/
void UDPBaseImplementation::setSilentMode(const bool i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
silentMode = i;
FILE_LOG(logINFO) << "Silent Mode: " << i;
}
/*************************************************************************
* Behavioral functions***************************************************
* They may modify the status of the receiver ****************************
*************************************************************************/
/***initial functions***/
int UDPBaseImplementation::setDetectorType(const detectorType d){
FILE_LOG(logDEBUG) << __AT__ << " starting";
myDetectorType = d;
//if eiger, set numberofListeningThreads = 2;
FILE_LOG(logINFO) << "Detector Type: " << getDetectorType(d);
return OK;
}
void UDPBaseImplementation::setDetectorPositionId(const int i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
detID = i;
FILE_LOG(logINFO) << "Detector Position Id: " << detID;
}
void UDPBaseImplementation::initialize(const char *c){
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(strlen(c))
strcpy(detHostname, c);
FILE_LOG(logINFO) << "Detector Hostname: " << detHostname;
}
/***acquisition functions***/
void UDPBaseImplementation::resetAcquisitionCount(){
FILE_LOG(logDEBUG) << __AT__ << " starting";
//overriden by resetting of new acquisition parameters
}
int UDPBaseImplementation::startReceiver(char *c){
FILE_LOG(logERROR) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
return OK;
}
void UDPBaseImplementation::stopReceiver(){
FILE_LOG(logERROR) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
}
void UDPBaseImplementation::startReadout(){
FILE_LOG(logERROR) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
}
void UDPBaseImplementation::shutDownUDPSockets(){
FILE_LOG(logERROR) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
}
//FIXME: needed, isnt stopReceiver enough?
void UDPBaseImplementation::abort(){
FILE_LOG(logERROR) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
}
bool UDPBaseImplementation::setActivate(bool enable){
FILE_LOG(logDEBUG) << __AT__ << " starting";
activated = enable;
FILE_LOG(logINFO) << "Activation: " << stringEnable(activated);
return activated;
}
bool UDPBaseImplementation::setDeactivatedPadding(bool enable){
FILE_LOG(logDEBUG) << __AT__ << " starting";
deactivatedPaddingEnable = enable;
FILE_LOG(logINFO) << "Deactivated Padding Enable: " << stringEnable(deactivatedPaddingEnable);
return deactivatedPaddingEnable;
}
void UDPBaseImplementation::setStreamingPort(const uint32_t i) {
streamingPort = i;
FILE_LOG(logINFO) << "Streaming Port: " << streamingPort;
}
void UDPBaseImplementation::setStreamingSourceIP(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
strcpy(streamingSrcIP, c);
FILE_LOG(logINFO) << "Streaming Source IP: " << streamingSrcIP;
}
void UDPBaseImplementation::setAdditionalJsonHeader(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
strcpy(additionalJsonHeader, c);
FILE_LOG(logINFO) << "Additional JSON Header: " << additionalJsonHeader;
}
int UDPBaseImplementation::setUDPSocketBufferSize(const uint32_t s) {
FILE_LOG(logDEBUG) << __AT__ << " starting";
udpSocketBufferSize = s;
return OK;
}
int UDPBaseImplementation::restreamStop() {
FILE_LOG(logERROR) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
return OK;
}
/***callback functions***/
void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg){
startAcquisitionCallBack=func;
pStartAcquisition=arg;
}
void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){
acquisitionFinishedCallBack=func;
pAcquisitionFinished=arg;
}
void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(char* ,
char*, uint32_t, void*),void *arg){
rawDataReadyCallBack=func;
pRawDataReady=arg;
}
void UDPBaseImplementation::registerCallBackRawDataModifyReady(void (*func)(char* ,
char*, uint32_t&, void*),void *arg){
rawDataModifyReadyCallBack=func;
pRawDataReady=arg;
}
//#endif

View File

@ -1,30 +0,0 @@
//#ifdef SLS_RECEIVER_UDP_FUNCTIONS
/********************************************//**
* @file slsReceiverUDPFunctions.cpp
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
***********************************************/
#include <iostream>
#include <string.h>
#include "UDPInterface.h"
#include "UDPBaseImplementation.h"
#include "UDPStandardImplementation.h"
UDPInterface * UDPInterface::create(std::string receiver_type){
if (receiver_type == "standard"){
FILE_LOG(logINFO) << "Starting " << receiver_type;
return new UDPStandardImplementation();
}
else{
FILE_LOG(logERROR) << "UDP interface not supported, using base implementation";
return new UDPBaseImplementation();
}
}
//#endif

View File

@ -11,11 +11,12 @@
#include <map>
#include <getopt.h>
#include "slsReceiver.h"
#include "slsReceiverTCPIPInterface.h"
#include "gitInfoReceiver.h"
#include "logger.h"
#include "utilities.h"
slsReceiver::slsReceiver(int argc, char *argv[]):
tcpipInterface (0) {

View File

@ -1,10 +1,10 @@
/********************************************//**
* @file UDPStandardImplementation.cpp
* @file slsReceiverImplementation.cpp
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
***********************************************/
#include "UDPStandardImplementation.h"
#include "slsReceiverImplementation.h"
#include "GeneralData.h"
#include "Listener.h"
#include "DataProcessor.h"
@ -12,6 +12,9 @@
#include "Fifo.h"
#include "ZmqSocket.h" //just for the zmq port define
#include <sys/stat.h> // stat
#include <iostream>
#include <string.h>
#include <cstdlib> //system
#include <cstring> //strcpy
#include <errno.h> //eperm
@ -20,51 +23,218 @@
/** cosntructor & destructor */
UDPStandardImplementation::UDPStandardImplementation() {
slsReceiverImplementation::slsReceiverImplementation() {
InitializeMembers();
}
UDPStandardImplementation::~UDPStandardImplementation() {
slsReceiverImplementation::~slsReceiverImplementation() {
DeleteMembers();
}
void UDPStandardImplementation::DeleteMembers() {
if (generalData) { delete generalData; generalData=0;}
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
delete(*it);
void slsReceiverImplementation::DeleteMembers() {
if (generalData) {
delete generalData;
generalData=0;
}
for (auto* it : listener)
delete it;
listener.clear();
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
delete(*it);
for (auto* it : dataProcessor)
delete it;
dataProcessor.clear();
for (std::vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
delete(*it);
for (auto* it : dataStreamer)
delete it;
dataStreamer.clear();
for (std::vector<Fifo*>::const_iterator it = fifo.begin(); it != fifo.end(); ++it)
delete(*it);
for (auto* it : fifo)
delete it;
fifo.clear();
}
void UDPStandardImplementation::InitializeMembers() {
UDPBaseImplementation::initializeMembers();
void slsReceiverImplementation::InitializeMembers() {
//**detector parameters***
myDetectorType = GENERIC;
for (int i = 0; i < MAX_DIMENSIONS; ++i)
numDet[i] = 0;
detID = 0;
strcpy(detHostname,"");
acquisitionPeriod = SAMPLE_TIME_IN_NS;
acquisitionTime = 0;
subExpTime = 0;
subPeriod = 0;
numberOfFrames = 0;
numberOfSamples = 0;
dynamicRange = 16;
tengigaEnable = false;
fifoDepth = 0;
flippedData[0] = 0;
flippedData[1] = 0;
gapPixelsEnable = false;
//*** receiver parameters ***
numThreads = 1;
numberofJobs = 1;
nroichannels = 0;
status = IDLE;
activated = true;
deactivatedPaddingEnable = true;
frameDiscardMode = NO_DISCARD;
framePadding = false;
silentMode = false;
//***connection parameters***
strcpy(eth,"");
for(int i=0;i<MAX_NUMBER_OF_LISTENING_THREADS;i++){
udpPortNum[i] = DEFAULT_UDP_PORTNO + i;
}
udpSocketBufferSize = 0;
actualUDPSocketBufferSize = 0;
//***file parameters***
fileFormatType = BINARY;
strcpy(fileName,"run");
strcpy(filePath,"");
fileIndex = 0;
framesPerFile = 0;
fileWriteEnable = true;
overwriteEnable = true;
//***acquisition parameters***
roi.clear();
streamingFrequency = 0;
streamingTimerInMs = DEFAULT_STREAMING_TIMER_IN_MS;
dataStreamEnable = false;
streamingPort = 0;
memset(streamingSrcIP, 0, sizeof(streamingSrcIP));
memset(additionalJsonHeader, 0, sizeof(additionalJsonHeader));
//** class objects ***
generalData = 0;
//***callback parameters***
startAcquisitionCallBack = NULL;
pStartAcquisition = NULL;
acquisitionFinishedCallBack = NULL;
pAcquisitionFinished = NULL;
rawDataReadyCallBack = NULL;
rawDataModifyReadyCallBack = NULL;
pRawDataReady = NULL;
}
/*************************************************************************
* Getters ***************************************************************
* They access local cache of configuration or detector parameters *******
*************************************************************************/
/**initial parameters***/
int* slsReceiverImplementation::getMultiDetectorSize() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return (int*) numDet;
}
int slsReceiverImplementation::getDetectorPositionId() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return detID;
}
char *slsReceiverImplementation::getDetectorHostname() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(detHostname))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,detHostname);
//freed by calling function
return output;
}
int slsReceiverImplementation::getFlippedData(int axis) const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(axis<0 || axis > 1) return -1;
return flippedData[axis];
}
bool slsReceiverImplementation::getGapPixelsEnable() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
return gapPixelsEnable;
}
/***file parameters***/
slsReceiverDefs::fileFormat slsReceiverImplementation::getFileFormat() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileFormatType;
}
char *slsReceiverImplementation::getFileName() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
/*** Overloaded Functions called by TCP Interface ***/
//not initialized
if(!strlen(fileName))
return NULL;
uint64_t UDPStandardImplementation::getTotalFramesCaught() const {
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,fileName);
//freed by calling function
return output;
}
char *slsReceiverImplementation::getFilePath() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(filePath))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,filePath);
//freed by calling function
return output;
}
uint64_t slsReceiverImplementation::getFileIndex() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileIndex;
}
uint32_t slsReceiverImplementation::getFramesPerFile() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return framesPerFile;
}
slsReceiverDefs::frameDiscardPolicy slsReceiverImplementation::getFrameDiscardPolicy() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return frameDiscardMode;
}
bool slsReceiverImplementation::getFramePaddingEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return framePadding;
}
bool slsReceiverImplementation::getFileWriteEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileWriteEnable;
}
bool slsReceiverImplementation::getOverwriteEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return overwriteEnable;
}
/***acquisition count parameters***/
uint64_t slsReceiverImplementation::getTotalFramesCaught() const {
uint64_t sum = 0;
uint32_t flagsum = 0;
@ -80,7 +250,7 @@ uint64_t UDPStandardImplementation::getTotalFramesCaught() const {
return (sum/dataProcessor.size());
}
uint64_t UDPStandardImplementation::getFramesCaught() const {
uint64_t slsReceiverImplementation::getFramesCaught() const {
uint64_t sum = 0;
uint32_t flagsum = 0;
@ -95,7 +265,7 @@ uint64_t UDPStandardImplementation::getFramesCaught() const {
return (sum/dataProcessor.size());
}
int64_t UDPStandardImplementation::getAcquisitionIndex() const {
int64_t slsReceiverImplementation::getAcquisitionIndex() const {
uint64_t sum = 0;
uint32_t flagsum = 0;
@ -112,7 +282,190 @@ int64_t UDPStandardImplementation::getAcquisitionIndex() const {
int UDPStandardImplementation::setGapPixelsEnable(const bool b) {
/***connection parameters***/
uint32_t slsReceiverImplementation::getUDPPortNumber() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpPortNum[0];
}
uint32_t slsReceiverImplementation::getUDPPortNumber2() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpPortNum[1];
}
char *slsReceiverImplementation::getEthernetInterface() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,eth);
//freed by calling function
return output;
}
/***acquisition parameters***/
std::vector<slsReceiverDefs::ROI> slsReceiverImplementation::getROI() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return roi;
}
uint32_t slsReceiverImplementation::getStreamingFrequency() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return streamingFrequency;
}
uint32_t slsReceiverImplementation::getStreamingTimer() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return streamingTimerInMs;
}
bool slsReceiverImplementation::getDataStreamEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return dataStreamEnable;
}
uint64_t slsReceiverImplementation::getAcquisitionPeriod() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return acquisitionPeriod;
}
uint64_t slsReceiverImplementation::getAcquisitionTime() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return acquisitionTime;
}
uint64_t slsReceiverImplementation::getSubExpTime() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return subExpTime;
}
uint64_t slsReceiverImplementation::getSubPeriod() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return subPeriod;
}
uint64_t slsReceiverImplementation::getNumberOfFrames() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return numberOfFrames;
}
uint64_t slsReceiverImplementation::getNumberofSamples() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return numberOfSamples;
}
uint32_t slsReceiverImplementation::getDynamicRange() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return dynamicRange;}
bool slsReceiverImplementation::getTenGigaEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return tengigaEnable;
}
uint32_t slsReceiverImplementation::getFifoDepth() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fifoDepth;
}
/***receiver status***/
slsReceiverDefs::runStatus slsReceiverImplementation::getStatus() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return status;}
bool slsReceiverImplementation::getSilentMode() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return silentMode;}
bool slsReceiverImplementation::getActivate() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return activated;
}
bool slsReceiverImplementation::getDeactivatedPadding() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return deactivatedPaddingEnable;
}
uint32_t slsReceiverImplementation::getStreamingPort() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return streamingPort;
}
char *slsReceiverImplementation::getStreamingSourceIP() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,streamingSrcIP);
//freed by calling function
return output;
}
char *slsReceiverImplementation::getAdditionalJsonHeader() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
memset(output, 0, MAX_STR_LENGTH);
strcpy(output,additionalJsonHeader);
//freed by calling function
return output;
}
uint32_t slsReceiverImplementation::getUDPSocketBufferSize() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpSocketBufferSize;
}
uint32_t slsReceiverImplementation::getActualUDPSocketBufferSize() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
return actualUDPSocketBufferSize;
}
/*************************************************************************
* Setters ***************************************************************
* They modify the local cache of configuration or detector parameters ***
*************************************************************************/
/**initial parameters***/
void slsReceiverImplementation::setDetectorHostname(const char *c){
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(strlen(c))
strcpy(detHostname, c);
FILE_LOG(logINFO) << "Detector Hostname: " << detHostname;
}
void slsReceiverImplementation::setMultiDetectorSize(const int* size) {
FILE_LOG(logDEBUG) << __AT__ << " starting";
char message[100];
strcpy(message, "Detector Size: (");
for (int i = 0; i < MAX_DIMENSIONS; ++i) {
if (myDetectorType == EIGER && (!i))
numDet[i] = size[i]*2;
else
numDet[i] = size[i];
sprintf(message,"%s%d",message,numDet[i]);
if (i < MAX_DIMENSIONS-1 )
strcat(message,",");
}
strcat(message,")");
FILE_LOG(logINFO) << message;
}
void slsReceiverImplementation::setFlippedData(int axis, int enable){
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(axis<0 || axis>1) return;
flippedData[axis] = enable==0?0:1;
FILE_LOG(logINFO) << "Flipped Data: " << flippedData[0] << " , " << flippedData[1];
}
int slsReceiverImplementation::setGapPixelsEnable(const bool b) {
if (gapPixelsEnable != b) {
gapPixelsEnable = b;
@ -131,7 +484,7 @@ int UDPStandardImplementation::setGapPixelsEnable(const bool b) {
}
void UDPStandardImplementation::setFileFormat(const fileFormat f){
void slsReceiverImplementation::setFileFormat(const fileFormat f){
switch(f){
#ifdef HDF5C
case HDF5:
@ -150,7 +503,66 @@ void UDPStandardImplementation::setFileFormat(const fileFormat f){
}
void UDPStandardImplementation::setFileWriteEnable(const bool b){
void slsReceiverImplementation::setFileName(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(strlen(c))
strcpy(fileName, c);
FILE_LOG(logINFO) << "File name: " << fileName;
}
void slsReceiverImplementation::setFilePath(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(strlen(c)){
//check if filepath exists
struct stat st;
if(stat(c,&st) == 0)
strcpy(filePath,c);
else
FILE_LOG(logERROR) << "FilePath does not exist: " << filePath;
}
FILE_LOG(logINFO) << "File path: " << filePath;
}
void slsReceiverImplementation::setFileIndex(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
fileIndex = i;
FILE_LOG(logINFO) << "File Index: " << fileIndex;
}
void slsReceiverImplementation::setFramesPerFile(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
framesPerFile = i;
FILE_LOG(logINFO) << "Frames per file: " << framesPerFile;
}
void slsReceiverImplementation::setFrameDiscardPolicy(const frameDiscardPolicy i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
if (i >= 0 && i < NUM_DISCARD_POLICIES)
frameDiscardMode = i;
FILE_LOG(logINFO) << "Frame Discard Policy: " << getFrameDiscardPolicyType(frameDiscardMode);
}
void slsReceiverImplementation::setFramePaddingEnable(const bool i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
framePadding = i;
FILE_LOG(logINFO) << "Frame Padding: " << framePadding;
}
void slsReceiverImplementation::setFileWriteEnable(const bool b){
if (fileWriteEnable != b){
fileWriteEnable = b;
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
@ -165,9 +577,45 @@ void UDPStandardImplementation::setFileWriteEnable(const bool b){
}
void slsReceiverImplementation::setOverwriteEnable(const bool b){
FILE_LOG(logDEBUG) << __AT__ << " starting";
overwriteEnable = b;
FILE_LOG(logINFO) << "Overwrite Enable: " << stringEnable(overwriteEnable);
}
int UDPStandardImplementation::setROI(const std::vector<slsReceiverDefs::ROI> i) {
/***connection parameters***/
void slsReceiverImplementation::setUDPPortNumber(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
udpPortNum[0] = i;
FILE_LOG(logINFO) << "UDP Port Number[0]: " << udpPortNum[0];
}
void slsReceiverImplementation::setUDPPortNumber2(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
udpPortNum[1] = i;
FILE_LOG(logINFO) << "UDP Port Number[1]: " << udpPortNum[1];
}
void slsReceiverImplementation::setEthernetInterface(const char* c){
FILE_LOG(logDEBUG) << __AT__ << " starting";
strcpy(eth, c);
FILE_LOG(logINFO) << "Ethernet Interface: " << eth;
}
int slsReceiverImplementation::setUDPSocketBufferSize(const uint32_t s) {
if (listener.size())
return listener[0]->CreateDummySocketForUDPSocketBufferSize(s);
return FAIL;
}
/***acquisition parameters***/
int slsReceiverImplementation::setROI(const std::vector<slsReceiverDefs::ROI> i) {
if (myDetectorType != GOTTHARD) {
cprintf(RED, "Error: Can not set ROI for this detector\n");
return FAIL;
@ -229,16 +677,23 @@ int UDPStandardImplementation::setROI(const std::vector<slsReceiverDefs::ROI> i)
}
int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t freq) {
if (frameToGuiFrequency != freq) {
frameToGuiFrequency = freq;
int slsReceiverImplementation::setStreamingFrequency(const uint32_t freq) {
if (streamingFrequency != freq) {
streamingFrequency = freq;
}
FILE_LOG(logINFO) << "Frame to Gui Frequency: " << frameToGuiFrequency;
FILE_LOG(logINFO) << "Streaming Frequency: " << streamingFrequency;
return OK;
}
void slsReceiverImplementation::setStreamingTimer(const uint32_t time_in_ms){
FILE_LOG(logDEBUG) << __AT__ << " starting";
int UDPStandardImplementation::setDataStreamEnable(const bool enable) {
streamingTimerInMs = time_in_ms;
FILE_LOG(logINFO) << "Streamer Timer: " << streamingTimerInMs;
}
int slsReceiverImplementation::setDataStreamEnable(const bool enable) {
if (dataStreamEnable != enable) {
dataStreamEnable = enable;
@ -273,8 +728,73 @@ int UDPStandardImplementation::setDataStreamEnable(const bool enable) {
}
void slsReceiverImplementation::setStreamingPort(const uint32_t i) {
streamingPort = i;
int UDPStandardImplementation::setNumberofSamples(const uint64_t i) {
FILE_LOG(logINFO) << "Streaming Port: " << streamingPort;
}
void slsReceiverImplementation::setStreamingSourceIP(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
strcpy(streamingSrcIP, c);
FILE_LOG(logINFO) << "Streaming Source IP: " << streamingSrcIP;
}
void slsReceiverImplementation::setAdditionalJsonHeader(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
strcpy(additionalJsonHeader, c);
FILE_LOG(logINFO) << "Additional JSON Header: " << additionalJsonHeader;
}
int slsReceiverImplementation::setAcquisitionPeriod(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
acquisitionPeriod = i;
FILE_LOG(logINFO) << "Acquisition Period: " << (double)acquisitionPeriod/(1E9) << "s";
//overrridden child classes might return FAIL
return OK;
}
int slsReceiverImplementation::setAcquisitionTime(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
acquisitionTime = i;
FILE_LOG(logINFO) << "Acquisition Time: " << (double)acquisitionTime/(1E9) << "s";
//overrridden child classes might return FAIL
return OK;
}
void slsReceiverImplementation::setSubExpTime(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
subExpTime = i;
FILE_LOG(logINFO) << "Sub Exposure Time: " << (double)subExpTime/(1E9) << "s";
}
void slsReceiverImplementation::setSubPeriod(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
subPeriod = i;
FILE_LOG(logINFO) << "Sub Exposure Time: " << (double)subPeriod/(1E9) << "s";
}
int slsReceiverImplementation::setNumberOfFrames(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
numberOfFrames = i;
FILE_LOG(logINFO) << "Number of Frames: " << numberOfFrames;
//overrridden child classes might return FAIL
return OK;
}
int slsReceiverImplementation::setNumberofSamples(const uint64_t i) {
if (numberOfSamples != i) {
numberOfSamples = i;
@ -289,7 +809,7 @@ int UDPStandardImplementation::setNumberofSamples(const uint64_t i) {
}
int UDPStandardImplementation::setDynamicRange(const uint32_t i) {
int slsReceiverImplementation::setDynamicRange(const uint32_t i) {
if (dynamicRange != i) {
dynamicRange = i;
@ -309,7 +829,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i) {
}
int UDPStandardImplementation::setTenGigaEnable(const bool b) {
int slsReceiverImplementation::setTenGigaEnable(const bool b) {
if (tengigaEnable != b) {
tengigaEnable = b;
//side effects
@ -324,7 +844,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b) {
}
int UDPStandardImplementation::setFifoDepth(const uint32_t i) {
int slsReceiverImplementation::setFifoDepth(const uint32_t i) {
if (fifoDepth != i) {
fifoDepth = i;
@ -337,8 +857,38 @@ int UDPStandardImplementation::setFifoDepth(const uint32_t i) {
}
/***receiver parameters***/
bool slsReceiverImplementation::setActivate(bool enable){
FILE_LOG(logDEBUG) << __AT__ << " starting";
activated = enable;
FILE_LOG(logINFO) << "Activation: " << stringEnable(activated);
return activated;
}
int UDPStandardImplementation::setDetectorType(const detectorType d) {
bool slsReceiverImplementation::setDeactivatedPadding(bool enable){
FILE_LOG(logDEBUG) << __AT__ << " starting";
deactivatedPaddingEnable = enable;
FILE_LOG(logINFO) << "Deactivated Padding Enable: " << stringEnable(deactivatedPaddingEnable);
return deactivatedPaddingEnable;
}
void slsReceiverImplementation::setSilentMode(const bool i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
silentMode = i;
FILE_LOG(logINFO) << "Silent Mode: " << i;
}
/*************************************************************************
* Behavioral functions***************************************************
* They may modify the status of the receiver ****************************
*************************************************************************/
/***initial functions***/
int slsReceiverImplementation::setDetectorType(const detectorType d) {
FILE_LOG(logDEBUG) << "Setting receiver type";
DeleteMembers();
InitializeMembers();
@ -395,7 +945,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
DataProcessor* p = new DataProcessor(i, myDetectorType, fifo[i], &fileFormatType,
fileWriteEnable, &dataStreamEnable, &gapPixelsEnable,
&dynamicRange, &frameToGuiFrequency, &frameToGuiTimerinMS,
&dynamicRange, &streamingFrequency, &streamingTimerInMs,
&framePadding, &activated, &deactivatedPaddingEnable, &silentMode,
rawDataReadyCallBack, rawDataModifyReadyCallBack, pRawDataReady);
dataProcessor.push_back(p);
@ -430,7 +980,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
void UDPStandardImplementation::setDetectorPositionId(const int i){
void slsReceiverImplementation::setDetectorPositionId(const int i){
detID = i;
FILE_LOG(logINFO) << "Detector Position Id:" << detID;
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
@ -449,7 +999,8 @@ void UDPStandardImplementation::setDetectorPositionId(const int i){
}
void UDPStandardImplementation::resetAcquisitionCount() {
/***acquisition functions***/
void slsReceiverImplementation::resetAcquisitionCount() {
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->ResetParametersforNewAcquisition();
@ -464,7 +1015,7 @@ void UDPStandardImplementation::resetAcquisitionCount() {
int UDPStandardImplementation::startReceiver(char *c) {
int slsReceiverImplementation::startReceiver(char *c) {
cprintf(RESET,"\n");
FILE_LOG(logINFO) << "Starting Receiver";
ResetParametersforNewMeasurement();
@ -510,7 +1061,7 @@ int UDPStandardImplementation::startReceiver(char *c) {
void UDPStandardImplementation::stopReceiver(){
void slsReceiverImplementation::stopReceiver(){
FILE_LOG(logINFO) << "Stopping Receiver";
//set status to transmitting
@ -591,7 +1142,7 @@ void UDPStandardImplementation::stopReceiver(){
void UDPStandardImplementation::startReadout(){
void slsReceiverImplementation::startReadout(){
if(status == RUNNING){
// wait for incoming delayed packets
@ -634,14 +1185,14 @@ void UDPStandardImplementation::startReadout(){
}
void UDPStandardImplementation::shutDownUDPSockets() {
void slsReceiverImplementation::shutDownUDPSockets() {
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->ShutDownUDPSocket();
}
void UDPStandardImplementation::closeFiles() {
void slsReceiverImplementation::closeFiles() {
uint64_t maxIndexCaught = 0;
bool anycaught = false;
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
@ -654,13 +1205,8 @@ void UDPStandardImplementation::closeFiles() {
dataProcessor[0]->EndofAcquisition(anycaught, maxIndexCaught);
}
int UDPStandardImplementation::setUDPSocketBufferSize(const uint32_t s) {
if (listener.size())
return listener[0]->CreateDummySocketForUDPSocketBufferSize(s);
return FAIL;
}
int UDPStandardImplementation::restreamStop() {
int slsReceiverImplementation::restreamStop() {
bool ret = OK;
for (std::vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it) {
if ((*it)->RestreamStop() == FAIL)
@ -676,7 +1222,32 @@ int UDPStandardImplementation::restreamStop() {
}
void UDPStandardImplementation::SetLocalNetworkParameters() {
/***callback functions***/
void slsReceiverImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg){
startAcquisitionCallBack=func;
pStartAcquisition=arg;
}
void slsReceiverImplementation::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){
acquisitionFinishedCallBack=func;
pAcquisitionFinished=arg;
}
void slsReceiverImplementation::registerCallBackRawDataReady(void (*func)(char* ,
char*, uint32_t, void*),void *arg){
rawDataReadyCallBack=func;
pRawDataReady=arg;
}
void slsReceiverImplementation::registerCallBackRawDataModifyReady(void (*func)(char* ,
char*, uint32_t&, void*),void *arg){
rawDataModifyReadyCallBack=func;
pRawDataReady=arg;
}
void slsReceiverImplementation::SetLocalNetworkParameters() {
// to increase Max length of input packet queue
int max_back_log;
@ -703,7 +1274,7 @@ void UDPStandardImplementation::SetLocalNetworkParameters() {
void UDPStandardImplementation::SetThreadPriorities() {
void slsReceiverImplementation::SetThreadPriorities() {
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it){
if ((*it)->SetThreadPriority(LISTENER_PRIORITY) == FAIL) {
@ -719,7 +1290,7 @@ void UDPStandardImplementation::SetThreadPriorities() {
}
int UDPStandardImplementation::SetupFifoStructure() {
int slsReceiverImplementation::SetupFifoStructure() {
numberofJobs = 1;
@ -754,7 +1325,7 @@ int UDPStandardImplementation::SetupFifoStructure() {
void UDPStandardImplementation::ResetParametersforNewMeasurement() {
void slsReceiverImplementation::ResetParametersforNewMeasurement() {
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->ResetParametersforNewMeasurement();
for (std::vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
@ -770,7 +1341,7 @@ void UDPStandardImplementation::ResetParametersforNewMeasurement() {
int UDPStandardImplementation::CreateUDPSockets() {
int slsReceiverImplementation::CreateUDPSockets() {
bool error = false;
for (unsigned int i = 0; i < listener.size(); ++i)
if (listener[i]->CreateUDPSockets() == FAIL) {
@ -787,7 +1358,7 @@ int UDPStandardImplementation::CreateUDPSockets() {
}
int UDPStandardImplementation::SetupWriter() {
int slsReceiverImplementation::SetupWriter() {
bool error = false;
for (unsigned int i = 0; i < dataProcessor.size(); ++i)
if (dataProcessor[i]->CreateNewFile(tengigaEnable,
@ -805,7 +1376,7 @@ int UDPStandardImplementation::SetupWriter() {
}
void UDPStandardImplementation::StartRunning() {
void slsReceiverImplementation::StartRunning() {
//set running mask and post semaphore to start the inner loop in execution thread
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it) {
(*it)->StartRunning();

View File

@ -4,7 +4,8 @@
***********************************************/
#include "slsReceiverTCPIPInterface.h"
#include "UDPInterface.h"
#include "slsReceiverImplementation.h"
#include "MySocketTCP.h"
#include "gitInfoReceiver.h"
#include "slsReceiverUsers.h"
#include "slsReceiver.h"
@ -210,11 +211,10 @@ const char* slsReceiverTCPIPInterface::getFunctionName(enum recFuncs func) {
case F_SETUP_RECEIVER_UDP: return "F_SETUP_RECEIVER_UDP";
case F_SET_RECEIVER_TIMER: return "F_SET_RECEIVER_TIMER";
case F_SET_RECEIVER_DYNAMIC_RANGE: return "F_SET_RECEIVER_DYNAMIC_RANGE";
case F_READ_RECEIVER_FREQUENCY: return "F_READ_RECEIVER_FREQUENCY";
case F_RECEIVER_STREAMING_FREQUENCY:return "F_RECEIVER_STREAMING_FREQUENCY";
case F_GET_RECEIVER_STATUS: return "F_GET_RECEIVER_STATUS";
case F_START_RECEIVER: return "F_START_RECEIVER";
case F_STOP_RECEIVER: return "F_STOP_RECEIVER";
case F_START_RECEIVER_READOUT: return "F_START_RECEIVER_READOUT";
case F_SET_RECEIVER_FILE_PATH: return "F_SET_RECEIVER_FILE_PATH";
case F_SET_RECEIVER_FILE_NAME: return "F_SET_RECEIVER_FILE_NAME";
case F_SET_RECEIVER_FILE_INDEX: return "F_SET_RECEIVER_FILE_INDEX";
@ -222,20 +222,19 @@ const char* slsReceiverTCPIPInterface::getFunctionName(enum recFuncs func) {
case F_GET_RECEIVER_FRAMES_CAUGHT: return "F_GET_RECEIVER_FRAMES_CAUGHT";
case F_RESET_RECEIVER_FRAMES_CAUGHT:return "F_RESET_RECEIVER_FRAMES_CAUGHT";
case F_ENABLE_RECEIVER_FILE_WRITE: return "F_ENABLE_RECEIVER_FILE_WRITE";
case F_ENABLE_RECEIVER_COMPRESSION: return "F_ENABLE_RECEIVER_COMPRESSION";
case F_ENABLE_RECEIVER_OVERWRITE: return "F_ENABLE_RECEIVER_OVERWRITE";
case F_ENABLE_RECEIVER_TEN_GIGA: return "F_ENABLE_RECEIVER_TEN_GIGA";
case F_SET_RECEIVER_FIFO_DEPTH: return "F_SET_RECEIVER_FIFO_DEPTH";
case F_RECEIVER_ACTIVATE: return "F_RECEIVER_ACTIVATE";
case F_STREAM_DATA_FROM_RECEIVER: return "F_STREAM_DATA_FROM_RECEIVER";
case F_READ_RECEIVER_TIMER: return "F_READ_RECEIVER_TIMER";
case F_RECEIVER_STREAMING_TIMER: return "F_RECEIVER_STREAMING_TIMER";
case F_SET_FLIPPED_DATA_RECEIVER: return "F_SET_FLIPPED_DATA_RECEIVER";
case F_SET_RECEIVER_FILE_FORMAT: return "F_SET_RECEIVER_FILE_FORMAT";
case F_SEND_RECEIVER_DETPOSID: return "F_SEND_RECEIVER_DETPOSID";
case F_SEND_RECEIVER_MULTIDETSIZE: return "F_SEND_RECEIVER_MULTIDETSIZE";
case F_SET_RECEIVER_STREAMING_PORT: return "F_SET_RECEIVER_STREAMING_PORT";
case F_SET_RECEIVER_SILENT_MODE: return "F_SET_RECEIVER_SILENT_MODE";
case F_RECEIVER_STREAMING_SRC_IP: return "F_RECEIVER_STREAMING_SRC_IP";
case F_SET_RECEIVER_SILENT_MODE: return "F_SET_RECEIVER_SILENT_MODE";
case F_ENABLE_GAPPIXELS_IN_RECEIVER:return "F_ENABLE_GAPPIXELS_IN_RECEIVER";
case F_RESTREAM_STOP_FROM_RECEIVER: return "F_RESTREAM_STOP_FROM_RECEIVER";
case F_ADDITIONAL_JSON_HEADER: return "F_ADDITIONAL_JSON_HEADER";
@ -267,11 +266,10 @@ int slsReceiverTCPIPInterface::function_table(){
flist[F_SETUP_RECEIVER_UDP] = &slsReceiverTCPIPInterface::setup_udp;
flist[F_SET_RECEIVER_TIMER] = &slsReceiverTCPIPInterface::set_timer;
flist[F_SET_RECEIVER_DYNAMIC_RANGE] = &slsReceiverTCPIPInterface::set_dynamic_range;
flist[F_READ_RECEIVER_FREQUENCY] = &slsReceiverTCPIPInterface::set_read_frequency;
flist[F_RECEIVER_STREAMING_FREQUENCY] = &slsReceiverTCPIPInterface::set_streaming_frequency;
flist[F_GET_RECEIVER_STATUS] = &slsReceiverTCPIPInterface::get_status;
flist[F_START_RECEIVER] = &slsReceiverTCPIPInterface::start_receiver;
flist[F_STOP_RECEIVER] = &slsReceiverTCPIPInterface::stop_receiver;
flist[F_START_RECEIVER_READOUT] = &slsReceiverTCPIPInterface::start_readout;
flist[F_SET_RECEIVER_FILE_PATH] = &slsReceiverTCPIPInterface::set_file_dir;
flist[F_SET_RECEIVER_FILE_NAME] = &slsReceiverTCPIPInterface::set_file_name;
flist[F_SET_RECEIVER_FILE_INDEX] = &slsReceiverTCPIPInterface::set_file_index;
@ -279,20 +277,19 @@ int slsReceiverTCPIPInterface::function_table(){
flist[F_GET_RECEIVER_FRAMES_CAUGHT] = &slsReceiverTCPIPInterface::get_frames_caught;
flist[F_RESET_RECEIVER_FRAMES_CAUGHT] = &slsReceiverTCPIPInterface::reset_frames_caught;
flist[F_ENABLE_RECEIVER_FILE_WRITE] = &slsReceiverTCPIPInterface::enable_file_write;
flist[F_ENABLE_RECEIVER_COMPRESSION] = &slsReceiverTCPIPInterface::enable_compression;
flist[F_ENABLE_RECEIVER_OVERWRITE] = &slsReceiverTCPIPInterface::enable_overwrite;
flist[F_ENABLE_RECEIVER_TEN_GIGA] = &slsReceiverTCPIPInterface::enable_tengiga;
flist[F_SET_RECEIVER_FIFO_DEPTH] = &slsReceiverTCPIPInterface::set_fifo_depth;
flist[F_RECEIVER_ACTIVATE] = &slsReceiverTCPIPInterface::set_activate;
flist[F_STREAM_DATA_FROM_RECEIVER] = &slsReceiverTCPIPInterface::set_data_stream_enable;
flist[F_READ_RECEIVER_TIMER] = &slsReceiverTCPIPInterface::set_read_receiver_timer;
flist[F_RECEIVER_STREAMING_TIMER] = &slsReceiverTCPIPInterface::set_streaming_timer;
flist[F_SET_FLIPPED_DATA_RECEIVER] = &slsReceiverTCPIPInterface::set_flipped_data;
flist[F_SET_RECEIVER_FILE_FORMAT] = &slsReceiverTCPIPInterface::set_file_format;
flist[F_SEND_RECEIVER_DETPOSID] = &slsReceiverTCPIPInterface::set_detector_posid;
flist[F_SEND_RECEIVER_MULTIDETSIZE] = &slsReceiverTCPIPInterface::set_multi_detector_size;
flist[F_SET_RECEIVER_STREAMING_PORT] = &slsReceiverTCPIPInterface::set_streaming_port;
flist[F_SET_RECEIVER_SILENT_MODE] = &slsReceiverTCPIPInterface::set_silent_mode;
flist[F_RECEIVER_STREAMING_SRC_IP] = &slsReceiverTCPIPInterface::set_streaming_source_ip;
flist[F_SET_RECEIVER_SILENT_MODE] = &slsReceiverTCPIPInterface::set_silent_mode;
flist[F_ENABLE_GAPPIXELS_IN_RECEIVER] = &slsReceiverTCPIPInterface::enable_gap_pixels;
flist[F_RESTREAM_STOP_FROM_RECEIVER] = &slsReceiverTCPIPInterface::restream_stop;
flist[F_ADDITIONAL_JSON_HEADER] = &slsReceiverTCPIPInterface::set_additional_json_header;
@ -675,9 +672,9 @@ int slsReceiverTCPIPInterface::send_update() {
#endif
n += mySock->SendDataOnly(&ind,sizeof(ind));
// receiver read frequency
// streaming frequency
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
ind=(int)receiverBase->getFrameToGuiFrequency();
ind=(int)receiverBase->getStreamingFrequency();
#endif
n += mySock->SendDataOnly(&ind,sizeof(ind));
@ -792,7 +789,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){
}
if(ret == OK) {
if(receiverBase == NULL){
receiverBase = UDPInterface::create();
receiverBase = new slsReceiverImplementation();
if(startAcquisitionCallBack)
receiverBase->registerCallBackStartAcquisition(startAcquisitionCallBack,pStartAcquisition);
if(acquisitionFinishedCallBack)
@ -852,7 +849,7 @@ int slsReceiverTCPIPInterface::set_detector_hostname() {
else if (receiverBase->getStatus() != IDLE)
receiverNotIdle();
else {
receiverBase->initialize(hostname);
receiverBase->setDetectorHostname(hostname);
retval = receiverBase->getDetectorHostname();
if(retval == NULL)
ret = FAIL;
@ -1213,7 +1210,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() {
int slsReceiverTCPIPInterface::set_read_frequency(){
int slsReceiverTCPIPInterface::set_streaming_frequency(){
ret = OK;
memset(mess, 0, sizeof(mess));
int index = -1;
@ -1235,7 +1232,7 @@ int slsReceiverTCPIPInterface::set_read_frequency(){
else if (receiverBase->getStatus() != IDLE)
receiverNotIdle();
else {
ret = receiverBase->setFrameToGuiFrequency(index);
ret = receiverBase->setStreamingFrequency(index);
if(ret == FAIL) {
strcpy(mess, "Could not allocate memory for listening fifo\n");
FILE_LOG(logERROR) << mess;
@ -1243,10 +1240,10 @@ int slsReceiverTCPIPInterface::set_read_frequency(){
}
}
//get
retval=receiverBase->getFrameToGuiFrequency();
retval=receiverBase->getStreamingFrequency();
if(index >= 0 && retval != index){
ret = FAIL;
strcpy(mess,"Could not set frame to gui frequency");
strcpy(mess,"Could not set streaming frequency");
FILE_LOG(logERROR) << mess;
}
}
@ -1380,50 +1377,6 @@ int slsReceiverTCPIPInterface::stop_receiver(){
int slsReceiverTCPIPInterface::start_readout(){
ret = OK;
memset(mess, 0, sizeof(mess));
enum runStatus retval;
// execute action
// only a set, not a get
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
if (receiverBase == NULL)
invalidReceiverObject();
else if (mySock->differentClients && lockStatus)
receiverlocked();
/*else if(receiverBase->getStatus() != IDLE){
strcpy(mess,"Can not start receiver readout while receiver not idle\n");
ret = FAIL;
}*/
else {
receiverBase->startReadout();
retval = receiverBase->getStatus();
if ((retval == TRANSMITTING) || (retval == RUN_FINISHED) || (retval == IDLE))
ret = OK;
else {
ret = FAIL;
strcpy(mess,"Could not start readout");
FILE_LOG(logERROR) << mess;
}
}
#endif
if (ret == OK && mySock->differentClients)
ret = FORCE_UPDATE;
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
if (ret == FAIL)
mySock->SendDataOnly(mess,sizeof(mess));
mySock->SendDataOnly(&retval,sizeof(retval));
// return ok/fail
return ret;
}
@ -1741,29 +1694,6 @@ int slsReceiverTCPIPInterface::enable_file_write(){
int slsReceiverTCPIPInterface::enable_compression() {
ret = OK;
memset(mess, 0, sizeof(mess));
int enable = -1;
// receive arguments
if(mySock->ReceiveDataOnly(&enable,sizeof(enable)) < 0 )
return printSocketReadError();
ret = FAIL;
sprintf(mess, "This function (%s) is not implemented yet\n", getFunctionName((enum recFuncs)fnum));
FILE_LOG(logERROR) << mess;
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
mySock->SendDataOnly(mess,sizeof(mess));
// return ok/fail
return ret;
}
int slsReceiverTCPIPInterface::enable_overwrite() {
ret = OK;
memset(mess, 0, sizeof(mess));
@ -2046,7 +1976,7 @@ int slsReceiverTCPIPInterface::set_data_stream_enable(){
int slsReceiverTCPIPInterface::set_read_receiver_timer(){
int slsReceiverTCPIPInterface::set_streaming_timer(){
ret = OK;
memset(mess, 0, sizeof(mess));
int index = -1;
@ -2068,11 +1998,11 @@ int slsReceiverTCPIPInterface::set_read_receiver_timer(){
else if (receiverBase->getStatus() != IDLE)
receiverNotIdle();
else {
receiverBase->setFrameToGuiTimer(index);
receiverBase->setStreamingTimer(index);
}
}
//get
retval=receiverBase->getFrameToGuiTimer();
retval=receiverBase->getStreamingTimer();
if(index >= 0 && retval != index){
ret = FAIL;
strcpy(mess,"Could not set datastream timer");
@ -2081,7 +2011,7 @@ int slsReceiverTCPIPInterface::set_read_receiver_timer(){
}
#endif
#ifdef VERYVERBOSE
FILE_LOG(logDEBUG1) << "receiver read timer:" << retval;
FILE_LOG(logDEBUG1) << "Streaming timer:" << retval;
#endif
if (ret == OK && mySock->differentClients)