[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5857 - in grc/branches/jblum_work/src: . SignalBlockD
From: |
jblum |
Subject: |
[Commit-gnuradio] r5857 - in grc/branches/jblum_work/src: . SignalBlockDefs |
Date: |
Wed, 27 Jun 2007 12:26:07 -0600 (MDT) |
Author: jblum
Date: 2007-06-27 12:26:04 -0600 (Wed, 27 Jun 2007)
New Revision: 5857
Modified:
grc/branches/jblum_work/src/ActionHandler.py
grc/branches/jblum_work/src/Constants.py
grc/branches/jblum_work/src/ExecFlowGraph.py
grc/branches/jblum_work/src/ExecFlowGraphGUI.py
grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py
grc/branches/jblum_work/src/SignalBlockDefs/Packet.py
grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py
grc/branches/jblum_work/src/Variables.py
Log:
lock and unlock at top level, comments, variable reregister, misc
Modified: grc/branches/jblum_work/src/ActionHandler.py
===================================================================
--- grc/branches/jblum_work/src/ActionHandler.py 2007-06-27 18:05:27 UTC
(rev 5856)
+++ grc/branches/jblum_work/src/ActionHandler.py 2007-06-27 18:26:04 UTC
(rev 5857)
@@ -332,14 +332,14 @@
self.handle_states(FLOW_GRAPH_SAVE)
if self.flow_graph_file_path != '':
ExecFlowGraphThread(self)
elif state == FLOW_GRAPH_STOP:
- while not MUTEX.testandset(): pass #try to lock
repeatedly until lock is aquired
+ MUTEX.lock()
if self.pid_file!= None:
try: os.kill(int(open(self.pid_file,
'r').read()), 9)
except: print "could not kill pid file:
%s"%self.pid_file
MUTEX.unlock()
else: print "!!! State not handled !!!"
# set the exec button if the flow graph is valid and is not
already running #
- while not MUTEX.testandset(): pass #try to lock repeatedly
until lock is aquired
+ MUTEX.lock()
get_action_from_name(FLOW_GRAPH_EXEC).set_sensitive(self.flow_graph.is_valid()
and self.pid_file == None)
MUTEX.unlock()
# hide/show the reports window based on the preferences #
@@ -404,7 +404,7 @@
except IOError: print "could not read report file:
%s"%self.report_file
try: os.remove(self.pid_file)
except: print "could not remove pid file: %s"%self.pid_file
- while not MUTEX.testandset(): pass #try to lock repeatedly
until lock is aquired
+ MUTEX.lock()
self.action_handler.pid_file = None
get_action_from_name(FLOW_GRAPH_STOP).set_sensitive(False)
get_action_from_name(FLOW_GRAPH_EXEC).set_sensitive(True)
Modified: grc/branches/jblum_work/src/Constants.py
===================================================================
--- grc/branches/jblum_work/src/Constants.py 2007-06-27 18:05:27 UTC (rev
5856)
+++ grc/branches/jblum_work/src/Constants.py 2007-06-27 18:26:04 UTC (rev
5857)
@@ -25,6 +25,9 @@
##mutex used when running a flow graph.
MUTEX = mutex.mutex()
+def lock(mutex):
+ while not mutex.testandset(): pass #try to lock repeatedly until
lock is aquired
+MUTEX.lock = lambda: lock(MUTEX)
######################################################################################################
## Global Titles @{
Modified: grc/branches/jblum_work/src/ExecFlowGraph.py
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraph.py 2007-06-27 18:05:27 UTC
(rev 5856)
+++ grc/branches/jblum_work/src/ExecFlowGraph.py 2007-06-27 18:26:04 UTC
(rev 5857)
@@ -26,7 +26,7 @@
from Elements import SignalBlock
from gnuradio import gr
import os
-from Constants import DEFAULT_FILE_EXTENSION
+from Constants import DEFAULT_FILE_EXTENSION,MUTEX
from optparse import OptionParser
##############################################################################################
@@ -39,15 +39,23 @@
gr.top_block.__init__(self, file_path)
#internal data structures
self.callbacks = list()
- self.var_keys = list()
- #access methods to runtime
- runtime = gr.runtime(self)
- self.start = lambda: runtime.start()
- self.stop = lambda: runtime.stop()
+ self.var_keys = list()
+ self.runtime = gr.runtime(self)
+ self.started = False
#build the flow graph
self._parse_nested_data(ParseXML.from_xml(ParseXML.from_file(file_path)))
+
+ def start(self):
+ """Start the flow graph."""
+ self.runtime.start()
+ self.started = True
+
+ def stop(self):
+ """Stop the flow graph."""
+ self.runtime.stop()
+ self.started = False
- def add_window(self, window, type='', title=''):
+ def add_window(self, *args):
"""Empty method for adding a window in the GUI flow graph."""
pass
@@ -66,16 +74,27 @@
def parse_callbacks(self):
"""For each call back, parse all of the data and
call the registered callback function on that data."""
+ MUTEX.lock()
+ print "***\n\nCallback Time BEGIN\n\n***"
+ started = self.started
+ if started: self._hb.lock()
for function, data_type_params in self.callbacks:
+ print "***\nBegin A callback\n%s\n\n***"%function
try:
if type(data_type_params) in (type(list()),
type(tuple())):
function(*map(lambda param:
param.parse(), data_type_params))
else: function(data_type_params.parse())
- except: print "error parsing a callback -> ignoring..."
+ except Exception, e: print "***\n\nerror parsing a
callback -> ignoring\n%s...\n\n***"%e
+ print "***\nEnd A callback\n***"
+ if started: self._hb.unlock()
+ print "***\n\nCallback Time END\n\n***"
+ MUTEX.unlock()
def _parse_nested_data(self, nested_data):
- """Parse nested data from a flow graph file and build the
graphics.
- This code is partially copied from FlowGraph.py, with
unnecessary code removed."""
+ """!
+ Parse nested data from a flow graph file and build the
graphics.
+ @param nested_data the nested flow graph data
+ """
find_data = ParseXML.find_data
flow_graph = find_data([nested_data], 'flow_graph')
vars = find_data(flow_graph, 'vars')
Modified: grc/branches/jblum_work/src/ExecFlowGraphGUI.py
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraphGUI.py 2007-06-27 18:05:27 UTC
(rev 5856)
+++ grc/branches/jblum_work/src/ExecFlowGraphGUI.py 2007-06-27 18:26:04 UTC
(rev 5857)
@@ -32,10 +32,16 @@
# Variable Control
##############################################################################################
class VariableControl(wx.BoxSizer):
- """ House a Slider and a Text Box for variable control. """
+ """House a Slider and a Text Box for variable control."""
def __init__(self, parent, key, parse_callbacks):
- """ Create the slider, text box, and label given the variable
key.
- parse_callbacks is a method to update the registered
signal block callback methods. """
+ """!
+ VariableControl contructor.
+ Create the slider, text box, and label given the variable key.
+ parse_callbacks is a method to update the registered signal
block callback methods.
+ @param parent the wx parent window
+ @param key the variable key
+ @param parse_callbacksa the callback function for variables
+ """
self.key = key
self.parse_callbacks = parse_callbacks
value, min, max, step = Variables.get_values(key)
@@ -63,67 +69,72 @@
sys.exit(1)
slider.Bind(wx.EVT_SCROLL, self._handle_scroll) #bind the
scrolling event
self.Add(slider, 0, wx.ALIGN_CENTER)
- self._handle_enter()#sets the slider's value
+ self._set_slider_value(value)#sets the slider's value
def get_slider_width(self):
- """ Get the width of the slider in pixels. """
+ """!
+ Get the width of the slider.
+ @return the slider width in pixels
+ """
return self.slider_width
def _get_slider_value(self):
- """ Read the value from the slider slider.
- Translate the slider value into a real numerical value. """
+ """!
+ Read the value from the slider and,
+ translate the slider value into a real numerical value.
+ @return the numeric representation of the slider
+ """
slider_value = self.slider.GetValue()
value, min, max, step = Variables.get_values(self.key)
return str(slider_value*(float(max)-float(min))/self.num_steps
+ float(min))
def _set_slider_value(self, real_value):
- """ Translate the real numerical value into a slider value.
- Write the value to the slider. """
+ """!
+ Translate the real numerical value into a slider value and,
+ write the value to the slider.
+ @param real_value the numeric value the slider should represent
+ """
value, min, max, step = Variables.get_values(self.key)
slider_value =
(float(real_value)-float(min))*self.num_steps/(float(max)-float(min))
self.slider.SetValue(slider_value)
def _handle_scroll(self, event=None):
- """ A scroll event is detected. Read the slider. Try to
register the new entry:
+ """A scroll event is detected. Read the slider. Try to register
the new entry:
If the registration passes, update the text box, and parse the
callbacks.
- If the registration fails, restore the slider to the previous
registered values. """
+ If the registration fails, restore the slider to the previous
registered values. """
key = self.key
new_value = str(self._get_slider_value()) #the new value
must be a string!
- value, min, max, step = Variables.get_values(key)
- Variables.unregister(key)
try:
- Variables.register(key, new_value, min, max, step)
- self.text_box.SetValue(str(new_value))
- self.parse_callbacks()
- except:
- Variables.register(key, value, min, max, step)
- self._set_slider_value(value)
+ if Variables.reregister(key, new_value):
self.parse_callbacks()
+ except Exception, e: print 'Error in handle scroll: "%s".'%e
+ self._set_slider_value(Variables.get_value(key))
+ self.text_box.SetValue(Variables.get_value(key))
def _handle_enter(self, event=None):
- """ An enter key was pressed. Read the text box. Try to
register the new entry:
- If the registration passes, move the slider, and parse the
callbacks.
- If the registration fails, restore the text box to the
previous registered value. """
+ """An enter key was pressed. Read the text box. Try to register
the new entry:
+ If the registration passes, move the slider, and parse the
callbacks.
+ If the registration fails, restore the text box to the previous
registered value."""
key = self.key
new_value = str(self.text_box.GetValue()) #the new value
must be a string!
- value, min, max, step = Variables.get_values(key)
- Variables.unregister(key)
try:
- Variables.register(key, new_value, min, max, step)
- self._set_slider_value(new_value)
- self.parse_callbacks()
- except:
- Variables.register(key, value, min, max, step)
- self.text_box.SetValue(value)
+ if Variables.reregister(key, new_value):
self.parse_callbacks()
+ except Exception, e: print 'Error in handle enter: "%s".'%e
+ self._set_slider_value(Variables.get_value(key))
+ self.text_box.SetValue(Variables.get_value(key))
##############################################################################################
# Flow Graph Frame
##############################################################################################
class FlowGraphFrame(wx.Frame, FlowGraphBuilder):
- """ A FlowGraphFrame is a wx.Frame and a FlowGraphBuilder.
+ """A FlowGraphFrame is a wx.Frame and a FlowGraphBuilder.
This flow graph frame parses a saved flow graph file,
houses all the sliders and graphical sinks,
- and starts the flow graph. """
+ and starts the flow graph."""
def __init__(self, file_path):
+ """!
+ FlowGraphFrame contructor.
+ @param file_path the file path to the flow graph
+ """
file_path = os.path.abspath(file_path)
wx.Frame.__init__(self, None , -1, MAIN_WINDOW_PREFIX+' -
Executing: '+file_path)
if WX_APP_ICON: self.SetIcon(wx.Icon(WX_APP_ICON,
wx.BITMAP_TYPE_ANY))
@@ -150,24 +161,33 @@
self.start() #start the flow graph
def _quit(self, event):
- ''' Exit the application. '''
+ """Exit the application."""
self.stop() #stop the flow graph
self.Destroy() #destroy the wx frame
sys.exit(0)
def add_window(self, window, type='', title=''):
- ''' Register the scope/fft window with a unique key. '''
+ """!
+ Register the graphical sink window with a unique key.
+ The key is based on the type and title.
+ @param window the new gui window
+ @param type an integer used to categorize the window
+ @param title the title of the window
+ """
key = str(type) + str(title)
while self.sink_windows.has_key(key): key = key + '_'
self.sink_windows[key] = window
def get_panel(self):
- ''' Get the panel that will parent the graphical blocks.
'''
+ """!
+ Get the panel that will parent the graphical blocks.
+ @return the wx panel
+ """
return self.panel
def _create_sliders(self):
- ''' Using the list of variable keys imported by the builder,
- create sliders for those variables with ranges. '''
+ """Using the list of variable keys imported by the builder,
+ create sliders for those variables with ranges."""
len = 0
for key in self.var_keys:
value, min, max, step = Variables.get_values(key)
@@ -186,13 +206,21 @@
# Flow Graph App
##############################################################################################
class FlowGraphApp(wx.App):
- """ The FlowGraphApp is the wx.App containing the FlowGraphFrame.
"""
+ """The FlowGraphApp is the wx.App containing the FlowGraphFrame."""
def __init__(self, flow_graph_file_path):
+ """!
+ FlowGraphApp constructor.
+ @param flow_graph_file_path the file path to the flow graph
+ """
self.flow_graph_file_path = flow_graph_file_path
wx.App.__init__(self, 0)
def OnInit(self):
- """ If the creation of the frame fails, exit with error.
"""
+ """!
+ Create the top level flow graph frame.
+ If the creation of the frame fails, exit with error.
+ @return true if the flow graph frame is created
+ """
try:
self.SetTopWindow(FlowGraphFrame(self.flow_graph_file_path))#first argument is
the flow graph
return True
Modified: grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py 2007-06-27 18:05:27 UTC
(rev 5856)
+++ grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py 2007-06-27 18:26:04 UTC
(rev 5857)
@@ -56,16 +56,10 @@
""" Value can be any type (will be cast to a string below).
Register the new value and call parse callbacks.
Return the new value as a string. """
- value, min, max, step = Variables.get_values(key)
- Variables.unregister(key)
- try:
- new_value = str(new_value) #must be a string
- Variables.register(key, new_value, min, max, step)
- self.parse_callbacks()
- except Exception, e: #restore variable and raise Error
- Variables.register(key, value, min, max, step)
- raise Error, e
- return new_value
+ try:
+ if Variables.reregister(key, new_value):
self.parse_callbacks()
+ except: pass
+ return Variables.get_value(key)
##############################################################################################
# Main
Modified: grc/branches/jblum_work/src/SignalBlockDefs/Packet.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/Packet.py 2007-06-27
18:05:27 UTC (rev 5856)
+++ grc/branches/jblum_work/src/SignalBlockDefs/Packet.py 2007-06-27
18:26:04 UTC (rev 5857)
@@ -71,10 +71,9 @@
class PacketModHelper(gr.hier_block2):
"""Forward data from the gr data stream to the mod packet."""
- def __init__(self, fg, item_size, packet_length, samples_per_symbol,
bits_per_symbol, access_code, pad_for_usrp, use_whitener_offset):
+ def __init__(self, item_size, packet_length, samples_per_symbol,
bits_per_symbol, access_code, pad_for_usrp, use_whitener_offset):
"""!
PacketModHelper constructor.
- @param fg the flow graph
@param item_size the size in bytes of the input data stream
@param packet_length the length in bytes of the packets
@param *args the arguments for blks.mod_pkts
@@ -91,7 +90,7 @@
modulator.bits_per_symbol = lambda: bits_per_symbol
#create the packet modulator (handles the output data stream)
packet_mod = blks.mod_pkts(
- fg=fg,
+ fg=self,
modulator=modulator,
access_code=access_code,
msgq_limit=DEFAULT_QUEUE_LIMIT,
@@ -109,10 +108,9 @@
class PacketDemodHelper(gr.hier_block2):
"""Forward data from demod packet to the gr data stream."""
- def __init__(self, fg, item_size, access_code, threshold):
+ def __init__(self, item_size, access_code, threshold):
"""!
PacketDemodHelper constructor.
- @param fg the flow graph
@param item_size the size in bytes of the output data stream
@param *args the arguments for blks.demod_pkts
@param msgq_limit the queue limit for the message source
@@ -132,7 +130,7 @@
demodulator = gr.skiphead(Byte().get_num_bytes(), 0)
#create the packet demodulator (handles the input data stream)
packet_demod = blks.demod_pkts(
- fg=fg,
+ fg=self,
demodulator=demodulator,
access_code=access_code,
callback=callback,
@@ -188,7 +186,6 @@
if packet_length%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".'%(packet_length, item_size))
return PacketModHelper(
- fg=fg,
item_size=item_size,
packet_length=packet_length,
samples_per_symbol=samples_per_symbol.parse(),
@@ -220,7 +217,6 @@
access_code = access_code.parse()
if access_code == '': access_code = None #access code
should be None if blank
return PacketDemodHelper(
- fg=fg,
item_size=type.parse().get_num_bytes(),
access_code=access_code,
threshold=threshold.parse(),
Modified: grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py 2007-06-27
18:05:27 UTC (rev 5856)
+++ grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py 2007-06-27
18:26:04 UTC (rev 5857)
@@ -125,13 +125,12 @@
complex_data = numpy.fromstring (s, numpy.float32)
if len(complex_data) == 2: new_value = "%f +
%fj"%(complex_data[0], complex_data[1])
else: new_value = "%f"%(complex_data[0],)
- while not MUTEX.testandset(): pass #try to lock
repeatedly until lock is aquired
+ #MUTEX.lock()
# write the new value #
- Variables.unregister(self.var_key)
- Variables.register(self.var_key, new_value)
+ Variables.reregister(self.var_key, new_value)
# parse the call backs #
self.fg.parse_callbacks()
- MUTEX.unlock()
+ #MUTEX.unlock()
def VariableSink(sb):
type = Enum(all_choices, 1)
Modified: grc/branches/jblum_work/src/Variables.py
===================================================================
--- grc/branches/jblum_work/src/Variables.py 2007-06-27 18:05:27 UTC (rev
5856)
+++ grc/branches/jblum_work/src/Variables.py 2007-06-27 18:26:04 UTC (rev
5857)
@@ -88,6 +88,27 @@
### register the values ###
VARS_DICT[key] = (value, min, max, step)
+def reregister(key, new_value):
+ """!
+ Register a new value for variable:
+ Unregister the variable and try to register it with the new values.
+ If an exception is raised, register the old values.
+ @param key the variable key
+ @param new_value the value
+ @throw Exception invalid arguments
+ @return true if the variable was registered
+ """
+ value, min, max, step = get_values(key)
+ if new_value != value:
+ unregister(key)
+ try:
+ register(key, new_value, min, max, step)
+ return True
+ except Exception, e:
+ register(key, value, min, max, step)
+ raise e
+ else: return False
+
def is_key_name_valid(key_name):
"""!
Is the key valid?
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5857 - in grc/branches/jblum_work/src: . SignalBlockDefs,
jblum <=