Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions disco/uavpal/bin/uavpal_disco.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/sh
{
# exports
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/ftp/uavpal/lib

# variables
cdc_if="eth1"
# TODO: make the following dynamic if possible
Expand Down
17 changes: 12 additions & 5 deletions disco/uavpal/bin/uavpal_globalfunctions.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# exports
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/ftp/uavpal/lib

# variables
curl=/data/ftp/uavpal/bin/curl
#curl=`which curl`

hilink_api()
{
# Usage: hilink_api {get,post} url-context [json-data]
Expand All @@ -13,12 +20,12 @@ hilink_api()
data="$3"

hilink_router_ip=$(cat /tmp/hilink_router_ip)
sessionInfo=$(/data/ftp/uavpal/bin/curl -s -X GET "http://${hilink_router_ip}/api/webserver/SesTokInfo" 2>/dev/null)
sessionInfo=$(${curl} -s -X GET "http://${hilink_router_ip}/api/webserver/SesTokInfo" 2>/dev/null)
if [ "$?" -ne "0" ]; then ulogger -s -t uavpal_hilink_api "... Error connecting to Hi-Link API"; fi
cookie=$(echo "$sessionInfo" | grep "SessionID=" | cut -b 10-147)
token=$(echo "$sessionInfo" | grep "TokInfo" | cut -b 10-41)
if [ -f /tmp/hilink_login_required ]; then
sessionInfoLogin=$(/data/ftp/uavpal/bin/curl -s -X POST "http://${hilink_router_ip}/api/user/login" -d "<request><Username>admin</Username><Password>$(echo -n "admin" |base64)</Password><password_type>3</password_type></request>" -H "Cookie: $cookie" -H "__RequestVerificationToken: $token" --dump-header - 2>/dev/null)
sessionInfoLogin=$(${curl} -s -X POST "http://${hilink_router_ip}/api/user/login" -d "<request><Username>admin</Username><Password>$(echo -n "admin" |base64)</Password><password_type>3</password_type></request>" -H "Cookie: $cookie" -H "__RequestVerificationToken: $token" --dump-header - 2>/dev/null)
if echo -n "$sessionInfoLogin" | grep '<code>108006\|<code>108007' ; then
ulogger -s -t uavpal_hilink_api "... Hi-Link authentication error. Please disable password protection or set it to user=admin, password=admin"
return # break out function
Expand All @@ -28,7 +35,7 @@ hilink_api()
sessionInfoAdm=$(curl -s -X GET "http://${hilink_router_ip}/api/webserver/SesTokInfo" -H "Cookie: $cookie" 2>/dev/null)
token=$(echo "$sessionInfoAdm" | grep "TokInfo" | cut -b 10-41)
fi
result=$(/data/ftp/uavpal/bin/curl -s -X $method "http://${hilink_router_ip}${url}" -d "$data" -H "Cookie: $cookie" -H "__RequestVerificationToken: $token" 2>/dev/null)
result=$(${curl} -s -X $method "http://${hilink_router_ip}${url}" -d "$data" -H "Cookie: $cookie" -H "__RequestVerificationToken: $token" 2>/dev/null)
if echo "$result" | grep "<error>" ; then
if [ "$(echo $result | xmllint --xpath 'string(//error/code)' -)" -eq "100003" ]; then
ulogger -s -t uavpal_hilink_api "... Hi-Link authentication required. Trying to login using user=admin, password=admin"
Expand Down Expand Up @@ -90,7 +97,7 @@ send_message()
pb_access_token="$(conf_read pushbullet)"
if [ "$pb_access_token" != "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ]; then
ulogger -s -t uavpal_send_message "... sending push notification (via Pushbullet API)"
/data/ftp/uavpal/bin/curl -q -k -u ${pb_access_token}: -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "'"$2"'", "body": "'"$1"'"}'
${curl} -q -k -u ${pb_access_token}: -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "'"$2"'", "body": "'"$1"'"}'
fi
}

