[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8280 - in grc/trunk: notes src/grc_gnuradio/blks2 src
From: |
jblum |
Subject: |
[Commit-gnuradio] r8280 - in grc/trunk: notes src/grc_gnuradio/blks2 src/grc_gnuradio/blocks/graphical_sinks src/grc_gnuradio/blocks/misc src/grc_gnuradio/data src/grc_gnuradio/wxgui |
Date: |
Fri, 25 Apr 2008 22:26:16 -0600 (MDT) |
Author: jblum
Date: 2008-04-25 22:26:15 -0600 (Fri, 25 Apr 2008)
New Revision: 8280
Added:
grc/trunk/src/grc_gnuradio/blks2/error_rate.py
grc/trunk/src/grc_gnuradio/blocks/misc/blks2_error_rate.xml
grc/trunk/src/grc_gnuradio/wxgui/top_block_gui.py
Removed:
grc/trunk/src/grc_gnuradio/wxgui/grc_app.py
Modified:
grc/trunk/notes/todo.txt
grc/trunk/src/grc_gnuradio/blks2/__init__.py
grc/trunk/src/grc_gnuradio/blocks/graphical_sinks/wxgui_fftsink2.xml
grc/trunk/src/grc_gnuradio/data/block_tree.xml
grc/trunk/src/grc_gnuradio/data/wx_gui.tmpl
grc/trunk/src/grc_gnuradio/wxgui/__init__.py
Log:
top block gui, ber/ser error rate block, fft sink fix
Modified: grc/trunk/notes/todo.txt
===================================================================
--- grc/trunk/notes/todo.txt 2008-04-26 03:26:58 UTC (rev 8279)
+++ grc/trunk/notes/todo.txt 2008-04-26 04:26:15 UTC (rev 8280)
@@ -8,15 +8,14 @@
-hier block
-optparse block
-############ Known Problems: ####################
--packet threads block on close (needs a msg with -1)
-
############ Features to Add: ####################
-startup tips
-save working directory after close
-create sub-flow graphs to be used in larger flow graphs
-copy and paste blocks
-disable blocks (grey out, keep in design file, but generate ignores)
+-conversion script from previous format
+-print stdout with stderr from exec
############ Suggestions: ####################
-scope sink constructor needs average option and triggering option
Modified: grc/trunk/src/grc_gnuradio/blks2/__init__.py
===================================================================
--- grc/trunk/src/grc_gnuradio/blks2/__init__.py 2008-04-26 03:26:58 UTC
(rev 8279)
+++ grc/trunk/src/grc_gnuradio/blks2/__init__.py 2008-04-26 04:26:15 UTC
(rev 8280)
@@ -3,4 +3,5 @@
from selector import selector, valve
from packet import packet_mod, packet_demod
from packet import mod_pkts, demod_pkts
+from error_rate import error_rate
Added: grc/trunk/src/grc_gnuradio/blks2/error_rate.py
===================================================================
--- grc/trunk/src/grc_gnuradio/blks2/error_rate.py
(rev 0)
+++ grc/trunk/src/grc_gnuradio/blks2/error_rate.py 2008-04-26 04:26:15 UTC
(rev 8280)
@@ -0,0 +1,143 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 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.
+#
+
+default_num_samples = 1000
+
+from gnuradio import gr
+import gnuradio.gr.gr_threading as _threading
+import numpy
+
+class input_watcher(_threading.Thread):
+ """
+ Read samples from the message queue and hand them to the callback.
+ """
+
+ def __init__(self, msgq, callback):
+ self._msgq = msgq
+ self._callback = callback
+ _threading.Thread.__init__(self)
+ self.setDaemon(1)
+ self.keep_running = True
+ self.start()
+
+ def run(self):
+ r = ''
+ while True:
+ msg = self._msgq.delete_head()
+ itemsize = int(msg.arg1())
+ nitems = int(msg.arg2())
+ s = r + msg.to_string()
+ i = (nitems-nitems%2)*itemsize
+ r = s[i:]
+ s = s[:i]
+ samples = numpy.fromstring(s, numpy.int8)
+ self._callback(samples)
+
+class error_rate(gr.hier_block2):
+ """
+ Sample the incoming data streams (byte) and calculate the bit or symbol
error rate.
+ Write the running rate to the output data stream (float).
+ """
+
+ def __init__(self, type='BER', num_samples=default_num_samples,
bits_per_symbol=2):
+ """!
+ Error rate constructor.
+ @param type a string 'BER' or 'SER'
+ @param num_samples the number of samples to calculate over
+ @param bits_per_symbol the number of information bits per
symbol (BER only)
+ """
+ #init
+ gr.hier_block2.__init__(
+ self, 'error_rate',
+ gr.io_signature(2, 2, gr.sizeof_char),
+ gr.io_signature(1, 1, gr.sizeof_float),
+ )
+ assert type in ('BER', 'SER')
+ self._max_samples = num_samples
+ self._bits_per_symbol = bits_per_symbol
+ #setup message queue
+ msg_source = gr.message_source(gr.sizeof_float, 1)
+ self._msgq_source = msg_source.msgq()
+ msgq_sink = gr.msg_queue(2)
+ msg_sink = gr.message_sink(gr.sizeof_char, msgq_sink, False)
#False -> blocking
+ inter = gr.interleave(gr.sizeof_char)
+ #start thread
+ self._num_errs = 0
+ self._err_index = 0
+ self._num_samps = 0
+ self._err_array = numpy.zeros(self._max_samples, numpy.int8)
+ if type == 'BER':
+ input_watcher(msgq_sink, self._handler_ber)
+ elif type == 'SER':
+ input_watcher(msgq_sink, self._handler_ser)
+ #connect
+ self.connect(msg_source, self)
+ self.connect((self, 0), (inter, 0))
+ self.connect((self, 1), (inter, 1))
+ self.connect(inter, msg_sink)
+
+ def _handler_ber(self, samples):
+ num = len(samples)/2
+ arr = numpy.zeros(num, numpy.float32)
+ for i in range(num):
+ old_err = self._err_array[self._err_index]
+ #record error
+ ref = samples[i*2] ^ samples[i*2 + 1]
+ self._err_array[self._err_index] = 0
+ for j in range(self._bits_per_symbol):
+ if (ref & 1) != 0:
+ self._err_array[self._err_index] =
self._err_array[self._err_index] + 1
+ ref >> 1
+ #update number of errors
+ self._num_errs = self._num_errs +
self._err_array[self._err_index] - old_err
+ #increment index
+ self._err_index = (self._err_index +
1)%self._max_samples
+ self._num_samps = min(self._num_samps + 1,
self._max_samples)
+ #write sample
+ arr[i] =
float(self._num_errs)/float(self._num_samps*self._bits_per_symbol)
+ #write message
+ msg = gr.message_from_string(arr.tostring(), 0,
gr.sizeof_float, num)
+ self._msgq_source.insert_tail(msg)
+
+ def _handler_ser(self, samples):
+ num = len(samples)/2
+ arr = numpy.zeros(num, numpy.float32)
+ for i in range(num):
+ old_err = self._err_array[self._err_index]
+ #record error
+ ref = samples[i*2]
+ res = samples[i*2 + 1]
+ if ref == res:
+ self._err_array[self._err_index] = 0
+ else:
+ self._err_array[self._err_index] = 1
+ #update number of errors
+ self._num_errs = self._num_errs +
self._err_array[self._err_index] - old_err
+ #increment index
+ self._err_index = (self._err_index +
1)%self._max_samples
+ self._num_samps = min(self._num_samps + 1,
self._max_samples)
+ #write sample
+ arr[i] = float(self._num_errs)/float(self._num_samps)
+ #write message
+ msg = gr.message_from_string(arr.tostring(), 0,
gr.sizeof_float, num)
+ self._msgq_source.insert_tail(msg)
+
Modified: grc/trunk/src/grc_gnuradio/blocks/graphical_sinks/wxgui_fftsink2.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/graphical_sinks/wxgui_fftsink2.xml
2008-04-26 03:26:58 UTC (rev 8279)
+++ grc/trunk/src/grc_gnuradio/blocks/graphical_sinks/wxgui_fftsink2.xml
2008-04-26 04:26:15 UTC (rev 8280)
@@ -18,14 +18,14 @@
sample_rate=$samp_rate,
fft_size=$fft_size,
fft_rate=$fft_rate,
- average=$options.average,
+ average=$average,
#if $avg_alpha.eval == 0
avg_alpha=None,
#else
avg_alpha=$avg_alpha,
#end if
title=$title,
- peak_hold=$options.peak_hold,
+ peak_hold=$peak_hold,
)</make>
<param>
<name>Type</name>
@@ -98,28 +98,32 @@
<type>real</type>
</param>
<param>
- <name>Options</name>
- <key>options</key>
- <value>none</value>
+ <name>Average</name>
+ <key>average</key>
+ <value>False</value>
<type>enum</type>
<option>
- <name>None</name>
- <key>none</key>
- <opt>peak_hold:False</opt>
- <opt>average:False</opt>
+ <name>Yes</name>
+ <key>True</key>
</option>
<option>
- <name>Average</name>
- <key>average</key>
- <opt>peak_hold:False</opt>
- <opt>average:True</opt>
+ <name>No</name>
+ <key>False</key>
</option>
+ </param>
+ <param>
+ <name>Peak Hold</name>
+ <key>peak_hold</key>
+ <value>False</value>
+ <type>enum</type>
<option>
- <name>Peak Hold</name>
- <key>peak_hold</key>
- <opt>peak_hold:True</opt>
- <opt>average:False</opt>
+ <name>Yes</name>
+ <key>True</key>
</option>
+ <option>
+ <name>No</name>
+ <key>False</key>
+ </option>
</param>
<param>
<name>Num Inputs</name>
Added: grc/trunk/src/grc_gnuradio/blocks/misc/blks2_error_rate.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/misc/blks2_error_rate.xml
(rev 0)
+++ grc/trunk/src/grc_gnuradio/blocks/misc/blks2_error_rate.xml 2008-04-26
04:26:15 UTC (rev 8280)
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!--
+###################################################
+##Error Rate:
+## Custom blks2 block
+###################################################
+ -->
+<block>
+ <name>Error Rate</name>
+ <key>blks2_error_rate</key>
+ <import>from grc_gnuradio import blks2 as grc_blks2</import>
+ <make>grc_blks2.error_rate(
+ type=$type,
+ num_samples=$num_samples,
+ bits_per_symbol=$bits_per_symbol,
+)</make>
+ <param>
+ <name>Type</name>
+ <key>type</key>
+ <type>enum</type>
+ <option>
+ <name>Bit Error Rate</name>
+ <key>"BER"</key>
+ </option>
+ <option>
+ <name>Symbol Error Rate</name>
+ <key>"SER"</key>
+ </option>
+ </param>
+ <param>
+ <name>Num Samples</name>
+ <key>num_samples</key>
+ <value>1000</value>
+ <type>int</type>
+ </param>
+ <param>
+ <name>Bits per Symbol</name>
+ <key>bits_per_symbol</key>
+ <value>2</value>
+ <type>int</type>
+ </param>
+ <sink>
+ <name>ref</name>
+ <type>byte</type>
+ </sink>
+ <sink>
+ <name>in</name>
+ <type>byte</type>
+ </sink>
+ <source>
+ <name>out</name>
+ <type>float</type>
+ </source>
+</block>
Modified: grc/trunk/src/grc_gnuradio/data/block_tree.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/data/block_tree.xml 2008-04-26 03:26:58 UTC
(rev 8279)
+++ grc/trunk/src/grc_gnuradio/data/block_tree.xml 2008-04-26 04:26:15 UTC
(rev 8280)
@@ -227,6 +227,7 @@
<block>blks2_selector</block>
<block>blks2_valve</block>
+ <block>blks2_error_rate</block>
<block>gr_head</block>
<block>gr_skiphead</block>
Modified: grc/trunk/src/grc_gnuradio/data/wx_gui.tmpl
===================================================================
--- grc/trunk/src/grc_gnuradio/data/wx_gui.tmpl 2008-04-26 03:26:58 UTC (rev
8279)
+++ grc/trunk/src/grc_gnuradio/data/wx_gui.tmpl 2008-04-26 04:26:15 UTC (rev
8280)
@@ -14,6 +14,14 @@
address@hidden graphical_sinks the graphical sink blocks
########################################################
#import time
+#import os
+#from grc.Constants import MAIN_WINDOW_PREFIX,DATA_DIR
+##set the icon for the wx app
+#set $WX_APP_ICON = '"%s"'%os.path.abspath($DATA_DIR + '/grc-icon-32.png')
+##>>> platform dependency! wx under cygwin has issues with icon paths
+#if sys.platform == 'cygwin'
+#set $WX_APP_ICON = None
+#end if
$('#'*40)
# Gnuradio Python Flow Graph (wx gui)
$('# Name: %s'%$flow_graph.get_option('name'))
@@ -46,7 +54,10 @@
$imp
#end for
-tb = grc_wxgui.grc_app("$flow_graph.get_option('name')")
+tb = grc_wxgui.top_block_gui(
+ title="$MAIN_WINDOW_PREFIX - Executing: $flow_graph.get_option('name')",
+ icon=$WX_APP_ICON,
+)
########################################################
## Create Variables
Modified: grc/trunk/src/grc_gnuradio/wxgui/__init__.py
===================================================================
--- grc/trunk/src/grc_gnuradio/wxgui/__init__.py 2008-04-26 03:26:58 UTC
(rev 8279)
+++ grc/trunk/src/grc_gnuradio/wxgui/__init__.py 2008-04-26 04:26:15 UTC
(rev 8280)
@@ -1,5 +1,5 @@
# make this directory a package
from callback_controls import chooser_control, slider_control
-from grc_app import grc_app
+from top_block_gui import top_block_gui
Deleted: grc/trunk/src/grc_gnuradio/wxgui/grc_app.py
Copied: grc/trunk/src/grc_gnuradio/wxgui/top_block_gui.py (from rev 8278,
grc/trunk/src/grc_gnuradio/wxgui/grc_app.py)
===================================================================
--- grc/trunk/src/grc_gnuradio/wxgui/top_block_gui.py
(rev 0)
+++ grc/trunk/src/grc_gnuradio/wxgui/top_block_gui.py 2008-04-26 04:26:15 UTC
(rev 8280)
@@ -0,0 +1,94 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 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.
+#
+
+import wx
+import sys, os
+from gnuradio import gr
+
+default_gui_size = (200, 100)
+
+class top_block_gui(gr.top_block):
+ """gr top block with wx gui app and grid sizer."""
+
+ def __init__(self, title='', size=default_gui_size, icon=None):
+ """!
+ Initialize the gr top block.
+ Create the wx gui elements.
+ @param title the main window title
+ @param size the main window size tuple in pixels
+ @param icon the file path to an icon or None
+ """
+ #initialize
+ gr.top_block.__init__(self)
+ self._size = size
+ try:
+ assert os.path.isfile(icon)
+ self._icon = icon
+ except AssertionError: self._icon = None
+ #create gui elements
+ self._wx_app = wx.App()
+ self._wx_frame = wx.Frame(None , -1, title)
+ self._wx_grid = wx.GridBagSizer(5, 5)
+
+ def GetWin(self):
+ """!
+ Get the window for wx elements to fit within.
+ @return the wx frame
+ """
+ return self._wx_frame
+
+ def GridAdd(self, win, row, col, row_span=1, col_span=1):
+ """!
+ Add a window to the wx grid at the given position.
+ @param win the wx window
+ @param row the row specification (integer >= 0)
+ @param col the column specification (integer >= 0)
+ @param row_span the row span specification (integer >= 1)
+ @param col_span the column span specification (integer >= 1)
+ """
+ self._wx_grid.Add(win, wx.GBPosition(row, col),
wx.GBSpan(row_span, col_span))
+
+ def Run(self):
+ """!
+ Setup the wx gui elements.
+ Start the gr top block.
+ Block with the wx main loop.
+ """
+ #set wx app icon
+ if self._icon: self._wx_frame.SetIcon(wx.Icon(self._icon,
wx.BITMAP_TYPE_ANY))
+ #set minimal window size
+ self._wx_frame.SetSizeHints(*self._size)
+ #create callback for quit
+ def _quit(event):
+ gr.top_block.stop(self)
+ self._wx_frame.Destroy()
+ exit(0)
+ #setup app
+ self._wx_frame.Bind(wx.EVT_CLOSE, _quit)
+ self._wx_frame.SetSizerAndFit(self._wx_grid)
+ self._wx_frame.Show()
+ self._wx_app.SetTopWindow(self._wx_frame)
+ #start flow graph
+ gr.top_block.start(self)
+ #blocking main loop
+ self._wx_app.MainLoop()
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8280 - in grc/trunk: notes src/grc_gnuradio/blks2 src/grc_gnuradio/blocks/graphical_sinks src/grc_gnuradio/blocks/misc src/grc_gnuradio/data src/grc_gnuradio/wxgui,
jblum <=