summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorNélio Laranjeiro2009-07-13 16:56:36 +0200
committerNélio Laranjeiro2009-07-13 16:56:36 +0200
commitbc6e46cce9e2f6e4555a2c6cff1521a522156c6d (patch)
treecb36983f58beaa124d2ea081e8f902a8727d40b3 /tools
parent41813460998b22f7ea3ac35ae6f8f9cda3886ac9 (diff)
*tools/trace:
* Added the possibility to add a callback file containing the function to decode traces. See the example/trace.trc to use it, the file containing the callback must be provided using the -c option in the interpretor.
Diffstat (limited to 'tools')
-rw-r--r--tools/trace/example/__init__.py0
-rw-r--r--tools/trace/example/callback.py4
-rw-r--r--tools/trace/example/trace.trc2
-rw-r--r--tools/trace/lib/parser.g7
-rw-r--r--tools/trace/lib/traceclass.py3
-rw-r--r--tools/trace/tinter/tinter.py15
-rw-r--r--tools/trace/trace.py4
7 files changed, 28 insertions, 7 deletions
diff --git a/tools/trace/example/__init__.py b/tools/trace/example/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tools/trace/example/__init__.py
diff --git a/tools/trace/example/callback.py b/tools/trace/example/callback.py
new file mode 100644
index 00000000..84876016
--- /dev/null
+++ b/tools/trace/example/callback.py
@@ -0,0 +1,4 @@
+def ia (data):
+ string = "\"IA arg1: %d arg2: %d arg3: %d\""
+ string = string % tuple (data)
+ return string
diff --git a/tools/trace/example/trace.trc b/tools/trace/example/trace.trc
index 58b9e19a..cb9e9bdb 100644
--- a/tools/trace/example/trace.trc
+++ b/tools/trace/example/trace.trc
@@ -1,3 +1,3 @@
EVENT asserv__right_motor speed 4 position 4 acceleration 2 "Right motor speed : %d, position : %d, acceleration : %d"
EVENT asserv__left_motor speed 4 position 4 acceleration 2 "Left motor speed : %d, position : %d, acceleration : %d"
-EVENT ia__ia_cmd arg1 2 arg2 2 arg3 4 "IA cmd, arg1 : %d, arg2 : %d, arg3 : %d"
+EVENT ia__ia_cmd arg1 2 arg2 2 arg3 4 [ia]
diff --git a/tools/trace/lib/parser.g b/tools/trace/lib/parser.g
index 2cee66b5..ba4e974f 100644
--- a/tools/trace/lib/parser.g
+++ b/tools/trace/lib/parser.g
@@ -12,6 +12,7 @@ parser TraceParser:
token PARAM: "[a-zA-Z_1-9]+"
token LENGTH: "[1-2-4]"
token STRING: "\".*\""
+ token CB: "[a-zA-Z_]+"
token SPACE: " "
rule parser: START {{ my_list = list() }}
@@ -24,9 +25,13 @@ parser TraceParser:
( param SPACE {{ e.param_add (param[0], param[1]) }}
)*
( string {{ e.string_set (string) }}
- )*
+ )?
+ ( cb {{ e.callback = cb }}
+ )?
"\n" {{ return e }}
rule param: PARAM SPACE LENGTH {{ return [PARAM.strip(), int(LENGTH.strip())] }}
rule string: STRING {{ return (STRING.strip()) }}
+
+ rule cb: "\[" CB "\]" {{ return (CB.strip()) }}
diff --git a/tools/trace/lib/traceclass.py b/tools/trace/lib/traceclass.py
index 4c194c73..27b9ba53 100644
--- a/tools/trace/lib/traceclass.py
+++ b/tools/trace/lib/traceclass.py
@@ -21,6 +21,7 @@ class TraceEvent:
self.__name = name
self.__param_list = list()
self.__string = ""
+ self.callback = None
def name (self):
return self.__name
@@ -28,7 +29,7 @@ class TraceEvent:
def param_add (self, name, length):
param = TraceParam (name, length)
self.__param_list.append(param)
-
+
def param_get (self, pos):
if pos <= len (self.__param_list):
return self.__param_list[pos]
diff --git a/tools/trace/tinter/tinter.py b/tools/trace/tinter/tinter.py
index 1491f6a8..f326d27f 100644
--- a/tools/trace/tinter/tinter.py
+++ b/tools/trace/tinter/tinter.py
@@ -10,12 +10,13 @@ except:
class TInter:
- def __init__(self, infile, outfile, prgm):
+ def __init__(self, infile, outfile, prgm, cb):
self.__infile = infile
self.__events = None
self.__outfile = outfile
self.__file = None
self.__host = THost(prgm)
+ self.__cb_file = cb.strip('.py').replace('/', '.')
def __events_get (self):
infile = open (self.__infile, 'r')
@@ -23,20 +24,28 @@ class TInter:
infile.close()
return events
+ def __callback (self, event, data):
+ if event.callback == None:
+ string = event.string_get()
+ string = string % tuple (data)
+ else:
+ exec "from " + self.__cb_file + " import " + event.callback
+ string = locals()[event.callback](data)
+ return string
+
def __event_print (self, events, memory):
if len(memory) > 0:
cmd = get_size (memory, 2)
memory = memory[2:]
if cmd < len(events):
e = events[cmd]
- string = e.string_get()
vals = [ ]
for i in range (0, e.param_nb()):
p = e.param_get(i)
size = p.length()
vals.append (get_size (memory, size))
memory = memory[size:]
- string = string % tuple (vals)
+ string = self.__callback (e, vals)
if self.__file == None:
print string[1:len(string)-1]
diff --git a/tools/trace/trace.py b/tools/trace/trace.py
index b4010a25..e6a2c756 100644
--- a/tools/trace/trace.py
+++ b/tools/trace/trace.py
@@ -24,6 +24,8 @@ parser.add_option("-l", "--list", dest="list_trace", action="store_true",
help="List the number of the traces" + INTER_MODE)
parser.add_option("-n", "--num", type="int", dest="trace",
help="Dump the trace number provided" + INTER_MODE)
+parser.add_option("-c", "--callback", dest="cb",
+ help="The callback file containing the functions" + INTER_MODE)
[options, args] = parser.parse_args()
@@ -31,7 +33,7 @@ if options.type == 'create':
cre = TCreator (options.infile, options.outfile, options.enum_name)
cre.create ()
elif options.type == "inter":
- inter = TInter (options.infile, options.outfile, args[0])
+ inter = TInter (options.infile, options.outfile, args[0], options.cb)
if options.list_trace:
inter.available_traces ()
elif options.trace != None: