refactoring startReadout

This commit is contained in:
Erik Frojdh 2018-10-16 15:08:59 +02:00
parent 5b8dfd7943
commit 66e79dc9a9

View File

@ -1144,43 +1144,35 @@ void slsReceiverImplementation::stopReceiver(){
void slsReceiverImplementation::startReadout(){ void slsReceiverImplementation::startReadout(){
if(status == RUNNING){ if(status == RUNNING){
// wait for incoming delayed packets // wait for incoming delayed packets
//current packets caught int totalPacketsReceived = 0;
volatile int totalP = 0,prev=-1; int previousValue=-1;
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it) for(const auto& it : listener)
totalP += (*it)->GetPacketsCaught(); totalPacketsReceived += it->GetPacketsCaught();
//wait for all packets //wait for all packets
if((unsigned long long int)totalP!=numberOfFrames*generalData->packetsPerFrame*listener.size()){ const auto numPacketsToReceive = numberOfFrames*generalData->packetsPerFrame*listener.size();
if(totalPacketsReceived != numPacketsToReceive){
//wait as long as there is change from prev totalP, while(totalPacketsReceived != previousValue){
while(prev != totalP){
#ifdef VERY_VERBOSE #ifdef VERY_VERBOSE
cprintf(MAGENTA,"waiting for all packets prevP:%d totalP:%d\n", cprintf(MAGENTA,"waiting for all packets previousValue:%d totalPacketsReceived:%d\n",
prev,totalP); previousValue,totalPacketsReceived);
#endif #endif
//usleep(1*1000*1000);usleep(1*1000*1000);usleep(1*1000*1000);usleep(1*1000*1000); usleep(5*1000);/* TODO! Need to find optimal time **/
usleep(5*1000);/* Need to find optimal time **/ previousValue = totalPacketsReceived;
totalPacketsReceived = 0;
for(const auto& it : listener)
totalPacketsReceived += it->GetPacketsCaught();
prev = totalP;
totalP = 0;
for (std::vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
totalP += (*it)->GetPacketsCaught();
#ifdef VERY_VERBOSE #ifdef VERY_VERBOSE
cprintf(MAGENTA,"\tupdated: totalP:%d\n",totalP); cprintf(MAGENTA,"\tupdated: totalP:%d\n",totalPacketsReceived);
#endif #endif
} }
} }
//set status
status = TRANSMITTING; status = TRANSMITTING;
FILE_LOG(logINFO) << "Status: Transmitting"; FILE_LOG(logINFO) << "Status: Transmitting";
} }
//shut down udp sockets so as to make listeners push dummy (end) packets for processors //shut down udp sockets to make listeners push dummy (end) packets for processors
shutDownUDPSockets(); shutDownUDPSockets();
} }