Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / general / gr_decode_ccsds_27_fb.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  * 
5  * GNU Radio is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3, or (at your option)
8  * any later version.
9  * 
10  * GNU Radio is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with GNU Radio; see the file COPYING.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <gr_decode_ccsds_27_fb.h>
26 #include <gr_io_signature.h>
27
28 gr_decode_ccsds_27_fb_sptr 
29 gr_make_decode_ccsds_27_fb()
30 {
31   return gr_decode_ccsds_27_fb_sptr(new gr_decode_ccsds_27_fb());
32 }
33
34 gr_decode_ccsds_27_fb::gr_decode_ccsds_27_fb()
35   : gr_sync_decimator("decode_ccsds_27_fb",
36                       gr_make_io_signature(1, 1, sizeof(float)),
37                       gr_make_io_signature(1, 1, sizeof(char)),
38                       2*8)  // Rate 1/2 code, unpacked to packed translation
39 {
40     float RATE = 0.5;
41     float ebn0 = 12.0;
42     float esn0 = RATE*pow(10.0, ebn0/10);
43
44     gen_met(d_mettab, 100, esn0, 0.0, 256);
45     viterbi_chunks_init(d_state0);
46 }
47
48 gr_decode_ccsds_27_fb::~gr_decode_ccsds_27_fb()
49 {
50 }
51
52 int 
53 gr_decode_ccsds_27_fb::work(int noutput_items,
54                             gr_vector_const_void_star &input_items,
55                             gr_vector_void_star &output_items)
56 {
57   const float *in = (const float *)input_items[0];
58   unsigned char *out = (unsigned char *)output_items[0];
59
60   for (int i = 0; i < noutput_items*16; i++) {
61     // Translate and clip [-1.0..1.0] to [28..228]
62     float sample = in[i]*100.0+128.0;
63     if (sample > 255.0)
64         sample = 255.0;
65     else if (sample < 0.0)
66         sample = 0.0;
67     unsigned char sym = (unsigned char)(floor(sample));
68     
69     d_viterbi_in[d_count % 4] = sym;
70     if ((d_count % 4) == 3) {
71       // Every fourth symbol, perform butterfly operation
72       viterbi_butterfly2(d_viterbi_in, d_mettab, d_state0, d_state1);
73       
74       // Every sixteenth symbol, read out a byte
75       if (d_count % 16 == 11) {
76         // long metric = 
77         viterbi_get_output(d_state0, out++);
78         // printf("%li\n", *(out-1), metric);
79       }
80     }
81     
82     d_count++;
83   }
84
85   return noutput_items;
86 }