Skip to content

Commit

Permalink
[ardrone] Handle memory full FTP upload error on ardrone (#967)
Browse files Browse the repository at this point in the history
  • Loading branch information
dewagter committed Nov 21, 2014
1 parent c615073 commit ad8358d
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions sw/ext/ardrone2_drivers/ardrone2.py
Expand Up @@ -6,10 +6,21 @@
import socket
import telnetlib
import os
import sys
from time import sleep
from ftplib import FTP


# Upload ftp and catch memory-full error
def uploadfile(ftp, filename, content):
try:
ftp.storbinary("STOR " + filename, content)
except ftplib.error_temp:
print("FTP UPLOAD ERROR: Uploading FAILED: Probably your ARDrone memory is full.")
except:
print("FTP UPLOAD ERROR: ", sys.exc_info()[0])
raise

# Check if IP is valid
def is_ip(address):
try:
Expand Down Expand Up @@ -102,7 +113,7 @@ def ardrone2_reboot():
# Install the vision framework
def ardrone2_install_vision():
print('Uploading GST')
ftp.storbinary("STOR arm_light.tgz", file("bin/arm_light.tgz", "rb"))
uploadfile(ftp, ("arm_light.tgz", file("bin/arm_light.tgz", "rb"))
print(execute_command("cd /data/video && tar -xzf arm_light.tgz"))
print(execute_command("rm -rf /data/video/arm_light.tgz"))
print('Now Starting Vision')
Expand Down Expand Up @@ -134,14 +145,14 @@ def ardrone2_start_vision():
# Install autoboot script
def ardrone2_install_autoboot():
print('Uploading autoboot script')
ftp.storbinary("STOR check_update.sh", file("check_update.sh", "rb"))
uploadfile(ftp, "check_update.sh", file("check_update.sh", "rb"))
print(execute_command("mv /data/video/check_update.sh /bin/check_update.sh"))
print(execute_command("chmod 777 /bin/check_update.sh"))

# Install network script
def ardrone2_install_network_script():
print('Uploading Wifi script')
ftp.storbinary("STOR wifi_setup.sh", file("wifi_setup.sh", "rb"))
uploadfile(ftp, "wifi_setup.sh", file("wifi_setup.sh", "rb"))
print(execute_command("mv /data/video/wifi_setup.sh /bin/wifi_setup.sh"))
print(execute_command("chmod 777 /bin/wifi_setup.sh"))

Expand Down Expand Up @@ -203,7 +214,6 @@ def ardrone2_status():
print('\n======================== Filesystem Status ========================')
print(check_filesystem())


# Parse the arguments
parser = argparse.ArgumentParser(description='ARDrone 2 python helper. Use ardrone2.py -h for help')
parser.add_argument('--host', metavar='HOST', default='192.168.1.1',
Expand Down Expand Up @@ -387,7 +397,7 @@ def ardrone2_status():

elif args.command == 'upload_gst_module':
print('Uploading ...' + args.file)
ftp.storbinary("STOR " + args.file, file(args.file, "rb"))
uploadfile(ftp, args.file, file(args.file, "rb"))
execute_command("chmod 777 /data/video/" + args.file)
execute_command("mv /data/video/" + args.file + " /data/video/opt/arm/gst/lib/gstreamer-0.10")
if check_vision_running():
Expand All @@ -407,7 +417,7 @@ def ardrone2_status():
elif args.command == 'insmod':
modfile = split_into_path_and_file(args.file)
print('Uploading \'' + modfile[1])
ftp.storbinary("STOR " + modfile[1], file(args.file, "rb"))
uploadfile(ftp, modfile[1], file(args.file, "rb"))
print(execute_command("insmod /data/video/" + modfile[1]))

elif args.command == 'upload_file_and_run':
Expand All @@ -419,7 +429,7 @@ def ardrone2_status():
sleep(1)
execute_command("mkdir -p /data/video/" + args.folder)
print('Uploading \'' + f[1] + "\' from " + f[0] + " to " + args.folder)
ftp.storbinary("STOR " + args.folder + "/" + f[1], file(args.file, "rb"))
uploadfile(ftp, args.folder + "/" + f[1], file(args.file, "rb"))
sleep(0.5)
execute_command("chmod 777 /data/video/" + args.folder + "/" + f[1])
execute_command("/data/video/" + args.folder + "/" + f[1] + " > /dev/null 2>&1 &")
Expand All @@ -431,7 +441,7 @@ def ardrone2_status():

execute_command("mkdir -p /data/video/" + args.folder)
print('Uploading \'' + f[1] + "\' from " + f[0] + " to /data/video/" + args.folder)
ftp.storbinary("STOR " + args.folder + "/" + f[1], file(args.file, "rb"))
uploadfile(ftp, args.folder + "/" + f[1], file(args.file, "rb"))
print("#pragma message: Upload of " + f[1] + " to ARDrone2 Succes!")

elif args.command == 'download_file':
Expand Down

0 comments on commit ad8358d

Please sign in to comment.