Merge branch 'dhanya_devel'

This commit is contained in:
Dhanya Maliakal 2015-02-10 16:44:57 +01:00
commit c5f8067735
4 changed files with 99 additions and 47 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: e019a6ce7d96d4ac9cb5762b7137245aedb4d5b8 Repsitory UUID: 879c5e2ee129acfd70aba4ae6fab829cc5409350
Revision: 22 Revision: 67
Branch: master Branch: gemma
Last Changed Author: Anna_Bergamaschi Last Changed Author: Maliakal_Dhanya
Last Changed Rev: 22 Last Changed Rev: 67
Last Changed Date: 2014-10-15 09:22:40 +0200 Last Changed Date: 2014-12-08 09:17:56 +0100

View File

@ -47,7 +47,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
*/ */
virtual ~UDPStandardImplementation(); virtual ~UDPStandardImplementation();
void configure(map<string, string> config_map);
/** /**
* delete and free member parameters * delete and free member parameters

View File

@ -92,6 +92,22 @@ UDPStandardImplementation::UDPStandardImplementation()
} }
void UDPStandardImplementation::configure(map<string, string> config_map){
FILE_LOG(logWARNING) << __AT__ << " called";
map<string, string>::const_iterator pos;
pos = config_map.find("mode");
if (pos != config_map.end() ){
int b;
if(!sscanf(pos->second.c_str(), "%d", &b)){
cout << "Warning: Could not parse mode. Assuming top mode." << endl;
b = 0;
}
bottom = b!= 0;
cout << "bottom:"<< bottom << endl;
}
};
void UDPStandardImplementation::initializeMembers(){ void UDPStandardImplementation::initializeMembers(){
myDetectorType = GENERIC; myDetectorType = GENERIC;
maxPacketsPerFile = 0; maxPacketsPerFile = 0;
@ -849,8 +865,10 @@ void UDPStandardImplementation::setupFifoStructure(){
void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){
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;
//cout <<"gui data not null anymore" << endl;
}
//copy data and filename //copy data and filename
strcpy(c,guiFileName); strcpy(c,guiFileName);
@ -859,10 +877,12 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui
//could not get gui data //could not get gui data
if(!guiDataReady){ if(!guiDataReady){
//cout<<"gui data not ready"<<endl;
*raw = NULL; *raw = NULL;
} }
//data ready, set guidata to receive new data //data ready, set guidata to receive new data
else{ else{
//cout<<"gui data ready"<<endl;
*raw = guiData; *raw = guiData;
guiData = NULL; guiData = NULL;
@ -870,10 +890,12 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui
guiDataReady = 0; guiDataReady = 0;
pthread_mutex_unlock(&dataReadyMutex); pthread_mutex_unlock(&dataReadyMutex);
if((nFrameToGui) && (writerthreads_mask)){ if((nFrameToGui) && (writerthreads_mask)){
//cout<<"gonna post"<<endl;
/*if(nFrameToGui){*/ /*if(nFrameToGui){*/
//release after getting data //release after getting data
sem_post(&smp); sem_post(&smp);
} }
//cout<<"done post"<<endl;
} }
} }
@ -885,7 +907,7 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum,
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
//random read when gui not ready //random read when gui not ready , also command line doesnt have nthframetogui
if((!nFrameToGui) && (!guiData)){ if((!nFrameToGui) && (!guiData)){
pthread_mutex_lock(&dataReadyMutex); pthread_mutex_lock(&dataReadyMutex);
guiDataReady=0; guiDataReady=0;
@ -894,6 +916,7 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum,
//random read or nth frame read, gui needs data now //random read or nth frame read, gui needs data now
else{ else{
//cout <<"gui needs data now"<<endl;
/* /*
//nth frame read, block current process if the guireader hasnt read it yet //nth frame read, block current process if the guireader hasnt read it yet
if(nFrameToGui) if(nFrameToGui)
@ -928,8 +951,11 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum,
pthread_mutex_unlock(&dataReadyMutex); pthread_mutex_unlock(&dataReadyMutex);
//nth frame read, block current process if the guireader hasnt read it yet //nth frame read, block current process if the guireader hasnt read it yet
if(nFrameToGui) if(nFrameToGui){
//cout<<"waiting after copying"<<endl;
sem_wait(&smp); sem_wait(&smp);
//cout<<"done waiting"<<endl;
}
} }
} }
@ -946,12 +972,12 @@ int UDPStandardImplementation::createUDPSockets(){
port[1] = server_port[1]; port[1] = server_port[1];
/** eiger specific */ /** eiger specific */
/*
if(bottom){ if(bottom){
port[0] = server_port[1]; port[0] = server_port[1];
port[1] = server_port[0]; 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,"");
@ -1412,7 +1438,10 @@ void UDPStandardImplementation::closeFile(int ithr){
/**
* Pre:
* Post: eiger req. time for 32bit before acq start
* */
int UDPStandardImplementation::startReceiver(char message[]){ int UDPStandardImplementation::startReceiver(char message[]){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
@ -1475,24 +1504,26 @@ int UDPStandardImplementation::startReceiver(char message[]){
for(i=0; i < numWriterThreads; ++i) for(i=0; i < numWriterThreads; ++i)
sem_post(&writersmp[i]); sem_post(&writersmp[i]);
//usleep(5000000);
cout << "Receiver Started.\nStatus:" << status << endl; cout << "Receiver Started.\nStatus:" << status << endl;
return OK; return OK;
} }
/**
* Pre: status is running, semaphores have been instantiated,
* Post: udp sockets shut down, status is idle, sempahores destroyed
* */
int UDPStandardImplementation::stopReceiver(){ int UDPStandardImplementation::stopReceiver(){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
if(status != IDLE){
//#ifdef VERBOSE //#ifdef VERBOSE
cout << "Stopping Receiver" << endl; cout << "Stopping Receiver" << endl;
//#endif //#endif
if(status == RUNNING)
startReadout(); startReadout();
while(status == TRANSMITTING) while(status == TRANSMITTING)
@ -1508,13 +1539,19 @@ int UDPStandardImplementation::stopReceiver(){
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
cout << "Receiver Stopped.\nStatus:" << status << endl << endl; cout << "Receiver Stopped.\nStatus:" << status << endl << endl;
}
return OK; return OK;
} }
/**
* Pre: status is running, udp sockets have been initialized,
* stop receiver initiated
* Post:udp sockets closed, status is transmitting
* */
void UDPStandardImplementation::startReadout(){ void UDPStandardImplementation::startReadout(){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
@ -1522,15 +1559,19 @@ void UDPStandardImplementation::startReadout(){
cout << "Start Receiver Readout" << endl; cout << "Start Receiver Readout" << endl;
//#endif //#endif
if(status == RUNNING){
//wait so that all packets which take time has arrived //wait so that all packets which take time has arrived
usleep(5000); usleep(5000);
/********************************************/ /********************************************/
//usleep(10000000);
//usleep(2000000); //usleep(2000000);
pthread_mutex_lock(&status_mutex); pthread_mutex_lock(&status_mutex);
status = TRANSMITTING; status = TRANSMITTING;
pthread_mutex_unlock(&status_mutex); pthread_mutex_unlock(&status_mutex);
cout << "Status: Transmitting" << endl; cout << "Status: Transmitting" << endl;
}
//kill udp socket to tell the listening thread to push last packet //kill udp socket to tell the listening thread to push last packet
shutDownUDPSockets(); shutDownUDPSockets();
@ -1613,6 +1654,7 @@ int UDPStandardImplementation::startListening(){
/* if(!ithread){*/ /* 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);
//cout<<"value:"<<htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)<<endl;
expected = maxBufferSize; expected = maxBufferSize;
/*}else{ /*}else{
while(1) usleep(100000000); while(1) usleep(100000000);
@ -1815,11 +1857,12 @@ int UDPStandardImplementation::startWriting(){
#endif #endif
//pop //pop
for(i=0;i<numListeningThreads;++i){ for(i=0;i<numListeningThreads;++i){
//cout<<"writer gonna pop from fifo:"<<i<<endl;
fifo[i]->pop(wbuf[i]); fifo[i]->pop(wbuf[i]);
numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); numpackets = (uint16_t)(*((uint16_t*)wbuf[i]));
#ifdef VERYDEBUG //#ifdef VERYDEBUG
cout << ithread << " numpackets:" << dec << numpackets << endl; cout << ithread << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl;
#endif //#endif
} }
#ifdef VERYDEBUG #ifdef VERYDEBUG
@ -1878,7 +1921,9 @@ int UDPStandardImplementation::startWriting(){
if(myDetectorType == EIGER) { if(myDetectorType == EIGER) {
//cout<<"gonna copy frame"<<endl;
copyFrameToGui(wbuf,currframenum); copyFrameToGui(wbuf,currframenum);
//cout<<"copied frame"<<endl;
for(i=0;i<numListeningThreads;++i){ for(i=0;i<numListeningThreads;++i){
while(!fifoFree[i]->push(wbuf[i])); while(!fifoFree[i]->push(wbuf[i]));
#ifdef VERYDEBUG #ifdef VERYDEBUG
@ -1991,7 +2036,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){
startAcquisitionIndex=startFrameIndex; startAcquisitionIndex=startFrameIndex;
currframenum = startAcquisitionIndex; currframenum = startAcquisitionIndex;
acqStarted = true; acqStarted = true;
cout << "startAcquisitionIndex:" << startAcquisitionIndex<<endl; cout << "startAcquisitionIndex:" << hex << startAcquisitionIndex<<endl;
} }
//for scans, cuz currfraenum resets //for scans, cuz currfraenum resets
else if (myDetectorType == EIGER){ else if (myDetectorType == EIGER){
@ -2100,7 +2145,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){
int i,j; int i,j;
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[wIndex] << endl; cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[0] << endl;
#endif #endif
//free fifo //free fifo

View File

@ -65,6 +65,13 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
switch(c){ switch(c){
case 'm':
int b;
sscanf(optarg, "%d", &b);
bottom = b != 0;
configuration_map["mode"] = optarg;
break;
case 'f': case 'f':
fname = optarg; fname = optarg;
//cout << long_options[option_index].name << " " << optarg << endl; //cout << long_options[option_index].name << " " << optarg << endl;
@ -86,7 +93,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--mode:\t 1 for bottom and 0 for top\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""";
@ -120,10 +127,10 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){
} }
if (success==OK){ if (success==OK){
FILE_LOG(logINFO) << "SLS Receiver starting " << udp_interface_type << " on port " << tcpip_port_no << endl; FILE_LOG(logINFO) << "SLS Receiver starting " << udp_interface_type << " on port " << tcpip_port_no << " with mode " << bottom << endl;
udp_interface = UDPInterface::create(udp_interface_type); udp_interface = UDPInterface::create(udp_interface_type);
udp_interface->configure(configuration_map); udp_interface->configure(configuration_map);
tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no); tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no, bottom);
//tcp ip interface //tcp ip interface
} }
} }