Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / general / gr_fake_channel_coder_pp.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2005 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <gr_fake_channel_coder_pp.h>
28 #include <gr_io_signature.h>
29 #include <string.h>
30 #include <stdexcept>
31 #include <string.h>
32
33 static const int PAD_VAL = 0xAA;
34
35 gr_fake_channel_encoder_pp_sptr
36 gr_make_fake_channel_encoder_pp(int input_vlen, int output_vlen)
37 {
38   return gr_fake_channel_encoder_pp_sptr(new gr_fake_channel_encoder_pp(input_vlen,
39                                                                         output_vlen));
40 }
41
42 gr_fake_channel_encoder_pp::gr_fake_channel_encoder_pp(int input_vlen, int output_vlen)
43   : gr_sync_block("fake_channel_encoder_pp",
44                   gr_make_io_signature(1, 1, input_vlen * sizeof(unsigned char)),
45                   gr_make_io_signature(1, 1, output_vlen * sizeof(unsigned char))),
46     d_input_vlen(input_vlen), d_output_vlen(output_vlen)
47 {
48   if (input_vlen <= 0 || output_vlen <= 0 || input_vlen > output_vlen)
49     throw std::invalid_argument("gr_fake_channel_encoder_pp");
50 }
51
52 gr_fake_channel_encoder_pp::~gr_fake_channel_encoder_pp()
53 {
54 }
55
56 int
57 gr_fake_channel_encoder_pp::work (int noutput_items,
58                                   gr_vector_const_void_star &input_items,
59                                   gr_vector_void_star &output_items)
60 {
61   const unsigned char *in = (const unsigned char *) input_items[0];
62   unsigned char *out = (unsigned char *) output_items[0];
63   int   npad = d_output_vlen - d_input_vlen;
64   
65   for (int i = 0; i < noutput_items; i++){
66     memcpy(out, in, d_input_vlen);
67     memset(out + d_input_vlen, PAD_VAL, npad);
68     in += d_input_vlen;
69     out += d_output_vlen;
70   }
71
72   return noutput_items;
73 }
74
75 // ------------------------------------------------------------------------
76
77 gr_fake_channel_decoder_pp_sptr
78 gr_make_fake_channel_decoder_pp(int input_vlen, int output_vlen)
79 {
80   return gr_fake_channel_decoder_pp_sptr(new gr_fake_channel_decoder_pp(input_vlen,
81                                                                         output_vlen));
82 }
83
84 gr_fake_channel_decoder_pp::gr_fake_channel_decoder_pp(int input_vlen, int output_vlen)
85   : gr_sync_block("fake_channel_decoder_pp",
86                   gr_make_io_signature(1, 1, input_vlen * sizeof(unsigned char)),
87                   gr_make_io_signature(1, 1, output_vlen * sizeof(unsigned char))),
88     d_input_vlen(input_vlen), d_output_vlen(output_vlen)
89 {
90   if (input_vlen <= 0 || output_vlen <= 0 || output_vlen > input_vlen)
91     throw std::invalid_argument("gr_fake_channel_decoder_pp");
92 }
93
94 gr_fake_channel_decoder_pp::~gr_fake_channel_decoder_pp()
95 {
96 }
97
98 int
99 gr_fake_channel_decoder_pp::work (int noutput_items,
100                                   gr_vector_const_void_star &input_items,
101                                   gr_vector_void_star &output_items)
102 {
103   const unsigned char *in = (const unsigned char *) input_items[0];
104   unsigned char *out = (unsigned char *) output_items[0];
105   
106   for (int i = 0; i < noutput_items; i++){
107     memcpy(out, in, d_output_vlen);
108     in += d_input_vlen;
109     out += d_output_vlen;
110   }
111
112   return noutput_items;
113 }