fun_ofdm
1.0
802.11a Physical Layer for USRP
Main Page
Namespaces
Classes
Files
File List
File Members
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
{
29
receiver_chain::receiver_chain
()
30
{
31
m_frame_detector
=
new
frame_detector
();
32
m_timing_sync
=
new
timing_sync
();
33
m_fft_symbols
=
new
fft_symbols
();
34
m_channel_est
=
new
channel_est
();
35
m_phase_tracker
=
new
phase_tracker
();
36
m_frame_decoder
=
new
frame_decoder
();
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
45
add_block
(
m_frame_detector
);
46
add_block
(
m_timing_sync
);
47
add_block
(
m_fft_symbols
);
48
add_block
(
m_channel_est
);
49
add_block
(
m_phase_tracker
);
50
add_block
(
m_frame_decoder
);
51
}
52
58
void
receiver_chain::add_block
(
fun::block_base
*
block
)
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
78
void
receiver_chain::run_block
(
int
index,
fun::block_base
*
block
)
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
118
m_timing_sync
->
input_buffer
.swap(
m_frame_detector
->
output_buffer
);
119
m_fft_symbols
->
input_buffer
.swap(
m_timing_sync
->
output_buffer
);
120
m_channel_est
->
input_buffer
.swap(
m_fft_symbols
->
output_buffer
);
121
m_phase_tracker
->
input_buffer
.swap(
m_channel_est
->
output_buffer
);
122
m_frame_decoder
->
input_buffer
.swap(
m_phase_tracker
->
output_buffer
);
123
124
// Return any completed packets
125
return
m_frame_decoder
->
output_buffer
;
126
}
127
128
}
src
receiver_chain.cpp
Generated on Mon Oct 20 2014 10:26:27 for fun_ofdm by
1.8.4