Expand Down Expand Up @@ -185,4 +192,4 @@ check_connection()
done
# none of the ping destinations could have been reached
return 1
}
}
115 changes: 74 additions & 41 deletions disco/uavpal/bin/uavpal_glympse.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/bin/sh

# exports
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/ftp/uavpal/lib

# variables
platform=$(grep 'ro.parrot.build.product' /etc/build.prop | cut -d'=' -f 2)
serial_ctrl_dev=`head -1 /tmp/serial_ctrl_dev |tr -d '\r\n' |tr -d '\n'`
dc=/data/ftp/uavpal/bin/dc
#dc=`which dc`

# functions
. /data/ftp/uavpal/bin/uavpal_globalfunctions.sh
Expand All @@ -20,9 +19,9 @@ function gpsDecimal()
{
gpsVal=$1
gpsDir="$2"
gpsInt=$(echo "$gpsVal 100 / p" | /data/ftp/uavpal/bin/dc)
gpsMin=$(echo "3k$gpsVal $gpsInt 100 * - p" | /data/ftp/uavpal/bin/dc)
gpsDec=$(echo "6k$gpsMin 60 / $gpsInt + 1000000 * p" | /data/ftp/uavpal/bin/dc | cut -d '.' -f 1)
gpsInt=$(echo "$gpsVal 100 / p" | ${dc})
gpsMin=$(echo "3k$gpsVal $gpsInt 100 * - p" | ${dc})
gpsDec=$(echo "6k$gpsMin 60 / $gpsInt + 1000000 * p" | ${dc} | cut -d '.' -f 1)
if [[ "$gpsDir" != "E" && "$gpsDir" != "N" ]]; then gpsDec="-$gpsDec"; fi
echo $gpsDec
}
Expand Down Expand Up @@ -61,6 +60,27 @@ function calc_volt()
bat_volts=$(printf "%d.%02d" $(($val / 1000)) $(($val % 1000 / 10)))
}

function check_volt()
{
local line=$1
local voltpos=4
volts_ok=1
if [ "$platform" == "ardrone3" ]; then
voltpos=16
fi
local msb=$(echo $line | cut -d " " -f $voltpos)
local lsb=$(echo $line | cut -d " " -f $(($voltpos+1)))
local val=$((0x$msb$lsb))
# values under 5V are considered bogus
if [ $val -lt 5000 ]; then
volts_ok=0
fi
# values over 15V are considered bogus, too
if [ $val -gt 15000 ]; then
volts_ok=0
fi
}

# main
ulogger -s -t uavpal_glympse "... reading Glympse API key from config file"
apikey="$(conf_read glympse_apikey)"
Expand All @@ -73,22 +93,22 @@ ulogger -s -t uavpal_glympse "... reading drone ID from avahi"
droneName=$(cat /tmp/avahi/services/ardiscovery.service |grep name |cut -d '>' -f 2 |cut -d '<' -f 0)

ulogger -s -t uavpal_glympse "... Glympse API: creating account"
glympseCreateAccount=$(/data/ftp/uavpal/bin/curl -q -k -H "Content-Type: application/json" -X POST "https://api.glympse.com/v2/account/create?api_key=${apikey}")
glympseCreateAccount=$(${curl} -q -k -H "Content-Type: application/json" -X POST "https://api.glympse.com/v2/account/create?api_key=${apikey}")

ulogger -s -t uavpal_glympse "... Glympse API: logging in"
glympseLogin=$(/data/ftp/uavpal/bin/curl -q -k -H "Content-Type: application/json" -X POST "https://api.glympse.com/v2/account/login?api_key=${apikey}&id=$(parse_json $glympseCreateAccount id)&password=$(parse_json $glympseCreateAccount password)")
glympseLogin=$(${curl} -q -k -H "Content-Type: application/json" -X POST "https://api.glympse.com/v2/account/login?api_key=${apikey}&id=$(parse_json $glympseCreateAccount id)&password=$(parse_json $glympseCreateAccount password)")

