-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadLog.py
82 lines (64 loc) · 1.85 KB
/
loadLog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
import subprocess
import sys
import os
import time
from pymavlink import mavutil
import glob
import ConfigParser
import shutil
from datetime import datetime
import argparse
SELECT_GPIO = "21"
ENABLE_GPIO = "19"
#GPIO direction set
def setGPIODir(gpio, direction):
dir_fd = open("/sys/class/gpio/gpio"+str(gpio)+"/direction", "w")
dir_fd.write(direction)
dir_fd.close()
#Open the GPIO
def openGPIO(gpio):
#Check and see if the GPIO is already exported
if not os.path.isdir("/sys/class/gpio/gpio"+str(gpio)):
#otherwise export it
exp_fd = open("/sys/class/gpio/export", "w")
exp_fd.write(gpio)
exp_fd.close()
setGPIODir(gpio, "out");
def closeGPIO(gpio):
unexp_fd = open("/sys/class/gpio/unexport", "w")
unexp_fd.write(gpio)
unexp_fd.close()
def setGPIO(gpio, value):
val_fd = open("/sys/class/gpio/gpio"+str(gpio)+"/value", "w")
val_fd.write(value)
val_fd.close()
def openSetClose(gpio, value):
openGPIO(gpio)
setGPIO(gpio, value)
closeGPIO(gpio)
#Set the GPIO low
def disconnectAndExit():
openSetClose(SELECT_GPIO, "0")
openSetClose(ENABLE_GPIO, "1")
sys.exit()
parser = argparse.ArgumentParser()
parser.add_argument("lognum", help="Log number to download, or 'latest'")
args = parser.parse_args()
#Log downloading process
print "Pixhawk log loader"
#Set the USB select GPIOs
openSetClose(SELECT_GPIO, "1")
openSetClose(ENABLE_GPIO, "0")
time.sleep(1)
print "Checking for pixhawk on USB"
usb_devs = glob.glob('/dev/serial/by-id/usb-3D*')
if not usb_devs:
print "No pixhawk found on USB. Exiting."
disconnectAndExit()
print "Pixhawk found on USB, requesting log."
pixhawk_usb = usb_devs[-1]
m = mavutil.mavlink_connection(pixhawk_usb)
#Call the log downloader app
ret = subprocess.call(["dflog", str(args.lognum)])
disconnectAndExit()