Imported Upstream version 3.2.2
[debian/gnuradio] / gr-pager / src / pager_utils.py
1 #
2 # Copyright 2008,2009 Free Software Foundation, Inc.
3
4 # This file is part of GNU Radio
5
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
9 # any later version.
10
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #
20
21 from gnuradio import gr
22 import gnuradio.gr.gr_threading as _threading
23 from string import split, join, printable
24 import time
25
26 def make_trans_table():
27     table = 256 * ['.']
28     for i in range(256):
29         if (i < 32):
30             table[i] = '.'
31         else:
32             table[i] = chr(i)
33     return ''.join(table)
34
35 _trans_table = make_trans_table()
36
37 def make_printable(s):
38     return s.translate(_trans_table)
39
40
41 class queue_runner(_threading.Thread):
42     def __init__(self, msgq):
43         _threading.Thread.__init__(self)
44         self.msgq = msgq
45         self.done = False
46         self.start()
47
48     def run(self):
49         while 1:
50             msg = self.msgq.delete_head() # Blocking read
51             if msg.type() != 0:
52                 break
53             
54             page = join(split(msg.to_string(), chr(128)), '|')
55             s = make_printable(page)
56             print msg.type(), s
57                 
58     def end(self):
59         self.msgq.insert_tail(gr.message(1))
60         self.done = True