ulogger -s -t uavpal_glympse "... Glympse API: parsing access token"
access_token=$(parse_json $(echo $glympseLogin |sed 's/\:\"access_token/\:\"tmp/g') access_token)

ulogger -s -t uavpal_glympse "... Glympse API: creating ticket"
glympseCreateTicket=$(/data/ftp/uavpal/bin/curl -q -k -H "Content-Type: application/json" -H "Authorization: Bearer ${access_token}" -X POST "https://api.glympse.com/v2/users/self/create_ticket?duration=14400000")
glympseCreateTicket=$(${curl} -q -k -H "Content-Type: application/json" -H "Authorization: Bearer ${access_token}" -X POST "https://api.glympse.com/v2/users/self/create_ticket?duration=14400000")

ulogger -s -t uavpal_glympse "... Glympse API: parsing ticket"
ticket=$(parse_json $glympseCreateTicket id)

ulogger -s -t uavpal_glympse "... Glympse API: creating invite"
glympseCreateInvite=$(/data/ftp/uavpal/bin/curl -q -k -H "Content-Type: application/json" -H "Authorization: Bearer ${access_token}" -X POST "https://api.glympse.com/v2/tickets/$ticket/create_invite?type=sms&address=1234567890&send=client")
glympseCreateInvite=$(${curl} -q -k -H "Content-Type: application/json" -H "Authorization: Bearer ${access_token}" -X POST "https://api.glympse.com/v2/tickets/$ticket/create_invite?type=sms&address=1234567890&send=client")

ulogger -s -t uavpal_glympse "... Glympse link generated: https://glympse.com/$(parse_json ${glympseCreateInvite% *} id)"

Expand All @@ -104,54 +124,65 @@ elif [ "$platform" == "ardrone3" ]; then
# Parrot Bebop 2
tn_filename="bebop2.png"
fi
/data/ftp/uavpal/bin/curl -q -k -H "Content-Type: application/json" -H "Authorization: Bearer ${access_token}" -X POST -d "[{\"t\": $(date +%s)000, \"pid\": 0, \"n\": \"avatar\", \"v\": \"https://uavpal.com/img/${tn_filename}?$(date +%s)\"}]" "https://api.glympse.com/v2/tickets/$ticket/append_data"
${curl} -q -k -H "Content-Type: application/json" -H "Authorization: Bearer ${access_token}" -X POST -d "[{\"t\": $(date +%s)000, \"pid\": 0, \"n\": \"avatar\", \"v\": \"https://uavpal.com/img/${tn_filename}?$(date +%s)\"}]" "https://api.glympse.com/v2/tickets/$ticket/append_data"

ztVersion=$(/data/ftp/uavpal/bin/zerotier-one -v)

ulogger -s -t uavpal_glympse "... Glympse API: reading out drone's GPS coordinates every 5 seconds to update Glympse via API"
ulogger -s -t uavpal_glympse "... Glympse API: reading out drone's GPS coordinates, battery voltage, connection type and signal strength approx. every 5 seconds to update Glympse via WebAPI"

# initializing vars
bat_volts="n/a"
bat_percent="n/a"

while true
do
crc_ok=0
volts_ok=0
# Try to get valid i2c data 5 times
for i in $(seq 1 5); do
i2cline=$(i2cdump -r 0x20-0x2f -y 1 0x08 |tail -n 1)
calc_crc "$i2cline"
if [ $crc_ok -gt 0 ]; then
check_volt "$i2cline"
if [ $volts_ok -gt 0 ]; then
# correct voltage reading
break
fi
fi
done

