fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
receiver_chain.cpp
Go to the documentation of this file.
1 
10 #include <iostream>
11 #include <functional>
12 #include <boost/date_time/posix_time/posix_time.hpp>
13 
14 #include "receiver_chain.h"
15 
16 namespace fun
17 {
30  {
32  m_timing_sync = new timing_sync();
33  m_fft_symbols = new fft_symbols();
34  m_channel_est = new channel_est();
37 
38  // We use semaphore references, so we don't
39  // want them to move to a different memory location
40  // if the vectors get resized
41  m_wake_sems.reserve(100);
42  m_done_sems.reserve(100);
43 
44  // Add the blocks to the receiver chain
51  }
52 
59  {
60  m_wake_sems.push_back(sem_t());
61  m_done_sems.push_back(sem_t());
62  int index = m_wake_sems.size() - 1;
63  sem_init(&m_wake_sems[index], 0, 0);
64  sem_init(&m_done_sems[index], 0, 0);
65  m_threads.push_back(std::thread(&receiver_chain::run_block, this, index, block));
66  }
67 
79  {
80  while(1)
81  {
82  sem_wait(&m_wake_sems[index]);
83 
84  boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time();
85  block->work();
86  boost::posix_time::time_duration elapsed = boost::posix_time::microsec_clock::local_time() - start;
87 
88  if(elapsed.total_microseconds() > (2000 / 5e6 * 1e6))
89  {
90  //std::cout << "! - " << block->name << std::endl;
91  }
92 
93  sem_post(&m_done_sems[index]);
94  }
95  }
96 
106  std::vector<std::vector<unsigned char> > receiver_chain::process_samples(std::vector<std::complex<double> > samples)
107  {
108  // samples -> sync short in
109  m_frame_detector->input_buffer.swap(samples);
110 
111  // Unlock the threads
112  for(int x = 0; x < m_wake_sems.size(); x++) sem_post(&m_wake_sems[x]);
113 
114  // Wait for the threads to finish
115  for(int x = 0; x < m_done_sems.size(); x++) sem_wait(&m_done_sems[x]);
116 
117  // Update the buffers
123 
124  // Return any completed packets
126  }
127 
128 }