Commit a508f5b2 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

changed responses format

parent ace36ad6
...@@ -69,6 +69,10 @@ def cmd_callback(req,res): ...@@ -69,6 +69,10 @@ def cmd_callback(req,res):
print("Parsed command:") print("Parsed command:")
print(q) print(q)
if q['cmd']=='list':
res.response = '<?xml version="1.0"?><document>'+'\n'.join(['<target>'+c+'</target>' for c in q['targets']])+'</document>'
return res
if q['cmd']=='state': if q['cmd']=='state':
cmd_func = pass_cmd cmd_func = pass_cmd
...@@ -88,7 +92,7 @@ def cmd_callback(req,res): ...@@ -88,7 +92,7 @@ def cmd_callback(req,res):
# if n/a # if n/a
if not cli.wait_for_service(timeout_sec=1.0): if not cli.wait_for_service(timeout_sec=1.0):
cmdres = "<response><node>"+tgt+"</node><state>dead</state></response>" cmdres = "<response><node>"+t+"</node><state>dead</state></response>"
else: else:
# timer?! # timer?!
timer = g_node.create_timer(0.0, cmd_func, callback_group=cb_group) timer = g_node.create_timer(0.0, cmd_func, callback_group=cb_group)
...@@ -100,12 +104,12 @@ def cmd_callback(req,res): ...@@ -100,12 +104,12 @@ def cmd_callback(req,res):
# spin until it gets "blue" # spin until it gets "blue"
while rclpy.ok() and not did_get_result: while rclpy.ok() and not did_get_result:
rclpy.spin_once(g_node) rclpy.spin_once(g_node)
cmdres = cmd_result.response cmdres = "<response><node>"+t+"</node>"+cmd_result.response+"</response>"
# store response # store response
reslist.append(cmdres) reslist.append(cmdres)
# convert to string # convert to string
res.response = '\n'.join(reslist) res.response = '<?xml version="1.0"?><document>'+'\n'.join(reslist)+'</document>'
return res return res
......
...@@ -32,7 +32,7 @@ def cmd_callback(req,res): ...@@ -32,7 +32,7 @@ def cmd_callback(req,res):
print(q) print(q)
if q['cmd']=='state': if q['cmd']=='state':
res.response = '<response><node>'+nodename+'</node><state>idle</state></response>' res.response = '<state>idle</state>'
else: else:
# call to localhost here, get response and send it back # call to localhost here, get response and send it back
try: try:
...@@ -40,7 +40,7 @@ def cmd_callback(req,res): ...@@ -40,7 +40,7 @@ def cmd_callback(req,res):
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
output = "<error>CalledProcessError</error>".encode() output = "<error>CalledProcessError</error>".encode()
res.response = '<response><node>'+nodename+'</node><state>'+output.decode()+'</state></response>' res.response = '<state>'+output.decode()+'</state>'
print('Slave sending: '+res.response) print('Slave sending: '+res.response)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment