def check_autoboot(): check_update = parrot_utils.execute_command(tn,'grep "START_PAPARAZZI" /bin/check_update.sh') wifi_setup = parrot_utils.execute_command(tn,'grep "BASE_ADRESS" /bin/wifi_setup.sh') if "START_PAPARAZZI" in check_update and "BASE_ADRESS" in wifi_setup: return True else: return False
def ardrone2_install_vision(): print('Uploading GST') parrot_utils.uploadfile(ftp, "arm_light.tgz", file("bin/arm_light.tgz", "rb")) print(parrot_utils.execute_command(tn,"cd /data/video && tar -xzf arm_light.tgz")) print(parrot_utils.execute_command(tn,"rm -rf /data/video/arm_light.tgz")) print('Now Starting Vision') ardrone2_start_vision()
def ardrone2_install_olsrd(): print('Uploading olsr deamon') parrot_utils.uploadfile(ftp, "olsrd", file("ardrone2/olsrd", "rb")) parrot_utils.uploadfile(ftp, "olsrd.conf", file("ardrone2/olsrd.conf", "rb")) print(parrot_utils.execute_command(tn,"mv /data/video/olsrd /bin/olsrd")) print(parrot_utils.execute_command(tn,"chmod 777 /bin/olsrd")) print(parrot_utils.execute_command(tn,"mkdir -p /etc/olsrd")) print(parrot_utils.execute_command(tn,"mv /data/video/olsrd.conf /etc/olsrd")) print(parrot_utils.execute_command(tn,"rm -f /var/run && ln -s /tmp /var/run")) # olsrd needs /var/run folder, symlinked to /tmp
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('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)') print('Currently running:\t' + parrot_utils.check_running(tn)) print('Serial number:\t\t' + read_from_config('drone_serial', config_ini)) print('Network id:\t\t' + read_from_config('ssid_single_player', config_ini)) print('Motor software:\t\t' + read_from_config('motor1_soft', config_ini) + '\t' + read_from_config('motor2_soft', config_ini) + '\t' + read_from_config('motor3_soft', config_ini) + '\t' + read_from_config('motor4_soft', config_ini)) print('Motor hardware:\t\t' + read_from_config('motor1_hard', config_ini) + '\t' + read_from_config('motor2_hard', config_ini) + '\t' + read_from_config('motor3_hard', config_ini) + '\t' + read_from_config('motor4_hard', config_ini)) autorun = {'': 'Native', '0': 'Native', '1': 'Paparazzi RAW', '2': 'Paparazzi SDK'} if check_autoboot(): print('Autorun at start:\tInstalled booting ' + autorun[read_from_config('start_paparazzi', config_ini)]) else: print('Autorun at start:\tNot installed') # Check if the vision framework is installed and running vision_framework = "" if check_vision_installed(): vision_framework += "Installed" if check_vision_running(): vision_framework += " and running" print('Vision framework:\t' + vision_framework) # Request the filesystem status print('\n======================== Filesystem Status ========================') print(parrot_utils.check_filesystem(tn))
def read_from_config(name, config=''): if config == '': config = parrot_utils.execute_command('cat /data/config.ini') search = re.search(name + '[^=]+=[\r\n\t ]([^\r\n\t ]+)', config) if search is None: return '' else: return search.group(1)
def read_from_config(name, config=""): if config == "": config = parrot_utils.execute_command("cat /data/config.ini") search = re.search(name + "[^=]+=[\r\n\t ]([^\r\n\t ]+)", config) if search is None: return "" else: return search.group(1)
def ardrone2_remove_vision(): parrot_utils.execute_command(tn,"rm -rf /opt/arm") parrot_utils.execute_command(tn,"rm -rf /lib/dsp") parrot_utils.execute_command(tn,"rm -rf /data/video/opt")
def check_wifi_setup(): check_wifi = parrot_utils.execute_command(tn,'grep "static_ip_address_base" /bin/wifi_setup.sh') if "static_ip_address_base" in check_wifi: return True else: return False
def check_vision_running(): du_opt = parrot_utils.execute_command(tn,'du -d 2 /opt') return '/opt/arm/gst' in du_opt and '/opt/arm/lib' in du_opt and '/opt/arm/tidsp-binaries-23.i3.8' in du_opt
def ardrone2_remove_vision(): parrot_utils.execute_command(tn, "rm -rf /opt/arm") parrot_utils.execute_command(tn, "rm -rf /lib/dsp") parrot_utils.execute_command(tn, "rm -rf /data/video/opt")
def ardrone2_install_network_script(): print('Uploading Wifi script') parrot_utils.uploadfile(ftp, "wifi_setup.sh", file("ardrone2/wifi_setup.sh", "rb")) print(parrot_utils.execute_command(tn,"mv /data/video/wifi_setup.sh /bin/wifi_setup.sh")) print(parrot_utils.execute_command(tn,"chmod 777 /bin/wifi_setup.sh"))
def ardrone2_install_autoboot(): print('Uploading autoboot script') parrot_utils.uploadfile(ftp, "check_update.sh", file("ardrone2/check_update.sh", "rb")) print(parrot_utils.execute_command(tn,"mv /data/video/check_update.sh /bin/check_update.sh")) print(parrot_utils.execute_command(tn,"chmod 777 /bin/check_update.sh"))
# Connect with telnet and ftp tn, ftp = parrot_utils.connect(args.host) # Check the ARDrone 2 status if args.command == 'status': ardrone2_status() # Reboot the drone elif args.command == 'reboot': parrot_utils.reboot(tn) print('The ARDrone 2 is rebooting...') # Kill a program elif args.command == 'kill': parrot_utils.execute_command(tn,'killall -9 ' + args.program + ' &') print('Program "' + args.program + '" is now killed') # Start a program elif args.command == 'start': parrot_utils.execute_command(tn,args.start + ' &') print('Program "' + args.start + '" is now started') # Change the network ID elif args.command == 'networkid': ardrone2_set_ssid(args.name) if raw_input("Shall I restart the ARDrone 2? (y/N) ").lower() == 'y': parrot_utils.reboot(tn) # Change the IP address
def check_vision_installed(): du_opt = parrot_utils.execute_command(tn, 'du -d 2 /data/video/opt') return '/data/video/opt/arm/gst' in du_opt or '/data/video/opt/arm/lib' in du_opt or '/data/video/opt/arm/tidsp-binaries-23.i3.8' in du_opt
def ardrone2_start_vision(): # Mount the directories parrot_utils.execute_command(tn, "mkdir -p /opt/arm") parrot_utils.execute_command(tn, "mkdir -p /lib/dsp") parrot_utils.execute_command(tn, "mount --bind /data/video/opt/arm /opt/arm") parrot_utils.execute_command( tn, "mount --bind /data/video/opt/arm/lib/dsp /lib/dsp") # Start The DSP programs parrot_utils.execute_command(tn, "kill -9 `pidof program.elf`") parrot_utils.execute_command(tn, "kill -9 `pidof gst-launch-0.10`") parrot_utils.execute_command(tn, "export PATH=/opt/arm/gst/bin:$PATH") parrot_utils.execute_command( tn, "export DSP_PATH=/opt/arm/tidsp-binaries-23.i3.8/") parrot_utils.execute_command( tn, "/bin/dspbridge/cexec.out -T /opt/arm/tidsp-binaries-23.i3.8/baseimage.dof -v" ) parrot_utils.execute_command( tn, "/bin/dspbridge/dynreg.out -r /opt/arm/tidsp-binaries-23.i3.8/m4venc_sn.dll64P -v" ) # Show result parrot_utils.execute_command(tn, "ls -altr /opt/arm/gst/bin")
def ardrone2_start_vision(): # Mount the directories parrot_utils.execute_command(tn,"mkdir -p /opt/arm") parrot_utils.execute_command(tn,"mkdir -p /lib/dsp") parrot_utils.execute_command(tn,"mount --bind /data/video/opt/arm /opt/arm") parrot_utils.execute_command(tn,"mount --bind /data/video/opt/arm/lib/dsp /lib/dsp") # Start The DSP programs parrot_utils.execute_command(tn,"kill -9 `pidof program.elf`") parrot_utils.execute_command(tn,"kill -9 `pidof gst-launch-0.10`") parrot_utils.execute_command(tn,"export PATH=/opt/arm/gst/bin:$PATH") parrot_utils.execute_command(tn,"export DSP_PATH=/opt/arm/tidsp-binaries-23.i3.8/") parrot_utils.execute_command(tn,"/bin/dspbridge/cexec.out -T /opt/arm/tidsp-binaries-23.i3.8/baseimage.dof -v") parrot_utils.execute_command(tn,"/bin/dspbridge/dynreg.out -r /opt/arm/tidsp-binaries-23.i3.8/m4venc_sn.dll64P -v") # Show result parrot_utils.execute_command(tn,"ls -altr /opt/arm/gst/bin")
# Connect with telnet and ftp tn, ftp = parrot_utils.connect(args.host) # Check the Bebop status if args.command == 'status': print("Connected to Bebop at " + args.host) bebop_status() # Reboot the drone elif args.command == 'reboot': parrot_utils.reboot(tn) print('The Bebop is rebooting...') # Kill a program elif args.command == 'kill': parrot_utils.execute_command(tn, 'killall -9 ' + args.program) print('Program "' + args.program + '" is now killed') # Start a program elif args.command == 'start': parrot_utils.execute_command(tn, args.start + ' &') print('Program "' + args.start + '" is now started') elif args.command == 'insmod': modfile = parrot_utils.split_into_path_and_file(args.file) print('Uploading \'' + modfile[1]) parrot_utils.uploadfile(ftp, modfile[1], file(args.file, "rb")) print(parrot_utils.execute_command(tn, "insmod /data/ftp/" + modfile[1])) elif args.command == 'upload_file_and_run':
def check_vision_installed(): du_opt = parrot_utils.execute_command(tn,'du -d 2 /data/video/opt') return '/data/video/opt/arm/gst' in du_opt or '/data/video/opt/arm/lib' in du_opt or '/data/video/opt/arm/tidsp-binaries-23.i3.8' in du_opt
def write_to_config(name, value): if read_from_config(name) == '': parrot_utils.execute_command('echo "' + name + ' = ' + value + '\" >> /data/config.ini') else: parrot_utils.execute_command('sed -i "s/\(' + name + ' *= *\).*/\\1' + value + '/g" /data/config.ini')
# Connect with telnet and ftp tn, ftp = parrot_utils.connect(args.host) # Check the ARDrone 2 status if args.command == 'status': ardrone2_status() # Reboot the drone elif args.command == 'reboot': parrot_utils.reboot(tn) print('The ARDrone 2 is rebooting...') # Kill a program elif args.command == 'kill': parrot_utils.execute_command(tn, 'killall -9 ' + args.program + ' &') print('Program "' + args.program + '" is now killed') # Start a program elif args.command == 'start': parrot_utils.execute_command(tn, args.start + ' &') print('Program "' + args.start + '" is now started') # Change the network ID elif args.command == 'networkid': ardrone2_set_ssid(args.name) if raw_input("Shall I restart the ARDrone 2? (y/N) ").lower() == 'y': parrot_utils.reboot(tn) # Change the IP address