1#!/vendor/bin/sh
2# only use xtal_trim from factory calibration
3if [ -z "$2" ]
4then
5    echo "usage is $0 input-calibration output_calibration"
6    exit 0
7fi
8OUTPUT_CALIB="$2"
9if [ ! -f "$OUTPUT_CALIB" ]; then
10    touch $OUTPUT_CALIB
11    chmod 0644 $OUTPUT_CALIB
12    file="$1"
13    while IFS=, read -r f1 f2
14    do
15        case $f1 in
16            "UWB_cal_tx_xtal_reg_final_value")
17                if [ $((0x$f2)) -gt 63 ]; then
18                    f2=63
19                fi
20                echo 'xtal_trim=0x'$f2 >> $OUTPUT_CALIB
21                ;;
22        esac
23    done <"$file"
24    exit 0
25fi
26
27