Changed Argument Parsing for sim_vehicle.py
The arguments now properly pare the arguments passed through to the ardupilot instance and to mavproxy.
This commit is contained in:
parent
b014b6c857
commit
014702fc64
@ -629,9 +629,36 @@ def start_mavproxy(opts, stuff):
|
||||
if "extra_mavlink_cmds" in stuff:
|
||||
extra_cmd += " " + stuff["extra_mavlink_cmds"]
|
||||
|
||||
# Parsing the arguments to pass to mavproxy, split args on space and "=" signs and ignore those signs within quotation marks
|
||||
if opts.mavproxy_args:
|
||||
# this could be a lot better:
|
||||
cmd.extend(opts.mavproxy_args.split(" "))
|
||||
# It would be great if this could be done with regex
|
||||
mavargs = opts.mavproxy_args.split(" ")
|
||||
# Find the arguments with '=' in them and split them up
|
||||
for i, x in enumerate(mavargs):
|
||||
if '=' in x:
|
||||
mavargs[i] = x.split('=')[0]
|
||||
mavargs.insert(i+1, x.split('=')[1])
|
||||
# Use this flag to tell if parsing character inbetween a pair of quotation marks
|
||||
inString = False
|
||||
beginStringIndex = []
|
||||
endStringIndex = []
|
||||
# Iterate through the arguments, looking for the arguments that
|
||||
# begin with a quotation mark and the ones that end with a quotation mark
|
||||
for i, x in enumerate(mavargs):
|
||||
if not inString and x[0] == "\"":
|
||||
beginStringIndex.append(i)
|
||||
mavargs[i] = x[1:]
|
||||
inString = True
|
||||
elif inString and x[-1] == "\"":
|
||||
endStringIndex.append(i)
|
||||
inString = False
|
||||
mavargs[i] = x[:-1]
|
||||
# Replace the list items with one string to be passed into mavproxy
|
||||
for begin, end in zip(beginStringIndex, endStringIndex):
|
||||
replacement = " ".join(mavargs[begin:end+1])
|
||||
mavargs[begin] = replacement
|
||||
mavargs = mavargs[0:begin+1] + mavargs[end+1:]
|
||||
cmd.extend(mavargs)
|
||||
|
||||
# compatibility pass-through parameters (for those that don't want
|
||||
# to use -C :-)
|
||||
|
Loading…
Reference in New Issue
Block a user