3 * Copyright 2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
27 #include <gr_simple_framer.h>
28 #include <gr_simple_framer_sync.h>
29 #include <gr_io_signature.h>
36 gr_make_simple_framer (int payload_bytesize)
38 return gr_simple_framer_sptr (new gr_simple_framer (payload_bytesize));
41 gr_simple_framer::gr_simple_framer (int payload_bytesize)
42 : gr_block ("simple_framer",
43 gr_make_io_signature (1, 1, sizeof (unsigned char)),
44 gr_make_io_signature (1, 1, sizeof (unsigned char))),
45 d_seqno (0), d_payload_bytesize (payload_bytesize),
46 d_input_block_size (payload_bytesize),
47 d_output_block_size (payload_bytesize + GRSF_OVERHEAD)
49 set_output_multiple (d_output_block_size);
53 gr_simple_framer::forecast (int noutput_items, gr_vector_int &ninput_items_required)
55 assert (noutput_items % d_output_block_size == 0);
57 int nblocks = noutput_items / d_output_block_size;
58 int input_required = nblocks * d_input_block_size;
60 unsigned ninputs = ninput_items_required.size();
61 for (unsigned int i = 0; i < ninputs; i++)
62 ninput_items_required[i] = input_required;
66 gr_simple_framer::general_work (int noutput_items,
67 gr_vector_int &ninput_items,
68 gr_vector_const_void_star &input_items,
69 gr_vector_void_star &output_items)
71 const unsigned char *in = (const unsigned char *) input_items[0];
72 unsigned char *out = (unsigned char *) output_items[0];
77 memset (out, 0x55, noutput_items);
79 while (n < noutput_items){
80 out[0] = (GRSF_SYNC >> 56) & 0xff;
81 out[1] = (GRSF_SYNC >> 48) & 0xff;
82 out[2] = (GRSF_SYNC >> 40) & 0xff;
83 out[3] = (GRSF_SYNC >> 32) & 0xff;
84 out[4] = (GRSF_SYNC >> 24) & 0xff;
85 out[5] = (GRSF_SYNC >> 16) & 0xff;
86 out[6] = (GRSF_SYNC >> 8) & 0xff;
87 out[7] = (GRSF_SYNC >> 0) & 0xff;
90 memcpy (&out[9], in, d_input_block_size);
91 in += d_input_block_size;
92 out += d_output_block_size;
93 n += d_output_block_size;
97 assert (n == noutput_items);
99 consume_each (nblocks * d_input_block_size);