Verified Commit 9e8a67ed authored by Martin Prudek's avatar Martin Prudek
Browse files

downloader: Split to functions, add outer wrapper

parent 9e90569a
#!/bin/bash
#DOWNLOAD_SOURCE=http://cdimage.ubuntu.com/releases/18.04/release/ubuntu-18.04.1-server-arm64.template
DOWNLOAD_SOURCE=http://185.68.215.129/1GB.bin
IFACE=wwan0
wget -O /dev/null -o /dev/null $DOWNLOAD_SOURCE &
PID=$!
trap "kill $PID 2> /dev/null" EXIT
echo "Time,Lat,Long,RSRP,SINR Rx[0],RSRQ,RSSI,IP Thrpt DL,MCC,MNC,LAC,Cell Id,PCI,DL EARFCN,Bandwidth,QPSK Rate,16-QAM Rate,64-QAM Rate,256-QAM Rate,Carrier Aggregation DL"
OLD_COUNT=$(cat /sys/class/net/$IFACE/statistics/rx_bytes)
#require codeutils-date package
sleep 0.$(printf '%04d' $((10000 - 10#$(/usr/bin/date +%4N))))
while kill -0 $PID 2> /dev/null; do
function wait_to_full_second {
# require coreutils-date package
# get the number of nanoseconds, round it to hundreds of microseconds
# (use uppermost 4 digits), mark it decadic (#10) and substract it from 10000
# The result is number of remaining hundreds of microseconds to wait
sleep 0.$(printf '%04d' $((10000 - 10#$(/usr/bin/date +%4N))))
COUNT=$(cat /sys/class/net/$IFACE/statistics/rx_bytes)
let "KBPS=($COUNT-$OLD_COUNT)*8/1000"
RESLINE=$(date +"%d.%m.%Y %H:%M:%S")","$(/root/lteinfo.py)",,,,"
eval echo "$RESLINE"
OLD_COUNT=$COUNT
}
function download {
wget -O /dev/null -o /dev/null $DOWNLOAD_SOURCE &
PID=$!
# kill downloading thread on exit
trap "kill $PID 2> /dev/null" EXIT
echo "Time,Lat,Long,RSRP,SINR Rx[0],RSRQ,RSSI,IP Thrpt DL,MCC,MNC,LAC,Cell Id,PCI,DL EARFCN,Bandwidth,QPSK Rate,16-QAM Rate,64-QAM Rate,256-QAM Rate,Carrier Aggregation DL"
OLD_COUNT=$(cat /sys/class/net/$IFACE/statistics/rx_bytes)
# Check whether the file is still being downloaded
while kill -0 $PID 2> /dev/null; do
wait_to_full_second
COUNT=$(cat /sys/class/net/$IFACE/statistics/rx_bytes)
let "KBPS=($COUNT-$OLD_COUNT)*8/1000"
RESLINE=$(date +"%d.%m.%Y %H:%M:%S")","$(/root/lteinfo.py)",,,,"
eval echo "$RESLINE"
OLD_COUNT=$COUNT
done
# Disable the trap on a normal exit.
trap - EXIT
}
while true; do
echo "Starting download speed measurement..."
download > "`/usr/bin/date +'%Y-%m-%d_%H-%M-%S'`_`atsha204cmd serial-number`.csv"
echo "Download speed measurement finished. Starting netmetr..."
netmetr > /dev/null 2>&1
done
# Disable the trap on a normal exit.
trap - EXIT
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment