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

This commit is contained in:
bergamaschi 2014-10-15 09:22:40 +02:00
commit cd3a502167
5 changed files with 146 additions and 55 deletions

View File

@ -18,9 +18,8 @@ using namespace std;
slsReceiver::slsReceiver(int argc, char *argv[], int &success){ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
//creating base receiver //creating base receiver
cout << "SLS Receiver" << endl; cout << "SLS Receiver" << endl;
receiverBase = new slsReceiverUDPFunctions();
int tcpip_port_no=-1; int tcpip_port_no=-1;
bool bottom = false;
ifstream infile; ifstream infile;
@ -116,6 +115,31 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
} }
} }
} }
//mode top:bottom
else if(!strcasecmp(argv[iarg],"-mode")){
if(iarg+1==argc){
cout << "no mode given after -mode in command line. Exiting." << endl;
success=FAIL;
}else{
if(!strcasecmp(argv[iarg+1],"bottom")){
cout<<"mode: bottom"<<endl;
bottom = true;
iarg++;
}else if(!strcasecmp(argv[iarg+1],"top")){
cout<<"mode: top"<<endl;
iarg++;
}
else{
cout << "could not decode port in command line. \n\nExiting." << endl;
success=FAIL;
}
}
}
else{ else{
cout << "Unknown argument:" << argv[iarg] << endl; cout << "Unknown argument:" << argv[iarg] << endl;
success=FAIL; success=FAIL;
@ -130,9 +154,9 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
cout << "rx_tcpport:\t TCP Communication Port with the client. Default:1954. " << endl << endl; cout << "rx_tcpport:\t TCP Communication Port with the client. Default:1954. " << endl << endl;
} }
receiverBase = new slsReceiverUDPFunctions(bottom);
if (success==OK) if (success==OK)
tcpipInterface = new slsReceiverTCPIPInterface(success,receiverBase, tcpip_port_no); tcpipInterface = new slsReceiverTCPIPInterface(success,receiverBase, tcpip_port_no, bottom);
//tcp ip interface //tcp ip interface

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;
@ -28,7 +31,7 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() {
} }
slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, slsReceiverBase* rbase, int pn): slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, slsReceiverBase* rbase, int pn, bool bot):
myDetectorType(GOTTHARD), myDetectorType(GOTTHARD),
receiverBase(rbase), receiverBase(rbase),
ret(OK), ret(OK),
@ -38,7 +41,8 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, slsReceiverBa
dynamicrange(16), dynamicrange(16),
socket(NULL), socket(NULL),
killTCPServerThread(0), killTCPServerThread(0),
tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2){ tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2),
bottom(bot){
int port_no=portNumber; int port_no=portNumber;
@ -1336,7 +1340,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;
@ -1344,12 +1348,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
@ -1357,55 +1360,106 @@ 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(repeat == 2) c1 += 16; if(dynamicrange == 32){
} c1 += 16;
for(irepeat=0;irepeat<repeat;irepeat++){//only for 32 bit mode, take 2 packets from same port 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(repeat == 2) c2 += 16; 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;
}
if(repeat == 1) {
c1 += 16;
c2 += 16;
} }
} }
//bottom half module
else{
c1 = (frameSize/2) - numbytesperlineperport - 8 ;
c2 = total_num_bytes - numbytesperlineperport - 8;
int64_t temp; 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
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;
*/
} }
/*
( (((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-startIndex; arg = index-startIndex;
} }
} }

View File

@ -26,8 +26,9 @@ public:
* @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, slsReceiverBase* rbase, int pn=-1); slsReceiverTCPIPInterface(int &success, slsReceiverBase* rbase, int pn=-1, bool bot=false);
/** /**
* Sets the port number to listen to. * Sets the port number to listen to.
@ -272,6 +273,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

@ -31,13 +31,14 @@ using namespace std;
slsReceiverUDPFunctions::slsReceiverUDPFunctions(): slsReceiverUDPFunctions::slsReceiverUDPFunctions(bool bot):
thread_started(0), thread_started(0),
eth(NULL), eth(NULL),
latestData(NULL), latestData(NULL),
guiFileName(NULL), guiFileName(NULL),
guiFrameNumber(0), guiFrameNumber(0),
tengigaEnable(0){ tengigaEnable(0),
bottom(bot){
for(int i=0;i<MAX_NUM_LISTENING_THREADS;i++){ for(int i=0;i<MAX_NUM_LISTENING_THREADS;i++){
udpSocket[i] = NULL; udpSocket[i] = NULL;
server_port[i] = DEFAULT_UDP_PORTNO+i; server_port[i] = DEFAULT_UDP_PORTNO+i;
@ -443,16 +444,12 @@ void slsReceiverUDPFunctions::setEthernetInterface(char* c){
void slsReceiverUDPFunctions::setUDPPortNo(int p){ void slsReceiverUDPFunctions::setUDPPortNo(int p){
//for(int i=0;i<numListeningThreads;i++){ server_port[0] = p;
server_port[0] = p;
//}
} }
void slsReceiverUDPFunctions::setUDPPortNo2(int p){ void slsReceiverUDPFunctions::setUDPPortNo2(int p){
//for(int i=0;i<numListeningThreads;i++){ server_port[1] = p;
server_port[1] = p;
//}
} }
@ -885,6 +882,15 @@ void slsReceiverUDPFunctions::copyFrameToGui(char* startbuf[], uint32_t fnum, ch
int slsReceiverUDPFunctions::createUDPSockets(){ int slsReceiverUDPFunctions::createUDPSockets(){
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)
@ -897,14 +903,14 @@ int slsReceiverUDPFunctions::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
@ -912,10 +918,10 @@ int slsReceiverUDPFunctions::createUDPSockets(){
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 " << server_port[i] << endl; cout << "UDP port opened at port " << port[i] << endl;
else{ 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;
} }
@ -1351,7 +1357,7 @@ int slsReceiverUDPFunctions::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){
@ -1540,9 +1546,9 @@ int slsReceiverUDPFunctions::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
@ -1954,9 +1960,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

@ -40,7 +40,7 @@ public:
/** /**
* Constructor * Constructor
*/ */
slsReceiverUDPFunctions(); slsReceiverUDPFunctions(bool bot);
/** /**
* Destructor * Destructor
@ -768,6 +768,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: