diff options
author | jblum | 2009-03-12 06:53:54 +0000 |
---|---|---|
committer | jblum | 2009-03-12 06:53:54 +0000 |
commit | 2c4a4e0c371b1cd0029901aa176915300a02f1b8 (patch) | |
tree | e251c87a4929b49e1695f4abb57dbbe1e1b0a000 /grc/src/grc_gnuradio | |
parent | 48ecbf1162f9031ab7134bbb571efc345bc8d7bd (diff) | |
download | gnuradio-2c4a4e0c371b1cd0029901aa176915300a02f1b8.tar.gz gnuradio-2c4a4e0c371b1cd0029901aa176915300a02f1b8.tar.bz2 gnuradio-2c4a4e0c371b1cd0029901aa176915300a02f1b8.zip |
Added OFDM Mod and Demod to GRC (cough cough... kludge).
Generalized the packet mod and demod stuff to accept the OFDM blocks.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10585 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/src/grc_gnuradio')
-rw-r--r-- | grc/src/grc_gnuradio/blks2/__init__.py | 6 | ||||
-rw-r--r-- | grc/src/grc_gnuradio/blks2/packet.py | 161 |
2 files changed, 110 insertions, 57 deletions
diff --git a/grc/src/grc_gnuradio/blks2/__init__.py b/grc/src/grc_gnuradio/blks2/__init__.py index 1705a3f9b..185230ab0 100644 --- a/grc/src/grc_gnuradio/blks2/__init__.py +++ b/grc/src/grc_gnuradio/blks2/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2008 Free Software Foundation, Inc. +# Copyright 2008, 2009 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -19,6 +19,8 @@ # from selector import selector, valve -from packet import packet_encoder, packet_decoder +from packet import options, packet_encoder, packet_decoder, \ + packet_mod_b, packet_mod_s, packet_mod_i, packet_mod_f, packet_mod_c, \ + packet_demod_b, packet_demod_s, packet_demod_i, packet_demod_f, packet_demod_c from error_rate import error_rate from probe import probe_function, probe_avg_mag_sqrd_c, probe_avg_mag_sqrd_f, probe_density_b, probe_mpsk_snr_c diff --git a/grc/src/grc_gnuradio/blks2/packet.py b/grc/src/grc_gnuradio/blks2/packet.py index fcdfb9ae2..a305b961e 100644 --- a/grc/src/grc_gnuradio/blks2/packet.py +++ b/grc/src/grc_gnuradio/blks2/packet.py @@ -1,4 +1,4 @@ -# Copyright 2008 Free Software Foundation, Inc. +# Copyright 2008, 2009 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -30,10 +30,16 @@ DEFAULT_MSGQ_LIMIT = 2 ##threshold for unmaking packets DEFAULT_THRESHOLD = 12 -####################################################################################### -## Packet Encoder -####################################################################################### +################################################## +## Options Class for OFDM +################################################## +class options(object): + def __init__(self, **kwargs): + for key, value in kwargs.iteritems(): setattr(self, key, value) +################################################## +## Packet Encoder +################################################## class _packet_encoder_thread(_threading.Thread): def __init__(self, msgq, payload_length, send): @@ -51,7 +57,7 @@ class _packet_encoder_thread(_threading.Thread): msg = self._msgq.delete_head() #blocking read of message queue sample = sample + msg.to_string() #get the body of the msg as a string while len(sample) >= self._payload_length: - payload = sample[0:self._payload_length] + payload = sample[:self._payload_length] sample = sample[self._payload_length:] self._send(payload) @@ -60,10 +66,9 @@ class packet_encoder(gr.hier_block2): Hierarchical block for wrapping packet-based modulators. """ - def __init__(self, item_size_in, samples_per_symbol, bits_per_symbol, access_code='', pad_for_usrp=True, payload_length=-1): + def __init__(self, samples_per_symbol, bits_per_symbol, access_code='', pad_for_usrp=True): """ packet_mod constructor. - @param item_size_in the size of the input data stream in bytes @param samples_per_symbol number of samples per symbol @param bits_per_symbol number of bits per symbol @param access_code AKA sync vector @@ -71,7 +76,6 @@ class packet_encoder(gr.hier_block2): @param payload_length number of bytes in a data-stream slice """ #setup parameters - self._item_size_in = item_size_in self._samples_per_symbol = samples_per_symbol self._bits_per_symbol = bits_per_symbol self._pad_for_usrp = pad_for_usrp @@ -81,30 +85,20 @@ class packet_encoder(gr.hier_block2): raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,) self._access_code = access_code self._pad_for_usrp = pad_for_usrp - if payload_length < 0: #get payload length - payload_length = DEFAULT_PAYLOAD_LEN - if payload_length%self._item_size_in != 0: #verify that packet length is a multiple of the stream size - raise ValueError, 'The packet length: "%d" is not a mutiple of the stream size: "%d".'%(payload_length, self._item_size_in) - self._payload_length = payload_length #create blocks msg_source = gr.message_source(gr.sizeof_char, DEFAULT_MSGQ_LIMIT) self._msgq_out = msg_source.msgq() - self._msgq_in = gr.msg_queue(DEFAULT_MSGQ_LIMIT) - msg_sink = gr.message_sink(self._item_size_in, self._msgq_in, False) #False -> blocking #initialize hier2 gr.hier_block2.__init__( self, "packet_encoder", - gr.io_signature(1, 1, self._item_size_in), # Input signature + gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_char) # Output signature ) #connect - self.connect(self, msg_sink) self.connect(msg_source, self) - #start thread - _packet_encoder_thread(self._msgq_in, self._payload_length, self._send_packet) - def _send_packet(self, payload): + def send_pkt(self, payload): """ Wrap the payload in a packet and push onto the message queue. @param payload string, data to send @@ -119,41 +113,38 @@ class packet_encoder(gr.hier_block2): msg = gr.message_from_string(packet) self._msgq_out.insert_tail(msg) -####################################################################################### +################################################## ## Packet Decoder -####################################################################################### - +################################################## class _packet_decoder_thread(_threading.Thread): - def __init__(self, msgq, callback): - _threading.Thread.__init__(self) - self.setDaemon(1) - self._msgq = msgq - self.callback = callback - self.keep_running = True - self.start() - - def run(self): - while self.keep_running: - msg = self._msgq.delete_head() - ok, payload = packet_utils.unmake_packet(msg.to_string(), int(msg.arg1())) - if self.callback: - self.callback(ok, payload) + def __init__(self, msgq, callback): + _threading.Thread.__init__(self) + self.setDaemon(1) + self._msgq = msgq + self.callback = callback + self.keep_running = True + self.start() + + def run(self): + while self.keep_running: + msg = self._msgq.delete_head() + ok, payload = packet_utils.unmake_packet(msg.to_string(), int(msg.arg1())) + if self.callback: + self.callback(ok, payload) class packet_decoder(gr.hier_block2): """ Hierarchical block for wrapping packet-based demodulators. """ - def __init__(self, item_size_out, access_code='', threshold=-1): + def __init__(self, access_code='', threshold=-1, callback=None): """ packet_demod constructor. - @param item_size_out the size of the output data stream in bytes @param access_code AKA sync vector - @param threshold detect access_code with up to threshold bits wrong (-1 -> use default) + @param threshold detect access_code with up to threshold bits wrong (0 -> use default) + @param callback a function of args: ok, payload """ - #setup - self._item_size_out = item_size_out #access code if not access_code: #get access code access_code = packet_utils.default_access_code @@ -164,29 +155,89 @@ class packet_decoder(gr.hier_block2): if threshold < 0: threshold = DEFAULT_THRESHOLD self._threshold = threshold #blocks - self._msgq_in = gr.msg_queue(DEFAULT_MSGQ_LIMIT) #holds packets from the PHY + msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT) #holds packets from the PHY correlator = gr.correlate_access_code_bb(self._access_code, self._threshold) - framer_sink = gr.framer_sink_1(self._msgq_in) - msg_source = gr.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT) - self._msgq_out = msg_source.msgq() + framer_sink = gr.framer_sink_1(msgq) #initialize hier2 gr.hier_block2.__init__( self, "packet_decoder", gr.io_signature(1, 1, gr.sizeof_char), # Input signature - gr.io_signature(1, 1, self._item_size_out) # Output signature + gr.io_signature(0, 0, 0) # Output signature ) #connect self.connect(self, correlator, framer_sink) - self.connect(msg_source, self) #start thread - _packet_decoder_thread(self._msgq_in, self._recv_packet) + _packet_decoder_thread(msgq, callback) - def _recv_packet(self, ok, payload): - """ - Extract the payload from the packet and push onto message queue. - @param ok boolean ok - @param payload data received - """ +################################################## +## Packet Mod for OFDM Mod and Packet Encoder +################################################## +class packet_mod_base(gr.hier_block2): + """ + Hierarchical block for wrapping packet source block. + """ + + def __init__(self, packet_source=None, payload_length=0): + if not payload_length: #get payload length + payload_length = DEFAULT_PAYLOAD_LEN + if payload_length%self._item_size_in != 0: #verify that packet length is a multiple of the stream size + raise ValueError, 'The payload length: "%d" is not a mutiple of the stream size: "%d".'%(payload_length, self._item_size_in) + #initialize hier2 + gr.hier_block2.__init__( + self, + "ofdm_mod", + gr.io_signature(1, 1, self._item_size_in), # Input signature + gr.io_signature(1, 1, packet_source._hb.output_signature().sizeof_stream_item(0)) # Output signature + ) + #create blocks + msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT) + msg_sink = gr.message_sink(self._item_size_in, msgq, False) #False -> blocking + copy = gr.kludge_copy(packet_source._hb.output_signature().sizeof_stream_item(0)) + #connect + self.connect(self, msg_sink) + self.connect(packet_source, copy, self) + #start thread + _packet_encoder_thread(msgq, payload_length, packet_source.send_pkt) + +class packet_mod_b(packet_mod_base): _item_size_in = gr.sizeof_char +class packet_mod_s(packet_mod_base): _item_size_in = gr.sizeof_short +class packet_mod_i(packet_mod_base): _item_size_in = gr.sizeof_int +class packet_mod_f(packet_mod_base): _item_size_in = gr.sizeof_float +class packet_mod_c(packet_mod_base): _item_size_in = gr.sizeof_gr_complex + +################################################## +## Packet Demod for OFDM Demod and Packet Decoder +################################################## +class packet_demod_base(gr.hier_block2): + """ + Hierarchical block for wrapping packet sink block. + """ + + def __init__(self, packet_sink=None): + #initialize hier2 + gr.hier_block2.__init__( + self, + "ofdm_mod", + gr.io_signature(1, 1, packet_sink._hb.input_signature().sizeof_stream_item(0)), # Input signature + gr.io_signature(1, 1, self._item_size_out) # Output signature + ) + #create blocks + msg_source = gr.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT) + self._msgq_out = msg_source.msgq() + copy = gr.kludge_copy(packet_sink._hb.input_signature().sizeof_stream_item(0)) + #connect + self.connect(self, copy, packet_sink) + self.connect(msg_source, self) + if packet_sink._hb.output_signature().sizeof_stream_item(0): + self.connect(packet_sink, gr.null_sink(packet_sink._hb.output_signature().sizeof_stream_item(0))) + + def recv_pkt(self, ok, payload): msg = gr.message_from_string(payload, 0, self._item_size_out, len(payload)/self._item_size_out) if ok: self._msgq_out.insert_tail(msg) + +class packet_demod_b(packet_demod_base): _item_size_out = gr.sizeof_char +class packet_demod_s(packet_demod_base): _item_size_out = gr.sizeof_short +class packet_demod_i(packet_demod_base): _item_size_out = gr.sizeof_int +class packet_demod_f(packet_demod_base): _item_size_out = gr.sizeof_float +class packet_demod_c(packet_demod_base): _item_size_out = gr.sizeof_gr_complex |