Changeset 9514
- Timestamp:
- 09/06/08 22:13:30
- Files:
-
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/blks2/__init__.py (modified) (2 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/blks2/error_rate.py (modified) (8 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/blks2/packet.py (modified) (12 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/blks2/queue.py (modified) (11 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/blks2/selector.py (modified) (6 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/usrp/__init__.py (modified) (2 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/usrp/simple_usrp.py (modified) (27 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/wxgui/__init__.py (modified) (2 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/wxgui/callback_controls.py (modified) (16 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/wxgui/top_block_gui.py (modified) (6 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/ActionHandler.py (modified) (5 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Actions.py (modified) (2 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Bars.py (modified) (1 diff)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/BlockTreeWindow.py (modified) (8 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Constants.py (modified) (1 diff)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Dialogs.py (modified) (2 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/DrawingArea.py (modified) (6 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/FileDialogs.py (modified) (6 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/MainWindow.py (modified) (13 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Messages.py (modified) (8 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/NotebookPage.py (modified) (10 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/ParamsDialog.py (modified) (6 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Preferences.py (modified) (2 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/StateCache.py (modified) (6 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/base/Block.py (modified) (3 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/base/Connection.py (modified) (2 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/base/Constants.py.in (modified) (1 diff)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/base/Element.py (modified) (1 diff)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/base/FlowGraph.py (modified) (10 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/base/Param.py (modified) (2 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/base/Platform.py (modified) (4 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/base/Port.py (modified) (5 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/gui/Block.py (modified) (8 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/gui/Connection.py (modified) (3 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/gui/Constants.py (modified) (1 diff)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/gui/Element.py (modified) (17 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/gui/FlowGraph.py (modified) (27 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/gui/Param.py (modified) (6 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/gui/Platform.py (modified) (1 diff)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/gui/Port.py (modified) (11 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/gui/Utils.py (modified) (3 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/python/Block.py (modified) (3 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/python/Connection.py (modified) (1 diff)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/python/Constants.py.in (modified) (1 diff)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/python/FlowGraph.py (modified) (9 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/python/Generator.py (modified) (4 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/python/Param.py (modified) (5 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/python/Platform.py (modified) (3 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/python/Port.py (modified) (1 diff)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/python/utils/expr_utils.py (modified) (6 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/python/utils/extract_docs.py (modified) (3 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/utils/ParseXML.py (modified) (5 diffs)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/utils/__init__.py (modified) (1 diff)
- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/utils/converter.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/blks2/__init__.py
r9378 r9514 1 1 # Copyright 2008 Free Software Foundation, Inc. 2 # 2 # 3 3 # This file is part of GNU Radio 4 # 4 # 5 5 # GNU Radio is free software; you can redistribute it and/or modify 6 6 # it under the terms of the GNU General Public License as published by 7 7 # the Free Software Foundation; either version 3, or (at your option) 8 8 # any later version. 9 # 9 # 10 10 # GNU Radio is distributed in the hope that it will be useful, 11 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 # GNU General Public License for more details. 14 # 14 # 15 15 # You should have received a copy of the GNU General Public License 16 16 # along with GNU Radio; see the file COPYING. If not, write to 17 17 # the Free Software Foundation, Inc., 51 Franklin Street, 18 18 # Boston, MA 02110-1301, USA. 19 # 19 # 20 20 21 21 from queue import queue_sink_thread … … 26 26 from packet import packet_encoder, packet_decoder 27 27 from error_rate import error_rate 28 gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/blks2/error_rate.py
r9378 r9514 1 1 # Copyright 2008 Free Software Foundation, Inc. 2 # 2 # 3 3 # This file is part of GNU Radio 4 # 4 # 5 5 # GNU Radio is free software; you can redistribute it and/or modify 6 6 # it under the terms of the GNU General Public License as published by 7 7 # the Free Software Foundation; either version 3, or (at your option) 8 8 # any later version. 9 # 9 # 10 10 # GNU Radio is distributed in the hope that it will be useful, 11 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 # GNU General Public License for more details. 14 # 14 # 15 15 # You should have received a copy of the GNU General Public License 16 16 # along with GNU Radio; see the file COPYING. If not, write to 17 17 # the Free Software Foundation, Inc., 51 Franklin Street, 18 18 # Boston, MA 02110-1301, USA. 19 # 19 # 20 20 21 21 default_win_size = 1000 … … 32 32 Read samples from the message queue and hand them to the callback. 33 33 """ 34 34 35 35 def __init__(self, msgq, callback): 36 36 self._msgq = msgq … … 40 40 self.keep_running = True 41 41 self.start() 42 42 43 43 def run(self): 44 44 r = '' … … 50 50 i = (nitems-nitems%2)*itemsize 51 51 r = s[i:] 52 s = s[:i] 52 s = s[:i] 53 53 samples = numpy.fromstring(s, numpy.int8) 54 self._callback(samples) 55 54 self._callback(samples) 55 56 56 class error_rate(gr.hier_block2): 57 57 """ … … 59 59 Write the running rate to the output data stream (float). 60 60 """ 61 62 def __init__(self, type='BER', win_size=default_win_size, bits_per_symbol=2): 63 """ !61 62 def __init__(self, type='BER', win_size=default_win_size, bits_per_symbol=2): 63 """ 64 64 Error rate constructor. 65 65 @param type a string 'BER' or 'SER' 66 66 @param win_size the number of samples to calculate over 67 67 @param bits_per_symbol the number of information bits per symbol (BER only) 68 """ 68 """ 69 69 #init 70 70 gr.hier_block2.__init__( 71 self, 'error_rate', 72 gr.io_signature(2, 2, gr.sizeof_char), 71 self, 'error_rate', 72 gr.io_signature(2, 2, gr.sizeof_char), 73 73 gr.io_signature(1, 1, gr.sizeof_float), 74 74 ) … … 96 96 self.connect((self, 1), (inter, 1)) 97 97 self.connect(inter, msg_sink) 98 98 99 99 def _handler_ber(self, samples): 100 100 num = len(samples)/2 101 101 arr = numpy.zeros(num, numpy.float32) 102 102 for i in range(num): 103 old_err = self._err_array[self._err_index] 103 old_err = self._err_array[self._err_index] 104 104 #record error 105 105 self._err_array[self._err_index] = _1s_counts[samples[i*2] ^ samples[i*2 + 1]] … … 112 112 #write message 113 113 msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, num) 114 self._msgq_source.insert_tail(msg) 115 114 self._msgq_source.insert_tail(msg) 115 116 116 def _handler_ser(self, samples): 117 117 num = len(samples)/2 118 118 arr = numpy.zeros(num, numpy.float32) 119 119 for i in range(num): 120 old_err = self._err_array[self._err_index] 120 old_err = self._err_array[self._err_index] 121 121 #record error 122 122 ref = samples[i*2] … … 135 135 #write message 136 136 msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, num) 137 self._msgq_source.insert_tail(msg) 138 137 self._msgq_source.insert_tail(msg) gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/blks2/packet.py
r9378 r9514 1 1 # Copyright 2008 Free Software Foundation, Inc. 2 # 2 # 3 3 # This file is part of GNU Radio 4 # 4 # 5 5 # GNU Radio is free software; you can redistribute it and/or modify 6 6 # it under the terms of the GNU General Public License as published by 7 7 # the Free Software Foundation; either version 3, or (at your option) 8 8 # any later version. 9 # 9 # 10 10 # GNU Radio is distributed in the hope that it will be useful, 11 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 # GNU General Public License for more details. 14 # 14 # 15 15 # You should have received a copy of the GNU General Public License 16 16 # along with GNU Radio; see the file COPYING. If not, write to 17 17 # the Free Software Foundation, Inc., 51 Franklin Street, 18 18 # Boston, MA 02110-1301, USA. 19 # 19 # 20 20 21 21 from gnuradio import gr, packet_utils … … 32 32 33 33 ####################################################################################### 34 ## Packet Encoder34 ## Packet Encoder 35 35 ####################################################################################### 36 36 37 37 class _packet_encoder_thread(_threading.Thread): 38 38 39 39 def __init__(self, msgq, payload_length, send): 40 40 self._msgq = msgq … … 45 45 self.keep_running = True 46 46 self.start() 47 47 48 48 def run(self): 49 49 sample = '' #residual sample 50 50 while self.keep_running: 51 51 msg = self._msgq.delete_head() #blocking read of message queue 52 sample = sample + msg.to_string() #get the body of the msg as a string 53 while len(sample) >= self._payload_length: 52 sample = sample + msg.to_string() #get the body of the msg as a string 53 while len(sample) >= self._payload_length: 54 54 payload = sample[0:self._payload_length] 55 sample = sample[self._payload_length:] 56 self._send(payload) 55 sample = sample[self._payload_length:] 56 self._send(payload) 57 57 58 58 class packet_encoder(gr.hier_block2): … … 60 60 Hierarchical block for wrapping packet-based modulators. 61 61 """ 62 62 63 63 def __init__(self, item_size_in, samples_per_symbol, bits_per_symbol, access_code='', pad_for_usrp=True, payload_length=-1): 64 """ !64 """ 65 65 packet_mod constructor. 66 66 @param item_size_in the size of the input data stream in bytes … … 80 80 if not packet_utils.is_1_0_string(access_code): 81 81 raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,) 82 self._access_code = access_code 83 self._pad_for_usrp = pad_for_usrp 82 self._access_code = access_code 83 self._pad_for_usrp = pad_for_usrp 84 84 if payload_length < 0: #get payload length 85 85 payload_length = DEFAULT_PAYLOAD_LEN … … 89 89 #create blocks 90 90 msg_source = gr.message_source(gr.sizeof_char, DEFAULT_MSGQ_LIMIT) 91 self._msgq_out = msg_source.msgq() 91 self._msgq_out = msg_source.msgq() 92 92 self._msgq_in = gr.msg_queue(DEFAULT_MSGQ_LIMIT) 93 msg_sink = gr.message_sink(self._item_size_in, self._msgq_in, False) #False -> blocking 93 msg_sink = gr.message_sink(self._item_size_in, self._msgq_in, False) #False -> blocking 94 94 #initialize hier2 95 95 gr.hier_block2.__init__( 96 self, 96 self, 97 97 "packet_encoder", 98 98 gr.io_signature(1, 1, self._item_size_in), # Input signature … … 104 104 #start thread 105 105 _packet_encoder_thread(self._msgq_in, self._payload_length, self._send_packet) 106 106 107 107 def _send_packet(self, payload): 108 """ !108 """ 109 109 Wrap the payload in a packet and push onto the message queue. 110 110 @param payload string, data to send 111 """ 111 """ 112 112 packet = packet_utils.make_packet( 113 113 payload, … … 119 119 msg = gr.message_from_string(packet) 120 120 self._msgq_out.insert_tail(msg) 121 121 122 122 ####################################################################################### 123 ## Packet Decoder123 ## Packet Decoder 124 124 ####################################################################################### 125 125 126 126 class _packet_decoder_thread(_threading.Thread): 127 127 128 128 def __init__(self, msgq, callback): 129 129 _threading.Thread.__init__(self) … … 145 145 Hierarchical block for wrapping packet-based demodulators. 146 146 """ 147 147 148 148 def __init__(self, item_size_out, access_code='', threshold=-1): 149 """ !149 """ 150 150 packet_demod constructor. 151 151 @param item_size_out the size of the output data stream in bytes … … 160 160 if not packet_utils.is_1_0_string(access_code): 161 161 raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,) 162 self._access_code = access_code 162 self._access_code = access_code 163 163 #threshold 164 if threshold < 0: threshold = DEFAULT_THRESHOLD 165 self._threshold = threshold 164 if threshold < 0: threshold = DEFAULT_THRESHOLD 165 self._threshold = threshold 166 166 #blocks 167 167 self._msgq_in = gr.msg_queue(DEFAULT_MSGQ_LIMIT) #holds packets from the PHY 168 168 correlator = gr.correlate_access_code_bb(self._access_code, self._threshold) 169 framer_sink = gr.framer_sink_1(self._msgq_in) 169 framer_sink = gr.framer_sink_1(self._msgq_in) 170 170 msg_source = gr.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT) 171 self._msgq_out = msg_source.msgq() 171 self._msgq_out = msg_source.msgq() 172 172 #initialize hier2 173 173 gr.hier_block2.__init__( 174 self, 174 self, 175 175 "packet_decoder", 176 176 gr.io_signature(1, 1, gr.sizeof_char), # Input signature … … 184 184 185 185 def _recv_packet(self, ok, payload): 186 """ !186 """ 187 187 Extract the payload from the packet and push onto message queue. 188 188 @param ok boolean ok … … 190 190 """ 191 191 msg = gr.message_from_string(payload, 0, self._item_size_out, len(payload)/self._item_size_out) 192 if ok: self._msgq_out.insert_tail(msg) 193 194 192 if ok: self._msgq_out.insert_tail(msg) gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/blks2/queue.py
r9378 r9514 1 1 # Copyright 2008 Free Software Foundation, Inc. 2 # 2 # 3 3 # This file is part of GNU Radio 4 # 4 # 5 5 # GNU Radio is free software; you can redistribute it and/or modify 6 6 # it under the terms of the GNU General Public License as published by 7 7 # the Free Software Foundation; either version 3, or (at your option) 8 8 # any later version. 9 # 9 # 10 10 # GNU Radio is distributed in the hope that it will be useful, 11 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 # GNU General Public License for more details. 14 # 14 # 15 15 # You should have received a copy of the GNU General Public License 16 16 # along with GNU Radio; see the file COPYING. If not, write to 17 17 # the Free Software Foundation, Inc., 51 Franklin Street, 18 18 # Boston, MA 02110-1301, USA. 19 # 19 # 20 20 21 21 from gnuradio import gr … … 24 24 25 25 ####################################################################################### 26 ## Queue Sink Thread26 ## Queue Sink Thread 27 27 ####################################################################################### 28 28 class queue_sink_thread(_threading.Thread): 29 """ !29 """ 30 30 Read samples from the queue sink and execute the callback. 31 31 """ 32 32 33 33 def __init__(self, queue_sink, callback): 34 """ !34 """ 35 35 Queue sink thread contructor. 36 36 @param queue_sink the queue to pop messages from … … 43 43 self.keep_running = True 44 44 self.start() 45 45 46 46 def run(self): 47 47 while self.keep_running: … … 49 49 50 50 ####################################################################################### 51 ## Queue Sink51 ## Queue Sink 52 52 ####################################################################################### 53 53 class _queue_sink_base(gr.hier_block2): 54 """ !54 """ 55 55 Queue sink base, a queue sink for any size queue. 56 56 Easy read access to a gnuradio data stream from python. … … 58 58 Samples are cast as python data types, complex, float, or int. 59 59 """ 60 60 61 61 def __init__(self, vlen=1): 62 """ !62 """ 63 63 Queue sink base contructor. 64 64 @param vlen the vector length … … 67 67 #initialize hier2 68 68 gr.hier_block2.__init__( 69 self, 69 self, 70 70 "queue_sink", 71 71 gr.io_signature(1, 1, self._item_size*self._vlen), # Input signature … … 78 78 self.connect(self, message_sink) 79 79 self.arr = '' 80 80 81 81 def pop(self): 82 """ !82 """ 83 83 Pop a new sample off the front of the queue. 84 84 @return a new sample … … 96 96 _item_size = gr.sizeof_gr_complex 97 97 _numpy = numpy.complex64 98 def _cast(self, arg): return complex(arg.real, arg.imag) 99 98 def _cast(self, arg): return complex(arg.real, arg.imag) 99 100 100 class queue_sink_f(_queue_sink_base): 101 101 _item_size = gr.sizeof_float 102 102 _numpy = numpy.float32 103 103 _cast = float 104 104 105 105 class queue_sink_i(_queue_sink_base): 106 106 _item_size = gr.sizeof_int 107 107 _numpy = numpy.int32 108 108 _cast = int 109 109 110 110 class queue_sink_s(_queue_sink_base): 111 111 _item_size = gr.sizeof_short 112 112 _numpy = numpy.int16 113 113 _cast = int 114 114 115 115 class queue_sink_b(_queue_sink_base): 116 116 _item_size = gr.sizeof_char 117 117 _numpy = numpy.int8 118 118 _cast = int 119 119 120 120 ####################################################################################### 121 ## Queue Source121 ## Queue Source 122 122 ####################################################################################### 123 123 class _queue_source_base(gr.hier_block2): 124 """ !124 """ 125 125 Queue source base, a queue source for any size queue. 126 126 Easy write access to a gnuradio data stream from python. 127 127 Call push to to write a sample into the gnuradio data stream. 128 128 """ 129 129 130 130 def __init__(self, vlen=1): 131 """ !131 """ 132 132 Queue source base contructor. 133 133 @param vlen the vector length … … 136 136 #initialize hier2 137 137 gr.hier_block2.__init__( 138 self, 138 self, 139 139 "queue_source", 140 140 gr.io_signature(0, 0, 0), # Input signature … … 142 142 ) 143 143 #create message sink 144 message_source = gr.message_source(self._item_size*self._vlen, 1) 144 message_source = gr.message_source(self._item_size*self._vlen, 1) 145 145 self._msgq = message_source.msgq() 146 146 #connect 147 147 self.connect(message_source, self) 148 148 149 149 def push(self, item): 150 """ !150 """ 151 151 Push an item into the back of the queue. 152 152 @param item the item … … 160 160 _item_size = gr.sizeof_gr_complex 161 161 _numpy = numpy.complex64 162 162 163 163 class queue_source_f(_queue_source_base): 164 164 _item_size = gr.sizeof_float 165 165 _numpy = numpy.float32 166 166 167 167 class queue_source_i(_queue_source_base): 168 168 _item_size = gr.sizeof_int 169 169 _numpy = numpy.int32 170 170 171 171 class queue_source_s(_queue_source_base): 172 172 _item_size = gr.sizeof_short 173 173 _numpy = numpy.int16 174 174 175 175 class queue_source_b(_queue_source_base): 176 176 _item_size = gr.sizeof_char 177 177 _numpy = numpy.int8 178 gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/blks2/selector.py
r9378 r9514 2 2 # 3 3 # Copyright 2008 Free Software Foundation, Inc. 4 # 4 # 5 5 # This file is part of GNU Radio 6 # 6 # 7 7 # GNU Radio is free software; you can redistribute it and/or modify 8 8 # it under the terms of the GNU General Public License as published by 9 9 # the Free Software Foundation; either version 3, or (at your option) 10 10 # any later version. 11 # 11 # 12 12 # GNU Radio is distributed in the hope that it will be useful, 13 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 # GNU General Public License for more details. 16 # 16 # 17 17 # You should have received a copy of the GNU General Public License 18 18 # along with GNU Radio; see the file COPYING. If not, write to 19 19 # the Free Software Foundation, Inc., 51 Franklin Street, 20 20 # Boston, MA 02110-1301, USA. 21 # 21 # 22 22 23 23 from gnuradio import gr 24 24 25 25 class selector(gr.hier_block2): 26 26 """A hier2 block with N inputs and M outputs, where data is only forwarded through input n to output m.""" 27 def __init__(self, item_size, num_inputs, num_outputs, input_index, output_index): 28 """ !27 def __init__(self, item_size, num_inputs, num_outputs, input_index, output_index): 28 """ 29 29 SelectorHelper constructor. 30 30 @param item_size the size of the gr data stream in bytes … … 33 33 @param input_index the index for the source data 34 34 @param output_index the index for the destination data 35 """ 35 """ 36 36 gr.hier_block2.__init__( 37 self, 'selector', 38 gr.io_signature(num_inputs, num_inputs, item_size), 37 self, 'selector', 38 gr.io_signature(num_inputs, num_inputs, item_size), 39 39 gr.io_signature(num_outputs, num_outputs, item_size), 40 40 ) 41 #terminator blocks for unused inputs and outputs 41 #terminator blocks for unused inputs and outputs 42 42 self.input_terminators = [gr.null_sink(item_size)] * num_inputs 43 43 self.output_terminators = [gr.head(item_size, 0)] * num_outputs 44 44 self.copy = None 45 #connections 45 #connections 46 46 for i in range(num_inputs): self.connect((self, i), self.input_terminators[i]) 47 for i in range(num_outputs): self.connect(gr.null_source(item_size), self.output_terminators[i], (self, i)) 48 self.item_size = item_size 47 for i in range(num_outputs): self.connect(gr.null_source(item_size), self.output_terminators[i], (self, i)) 48 self.item_size = item_size 49 49 self.input_index = input_index 50 self.output_index = output_index 50 self.output_index = output_index 51 51 self.num_inputs = num_inputs 52 52 self.num_outputs = num_outputs 53 53 self._connect_current() 54 54 55 55 def _indexes_valid(self): 56 """ !56 """ 57 57 Are the input and output indexes within range of the number of inputs and outputs? 58 58 @return true if input index and output index are in range 59 59 """ 60 60 return self.input_index in range(self.num_inputs) and self.output_index in range(self.num_outputs) 61 61 62 62 def _connect_current(self): 63 """If the input and output indexes are valid: 64 disconnect the blocks at the input and output index from their terminators, 63 """If the input and output indexes are valid: 64 disconnect the blocks at the input and output index from their terminators, 65 65 and connect them to one another. Then connect the terminators to one another.""" 66 66 if self._indexes_valid(): 67 self.disconnect((self, self.input_index), self.input_terminators[self.input_index]) 67 self.disconnect((self, self.input_index), self.input_terminators[self.input_index]) 68 68 self.disconnect(self.output_terminators[self.output_index], (self, self.output_index)) 69 69 self.copy = gr.skiphead(self.item_size, 0) 70 70 self.connect((self, self.input_index), self.copy) 71 self.connect(self.copy, (self, self.output_index)) 72 self.connect(self.output_terminators[self.output_index], self.input_terminators[self.input_index]) 73 71 self.connect(self.copy, (self, self.output_index)) 72 self.connect(self.output_terminators[self.output_index], self.input_terminators[self.input_index]) 73 74 74 def _disconnect_current(self): 75 """If the input and output indexes are valid: 76 disconnect the blocks at the input and output index from one another, 75 """If the input and output indexes are valid: 76 disconnect the blocks at the input and output index from one another, 77 77 and the terminators at the input and output index from one another. 78 78 Reconnect the blocks to the terminators.""" … … 81 81 self.disconnect(self.copy, (self, self.output_index)) 82 82 self.disconnect(self.output_terminators[self.output_index], self.input_terminators[self.input_index]) 83 del self.copy 84 self.copy = None 83 del self.copy 84 self.copy = None 85 85 self.connect((self, self.input_index), self.input_terminators[self.input_index]) 86 86 self.connect(self.output_terminators[self.output_index], (self, self.output_index)) 87 87 88 88 def set_input_index(self, input_index): 89 """ !89 """ 90 90 Change the block to the new input index if the index changed. 91 91 @param input_index the new input index … … 96 96 self.input_index = input_index 97 97 self._connect_current() 98 self.unlock() 99 98 self.unlock() 99 100 100 def set_output_index(self, output_index): 101 """ !101 """ 102 102 Change the block to the new output index if the index changed. 103 103 @param output_index the new output index 104 """ 105 if self.output_index != output_index: 104 """ 105 if self.output_index != output_index: 106 106 self.lock() 107 107 self._disconnect_current() 108 108 self.output_index = output_index 109 self._connect_current() 110 self.unlock() 109 self._connect_current() 110 self.unlock() 111 111 112 112 class valve(selector): 113 113 """Wrapper for selector with 1 input and 1 output.""" 114 114 115 115 def __init__(self, item_size, open): 116 """ !116 """ 117 117 Constructor for valve. 118 118 @param item_size the size of the gr data stream in bytes … … 122 122 else: output_index = 0 123 123 selector.__init__(self, item_size, 1, 1, 0, output_index) 124 124 125 125 def set_open(self, open): 126 """ !126 """ 127 127 Callback to set open state. 128 128 @param open true to set valve state to open … … 131 131 else: output_index = 0 132 132 self.set_output_index(output_index) 133 gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc_gnuradio/usrp/__init__.py
r9378 r9514 1 1 # Copyright 2008 Free Software Foundation, Inc. 2 # 2 # 3 3 # This file is part of GNU Radio 4 # 4 # 5 5 # GNU Radio is free software; you can redistribute it and/or modify 6 6 # it under the terms of the GNU General Public License as published by 7 7 # the Free Software
