Commit a508f5b2 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev
Browse files

changed responses format

parent ace36ad6
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -69,6 +69,10 @@ def cmd_callback(req,res):
  print("Parsed command:")
  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':
    cmd_func = pass_cmd
  
@@ -88,7 +92,7 @@ def cmd_callback(req,res):

    # if n/a
    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:
      # timer?!
      timer = g_node.create_timer(0.0, cmd_func, callback_group=cb_group)
@@ -100,12 +104,12 @@ def cmd_callback(req,res):
      # spin until it gets "blue"
      while rclpy.ok() and not did_get_result:
        rclpy.spin_once(g_node)
      cmdres = cmd_result.response
      cmdres  = "<response><node>"+t+"</node>"+cmd_result.response+"</response>"
    # store response
    reslist.append(cmdres)

  # convert to string
  res.response = '\n'.join(reslist)
  res.response = '<?xml version="1.0"?><document>'+'\n'.join(reslist)+'</document>'
  return res


+2 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ def cmd_callback(req,res):
  print(q)

  if q['cmd']=='state':
    res.response = '<response><node>'+nodename+'</node><state>idle</state></response>'
    res.response = '<state>idle</state>'
  else:
    # call to localhost here, get response and send it back
    try:
@@ -40,7 +40,7 @@ def cmd_callback(req,res):
    except subprocess.CalledProcessError:
      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)