mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-05 20:30:03 +02:00
trying to get in changes for activate in receiver
This commit is contained in:
parent
f6b7fd7aa3
commit
489b623afd
@ -200,6 +200,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
*/
|
||||
runStatus getStatus() const;
|
||||
|
||||
/**
|
||||
* Get activate
|
||||
* If deactivated, receiver will write dummy packets 0xFF
|
||||
* (as it will receive nothing from detector)
|
||||
* @return 0 for deactivated, 1 for activated
|
||||
*/
|
||||
int getActivate() const;
|
||||
|
||||
|
||||
|
||||
@ -432,6 +439,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
*/
|
||||
void closeFile(int ithread = 0);
|
||||
|
||||
/**
|
||||
* Activate / Deactivate Receiver
|
||||
* If deactivated, receiver will write dummy packets 0xFF
|
||||
* (as it will receive nothing from detector)
|
||||
*/
|
||||
int setActivate(int enable = -1);
|
||||
|
||||
//***callback functions***
|
||||
/**
|
||||
@ -500,6 +513,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
const static int MAX_NUMBER_OF_LISTENING_THREADS = 2;
|
||||
/** Receiver Status */
|
||||
runStatus status;
|
||||
/** Activated/Deactivated */
|
||||
int activated;
|
||||
|
||||
//***connection parameters***
|
||||
/** Ethernet Interface */
|
||||
|
@ -258,6 +258,13 @@ class UDPInterface {
|
||||
*/
|
||||
virtual slsReceiverDefs::runStatus getStatus() const = 0;
|
||||
|
||||
/**
|
||||
* Get activate
|
||||
* If deactivated, receiver will write dummy packets 0xFF
|
||||
* (as it will receive nothing from detector)
|
||||
* @return 0 for deactivated, 1 for activated
|
||||
*/
|
||||
virtual int getActivate() const = 0;
|
||||
|
||||
|
||||
|
||||
@ -489,6 +496,13 @@ class UDPInterface {
|
||||
virtual void closeFile(int ithread = 0) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Activate / Deactivate Receiver
|
||||
* If deactivated, receiver will write dummy packets 0xFF
|
||||
* (as it will receive nothing from detector)
|
||||
*/
|
||||
virtual int setActivate(int enable = -1) = 0;
|
||||
|
||||
//***callback functions***
|
||||
/**
|
||||
* Call back for start acquisition
|
||||
|
@ -663,6 +663,7 @@ private:
|
||||
|
||||
/** Missing Packet identifier value */
|
||||
const static uint16_t missingPacketValue = 0xFFFF;
|
||||
const static uint16_t deactivatedPacketValue = 0xFEFE;
|
||||
|
||||
/** Dummy Packet identifier value */
|
||||
const static uint32_t dummyPacketValue = 0xFFFFFFFF;
|
||||
@ -756,6 +757,10 @@ private:
|
||||
|
||||
|
||||
|
||||
//***deactivated parameters***
|
||||
uint64_t deactivatedFrameNumber[MAX_NUMBER_OF_LISTENING_THREADS];
|
||||
int deactivatedFrameIncrement;
|
||||
|
||||
|
||||
|
||||
//***filter parameters***
|
||||
|
@ -210,6 +210,10 @@ private:
|
||||
/** set fifo depth */
|
||||
int set_fifo_depth();
|
||||
|
||||
/** activate/ deactivate */
|
||||
int set_activate();
|
||||
|
||||
|
||||
//General Functions
|
||||
/** Locks Receiver */
|
||||
int lock_receiver();
|
||||
|
@ -51,6 +51,7 @@ enum {
|
||||
F_ENABLE_RECEIVER_TEN_GIGA, /**< enable 10Gbe in receiver */
|
||||
F_SET_RECEIVER_FIFO_DEPTH, /**< set receiver fifo depth */
|
||||
|
||||
F_ACTIVATE, /** < activate/deactivate readout */
|
||||
F_STREAM_DATA_FROM_RECEIVER /**< stream data from receiver to client */
|
||||
|
||||
/* Always append functions hereafter!!! */
|
||||
|
@ -49,6 +49,7 @@ void UDPBaseImplementation::initializeMembers(){
|
||||
|
||||
//***receiver parameters***
|
||||
status = IDLE;
|
||||
activated = true;
|
||||
|
||||
//***connection parameters***
|
||||
strcpy(eth,"");
|
||||
@ -190,7 +191,7 @@ uint32_t UDPBaseImplementation::getFifoDepth() const{ FILE_LOG(logDEBUG) << __AT
|
||||
/***receiver status***/
|
||||
slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return status;}
|
||||
|
||||
|
||||
int UDPBaseImplementation::getActivate() const{FILE_LOG(logDEBUG) << __AT__ << " starting"; return activated;}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@ -464,6 +465,17 @@ void UDPBaseImplementation::closeFile(int ithread){
|
||||
}
|
||||
|
||||
|
||||
int UDPBaseImplementation::setActivate(int enable){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
if(enable != -1){
|
||||
activated = enable;
|
||||
FILE_LOG(logINFO) << "Activation: " << stringEnable(activated);
|
||||
}
|
||||
|
||||
return activated;
|
||||
}
|
||||
|
||||
/***callback functions***/
|
||||
void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){
|
||||
startAcquisitionCallBack=func;
|
||||
|
@ -212,6 +212,12 @@ void UDPStandardImplementation::initializeMembers(){
|
||||
createFileMask = 0x0;
|
||||
killAllWritingThreads = false;
|
||||
|
||||
|
||||
//***deactivated parameters***
|
||||
for(int i=0; i < MAX_NUMBER_OF_LISTENING_THREADS; i++)
|
||||
deactivatedFrameNumber[i] = 0;
|
||||
deactivatedFrameIncrement = 0;
|
||||
|
||||
//***filter parameters***
|
||||
commonModeSubtractionEnable = false;
|
||||
moenchCommonModeSubtraction = NULL;
|
||||
@ -957,6 +963,11 @@ int UDPStandardImplementation::startReceiver(char *c){
|
||||
fileCreateSuccess = false;
|
||||
pthread_mutex_unlock(&statusMutex);
|
||||
|
||||
//deactivated parameters
|
||||
for(int i = 0; i < numberofListeningThreads; ++i)
|
||||
deactivatedFrameNumber[i] = 0;
|
||||
deactivatedFrameIncrement = (bufferSize/(onePacketSize*packetsPerFrame))*numberofJobsPerBuffer;
|
||||
FILE_LOG(logINFO) << "Deactivated Frame Increment:" << deactivatedFrameIncrement;
|
||||
|
||||
|
||||
//Print Receiver Configuration
|
||||
@ -1095,44 +1106,48 @@ void UDPStandardImplementation::startReadout(){
|
||||
|
||||
if(status == RUNNING){
|
||||
|
||||
//check if all packets got
|
||||
int totalP = 0,prev=-1,i;
|
||||
for(i=0; i<numberofListeningThreads; ++i)
|
||||
totalP += totalListeningPacketCount[i];
|
||||
|
||||
//check if current buffer still receiving something
|
||||
int currentReceivedInBuffer=0,prevReceivedInBuffer=-1;
|
||||
for(i=0; i<numberofListeningThreads; ++i)
|
||||
currentReceivedInBuffer += udpSocket[i]->getCurrentTotalReceived();
|
||||
//needs to wait for packets only if activated
|
||||
if(activated){
|
||||
//check if all packets got
|
||||
int totalP = 0,prev=-1,i;
|
||||
for(i=0; i<numberofListeningThreads; ++i)
|
||||
totalP += totalListeningPacketCount[i];
|
||||
|
||||
//wait for all packets
|
||||
if(totalP!=numberOfFrames*packetsPerFrame*numberofListeningThreads){
|
||||
//check if current buffer still receiving something
|
||||
int currentReceivedInBuffer=0,prevReceivedInBuffer=-1;
|
||||
for(i=0; i<numberofListeningThreads; ++i)
|
||||
currentReceivedInBuffer += udpSocket[i]->getCurrentTotalReceived();
|
||||
|
||||
//wait as long as there is change from prev totalP,
|
||||
//and also change from received in buffer to previous value
|
||||
//(as one listens to many at a time, shouldnt cut off in between)
|
||||
while((prev != totalP) || (prevReceivedInBuffer!= currentReceivedInBuffer)){
|
||||
//wait for all packets
|
||||
if(totalP!=numberOfFrames*packetsPerFrame*numberofListeningThreads){
|
||||
|
||||
//wait as long as there is change from prev totalP,
|
||||
//and also change from received in buffer to previous value
|
||||
//(as one listens to many at a time, shouldnt cut off in between)
|
||||
while((prev != totalP) || (prevReceivedInBuffer!= currentReceivedInBuffer)){
|
||||
#ifdef DEBUG5
|
||||
cprintf(MAGENTA,"waiting for all packets totalP:%d currently in buffer:%d\n",totalP,currentReceivedInBuffer);
|
||||
cprintf(MAGENTA,"waiting for all packets totalP:%d currently in buffer:%d\n",totalP,currentReceivedInBuffer);
|
||||
|
||||
#endif
|
||||
|
||||
usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/
|
||||
prev = totalP;
|
||||
totalP = 0;
|
||||
for(i=0; i<numberofListeningThreads; ++i)
|
||||
totalP += totalListeningPacketCount[i];
|
||||
usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/
|
||||
prev = totalP;
|
||||
totalP = 0;
|
||||
for(i=0; i<numberofListeningThreads; ++i)
|
||||
totalP += totalListeningPacketCount[i];
|
||||
|
||||
prevReceivedInBuffer = currentReceivedInBuffer;
|
||||
currentReceivedInBuffer = 0;
|
||||
for(i=0; i<numberofListeningThreads; ++i)
|
||||
currentReceivedInBuffer += udpSocket[i]->getCurrentTotalReceived();
|
||||
prevReceivedInBuffer = currentReceivedInBuffer;
|
||||
currentReceivedInBuffer = 0;
|
||||
for(i=0; i<numberofListeningThreads; ++i)
|
||||
currentReceivedInBuffer += udpSocket[i]->getCurrentTotalReceived();
|
||||
#ifdef DEBUG5
|
||||
cprintf(MAGENTA,"\tupdated: totalP:%d currently in buffer:%d\n",totalP,currentReceivedInBuffer);
|
||||
cprintf(MAGENTA,"\tupdated: totalP:%d currently in buffer:%d\n",totalP,currentReceivedInBuffer);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//set status
|
||||
@ -1953,7 +1968,7 @@ void UDPStandardImplementation::startListening(){
|
||||
|
||||
|
||||
//udpsocket doesnt exist
|
||||
if(status == TRANSMITTING){
|
||||
if ((status == TRANSMITTING)||(rc == 0 && activated == 0)){
|
||||
FILE_LOG(logERROR) << "Listening_Thread " << ithread << ": UDP Socket not created or shut down earlier";
|
||||
stopListening(ithread,0);
|
||||
continue;
|
||||
@ -2023,6 +2038,50 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int cSize, ch
|
||||
//carry over from previous buffer
|
||||
if(cSize) memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize);
|
||||
|
||||
|
||||
if(!activated){
|
||||
//cSize = 0 for deactivated
|
||||
int framestoclone = 0;
|
||||
//done
|
||||
if(deactivatedFrameNumber[ithread] == numberOfFrames)
|
||||
return 0;
|
||||
//last
|
||||
if((deactivatedFrameNumber[ithread] + deactivatedFrameIncrement) > numberOfFrames)
|
||||
framestoclone = numberOfFrames - deactivatedFrameNumber[ithread];
|
||||
//in progress
|
||||
else
|
||||
framestoclone = deactivatedFrameIncrement;
|
||||
|
||||
//copy dummy packets
|
||||
memset(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, 0xFF,framestoclone*packetsPerFrame*onePacketSize);
|
||||
|
||||
//set fnum, pnum and deactivatedpacket label
|
||||
eiger_packet_header_t* header;
|
||||
eiger_packet_footer_t* footer;
|
||||
int pnum=0;
|
||||
//loop by each packet
|
||||
for(int offset=HEADER_SIZE_NUM_TOT_PACKETS;
|
||||
offset<framestoclone*packetsPerFrame*onePacketSize;
|
||||
offset+=onePacketSize){
|
||||
header = (eiger_packet_header_t*)(buffer[ithread] + offset);
|
||||
footer = (eiger_packet_footer_t*)(buffer[ithread] + offset + footerOffset);
|
||||
*( (uint64_t*) footer) = ++deactivatedFrameNumber[ithread];
|
||||
*( (uint16_t*) footer->packetNumber) = ++pnum;
|
||||
*( (uint16_t*) header->missingPacket) = deactivatedPacketValue;
|
||||
#ifdef MANUALDEBUG
|
||||
cprintf(GREEN,"thread:%d pnum:%d fnum:%d\n",
|
||||
ithread,
|
||||
(*( (uint16_t*) footer->packetNumber)),
|
||||
(uint32_t)(*( (uint64_t*) footer)));
|
||||
#endif
|
||||
if(pnum == packetsPerFrame)
|
||||
pnum = 0;
|
||||
}
|
||||
|
||||
return framestoclone*onePacketSize;
|
||||
}
|
||||
|
||||
|
||||
if(status != TRANSMITTING)
|
||||
receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, (bufferSize * numberofJobsPerBuffer) - cSize);
|
||||
//eiger returns 0 when header packet caught
|
||||
@ -2604,6 +2663,8 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer){
|
||||
}
|
||||
|
||||
}
|
||||
if(!activated)
|
||||
cprintf(RED,"Note: Deactivated Receiver\n");
|
||||
|
||||
//acquisition end
|
||||
if (acquisitionFinishedCallBack)
|
||||
|
@ -262,6 +262,7 @@ int slsReceiverTCPIPInterface::function_table(){
|
||||
|
||||
flist[F_ENABLE_RECEIVER_TEN_GIGA] = &slsReceiverTCPIPInterface::enable_tengiga;
|
||||
flist[F_SET_RECEIVER_FIFO_DEPTH] = &slsReceiverTCPIPInterface::set_fifo_depth;
|
||||
flist[F_ACTIVATE] = &slsReceiverTCPIPInterface::set_activate;
|
||||
flist[F_STREAM_DATA_FROM_RECEIVER] = &slsReceiverTCPIPInterface::set_data_stream_enable;
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
@ -2862,6 +2863,77 @@ int slsReceiverTCPIPInterface::set_fifo_depth() {
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::set_activate() {
|
||||
ret=OK;
|
||||
int retval=-1;
|
||||
int enable;
|
||||
strcpy(mess,"Could not activate/deactivate\n");
|
||||
|
||||
|
||||
// receive arguments
|
||||
if(socket->ReceiveDataOnly(&enable,sizeof(enable)) < 0 ){
|
||||
strcpy(mess,"Error reading from socket\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret = FAIL;
|
||||
}
|
||||
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
if (ret==OK) {
|
||||
if (lockStatus==1 && socket->differentClients==1){
|
||||
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
if(ret!=FAIL){
|
||||
if (receiverBase == NULL){
|
||||
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}else if(receiverBase->getStatus()==RUNNING){
|
||||
strcpy(mess,"Cannot activate/deactivate while status is running\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}else{
|
||||
if(enable != -1)
|
||||
receiverBase->setActivate(enable);
|
||||
retval = receiverBase->getActivate();
|
||||
if(enable >= 0 && retval != enable){
|
||||
sprintf(mess,"Tried to set activate to %d, but returned %d\n",enable,retval);
|
||||
ret = FAIL;
|
||||
cprintf(RED,"%s",mess);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef VERYVERBOSE
|
||||
if(ret!=FAIL)
|
||||
cout << "Activate: " << retval << endl;
|
||||
else
|
||||
cout << mess << endl;
|
||||
#endif
|
||||
|
||||
|
||||
if(ret==OK && socket->differentClients){
|
||||
FILE_LOG(logDEBUG) << "Force update";
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
socket->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
cprintf(RED,"%s\n",mess);
|
||||
socket->SendDataOnly(mess,sizeof(mess));
|
||||
}
|
||||
socket->SendDataOnly(&retval,sizeof(retval));
|
||||
|
||||
//return ok/fail
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user