Commit 2184465a authored by Thomas Telkamp's avatar Thomas Telkamp
Browse files

add option to align start of reception to integer second

parent 81558001
......@@ -28,6 +28,7 @@ if __name__ == "__main__":
parser.add_argument("--progress", help="periodically display short-term bandwidth", action="store_true")
parser.add_argument("--stats", help="show average bandwidth on exit", action="store_true")
parser.add_argument("--pps", help="use external pps signal", action="store_true")
parser.add_argument("--int-second", help="align start of reception to integer second", action="store_true")
parser.add_argument("--null", help="run without writing to file", action="store_true")
parser.add_argument("--continue", help="don't abort on a bad packet", action="store_true")
parser.add_argument("--ski-lo", help="skip checking LO lock status", action="store_true")
......
......@@ -60,20 +60,22 @@ void write_worker(const std::string& file, bool null, size_t samps_per_buff) {
start_rx = true;
while (not stop_signal_called || ( stop_signal_called && readcounter <= writecounter ) ) {
while (not stop_signal_called || ( stop_signal_called && readcounter < writecounter ) ) {
while(readpointer == writepointer && not stop_signal_called) {
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
readcounter++;
if (readcounter < writecounter) {
readcounter++;
if (outfile.is_open()) {
outfile.write((const char*)readpointer, numbytes);
if (outfile.is_open()) {
outfile.write((const char*)readpointer, numbytes);
}
readpointer += numbytes;
if (readpointer > &writebuffer[BUFFER_SIZE]-samps_per_buff)
readpointer = writebuffer;
}
readpointer += numbytes;
if (readpointer > &writebuffer[BUFFER_SIZE]-samps_per_buff)
readpointer = writebuffer;
}
if (outfile.is_open()) {
......@@ -93,7 +95,7 @@ void recv_to_file(uhd::usrp::multi_usrp::sptr usrp,
bool bw_summary = false,
bool stats = false,
bool null = false,
bool enable_size_map = false,
bool int_second = false,
bool continue_on_bad_packet = false)
{
// create a receive streamer
......@@ -115,20 +117,29 @@ void recv_to_file(uhd::usrp::multi_usrp::sptr usrp,
// wait for write thread
while (!start_rx && not stop_signal_called) {}
// time keeping
auto start_time = std::chrono::steady_clock::now();
auto stop_time =
start_time + std::chrono::milliseconds(int64_t(1000 * time_requested));
// setup streaming
uhd::stream_cmd_t stream_cmd((num_requested_samples == 0)
? uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS
: uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
stream_cmd.num_samps = size_t(num_requested_samples);
stream_cmd.stream_now = true;
stream_cmd.time_spec = uhd::time_spec_t();
if (int_second) {
stream_cmd.time_spec = usrp->get_time_now().get_full_secs() + 1;
stream_cmd.stream_now = false;
}
else {
stream_cmd.time_spec = uhd::time_spec_t();
stream_cmd.stream_now = true;
}
rx_stream->issue_stream_cmd(stream_cmd);
// typedef std::map<size_t, size_t> SizeMap;
// SizeMap mapSizes;
const auto start_time = std::chrono::steady_clock::now();
const auto stop_time =
start_time + std::chrono::milliseconds(int64_t(1000 * time_requested));
// Track time and samps between updating the BW summary
auto last_update = start_time;
unsigned long long last_update_samps = 0;
......@@ -136,6 +147,10 @@ void recv_to_file(uhd::usrp::multi_usrp::sptr usrp,
int32_t buffer_size = BUFFER_SIZE/samps_per_buff;
int32_t diff;
if (int_second) {
stop_time += std::chrono::milliseconds(int64_t(1000.0*(double)(stream_cmd.time_spec.get_real_secs()-usrp->get_time_now().get_real_secs())));
}
// Run this loop until either time expired (if a duration was given), until
// the requested number of samples were collected (if such a number was
// given), or until Ctrl-C was pressed.
......@@ -145,7 +160,7 @@ void recv_to_file(uhd::usrp::multi_usrp::sptr usrp,
const auto now = std::chrono::steady_clock::now();
size_t num_rx_samps =
rx_stream->recv(&buff.front(), buff.size(), md, 3.0, enable_size_map);
rx_stream->recv(&buff.front(), buff.size(), md, 3.0, false);
if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) {
std::cout << boost::format("Timeout while streaming") << std::endl;
......@@ -185,6 +200,8 @@ void recv_to_file(uhd::usrp::multi_usrp::sptr usrp,
first_frame = false;
}
stream_cmd.stream_now = false;
// if (enable_size_map) {
// SizeMap::iterator it = mapSizes.find(num_rx_samps);
// if (it == mapSizes.end())
......@@ -233,6 +250,8 @@ void recv_to_file(uhd::usrp::multi_usrp::sptr usrp,
uint32_t clip_i = 0;
uint32_t clip_q = 0;
// TODO: this assumes cs16...
for (int i=0; i<num_rx_samps; i++ ) {
int16_t sample_i = fabs(reinterpret_cast<short int (&)[2]>(buff[i])[0]);
int16_t sample_q = fabs(reinterpret_cast<short int (&)[2]>(buff[i])[1]);
......@@ -365,6 +384,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
("stats", "show average bandwidth on exit")
// ("sizemap", "track packet size and display breakdown on exit")
("pps", "use external pps signal")
("int-second", "align start of reception to integer second")
("null", "run without writing to file")
("continue", "don't abort on a bad packet")
("skip-lo", "skip checking LO lock status")
......@@ -622,7 +642,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
bw_summary, \
stats, \
null, \
enable_size_map, \
(bool)vm.count("int-second"), \
continue_on_bad_packet)
// recv to file
if (wirefmt == "s16") {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment