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

The receiver class is the public interface for the fun_ofdm receiver. This is the easiest way to start receiving 802.11a OFDM frames out of the box. More...

#include <receiver.h>

Public Member Functions

 receiver (void(*callback)(std::vector< std::vector< unsigned char > > packets), double freq=5.72e9, double samp_rate=5e6, double rx_gain=20, std::string device_addr="")
 Constructor for the receiver with raw parameters. More...
 
 receiver (void(*callback)(std::vector< std::vector< unsigned char > > packets), usrp_params params=usrp_params())
 Constructor for the receiver that uses the usrp_params struct. More...
 
void pause ()
 Pauses the receiver thread. More...
 
void resume ()
 Resumes the receiver thread after it has been paused. More...
 

Private Member Functions

void receiver_chain_loop ()
 Infinite while loop where samples are received from USRP and processed by the receiver_chain. More...
 

Private Attributes

void(* m_callback )(std::vector< std::vector< unsigned char > > packets)
 Callback function pointer. More...
 
usrp m_usrp
 The usrp object used to receiver frames over the air. More...
 
receiver_chain m_rec_chain
 The receiver chain object used to detect & decode incoming frames. More...
 
std::vector< std::complex
< double > > 
m_samples
 Vector to hold the raw samples received from the USRP and passed into the receiver_chain. More...
 
std::thread m_rec_thread
 The thread that the receiver chain runs in. More...
 
sem_t m_pause
 Semaphore used to pause the receiver thread. More...
 

Detailed Description

The receiver class is the public interface for the fun_ofdm receiver. This is the easiest way to start receiving 802.11a OFDM frames out of the box.

Usage: To receive packets simply create a receiver object and pass it a callback function that takes a std::vector<std::vector<unsigned char> > as an input parameter. The receiver object then automatically creates a separate thread that pulls samples from the USRP and processes them with the receive chain. The received packets (if any) are then passed into the callback function where the user is able to process them further.

If at any time the user wishes to pause the receiver (i.e. so that the user can transmit some packets) the user simply needs to call the receiver::pause() function on the receiver object. Similarly, the receiver::resume() function can then be used to begin receiving again after a pause.

Definition at line 36 of file receiver.h.

Constructor & Destructor Documentation

fun::receiver::receiver ( void(*)(std::vector< std::vector< unsigned char > > packets)  callback,
double  freq = 5.72e9,
double  samp_rate = 5e6,
double  rx_gain = 20,
std::string  device_addr = "" 
)

Constructor for the receiver with raw parameters.

Parameters
callbackFunction pointer to the callback function where received packets are passed
freq[Optional] Center frequency
samp_rate[Optional] Sample Rate
rx_gain[Optional] Receive Gain
device_addr[Optional] IP address of USRP device

Defaults to:

  • center freq -> 5.72e9 (5.72 GHz)
  • sample rate -> 5e6 (5 MHz)
  • rx gain -> 20
  • device ip address -> "" (empty string will default to letting the UHD api automatically find an available USRP)
  • *Note:
    • tx_gain -> 20 even though it is irrelevant for the receiver
    • amp -> 1.0 even though it is irrelevant for the receiver

This constructor shows exactly what parameters need to be set for the receiver.

Definition at line 16 of file receiver.cpp.

16  :
17  receiver(callback, usrp_params(freq, samp_rate, 20, rx_gain, 1.0, device_addr))
18  {
19  }
fun::receiver::receiver ( void(*)(std::vector< std::vector< unsigned char > > packets)  callback,
usrp_params  params = usrp_params() 
)

Constructor for the receiver that uses the usrp_params struct.

Parameters
callbackFunction pointer to the callback function where received packets are passed
params[Optional] The usrp parameters you want to use for this receiver.

Defaults to:

  • center freq -> 5.72e9 (5.72 GHz)
  • sample rate -> 5e6 (5 MHz)
  • tx gain -> 20
  • rx gain -> 20 (although this is irrelevant for the transmitter)
  • device ip address -> "" (empty string will default to letting the UHD api automatically find an available USRP)

This constructor is for those who feel more comfortable using the usrp_params struct.

Definition at line 24 of file receiver.cpp.

References m_pause, m_rec_thread, and receiver_chain_loop().

24  :
25  m_usrp(params),
28  m_rec_chain()
29  {
30  sem_init(&m_pause, 0, 1); //Initial value is 1 so that the receiver_chain_loop() will begin executing immediately
31  m_rec_thread = std::thread(&receiver::receiver_chain_loop, this); //Initialize the main receiver thread
32  }

Member Function Documentation

void fun::receiver::pause ( )

Pauses the receiver thread.

Uses an internal semaphore to block the execution of the receiver loop code effectively pausing the receiver until the semaphore is posted to (cleared) by the receiver::resume() function.

Definition at line 64 of file receiver.cpp.

References m_pause.

Referenced by main(), and test_rx_pause().

65  {
66  sem_wait(&m_pause);
67  }
void fun::receiver::receiver_chain_loop ( )
private

Infinite while loop where samples are received from USRP and processed by the receiver_chain.

This function loops forever (unless it is paused) pulling samples from the USRP and passing them through the receiver chain. It then passes any successfully decoded packets to the callback function for the user to process further. This function can be paused by the user by calling the receiver::pause() function, presumably so that the user can transmit packets over the air using the transmitter. Once the user is finished transmitting he/she can resume the receiver by called the receiver::resume() function. These two functions use an internal semaphore to block the receiver code execution while in the paused state.

Definition at line 42 of file receiver.cpp.

References fun::usrp::get_samples(), m_callback, m_pause, m_rec_chain, m_samples, m_usrp, NUM_RX_SAMPLES, and fun::receiver_chain::process_samples().

Referenced by receiver().

43  {
44  while(1)
45  {
46  sem_wait(&m_pause); // Block if the receiver is paused
47 
49 
50  std::vector<std::vector<unsigned char> > packets =
52 
53  m_callback(packets);
54 
55  sem_post(&m_pause); // Flags the end of this loop and wakes up any other threads waiting on this semaphore
56  // i.e. a call to the pause() function in the main thread.
57  }
58  }
void fun::receiver::resume ( )

Resumes the receiver thread after it has been paused.

This function posts to (clears) the internal semaphore that is blocking the receiver loop code execution due to a previous call to the receiver::pause() function, thus allowing the main receiver loop to begin executing again.

Definition at line 74 of file receiver.cpp.

References m_pause.

Referenced by main(), and test_rx_pause().

75  {
76  sem_post(&m_pause);
77  }

Member Data Documentation

void(* fun::receiver::m_callback)(std::vector< std::vector< unsigned char > > packets)
private

Callback function pointer.

Definition at line 89 of file receiver.h.

Referenced by receiver_chain_loop().

sem_t fun::receiver::m_pause
private

Semaphore used to pause the receiver thread.

Definition at line 99 of file receiver.h.

Referenced by pause(), receiver(), receiver_chain_loop(), and resume().

receiver_chain fun::receiver::m_rec_chain
private

The receiver chain object used to detect & decode incoming frames.

Definition at line 93 of file receiver.h.

Referenced by receiver_chain_loop().

std::thread fun::receiver::m_rec_thread
private

The thread that the receiver chain runs in.

Definition at line 97 of file receiver.h.

Referenced by receiver().

std::vector<std::complex<double> > fun::receiver::m_samples
private

Vector to hold the raw samples received from the USRP and passed into the receiver_chain.

Definition at line 95 of file receiver.h.

Referenced by receiver_chain_loop().

usrp fun::receiver::m_usrp
private

The usrp object used to receiver frames over the air.

Definition at line 91 of file receiver.h.

Referenced by receiver_chain_loop().


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