Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gr / qa_fsk_stuff.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2004 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 from gnuradio import gr, gr_unittest
24 import math
25
26 def sincos(x):
27     return  math.cos(x) + math.sin(x) * 1j
28
29 class test_bytes_to_syms (gr_unittest.TestCase):
30
31     def setUp (self):
32         self.fg = gr.flow_graph ()
33
34     def tearDown (self):
35         self.fg = None
36
37     def test_bytes_to_syms_001 (self):
38         src_data = (0x01, 0x80, 0x03)
39         expected_result = (-1, -1, -1, -1, -1, -1, -1, +1,
40                            +1, -1, -1, -1, -1, -1, -1, -1,
41                            -1, -1, -1, -1, -1, -1, +1, +1)
42         src = gr.vector_source_b (src_data)
43         op = gr.bytes_to_syms ()
44         dst = gr.vector_sink_f ()
45         self.fg.connect (src, op)
46         self.fg.connect (op, dst)
47         self.fg.run ()
48         result_data = dst.data ()
49         self.assertEqual (expected_result, result_data)
50
51     def test_simple_framer (self):
52         src_data = (0x00, 0x11, 0x22, 0x33, 
53                     0x44, 0x55, 0x66, 0x77,
54                     0x88, 0x99, 0xaa, 0xbb, 
55                     0xcc, 0xdd, 0xee, 0xff)
56
57         expected_result = (
58             0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x00, 0x00, 0x11, 0x22, 0x33, 0x55,
59             0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x01, 0x44, 0x55, 0x66, 0x77, 0x55,
60             0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x02, 0x88, 0x99, 0xaa, 0xbb, 0x55,
61             0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x03, 0xcc, 0xdd, 0xee, 0xff, 0x55)
62
63         src = gr.vector_source_b (src_data)
64         op = gr.simple_framer (4)
65         dst = gr.vector_sink_b ()
66         self.fg.connect (src, op)
67         self.fg.connect (op, dst)
68         self.fg.run ()
69         result_data = dst.data ()
70         self.assertEqual (expected_result, result_data)
71         
72
73 if __name__ == '__main__':
74     gr_unittest.main ()
75