laymanshex-files/Sports/Concept2/PM5/pm5conv.bash
2020-04-30 19:43:31 +02:00

81 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
cmd="laymanshex"
accTable="LogDataAccessTbl.bin"
storage="LogDataStorage.bin"
# uses evil eval
function printNonEmpty {
varname='$'"$1"
eval "val=$varname"
if [ "$val" != "" ]; then
echo "$1=$val"
fi
}
function printTimestamp {
timestamp="0x$1"
year="$(( ((timestamp & 0xFE000000) >> 25) + 2000 ))"
day="$(( (timestamp & 0x01F00000) >> 21 ))"
month="$(( (timestamp & 0x000F0000) >> 16 ))"
hour="$(( (timestamp & 0x0000FF00) >> 8 ))"
minute="$(( timestamp & 0x000000FF ))"
printf "Date %d-%02d-%02d %02d:%02d\n" $year $month $day $hour $minute
}
function printSplit {
outputSplit="$($cmd -nopadding -fvar=offset=$1,splitNo=$2 $storage-Workout$3.layhex $storage 2> /dev/null)"
status=$?
if [ $status -eq 0 ]; then
eval "$outputSplit"
echo
echo "Split $(($2+1))"
echo "----------"
printNonEmpty "SplitDuration"
printNonEmpty "SplitDistance"
printNonEmpty "SplitHeartRate"
printNonEmpty "SplitSPM"
fi
}
function printWorkout {
echo "Workout $1"
echo "============="
outputHeader="$($cmd -nopadding -fvar=offset=$2,splitNo=0 $storage-Workout$3.layhex $storage 2> /dev/null)"
status=$?
if [ $status -eq 0 ]; then
eval "$outputHeader"
printTimestamp "$Timestamp"
printNonEmpty "TotalDuration"
printNonEmpty "TotalDistance"
printNonEmpty "SplitSize"
printNonEmpty "SPM"
j=0
while [ "$j" -lt "$NoSplits" ]; do
printSplit $2 $j $3
j=$((j+1))
done
echo
fi
}
function printAll {
i=0
while : ; do
offset=$(($i))
output="$($cmd -nopadding -fvar=offset=$offset $accTable.layhex $accTable 2>/dev/null)"
status=$?
if [ $status -ne 0 ]; then
break
else
eval "$output"
printWorkout $Index $Offset $WorkoutType
fi
i=$((i+1))
done
}
printAll