I'm doing a loopback to check which sample a certain signal level is found.
I'm transmitting in the main thread and I create a receiver thread to look
for the rise in the input signal. Here is my receiver worker
void receive_worker(
uhd::usrp::multi_usrp::sptr usrp,
std::vector<std::complex<float> > rx_buff,
uhd::rx_streamer::sptr rx_stream,
size_t total_num_rx_samps,
double time_to_receive,
std::queue<size_t>* edge_queue,
bool* stop_receive
){
io_mutex.lock();
std::cout << boost::format("Receive thread started!") << std::endl;
io_mutex.unlock();
//set buffers same for all channels (if more than 1)
std::vector<std::complex<float> *>
rx_buffs(rx_stream->get_num_channels(), &rx_buff.front());
//setup streaming
uhd::stream_cmd_t stream_cmd((total_num_rx_samps == 0)?
uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS:
uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE
);
io_mutex.lock();
// if we are looking for a finite set of samples
if (total_num_rx_samps > 0){
std::cout << boost::format(
"Begin streaming in for %u samples starting at %0.9f device time"
) % total_num_rx_samps % time_to_receive << std::endl;
}
else{
std::cout << boost::format(
"Begin streaming in continuous samples starting at %0.9f device
time"
) % time_to_receive << std::endl;
}
io_mutex.unlock();
//set up the RX command
stream_cmd.num_samps = total_num_rx_samps;
stream_cmd.stream_now = false;
stream_cmd.time_spec = uhd::time_spec_t(time_to_receive);
rx_stream->issue_stream_cmd(stream_cmd);
//meta-data will be filled in by recv()
uhd::rx_metadata_t rx_md;
double rx_timeout = time_to_receive + 0.1;
size_t num_acc_samps = 0;
/* ------------- Main While Loop --------------- */
while(not *stop_receive and (num_acc_samps < total_num_rx_samps or
total_num_rx_samps == 0)){
//rece ive a single full otw packet
size_t num_rx_samps = rx_stream->recv(
rx_buffs, rx_buff.size(), rx_md, rx_timeout, true
);
rx_timeout = 0.1f; //small timeout for subsequent recv
//error handling
if (rx_md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
io_mutex.lock();
std::cout << boost::format(
"Receiver Error %s ... Shutting down!"
) % rx_md.strerror() << std::endl;
io_mutex.unlock();
//set stop receive signal
*stop_receive = true;
}
//look for a single rising edge
edge_offset_calc(rx_buff, num_acc_samps, edge_queue);
//keep track of absolute sample number
num_acc_samps += num_rx_samps;
//if we were streaming continuously, send a stop command
if (*stop_receive and total_num_rx_samps == 0){
// Shut down receiver
std::cout << boost::format("Sending stop command...") << std::endl;
stream_cmd.stream_mode =
uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS;
rx_stream->issue_stream_cmd(stream_cmd);
}
}//RX while
boost::this_thread::sleep(boost::posix_time::seconds(0.2)); //wait
io_mutex.lock();
std::cout << boost::format("Receive thread ended!") << std::endl;
io_mutex.unlock();
}
I create the rx thread with:
//edge queue
std::queue<size_t> edge_queue;
bool stop_receive = false;
//start the thread
boost::thread_group transmit_thread;
transmit_thread.create_thread(
boost::bind(
&receive_worker, usrp, rx_buff, rx_stream, total_num_rx_samps,
time_to_receive, &edge_queue, &stop_receive
)
);
the edge calc function simply iterates through the vector and pushes the
sample location of the rise in signal level (2-norm of the complex float)
to the queue. When debugging I sometimes get this kind of output after
starting up the device
Setting device timestamp to 0...
Transmitting 50 samples at 0.200000000 device time
Receive thread started!
Begin streaming in for 400000 samples starting at 0.190000000 device time
Transmit burst success!
max is 0.358725
Edge found on sample 200164 packet offset of 164
max is 2.0942e+34
Edge found on sample 242000 packet offset of 2000
max is 2.0942e+34
Edge found on sample 244000 packet offset of 2000
max is 2.0943e+34
Edge found on sample 254000 packet offset of 2000
max is inf
Edge found on sample 262000 packet offset of 2000
max is inf
Edge found on sample 264000 packet offset of 2000
max is 2.09449e+34
Edge found on sample 272000 packet offset of 2000
max is 2.09449e+34
Edge found on sample 274000 packet offset of 2000
Receive thread ended!
My spp is forced to 2000 using the stream args. and This is on UHD 3.010.03.
thanks for the help.
On Wed, Oct 10, 2018 at 5:07 PM Michael Dickens <[email protected]>
wrote:
> Hi Mitch - Can you provide your code for us to review, to get an idea of
> what you're doing that's causing this issue for you? Without specific
> code, debugging is a little difficult ... And, no, I haven't seen this
> issue to the best of my knowledge / understanding of what it might be.
> Cheers! - MLD
>
> On Wed, Oct 10, 2018, at 4:03 PM, Mitch Grabner via USRP-users wrote:
>
> Hello,
>
> I find that sometimes when I initialize a b200 and start streaming in
> samples I will get buffers with values of infinity (especially at the last
> sample in the buffer). Is this caused by a bad packet or overflow
> condition? It also seems to happen randomly.
>
> Thanks for your help,
> - mitch
>
>
>
--
*Mitchell J Grabner*
*Student Member IEEE Communications Society*
*------------------------------------------------*
My Linkedin <http://www.linkedin.com/pub/mitch-grabner/43/23b/bb5>
_______________________________________________
USRP-users mailing list
[email protected]
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com