Merge branch 'master' into eiger_receiver

Conflicts:
	include/slsReceiverTCPIPInterface.h
	slsReceiver/slsReceiver.cpp
	src/UDPStandardImplementation.cpp
	src/slsReceiverTCPIPInterface.cpp

it compiles
This commit is contained in:
sala 2014-11-11 15:53:48 +01:00 committed by Manuel Guizar
commit 7c51b06777
17 changed files with 362 additions and 209 deletions

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsReceiverSoftware Path: slsDetectorsPackage/slsReceiverSoftware
URL: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git URL: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git
Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git
Repsitory UUID: 1c259aeba8b068b9f6e550d63a9a3a14bd7d3ab7 Repsitory UUID: e019a6ce7d96d4ac9cb5762b7137245aedb4d5b8
Revision: 6 Revision: 22
Branch: master Branch: master
Last Changed Author: Maliakal_Dhanya Last Changed Author: Anna_Bergamaschi
Last Changed Rev: 6 Last Changed Rev: 22
Last Changed Date: 2014-06-03 12:06:57 +0200 Last Changed Date: 2014-10-15 09:22:40 +0200

View File

@ -213,6 +213,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
* Set UDP Port Number * Set UDP Port Number
*/ */
void setUDPPortNo(int p); void setUDPPortNo(int p);
void setUDPPortNo2(int p);
/* /*
* Returns number of frames to receive * Returns number of frames to receive
@ -287,9 +288,9 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
* @param c pointer to current file name * @param c pointer to current file name
* @param raw address of pointer, pointing to current frame to send to gui * @param raw address of pointer, pointing to current frame to send to gui
* @param fnum frame number for eiger as it is not in the packet * @param fnum frame number for eiger as it is not in the packet
* @param fstartind is the start index of the acquisition
*/ */
void readFrame(char* c,char** raw, uint32_t &fnum); void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind);
/** /**
* Closes all files * Closes all files
* @param ithr thread index * @param ithr thread index
@ -777,6 +778,8 @@ protected:
* 2 we open, close, write file, callback does not do anything */ * 2 we open, close, write file, callback does not do anything */
int cbAction; int cbAction;
/** true if bottom half module for eiger */
bool bottom;
public: public:

View File