if [ $crc_ok -gt 0 -a $volts_ok -gt 0 ]; then
bat_volts_prev="$bat_volts"
calc_volt "$i2cline"
bat_percent_prev="$bat_percent"
bat_percent=$(ulogcat -d -v csv |grep "Battery percentage" |tail -n 1 | cut -d " " -f 4)
else
bat_volts="$bat_volts_prev"
bat_percent="$bat_percent_prev"
fi

gps_nmea_out=$(grep GNRMC -m 1 /tmp/gps_nmea_out | cut -c4-)
lat=$(echo $gps_nmea_out | cut -d ',' -f 4)
latdir=$(echo $gps_nmea_out | cut -d ',' -f 5)
long=$(echo $gps_nmea_out | cut -d ',' -f 6)
longdir=$(echo $gps_nmea_out | cut -d ',' -f 7)
speed=$(printf "%.0f\n" $(/data/ftp/uavpal/bin/dc -e "$(echo $gps_nmea_out | cut -d ',' -f 8) 51.4444 * p"))
speed=$(printf "%.0f\n" $(${dc} -e "$(echo $gps_nmea_out | cut -d ',' -f 8) 51.4444 * p"))
heading="$(printf "%.0f\n" $(echo $gps_nmea_out | cut -d ',' -f 9))"
altitude_abs=$(grep GNGNS -m 1 /tmp/gps_nmea_out | cut -c4- | cut -d ',' -f 10)

