[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r6547 - in grc/trunk/src: Graphics SignalBlockDefs Sig
From: |
jblum |
Subject: |
[Commit-gnuradio] r6547 - in grc/trunk/src: Graphics SignalBlockDefs SignalBlockDefs/ext |
Date: |
Wed, 26 Sep 2007 22:53:38 -0600 (MDT) |
Author: jblum
Date: 2007-09-26 22:53:38 -0600 (Wed, 26 Sep 2007)
New Revision: 6547
Added:
grc/trunk/src/SignalBlockDefs/ext/packet.py
Modified:
grc/trunk/src/Graphics/MainWindow.py
grc/trunk/src/SignalBlockDefs/Misc.py
grc/trunk/src/SignalBlockDefs/Packet.py
grc/trunk/src/SignalBlockDefs/SignalBlockTree.py
grc/trunk/src/SignalBlockDefs/ext/__init__.py
Log:
moved packet mod/demod to ext dir
Modified: grc/trunk/src/Graphics/MainWindow.py
===================================================================
--- grc/trunk/src/Graphics/MainWindow.py 2007-09-26 20:57:33 UTC (rev
6546)
+++ grc/trunk/src/Graphics/MainWindow.py 2007-09-27 04:53:38 UTC (rev
6547)
@@ -64,7 +64,7 @@
self.tab = gtk.HBox(False, 0)
#setup tab label
self.label = gtk.Label()
- self.tab.pack_start(self.label, True, False, 0)
+ self.tab.pack_start(self.label, False)
#setup button image
image = gtk.Image()
image.set_from_stock('gtk-close', gtk.ICON_SIZE_MENU)
@@ -79,7 +79,7 @@
#button size
w, h = gtk.icon_size_lookup_for_settings(button.get_settings(),
gtk.ICON_SIZE_MENU)
button.set_size_request(w+6, h+6)
- self.tab.pack_start(button)
+ self.tab.pack_start(button, False)
self.tab.show_all()
def _handle_button(self, button):
@@ -290,6 +290,7 @@
self.notebook.append_page(page, page.get_tab())
try: self.notebook.set_tab_reorderable(page, True)
except: pass #gtk too old
+ self.notebook.set_tab_label_packing(page, False, False,
gtk.PACK_START)
if not file_path: self._set_page(page) #only show if blank
def close_pages(self):
Modified: grc/trunk/src/SignalBlockDefs/Misc.py
===================================================================
--- grc/trunk/src/SignalBlockDefs/Misc.py 2007-09-26 20:57:33 UTC (rev
6546)
+++ grc/trunk/src/SignalBlockDefs/Misc.py 2007-09-27 04:53:38 UTC (rev
6547)
@@ -24,7 +24,7 @@
from DataTypes import *
from gnuradio import gr
from SignalBlockConstants import default_samp_rate,all_choices,MAX_NUM_SOCKETS
-import ext as blks2
+from ext import selector
def Throttle(sb):
fcn = gr.throttle
@@ -87,7 +87,7 @@
return sb, lambda *args: None
def Selector(sb):
- fcn = blks2.selector
+ fcn = selector.selector
type = Enum(all_choices, 1)
vlen = Int(1, min=1)
sb.add_input_socket('in', Variable(type), vlen=vlen)
@@ -116,7 +116,7 @@
return sb, make
def Valve(sb):
- fcn = blks2.selector
+ fcn = selector.selector
type = Enum(all_choices, 1)
vlen = Int(1, min=1)
sb.add_input_socket('in', Variable(type), vlen=vlen)
Modified: grc/trunk/src/SignalBlockDefs/Packet.py
===================================================================
--- grc/trunk/src/SignalBlockDefs/Packet.py 2007-09-26 20:57:33 UTC (rev
6546)
+++ grc/trunk/src/SignalBlockDefs/Packet.py 2007-09-27 04:53:38 UTC (rev
6547)
@@ -23,128 +23,19 @@
import struct
import os
from DataTypes import *
-from gnuradio import gr, packet_utils
-import gnuradio.gr.gr_threading as threading
+from gnuradio import gr
from SignalBlockConstants import all_choices
+from ext import packet
-##payload length in bytes
-DEFAULT_PAYLOAD_LEN = 512
-
-##how many messages in a queue
-DEFAULT_MSGQ_LIMIT = 2
-
-##threshold for unmaking packets
-DEFAULT_THRESHOLD = 12
-
-#######################################################################################
-## Packet Mod
-#######################################################################################
-
-class PacketModThread(threading.Thread):
- """
- Sample the input message queue and call send payload.
- """
-
- def __init__(self, msgq, payload_length, send_payload):
- """!
- Create the packet_mod_thread.
- @param msgq the message queue to sample
- @param payload_length number of bytes in a data-stream slice
- @param send_payload a function that takes a payload
- """
- self._msgq = msgq
- self._payload_length = payload_length
- self._send_payload = send_payload
- threading.Thread.__init__(self)
- self.setDaemon(1)
- self.keep_running = True
- self.start()
-
- def run(self):
- """
- Run this thread by sampling the message queue in and cutting
out chunks of size payload.
- """
- sample = '' #residual sample
- while self.keep_running:
- 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]
- sample = sample[self._payload_length:]
- self._send_payload(payload)
-
-class PacketModHelper(gr.hier_block2):
- """
- Hierarchical block for sending packet based data.
- """
-
- def __init__(self, item_size, samples_per_symbol, bits_per_symbol,
payload_length=None, access_code=None, pad_for_usrp=True):
- """!
- PacketModHelper constructor.
- @param item_size 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 payload_length number of bytes in a data-stream slice
- @param access_code AKA sync vector
- @param pad_for_usrp If true, packets are padded such that they
end up a multiple of 128 samples
- """
- #setup parameters
- self._item_size = item_size
- self._samples_per_symbol = samples_per_symbol
- self._bits_per_symbol = bits_per_symbol
- self._pad_for_usrp = pad_for_usrp
- if access_code is None: #get access code
- access_code = packet_utils.default_access_code
- if not packet_utils.is_1_0_string(access_code):
- raise ValueError, "Invalid access_code %r. Must be
string of 1's and 0's" % (access_code,)
- self._access_code = access_code
- if payload_length is None: #get packet length
- payload_length = DEFAULT_PAYLOAD_LEN
- if payload_length%self._item_size != 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, item_size)
- self._payload_length = payload_length
- self._pad_for_usrp = pad_for_usrp
- #create message queues and message blocks
- self._msgq_in = gr.msg_queue(DEFAULT_MSGQ_LIMIT)
- msg_sink = gr.message_sink(self._item_size,
self._msgq_in, False) #False -> blocking
- msg_source = gr.message_source(gr.sizeof_char,
DEFAULT_MSGQ_LIMIT)
- self._msgq_out = msg_source.msgq()
- #initialize hier2
- gr.hier_block2.__init__(
- self,
- "packet_mod",
- gr.io_signature(1, 1, self._item_size), # 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
- PacketModThread(self._msgq_in, self._payload_length,
self._send_payload)
-
- def _send_payload(self, payload):
- """!
- Wrap the payload in a packet and push onto the message queue.
- @param payload data to send
- """
- packet = packet_utils.make_packet(
- payload,
- self._samples_per_symbol,
- self._bits_per_symbol,
- self._access_code,
- self._pad_for_usrp
- )
- msg = gr.message_from_string(packet)
- self._msgq_out.insert_tail(msg)
-
def PacketMod(sb):
+ packet.mod_pkts, packet.packet_mod #uses
type = Enum(all_choices, 1)
sb.add_input_socket('in', Variable(type))
sb.add_output_socket('out', Byte())
sb.add_param('Type', type, False, type=True)
sb.add_param('Samples/Symbol', Int(1))
sb.add_param('Bits/Symbol', Int(1))
- sb.add_param('Payload Length', Int(DEFAULT_PAYLOAD_LEN))
+ sb.add_param('Payload Length', Int(packet.DEFAULT_PAYLOAD_LEN))
sb.add_param('Access Code', String())
sb.add_param('Pad for USRP', Bool(true='Yes', false='No', default=True))
sb.set_docs("""\
@@ -165,99 +56,23 @@
def make(fg, type, samples_per_symbol, bits_per_symbol, payload_length,
access_code, pad_for_usrp):
access_code = access_code.parse()
if not access_code: access_code = None
- return PacketModHelper(
- item_size = type.parse().get_num_bytes(),
+ mod = packet.mod_pkts(
samples_per_symbol=samples_per_symbol.parse(),
bits_per_symbol=bits_per_symbol.parse(),
- payload_length=payload_length.parse(),
access_code=access_code,
pad_for_usrp=pad_for_usrp.parse(),
)
+ helper = packet.packet_mod(
+ item_size_in=type.parse().get_num_bytes(),
+ item_size_out=Byte().get_num_bytes(),
+ modulator=mod,
+ payload_length=payload_length.parse(),
+ )
+ return helper
return sb, make
-#######################################################################################
-## Packet Demod
-#######################################################################################
-
-class PacketDemodThread(threading.Thread):
- """
- Sample the input message queue and call send packet.
- """
-
- def __init__(self, msgq, recv_packet):
- """!
- Create the packet_mod_thread.
- @param msgq the message queue to sample
- @param recv_packet a function that takes a packet
- """
- self._msgq = msgq
- self._recv_packet = recv_packet
- threading.Thread.__init__(self)
- self.setDaemon(1)
- self.keep_running = True
- self.start()
-
- def run(self):
- """
- Run this thread by sampling the message queue and calling send
payload
- """
- while self.keep_running:
- msg = self._msgq.delete_head() #blocking read of
message queue
- packet = msg.to_string()
- self._recv_packet(packet)
-
-class PacketDemodHelper(gr.hier_block2):
- """
- Hierarchical block for demodulating and deframing packets.
- """
-
- def __init__(self, item_size, access_code=None, threshold=-1):
- """!
- PacketDemodHelper contructor.
- @param item_size the size of the input data stream in bytes
- @param access_code AKA sync vector
- @param threshold detect access_code with up to threshold bits
wrong (-1 -> use default)
- """
- #setup parameters
- self._item_size = item_size
- #access code
- if access_code is None: #get access code
- access_code = packet_utils.default_access_code
- if not packet_utils.is_1_0_string(access_code):
- raise ValueError, "Invalid access_code %r. Must be
string of 1's and 0's" % (access_code,)
- self._access_code = access_code
- #threshold
- if threshold == -1: threshold = DEFAULT_THRESHOLD
- self._threshold = threshold
- #initialize hier2
- gr.hier_block2.__init__(
- self,
- "packet_demod",
- gr.io_signature(1, 1, gr.sizeof_char), # Input signature
- gr.io_signature(1, 1, self._item_size), # Output
signature
- )
- #blocks
- self._msgq_in = 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,
DEFAULT_MSGQ_LIMIT)
- self._msgq_out = msg_source.msgq()
- #connect
- self.connect(self, correlator, framer_sink)
- self.connect(msg_source, self)
- #start thread
- PacketDemodThread(self._msgq_in, self._recv_packet)
-
- def _recv_packet(self, packet):
- """!
- Extract the payload from the packet and push onto message queue.
- @param packet data received
- """
- ok, payload = packet_utils.unmake_packet(packet)
- msg = gr.message_from_string(payload, 0, self._item_size,
len(payload)/self._item_size)
- if ok: self._msgq_out.insert_tail(msg)
-
def PacketDemod(sb):
+ packet.demod_pkts, packet.packet_demod #uses
type = Enum(all_choices, 1)
sb.add_input_socket('in', Byte())
sb.add_output_socket('out', Variable(type))
@@ -272,11 +87,16 @@
def make(fg, type, access_code, threshold):
access_code = access_code.parse()
if not access_code: access_code = None
- return PacketDemodHelper(
- item_size = type.parse().get_num_bytes(),
+ demod = packet.demod_pkts(
access_code=access_code,
threshold=threshold.parse(),
)
+ helper = packet.packet_demod(
+ item_size_in=Byte().get_num_bytes(),
+ item_size_out=type.parse().get_num_bytes(),
+ demodulator=demod,
+ )
+ return helper
return sb, make
#######################################################################################
Modified: grc/trunk/src/SignalBlockDefs/SignalBlockTree.py
===================================================================
--- grc/trunk/src/SignalBlockDefs/SignalBlockTree.py 2007-09-26 20:57:33 UTC
(rev 6546)
+++ grc/trunk/src/SignalBlockDefs/SignalBlockTree.py 2007-09-27 04:53:38 UTC
(rev 6547)
@@ -221,7 +221,7 @@
print 'Removing redundant tag "%s" in category
"%s"...'%(tag[0], category)
tags_to_remove.append(tag)
else: tags_set.add(tag[0])
- except (ImportError, AttributeError), e:
+ except (ImportError, AttributeError, NameError), e:
print e, " in %s! -> continuing..."%tag[0]
tags_to_remove.append(tag)
for tag in tags_to_remove: tags.remove(tag)
Modified: grc/trunk/src/SignalBlockDefs/ext/__init__.py
===================================================================
--- grc/trunk/src/SignalBlockDefs/ext/__init__.py 2007-09-26 20:57:33 UTC
(rev 6546)
+++ grc/trunk/src/SignalBlockDefs/ext/__init__.py 2007-09-27 04:53:38 UTC
(rev 6547)
@@ -20,7 +20,3 @@
#Package for external gnuradio blocks.
address@hidden Josh Blum
-import selector
-import scopesink2
-
-selector = selector.selector
Added: grc/trunk/src/SignalBlockDefs/ext/packet.py
===================================================================
--- grc/trunk/src/SignalBlockDefs/ext/packet.py (rev 0)
+++ grc/trunk/src/SignalBlockDefs/ext/packet.py 2007-09-27 04:53:38 UTC (rev
6547)
@@ -0,0 +1,263 @@
+#!/usr/bin/env python
+#
+# Copyright 2003,2004,2006,2007 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+from gnuradio import gr, packet_utils
+import gnuradio.gr.gr_threading as _threading
+
+##payload length in bytes
+DEFAULT_PAYLOAD_LEN = 512
+
+##how many messages in a queue
+DEFAULT_MSGQ_LIMIT = 2
+
+##threshold for unmaking packets
+DEFAULT_THRESHOLD = 12
+
+#######################################################################################
+## Packet Modulation
+#######################################################################################
+
+class packet_mod_thread(_threading.Thread):
+ """
+ Sample the input message queue and call send.
+ """
+
+ def __init__(self, msgq, payload_length, send):
+ """!
+ packet_mod_thread contructor.
+ @param msgq the message queue to sample
+ @param payload_length number of bytes in a data-stream slice
+ @param send a function that takes a payload
+ """
+ self._msgq = msgq
+ self._payload_length = payload_length
+ self._send = send
+ _threading.Thread.__init__(self)
+ self.setDaemon(1)
+ self.keep_running = True
+ self.start()
+
+ def run(self):
+ """
+ Run this thread by sampling the message queue in and cutting
out chunks of size payload.
+ """
+ sample = '' #residual sample
+ while self.keep_running:
+ 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]
+ sample = sample[self._payload_length:]
+ self._send(payload)
+
+class packet_mod(gr.hier_block2):
+ """
+ Hierarchical block for wrapping packet-based modulators.
+ """
+
+ def __init__(self, item_size_in, item_size_out, modulator,
payload_length=None):
+ """!
+ packet_mod constructor.
+ @param item_size_in the size of the input data stream in bytes
+ @param item_size_out the size of the output data stream in bytes
+ @param modulator the packet-based modulator
+ @param payload_length number of bytes in a data-stream slice
+ """
+ #setup
+ self._item_size_in = item_size_in
+ self._item_size_out = item_size_out
+ if payload_length is None: #get packet 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
+ self._modulator = modulator
+ #create blocks
+ 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 mod",
+ gr.io_signature(1, 1, self._item_size_in), # Input
signature
+ gr.io_signature(1, 1, self._item_size_out) # Output
signature
+ )
+ #connect
+ self.connect(self, msg_sink)
+ self.connect(self._modulator, self)
+ #start thread
+ packet_mod_thread(self._msgq_in, self._payload_length,
self._modulator.send_pkt)
+
+class mod_pkts(gr.hier_block2):
+ """
+ Hierarchical block for sending packet based data.
+ """
+
+ def __init__(self, samples_per_symbol, bits_per_symbol,
access_code=None, pad_for_usrp=True):
+ """!
+ mod_pkts constructor.
+ @param samples_per_symbol number of samples per symbol
+ @param bits_per_symbol number of bits per symbol
+ @param access_code AKA sync vector
+ @param pad_for_usrp If true, packets are padded such that they
end up a multiple of 128 samples
+ """
+ #setup parameters
+ self._samples_per_symbol = samples_per_symbol
+ self._bits_per_symbol = bits_per_symbol
+ self._pad_for_usrp = pad_for_usrp
+ if access_code is None: #get access code
+ access_code = packet_utils.default_access_code
+ if not packet_utils.is_1_0_string(access_code):
+ 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
+ #create blocks
+ msg_source = gr.message_source(gr.sizeof_char,
DEFAULT_MSGQ_LIMIT)
+ self._msgq_out = msg_source.msgq()
+ #initialize hier2
+ gr.hier_block2.__init__(
+ self,
+ "mod pkts",
+ gr.io_signature(0, 0, 0), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_char) # Output signature
+ )
+ #connect
+ self.connect(msg_source, self)
+
+ def send_pkt(self, payload='', eof=False):
+ """!
+ Wrap the payload in a packet and push onto the message queue.
+ @param payload string, data to send
+ @param eof boolean, end of file
+ """
+ if eof:
+ msg = gr.message(1) # tell self._pkt_input we're not
sending any more packets
+ else:
+ packet = packet_utils.make_packet(
+ payload,
+ self._samples_per_symbol,
+ self._bits_per_symbol,
+ self._access_code,
+ self._pad_for_usrp
+ )
+ msg = gr.message_from_string(packet)
+ self._msgq_out.insert_tail(msg)
+
+#######################################################################################
+## Packet Demodulation
+#######################################################################################
+
+class packet_demod(gr.hier_block2):
+ """
+ Hierarchical block for wrapping packet-based demodulators.
+ """
+
+ def __init__(self, item_size_in, item_size_out, demodulator):
+ """!
+ packet_demod constructor.
+ @param item_size_in the size of the input data stream in bytes
+ @param item_size_out the size of the output data stream in bytes
+ @param demodulator the packet-based demodulator
+ """
+ #setup
+ self._item_size_in = item_size_in
+ self._item_size_out = item_size_out
+ self._demodulator = demodulator
+ #blocks
+ msg_source = gr.message_source(self._item_size_out,
DEFAULT_MSGQ_LIMIT)
+ self._msgq_out = msg_source.msgq()
+ #initialize hier2
+ gr.hier_block2.__init__(
+ self,
+ "packet demod",
+ gr.io_signature(1, 1, self._item_size_in), # Input
signature
+ gr.io_signature(1, 1, self._item_size_out) # Output
signature
+ )
+ #connect
+ self.connect(self, gr.kludge_copy(self._item_size_in),
self._demodulator)
+ self.connect(msg_source, self)
+ #set callback
+ self._demodulator._watcher.callback = self._recv_packet
+
+ 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
+ """
+ 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 demod_pkts(gr.hier_block2):
+ """
+ Hierarchical block for demodulating and deframing packets.
+ """
+
+ def __init__(self, access_code=None, callback=None, threshold=-1):
+ """!
+ demod_pkts contructor.
+ @param access_code AKA sync vector
+ @param callback function of two args: ok, payload
+ @param threshold detect access_code with up to threshold bits
wrong (-1 -> use default)
+ """
+ #access code
+ if access_code is None: #get access code
+ access_code = packet_utils.default_access_code
+ if not packet_utils.is_1_0_string(access_code):
+ raise ValueError, "Invalid access_code %r. Must be
string of 1's and 0's" % (access_code,)
+ self._access_code = access_code
+ #threshold
+ if threshold == -1: threshold = DEFAULT_THRESHOLD
+ self._threshold = threshold
+ self._callback = callback
+ #initialize hier2
+ gr.hier_block2.__init__(
+ self,
+ "demod pkts",
+ gr.io_signature(1, 1, gr.sizeof_char), # Input signature
+ gr.io_signature(0, 0, 0), # Output signature
+ )
+ #blocks
+ self._msgq_in = 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)
+ #connect
+ self.connect(self, correlator, framer_sink)
+ #start thread
+ self._watcher = _queue_watcher_thread(self._msgq_in,
self._callback)
+
+class _queue_watcher_thread(_threading.Thread):
+ def __init__(self, rcvd_pktq, callback):
+ _threading.Thread.__init__(self)
+ self.setDaemon(1)
+ self.rcvd_pktq = rcvd_pktq
+ self.callback = callback
+ self.keep_running = True
+ self.start()
+
+ def run(self):
+ while self.keep_running:
+ msg = self.rcvd_pktq.delete_head()
+ ok, payload = packet_utils.unmake_packet(msg.to_string(),
int(msg.arg1()))
+ if self.callback:
+ self.callback(ok, payload)
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r6547 - in grc/trunk/src: Graphics SignalBlockDefs SignalBlockDefs/ext,
jblum <=