@ -281,6 +281,11 @@ class UDPInterface {
*/ */
virtual void setUDPPortNo(int p) = 0; virtual void setUDPPortNo(int p) = 0;
/**
* Set UDP Port Number
*/
virtual void setUDPPortNo2(int p) = 0;
/** /**
* Set Ethernet Interface or IP to listen to * Set Ethernet Interface or IP to listen to
*/ */
@ -322,8 +327,9 @@ class UDPInterface {
* @param c pointer to current file name * @param c pointer to current file name
* @param raw address of pointer, pointing to current frame to send to gui * @param raw address of pointer, pointing to current frame to send to gui
* @param fnum frame number for eiger as it is not in the packet * @param fnum frame number for eiger as it is not in the packet
* @param fstartind is the start index of the acquisition
*/ */
virtual void readFrame(char* c,char** raw, uint32_t &fnum) = 0; virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind ) = 0;
/** set status to transmitting and /** set status to transmitting and
* when fifo is empty later, sets status to run_finished * when fifo is empty later, sets status to run_finished

View File

@ -223,6 +223,7 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI
* Set UDP Port Number * Set UDP Port Number
*/ */
void setUDPPortNo(int p); void setUDPPortNo(int p);
void setUDPPortNo2(int p);
/* /*
* Returns number of frames to receive * Returns number of frames to receive
@ -300,7 +301,7 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI
* @param raw address of pointer, pointing to current frame to send to gui * @param raw address of pointer, pointing to current frame to send to gui
* @param fnum frame number for eiger as it is not in the packet * @param fnum frame number for eiger as it is not in the packet
*/ */
void readFrame(char* c,char** raw, uint32_t &fnum); void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind);
/** /**
* Closes all files * Closes all files

View File

@ -212,6 +212,10 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
* Set UDP Port Number * Set UDP Port Number
*/ */
void setUDPPortNo(int p); void setUDPPortNo(int p);
/**
* Set UDP Port Number
*/
void setUDPPortNo2(int p);
/* /*
* Returns number of frames to receive * Returns number of frames to receive
@ -287,8 +291,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
* @param raw address of pointer, pointing to current frame to send to gui * @param raw address of pointer, pointing to current frame to send to gui
* @param fnum frame number for eiger as it is not in the packet * @param fnum frame number for eiger as it is not in the packet
*/ */
void readFrame(char* c,char** raw, uint32_t &fnum); void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind);
/** /**
* Closes all files * Closes all files
* @param ithr thread index * @param ithr thread index

View File

@ -61,6 +61,8 @@ class sockaddr_in;
#endif #endif
#include <stdlib.h> /******exit */
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <iostream> #include <iostream>
@ -558,6 +560,16 @@ enum communicationProtocol{
break; break;
case UDP: case UDP:
if (socketDescriptor<0) return -1; if (socketDescriptor<0) return -1;
/*
cout <<"******listening inside genericsocket"<<endl;
for(int i=0;i<10000;i++){
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,5000, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
cout<<i<<":"<<nsent<<"\t\t";
}
exit(-1);
*/
//if length given, listens to length, else listens for packetsize till length is reached //if length given, listens to length, else listens for packetsize till length is reached
if(length){ if(length){
while(length>0){ while(length>0){

View File

@ -1,11 +1,11 @@
//#define SVNPATH "" //#define SVNPATH ""
#define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git" #define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUID "1c259aeba8b068b9f6e550d63a9a3a14bd7d3ab7" #define SVNREPUUID "e019a6ce7d96d4ac9cb5762b7137245aedb4d5b8"
//#define SVNREV 0x6 //#define SVNREV 0x22
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTH "Maliakal_Dhanya" #define SVNAUTH "Anna_Bergamaschi"
#define SVNREV 0x6 #define SVNREV 0x22
#define SVNDATE 0x20140603 #define SVNDATE 0x20141015
// //

View File

@ -26,9 +26,11 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs {
* @param succecc socket creation was successfull * @param succecc socket creation was successfull
* @param rbase pointer to the receiver base * @param rbase pointer to the receiver base
* @param pn port number (defaults to default port number) * @param pn port number (defaults to default port number)
* @param bot mode is bottom if true, else its a top half module
*/ */
slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn=-1);
slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn=-1, bool bot=false);
/** /**
* Sets the port number to listen to. * Sets the port number to listen to.
Take care that the client must know to whcih port it has to listen to, so normally it is better to use a fixes port from the instatiation or change it from the client. Take care that the client must know to whcih port it has to listen to, so normally it is better to use a fixes port from the instatiation or change it from the client.
@ -272,6 +274,9 @@ private:
/** port number */ /** port number */
int portNumber; int portNumber;
/** true if bottom half module for eiger */
bool bottom;
protected: protected:
/** Socket */ /** Socket */

View File

@ -43,7 +43,7 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public UDPInter
/** /**
* Constructor * Constructor
*/ */
slsReceiverUDPFunctions(); slsReceiverUDPFunctions(bool bot);
/** /**
* Destructor * Destructor
@ -216,6 +216,11 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public UDPInter
*/ */
void setUDPPortNo(int p); void setUDPPortNo(int p);
/**
* Set UDP Port Number2
*/
void setUDPPortNo2(int p);
/* /*
* Returns number of frames to receive * Returns number of frames to receive
* This is the number of frames to expect to receiver from the detector. * This is the number of frames to expect to receiver from the detector.
@ -289,8 +294,9 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public UDPInter
* @param c pointer to current file name * @param c pointer to current file name
* @param raw address of pointer, pointing to current frame to send to gui * @param raw address of pointer, pointing to current frame to send to gui
* @param fnum frame number for eiger as it is not in the packet * @param fnum frame number for eiger as it is not in the packet
* @param fstartind is the start index of the acquisition
*/ */
void readFrame(char* c,char** raw, uint32_t &fnum); void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind);
/** /**
* Closes all files * Closes all files
@ -471,7 +477,6 @@ private:
unsigned char header_after[24]; unsigned char header_after[24];
} eiger_image_header; } eiger_image_header;
/** structure of an eiger image header*/ /** structure of an eiger image header*/
typedef struct typedef struct
{ {
@ -766,6 +771,9 @@ private:
* 2 we open, close, write file, callback does not do anything */ * 2 we open, close, write file, callback does not do anything */
int cbAction; int cbAction;
/** true if bottom half module for eiger */
bool bottom;
public: public:

View File

@ -55,7 +55,9 @@ public:
GOTTHARD, /**< gotthard */ GOTTHARD, /**< gotthard */
PICASSO, /**< picasso */ PICASSO, /**< picasso */
AGIPD, /**< agipd */ AGIPD, /**< agipd */
MOENCH /**< moench */ MOENCH, /**< moench */
JUNGFRAU, /**< jungfrau */
JUNGFRAUCTB /**< jungfrauCTBversion */
}; };
@ -85,7 +87,9 @@ public:
MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */ MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */
PROGRESS, /**< fraction of measurement elapsed - only get! */ PROGRESS, /**< fraction of measurement elapsed - only get! */
MEASUREMENTS_NUMBER MEASUREMENTS_NUMBER,
FRAMES_FROM_START,
FRAMES_FROM_START_PG
}; };

View File

@ -8,7 +8,7 @@
enum { enum {
//General functions //General functions
F_EXEC_RECEIVER_COMMAND=0, /**< command is executed */ F_EXEC_RECEIVER_COMMAND=128, /**< command is executed */
F_EXIT_RECEIVER, /**< turn off receiver server */ F_EXIT_RECEIVER, /**< turn off receiver server */
F_LOCK_RECEIVER, /**< Locks/Unlocks server communication to the given client */ F_LOCK_RECEIVER, /**< Locks/Unlocks server communication to the given client */
F_GET_LAST_RECEIVER_CLIENT_IP, /**< returns the IP of the client last connected to the receiver */ F_GET_LAST_RECEIVER_CLIENT_IP, /**< returns the IP of the client last connected to the receiver */

View File

@ -29,7 +29,8 @@ using namespace std;
UDPBaseImplementation::UDPBaseImplementation(){} UDPBaseImplementation::UDPBaseImplementation(){
}
UDPBaseImplementation::~UDPBaseImplementation(){} UDPBaseImplementation::~UDPBaseImplementation(){}
@ -291,10 +292,13 @@ void UDPBaseImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) <<
} }
void UDPBaseImplementation::setUDPPortNo(int p){ FILE_LOG(logDEBUG) << __AT__ << " starting"; void UDPBaseImplementation::setUDPPortNo(int p){
for(int i=0;i<numListeningThreads;i++){ server_port[0] = p;
server_port[i] = p+i; }
}
void UDPBaseImplementation::setUDPPortNo2(int p){
server_port[1] = p;
} }
@ -636,41 +640,43 @@ void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ <
/** acquisition functions */ /** acquisition functions */
void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t& fstartind){
void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ FILE_LOG(logDEBUG) << __AT__ << " starting"; FILE_LOG(logDEBUG) << __AT__ << " starting";
//point to gui data
if (guiData == NULL) //point to gui data
guiData = latestData; if (guiData == NULL)
guiData = latestData;
//copy data and filename
strcpy(c,guiFileName); //copy data and filename
fnum = guiFrameNumber; strcpy(c,guiFileName);
fnum = guiFrameNumber;
fstartind = getStartFrameIndex();
//could not get gui data
if(!guiDataReady){ //could not get gui data
*raw = NULL; if(!guiDataReady){
} *raw = NULL;
//data ready, set guidata to receive new data }
else{ //data ready, set guidata to receive new data
*raw = guiData; else{
guiData = NULL; *raw = guiData;
guiData = NULL;
pthread_mutex_lock(&dataReadyMutex);
guiDataReady = 0; pthread_mutex_lock(&dataReadyMutex);
pthread_mutex_unlock(&dataReadyMutex); guiDataReady = 0;
if((nFrameToGui) && (writerthreads_mask)){ pthread_mutex_unlock(&dataReadyMutex);
/*if(nFrameToGui){*/ if((nFrameToGui) && (writerthreads_mask)){
//release after getting data /*if(nFrameToGui){*/
sem_post(&smp); //release after getting data
} sem_post(&smp);
} }
}
} }
void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting"; void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting";
//random read when gui not ready //random read when gui not ready

