fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
fun::usrp Class Reference

A simple class used to easily interface with a USRP. More...

#include <usrp.h>

Public Member Functions

 usrp (usrp_params params)
 Constructor for usrp class. More...
 
void send_burst_sync (std::vector< std::complex< double > > samples)
 Sends a burst of samples and block until the burst has finished. More...
 
void send_burst (std::vector< std::complex< double > > samples)
 Sends a burst of samples but does not block until the burst has finished. More...
 
void get_samples (int num_samples, std::vector< std::complex< double > > &buffer)
 Gets num_samples samples and places them in the first num_samples of buffer. More...
 

Private Attributes

usrp_params m_params
 Container for the parameters for this instance of the USRP class. More...
 
boost::shared_ptr
< uhd::usrp::multi_usrp > 
m_usrp
 multi_usrp (main USRP handle) More...
 
boost::shared_ptr< uhd::device > m_device
 device (receives async messages) More...
 
uhd::rx_streamer::sptr m_rx_streamer
 TX (output) streamer. More...
 
uhd::tx_streamer::sptr m_tx_streamer
 RX (input) streamer. More...
 
sem_t m_tx_sem
 Sempahore used to block for send_burst_sync. More...
 

Detailed Description

A simple class used to easily interface with a USRP.

The usrp class is a wrapper class for the UHD API. It provides a simple interface for transmitting and receiving samples to/from the USRP.

Definition at line 60 of file usrp.h.

Constructor & Destructor Documentation

fun::usrp::usrp ( usrp_params  params)

Constructor for usrp class.

Parameters
paramsthe parameters for the intance of this class. These parameters will remain fixed for the lifetime of the USRP object.

-Initializations

  • m_params -> Previously initialized usrp_params object containing the desired parameters for the USRP.

Definition at line 20 of file usrp.cpp.

References fun::usrp_params::device_addr, fun::usrp_params::freq, m_device, m_params, m_rx_streamer, m_tx_sem, m_tx_streamer, m_usrp, fun::usrp_params::rate, fun::usrp_params::rx_gain, and fun::usrp_params::tx_gain.

20  :
21  m_params(params)
22  {
23  // Instantiate the multi_usrp
24  m_usrp = uhd::usrp::multi_usrp::make(uhd::device_addr_t(m_params.device_addr));
25  m_device = m_usrp->get_device();
26 
27  // Set the center frequency
28  m_usrp->set_tx_freq(uhd::tune_request_t(m_params.freq));
29  m_usrp->set_rx_freq(uhd::tune_request_t(m_params.freq));
30 
31  // Set the sample rate
32  m_usrp->set_tx_rate(m_params.rate);
33  m_usrp->set_rx_rate(m_params.rate);
34 
35  // Set the gains
36  m_usrp->set_tx_gain(m_params.tx_gain);
37  m_usrp->set_rx_gain(m_params.rx_gain);
38 
39  // Set the RX antenna
40  //m_usrp->set_rx_antenna("RX2");
41 
42  // Get the TX and RX stream handles
43  m_tx_streamer = m_usrp->get_tx_stream(uhd::stream_args_t("fc64"));
44  m_rx_streamer = m_usrp->get_rx_stream(uhd::stream_args_t("fc64"));
45 
46  // Start the RX stream
47  uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
48  stream_cmd.stream_now = true;
49  m_usrp->issue_stream_cmd(stream_cmd);
50 
51  sem_init(&m_tx_sem, 0, 0);
52  sem_post(&m_tx_sem);
53  }

Member Function Documentation

void fun::usrp::get_samples ( int  num_samples,
std::vector< std::complex< double > > &  buffer 
)

Gets num_samples samples and places them in the first num_samples of buffer.

Parameters
num_samplesThe number of samples to retrieve from USRP.
bufferThe buffer to place the retrieved samples in.

Gets num_samples from the USRP and places them in the buffer parameter. If this function is not called "fast enough" the USRP will get upset because the computer is not consuming samples fast enough to keep up with the USRPs receive sample rate. This will cause the USRP to indicate an overflow and thus not guarantee the integrity of the retrieved data. See link to ettus' website for more details.

Definition at line 125 of file usrp.cpp.

References m_rx_streamer.

Referenced by fun::receiver::receiver_chain_loop().

