[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5751 - in grc/branches/jblum_work: examples examples/
From: |
jblum |
Subject: |
[Commit-gnuradio] r5751 - in grc/branches/jblum_work: examples examples/xmlrpc notes src src/SignalBlockDefs |
Date: |
Fri, 8 Jun 2007 20:07:29 -0600 (MDT) |
Author: jblum
Date: 2007-06-08 20:07:29 -0600 (Fri, 08 Jun 2007)
New Revision: 5751
Added:
grc/branches/jblum_work/examples/xmlrpc/
grc/branches/jblum_work/examples/xmlrpc/client.py
grc/branches/jblum_work/examples/xmlrpc/readme.txt
grc/branches/jblum_work/examples/xmlrpc/server.sh
grc/branches/jblum_work/examples/xmlrpc/tone.grc.xml
grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py
Modified:
grc/branches/jblum_work/notes/notes.txt
grc/branches/jblum_work/src/Editor.py
grc/branches/jblum_work/src/ExecFlowGraph.py
grc/branches/jblum_work/src/ExecFlowGraphGUI.py
grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py
grc/branches/jblum_work/src/Variables.py
Log:
created fg executor and examples implementing xmlrpc server/client
Added: grc/branches/jblum_work/examples/xmlrpc/client.py
===================================================================
--- grc/branches/jblum_work/examples/xmlrpc/client.py
(rev 0)
+++ grc/branches/jblum_work/examples/xmlrpc/client.py 2007-06-09 02:07:29 UTC
(rev 5751)
@@ -0,0 +1,33 @@
+#! /usr/bin/env python
+"""
+Copyright 2007 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+"""
+
+from xmlrpclib import ServerProxy,Error
+import time
+
+server = ServerProxy("http://localhost:3030")
+print server
+
+try:
+ for i in list(range(-4, 8))+list(reversed(range(-4, 9))):
+ print server.set_var('freq', 440*2**(i/12.0))
+ time.sleep(1)
+ server.set_var('freq', 0)
+except Error, v:
+ print "ERROR", v
Property changes on: grc/branches/jblum_work/examples/xmlrpc/client.py
___________________________________________________________________
Name: svn:executable
+ *
Added: grc/branches/jblum_work/examples/xmlrpc/readme.txt
===================================================================
--- grc/branches/jblum_work/examples/xmlrpc/readme.txt
(rev 0)
+++ grc/branches/jblum_work/examples/xmlrpc/readme.txt 2007-06-09 02:07:29 UTC
(rev 5751)
@@ -0,0 +1,12 @@
+##############################################
+# Executing the example
+##############################################
+
+!This example requires audio support in gnuradio
+
+Start the server by executing server.sh in this directory.
+The server.sh script will execute ExecFlowGraphXMLRPC.py on tone.grc.xml
+
+Start the client by executing client.py.
+The client will change the frequency of the tone once per second.
+The client changes the tone by making XMLRPC calls that set the variable
'freq'.
Added: grc/branches/jblum_work/examples/xmlrpc/server.sh
===================================================================
--- grc/branches/jblum_work/examples/xmlrpc/server.sh
(rev 0)
+++ grc/branches/jblum_work/examples/xmlrpc/server.sh 2007-06-09 02:07:29 UTC
(rev 5751)
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+ADDR=localhost
+PORT=3030
+FLOWGRAPH=./tone.grc.xml
+
+python ../../src/ExecFlowGraphXMLRPC.py $FLOWGRAPH -a $ADDR -P $PORT
Property changes on: grc/branches/jblum_work/examples/xmlrpc/server.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: grc/branches/jblum_work/examples/xmlrpc/tone.grc.xml
===================================================================
--- grc/branches/jblum_work/examples/xmlrpc/tone.grc.xml
(rev 0)
+++ grc/branches/jblum_work/examples/xmlrpc/tone.grc.xml 2007-06-09
02:07:29 UTC (rev 5751)
@@ -0,0 +1,60 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<flow_graph>
+ <timestamp>1181338235.34</timestamp>
+ <hostname>tiggle</hostname>
+ <version>0.70 alpha</version>
+ <valid>True</valid>
+ <window_width>1600</window_width>
+ <window_height>1200</window_height>
+ <vars>
+ <var>
+ <key>samp_rate</key>
+ <value>100e3</value>
+ <min/>
+ <max/>
+ <step/>
+ </var>
+ <var>
+ <key>freq</key>
+ <value>0</value>
+ <min>0</min>
+ <max>5000</max>
+ <step>50.0</step>
+ </var>
+ </vars>
+ <signal_blocks>
+ <signal_block>
+ <tag>Audio Sink</tag>
+ <id>Audio Sink0</id>
+ <x_coordinate>529</x_coordinate>
+ <y_coordinate>67</y_coordinate>
+ <rotation>0</rotation>
+ <params>
+ <param>3</param>
+ </params>
+ </signal_block>
+ <signal_block>
+ <tag>Signal Source</tag>
+ <id>Signal Source0</id>
+ <x_coordinate>282</x_coordinate>
+ <y_coordinate>227</y_coordinate>
+ <rotation>0</rotation>
+ <params>
+ <param>1</param>
+ <param>$samp_rate</param>
+ <param>1</param>
+ <param>$freq</param>
+ <param>.5</param>
+ <param>0</param>
+ </params>
+ </signal_block>
+ </signal_blocks>
+ <connections>
+ <connection>
+ <input_signal_block_id>Audio Sink0</input_signal_block_id>
+ <input_socket_index>0</input_socket_index>
+ <output_signal_block_id>Signal Source0</output_signal_block_id>
+ <output_socket_index>0</output_socket_index>
+ </connection>
+ </connections>
+</flow_graph>
Modified: grc/branches/jblum_work/notes/notes.txt
===================================================================
--- grc/branches/jblum_work/notes/notes.txt 2007-06-08 20:18:31 UTC (rev
5750)
+++ grc/branches/jblum_work/notes/notes.txt 2007-06-09 02:07:29 UTC (rev
5751)
@@ -17,7 +17,6 @@
############ Features to Add: ####################
-save settings after close (working directory)
-create sub-flow graphs to be used in larger flow graphs
--stdin/out communication protocal (non graphical)
-include dtd in saved flow graphs
-immediate display of tool tips in entry boxes
-function to import taps from a file
Modified: grc/branches/jblum_work/src/Editor.py
===================================================================
--- grc/branches/jblum_work/src/Editor.py 2007-06-08 20:18:31 UTC (rev
5750)
+++ grc/branches/jblum_work/src/Editor.py 2007-06-09 02:07:29 UTC (rev
5751)
@@ -31,7 +31,7 @@
version = """
GNU Radio Companion %s
-This file is part of GNU Radio
+This program is part of GNU Radio
GRC comes with ABSOLUTELY NO WARRANTY.
This is free software,
and you are welcome to redistribute it.
Modified: grc/branches/jblum_work/src/ExecFlowGraph.py
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraph.py 2007-06-08 20:18:31 UTC
(rev 5750)
+++ grc/branches/jblum_work/src/ExecFlowGraph.py 2007-06-09 02:07:29 UTC
(rev 5751)
@@ -25,7 +25,6 @@
import ParseXML
import Variables
-import SignalBlockDefs
from Elements import SignalBlock
from gnuradio import gr
import os
@@ -98,18 +97,40 @@
(signal_blocks_dict[output_signal_block_id],
output_socket_index),
(signal_blocks_dict[input_signal_block_id],
input_socket_index))
+##############################################################################################
+# Option Parser for running a flow graph
+##############################################################################################
+class FlowGraphOptionParser(OptionParser):
+ """ This flow graph option parser provides a basic help,
+ and ensures that a flow graph is passed on the command line.
"""
+ def __init__(self):
+ """ Create the base option parser and add usage and basic
options. """
+ usage = "usage: %prog [options]
flow_graph"+DEFAULT_FILE_EXTENSION
+ OptionParser.__init__(self, usage=usage)
+ self.add_option("-p", "--pid_file", action="store",
type="string", dest="pid_file", help="record process id")
+
+ def parse_args(self):
+ """ Call the base parse_args, handle the basic options,
+ and ensure a flow graph was passed in args. Return the
(options, args). """
+ (options, args) = OptionParser.parse_args(self)
+ if options.pid_file:
+ try: open(options.pid_file, 'w').write('%d\n' %
os.getpid())
+ except:
+ print '\nCould not create pid file:
"%s".\nExiting!'%options.pid_file
+ exit(-1)
+ if not len(args):
+ self.print_help()
+ exit(-1)
+ return options, args
+
+##############################################################################################
+# Main
+##############################################################################################
if __name__ == '__main__':
- usage = "usage: %prog [-p] flow_graph"+DEFAULT_FILE_EXTENSION
- parser = OptionParser(usage=usage)
- parser.add_option("-p", "--pid_file", action="store", type="string",
dest="pid_file", help="record process id")
- (options, args) = parser.parse_args()
- if options.pid_file:
- try: open(options.pid_file, 'w').write('%d\n' % os.getpid())
- except: print "could not create pid file: %s"%options.pid_file
- if len(args): #only create the flow graph if a file was passed
- fg = FlowGraphBuilder(args[0])
- fg.start()
- raw_input('Flow Graph Running...\nPress Enter to Exit: ')
- fg.stop()
- else: parser.print_help()
+ parser = FlowGraphOptionParser()
+ (options, args) = parser.parse_args()
+ fg = FlowGraphBuilder(args[0])
+ fg.start()
+ raw_input('Flow Graph Running...\nPress Enter to Exit: ')
+ fg.stop()
\ No newline at end of file
Modified: grc/branches/jblum_work/src/ExecFlowGraphGUI.py
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraphGUI.py 2007-06-08 20:18:31 UTC
(rev 5750)
+++ grc/branches/jblum_work/src/ExecFlowGraphGUI.py 2007-06-09 02:07:29 UTC
(rev 5751)
@@ -24,12 +24,11 @@
"""
import Variables
-from ExecFlowGraph import FlowGraphBuilder
+from ExecFlowGraph import FlowGraphBuilder,FlowGraphOptionParser
import wx
import os
from Constants import *
import math
-from optparse import OptionParser
##############################################################################################
# Variable Control
@@ -202,20 +201,16 @@
except Exception, e:
sys.stderr.write(str(e)+'\n')
sys.exit(1)
-
+
+##############################################################################################
+# Main
+##############################################################################################
if __name__ == '__main__':
- usage = "usage: %prog [-p] flow_graph"+DEFAULT_FILE_EXTENSION
- parser = OptionParser(usage=usage)
- parser.add_option("-p", "--pid_file", action="store", type="string",
dest="pid_file", help="record process id")
+ parser = FlowGraphOptionParser()
parser.add_option("-d", "--disable-wx", action="store_true",
dest="no_wx", default=False, help="disable the wx gui")
(options, args) = parser.parse_args()
- if options.pid_file:
- try: open(options.pid_file, 'w').write('%d\n' % os.getpid())
- except: print "could not create pid file: %s"%options.pid_file
- if len(args): #only create the wx app if a flow graph was passed
- app = FlowGraphApp(args[0])
- if options.no_wx: raw_input('Flow Graph Running...\nPress Enter
to Exit: ') #do not start wx
- else: app.MainLoop() #start the wxApp MainLoop
- else: parser.print_help()
+ app = FlowGraphApp(args[0])
+ if options.no_wx: raw_input('Flow Graph Running...\nPress Enter to
Exit: ') #do not start wx
+ else: app.MainLoop() #start the wxApp MainLoop
\ No newline at end of file
Copied: grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py (from rev 5692,
grc/branches/jblum_work/src/ExecFlowGraph.py)
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py
(rev 0)
+++ grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py 2007-06-09 02:07:29 UTC
(rev 5751)
@@ -0,0 +1,89 @@
+#! /usr/bin/env python
+"""
+Copyright 2007 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+"""
+"""
+ ExecFlowGraphXMLRPC.py
+ Josh Blum
+ Use a xml input file to build and run a gnu radio flow graph without
graphics.
+ Create an XMLRPC sever to control the running flow graph.
+"""
+
+from SimpleXMLRPCServer import SimpleXMLRPCServer
+from xmlrpclib import Error
+from ExecFlowGraph import FlowGraphBuilder,FlowGraphOptionParser
+import Variables
+
+DEFAULT_ADDR = 'localhost'
+DEFAULT_PORT = 3030
+
+##############################################################################################
+# Flow Graph Access
+##############################################################################################
+class FlowGraphAccess(FlowGraphBuilder):
+ """ Implement a flow graph builder,
+ and provide access functions for the xmlrpc server. """
+
+ def get_var_key_list(self):
+ """ Get a list of all possible variable keys. """
+ return self.var_keys #the var keys in order
+
+ def get_var_range(self, key):
+ """ Return the min and the max of a variable (strings). """
+ value, min, max, step = Variables.get_values(key)
+ return str(min), str(max)
+
+ def set_var(self, key, new_value):
+ """ 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(str(e))
+ return new_value
+
+##############################################################################################
+# Main
+##############################################################################################
+if __name__ == '__main__':
+ parser = FlowGraphOptionParser()
+ parser.add_option("-a", "--addr", action="store", type="string",
dest="addr", default=DEFAULT_ADDR, help='bind address for XMLRPC server')
+ parser.add_option("-P", "--port", action="store", type="int",
dest="port", default=DEFAULT_PORT, help='tcp port for XMLRPC server')
+ (options, args) = parser.parse_args()
+ fg = FlowGraphAccess(args[0]) #create the flow graph
+ server = SimpleXMLRPCServer((options.addr, options.port)) #create
the xmlrpc server
+ # register access methods #
+ server.register_function(lambda key: bool(Variables.is_ranged(key)),
"var_has_range")
+ server.register_function(lambda key: bool(Variables.has_key(key)),
"var_exists")
+ server.register_function(fg.get_var_key_list, "get_var_key_list")
+ server.register_function(lambda key: str(Variables.get_value(key)),
"get_var")
+ server.register_function(fg.get_var_range, "get_var_range")
+ server.register_function(fg.set_var, "set_var")
+ server.register_function(fg.start, "start_fg")
+ server.register_function(fg.stop, "stop_fg")
+ fg.start() #start the flow graph
+ print 'Starting XMLRPC server on address: "%s" and port:
"%d"'%(options.addr, options.port)
+ server.serve_forever() #start the xmlrpc server
+
+
\ No newline at end of file
Modified: grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py 2007-06-08
20:18:31 UTC (rev 5750)
+++ grc/branches/jblum_work/src/SignalBlockDefs/Sinks.py 2007-06-09
02:07:29 UTC (rev 5751)
@@ -25,7 +25,7 @@
from DataType import *
from gnuradio import gr
from SignalBlockConstants import *
-from Constants import DEFAULT_FILE_PATH
+from Constants import DEFAULT_FILE_PATH,MUTEX
def NullSink(sb):
type = Enum(all_choices, 1)
@@ -85,7 +85,7 @@
import threading
import Variables
-import Numeric
+import numpy
class VariableSinkThread(threading.Thread):
""" This thread will read the vector sink at the sampling rate,
@@ -114,15 +114,19 @@
start = itemsize * (nitems - 1)
s = s[start:start+itemsize]
# parse the data to a complex or
float/int string #
- complex_data = Numeric.fromstring (s,
Numeric.Float32)
+ 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],)
+ else: new_value = "%f"%(complex_data[0],)
+ while not MUTEX.testandset(): pass #try to
lock repeatedly until lock is aquired
# write the new value #
Variables.unregister(self.var_key)
Variables.register(self.var_key, new_value)
# parse the call backs #
self.fg.parse_callbacks()
- except: break
+ MUTEX.unlock()
+ except Exception, e:
+ print "done",self.var_key, e
+ break
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-08 20:18:31 UTC (rev
5750)
+++ grc/branches/jblum_work/src/Variables.py 2007-06-09 02:07:29 UTC (rev
5751)
@@ -98,9 +98,8 @@
return key in VARS_DICT
def get_values(key):
- ''' Get the tuple for this key, otherwise None. '''
- if has_key(key): return VARS_DICT[key]
- else: return None
+ ''' Get the tuple for this key. '''
+ return VARS_DICT[key]
def is_ranged(key):
''' Does this variable have a range:
@@ -108,9 +107,8 @@
return get_values(key)[1] != ''
def get_value(key):
- ''' Get the value for this key, otherwise None. '''
- if has_key(key): return VARS_DICT[key][0]
- else: return None
+ ''' Get the value for this key. '''
+ return VARS_DICT[key][0]
def replace_var_instances(string):
''' Replace every instance of a marker + variable key
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5751 - in grc/branches/jblum_work: examples examples/xmlrpc notes src src/SignalBlockDefs,
jblum <=