Fixed code style

This commit is contained in:
kevindehecker
2016-03-15 10:31:07 +01:00
parent 6d874bc4e8
commit 55844c2289
+58 -56
View File
@@ -11,69 +11,71 @@ firmware_file = sys.argv[2]
print "Target: " + target print "Target: " + target
print "Firmware file: " + firmware_file print "Firmware file: " + firmware_file
#test if pprz cdm is connected # test if pprz cdm is connected
mode =-1 mode = -1
port = "" port = ""
try : try:
port = "/dev/serial/by-id/usb-Paparazzi_UAV_CDC_Serial_STM32_*" port = "/dev/serial/by-id/usb-Paparazzi_UAV_CDC_Serial_STM32_*"
if len(glob.glob(port)) > 1: if len(glob.glob(port)) > 1:
print("Warning: multiple Paparazzi cdc devices found. Selecting the first one.") print("Warning: multiple Paparazzi cdc devices found. Selecting the first one.")
port = glob.glob(port)[0] port = glob.glob(port)[0]
ser = serial.Serial(port,timeout=0.5) ser = serial.Serial(port, timeout=0.5)
mode = 1 mode = 1
print ("Paparazzi CDC device found at port: " + port) print ("Paparazzi CDC device found at port: " + port)
except (serial.serialutil.SerialException,IndexError) : except (serial.serialutil.SerialException, IndexError):
print("No Paparazzi CDC device found, looking further.") print("No Paparazzi CDC device found, looking further.")
if mode == 1 : if mode == 1:
if target == "fbw" : if target == "fbw":
line = "pprz0" line = "pprz0"
else : else:
line = "pprz1" line = "pprz1"
print ("Sending target command to Paparazzi firmware...") print ("Sending target command to Paparazzi firmware...")
ser.flush() ser.flush()
ser.write(line) ser.write(line)
if target == "fbw" : if target == "fbw":
try : try:
c = ser.read(7) c = ser.read(7)
print ("AP responded with: " + c) print ("AP responded with: " + c)
if c=="TIMEOUT" : if c == "TIMEOUT":
print("Error: FBW bootloader TIMEOUT. Power cycle the board and wait between 5 seconds to 20 seconds to retry.") print(
sys.exit(1) "Error: FBW bootloader TIMEOUT. Power cycle the board and wait between 5 seconds to 20 seconds to retry.")
elif c != "FBWOKOK" : sys.exit(1)
print("Error: unknown error. Power cycle the board and wait between 5 seconds to 20 seconds to retry.") elif c != "FBWOKOK":
sys.exit(1) print(
except serial.serialutil.SerialException : "Error: unknown error. Power cycle the board and wait between 5 seconds to 20 seconds to retry.")
pass sys.exit(1)
except serial.serialutil.SerialException:
pass
print("Uploading using Paparazzi firmware...") print("Uploading using Paparazzi firmware...")
if target == "ap" : if target == "ap":
print("If the uploading does not start within a few seconds, please replug the usb (power cycle the board).") print("If the uploading does not start within a few seconds, please replug the usb (power cycle the board).")
sys.exit(0) sys.exit(0)
if mode == -1 : #no pprz cdc was found, look for PX4 if mode == -1: # no pprz cdc was found, look for PX4
ports = glob.glob("/dev/serial/by-id/usb-3D_Robotics*") ports = glob.glob("/dev/serial/by-id/usb-3D_Robotics*")
ports.append(glob.glob("/dev/serial/by-id/pci-3D_Robotics*")) ports.append(glob.glob("/dev/serial/by-id/pci-3D_Robotics*"))
for p in ports : for p in ports:
if len(p) > 0 : if len(p) > 0:
try : try:
ser = serial.Serial(p,timeout=0.5) ser = serial.Serial(p, timeout=0.5)
port = p port = p
mode = 2 mode = 2
print ("Original PX4 firmware CDC device found at port: " + port) print ("Original PX4 firmware CDC device found at port: " + port)
except serial.serialutil.SerialException : except serial.serialutil.SerialException:
print("Non working PX4 port found, continuing...") print("Non working PX4 port found, continuing...")
if mode == -1 : if mode == -1:
print("No original PX4 CDC firmware found either.") print("No original PX4 CDC firmware found either.")
print("Error: no compatible usb device found...") print("Error: no compatible usb device found...")
sys.exit(1) sys.exit(1)
if target == "fbw" : if target == "fbw":
print("Error: original firmware cannot be used to upload the fbw code. Wait for the PX4 bootloader to exit (takes 5 seconds), or in case this is the first upload; first upload the Paparazzi ap target.") print("Error: original firmware cannot be used to upload the fbw code. Wait for the PX4 bootloader to exit (takes 5 seconds), or in case this is the first upload; first upload the Paparazzi ap target.")
sys.exit(1) sys.exit(1)
else : else:
print("Uploading AP using original PX4 firmware...") print("Uploading AP using original PX4 firmware...")
print("If the uploading does not start within a few seconds, please replug the usb (power cycle the board).") print("If the uploading does not start within a few seconds, please replug the usb (power cycle the board).")