Skip to content

Commit

Permalink
Interrupt UHD when FCT value is not contiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
mpbraendli committed Sep 26, 2014
1 parent 6850954 commit 11295ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/EtiReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,13 @@ bool EtiReader::sourceContainsTimestamp()

double EtiReader::getPPSOffset()
{
if (!sourceContainsTimestamp())
if (!sourceContainsTimestamp()) {
//fprintf(stderr, "****** SOURCE NO TS\n");
return 0.0;
}

uint32_t timestamp = ntohl(eti_tist.TIST) & 0xFFFFFF;
//fprintf(stderr, "TIST 0x%x\n", timestamp);
//fprintf(stderr, "****** TIST 0x%x\n", timestamp);
double pps = timestamp / 16384000.0; // seconds

return pps;
Expand Down
35 changes: 16 additions & 19 deletions src/OutputUHD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ void UHDWorker::process()
md.start_of_burst = false;
md.end_of_burst = false;

int expected_next_fct = -1;

while (running) {
bool fct_discontinuity = false;
md.has_time_spec = false;
md.time_spec = uhd::time_spec_t(0.0);
num_acc_samps = 0;
Expand Down Expand Up @@ -376,19 +379,20 @@ void UHDWorker::process()

sizeIn = uwd->bufsize / sizeof(complexf);

#if FAKE_UHD
/* Verify that the FCT value is correct. If we miss one transmission
* frame we must interrupt UHD and resync to the timestamps
*/
if (expected_next_fct != -1) {
if (expected_next_fct != frame->ts.fct) {
if (expected_next_fct != (int)frame->ts.fct) {
uwd->logger->level(warn) <<
"OutputUHD: Incorrect expect fct " << frame->ts.fct;

// TODO here we should disrupt the UHD streamer so that
// it resyncs to the correct timestamps
fct_discontinuity = true;
}
}

expected_next_fct = (frame->ts.fct + uwd->fct_increment) % 250;
#else

// Check for ref_lock
if (uwd->check_refclk_loss)
{
Expand Down Expand Up @@ -482,7 +486,6 @@ void UHDWorker::process()
goto loopend;
}
}
#endif

PDEBUG("UHDWorker::process:max_num_samps: %zu.\n",
usrp_max_num_samps);
Expand All @@ -492,8 +495,13 @@ void UHDWorker::process()

//ensure the the last packet has EOB set if the timestamps has been
//refreshed and need to be reconsidered.
md.end_of_burst = (frame->ts.timestamp_refresh &&
(samps_to_send <= usrp_max_num_samps));
//Also, if we saw that the FCT did not increment as expected, which
//could be due to a lost incoming packet.
md.end_of_burst = (
uwd->sourceContainsTimestamp &&
(frame->ts.timestamp_refresh || fct_discontinuity) &&
samps_to_send <= usrp_max_num_samps );


#if FAKE_UHD
// This is probably very approximate
Expand Down Expand Up @@ -586,17 +594,6 @@ void UHDWorker::process()
}
}
#endif

/*
bool got_async_burst_ack = false;
//loop through all messages for the ACK packet (may have underflow messages in queue)
while (not got_async_burst_ack and uwd->myUsrp->get_device()->recv_async_msg(async_md, 0.2)){
got_async_burst_ack = (async_md.event_code == uhd::async_metadata_t::EVENT_CODE_BURST_ACK);
}
//std::cerr << (got_async_burst_ack? "success" : "fail") << std::endl;
// */


}

last_pps = pps_offset;
Expand Down
20 changes: 14 additions & 6 deletions src/TimestampDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "Eti.h"
#include "Log.h"

//#define MDEBUG(fmt, args...) fprintf (LOG, fmt , ## args)
//#define MDEBUG(fmt, args...) fprintf (LOG, "*****" fmt , ## args)
#define MDEBUG(fmt, args...) PDEBUG(fmt, ## args)


Expand All @@ -52,6 +52,7 @@ void TimestampDecoder::calculateTimestamp(struct frame_timestamp& ts)
ts_queued->timestamp_refresh = offset_changed;
offset_changed = false;

MDEBUG("time_secs=%d, time_pps=%f\n", time_secs, time_pps);
*ts_queued += timestamp_offset;

queue_timestamps.push(ts_queued);
Expand Down Expand Up @@ -90,7 +91,7 @@ void TimestampDecoder::calculateTimestamp(struct frame_timestamp& ts)
delete ts_queued;
}

PDEBUG("Timestamp queue size %zu, delay_calc %u\n",
MDEBUG("Timestamp queue size %zu, delay_calc %u\n",
queue_timestamps.size(),
modconfig.delay_calculation_pipeline_stages);

Expand Down Expand Up @@ -157,13 +158,14 @@ void TimestampDecoder::pushMNSCData(int framephase, uint16_t mnsc)

void TimestampDecoder::updateTimestampSeconds(uint32_t secs)
{
MDEBUG("TimestampDecoder::updateTimestampSeconds(%d)\n", secs);
if (inhibit_second_update > 0)
{
MDEBUG("TimestampDecoder::updateTimestampSeconds(%d) inhibit\n", secs);
inhibit_second_update--;
}
else
{
MDEBUG("TimestampDecoder::updateTimestampSeconds(%d) apply\n", secs);
time_secs = secs;
}
}
Expand Down Expand Up @@ -229,13 +231,16 @@ bool TimestampDecoder::updateModulatorOffset()
}
catch (bad_lexical_cast& e)
{
myLogger.level(error) << "Error parsing timestamp offset from file '" << modconfig.offset_filename << "'";
myLogger.level(error) <<
"Error parsing timestamp offset from file '" <<
modconfig.offset_filename << "'";
r = false;
}
}
else
{
myLogger.level(error) << "Error reading from timestamp offset file: eof reached\n";
myLogger.level(error) <<
"Error reading from timestamp offset file: eof reached\n";
r = false;
}
filestream.close();
Expand All @@ -252,7 +257,9 @@ bool TimestampDecoder::updateModulatorOffset()
if (timestamp_offset != newoffset)
{
timestamp_offset = newoffset;
myLogger.level(info) << "TimestampDecoder::updateTimestampOffset: new offset is " << timestamp_offset;
myLogger.level(info) <<
"TimestampDecoder::updateTimestampOffset: new offset is " <<
timestamp_offset;
offset_changed = true;
}

Expand All @@ -264,3 +271,4 @@ bool TimestampDecoder::updateModulatorOffset()
return false;
}
}

0 comments on commit 11295ea

Please sign in to comment.