diff --git a/MAC/APL/PIC/TBB_Driver/src/ReadCmd.cc b/MAC/APL/PIC/TBB_Driver/src/ReadCmd.cc index 54413c55857b66d2f2a73317039103c19442cb08..ba92ba03919e6280717a2ea82f58ae97d445b753 100644 --- a/MAC/APL/PIC/TBB_Driver/src/ReadCmd.cc +++ b/MAC/APL/PIC/TBB_Driver/src/ReadCmd.cc @@ -39,7 +39,7 @@ using namespace TBB; //--Constructors for a ReadCmd object.---------------------------------------- ReadCmd::ReadCmd(): itsSecondstime(0), itsSampleNr(0), itsPrepages(0), itsPostpages(0), itsStage(0), - itsLastSavedSecond(0), itsLastSavedSampleNr(0), + itsLastSavedSecond(0), itsLastSavedSampleNr(0), itsLastSavedNrOfSamples(0), itsLastSavedSampleFreq(0), itsTimestamp(0), itsTimeBefore(0), itsTimeAfter(0) { @@ -96,14 +96,14 @@ void ReadCmd::saveTbbEvent(GCFEvent& event) void ReadCmd::sendTpEvent() { switch (itsStage) { - + // stage 0, haal de sampletijd op van het laatst geschreven frame // stage 1, haal de sample frequentie op van het laatst gescreven frame // en kijk of gevraagde data aanwezig is. // stage 2, zet udp poort gegevens // stage 3, verstuur 1 arp bericht // stage 4, stuur het read commando - + // get last saved sampletime and samplenr case 0: { TPReadrEvent tp_event; @@ -112,12 +112,12 @@ void ReadCmd::sendTpEvent() tp_event.mp = (uint32)TS->getChMpNr(getChannelNr()); tp_event.pid = (uint32)TS->getChMemWriter(getChannelNr()); tp_event.regid = 4; - + TS->boardPort(getBoardNr()).send(tp_event); TS->setBoardUsed(getBoardNr()); TS->boardPort(getBoardNr()).setTimer(TS->timeout()); } break; - + // get last saved samplefreq case 1: { TPReadrEvent tp_event; @@ -126,12 +126,12 @@ void ReadCmd::sendTpEvent() tp_event.mp = TS->getChMpNr(getChannelNr()); tp_event.pid = TS->getChMemWriter(getChannelNr()); tp_event.regid = 6; - + TS->boardPort(getBoardNr()).send(tp_event); TS->setBoardUsed(getBoardNr()); TS->boardPort(getBoardNr()).setTimer(TS->timeout()); } break; - + // send UDP header settings for CEP port case 2: { TPUdpEvent tp_event; @@ -154,19 +154,19 @@ void ReadCmd::sendTpEvent() TS->setBoardUsed(getBoardNr()); TS->boardPort(getBoardNr()).setTimer(TS->timeout()); } break; - + // send 1 arp message case 3: { TPArpEvent tp_event; - + tp_event.opcode = oc_ARP; tp_event.status = 0; - + TS->boardPort(getBoardNr()).send(tp_event); TS->setBoardUsed(getBoardNr()); TS->boardPort(getBoardNr()).setTimer(TS->timeout()); } break; - + // send requested data to CEP case 4: { TPReadEvent tp_event; @@ -216,21 +216,19 @@ void ReadCmd::saveTpAckEvent(GCFEvent& event) itsLastSavedSampleFreq = tp_ack.data[1]; //LOG_DEBUG_STR(formatString("Last frame info: time=%lu samplenr=%lu nSamples=%lu freq=%lu", // itsLastSavedSecond, itsLastSavedSampleNr, itsLastSavedNrOfSamples, itsLastSavedSampleFreq )); - + double sampletime = 1. / (itsLastSavedSampleFreq * 1E6); // in sec - + // calculate time of last sample in memory - NsTimestamp - lastSampleTime(itsLastSavedSecond + ((itsLastSavedSampleNr + itsLastSavedNrOfSamples) * sampletime)); - + NsTimestamp lastSampleTime(itsLastSavedSecond + ((itsLastSavedSampleNr + itsLastSavedNrOfSamples) * sampletime)); + // calculate time of first sample in memory - NsTimestamp - firstSampleTime((double)lastSampleTime - (TS->getChPageSize(getChannelNr()) * itsLastSavedNrOfSamples * sampletime)); - + NsTimestamp firstSampleTime((double)lastSampleTime - (TS->getChPageSize(getChannelNr()) * itsLastSavedNrOfSamples * sampletime)); + // calculate start and stop time - NsTimestamp startTimestamp = itsTimestamp - itsTimeBefore; - NsTimestamp stopTimestamp = itsTimestamp + itsTimeAfter; - + NsTimestamp startTimestamp(itsTimestamp - itsTimeBefore); + NsTimestamp stopTimestamp(itsTimestamp + itsTimeAfter); + #if 1 //LOG_DEBUG_STR(formatString("Timestamp = %lu seconds %lu nseconds", itsTimestamp.sec(), itsTimestamp.nsec())); LOG_DEBUG_STR(formatString("firstSampleTime= %lu seconds %lu nseconds", firstSampleTime.sec(), firstSampleTime.nsec())); @@ -238,40 +236,40 @@ void ReadCmd::saveTpAckEvent(GCFEvent& event) LOG_DEBUG_STR(formatString("startTimestamp = %lu seconds %lu nseconds", startTimestamp.sec(), startTimestamp.nsec())); LOG_DEBUG_STR(formatString("stopTimestamp = %lu seconds %lu nseconds", stopTimestamp.sec(), stopTimestamp.nsec())); #endif - - // to get last part of recording + + // to get last part of recording if (itsTimestamp == 0.0) { itsTimestamp = lastSampleTime; } - + // check if center time in memory if ((itsTimestamp >= firstSampleTime) && (itsTimestamp <= lastSampleTime)) { // check if start time in memory, if not correct it if (startTimestamp < firstSampleTime) { LOG_WARN_STR(formatString("Not all requested prepages are available for rcu[%d]", TS->convertChanToRcu(getChannelNr()))); - LOG_WARN_STR(formatString("requested starttime = %lf, first time in memory = %lf", (double)startTimestamp, (double)firstSampleTime)); - + LOG_WARN_STR(formatString("requested starttime = %lf, first time in memory = %lf", (double)startTimestamp, (double)firstSampleTime)); + startTimestamp = firstSampleTime; } // check if stop time in memory, if not correct it if (stopTimestamp > lastSampleTime) { LOG_WARN_STR(formatString("Not all requested postpages are available for rcu[%d]", TS->convertChanToRcu(getChannelNr()))); - LOG_WARN_STR(formatString("requested stoptime = %lf, last time in memory = %lf", (double)stopTimestamp, (double)lastSampleTime)); + LOG_WARN_STR(formatString("requested stoptime = %lf, last time in memory = %lf", (double)stopTimestamp, (double)lastSampleTime)); stopTimestamp = lastSampleTime; } } else { // requested time not in memory LOG_WARN_STR(formatString("Requested time(data) not in memory for rcu[%d]", TS->convertChanToRcu(getChannelNr()))); - LOG_WARN_STR(formatString("requested time = %lf, in memory [%lf .. %lf]", (double)itsTimestamp, (double)firstSampleTime, (double)lastSampleTime)); + LOG_WARN_STR(formatString("requested time = %lf, in memory [%lf .. %lf]", (double)itsTimestamp, (double)firstSampleTime, (double)lastSampleTime)); setDone(true); - } - - itsTimeBefore = itsTimestamp - startTimestamp; - itsTimeAfter = stopTimestamp - itsTimestamp; - + } + + itsTimeBefore.set(itsTimestamp - startTimestamp); + itsTimeAfter.set(stopTimestamp - itsTimestamp); + // convert it to board units - + itsSecondstime = (uint32)itsTimestamp.sec(); itsSampleNr = (uint32)(itsTimestamp.nsec() / (sampletime * 1E9)); itsPrepages = (uint32)ceil(((double)(itsTimestamp - startTimestamp) / sampletime) / itsLastSavedNrOfSamples); @@ -294,7 +292,7 @@ void ReadCmd::saveTpAckEvent(GCFEvent& event) } else if (event.signal == TP_ARP_ACK) { TPArpAckEvent tp_ack(event); - + if (tp_ack.status != 0) { setStatus(0, (tp_ack.status << 24)); } @@ -316,7 +314,7 @@ void ReadCmd::saveTpAckEvent(GCFEvent& event) LOG_INFO_STR(formatString("TBB busy, %d pages left", tp_ack.pages_left)); usleep(100000); // wait for some time and try again } - else { + else { if (tp_ack.status != 0) { setStatus(0, (tp_ack.status << 24)); }