if [ -f /data/ftp/internal_000/*/academy/*.pud.temp ]; then
altitude_rel=$(/data/ftp/uavpal/bin/dc -e "$altitude_abs $(cat /tmp/alt_before_takeoff) - p")
altitude_rel=$(${dc} -e "$altitude_abs $(cat /tmp/alt_before_takeoff) - p")
else
echo $altitude_abs > /tmp/alt_before_takeoff
altitude_rel="0"
fi

if [ `cat /tmp/sc2ping | wc -l` -eq '1' ]; then
latency=$(/data/ftp/uavpal/bin/dc -e "$(cat /tmp/sc2ping) 2 / p")ms
else
latency="n/a"
fi

crc_ok=0
for i in $(seq 1 5); do
i2cline=$(i2cdump -r 0x20-0x2f -y 1 0x08)
calc_crc "$i2cline"
if [ $crc_ok -gt 0 ]; then break; fi
done
if [ $crc_ok -gt 0 ]; then
bat_volts_prev=$bat_volts
calc_volt "$i2cline"
bat_percent_prev=$bat_percent
bat_percent=$(ulogcat -d -v csv |grep "Battery percentage" |tail -n 1 | cut -d " " -f 4)
else
bat_percent="$bat_percent_prev";
fi
latency="n/a"
if [ -f /tmp/sc2ping ]; then
if [ `cat /tmp/sc2ping | wc -l` -eq '1' ]; then
latency=$(${dc} -e "$(cat /tmp/sc2ping) 2 / p")ms
fi
fi

ip_sc2=`netstat -nu |grep 9988 | head -1 | awk '{ print $5 }' | cut -d ':' -f 1`
ztConn=""
Expand All @@ -166,7 +197,7 @@ do
ztConn=" [R]"
fi

# reading out the modem's connection type and ignal strength
# reading out the modem's connection type and signal strength
if [ ! -f "/tmp/hilink_router_ip" ]; then
modeString=$(at_command "AT\^SYSINFOEX" "OK" "1" | grep "SYSINFOEX:" | tail -n 1)
modeNum=`echo $modeString | cut -d "," -f 8`
Expand All @@ -182,7 +213,7 @@ do
signalString=$(at_command "AT+CSQ" "OK" "1" | grep "CSQ:" | tail -n 1)
signalRSSI=`echo $signalString | awk '{print $2}' | cut -d ',' -f 1`
if [ $signalRSSI -ge 0 ] && [ $signalRSSI -le 31 ]; then
signalPercentage=$(printf "%.0f\n" $(/data/ftp/uavpal/bin/dc -e "$(echo $signalRSSI) 1 + 3.13 * p"))%
signalPercentage=$(printf "%.0f\n" $(${dc} -e "$(echo $signalRSSI) 1 + 3.13 * p"))%
else # including 99 for "Unknown or undetectable"
signalPercentage="n/a"
fi
Expand All @@ -199,10 +230,11 @@ do
mode="n/a"
fi
signalBars=$(hilink_api "get" "/api/monitoring/status" | xmllint --xpath 'string(//SignalIcon)' -)
signalPercentage=$(echo "$signalBars 20 * p" | /data/ftp/uavpal/bin/dc)%
signalPercentage=$(echo "$signalBars 20 * p" | ${dc})%
signal="$mode/$signalPercentage"
fi
fi

temp=""
tempfile="/sys/devices/platform/p7-temperature/iio:device1/in_temp7_p7mu_raw"
if [ -f $tempfile ]; then
Expand All @@ -212,16 +244,17 @@ do
droneLabel="${droneName} (${signal} ${altitude_rel}m ${bat_volts}V/${bat_percent}% ${temp} ${latency}${ztConn})"
ulogger -s -t uavpal_glympse "... updating Glympse label ($(date +%Y-%m-%d-%H:%M:%S)): $droneLabel"

/data/ftp/uavpal/bin/curl -q -k -H "Content-Type: application/json" -H "Authorization: Bearer ${access_token}" -X POST -d "[[$(date +%s)000,$(gpsDecimal $lat $latdir),$(gpsDecimal $long $longdir),$speed,$heading]]" "https://api.glympse.com/v2/tickets/$ticket/append_location" &
/data/ftp/uavpal/bin/curl -q -k -H "Content-Type: application/json" -H "Authorization: Bearer ${access_token}" -X POST -d "[{\"t\": $(date +%s)000, \"pid\": 0, \"n\": \"name\", \"v\": \"${droneLabel}\"}]" "https://api.glympse.com/v2/tickets/$ticket/append_data" &
${curl} -q -k -H "Content-Type: application/json" -H "Authorization: Bearer ${access_token}" -X POST -d "[[$(date +%s)000,$(gpsDecimal $lat $latdir),$(gpsDecimal $long $longdir),$speed,$heading]]" "https://api.glympse.com/v2/tickets/$ticket/append_location" &
${curl} -q -k -H "Content-Type: application/json" -H "Authorization: Bearer ${access_token}" -X POST -d "[{\"t\": $(date +%s)000, \"pid\": 0, \"n\": \"name\", \"v\": \"${droneLabel}\"}]" "https://api.glympse.com/v2/tickets/$ticket/append_data" &

if test -n "$ip_sc2"; then
ping -c 1 $ip_sc2 |grep 'bytes from' | cut -d '=' -f 4 | tr -d ' ms' > /tmp/sc2ping &
else
rm /tmp/sc2ping 2>/dev/null
fi
sleep 5

# make sure all curl processes have ended
while ps |grep curl |grep -v grep >/dev/null; do usleep 100000; done
while ps |grep curl |grep -v grep >/dev/null; do sleep 1; done

done

10 changes: 9 additions & 1 deletion disco/uavpal/bin/uavpal_sdcard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ if [ "$1" == "add" ]; then
fi
ulogger -s -t uavpal_sdcard "... disk ${disk} has been detected, trying to mount its last partition ${partition}"
title="SD card inserted"
mount -t vfat -o rw,noatime /dev/${partition} ${media_path}
for i in $(seq 1 5); do
mount -o rw,noatime /dev/${partition} ${media_path}
if [ $? -ne 0 ]; then
ulogger -s -t uavpal_sdcard "... could not mount sd card in try ${i}"
sleep 1
else
break
fi
done
if [ $? -ne 0 ]; then
message="could not mount SD card partition ${partition} - please ensure the SD card's file system is FAT32 (and not exFAT!)"
ulogger -s -t uavpal_sdcard "... ${message}. Exiting!"
Expand Down