fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
frame_decoder.cpp
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <cstring>
10 #include <arpa/inet.h>
11 #include <boost/crc.hpp>
12 
13 #include "frame_decoder.h"
14 #include "qam.h"
15 #include "interleaver.h"
16 #include "viterbi.h"
17 #include "parity.h"
18 #include "rates.h"
19 #include "modulator.h"
20 #include "puncturer.h"
21 #include "interleaver.h"
22 #include "ppdu.h"
23 
24 namespace fun
25 {
31  block("frame_decoder"),
32  m_current_frame(FrameData(RateParams(RATE_1_2_BPSK)))
33  {
35  }
36 
46  {
47  if(input_buffer.size() == 0) return;
48  output_buffer.resize(0);
49 
50  // Step through each 48 sample symbol
51  for(int x = 0; x < input_buffer.size(); x++)
52  {
53  // Copy over available symbols
55  {
56  memcpy(&m_current_frame.samples[m_current_frame.samples_copied], &input_buffer[x].samples[0], 48 * sizeof(std::complex<double>));
58  }
59 
60  // Decode the frame if possible
62  {
65  {
66  output_buffer.push_back(frame.get_payload());
67  }
69  }
70 
71  // Look for a start of frame
72  if(input_buffer[x].tag == START_OF_FRAME)
73  {
74  // Attempt to decode the header
75  ppdu h = ppdu();
76  std::vector<std::complex<double> > header_samples(48);
77  memcpy(header_samples.data(), input_buffer[x].samples, 48 * sizeof(std::complex<double>));
78  if(!h.decode_header(header_samples)) continue;
79 
80  // Calculate the frame sample count
81  int length = h.get_length();
82  RateParams rate_params = RateParams(h.get_rate());
83  int frame_sample_count = h.get_num_symbols() * 48;
84 
85  // Start a new frame
86  m_current_frame.Reset(rate_params, frame_sample_count, length);
87  m_current_frame.samples.resize(h.get_num_symbols() * 48);
88  continue;
89  }
90  }
91  }
92 }
93 
94