decode script renamed and added tests
parent
9099938f1d
commit
592de999b9
|
@ -3,6 +3,8 @@
|
|||
##
|
||||
## Usage: __PROG__ [options] wavfile
|
||||
##
|
||||
## Files are created as siblings of the wavfile
|
||||
##
|
||||
prog="$0"
|
||||
me=${HELP:-`basename "$prog"`}
|
||||
rootdir=$(dirname $(realpath $0))
|
||||
|
@ -22,18 +24,10 @@ function guess_timestamp() {
|
|||
expr ${mtime} - ${duration} + 2
|
||||
}
|
||||
|
||||
# Creates images from a recorded pass on the filesystem
|
||||
# @global output_prefix
|
||||
# @global satellite
|
||||
# @global timestamp
|
||||
# @global tle_file
|
||||
# @global enhancements
|
||||
# @param wavfile path to file to create images from
|
||||
# @output one line per file created
|
||||
function make_images() {
|
||||
wavfile=${1}
|
||||
prefix=${output_prefix:-$(basename ${wavfile} .wav)}
|
||||
manifest=${prefix}-manifest.txt
|
||||
local wavfile=${1}
|
||||
local prefix="$(dirname ${wavfile})/$(basename ${wavfile} .wav)"
|
||||
local manifest=${prefix}-manifest.txt
|
||||
|
||||
# check wavfile exists
|
||||
if [ ! -f ${wavfile} ]; then
|
||||
|
@ -41,7 +35,7 @@ function make_images() {
|
|||
exit 3
|
||||
fi
|
||||
log "Creating manifest file ${manifest}"
|
||||
echo "${wavfile}" > ${manifest}
|
||||
echo "$(basename $wavfile)" > ${manifest}
|
||||
|
||||
# quietly mkdir -p the output
|
||||
mkdir -p $(dirname ${prefix})
|
||||
|
@ -56,8 +50,9 @@ function make_images() {
|
|||
logerr "Error generating map"
|
||||
else
|
||||
log "Generated map ${mapfile}"
|
||||
# Dont include map; it is only used to generate images
|
||||
# echo "$(basename $mapfile)" > ${manifest}
|
||||
fi
|
||||
echo ${mapfile}
|
||||
fi
|
||||
if [ -f $mapfile ]; then
|
||||
log "Using map file ${mapfile}"
|
||||
|
@ -75,7 +70,7 @@ function make_images() {
|
|||
|
||||
if [ -f ${imgfile} ]; then
|
||||
log "Adding file to manifest: ${imgfile}"
|
||||
echo "${imgfile}" >> ${manifest}
|
||||
echo "$(basename $imgfile)" >> ${manifest}
|
||||
fi
|
||||
done
|
||||
((count++))
|
||||
|
@ -128,17 +123,17 @@ do
|
|||
shift
|
||||
;;
|
||||
|
||||
## --output <prefix> Prefix output with string (default based in input filename)
|
||||
'--output')
|
||||
# check that $2 exists and is not another flag
|
||||
if [[ $# -lt 2 ]] || [[ $2 == -* ]] ; then
|
||||
logerr "Option ${1} requires an argument"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
output_prefix=${2}
|
||||
shift
|
||||
;;
|
||||
# ## --output <prefix> Prefix output with string (default based in input filename)
|
||||
# '--output')
|
||||
# # check that $2 exists and is not another flag
|
||||
# if [[ $# -lt 2 ]] || [[ $2 == -* ]] ; then
|
||||
# logerr "Option ${1} requires an argument"
|
||||
# usage
|
||||
# exit 1
|
||||
# fi
|
||||
# output_prefix=${2}
|
||||
# shift
|
||||
# ;;
|
||||
|
||||
## --tle <file> Path to tle file (default: satellites.tle)
|
||||
'--tle')
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/bash
|
||||
prog="$0"
|
||||
me=`basename "$prog"`
|
||||
unit=$(realpath $(dirname "$0")/../decode.sh)
|
||||
fixture_dir=$(realpath $(dirname "$0")/fixtures)
|
||||
|
||||
setUp() {
|
||||
stdoutF="${SHUNIT_TMPDIR}/stdout"
|
||||
stderrF="${SHUNIT_TMPDIR}/stderr"
|
||||
>"${stdoutF}"
|
||||
>"${stderrF}"
|
||||
}
|
||||
|
||||
test_decode_wav_with_map() {
|
||||
mkdir -p ${SHUNIT_TMPDIR}/data
|
||||
cd ${SHUNIT_TMPDIR}
|
||||
cp ${fixture_dir}/$(basename $me .sh)/noaa_15-1643760991.wav ${SHUNIT_TMPDIR}/data/pass.wav
|
||||
${unit} --satellite noaa-15 --timestamp 1643760991 ${SHUNIT_TMPDIR}/data/pass.wav >${stdoutF} 2>${stderrF}
|
||||
rtrn=$?
|
||||
assertTrue "unexpected error status" $rtrn
|
||||
|
||||
# expect files to exist
|
||||
assertTrue "expected manifest" "[ -r ./data/pass-manifest.txt ]"
|
||||
assertTrue "expected MCIR" "[ -r ./data/pass-MCIR.png ]"
|
||||
assertTrue "expected MSA" "[ -r ./data/pass-MSA.png ]"
|
||||
assertTrue "expected PRECIP" "[ -r ./data/pass-MSA-PRECIP.png ]"
|
||||
assertTrue "expected NO" "[ -r ./data/pass-NO.png ]"
|
||||
assertTrue "expected therm" "[ -r ./data/pass-therm.png ]"
|
||||
assertTrue "expected ZA" "[ -r ./data/pass-ZA.png ]"
|
||||
assertTrue "expected map" "[ -r ./data/pass-map.png ]"
|
||||
|
||||
assertNotNull "expected manifest to contain MCIR image" \
|
||||
"`grep -E '^pass-MCIR\.png$' ./data/pass-manifest.txt`"
|
||||
assertNotNull "expected manifest to contain MSA image" \
|
||||
"`grep -E '^pass-MSA.png$' ./data/pass-manifest.txt`"
|
||||
assertNull "unexpected map in manifest" \
|
||||
"`grep -E '^pass-map.png$' ./data/pass-manifest.txt`"
|
||||
}
|
||||
|
||||
test_decode_without_map() {
|
||||
mkdir -p ${SHUNIT_TMPDIR}/foo/bar
|
||||
cd ${SHUNIT_TMPDIR}
|
||||
cp ${fixture_dir}/$(basename $me .sh)/noaa_15-1643760991.wav ${SHUNIT_TMPDIR}/foo/bar/pass.wav
|
||||
${unit} ${SHUNIT_TMPDIR}/foo/bar/pass.wav >${stdoutF} 2>${stderrF}
|
||||
rtrn=$?
|
||||
assertTrue "unexpected error status" $rtrn
|
||||
|
||||
assertFalse "unexpected map" "[ -r ./foo/bar/pass-map.png ]"
|
||||
assertTrue "expected MCIR" "[ -r ./foo/bar/pass-MCIR.png ]"
|
||||
}
|
||||
|
||||
. shunit2
|
Loading…
Reference in New Issue