Imported Upstream version 3.0
[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 2, 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
32 static const int PAD_VAL = 0xAA;
33
34 gr_fake_channel_encoder_pp_sptr
35 gr_make_fake_channel_encoder_pp(int input_vlen, int output_vlen)
36 {
37   return gr_fake_channel_encoder_pp_sptr(new gr_fake_channel_encoder_pp(input_vlen,
38                                                                         output_vlen));
39 }
40
41 gr_fake_channel_encoder_pp::gr_fake_channel_encoder_pp(int input_vlen, int output_vlen)
42   : gr_sync_block("fake_channel_encoder_pp",
43                   gr_make_io_signature(1, 1, input_vlen * sizeof(unsigned char)),
44                   gr_make_io_signature(1, 1, output_vlen * sizeof(unsigned char))),
45     d_input_vlen(input_vlen), d_output_vlen(output_vlen)
46 {
47   if (input_vlen <= 0 || output_vlen <= 0 || input_vlen > output_vlen)
48     throw std::invalid_argument("gr_fake_channel_encoder_pp");
49 }
50
51 gr_fake_channel_encoder_pp::~gr_fake_channel_encoder_pp()
52 {
53 }
54
55 int
56 gr_fake_channel_encoder_pp::work (int noutput_items,
57                                   gr_vector_const_void_star &input_items,
58                                   gr_vector_void_star &output_items)
59 {
60   const unsigned char *in = (const unsigned char *) input_items[0];
61   unsigned char *out = (unsigned char *) output_items[0];
62   int   npad = d_output_vlen - d_input_vlen;
63   
64   for (int i = 0; i < noutput_items; i++){
65     memcpy(out, in, d_input_vlen);
66     memset(out + d_input_vlen, PAD_VAL, npad);
67     in += d_input_vlen;
68     out += d_output_vlen;
69   }
70
71   return noutput_items;
72 }
73
74 // ------------------------------------------------------------------------
75
76 gr_fake_channel_decoder_pp_sptr
77 gr_make_fake_channel_decoder_pp(int input_vlen, int output_vlen)
78 {
79   return gr_fake_channel_decoder_pp_sptr(new gr_fake_channel_decoder_pp(input_vlen,
80                                                                         output_vlen));
81 }
82
83 gr_fake_channel_decoder_pp::gr_fake_channel_decoder_pp(int input_vlen, int output_vlen)
84   : gr_sync_block("fake_channel_decoder_pp",
85                   gr_make_io_signature(1, 1, input_vlen * sizeof(unsigned char)),
86                   gr_make_io_signature(1, 1, output_vlen * sizeof(unsigned char))),
87     d_input_vlen(input_vlen), d_output_vlen(output_vlen)
88 {
89   if (input_vlen <= 0 || output_vlen <= 0 || output_vlen > input_vlen)
90     throw std::invalid_argument("gr_fake_channel_decoder_pp");
91 }
92
93 gr_fake_channel_decoder_pp::~gr_fake_channel_decoder_pp()
94 {
95 }
96
97 int
98 gr_fake_channel_decoder_pp::work (int noutput_items,
99                                   gr_vector_const_void_star &input_items,
100                                   gr_vector_void_star &output_items)
101 {
102   const unsigned char *in = (const unsigned char *) input_items[0];
103   unsigned char *out = (unsigned char *) output_items[0];
104   
105   for (int i = 0; i < noutput_items; i++){
106     memcpy(out, in, d_output_vlen);
107     in += d_input_vlen;
108     out += d_output_vlen;
109   }
110
111   return noutput_items;
112 }