126  {
127  // Get some samples
128  uhd::rx_metadata_t rx_meta;
129  m_rx_streamer->recv(&buffer[0], num_samples, rx_meta);
130  }
void fun::usrp::send_burst ( std::vector< std::complex< double > >  samples)

Sends a burst of samples but does not block until the burst has finished.

Parameters
samplesA vector of complex doubles representing the base band time domain signal to be up-converted and transmitted by the USRP.

Sends a burst of samples to the USRP which represent the digital base-band signal to be up-converted and transmitted by the USRP.

This function does not block after it is called. Due to the multi-threading nature of the UHD API, this function may return before the USRP has finished transmitting all of the samples. This is generally ok as subsequent calls to this method will just buffer more samples in the USRP. However, if it is not called fast enough an underrun may occer. See link to ettus' website for more details.

Definition at line 66 of file usrp.cpp.

References m_tx_sem, and m_tx_streamer.

67  {
68  sem_wait(&m_tx_sem);
69 
70  uhd::tx_metadata_t tx_metadata;
71  tx_metadata.start_of_burst = true;
72  tx_metadata.end_of_burst = true;
73  tx_metadata.has_time_spec = false;
74  m_tx_streamer->send(&samples[0], samples.size(), tx_metadata);
75 
76  sem_post(&m_tx_sem);
77  }
void fun::usrp::send_burst_sync ( std::vector< std::complex< double > >  samples)

Sends a burst of samples and block until the burst has finished.

Parameters
samplesA vector of complex doubles representing the base band time domain signal to be up-converted and transmitted by the USRP.

Sends a burst of samples to the USRP which represent the digital base-band signal to be up-converted and transmitted by the USRP.

This function uses a semaphore to block until the USRP has responded with an acknowledgement that all the samples have been transmitted over the air. This prevents the user from sending too much data at once so that the user has some sense of when the transmission is finished. If the user does not call this fast enough an underrun may occur. See link to ettus' website for more details.

Definition at line 91 of file usrp.cpp.

References m_device, m_params, m_tx_streamer, and fun::usrp_params::tx_amp.

Referenced by fun::transmitter::send_packet().

92  {
93  // Scale the samples by m_amp
94  if(m_params.tx_amp != 1.0)
95  for(int x = 0; x < samples.size(); x++)
96  samples[x] *= m_params.tx_amp;
97 
98  // Send the samples
99  uhd::tx_metadata_t tx_metadata;
100  tx_metadata.start_of_burst = true;
101  tx_metadata.end_of_burst = true;
102  tx_metadata.has_time_spec = false;
103  m_tx_streamer->send(&samples[0], samples.size(), tx_metadata);
104 
105  // Wait for the end of burst ACK followed by an underflow
106  bool got_ack = false;
107  bool got_underflow = false;
108  uhd::async_metadata_t async_metadata;
109  while(!got_ack && !got_underflow && m_device->recv_async_msg(async_metadata, 1))
110  {
111  got_ack = (async_metadata.event_code == uhd::async_metadata_t::EVENT_CODE_BURST_ACK);
112  got_underflow = (got_ack && async_metadata.event_code == uhd::async_metadata_t::EVENT_CODE_UNDERFLOW);
113  }
114  }

Member Data Documentation

boost::shared_ptr<uhd::device> fun::usrp::m_device
private

device (receives async messages)

Definition at line 102 of file usrp.h.

Referenced by send_burst_sync(), and usrp().

usrp_params fun::usrp::m_params
private

Container for the parameters for this instance of the USRP class.

Definition at line 99 of file usrp.h.

Referenced by send_burst_sync(), and usrp().

uhd::rx_streamer::sptr fun::usrp::m_rx_streamer
private

TX (output) streamer.

Definition at line 103 of file usrp.h.

Referenced by get_samples(), and usrp().

sem_t fun::usrp::m_tx_sem
private

Sempahore used to block for send_burst_sync.

Definition at line 106 of file usrp.h.

Referenced by send_burst(), and usrp().

uhd::tx_streamer::sptr fun::usrp::m_tx_streamer
private

RX (input) streamer.

Definition at line 104 of file usrp.h.

Referenced by send_burst(), send_burst_sync(), and usrp().

boost::shared_ptr<uhd::usrp::multi_usrp> fun::usrp::m_usrp
private

multi_usrp (main USRP handle)

Definition at line 101 of file usrp.h.

Referenced by usrp().


The documentation for this class was generated from the following files: