summaryrefslogtreecommitdiff
path: root/gr-digital/lib/packet_header_ofdm.cc
blob: db190c13bb45f2ee6523b6427da90b5e4847f603 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* -*- c++ -*- */
/* Copyright 2012 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <digital/packet_header_ofdm.h>

namespace gr {
  namespace digital {

    int _get_header_len_from_occupied_carriers(const std::vector<std::vector<int> > &occupied_carriers, int n_syms)
    {
      int header_len = 0;
      for (int i = 0; i < n_syms; i++) {
	header_len += occupied_carriers[i].size();
      }

      return header_len;
    }

    packet_header_ofdm::sptr
    packet_header_ofdm::make(
		      const std::vector<std::vector<int> > &occupied_carriers,
		      int n_syms,
		      const std::string &len_tag_key,
		      const std::string &frame_len_tag_key,
		      const std::string &num_tag_key,
		      int bits_per_sym)
    {
      return packet_header_ofdm::sptr(
	  new packet_header_ofdm(
	    occupied_carriers, n_syms, len_tag_key, frame_len_tag_key, num_tag_key, bits_per_sym
	  )
      );
    }

    packet_header_ofdm::packet_header_ofdm(
		    const std::vector<std::vector<int> > &occupied_carriers,
		    int n_syms,
		    const std::string &len_tag_key,
		    const std::string &frame_len_tag_key,
		    const std::string &num_tag_key,
		    int bits_per_sym)
      : packet_header_default(
	  _get_header_len_from_occupied_carriers(occupied_carriers, n_syms),
	  len_tag_key,
	  num_tag_key,
	  bits_per_sym),
      d_frame_len_tag_key(pmt::pmt_string_to_symbol(frame_len_tag_key)),
      d_occupied_carriers(occupied_carriers),
      d_syms_per_set(0)
    {
      for (unsigned i = 0; i < d_occupied_carriers.size(); i++) {
	d_syms_per_set += d_occupied_carriers[i].size();
      }
    }

    packet_header_ofdm::~packet_header_ofdm()
    {
    }


    bool packet_header_ofdm::header_parser(
	const unsigned char *in,
	std::vector<gr_tag_t> &tags)
    {
      if (!packet_header_default::header_parser(in, tags)) {
	return false;
      }
      int packet_len = 0; // # of OFDM symbols
      for (unsigned i = 0; i < tags.size(); i++) {
	if (pmt::pmt_equal(tags[i].key, d_len_tag_key)) {
	  packet_len = pmt::pmt_to_long(tags[i].value);
	  break;
	}
      }

      int frame_len = packet_len / d_syms_per_set;
      int k = 0;
      int i = frame_len * d_syms_per_set;
      while (i < packet_len) {
	frame_len++;
	i += d_occupied_carriers[k].size();
      }
      gr_tag_t tag;
      tag.key = d_frame_len_tag_key;
      tag.value = pmt::pmt_from_long(frame_len);
      tags.push_back(tag);

      return true;
    }

  } /* namespace digital */
} /* namespace gr */