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
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
Repsitory UUID: 1c259aeba8b068b9f6e550d63a9a3a14bd7d3ab7
Revision: 6
Repsitory UUID: e019a6ce7d96d4ac9cb5762b7137245aedb4d5b8
Revision: 22
Branch: master
Last Changed Author: Maliakal_Dhanya
Last Changed Rev: 6
Last Changed Date: 2014-06-03 12:06:57 +0200
Last Changed Author: Anna_Bergamaschi
Last Changed Rev: 22
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
*/
void setUDPPortNo(int p);
void setUDPPortNo2(int p);
/*
* 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 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 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
* @param ithr thread index
@ -777,6 +778,8 @@ protected:
* 2 we open, close, write file, callback does not do anything */
int cbAction;
/** true if bottom half module for eiger */
bool bottom;
public:

View File

@ -281,6 +281,11 @@ class UDPInterface {
*/
virtual void setUDPPortNo(int p) = 0;
/**
* Set UDP Port Number
*/
virtual void setUDPPortNo2(int p) = 0;
/**
* Set Ethernet Interface or IP to listen to
*/
@ -322,8 +327,9 @@ class UDPInterface {
* @param c pointer to current file name
* @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 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
* 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
*/
void setUDPPortNo(int p);
void setUDPPortNo2(int p);
/*
* 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 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

View File

@ -212,6 +212,10 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
* Set UDP Port Number
*/
void setUDPPortNo(int p);
/**
* Set UDP Port Number
*/
void setUDPPortNo2(int p);
/*
* 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 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
* @param ithr thread index

View File

@ -61,6 +61,8 @@ class sockaddr_in;
#endif
#include <stdlib.h> /******exit */
#include <unistd.h>
#include <string.h>
#include <iostream>
@ -558,6 +560,16 @@ enum communicationProtocol{
break;
case UDP:
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){
while(length>0){

View File

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

View File

@ -26,8 +26,10 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs {
* @param succecc socket creation was successfull
* @param rbase pointer to the receiver base
* @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.
@ -272,6 +274,9 @@ private:
/** port number */
int portNumber;
/** true if bottom half module for eiger */
bool bottom;
protected:
/** Socket */

View File

@ -43,7 +43,7 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public UDPInter
/**
* Constructor
*/
slsReceiverUDPFunctions();
slsReceiverUDPFunctions(bool bot);
/**
* Destructor
@ -216,6 +216,11 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public UDPInter
*/
void setUDPPortNo(int p);
/**
* Set UDP Port Number2
*/
void setUDPPortNo2(int p);
/*
* Returns number of frames to receive
* 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 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 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
@ -471,7 +477,6 @@ private:
unsigned char header_after[24];
} eiger_image_header;
/** structure of an eiger image header*/
typedef struct
{
@ -766,6 +771,9 @@ private:
* 2 we open, close, write file, callback does not do anything */
int cbAction;
/** true if bottom half module for eiger */
bool bottom;
public:

View File

@ -55,7 +55,9 @@ public:
GOTTHARD, /**< gotthard */
PICASSO, /**< picasso */
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) */
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 {
//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_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 */

View File

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

View File

@ -19,6 +19,7 @@ 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){
if (receiver_type == "standard"){

View File

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

View File

@ -24,10 +24,73 @@
#include <string.h>
#include <iostream>
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(){
myDetectorType = GENERIC;
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";
@ -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 */
void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){
FILE_LOG(logDEBUG) << __AT__ << " called";
//point to gui data
if (guiData == NULL)
guiData = latestData;
@ -846,7 +854,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){
//copy data and filename
strcpy(c,guiFileName);
fnum = guiFrameNumber;
fstartind = getStartFrameIndex();
//could not get gui data
if(!guiDataReady){
@ -932,7 +940,17 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum,
int UDPStandardImplementation::createUDPSockets(){
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 (strchr(eth,'.')!=NULL)
strcpy(eth,"");
@ -944,23 +962,25 @@ int UDPStandardImplementation::createUDPSockets(){
cout<<"warning:eth is empty.listening to all"<<endl;
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
else{
cout<<"eth:"<<eth<<endl;
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
int iret;
for(int i=0;i<numListeningThreads;i++){
iret = udpSocket[i]->getErrorStatus();
if(iret){
if(!iret)
cout << "UDP port opened at port " << port[i] << endl;
else{
#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
return FAIL;
}
@ -1418,7 +1438,7 @@ int UDPStandardImplementation::startReceiver(char message[]){
cout << endl << message << endl;
return FAIL;
}
cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl;
cout << "UDP socket(s) created successfully." << endl;
if(setupWriter() == FAIL){
@ -1589,9 +1609,13 @@ int UDPStandardImplementation::startListening(){
//normal listening
else if(!carryonBufferSize){
/* if(!ithread){*/
rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize);
expected = maxBufferSize;
/*}else{
while(1) usleep(100000000);
}
*/
}
//the remaining packets from previous buffer
else{
@ -1608,24 +1632,26 @@ int UDPStandardImplementation::startListening(){
expected = maxBufferSize - carryonBufferSize;
}
#ifdef VERYDEBUG
//#ifdef VERYDEBUG
cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl;
#endif
//#endif
//start indices for each start of scan/acquisition - eiger does it before
if((!measurementStarted) && (rc > 0) && (!ithread))
startFrameIndices(ithread);
if((!measurementStarted) && (rc > 0) && (!ithread))
startFrameIndices(ithread);
//problem in receiving or end of acquisition
if((rc < expected)||(rc <= 0)){
stopListening(ithread,rc,packetcount,total);
continue;
}
/*
//start indices for each start of scan/acquisition - eiger does it before
if((!measurementStarted) && (rc > 0) && (!ithread))
startFrameIndices(ithread);
*/
//reset
packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread;
@ -1811,7 +1837,10 @@ int loop;
//for progress
if(myDetectorType == EIGER){
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))
tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset);
else
@ -1836,6 +1865,7 @@ int loop;
if (cbAction < DO_EVERYTHING){
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);
}else if (numpackets > 0){
for(i=0;i<numListeningThreads;++i)
@ -1957,8 +1987,13 @@ void UDPStandardImplementation::startFrameIndices(int ithread){
cout << "startAcquisitionIndex:" << startAcquisitionIndex<<endl;
}
//for scans, cuz currfraenum resets
else if (myDetectorType == EIGER)
startFrameIndex += currframenum;
else if (myDetectorType == EIGER){
if(dynamicRange == 32)
startFrameIndex = (currframenum + 1);// to be added later for scans
else
startFrameIndex += currframenum;
}
cout << "startFrameIndex:" << startFrameIndex<<endl;
@ -2019,9 +2054,9 @@ int i;
#endif
pthread_mutex_unlock(&(status_mutex));
#ifdef VERYDEBUG
//#ifdef VERYDEBUG
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
if(ithread == 0){

View File

@ -37,12 +37,14 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
string udp_interface_type = "standard";
string rest_hostname = "localhost:8081";
bool bottom = false; //TODO: properly set new parameter -> mode?
//parse command line for config
static struct option long_options[] = {
/* These options set a flag. */
//{"verbose", no_argument, &verbose_flag, 1},
/* These options dont set a flag.
We distinguish them by their indices. */
{"mode", required_argument, 0, 'm'},
{"type", required_argument, 0, 't'},
{"config", required_argument, 0, 'f'},
{"rx_tcpport", required_argument, 0, 'b'},
@ -55,13 +57,14 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
int c;
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. */
if (c == -1)
break;
switch(c){
case 'f':
fname = optarg;
//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""";
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--mode:\t ???\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""";

View File

@ -17,6 +17,9 @@
#include <sstream>
#include <fstream>
#include <stdlib.h>
#include <byteswap.h> //linux5
#define be64toh(x) __bswap_64 (x) //linux5
//#include <endian.h> //linux6
using namespace std;
@ -27,26 +30,26 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() {
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){
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;
int port_no=portNumber;
if (pn>0)
port_no = pn;
if (pn>0)
port_no = pn;
success=OK;
success=OK;
//create socket
if(success == OK){
@ -615,10 +618,10 @@ int slsReceiverTCPIPInterface::setup_udp(){
ret=OK;
strcpy(mess,"could not set up udp connection");
char retval[MAX_STR_LENGTH]="";
char args[2][MAX_STR_LENGTH];
char args[3][MAX_STR_LENGTH];
string temp;
int udpport;
int udpport,udpport2;
char eth[MAX_STR_LENGTH];
@ -643,8 +646,9 @@ int slsReceiverTCPIPInterface::setup_udp(){
else{
//set up udp port
sscanf(args[1],"%d",&udpport);
sscanf(args[2],"%d",&udpport2);
receiverBase->setUDPPortNo(udpport);
receiverBase->setUDPPortNo2(udpport2);
//setup udpip
//get ethernet interface or IP to listen to
temp = genericSocket::ipToName(args[0]);
@ -1002,8 +1006,8 @@ int slsReceiverTCPIPInterface::moench_read_frame(){
else{
ret = OK;
startIndex=receiverBase->getStartFrameIndex();
receiverBase->readFrame(fName,&raw,index);
/*startIndex=receiverBase->getStartFrameIndex();*/
receiverBase->readFrame(fName,&raw,index,startIndex);
/**send garbage with -1 index to try again*/
if (raw == NULL){
@ -1172,8 +1176,8 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){
cout<<"haven't caught any frame yet"<<endl;
}else{
ret = OK;
startIndex=receiverBase->getStartFrameIndex();
receiverBase->readFrame(fName,&raw,index);
/*startIndex=receiverBase->getStartFrameIndex();*/
receiverBase->readFrame(fName,&raw,index,startIndex);
/**send garbage with -1 index to try again*/
if (raw == NULL){
@ -1304,13 +1308,9 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
char* raw = new char[frameSize];
char* origVal = new char[frameSize];
char* retval = new char[dataSize];
uint32_t startIndex=0;
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
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
@ -1328,7 +1328,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
else{
ret = OK;
/** read a frame */
receiverBase->readFrame(fName,&raw, index);
receiverBase->readFrame(fName,&raw,index,startIndex);
#ifdef VERBOSE
cout << "index:" << dec << index << endl;
#endif
@ -1341,7 +1341,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
}
/**proper frame*/
else{
else{//cout<<"**** got proper frame ******"<<endl;
memcpy(origVal,raw,frameSize);
raw=NULL;
@ -1349,12 +1349,11 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
int c1=8;//first port
int c2=(frameSize/2) + 8; //second port
int retindex=0;
int irow,ibytesperpacket,irepeat;
int repeat=1;
int irow,ibytesperpacket;
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 datapacketlength = EIGER_ONE_GIGA_ONE_DATA_SIZE;
int total_num_bytes = 1040*(16*dynamicrange)*2;
if(tenGigaEnable){
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
else if(dynamicrange == 32){
repeat=2;
numbytesperlineperport = 1024;
linesperpacket = 1; //we repeat this twice anyway for 32 bit
}
if(!bottom){
for(irow=0;irow<EIGER_PIXELS_IN_ONE_COL/linesperpacket;++irow){
ibytesperpacket=0;
while(ibytesperpacket<datapacketlength){
for(irepeat=0;irepeat<repeat;irepeat++){//only for 32 bit mode, take 2 packets from same port
for(irow=0;irow<EIGER_PIXELS_IN_ONE_COL/linesperpacket;++irow){
ibytesperpacket=0;
while(ibytesperpacket<datapacketlength){
//first port
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c1 += numbytesperlineperport;
}
for(irepeat=0;irepeat<repeat;irepeat++){//only for 32 bit mode, take 2 packets from same port
if(dynamicrange == 32){
c1 += 16;
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c1 += numbytesperlineperport;
c1 += 16;
}
//second port
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += 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;
}
}
}
int64_t temp;
//64 bit htonl cuz of endianness
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 = ((temp << 8) & 0xFF00FF00FF00FF00ULL ) | ((temp >> 8) & 0x00FF00FF00FF00FFULL );
temp = ((temp << 16) & 0xFFFF0000FFFF0000ULL ) | ((temp >> 16) & 0x0000FFFF0000FFFFULL );
temp = (temp << 32) | ((temp >> 32) & 0xFFFFFFFFULL);
(*(((uint64_t*)retval)+i)) = temp;
*/
}
/*
( (((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;
arg = index-startIndex;
}
}