92 lines
2.8 KiB
Bash
92 lines
2.8 KiB
Bash
#!/bin/bash
|
|
|
|
#input="./Elite_test.txt"
|
|
input="D:/Elite/Calibration_data/$1.txt"
|
|
output="./simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDeviceCorrection.h"
|
|
|
|
#variable
|
|
declare -i current_line=79
|
|
declare -i col_index=0
|
|
declare -i row_index=0
|
|
#declare -i coeff=1
|
|
#declare -i offset=0
|
|
|
|
declare -i current_gain=0
|
|
#declare -i vin_gain=0
|
|
#declare -i vout_gain=0
|
|
MAC="MAC"
|
|
|
|
#constant
|
|
declare -i ADC_CURRENT_GAIN_NUMBER=3
|
|
declare -i ADC_VOLTAGE_GAIN_NUMBER=1
|
|
declare -i DAC_GAIN_NUMBER=1
|
|
|
|
while read -r line; do
|
|
for word in $line; do
|
|
# get device MAC
|
|
if [ $row_index -eq 0 ] && [ $col_index -eq 1 ];then
|
|
MAC=$word
|
|
sed -i "${current_line} i {" "$output"
|
|
sed -i "${current_line} i \\\n#ifdef BOARD_${MAC}" "$output"
|
|
sed -i 's/:/_/g' "$output"
|
|
current_line=$current_line+3
|
|
fi
|
|
|
|
#get ADC current cali data
|
|
declare -i Iin_range=2+$ADC_CURRENT_GAIN_NUMBER
|
|
if [ $row_index -gt 1 ] && [ $row_index -lt $Iin_range ];then
|
|
|
|
if [ $col_index -eq 1 ];then
|
|
sed -i "${current_line} i \\\t.ADC_current[${current_gain}].coeff = ($word)," "$output"
|
|
current_line=$current_line+1
|
|
|
|
elif [ $col_index -eq 2 ];then
|
|
sed -i "${current_line} i \\\t.ADC_current[${current_gain}].offset = ($word)," "$output"
|
|
current_line=$current_line+1
|
|
|
|
if [ $current_gain -lt 2 ];then
|
|
current_gain=$current_gain+1
|
|
else
|
|
current_gain=0
|
|
fi
|
|
fi
|
|
|
|
#get DAC Vout cali data
|
|
declare -i Vout_range=$Iin_range+$DAC_GAIN_NUMBER
|
|
elif [ $row_index -gt 1 ] && [ $row_index -lt $Vout_range ];then
|
|
if [ $col_index -eq 1 ];then
|
|
sed -i "${current_line} i \\\t.Usercode2DAC.coeff = ($word)," "$output"
|
|
current_line=$current_line+1
|
|
|
|
elif [ $col_index -eq 2 ];then
|
|
sed -i "${current_line} i \\\t.Usercode2DAC.offset = ($word)," "$output"
|
|
current_line=$current_line+1
|
|
fi
|
|
|
|
#get ADC Vin cali data
|
|
declare -i Vin_range=$Vout_range+$ADC_VOLTAGE_GAIN_NUMBER
|
|
elif [ $row_index -gt 1 ] && [ $row_index -lt $Vin_range ];then
|
|
if [ $col_index -eq 1 ];then
|
|
sed -i "${current_line} i \\\t.ADC_volt.coeff = ($word)," "$output"
|
|
current_line=$current_line+1
|
|
|
|
elif [ $col_index -eq 2 ];then
|
|
sed -i "${current_line} i \\\t.ADC_volt.offset = ($word)," "$output"
|
|
current_line=$current_line+1
|
|
fi
|
|
fi
|
|
|
|
#update index
|
|
if [ $col_index -lt 2 ];then
|
|
col_index=$col_index+1
|
|
else
|
|
col_index=0
|
|
row_index=$row_index+1
|
|
fi
|
|
done
|
|
done < $input
|
|
|
|
sed -i "${current_line} i };" "$output"
|
|
current_line=$current_line+1
|
|
sed -i "${current_line} i #endif" "$output"
|