Merge branch 'eiger_receiver' of gitorious.psi.ch:sls_det_software/sls_receiver_software into eiger_receiver

Conflicts:
	include/UDPInterface.h
This commit is contained in:
sala 2014-09-22 14:46:34 +02:00
commit 546d43dedb
16 changed files with 685 additions and 607 deletions

View File

@ -1,6 +1,6 @@
*~
*.o
build
build/*
GPATH
GRTAGS
GSYMS

View File

@ -15,17 +15,31 @@ CFLAGS= -g -DC_ONLY -fPIC
DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS
INCLUDES?= -Iinclude -I../slsDetectorCalibration -I$(ASM)
INCLUDES?= $(INCLUDESRXR) -I include/ -I ../slsDetectorCalibration
#-Iinclude -I../slsDetectorCalibration -I$(ASM)
SRC_CLNT = MySocketTCP.cpp UDPInterface.cpp UDPBaseImplementation.cpp UDPStandardImplementation.cpp slsReceiverTCPIPInterface.cpp slsReceiver.cpp slsReceiverUsers.cpp utilities.cpp
ifeq ($(REST), yes)
SRC_CLNT += UDPRESTImplementation.cpp
endif
MAIN_SRC = main.cpp
OBJS=$(SRC_CLNT:%.cpp=$(BUILDDIR)/%.o)
$(info )
$(info #######################################)
$(info # Compiling slsReceiverSoftware #)
$(info #######################################)
$(info )
.PHONY: all intdoc package eigerReceiver clean
all: lib receiver
all: builddir lib receiver
intdoc: $(SRC_H) $(SRC_CLNT)
doxygen doxy.config
@ -69,6 +83,8 @@ clean: buildclean
rm $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so
rm $(PROGS)
builddir:
if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi
buildclean:
rm -rf $(OBJS)

View File

@ -19,17 +19,13 @@
#include "JsonBox/Value.h"
//#include "logger.h"
#include <iostream>
#include <sstream>
#include <string>
#include <exception>
#define EIGER_DEBUG
#ifdef EIGER_DEBUG
#define DEBUG(x) do { std::cerr << "[DEBUG] " << x << std::endl; } while (0)
#else
#define DEBUG(x)
#endif
using namespace Poco::Net;
@ -39,7 +35,7 @@ using namespace std;
class RestHelper {
public:
RestHelper(int timeout=10, int n_tries=3){
RestHelper(int timeout=10, int n_tries=10){
/**
*
*
@ -78,18 +74,22 @@ class RestHelper {
*/
//Check for http:// string
FILE_LOG(logDEBUG) << __func__ << " starting";
string proto_str = "http://";
if( size_t found = hostname.find(proto_str) != string::npos ){
cout << hostname << endl;
char c1[hostname.size()-found-1];
cout << c1 << endl;
size_t length1 = hostname.copy(c1, hostname.size()-found-1, proto_str.size());
c1[length1]='\0';
hostname = c1;
}
full_hostname = "http://"+hostname;
session = new HTTPClientSession(hostname,port );
session = new HTTPClientSession(hostname, port );
session->setKeepAliveTimeout( Timespan( http_timeout,0) );
};
@ -168,7 +168,7 @@ class RestHelper {
string answer;
int code = send_request(session, req, &answer);
if(code == 0 ) {
DEBUG("ANSWER " << answer );
FILE_LOG(logDEBUG) << "ANSWER " << answer;
json_value->loadFromString(answer);
}
delete uri;
@ -176,7 +176,7 @@ class RestHelper {
};
int post_json(string request, string *answer, string request_body=""){
int post_json(string request, string *answer, string request_body="{}"){
/**
*
*
@ -192,15 +192,16 @@ class RestHelper {
if (path.empty()) path = "/";
HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 );
req.setContentType("application/json\r\n");
req.setContentLength( request.length() );
cout << "REQUEST BODY " << request_body << endl;
req.setContentLength( request_body.length() );
int code = send_request(session, req, answer, request_body);
delete uri;
return code;
}
int post_json(string request, JsonBox::Value* json_value, string request_body=""){
int post_json(string request, JsonBox::Value* json_value, string request_body="{}"){
/**
*
*
@ -283,7 +284,7 @@ class RestHelper {
return code;
}
catch (exception& e){
cout << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"<<n_connection_tries << ")" << endl;
FILE_LOG(logERROR) << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"<<n_connection_tries << ")";
sleep(5);
}
n+=1;

View File

@ -32,7 +32,7 @@
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
*/
class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterface {
class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInterface {
public:
/**
@ -45,7 +45,8 @@ class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterfa
*/
virtual ~UDPBaseImplementation();
void configure(map<string, string> config_map);
/**
* delete and free member parameters
@ -319,7 +320,7 @@ class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterfa
*/
int shutDownUDPSockets();
private:
protected:
/*
void not_implemented(string method_name){
@ -466,6 +467,10 @@ private:
void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf);
//// Could be done more fine-grained... TODO
// private:
protected:
/** structure of an eiger image header*/
typedef struct
{
@ -683,6 +688,9 @@ private:
/** 10Gbe enable*/
int tengigaEnable;
// TODO: not properly sure where to put these...
/** structure of an eiger image header*/

View File

@ -13,6 +13,7 @@
* @short Base class with all the functions for the UDP inteface of the receiver
*/
#include <exception>
#include "sls_receiver_defs.h"
#include "receiver_defs.h"
@ -24,6 +25,7 @@
class UDPInterface {
/* abstract class that defines the UDP interface of an sls detector data receiver.
*
* Use the factory method UDPInterface::create() to get an instance:
@ -59,11 +61,6 @@ class UDPInterface {
public:
/**
* constructor
*/
//UDPInterface(){};
/**
* Destructor
*/
@ -73,12 +70,12 @@ class UDPInterface {
* Factory create method
*/
static UDPInterface *create(string receiver_type = "standard");
virtual void configure(map<string, string> config_map) = 0;
public:
/**
* Initialize the Receiver
@param detectorHostName detector hostname
@ -88,10 +85,10 @@ class UDPInterface {
/* Returns detector hostname
/returns hostname
* caller needs to deallocate the returned char array.
* if uninitialized, it must return NULL
*/
/returns hostname
* caller needs to deallocate the returned char array.
* if uninitialized, it must return NULL
*/
virtual char *getDetectorHostname() const = 0;
/**

View File

@ -34,7 +34,7 @@
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
*/
class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImplementation {
class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseImplementation {
public:
/**
@ -47,7 +47,12 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp
*/
virtual ~UDPRESTImplementation();
protected:
void initialize_REST();
public:
void configure(map<string, string> config_map);
/**
* delete and free member parameters
@ -57,14 +62,28 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp
/**
* initialize member parameters
*/
void initializeMembers();
//void initializeMembers();
/**
* Set detector hostname
* @param c hostname
*/
//void initialize(const char *detectorHostName);
/* Returns detector hostname
/returns hostname
* caller needs to deallocate the returned char array.
* if uninitialized, it must return NULL
*/
//char *getDetectorHostname() const;
/**
* Set receiver type
* @param det detector type
* Returns success or FAIL
*/
int setDetectorType(detectorType det);
//int setDetectorType(detectorType det);
//Frame indices and numbers caught
@ -192,18 +211,6 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp
*/
runStatus getStatus() const;
/**
* Set detector hostname
* @param c hostname
*/
void initialize(const char *detectorHostName);
/* Returns detector hostname
/returns hostname
* caller needs to deallocate the returned char array.
* if uninitialized, it must return NULL
*/
//char *getDetectorHostname() const;
/**
* Set Ethernet Interface or IP to listen to
@ -811,6 +818,9 @@ public:
//REST specific
bool isInitialized;
RestHelper * rest ;
int rest_port; // receiver backend port
string rest_hostname; // receiver hostname
};

View File

@ -40,7 +40,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
/**
* Constructor
*/
UDPStandardImplementation();
UDPStandardImplementation();
/**
* Destructor
@ -466,308 +466,6 @@ private:
void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf);
/** structure of an eiger image header*/
typedef struct
{
unsigned char header_before[20];
unsigned char fnum[4];
unsigned char header_after[24];
} eiger_image_header;
/** structure of an eiger image header*/
typedef struct
{
unsigned char num1[4];
unsigned char num2[4];
} eiger_packet_header;
/** max number of listening threads */
const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS;
/** max number of writer threads */
const static int MAX_NUM_WRITER_THREADS = 15;
/** detector type */
detectorType myDetectorType;
/** detector hostname */
char detHostname[MAX_STR_LENGTH];
/** status of receiver */
runStatus status;
/** UDP Socket between Receiver and Detector */
genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS];
/** Server UDP Port*/
int server_port[MAX_NUM_LISTENING_THREADS];
/** ethernet interface or IP to listen to */
char *eth;
/** max packets per file **/
int maxPacketsPerFile;
/** File write enable */
int enableFileWrite;
/** File over write enable */
int overwrite;
/** Complete File name */
char savefilename[MAX_STR_LENGTH];
/** File Name without frame index, file index and extension*/
char fileName[MAX_STR_LENGTH];
/** File Path */
char filePath[MAX_STR_LENGTH];
/** File Index */
int fileIndex;
/** scan tag */
int scanTag;
/** if frame index required in file name */
int frameIndexNeeded;
/* Acquisition started */
bool acqStarted;
/* Measurement started */
bool measurementStarted;
/** Frame index at start of each real time acquisition (eg. for each scan) */
uint32_t startFrameIndex;
/** Actual current frame index of each time acquisition (eg. for each scan) */
uint32_t frameIndex;
/** Frames Caught for each real time acquisition (eg. for each scan) */
int packetsCaught;
/** Total packets caught for an entire acquisition (including all scans) */
int totalPacketsCaught;
/** Pckets currently in current file, starts new file when it reaches max */
int packetsInFile;
/** Frame index at start of an entire acquisition (including all scans) */
uint32_t startAcquisitionIndex;
/** Actual current frame index of an entire acquisition (including all scans) */
uint32_t acquisitionIndex;
/** number of packets per frame*/
int packetsPerFrame;
/** frame index mask */
uint32_t frameIndexMask;
/** packet index mask */
uint32_t packetIndexMask;
/** frame index offset */
int frameIndexOffset;
/** acquisition period */
int64_t acquisitionPeriod;
/** frame number */
int32_t numberOfFrames;
/** dynamic range */
int dynamicRange;
/** short frames */
int shortFrame;
/** current frame number */
uint32_t currframenum;
/** Previous Frame number from buffer */
uint32_t prevframenum;
/** size of one frame */
int frameSize;
/** buffer size. different from framesize as we wait for one packet instead of frame for eiger */
int bufferSize;
/** oen buffer size */
int onePacketSize;
/** latest data */
char* latestData;
/** gui data ready */
int guiDataReady;
/** points to the data to send to gui */
char* guiData;
/** points to the filename to send to gui */
char* guiFileName;
/** temporary number for eiger frame number as its not included in the packet */
uint32_t guiFrameNumber;
/** send every nth frame to gui or only upon gui request*/
int nFrameToGui;
/** fifo size */
unsigned int fifosize;
/** number of jobs per thread for data compression */
int numJobsPerThread;
/** datacompression - save only hits */
bool dataCompression;
/** memory allocated for the buffer */
char *mem0[MAX_NUM_LISTENING_THREADS];
/** circular fifo to store addresses of data read */
CircularFifo<char>* fifo[MAX_NUM_LISTENING_THREADS];
/** circular fifo to store addresses of data already written and ready to be resued*/
CircularFifo<char>* fifoFree[MAX_NUM_LISTENING_THREADS];
/** Receiver buffer */
char *buffer[MAX_NUM_LISTENING_THREADS];
/** number of writer threads */
int numListeningThreads;
/** number of writer threads */
int numWriterThreads;
/** to know if listening and writer threads created properly */
int thread_started;
/** current listening thread index*/
int currentListeningThreadIndex;
/** current writer thread index*/
int currentWriterThreadIndex;
/** thread listening to packets */
pthread_t listening_thread[MAX_NUM_LISTENING_THREADS];
/** thread writing packets */
pthread_t writing_thread[MAX_NUM_WRITER_THREADS];
/** total frame count the listening thread has listened to */
int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS];
/** mask showing which listening threads are running */
volatile uint32_t listeningthreads_mask;
/** mask showing which writer threads are running */
volatile uint32_t writerthreads_mask;
/** mask showing which threads have created files*/
volatile uint32_t createfile_mask;
/** OK if file created was successful */
int ret_createfile;
/** variable used to self terminate threads waiting for semaphores */
int killAllListeningThreads;
/** variable used to self terminate threads waiting for semaphores */
int killAllWritingThreads;
/** 10Gbe enable*/
int tengigaEnable;
//semaphores
/** semaphore to synchronize writer and guireader threads */
sem_t smp;
/** semaphore to synchronize listener threads */
sem_t listensmp[MAX_NUM_LISTENING_THREADS];
/** semaphore to synchronize writer threads */
sem_t writersmp[MAX_NUM_WRITER_THREADS];
//mutex
/** guiDataReady mutex */
pthread_mutex_t dataReadyMutex;
/** mutex for status */
pthread_mutex_t status_mutex;
/** mutex for progress variable currframenum */
pthread_mutex_t progress_mutex;
/** mutex for writing data to file */
pthread_mutex_t write_mutex;
/** File Descriptor */
FILE *sfilefd;
//filter
singlePhotonDetector<uint16_t> *singlePhotonDet[MAX_NUM_WRITER_THREADS];
slsReceiverData<uint16_t> *receiverdata[MAX_NUM_WRITER_THREADS];
moenchCommonMode *cmSub;
bool commonModeSubtractionEnable;
#ifdef MYROOT1
/** Tree where the hits are stored */
TTree *myTree[MAX_NUM_WRITER_THREADS];
/** File where the tree is saved */
TFile *myFile[MAX_NUM_WRITER_THREADS];
#endif
/**
callback arguments are
filepath
filename
fileindex
data size
return value is
0 callback takes care of open,close,write file
1 callback writes file, we have to open, close it
2 we open, close, write file, callback does not do anything
*/
int (*startAcquisitionCallBack)(char*, char*,int, int, void*);
void *pStartAcquisition;
/**
args to acquisition finished callback
total frames caught
*/
void (*acquisitionFinishedCallBack)(int, void*);
void *pAcquisitionFinished;
/**
args to raw data ready callback are
framenum
datapointer
datasize in bytes
file descriptor
guidatapointer (NULL, no data required)
*/
void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*);
void *pRawDataReady;
/** The action which decides what the user and default responsibilites to save data are
* 0 raw data ready callback takes care of open,close,write file
* 1 callback writes file, we have to open, close it
* 2 we open, close, write file, callback does not do anything */
int cbAction;
public:

View File

@ -5,6 +5,19 @@
#include <string>
#include <stdio.h>
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define MYCONCAT(x,y)
#define __AT__ string(__FILE__) + string("::") + string(__func__) + string("(): ")
//":" TOSTRING(__LINE__)
/*
void error(const char *location, const char *msg){
printf("Error at %s: %s\n", location, msg);
}
*/
inline std::string NowTime();
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4};
@ -110,7 +123,7 @@ template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
template <typename T> Log<T>::~Log()
{
os << std::endl;
T::Output(os.str());
T::Output( os.str());
}
template <typename T> TLogLevel& Log<T>::ReportingLevel()

View File

@ -2,6 +2,8 @@
#include <string>
#include <sstream>
#include <iostream>
#include <map>
using namespace std;
#include "sls_receiver_defs.h"
@ -9,5 +11,5 @@ using namespace std;
//#define EIGER_DEBUG
int read_config_file(string fname, int *tcpip_port_no);
int read_config_file(string fname, int *tcpip_port_no, map<string, string> * configuration_map);

View File

@ -35,6 +35,11 @@ UDPBaseImplementation::UDPBaseImplementation(){}
UDPBaseImplementation::~UDPBaseImplementation(){}
void UDPBaseImplementation::configure(map<string, string> config_map){
FILE_LOG(logWARNING) << __AT__ << "doing nothing...";
};
void UDPBaseImplementation::deleteMembers(){
FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects.";
}
@ -47,6 +52,92 @@ void UDPBaseImplementation::initializeMembers(){
int UDPBaseImplementation::setDetectorType(detectorType det){
cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl;
cout << "Setting Receiver Type " << endl;
deleteMembers();
initializeMembers();
myDetectorType = det;
switch(myDetectorType){
case GOTTHARD:
cout << endl << "***** This is a GOTTHARD Receiver *****" << endl << endl;
break;
case MOENCH:
cout << endl << "***** This is a MOENCH Receiver *****" << endl << endl;
break;
case EIGER:
cout << endl << "***** This is a EIGER Receiver *****" << endl << endl;
break;
default:
cout << endl << "***** Unknown Receiver *****" << endl << endl;
return FAIL;
break;
}
//moench variables
if(myDetectorType == GOTTHARD){
fifosize = GOTTHARD_FIFO_SIZE;
packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME;
onePacketSize = GOTTHARD_ONE_PACKET_SIZE;
frameSize = GOTTHARD_BUFFER_SIZE;
bufferSize = GOTTHARD_BUFFER_SIZE;
maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME;
frameIndexMask = GOTTHARD_FRAME_INDEX_MASK;
frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET;
packetIndexMask = GOTTHARD_PACKET_INDEX_MASK;
}else if(myDetectorType == MOENCH){
fifosize = MOENCH_FIFO_SIZE;
packetsPerFrame = MOENCH_PACKETS_PER_FRAME;
onePacketSize = MOENCH_ONE_PACKET_SIZE;
frameSize = MOENCH_BUFFER_SIZE;
bufferSize = MOENCH_BUFFER_SIZE;
maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME;
frameIndexMask = MOENCH_FRAME_INDEX_MASK;
frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET;
packetIndexMask = MOENCH_PACKET_INDEX_MASK;
}
else if(myDetectorType == EIGER){
fifosize = EIGER_FIFO_SIZE;
packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS;
onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE;
frameSize = onePacketSize * packetsPerFrame;
bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets)
maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame;
frameIndexMask = EIGER_FRAME_INDEX_MASK;
frameIndexOffset = EIGER_FRAME_INDEX_OFFSET;
packetIndexMask = EIGER_PACKET_INDEX_MASK;
pthread_mutex_lock(&status_mutex);
listeningthreads_mask = 0x0;
pthread_mutex_unlock(&(status_mutex));
if(thread_started)
createListeningThreads(true);
numListeningThreads = MAX_NUM_LISTENING_THREADS;
}
latestData = new char[frameSize];
setupFifoStructure();
if(createListeningThreads() == FAIL){
cout << "ERROR: Could not create listening thread" << endl;
exit (-1);
}
if(createWriterThreads() == FAIL){
cout << "ERROR: Could not create writer threads" << endl;
exit (-1);
}
setThreadPriorities();
cout << "Ready..." << endl;
return OK;
return OK;
}
@ -94,11 +185,11 @@ void UDPBaseImplementation::resetTotalFramesCaught(){
/*file parameters*/
char* UDPBaseImplementation::getFilePath() const{
FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects.";
return (char*)filePath;
}
char* UDPBaseImplementation::setFilePath(const char c[]){
inline char* UDPBaseImplementation::setFilePath(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << "called";
if(strlen(c)){
//check if filepath exists
struct stat st;
@ -109,6 +200,8 @@ char* UDPBaseImplementation::setFilePath(const char c[]){
FILE_LOG(logWARNING) << "FilePath does not exist:" << filePath;
}
}
FILE_LOG(logDEBUG) << __AT__ << getFilePath();
cout << getFilePath() << " " << filePath << endl;
return getFilePath();
}
@ -117,7 +210,7 @@ char* UDPBaseImplementation::getFileName() const{
return (char*)fileName;
}
char* UDPBaseImplementation::setFileName(const char c[]){
inline char* UDPBaseImplementation::setFileName(const char c[]){
//cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl;
if(strlen(c))
@ -132,17 +225,15 @@ int UDPBaseImplementation::getFileIndex(){
}
int UDPBaseImplementation::setFileIndex(int i){
cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl;
/*
//cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl;
if(i>=0)
fileIndex = i;
*/
return getFileIndex();
}
int UDPBaseImplementation::setFrameIndexNeeded(int i){
cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl;
//cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl;
frameIndexNeeded = i;
return frameIndexNeeded;
}
@ -628,6 +719,7 @@ void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char
int UDPBaseImplementation::createUDPSockets(){
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
//if eth is mistaken with ip address
@ -871,8 +963,10 @@ int UDPBaseImplementation::setupWriter(){
//acquisition start call back returns enable write
if (startAcquisitionCallBack)
if (startAcquisitionCallBack){
cout << filePath << " - " << fileName << endl;
cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition);
}
if(cbAction < DO_EVERYTHING)
cout << endl << "Note: Call back activated. Data saving must be taken care of by user in call back." << endl;
@ -952,14 +1046,21 @@ int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){
int UDPBaseImplementation::createNewFile(){
int gt = getFrameIndex();
if(gt==-1) gt=0;
cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl;
/*
int gt = getFrameIndex();
if(gt==-1) gt=0;
//create file name
if(frameIndexNeeded==-1)
sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
else
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex);
cout << filePath << " + " << fileName << endl;
//if filewrite and we are allowed to write
if(enableFileWrite && cbAction > DO_NOTHING){
//close
@ -974,7 +1075,7 @@ int UDPBaseImplementation::createNewFile(){
return FAIL;
}
}else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){
cout << "Error: Could not create file " << savefilename << endl;
cout << "Error: Could not creat dsdasdserwe file " << savefilename << endl;
return FAIL;
}
//setting buffer
@ -1001,22 +1102,17 @@ int UDPBaseImplementation::createNewFile(){
prevframenum = currframenum;
packetsInFile = 0;
}
*/
return OK;
}
void UDPBaseImplementation::closeFile(int ithr){
#ifdef VERBOSE
cout << "In closeFile for thread " << ithr << endl;
#endif
// This is actually called on CTRL-C
void UDPBaseImplementation::closeFile(int ithr)
{
FILE_LOG(logDEBUG) << __AT__ << "called";
if(!dataCompression){
if(sfilefd){
#ifdef VERBOSE
@ -1063,6 +1159,9 @@ void UDPBaseImplementation::closeFile(int ithr){
#endif
}
FILE_LOG(logDEBUG) << __AT__ << "exited";
}
@ -2022,12 +2121,24 @@ int UDPBaseImplementation::enableTenGiga(int enable){
createWriterThreads(true);
}
for(int i=0;i<numListeningThreads;i++){
if(mem0[i]) {free(mem0[i]); mem0[i] = NULL;}
if(fifo[i]) {delete fifo[i]; fifo[i] = NULL;}
if(fifoFree[i]) {delete fifoFree[i]; fifoFree[i] = NULL;}
if(mem0[i]){
free(mem0[i]);
mem0[i] = NULL;
}
if(fifo[i]){
delete fifo[i];
fifo[i] = NULL;
}
if(fifoFree[i]) {
delete fifoFree[i];
fifoFree[i] = NULL;
}
buffer[i] = NULL;
}
if(latestData) {delete [] latestData; latestData = NULL;}
if(latestData){
delete [] latestData;
latestData = NULL;
}
latestData = new char[frameSize];
numJobsPerThread = -1;

View File

@ -6,16 +6,6 @@
/*
#include <signal.h> // SIGINT
#include <sys/stat.h> // stat
#include <sys/socket.h> // socket(), bind(), listen(), accept(), shut down
#include <arpa/inet.h> // sock_addr_in, htonl, INADDR_ANY
#include <stdlib.h> // exit()
#include <iomanip> //set precision
#include <sys/mman.h> //munmap
*/
#include <string.h>
#include <iostream>
using namespace std;
@ -23,6 +13,7 @@ using namespace std;
#include "UDPInterface.h"
#include "UDPBaseImplementation.h"
#include "UDPStandardImplementation.h"
#include "UDPRESTImplementation.h"
@ -34,11 +25,11 @@ UDPInterface * UDPInterface::create(string receiver_type){
cout << "Starting " << receiver_type << endl;
return new UDPStandardImplementation();
}
#ifdef REST
else if (receiver_type == "REST")
//#ifdef REST
else if (receiver_type == "REST"){
return new UDPRESTImplementation();
#endif
}
//#endif
else{
FILE_LOG(logWARNING) << "[ERROR] UDP interface not supported, using standard implementation";
return new UDPBaseImplementation();

View File

@ -16,86 +16,173 @@
#include <sys/stat.h> // stat
#include <sys/socket.h> // socket(), bind(), listen(), accept(), shut down
#include <arpa/inet.h> // sock_addr_in, htonl, INADDR_ANY
#include <stdlib.h> // exit()
#include <iomanip> //set precision
#include <sys/mman.h> //munmap
#include <stdlib.h> // exit()
#include <iomanip> // set precision
#include <sys/mman.h> // munmap
#include <string.h>
#include <iostream>
#include <sstream>
//#include "utilities.h"
using namespace std;
/*
TODO
+ filePath != getFilePath
+ better state handling. Now it is only IDLE - RUNNING - IDLE
*/
UDPRESTImplementation::UDPRESTImplementation() : isInitialized(false), status(slsReceiverDefs::ERROR) {}
UDPRESTImplementation::UDPRESTImplementation(){
FILE_LOG(logDEBUG) << __AT__ << " called";
UDPRESTImplementation::~UDPRESTImplementation(){}
void UDPRESTImplementation::initialize(const char *detectorHostName){
string name;
if (detectorHostName != NULL)
name = detectorHostName;
if (name.empty()) {
FILE_LOG(logDEBUG) << "initialize(): can't initialize with empty string or NULL for detectorHostname";
} else if (isInitialized == true) {
FILE_LOG(logDEBUG) << "initialize(): already initialized, can't initialize several times";
} else {
FILE_LOG(logDEBUG) << "initialize(): initialize() with: detectorHostName=" << name;
strcpy(detHostname,detectorHostName);
//init_config.detectorHostname = name;
//REST call - hardcoded
//RestHelper rest ;
rest->init(detHostname, 8080);
std::string answer;
int code = rest->get_json("status", &answer);
if (code != 0){
//throw -1;
std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl;
}
else{
isInitialized = true;
status = slsReceiverDefs::IDLE;
}
std::cout << "Answer: " << answer << std::endl;
/*
std::std::cout << string << std::endl; << "---- REST test 3: true, json object "<< std::endl;
JsonBox::Value json_value;
code = rest.get_json("status", &json_value);
std::cout << "JSON " << json_value["status"] << std::endl;
*/
}
// Default values
rest_hostname = "localhost";
rest_port = 8081;
}
UDPRESTImplementation::~UDPRESTImplementation(){
delete rest;
}
void UDPRESTImplementation::configure(map<string, string> config_map){
FILE_LOG(logWARNING) << __AT__ << " called";
map<string, string>::const_iterator pos;
pos = config_map.find("rest_hostname");
if (pos != config_map.end() ){
string host_port_str = pos->second;
std::size_t pos = host_port_str.find(":"); // position of "live" in str
if(pos != string::npos){
istringstream (host_port_str.substr (pos)) >> rest_port;
rest_hostname = host_port_str.substr(0, pos);
}
}
/*
for(map<string, string>::const_iterator i=config_map.begin(); i != config_map.end(); i++){
std::cout << i->first << " " << i->second<< std::endl;
}
*/
};
void UDPRESTImplementation::initialize_REST(){
FILE_LOG(logDEBUG) << __AT__ << " called";
if (rest_hostname.empty()) {
FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname";
}
else if (isInitialized == true) {
FILE_LOG(logDEBUG) << __AT__ << "already initialized, can't initialize several times";
}
else {
FILE_LOG(logDEBUG) << __AT__ << "with receiverHostName=" << rest_hostname << ":" << rest_port;
rest = new RestHelper() ;
std::string answer;
int code;
try{
rest->init(rest_hostname, rest_port);
code = rest->get_json("state", &answer);
if (code != 0){
throw answer;
}
else{
isInitialized = true;
status = slsReceiverDefs::IDLE;
}
FILE_LOG(logDEBUG) << __func__ << "Answer: " << answer;
}
catch(std::string e){
FILE_LOG(logERROR) << __func__ << ": " << e;
throw;
}
//JsonBox::Object json_object;
//json_object["configfile"] = JsonBox::Value("FILENAME");
JsonBox::Value json_request;
//json_request["configfile"] = "config.py";
json_request["path"] = filePath;
stringstream ss;
string test;
std::cout << "GetSTring: " << json_request << std::endl;
json_request.writeToStream(ss, false);
//ss << json_request;
ss >> test;
test = "{\"path\":\"" + string( getFilePath() ) + "\"}";
code = rest->post_json("state/initialize", &answer, test);
FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code;
code = rest->get_json("state", &answer);
FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer;
/*
std::std::cout << string << std::endl; << "---- REST test 3: true, json object "<< std::endl;
JsonBox::Value json_value;
code = rest.get_json("status", &json_value);
std::cout << "JSON " << json_value["status"] << std::endl;
*/
}
FILE_LOG(logDEBUG) << __func__ << ": initialize() done";
}
/*
int UDPRESTImplementation::setDetectorType(detectorType det){
cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl;
return OK;
}
*/
/*Frame indices and numbers caught*/
bool UDPRESTImplementation::getAcquistionStarted(){return acqStarted;};
bool UDPRESTImplementation::getAcquistionStarted(){
FILE_LOG(logDEBUG) << __AT__ << " called";
return acqStarted;
};
bool UDPRESTImplementation::getMeasurementStarted(){return measurementStarted;};
bool UDPRESTImplementation::getMeasurementStarted(){
FILE_LOG(logDEBUG) << __AT__ << " called";
return measurementStarted;
};
int UDPRESTImplementation::getFramesCaught(){return (packetsCaught/packetsPerFrame);}
int UDPRESTImplementation::getFramesCaught(){
FILE_LOG(logDEBUG) << __AT__ << " called";
return (packetsCaught/packetsPerFrame);
}
int UDPRESTImplementation::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);}
int UDPRESTImplementation::getTotalFramesCaught(){
FILE_LOG(logDEBUG) << __AT__ << " called";
if (packetsPerFrame == 0){
FILE_LOG(logWARNING) << __AT__ << " packetsPerFrame is 0!!!";
return 0;
}
return (totalPacketsCaught/packetsPerFrame);
}
uint32_t UDPRESTImplementation::getStartFrameIndex(){return startFrameIndex;}
uint32_t UDPRESTImplementation::getStartFrameIndex(){
FILE_LOG(logDEBUG) << __AT__ << " called";
return startFrameIndex;
}
uint32_t UDPRESTImplementation::getFrameIndex(){
FILE_LOG(logDEBUG) << __AT__ << " called";
if(!packetsCaught)
frameIndex=-1;
else
@ -105,15 +192,22 @@ uint32_t UDPRESTImplementation::getFrameIndex(){
uint32_t UDPRESTImplementation::getAcquisitionIndex(){
//FILE_LOG(logDEBUG) << __AT__ << " called, idx: " << acquisitionIndex;
if(!totalPacketsCaught)
acquisitionIndex=-1;
acquisitionIndex = -1;
else
acquisitionIndex = currframenum - startAcquisitionIndex;
//FILE_LOG(logDEBUG) << __AT__ << " idx: " << acquisitionIndex
// << " currframenum: " << currframenum
// << " startAcqIdx: " << startAcquisitionIndex;
return acquisitionIndex;
}
void UDPRESTImplementation::resetTotalFramesCaught(){
FILE_LOG(logDEBUG) << __AT__ << " called";
acqStarted = false;
startAcquisitionIndex = 0;
totalPacketsCaught = 0;
@ -122,21 +216,22 @@ void UDPRESTImplementation::resetTotalFramesCaught(){
/*file parameters*/
int UDPRESTImplementation::getFileIndex(){
FILE_LOG(logDEBUG) << __AT__ << " called";
return fileIndex;
}
int UDPRESTImplementation::setFileIndex(int i){
cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl;
/*
FILE_LOG(logDEBUG) << __AT__ << " called";
if(i>=0)
fileIndex = i;
*/
return getFileIndex();
}
int UDPRESTImplementation::setFrameIndexNeeded(int i){
cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl;
FILE_LOG(logDEBUG) << __AT__ << " called";
frameIndexNeeded = i;
return frameIndexNeeded;
}
@ -168,6 +263,7 @@ int UDPRESTImplementation::setEnableOverwrite(int i){
/*other parameters*/
slsReceiverDefs::runStatus UDPRESTImplementation::getStatus() const{
FILE_LOG(logDEBUG) << __AT__ << " called, status: " << status;
return status;
}
@ -180,11 +276,16 @@ char *UDPRESTImplementation::getDetectorHostname() const{
*/
void UDPRESTImplementation::setEthernetInterface(char* c){
strcpy(eth,c);
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
// TODO: this segfaults
//strcpy(eth,c);
//FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done";
}
void UDPRESTImplementation::setUDPPortNo(int p){
FILE_LOG(logDEBUG) << __AT__ << " called";
for(int i=0;i<numListeningThreads;i++){
server_port[i] = p+i;
}
@ -219,19 +320,23 @@ int32_t UDPRESTImplementation::setScanTag(int32_t stag){
*/
int32_t UDPRESTImplementation::setDynamicRange(int32_t dr){
cout << "Setting Dynamic Range" << endl;
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
int olddr = dynamicRange;
if(dr >= 0){
dynamicRange = dr;
}
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << getDynamicRange();
return getDynamicRange();
}
int UDPRESTImplementation::setShortFrame(int i){
FILE_LOG(logDEBUG) << __AT__ << " called";
shortFrame=i;
if(shortFrame!=-1){
@ -262,6 +367,7 @@ int UDPRESTImplementation::setShortFrame(int i){
int UDPRESTImplementation::setNFrameToGui(int i){
FILE_LOG(logDEBUG) << __AT__ << " called";
if(i>=0){
nFrameToGui = i;
setupFifoStructure();
@ -272,7 +378,7 @@ int UDPRESTImplementation::setNFrameToGui(int i){
int64_t UDPRESTImplementation::setAcquisitionPeriod(int64_t index){
FILE_LOG(logDEBUG) << __AT__ << " called";
if(index >= 0){
if(index != acquisitionPeriod){
acquisitionPeriod = index;
@ -283,55 +389,15 @@ int64_t UDPRESTImplementation::setAcquisitionPeriod(int64_t index){
}
bool UDPRESTImplementation::getDataCompression(){return dataCompression;}
int UDPRESTImplementation::enableDataCompression(bool enable){
cout << "Data compression ";
if(enable)
cout << "enabled" << endl;
else
cout << "disabled" << endl;
#ifdef MYROOT1
cout << " WITH ROOT" << endl;
#else
cout << " WITHOUT ROOT" << endl;
#endif
//delete filter for the current number of threads
deleteFilter();
dataCompression = enable;
pthread_mutex_lock(&status_mutex);
writerthreads_mask = 0x0;
pthread_mutex_unlock(&(status_mutex));
createWriterThreads(true);
if(enable)
numWriterThreads = MAX_NUM_WRITER_THREADS;
else
numWriterThreads = 1;
if(createWriterThreads() == FAIL){
cout << "ERROR: Could not create writer threads" << endl;
return FAIL;
}
setThreadPriorities();
if(enable)
setupFilter();
return OK;
bool UDPRESTImplementation::getDataCompression(){
FILE_LOG(logDEBUG) << __AT__ << " called";
return dataCompression;
}
int UDPRESTImplementation::enableDataCompression(bool enable){
FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing";
return OK;
}
@ -339,6 +405,7 @@ int UDPRESTImplementation::enableDataCompression(bool enable){
void UDPRESTImplementation::deleteFilter(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
cmSub=NULL;
@ -356,6 +423,9 @@ void UDPRESTImplementation::deleteFilter(){
void UDPRESTImplementation::setupFilter(){
//LEO: check
FILE_LOG(logDEBUG) << __AT__ << " called";
double hc = 0;
double sigma = 5;
int sign = 1;
@ -392,6 +462,11 @@ void UDPRESTImplementation::setupFilter(){
//LEO: it is not clear to me..
void UDPRESTImplementation::setupFifoStructure(){
FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing";
}
/*
void UDPRESTImplementation::setupFifoStructure(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int64_t i;
int oldn = numJobsPerThread;
@ -437,10 +512,6 @@ void UDPRESTImplementation::setupFifoStructure(){
cout << "Number of Frames per buffer:" << numJobsPerThread << endl;
cout << "Fifo Size:" << fifosize << endl;
/*
//for testing
numJobsPerThread = 3; fifosize = 11;
*/
for(int i=0;i<numListeningThreads;i++){
//deleting old structure and creating fifo structure
@ -457,7 +528,7 @@ void UDPRESTImplementation::setupFifoStructure(){
//allocate memory
mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize);
/** shud let the client know about this */
// shud let the client know about this
if (mem0[i]==NULL){
cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl;
exit(-1);
@ -471,7 +542,7 @@ void UDPRESTImplementation::setupFifoStructure(){
}
cout << "Fifo structure(s) reconstructed" << endl;
}
*/
@ -481,6 +552,7 @@ void UDPRESTImplementation::setupFifoStructure(){
/** acquisition functions */
void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
FILE_LOG(logDEBUG) << __AT__ << " called";
//point to gui data
if (guiData == NULL)
guiData = latestData;
@ -515,6 +587,7 @@ void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
void UDPRESTImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){
FILE_LOG(logDEBUG) << __AT__ << " called";
//random read when gui not ready
if((!nFrameToGui) && (!guiData)){
@ -571,6 +644,7 @@ void UDPRESTImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char
int UDPRESTImplementation::createUDPSockets(){
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
//if eth is mistaken with ip address
if (strchr(eth,'.')!=NULL)
@ -587,7 +661,7 @@ int UDPRESTImplementation::createUDPSockets(){
}
//normal socket
else{
cout<<"eth:"<<eth<<endl;
cout << "eth:" << eth << endl;
for(int i=0;i<numListeningThreads;i++)
udpSocket[i] = new genericSocket(server_port[i],genericSocket::UDP,bufferSize,eth);
@ -615,13 +689,38 @@ int UDPRESTImplementation::createUDPSockets(){
int UDPRESTImplementation::shutDownUDPSockets(){
FILE_LOG(logDEBUG) << __AT__ << "called";
std::string answer;
int code = rest->get_json("state", &answer);
std::cout << answer << std::endl;
code = rest->post_json("state/close", &answer);
std::cout << answer << std::endl;
code = rest->post_json("state/reset", &answer);
std::cout << answer << std::endl;
code = rest->get_json("state", &answer);
std::cout << answer << std::endl;
status = slsReceiverDefs::RUN_FINISHED;
/*
for(int i=0;i<numListeningThreads;i++){
if(udpSocket[i]){
FILE_LOG(logDEBUG) << __AT__ << " UDP socket " << i;
udpSocket[i]->ShutDownSocket();
delete udpSocket[i];
udpSocket[i] = NULL;
}
}
*/
FILE_LOG(logDEBUG) << __AT__ << "finished";
return OK;
}
@ -630,6 +729,8 @@ int UDPRESTImplementation::shutDownUDPSockets(){
int UDPRESTImplementation::createListeningThreads(bool destroy){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
void* status;
@ -685,6 +786,7 @@ int UDPRESTImplementation::createListeningThreads(bool destroy){
int UDPRESTImplementation::createWriterThreads(bool destroy){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
void* status;
@ -746,6 +848,7 @@ int UDPRESTImplementation::createWriterThreads(bool destroy){
void UDPRESTImplementation::setThreadPriorities(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
//assign priorities
struct sched_param tcp_param, listen_param, write_param;
@ -783,7 +886,7 @@ void UDPRESTImplementation::setThreadPriorities(){
int UDPRESTImplementation::setupWriter(){
FILE_LOG(logDEBUG) << __AT__ << " called";
//reset writing thread variables
packetsInFile=0;
packetsCaught=0;
@ -866,6 +969,8 @@ int UDPRESTImplementation::setupWriter(){
int UDPRESTImplementation::createCompressionFile(int ithr, int iframe){
FILE_LOG(logDEBUG) << __AT__ << " called";
#ifdef MYROOT1
char temp[MAX_STR_LENGTH];
//create file name for gui purposes, and set up acquistion parameters
@ -894,8 +999,9 @@ int UDPRESTImplementation::createCompressionFile(int ithr, int iframe){
int UDPRESTImplementation::createNewFile(){
int gt = getFrameIndex();
if(gt==-1) gt=0;
FILE_LOG(logDEBUG) << __AT__ << " called";
int gt = getFrameIndex();
if(gt==-1) gt=0;
//create file name
if(frameIndexNeeded==-1)
sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
@ -955,9 +1061,7 @@ int UDPRESTImplementation::createNewFile(){
void UDPRESTImplementation::closeFile(int ithr){
#ifdef VERBOSE
cout << "In closeFile for thread " << ithr << endl;
#endif
FILE_LOG(logDEBUG) << __AT__ << "called for thread " << ithr;
if(!dataCompression){
if(sfilefd){
@ -1005,6 +1109,8 @@ void UDPRESTImplementation::closeFile(int ithr){
#endif
}
FILE_LOG(logDEBUG) << __AT__ << "exited for thread " << ithr;
}
@ -1014,13 +1120,33 @@ void UDPRESTImplementation::closeFile(int ithr){
int UDPRESTImplementation::startReceiver(char message[]){
int i;
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
initialize_REST();
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " initialized";
// #ifdef VERBOSE
cout << "Starting Receiver" << endl;
//#endif
std::string answer;
int code;
//test = "{\"configfile\":\"config.pu\", \"path\":\"patto\"}";
code = rest->post_json("state/configure", &answer);
std::cout << answer << std::endl;
code = rest->get_json("state", &answer);
std::cout << answer << std::endl;
code = rest->post_json("state/open", &answer);
std::cout << answer << std::endl;
code = rest->get_json("state", &answer);
std::cout << answer << std::endl;
status = slsReceiverDefs::RUNNING;
//reset listening thread variables
/*
measurementStarted = false;
//should be set to zero as its added to get next start frame indices for scans for eiger
if(!acqStarted) currframenum = 0;
@ -1028,8 +1154,9 @@ int UDPRESTImplementation::startReceiver(char message[]){
for(int i = 0; i < numListeningThreads; ++i)
totalListeningFrameCount[i] = 0;
*/
//udp socket
/*
if(createUDPSockets() == FAIL){
strcpy(message,"Could not create UDP Socket(s).\n");
cout << endl << message << endl;
@ -1037,7 +1164,8 @@ int UDPRESTImplementation::startReceiver(char message[]){
}
cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl;
*/
/*
if(setupWriter() == FAIL){
//stop udp socket
shutDownUDPSockets();
@ -1069,9 +1197,7 @@ int UDPRESTImplementation::startReceiver(char message[]){
sem_post(&listensmp[i]);
for(i=0; i < numWriterThreads; ++i)
sem_post(&writersmp[i]);
cout << "Receiver Started.\nStatus:" << status << endl;
*/
return OK;
}
@ -1081,10 +1207,7 @@ int UDPRESTImplementation::startReceiver(char message[]){
int UDPRESTImplementation::stopReceiver(){
//#ifdef VERBOSE
cout << "Stopping Receiver" << endl;
//#endif
FILE_LOG(logDEBUG) << __AT__ << "called";
if(status == RUNNING)
startReadout();
@ -1101,7 +1224,8 @@ int UDPRESTImplementation::stopReceiver(){
status = IDLE;
pthread_mutex_unlock(&(status_mutex));
cout << "Receiver Stopped.\nStatus:" << status << endl << endl;
FILE_LOG(logDEBUG) << __AT__ << "exited, status " << endl;
return OK;
}
@ -1110,10 +1234,7 @@ int UDPRESTImplementation::stopReceiver(){
void UDPRESTImplementation::startReadout(){
//#ifdef VERBOSE
cout << "Start Receiver Readout" << endl;
//#endif
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting";
//wait so that all packets which take time has arrived
usleep(50000);
@ -1127,12 +1248,15 @@ void UDPRESTImplementation::startReadout(){
//kill udp socket to tell the listening thread to push last packet
shutDownUDPSockets();
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done";
}
void* UDPRESTImplementation::startListeningThread(void* this_pointer){
FILE_LOG(logDEBUG) << __AT__ << " called";
((UDPRESTImplementation*)this_pointer)->startListening();
return this_pointer;
@ -1141,6 +1265,7 @@ void* UDPRESTImplementation::startListeningThread(void* this_pointer){
void* UDPRESTImplementation::startWritingThread(void* this_pointer){
FILE_LOG(logDEBUG) << __AT__ << " called";
((UDPRESTImplementation*)this_pointer)->startWriting();
return this_pointer;
}
@ -1151,6 +1276,8 @@ void* UDPRESTImplementation::startWritingThread(void* this_pointer){
int UDPRESTImplementation::startListening(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int ithread = currentListeningThreadIndex;
#ifdef VERYVERBOSE
cout << "In startListening() " << endl;
@ -1352,6 +1479,7 @@ int UDPRESTImplementation::startListening(){
int UDPRESTImplementation::startWriting(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int ithread = currentWriterThreadIndex;
#ifdef VERYVERBOSE
cout << ithread << "In startWriting()" <<endl;
@ -1545,6 +1673,7 @@ int loop;
void UDPRESTImplementation::startFrameIndices(int ithread){
FILE_LOG(logDEBUG) << __AT__ << " called";
if (myDetectorType == EIGER)
//add currframenum later in this method for scans
@ -1577,15 +1706,21 @@ void UDPRESTImplementation::startFrameIndices(int ithread){
}
void UDPRESTImplementation::stopListening(int ithread, int rc, int &pc, int &t){
FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing";
};
/*
void UDPRESTImplementation::stopListening(int ithread, int rc, int &pc, int &t){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
#ifdef VERYVERBOSE
cerr << ithread << " recvfrom() failed:"<<endl;
#endif
if(status != TRANSMITTING){
cout << ithread << " *** shoule never be here********* status not transmitting***********************"<<endl;/**/
cout << ithread << " *** shoule never be here********* status not transmitting***********************"<<endl;
fifoFree[ithread]->push(buffer[ithread]);
exit(-1);
}
@ -1646,7 +1781,7 @@ int i;
}
}
*/
@ -1657,6 +1792,7 @@ int i;
void UDPRESTImplementation::stopWriting(int ithread, char* wbuffer[]){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i,j;
#ifdef VERYDEBUG
cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[wIndex] << endl;
@ -1724,6 +1860,7 @@ void UDPRESTImplementation::stopWriting(int ithread, char* wbuffer[]){
void UDPRESTImplementation::writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum){
FILE_LOG(logDEBUG) << __AT__ << " called";
int packetsToSave, offset,lastpacket;
uint32_t tempframenum = framenum;
@ -1827,6 +1964,8 @@ void UDPRESTImplementation::writeToFile_withoutCompression(char* buf,int numpack
void UDPRESTImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){
FILE_LOG(logDEBUG) << __AT__ << " called";
#if defined(MYROOT1) && defined(ALLFILE_DEBUG)
writeToFile_withoutCompression(wbuf[0], numpackets,currframenum);
#endif
@ -1925,6 +2064,7 @@ void UDPRESTImplementation::handleDataCompression(int ithread, char* wbuffer[],
int UDPRESTImplementation::enableTenGiga(int enable){
FILE_LOG(logDEBUG) << __AT__ << " called";
cout << "Enabling 10Gbe to" << enable << endl;

View File

@ -110,8 +110,11 @@ void UDPStandardImplementation::initializeMembers(){
strcpy(detHostname,"");
strcpy(guiFileName,"");
strcpy(savefilename,"");
strcpy(filePath,"");
strcpy(fileName,"run");
setFileName("run");
setFilePath("");
//strcpy(filePath,"");
//strcpy(fileName,"run");
//status
@ -122,15 +125,17 @@ void UDPStandardImplementation::initializeMembers(){
}
UDPStandardImplementation::UDPStandardImplementation():
thread_started(0),
eth(NULL),
latestData(NULL),
guiFileName(NULL),
guiFrameNumber(0),
tengigaEnable(0){
UDPStandardImplementation::UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called";
cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa" << endl;
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting" ;
thread_started = 0;
eth = NULL;
latestData = NULL;
guiFileName = NULL;
guiFrameNumber = 0;
tengigaEnable = 0;
for(int i=0;i<MAX_NUM_LISTENING_THREADS;i++){
udpSocket[i] = NULL;
@ -178,7 +183,8 @@ UDPStandardImplementation::UDPStandardImplementation():
UDPStandardImplementation::~UDPStandardImplementation(){
UDPStandardImplementation::~UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called";
createListeningThreads(true);
createWriterThreads(true);
deleteMembers();
@ -187,7 +193,8 @@ UDPStandardImplementation::~UDPStandardImplementation(){
void UDPStandardImplementation::deleteMembers(){
void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG) << __AT__ << " called";
//kill threads
if(thread_started){
createListeningThreads(true);
@ -220,7 +227,8 @@ void UDPStandardImplementation::deleteMembers(){
int UDPStandardImplementation::setDetectorType(detectorType det){
int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logDEBUG) << __AT__ << " called";
cout << "Setting Receiver Type " << endl;
deleteMembers();
@ -364,7 +372,6 @@ char* UDPStandardImplementation::getFilePath() const{
return (char*)filePath;
}
*/
/*
char* UDPStandardImplementation::setFilePath(const char c[]){
if(strlen(c)){
@ -448,6 +455,9 @@ int UDPStandardImplementation::setEnableOverwrite(int i){
/*other parameters*/
slsReceiverDefs::runStatus UDPStandardImplementation::getStatus() const{
FILE_LOG(logDEBUG) << __AT__ << " called, status: " << status;
return status;
}
@ -462,12 +472,14 @@ char *UDPStandardImplementation::getDetectorHostname() const{
return (char*)detHostname;
}
void UDPStandardImplementation::setEthernetInterface(char* c){
void UDPStandardImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " called";
strcpy(eth,c);
}
void UDPStandardImplementation::setUDPPortNo(int p){
void UDPStandardImplementation::setUDPPortNo(int p){ FILE_LOG(logDEBUG) << __AT__ << " called";
for(int i=0;i<numListeningThreads;i++){
server_port[i] = p+i;
}
@ -479,7 +491,8 @@ int UDPStandardImplementation::getNumberOfFrames() const {
}
int32_t UDPStandardImplementation::setNumberOfFrames(int32_t fnum){
int32_t UDPStandardImplementation::setNumberOfFrames(int32_t fnum){ FILE_LOG(logDEBUG) << __AT__ << " called";
if(fnum >= 0)
numberOfFrames = fnum;
@ -491,7 +504,8 @@ int UDPStandardImplementation::getScanTag() const{
}
int32_t UDPStandardImplementation::setScanTag(int32_t stag){
int32_t UDPStandardImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " called";
if(stag >= 0)
scanTag = stag;
@ -503,7 +517,8 @@ int UDPStandardImplementation::getDynamicRange() const{
return dynamicRange;
}
int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){
int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " called";
cout << "Setting Dynamic Range" << endl;
int olddr = dynamicRange;
@ -563,7 +578,8 @@ int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){
int UDPStandardImplementation::setShortFrame(int i){
int UDPStandardImplementation::setShortFrame(int i){ FILE_LOG(logDEBUG) << __AT__ << " called";
shortFrame=i;
if(shortFrame!=-1){
@ -593,7 +609,8 @@ int UDPStandardImplementation::setShortFrame(int i){
}
int UDPStandardImplementation::setNFrameToGui(int i){
int UDPStandardImplementation::setNFrameToGui(int i){ FILE_LOG(logDEBUG) << __AT__ << " called";
if(i>=0){
nFrameToGui = i;
setupFifoStructure();
@ -603,7 +620,8 @@ int UDPStandardImplementation::setNFrameToGui(int i){
int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){
int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " called";
if(index >= 0){
if(index != acquisitionPeriod){
@ -615,9 +633,11 @@ int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){
}
bool UDPStandardImplementation::getDataCompression(){return dataCompression;}
bool UDPStandardImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " called";
return dataCompression;}
int UDPStandardImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " called";
int UDPStandardImplementation::enableDataCompression(bool enable){
cout << "Data compression ";
if(enable)
cout << "enabled" << endl;
@ -670,7 +690,8 @@ int UDPStandardImplementation::enableDataCompression(bool enable){
/*other functions*/
void UDPStandardImplementation::deleteFilter(){
void UDPStandardImplementation::deleteFilter(){ FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
cmSub=NULL;
@ -688,6 +709,8 @@ void UDPStandardImplementation::deleteFilter(){
void UDPStandardImplementation::setupFilter(){
FILE_LOG(logDEBUG) << __AT__ << " called";
double hc = 0;
double sigma = 5;
int sign = 1;
@ -724,6 +747,7 @@ void UDPStandardImplementation::setupFilter(){
//LEO: it is not clear to me..
void UDPStandardImplementation::setupFifoStructure(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int64_t i;
int oldn = numJobsPerThread;
@ -813,6 +837,8 @@ void UDPStandardImplementation::setupFifoStructure(){
/** acquisition functions */
void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
FILE_LOG(logDEBUG) << __AT__ << " called";
//point to gui data
if (guiData == NULL)
guiData = latestData;
@ -847,6 +873,8 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){
FILE_LOG(logDEBUG) << __AT__ << " called";
//random read when gui not ready
if((!nFrameToGui) && (!guiData)){
@ -902,6 +930,7 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum,
int UDPStandardImplementation::createUDPSockets(){
FILE_LOG(logDEBUG) << __AT__ << " called";
//if eth is mistaken with ip address
@ -947,6 +976,8 @@ int UDPStandardImplementation::createUDPSockets(){
int UDPStandardImplementation::shutDownUDPSockets(){
FILE_LOG(logDEBUG) << __AT__ << " called";
for(int i=0;i<numListeningThreads;i++){
if(udpSocket[i]){
udpSocket[i]->ShutDownSocket();
@ -960,8 +991,10 @@ int UDPStandardImplementation::shutDownUDPSockets(){
// TODO: add a destroyListeningThreads
int UDPStandardImplementation::createListeningThreads(bool destroy){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
void* status;
@ -971,6 +1004,8 @@ int UDPStandardImplementation::createListeningThreads(bool destroy){
listeningthreads_mask = 0x0;
pthread_mutex_unlock(&(status_mutex));
FILE_LOG(logDEBUG) << "Starting " << __func__ << endl;
if(!destroy){
//start listening threads
@ -1017,6 +1052,8 @@ int UDPStandardImplementation::createListeningThreads(bool destroy){
int UDPStandardImplementation::createWriterThreads(bool destroy){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
void* status;
@ -1078,6 +1115,8 @@ int UDPStandardImplementation::createWriterThreads(bool destroy){
void UDPStandardImplementation::setThreadPriorities(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
//assign priorities
struct sched_param tcp_param, listen_param, write_param;
@ -1115,6 +1154,7 @@ void UDPStandardImplementation::setThreadPriorities(){
int UDPStandardImplementation::setupWriter(){
FILE_LOG(logDEBUG) << __AT__ << " called";
//reset writing thread variables
packetsInFile=0;
@ -1198,6 +1238,8 @@ int UDPStandardImplementation::setupWriter(){
int UDPStandardImplementation::createCompressionFile(int ithr, int iframe){
FILE_LOG(logDEBUG) << __AT__ << " called";
#ifdef MYROOT1
char temp[MAX_STR_LENGTH];
//create file name for gui purposes, and set up acquistion parameters
@ -1226,6 +1268,8 @@ int UDPStandardImplementation::createCompressionFile(int ithr, int iframe){
int UDPStandardImplementation::createNewFile(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int gt = getFrameIndex();
if(gt==-1) gt=0;
//create file name
@ -1234,6 +1278,9 @@ int UDPStandardImplementation::createNewFile(){
else
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex);
cout << filePath << " + " << fileName << endl;
//if filewrite and we are allowed to write
if(enableFileWrite && cbAction > DO_NOTHING){
//close
@ -1287,6 +1334,8 @@ int UDPStandardImplementation::createNewFile(){
void UDPStandardImplementation::closeFile(int ithr){
FILE_LOG(logDEBUG) << __AT__ << " called";
#ifdef VERBOSE
cout << "In closeFile for thread " << ithr << endl;
#endif
@ -1344,6 +1393,8 @@ void UDPStandardImplementation::closeFile(int ithr){
int UDPStandardImplementation::startReceiver(char message[]){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
@ -1412,6 +1463,7 @@ int UDPStandardImplementation::startReceiver(char message[]){
int UDPStandardImplementation::stopReceiver(){
FILE_LOG(logDEBUG) << __AT__ << " called";
//#ifdef VERBOSE
@ -1442,6 +1494,7 @@ int UDPStandardImplementation::stopReceiver(){
void UDPStandardImplementation::startReadout(){
FILE_LOG(logDEBUG) << __AT__ << " called";
//#ifdef VERBOSE
cout << "Start Receiver Readout" << endl;
@ -1465,6 +1518,7 @@ void UDPStandardImplementation::startReadout(){
void* UDPStandardImplementation::startListeningThread(void* this_pointer){
FILE_LOG(logDEBUG) << __AT__ << " called";
((UDPStandardImplementation*)this_pointer)->startListening();
return this_pointer;
@ -1473,6 +1527,7 @@ void* UDPStandardImplementation::startListeningThread(void* this_pointer){
void* UDPStandardImplementation::startWritingThread(void* this_pointer){
FILE_LOG(logDEBUG) << __AT__ << " called";
((UDPStandardImplementation*)this_pointer)->startWriting();
return this_pointer;
}
@ -1483,6 +1538,7 @@ void* UDPStandardImplementation::startWritingThread(void* this_pointer){
int UDPStandardImplementation::startListening(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int ithread = currentListeningThreadIndex;
#ifdef VERYVERBOSE
cout << "In startListening() " << endl;
@ -1684,6 +1740,8 @@ int UDPStandardImplementation::startListening(){
int UDPStandardImplementation::startWriting(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int ithread = currentWriterThreadIndex;
#ifdef VERYVERBOSE
cout << ithread << "In startWriting()" <<endl;
@ -1877,6 +1935,7 @@ int loop;
void UDPStandardImplementation::startFrameIndices(int ithread){
FILE_LOG(logDEBUG) << __AT__ << " called";
if (myDetectorType == EIGER)
//add currframenum later in this method for scans
@ -1911,6 +1970,9 @@ void UDPStandardImplementation::startFrameIndices(int ithread){
void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i;
#ifdef VERYVERBOSE
@ -1989,6 +2051,8 @@ int i;
void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){
FILE_LOG(logDEBUG) << __AT__ << " called";
int i,j;
#ifdef VERYDEBUG
cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[wIndex] << endl;
@ -2056,6 +2120,8 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){
void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum){
FILE_LOG(logDEBUG) << __AT__ << " called";
int packetsToSave, offset,lastpacket;
uint32_t tempframenum = framenum;
@ -2158,6 +2224,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num
void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){
FILE_LOG(logDEBUG) << __AT__ << " called";
#if defined(MYROOT1) && defined(ALLFILE_DEBUG)
writeToFile_withoutCompression(wbuf[0], numpackets,currframenum);
@ -2257,6 +2324,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer
int UDPStandardImplementation::enableTenGiga(int enable){
FILE_LOG(logDEBUG) << __AT__ << " called";
cout << "Enabling 10Gbe to" << enable << endl;

View File

@ -8,7 +8,7 @@
#include <sstream>
#include <fstream>
#include <stdlib.h>
#include <map>
#include <getopt.h>
#include "slsReceiver.h"
@ -30,10 +30,12 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
*/
//creating base receiver
int tcpip_port_no = 1984;
map<string, string> configuration_map;
int tcpip_port_no = 1954;
success=OK;
string fname = "";
string udp_interface_type = "standard";
string rest_hostname = "localhost:8081";
//parse command line for config
static struct option long_options[] = {
@ -44,6 +46,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
{"type", required_argument, 0, 't'},
{"config", required_argument, 0, 'f'},
{"rx_tcpport", required_argument, 0, 'b'},
{"rest_hostname", required_argument, 0, 'r'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
@ -52,7 +55,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
int c;
while ( c != -1 ){
c = getopt_long (argc, argv, "bfht", long_options, &option_index);
c = getopt_long (argc, argv, "bfhtr", long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
@ -72,12 +75,19 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
udp_interface_type = optarg;
break;
case 'r':
rest_hostname = optarg;
break;
case 'h':
string help_message = """\nSLS Receiver Server\n\n""";
help_message += """usage: slsReceiver --config config_fname [--rx_tcpport port]\n\n""";
help_message += """\t--config:\t configuration filename for SLS Detector receiver\n""";
help_message += """\t--rx_tcpport:\t TCP Communication Port with the client. Default: 1954.\n\n""";
help_message += """\t--rest_hostname:\t Receiver hostname:port. It applies only to REST receivers, and indicates the hostname of the REST backend. Default: localhost:8081.\n\n""";
help_message += """\t--type:\t Type of the receiver. Possible arguments are: standard, REST. Default: standard.\n\n""";
cout << help_message << endl;
break;
@ -85,17 +95,19 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
}
// if required fname parameter not available, fail
if (fname == "")
success = FAIL;
//if (fname == "")
// success = FAIL;
if((!fname.empty()) && (success == OK)){
FILE_LOG(logINFO) << "config file name " << fname;
success = read_config_file(fname, &tcpip_port_no);
//VERBOSE_PRINT("Read configuration file of " + iline + " lines");
}
else {
FILE_LOG(logERROR) << "Error opening configuration file " << fname ;
if( !fname.empty() ){
try{
FILE_LOG(logINFO) << "config file name " << fname;
success = read_config_file(fname, &tcpip_port_no, &configuration_map);
//VERBOSE_PRINT("Read configuration file of " + iline + " lines");
}
catch(...){
FILE_LOG(logERROR) << "Error opening configuration file " << fname ;
success = FAIL;
}
}
@ -104,8 +116,9 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
}
if (success==OK){
cout << "SLS Receiver starting " << udp_interface_type << endl;
FILE_LOG(logINFO) << "SLS Receiver starting " << udp_interface_type << " on port " << tcpip_port_no << endl;
udp_interface = UDPInterface::create(udp_interface_type);
udp_interface->configure(configuration_map);
tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no);
//tcp ip interface
}

View File

@ -29,25 +29,25 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() {
slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn):
myDetectorType(GOTTHARD),
receiverBase(rbase),
ret(OK),
lockStatus(0),
shortFrame(-1),
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
dynamicrange(16),
socket(NULL),
killTCPServerThread(0),
tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2){
int port_no=portNumber;
if (pn>0)
port_no = pn;
success=OK;
myDetectorType(GOTTHARD),
receiverBase(rbase),
ret(OK),
lockStatus(0),
shortFrame(-1),
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
dynamicrange(16),
socket(NULL),
killTCPServerThread(0),
tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2){
int port_no=portNumber;
if (pn>0)
port_no = pn;
success=OK;
//create socket
if(success == OK){
socket = new MySocketTCP(port_no);
@ -56,27 +56,27 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface*
delete socket;
socket=NULL;
} else {
portNumber=port_no;
portNumber=port_no;
//initialize variables
strcpy(socket->lastClientIP,"none");
strcpy(socket->thisClientIP,"none1");
strcpy(mess,"dummy message");
function_table();
#ifdef VERBOSE
cout << "Function table assigned." << endl;
#endif
//Catch signal SIGINT to close files properly
signal(SIGINT,staticCloseFile);
}
}
}
int slsReceiverTCPIPInterface::setPortNumber(int pn){
int p_number;
int p_number;
MySocketTCP *oldsocket=NULL;;
int sd=0;
@ -144,10 +144,12 @@ void slsReceiverTCPIPInterface::stop(){
cout<<"Shutting down TCP Socket and TCP thread"<<endl;
killTCPServerThread = 1;
socket->ShutDownSocket();
cout<<"Socket closed"<<endl;
void* status;
pthread_join(TCPServer_thread, &status);
killTCPServerThread = 0;
cout<<"Threads joined"<<endl;
}
@ -656,7 +658,7 @@ int slsReceiverTCPIPInterface::setup_udp(){
strcpy(eth,"");
ret = FAIL;
}
cout<<"eth:"<<eth<<endl;
FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth;
receiverBase->setEthernetInterface(eth);
//get mac address from ethernet interface

View File

@ -5,19 +5,23 @@
#include <stdio.h>
#include <fstream>
#include <map>
#include "utilities.h"
using namespace std;
int read_config_file(string fname, int *tcpip_port_no){
int read_config_file(string fname, int *tcpip_port_no, map<string, string> * configuration_map ){
ifstream infile;
string sLine,sargname;
string sLine,sargname, sargvalue;
int iline = 0;
int success = slsReceiverDefs::OK;
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) {
while(infile.good()){
@ -26,21 +30,25 @@ int read_config_file(string fname, int *tcpip_port_no){
//VERBOSE_PRINT(sLine);
if(sLine.find('#')!=string::npos){
//VERBOSE_PRINT( "Line is a comment ");
if(sLine.find('#') != string::npos)
continue;
}
else if(sLine.length()<2){
//VERBOSE_PRINT("Empty line ");
else if(sLine.length()<2)
continue;
}
else{
istringstream sstr(sLine);
//parameter name
if(sstr.good())
if(sstr.good()){
sstr >> sargname;
if (! sstr.good())
continue;
sstr >> sargvalue;
(*configuration_map)[sargname] = sargvalue;
}
//tcp port
if(sargname=="rx_tcpport"){
if(sstr.good()) {