diff --git a/sw/tools/parrot/ardrone2.py b/sw/tools/parrot/ardrone2.py index 7baa2ea9080..0d786cdeaa3 100755 --- a/sw/tools/parrot/ardrone2.py +++ b/sw/tools/parrot/ardrone2.py @@ -160,7 +160,7 @@ def ardrone2_status(): config_ini = parrot_utils.execute_command(tn,'cat /data/config.ini') print('======================== ARDrone 2 Status ========================') - print('Version:\t\t' + parrot_utils.check_version(tn, '/firmware')) + print('Version:\t\t' + str(parrot_utils.check_version(tn, '/firmware'))) print('Host:\t\t\t' + args.host + ' (' + read_from_config('static_ip_address_base', config_ini) + read_from_config('static_ip_address_probe', config_ini) + ' after boot)') diff --git a/sw/tools/parrot/bebop.py b/sw/tools/parrot/bebop.py index 75b46db0594..a3437ab0b66 100755 --- a/sw/tools/parrot/bebop.py +++ b/sw/tools/parrot/bebop.py @@ -50,7 +50,7 @@ def bebop_status(): #config_ini = parrot_utils.execute_command(tn, 'cat /data/config.ini') print('======================== Bebop Status ========================') - print('Version:\t\t' + parrot_utils.check_version(tn, '')) + print('Version:\t\t' + str(parrot_utils.check_version(tn, ''))) # Request the filesystem status print('\n=================== Filesystem Status =======================') print(parrot_utils.check_filesystem(tn)) @@ -123,9 +123,9 @@ def bebop_status(): f = parrot_utils.split_into_path_and_file(args.file) #check firmware version - v = parrot_utils.check_version(tn, '').strip() + v = parrot_utils.check_version(tn, '') print("Checking Bebop firmware version... " + v ) - if ((v < '3.2.0') or (v > '3.9.0')): + if ((v < parrot_utils.ParrotVersion('3.2.0')) or (v > parrot_utils.ParrotVersion('3.9.0'))): print("Error: please upgrade your Bebop firmware to version between 3.2.0 and 3.9.0!") else: print("Kill running " + f[1] + " and make folder " + args.folder) diff --git a/sw/tools/parrot/parrot_utils.py b/sw/tools/parrot/parrot_utils.py index 0b893e8b9a1..0de8f953a1b 100644 --- a/sw/tools/parrot/parrot_utils.py +++ b/sw/tools/parrot/parrot_utils.py @@ -25,6 +25,50 @@ from ftplib import FTP import ftplib +class ParrotVersion(object): + def __init__(self): + self.h = 0 + self.m = 0 + self.l = 0 + self.rc = 0 + self.raw = '' + + def __init__(self, s): + try: + self.raw = s + ss = s.split(".") + self.h = int(ss[0]) + self.m = int(ss[1]) + sss=ss[2].split("-RC") + self.l = int(sss[0]) + if len(sss) > 1: + self.rc = int(sss[1]) + else: + self.rc = 0 + except: + self.__init__() + + def version(self): + return ( ( (self.h * 100 + self.m) * 100) + self.l) * 100 + self.rc + + def __str__(self): + return str(self.h) + "." + str(self.m) + "." + str(self.l) + "." + str(self.rc) + + def __eq__(self, other): + return self.version() == other.version() + + def __lt__(self, other): + return self.version() < other.version() + + def __le__(self, other): + return self.version() <= other.version() + + def __gt__(self, other): + return self.version() > other.version() + + def __ge__(self, other): + return self.version() >= other.version() + # Check if IP is valid def is_ip(address): @@ -48,7 +92,7 @@ def execute_command(tn, command): # Check the version def check_version(tn, directory): - return execute_command(tn, 'cat ' + directory + '/version.txt') + return ParrotVersion(execute_command(tn, 'cat ' + directory + '/version.txt').strip()) # Check what currently is running on the drone def check_running(tn):