View File

@ -19,6 +19,7 @@ using namespace std;
using namespace std; using namespace std;
// TODO: I do not really like passing a bottom-top boolean to the constructor...
UDPInterface * UDPInterface::create(string receiver_type){ UDPInterface * UDPInterface::create(string receiver_type){
if (receiver_type == "standard"){ if (receiver_type == "standard"){

View File

@ -38,6 +38,7 @@ using namespace std;
UDPRESTImplementation::UDPRESTImplementation(){ UDPRESTImplementation::UDPRESTImplementation(){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
//TODO I do not really know what to do with bottom...
// Default values // Default values
rest_hostname = "localhost"; rest_hostname = "localhost";
rest_port = 8081; rest_port = 8081;
@ -294,13 +295,22 @@ void UDPRESTImplementation::setEthernetInterface(char* c){
//FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; //FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done";
} }
/*
void UDPRESTImplementation::setUDPPortNo(int p){ void UDPRESTImplementation::setUDPPortNo(int p){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
for(int i=0;i<numListeningThreads;i++){ for(int i=0;i<numListeningThreads;i++){
server_port[i] = p+i; server_port[i] = p+i;
} }
} }
*/
void UDPRESTImplementation::setUDPPortNo(int p){
server_port[0] = p;
}
void UDPRESTImplementation::setUDPPortNo2(int p){
server_port[1] = p;
}
/* /*
int UDPRESTImplementation::getNumberOfFrames() const { int UDPRESTImplementation::getNumberOfFrames() const {
@ -567,8 +577,7 @@ void UDPRESTImplementation::setupFifoStructure(){
/** acquisition functions */ /** acquisition functions */
void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){
void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
//point to gui data //point to gui data
if (guiData == NULL) if (guiData == NULL)
@ -577,7 +586,7 @@ void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
//copy data and filename //copy data and filename
strcpy(c,guiFileName); strcpy(c,guiFileName);
fnum = guiFrameNumber; fnum = guiFrameNumber;
fstartind = getStartFrameIndex();
//could not get gui data //could not get gui data
if(!guiDataReady){ if(!guiDataReady){

View File

@ -24,10 +24,73 @@
#include <string.h> #include <string.h>
#include <iostream> #include <iostream>
using namespace std; using namespace std;
#define EIGER_32BIT_INITIAL_CONSTANT 0x17c
UDPStandardImplementation::UDPStandardImplementation()
//:
//thread_started(0),
//eth(NULL),
//latestData(NULL),
//guiFileName(NULL),
//guiFrameNumber(0),
//tengigaEnable(0)
{
thread_started = 0;
eth = NULL;
latestData = NULL;
guiFileName = NULL;
guiFrameNumber = NULL;
tengigaEnable = 0;
for(int i=0;i<MAX_NUM_LISTENING_THREADS;i++){
udpSocket[i] = NULL;
server_port[i] = DEFAULT_UDP_PORTNO+i;
mem0[i] = NULL;
fifo[i] = NULL;
fifoFree[i] = NULL;
}
for(int i=0;i<MAX_NUM_WRITER_THREADS;i++){
singlePhotonDet[i] = NULL;
receiverdata[i] = NULL;
}
startAcquisitionCallBack = NULL;
pStartAcquisition = NULL;
acquisitionFinishedCallBack = NULL;
pAcquisitionFinished = NULL;
rawDataReadyCallBack = NULL;
pRawDataReady = NULL;
initializeMembers();
//mutex
pthread_mutex_init(&dataReadyMutex,NULL);
pthread_mutex_init(&status_mutex,NULL);
pthread_mutex_init(&progress_mutex,NULL);
pthread_mutex_init(&write_mutex,NULL);
//to increase socket receiver buffer size and max length of input queue by changing kernel settings
if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max"))
cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl;
else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog"))
cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl;
/** permanent setting heiner
net.core.rmem_max = 104857600 # 100MiB
net.core.netdev_max_backlog = 250000
sysctl -p
// from the manual
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.netdev_max_backlog=250000
*/
}
void UDPStandardImplementation::initializeMembers(){ void UDPStandardImplementation::initializeMembers(){
myDetectorType = GENERIC; myDetectorType = GENERIC;
maxPacketsPerFile = 0; maxPacketsPerFile = 0;
@ -125,63 +188,6 @@ void UDPStandardImplementation::initializeMembers(){
} }
UDPStandardImplementation::UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called";
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;
server_port[i] = DEFAULT_UDP_PORTNO+i;
mem0[i] = NULL;
fifo[i] = NULL;
fifoFree[i] = NULL;
}
for(int i=0;i<MAX_NUM_WRITER_THREADS;i++){
singlePhotonDet[i] = NULL;
receiverdata[i] = NULL;
}
startAcquisitionCallBack = NULL;
pStartAcquisition = NULL;
acquisitionFinishedCallBack = NULL;
pAcquisitionFinished = NULL;
rawDataReadyCallBack = NULL;
pRawDataReady = NULL;
UDPStandardImplementation::initializeMembers();
//mutex
pthread_mutex_init(&dataReadyMutex,NULL);
pthread_mutex_init(&status_mutex,NULL);
pthread_mutex_init(&progress_mutex,NULL);
pthread_mutex_init(&write_mutex,NULL);
//to increase socket receiver buffer size and max length of input queue by changing kernel settings
if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max"))
cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl;
else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog"))
cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl;
/** permanent setting heiner
net.core.rmem_max = 104857600 # 100MiB
net.core.netdev_max_backlog = 250000
sysctl -p
// from the manual
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.netdev_max_backlog=250000
*/
}
UDPStandardImplementation::~UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called"; UDPStandardImplementation::~UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called";
@ -478,11 +484,15 @@ void UDPStandardImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBU
} }
void UDPStandardImplementation::setUDPPortNo(int p){ FILE_LOG(logDEBUG) << __AT__ << " called"; void UDPStandardImplementation::setUDPPortNo(int p){
FILE_LOG(logDEBUG) << __AT__ << " called";
server_port[0] = p;
}
for(int i=0;i<numListeningThreads;i++){
server_port[i] = p+i; void UDPStandardImplementation::setUDPPortNo2(int p){
} FILE_LOG(logDEBUG) << __AT__ << " called";
server_port[1] = p;
} }
@ -835,10 +845,8 @@ void UDPStandardImplementation::setupFifoStructure(){
/** acquisition functions */ /** acquisition functions */
void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){
void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
//point to gui data //point to gui data
if (guiData == NULL) if (guiData == NULL)
guiData = latestData; guiData = latestData;
@ -846,7 +854,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
//copy data and filename //copy data and filename
strcpy(c,guiFileName); strcpy(c,guiFileName);
fnum = guiFrameNumber; fnum = guiFrameNumber;
fstartind = getStartFrameIndex();
//could not get gui data //could not get gui data
if(!guiDataReady){ if(!guiDataReady){
@ -932,7 +940,17 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum,
int UDPStandardImplementation::createUDPSockets(){ int UDPStandardImplementation::createUDPSockets(){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
int port[2];
port[0] = server_port[0];
port[1] = server_port[1];
/** eiger specific */
/*
if(bottom){
port[0] = server_port[1];
port[1] = server_port[0];
}
*/
//if eth is mistaken with ip address //if eth is mistaken with ip address
if (strchr(eth,'.')!=NULL) if (strchr(eth,'.')!=NULL)
strcpy(eth,""); strcpy(eth,"");
@ -944,23 +962,25 @@ int UDPStandardImplementation::createUDPSockets(){
cout<<"warning:eth is empty.listening to all"<<endl; cout<<"warning:eth is empty.listening to all"<<endl;
for(int i=0;i<numListeningThreads;i++) for(int i=0;i<numListeningThreads;i++)
udpSocket[i] = new genericSocket(server_port[i],genericSocket::UDP,bufferSize); udpSocket[i] = new genericSocket(port[i],genericSocket::UDP,bufferSize);
} }
//normal socket //normal socket
else{ else{
cout<<"eth:"<<eth<<endl; cout<<"eth:"<<eth<<endl;
for(int i=0;i<numListeningThreads;i++) for(int i=0;i<numListeningThreads;i++)
udpSocket[i] = new genericSocket(server_port[i],genericSocket::UDP,bufferSize,eth); udpSocket[i] = new genericSocket(port[i],genericSocket::UDP,bufferSize,eth);
} }
//error //error
int iret; int iret;
for(int i=0;i<numListeningThreads;i++){ for(int i=0;i<numListeningThreads;i++){
iret = udpSocket[i]->getErrorStatus(); iret = udpSocket[i]->getErrorStatus();
if(iret){ if(!iret)
cout << "UDP port opened at port " << port[i] << endl;
else{
#ifdef VERBOSE #ifdef VERBOSE
cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; cout << "Could not create UDP socket on port " << port[i] << " error:" << iret << endl;
#endif #endif
return FAIL; return FAIL;
} }
@ -1418,7 +1438,7 @@ int UDPStandardImplementation::startReceiver(char message[]){
cout << endl << message << endl; cout << endl << message << endl;
return FAIL; return FAIL;
} }
cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; cout << "UDP socket(s) created successfully." << endl;
if(setupWriter() == FAIL){ if(setupWriter() == FAIL){
@ -1589,9 +1609,13 @@ int UDPStandardImplementation::startListening(){
//normal listening //normal listening
else if(!carryonBufferSize){ else if(!carryonBufferSize){
/* if(!ithread){*/
rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize);
expected = maxBufferSize; expected = maxBufferSize;
/*}else{
while(1) usleep(100000000);
}
*/
} }
//the remaining packets from previous buffer //the remaining packets from previous buffer
else{ else{
@ -1608,24 +1632,26 @@ int UDPStandardImplementation::startListening(){
expected = maxBufferSize - carryonBufferSize; expected = maxBufferSize - carryonBufferSize;
} }
#ifdef VERYDEBUG //#ifdef VERYDEBUG
cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl;
#endif //#endif
//start indices for each start of scan/acquisition - eiger does it before //start indices for each start of scan/acquisition - eiger does it before
if((!measurementStarted) && (rc > 0) && (!ithread)) if((!measurementStarted) && (rc > 0) && (!ithread))
startFrameIndices(ithread); startFrameIndices(ithread);
//problem in receiving or end of acquisition //problem in receiving or end of acquisition
if((rc < expected)||(rc <= 0)){ if((rc < expected)||(rc <= 0)){
stopListening(ithread,rc,packetcount,total); stopListening(ithread,rc,packetcount,total);
continue; continue;
} }
/*
//start indices for each start of scan/acquisition - eiger does it before
if((!measurementStarted) && (rc > 0) && (!ithread))
startFrameIndices(ithread);
*/
//reset //reset
packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread;
@ -1811,7 +1837,10 @@ int loop;
//for progress //for progress
if(myDetectorType == EIGER){ if(myDetectorType == EIGER){
tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum);
tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 if(dynamicRange != 32)
tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1
else
tempframenum = ((tempframenum / EIGER_32BIT_INITIAL_CONSTANT) + startFrameIndex)-1;//eiger 32 bit mode is a multiple of 17c. +startframeindex for scans
}else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1))
tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset);
else else
@ -1836,6 +1865,7 @@ int loop;
if (cbAction < DO_EVERYTHING){ if (cbAction < DO_EVERYTHING){
for(i=0;i<numListeningThreads;++i) for(i=0;i<numListeningThreads;++i)
/* for eiger 32 bit mode, currframenum like gotthard, does not start from 0 or 1 */
rawDataReadyCallBack(currframenum, wbuf[i], numpackets * onePacketSize, sfilefd, guiData,pRawDataReady); rawDataReadyCallBack(currframenum, wbuf[i], numpackets * onePacketSize, sfilefd, guiData,pRawDataReady);
}else if (numpackets > 0){ }else if (numpackets > 0){
for(i=0;i<numListeningThreads;++i) for(i=0;i<numListeningThreads;++i)
@ -1957,8 +1987,13 @@ void UDPStandardImplementation::startFrameIndices(int ithread){
cout << "startAcquisitionIndex:" << startAcquisitionIndex<<endl; cout << "startAcquisitionIndex:" << startAcquisitionIndex<<endl;
} }
//for scans, cuz currfraenum resets //for scans, cuz currfraenum resets
else if (myDetectorType == EIGER) else if (myDetectorType == EIGER){
startFrameIndex += currframenum; if(dynamicRange == 32)
startFrameIndex = (currframenum + 1);// to be added later for scans
else
startFrameIndex += currframenum;
}
cout << "startFrameIndex:" << startFrameIndex<<endl; cout << "startFrameIndex:" << startFrameIndex<<endl;
@ -2019,9 +2054,9 @@ int i;
#endif #endif
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
#ifdef VERYDEBUG //#ifdef VERYDEBUG
cout << ithread << ": Frames listened to " << dec << ((totalListeningFrameCount[ithread]*numListeningThreads)/packetsPerFrame) << endl; cout << ithread << ": Frames listened to " << dec << ((totalListeningFrameCount[ithread]*numListeningThreads)/packetsPerFrame) << endl;
#endif //#endif
//waiting for all listening threads to be done, to print final count of frames listened to //waiting for all listening threads to be done, to print final count of frames listened to
if(ithread == 0){ if(ithread == 0){

View File

@ -37,12 +37,14 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
string udp_interface_type = "standard"; string udp_interface_type = "standard";
string rest_hostname = "localhost:8081"; string rest_hostname = "localhost:8081";
bool bottom = false; //TODO: properly set new parameter -> mode?
//parse command line for config //parse command line for config
static struct option long_options[] = { static struct option long_options[] = {
/* These options set a flag. */ /* These options set a flag. */
//{"verbose", no_argument, &verbose_flag, 1}, //{"verbose", no_argument, &verbose_flag, 1},
/* These options dont set a flag. /* These options dont set a flag.
We distinguish them by their indices. */ We distinguish them by their indices. */
{"mode", required_argument, 0, 'm'},
{"type", required_argument, 0, 't'}, {"type", required_argument, 0, 't'},
{"config", required_argument, 0, 'f'}, {"config", required_argument, 0, 'f'},
{"rx_tcpport", required_argument, 0, 'b'}, {"rx_tcpport", required_argument, 0, 'b'},
@ -55,13 +57,14 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
int c; int c;
while ( c != -1 ){ while ( c != -1 ){
c = getopt_long (argc, argv, "bfhtr", long_options, &option_index); c = getopt_long (argc, argv, "mbfhtr", long_options, &option_index);
/* Detect the end of the options. */ /* Detect the end of the options. */
if (c == -1) if (c == -1)
break; break;
switch(c){ switch(c){
case 'f': case 'f':
fname = optarg; fname = optarg;
//cout << long_options[option_index].name << " " << optarg << endl; //cout << long_options[option_index].name << " " << optarg << endl;
@ -83,6 +86,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
string help_message = """\nSLS Receiver Server\n\n"""; string help_message = """\nSLS Receiver Server\n\n""";
help_message += """usage: slsReceiver --config config_fname [--rx_tcpport port]\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--config:\t configuration filename for SLS Detector receiver\n""";
help_message += """\t--mode:\t ???\n""";
help_message += """\t--rx_tcpport:\t TCP Communication Port with the client. Default: 1954.\n\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--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""";

View File

@ -17,6 +17,9 @@
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <stdlib.h> #include <stdlib.h>
#include <byteswap.h> //linux5
#define be64toh(x) __bswap_64 (x) //linux5
//#include <endian.h> //linux6
using namespace std; using namespace std;
@ -27,27 +30,27 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() {
closeFile(0); closeFile(0);
} }
slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn, bool bot):
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),
bottom(bot){
int port_no=portNumber;
if (pn>0)
port_no = pn;
success=OK;
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;
//create socket //create socket
if(success == OK){ if(success == OK){
socket = new MySocketTCP(port_no); socket = new MySocketTCP(port_no);
@ -615,10 +618,10 @@ int slsReceiverTCPIPInterface::setup_udp(){
ret=OK; ret=OK;
strcpy(mess,"could not set up udp connection"); strcpy(mess,"could not set up udp connection");
char retval[MAX_STR_LENGTH]=""; char retval[MAX_STR_LENGTH]="";
char args[2][MAX_STR_LENGTH]; char args[3][MAX_STR_LENGTH];
string temp; string temp;
int udpport; int udpport,udpport2;
char eth[MAX_STR_LENGTH]; char eth[MAX_STR_LENGTH];
@ -643,8 +646,9 @@ int slsReceiverTCPIPInterface::setup_udp(){
else{ else{
//set up udp port //set up udp port
sscanf(args[1],"%d",&udpport); sscanf(args[1],"%d",&udpport);
sscanf(args[2],"%d",&udpport2);
receiverBase->setUDPPortNo(udpport); receiverBase->setUDPPortNo(udpport);
receiverBase->setUDPPortNo2(udpport2);
//setup udpip //setup udpip
//get ethernet interface or IP to listen to //get ethernet interface or IP to listen to
temp = genericSocket::ipToName(args[0]); temp = genericSocket::ipToName(args[0]);
@ -1002,8 +1006,8 @@ int slsReceiverTCPIPInterface::moench_read_frame(){
else{ else{
ret = OK; ret = OK;
startIndex=receiverBase->getStartFrameIndex(); /*startIndex=receiverBase->getStartFrameIndex();*/
receiverBase->readFrame(fName,&raw,index); receiverBase->readFrame(fName,&raw,index,startIndex);
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if (raw == NULL){ if (raw == NULL){
@ -1172,8 +1176,8 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){
cout<<"haven't caught any frame yet"<<endl; cout<<"haven't caught any frame yet"<<endl;
}else{ }else{
ret = OK; ret = OK;
startIndex=receiverBase->getStartFrameIndex(); /*startIndex=receiverBase->getStartFrameIndex();*/
receiverBase->readFrame(fName,&raw,index); receiverBase->readFrame(fName,&raw,index,startIndex);
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if (raw == NULL){ if (raw == NULL){
@ -1304,13 +1308,9 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
char* raw = new char[frameSize]; char* raw = new char[frameSize];
char* origVal = new char[frameSize]; char* origVal = new char[frameSize];
char* retval = new char[dataSize]; char* retval = new char[dataSize];
uint32_t startIndex=0;
strcpy(mess,"Could not read frame\n"); strcpy(mess,"Could not read frame\n");
/* typedef struct{
unsigned char num1[4];
unsigned char num2[4];
} eiger_packet_header;*/
// execute action if the arguments correctly arrived // execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_UDP_FUNCTIONS #ifdef SLS_RECEIVER_UDP_FUNCTIONS
@ -1328,7 +1328,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
else{ else{
ret = OK; ret = OK;
/** read a frame */ /** read a frame */
receiverBase->readFrame(fName,&raw, index); receiverBase->readFrame(fName,&raw,index,startIndex);
#ifdef VERBOSE #ifdef VERBOSE
cout << "index:" << dec << index << endl; cout << "index:" << dec << index << endl;
#endif #endif
@ -1341,7 +1341,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
} }
/**proper frame*/ /**proper frame*/
else{ else{//cout<<"**** got proper frame ******"<<endl;
memcpy(origVal,raw,frameSize); memcpy(origVal,raw,frameSize);
raw=NULL; raw=NULL;
@ -1349,12 +1349,11 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
int c1=8;//first port int c1=8;//first port
int c2=(frameSize/2) + 8; //second port int c2=(frameSize/2) + 8; //second port
int retindex=0; int retindex=0;
int irow,ibytesperpacket,irepeat; int irow,ibytesperpacket;
int repeat=1;
int linesperpacket = (16/dynamicrange)* 1;// 16:1 line, 8:2 lines, 4:4 lines, 32: 0.5 int linesperpacket = (16/dynamicrange)* 1;// 16:1 line, 8:2 lines, 4:4 lines, 32: 0.5
int numbytesperlineperport=(EIGER_PIXELS_IN_ONE_ROW/EIGER_MAX_PORTS)*dynamicrange/8;//16:1024,8:512,4:256,32:2048 int numbytesperlineperport=(EIGER_PIXELS_IN_ONE_ROW/EIGER_MAX_PORTS)*dynamicrange/8;//16:1024,8:512,4:256,32:2048
int datapacketlength = EIGER_ONE_GIGA_ONE_DATA_SIZE; int datapacketlength = EIGER_ONE_GIGA_ONE_DATA_SIZE;
int total_num_bytes = 1040*(16*dynamicrange)*2;
if(tenGigaEnable){ if(tenGigaEnable){
linesperpacket = (16/dynamicrange)* 4;// 16:4 line, 8:8 lines, 4:16 lines, 32: 2 linesperpacket = (16/dynamicrange)* 4;// 16:4 line, 8:8 lines, 4:16 lines, 32: 2
@ -1362,51 +1361,108 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
} }
//if 1GbE, one line is split into two packets for 32 bit mode, so its special //if 1GbE, one line is split into two packets for 32 bit mode, so its special
else if(dynamicrange == 32){ else if(dynamicrange == 32){
repeat=2;
numbytesperlineperport = 1024; numbytesperlineperport = 1024;
linesperpacket = 1; //we repeat this twice anyway for 32 bit linesperpacket = 1; //we repeat this twice anyway for 32 bit
} }
if(!bottom){
for(irow=0;irow<EIGER_PIXELS_IN_ONE_COL/linesperpacket;++irow){ for(irow=0;irow<EIGER_PIXELS_IN_ONE_COL/linesperpacket;++irow){
ibytesperpacket=0; ibytesperpacket=0;
while(ibytesperpacket<datapacketlength){ while(ibytesperpacket<datapacketlength){
for(irepeat=0;irepeat<repeat;irepeat++){//only for 32 bit mode, take 2 packets from same port //first port
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport); memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport; retindex += numbytesperlineperport;
c1 += numbytesperlineperport; c1 += numbytesperlineperport;
} if(dynamicrange == 32){
for(irepeat=0;irepeat<repeat;irepeat++){//only for 32 bit mode, take 2 packets from same port c1 += 16;
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c1 += numbytesperlineperport;
c1 += 16;
}
//second port
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport); memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += numbytesperlineperport; retindex += numbytesperlineperport;
c2 += numbytesperlineperport; c2 += numbytesperlineperport;
if(dynamicrange == 32){
c2 += 16;
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c2 += numbytesperlineperport;
c2 += 16;
}
ibytesperpacket += numbytesperlineperport;
}
if(dynamicrange != 32) {
c1 += 16;
c2 += 16;
} }
ibytesperpacket += numbytesperlineperport;
} }
c1 += 16;
c2 += 16; }
//bottom half module
else{
c1 = (frameSize/2) - numbytesperlineperport - 8 ;
c2 = total_num_bytes - numbytesperlineperport - 8;
for(irow=0;irow<EIGER_PIXELS_IN_ONE_COL/linesperpacket;++irow){
ibytesperpacket=0;
while(ibytesperpacket<datapacketlength){
if(dynamicrange == 32){
//first port first chip
c1 -= (numbytesperlineperport + 16);
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
//first port second chip
c1 += (numbytesperlineperport+16);
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c1 -= (numbytesperlineperport*2+32);//1024*2+16*2
//second port first chip
c2 -= (numbytesperlineperport + 16);
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += numbytesperlineperport;
//second port second chip
c2 += (numbytesperlineperport + 16);
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c2 -= (numbytesperlineperport*2+32);
}else{
//first port
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c1 -= numbytesperlineperport;
//second port
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c2 -= numbytesperlineperport;
}
ibytesperpacket += numbytesperlineperport;
}
if(dynamicrange != 32) {
c1 -= 16;
c2 -= 16;
}
}
} }
//64 bit htonl cuz of endianness
int64_t temp;
for(i=0;i<(1024*(16*dynamicrange)*2)/8;i++){ for(i=0;i<(1024*(16*dynamicrange)*2)/8;i++){
(*(((uint64_t*)retval)+i)) = be64toh(((uint64_t)(*(((uint64_t*)retval)+i))));
/*
int64_t temp;
temp = ((uint64_t)(*(((uint64_t*)retval)+i))); temp = ((uint64_t)(*(((uint64_t*)retval)+i)));
temp = ((temp << 8) & 0xFF00FF00FF00FF00ULL ) | ((temp >> 8) & 0x00FF00FF00FF00FFULL ); temp = ((temp << 8) & 0xFF00FF00FF00FF00ULL ) | ((temp >> 8) & 0x00FF00FF00FF00FFULL );
temp = ((temp << 16) & 0xFFFF0000FFFF0000ULL ) | ((temp >> 16) & 0x0000FFFF0000FFFFULL ); temp = ((temp << 16) & 0xFFFF0000FFFF0000ULL ) | ((temp >> 16) & 0x0000FFFF0000FFFFULL );
temp = (temp << 32) | ((temp >> 32) & 0xFFFFFFFFULL); temp = (temp << 32) | ((temp >> 32) & 0xFFFFFFFFULL);
(*(((uint64_t*)retval)+i)) = temp; (*(((uint64_t*)retval)+i)) = temp;
*/
} }
/* arg = index-startIndex;
( (((val) >> 56) & 0x00000000000000FF) | (((val) >> 40) & 0x000000000000FF00) | \
(((val) >> 24) & 0x0000000000FF0000) | (((val) >> 8) & 0x00000000FF000000) | \
(((val) << 8) & 0x000000FF00000000) | (((val) << 24) & 0x0000FF0000000000) | \
(((val) << 40) & 0x00FF000000000000) | (((val) << 56) & 0xFF00000000000000) )
*/
/*
for(i=0;i<(1024*(16*dynamicrange)*2)/4;i++)
(*(((uint32_t*)retval)+i)) = htonl((uint32_t)(*(((uint32_t*)retval)+i)));
*/
arg = index-1;
} }
} }