#!/bin/sh
if [ "$2" = "" ];then
	echo "Usage:$0 [conf] [sn]"
	exit 0
fi

MS_CHECK_HEADER="ms_check:"
MS_ERROR_HEADER="ms_error:"
MS_SUCCESS_HEADER="ms_success"

C_SN=$2
SUMMARY=`ubus call yruo_status get '{"base":"summary"}'`
CELLULAR=`ubus call yruo_status get '{"base":"yruo_celluar"}'`
WIFI_STATUS=`ubus call yruo_wifi_status get '{"base":"yruo_wifi_status"}'`
PINFO_PRODUCTID=60
PINFO_CELLULAR="10000"
PINFO_WIFI="31"
PINFO_GPS=0
PINFO_WIFICTY="00"
PINFO_BLE=0
PINFO_POE=0
PINFO_HELIUM=0
PINFO_LORAFREQID=0
PINFO_LORAREGIONID=0
PINFO_ANT=1
PINFO_SN=""
PINFO_HWVER=""
PINFO_OEM=""
PINFO_PN1="0000000000000"
LORAWAN_BAND=""
DINFO_MODEL=""
DINFO_CELLULAR_VERSION=""
DINFO_CELLULAR_MODEL=""
DINFO_WIFI_MAC=""
DINFO_WIFI_SSID=""
DINFO_ECC608_KEY=""

print_log()
{
	if [ "$1" = "check" ];then
		echo "ms_check: $2"
	fi
        if [ "$1" = "error" ];then                                              
                echo "ms_error: $2"                                             
        fi
        if [ "$1" = "success" ];then                                              
                echo "ms_success: $2"                                             
        fi
        if [ "$1" = "info" ];then
                echo "ms_info: $2"
        fi
}

get_product_id()
{
	PINFO_PRODUCTID=`urtool -g  | grep "product" | awk -F ': ' '{print $2}'`
}

get_product_sn()
{
	PINFO_SN=`urtool -g  | grep "sn              : " | awk -F ': ' '{print $2}'`
}

get_product_pn1()
{
    PINFO_PN1=`urtool -g  | grep "sonboardsn" | awk -F ': ' '{print $2}'`
    PINFO_CELLULAR=${PINFO_PN1:0:5}
	PINFO_WIFI=${PINFO_PN1:5:2}
	PINFO_GPS=${PINFO_PN1:11:1}
}

get_product_pn2()
{
    	PINFO_PN2=`urtool -g  | grep "reserved" | awk -F ': ' '{print $2}'`
	PINFO_WIFICTY=${PINFO_PN2:0:2}
	PINFO_BLE=${PINFO_PN2:2:2}
	PINFO_POE=${PINFO_PN2:4:1}
	PINFO_HELIUM=${PINFO_PN2:5:1}
	PINFO_LORAFREQID=${PINFO_PN2:6:1}
	PINFO_LORAREGIONID=${PINFO_PN2:7:1}
	PINFO_ANT=${PINFO_PN2:9:1}
}

get_product_hwver()  
{                  
        PINFO_HWVER=`urtool -g  | grep "hwver" | awk -F ': ' '{print $2}'`
}

get_product_oem()
{                  
        PINFO_OEM=`urtool -g  | grep "oem" | awk -F ': ' '{print $2}'`
}

get_device_model_name()
{
	DINFO_MODEL=`echo $SUMMARY | awk -F '"model": ' '{print $2}' |awk -F ',' '{print $1}' |awk -F '"' '{print $2}'`
}

get_lorawan_band()
{
	LORAWAN_BAND=`echo $SUMMARY | awk -F '"lorawan_band": ' '{print $2}' |awk -F '"' '{print $2}'`
}

get_device_cellular_info()
{                                                                                                                            
        tmp=`echo $CELLULAR | awk -F '"version": ' '{print $2}' |awk -F ',' '{print $1}'`
        size=`expr length $tmp`                                  
        size=$((size-2))                                         
        DINFO_CELLULAR_VERSION=${tmp:1:$size}
} 

get_device_wifi_info()
{                                                                                                                            
        tmp=`echo $WIFI_STATUS | awk -F '"hw": ' '{print $2}' |awk -F ',' '{print $1}'`
        size=`expr length $tmp`                                                                                                     
        size=$((size-2))                                                                                                            
        DINFO_WIFI_MAC=${tmp:1:$size}
        tmp=`echo $WIFI_STATUS | awk -F '"ssid": ' '{print $2}' |awk -F ',' '{print $1}'`
        size=`expr length $tmp`                                                                                                     
        size=$((size-2))                                                                                                            
        DINFO_WIFI_SSID=${tmp:1:$size}
} 

get_device_ecc608_key()
{
        tmp=`gateway_mfr key 0 | grep key | awk -F ': ' '{print $2}' |awk -F ',' '{print $1}'`
        size=`expr length $tmp`                                                                                                             
        size=$((size-2))                                                                                                                    
        DINFO_ECC608_KEY=${tmp:1:$size}
}

switch_pinfo_to_cellular_name()
{
	case $PINFO_CELLULAR in
		"L00J0")
		PINFO_CELLULAR_NAME="EC25J"
		;;
		"L00AF")
		PINFO_CELLULAR_NAME="EC25AF"
		;;
		"L04AF")
        PINFO_CELLULAR_NAME="EC25AFX"
        ;; 
        "L00AU")                                                    
        PINFO_CELLULAR_NAME="EC25AU"
        ;; 
        "L04AU")                                                    
        PINFO_CELLULAR_NAME="EC25AUX"
        ;; 
        "L00E0")
        PINFO_CELLULAR_NAME="EC25E"
        ;; 
        "L04EU")
        PINFO_CELLULAR_NAME="EC25EUX"
        ;; 
        "L01CE")                                                    
        PINFO_CELLULAR_NAME="EC20CE"
		;;
		"L06CN")
		PINFO_CELLULAR_NAME="EC200SCN"
        ;; 
        "L01CN")
        PINFO_CELLULAR_NAME="EC200CN"
        ;; 
		*)
        PINFO_CELLULAR_NAME="None"
        ;; 
	esac
}

update_lora_freq()
{       
    case $PINFO_LORAFREQID in
	1)
		PINFO_LORA_FREQ=433
		;;  
	2)
		PINFO_LORA_FREQ=470
		cp /etc/quagga/lora/global_conf.json.CN470 /etc/quagga/lora/local_conf.json
		;;        
	3)
		PINFO_LORA_FREQ=868
		cp /etc/quagga/lora/global_conf.json.EU868 /etc/quagga/lora/local_conf.json
		sed -i '4c     "region": 0,' /etc/quagga/lora/ur_conf.json
		;;         
	4)      
		PINFO_LORA_FREQ=915
		cp /etc/quagga/lora/global_conf.json.AS923 /etc/quagga/lora/local_conf.json
		sed -i '4c     "region": 4,' /etc/quagga/lora/ur_conf.json
		;;
	esac
}   

check_pinfo()
{
	print_log info "check pinfo...."
	if [ "$PINFO_SN" != "$C_SN" ];then
		print_log error "check pinfo sn(PINFO_SN($PINFO_SN) != C_SN($C_SN))"
		echo "check_SN:PINFO_SN($PINFO_SN) != C_SN($C_SN)" >> result
	else
		print_log success "check SN"
		echo "check_SN:success" >> result
	fi
	if [ "$PINFO_PN1" != "$C_SONBOARDSN" ];then
		print_log error "check pinfo sn(PINFO_PN1($PINFO_PN1) != C_SONBOARDSN($C_SONBOARDSN))"
		echo "check_SONBOARDSN:PINFO_PN1($PINFO_PN1) != C_SONBOARDSN($C_SONBOARDSN)" >> result
	else
		print_log success "check SONBOARDSN"
		echo "check_SONBOARDSN:success" >> result
	fi
	if [ "$PINFO_PN2" != "$C_RESERVED" ];then                                                               
    		print_log error "check pinfo sn(PINFO_PN2($PINFO_PN2) != R_PN2($C_RESERVED))"
		echo "check_RESERVED:PINFO_PN2($PINFO_PN2) != R_PN2($C_RESERVED)" >> result
	else
		print_log success "check RESERVED"
		echo "check_RESERVED:success" >> result
    	fi
    	if [ "$PINFO_OEM" != "$C_OEM" ];then
        	print_log error "check pinfo sn(PINFO_OEM($PINFO_OEM) != C_OEM($C_OEM))"
		echo "check_OEM:PINFO_OEM($PINFO_OEM) != C_OEM($C_OEM)" >> result
	else
		print_log success "check OEMid"
		echo "check_OEM:success" >> result
    	fi
	#if [ "$DINFO_MODEL" != "$C_MODEL" ];then
    #    print_log error "check pinfo sn(DINFO_MODEL($DINFO_MODEL) != C_MODEL($C_MODEL))"
	#	echo "check_MODEL:DINFO_MODEL($DINFO_MODEL) != C_MODEL($C_MODEL)" >> result
	#else
	#	print_log success "check MODEL"
    #    echo "check_MODEL:success"  >> result                                                                  
    #fi
	if [ "$PINFO_PRODUCTID" == "$C_PRODUCT" ];then
		echo "check_PRODUCT:success" >> result
		print_log success "check PRODUCT"
	else
		print_log error "check product ($PINFO_PRODUCTID != $C_PRODUCT)"
		echo "check_PRODUCT:product ($PINFO_PRODUCTID != $C_PRODUCT)" >> result
	fi
}

check_raminfo()
{
	print_log info "check raminfo...."
	ramsize=`echo $SUMMARY | awk -F '"memory_total": ' '{print $2}' | awk -F ',' '{print $1}'`
	if [ "$ramsize" = "$C_RAM" ];then
		echo "check_RAM:success" >> result
		print_log success "check RAM"
	else
		print_log error "check raminfo ($ramsize != $C_RAM)"
		echo "check_RAM:raminfo ($ramsize != $C_RAM)" >> result
	fi
}

check_emmcinfo()
{
	print_log info "check emmcinfo...."
	emmc_total=`echo $SUMMARY | awk -F '"emmc_total": ' '{print $2}' | awk -F '"' '{print $2}'`
	if [ "$emmc_total" = "$C_EMMC" ];then
		echo "check_EMMC:success" >> result
		print_log success "check EMMC"
	else
		print_log error "check emmcinfo ($emmc_total != $C_EMMC)"
		echo "check_EMMC:emmcinfo ($emmc_total != $C_EMMC)" >> result
	fi
}

check_cellular_module()
{
	print_log info "check cellular module...."
	version=`echo $CELLULAR | awk -F '"version": ' '{print $2}' |awk -F ',' '{print $1}'`
	result=`echo $version |grep $PINFO_CELLULAR_NAME`
	if [ "$result" != "" ];then
		echo "check_CELLULAR:success" >> result
		print_log success "check CELLULAR MODULE"
	else
		print_log error "check cellular module ($PINFO_CELLULAR_NAME not in $version,hw != sw)"
		echo "check_CELLULAR:module ($PINFO_CELLULAR_NAME not in $version,hw != sw)" >> result
	fi
}

check_ping_cellular_network()
{
	print_log info "check ping cellular...."
	ping=`ping -c $C_CELLULAR_PING_COUNT $C_CELLULAR_PING_IP`
	ping=`echo $ping | awk -F 'packets received, ' '{print $2}'| awk -F '%' '{print $1}'`
	if [ "$ping" -lt "$C_CELLULAR_PING_THRESHOLD" ];then
        	echo "check_CELLULAR_PING:success" >> result
		print_log success "check CELLULAR PING"
	else
		print_log error "check packet loss $ping% > $C_CELLULAR_PING_THRESHOLD%"
		echo "check_CELLULAR_PING:packet loss $ping% > $C_CELLULAR_PING_THRESHOLD%" >> result
	fi
}

check_wifi_module_connect()
{
	print_log info "check wifi start...."
	wifi_enable=`echo $WIFI_STATUS | awk -F '"enabled": ' '{print $2}' | awk -F ',' '{print $1}'`
	wifi_mode=`echo $WIFI_STATUS | awk -F '"mode": ' '{print $2}' | awk -F ',' '{print $1}'`
	if [ "$wifi_enable" != "1" ] || [ "$wifi_mode" != "0" ];then
		ubus call yruo_wifi set '{"base":"yruo_wifi","index":0,"value":{"enabled":1,"mode":0,"ssid":"test","ht_capab":0,"ip":"192.168.11.1","mask":"255.255.255.0"}}'
		ubus call yruo_apply apply
	fi
}

check_wifi_module()
{
	print_log info "check wifi start time...."
	wifi_time=`ubus call yruo_wifi_status get '{"base":"yruo_wifi_status"}' | grep time | awk -F ': ' '{print $2}' | awk -F '"' '{print $2}' | awk -F ', ' '{print $2}'`
	zero_second=`date -d "00:00:00" +%s`
	now_second=`date -d $wifi_time +%s`
	re=`expr $now_second - $zero_second`
	if [ "$re" -ge "$C_WIFI_TIME_THRESHOLD" ];then
		print_log success "check wifi run time $wifi_time $re (s) >= $C_WIFI_TIME_THRESHOLD"
		echo "check_WIFI:success" >> result
	else
		print_log error "check wifi run time $wifi_time $re (s) < $C_WIFI_TIME_THRESHOLD"
		echo "check_WIFI:run time $wifi_time $re (s) < $C_WIFI_TIME_THRESHOLD" >> result
	fi
}

check_gps_module()
{
	print_log info "check gps module...."
	if [ -f /tmp/gps.info ];then
		echo "check_GPS:success" >> result
		print_log success "check GPS"
	else
		print_log error "check gps module failed!" 
		echo "check_GPS:failed" >> result
	fi
}

check_lora_freq()
{
	print_log info "check lora freq...."
	LORAFREQ=`cat /tmp/freqinfo`
	if [ "$PINFO_LORA_FREQ" == "$LORAFREQ" ];then
		echo "check_LORAFREQ:success" >> result
		print_log success "check LORAFREQ"
	else
		print_log error "check lora freq (hwfreq-$LORAFREQ, swfreq-$PINFO_LORA_FREQ)"
		echo "check_LORAFREQ:lora freq (hwfreq-$LORAFREQ, swfreq-$PINFO_LORA_FREQ)" >> result
	fi
}

check_lorawan_band()
{
	print_log info "check lorawan band...."
	if [ "$LORAWAN_BAND" == "$C_LORA" ];then
		echo "check_LORAWAN_BAND:success" >> result
		print_log success "check LORAWAN_BAND"
	else
		print_log error "check lorawan band ($LORAWAN_BAND != $C_LORA)"
		echo "check_LORAWAN_BAND:lorawan band ($LORAWAN_BAND != $C_LORA)" >> result
	fi
}

check_lora_antenna_cfg_ITXIRX()
{
	print_log info "check lora ITXIRX snr rssi...."
	rm /etc/urlog/lora-pkt-fwd.log
	sed -i.sav 's/\"antenna_cfg\": \"OTXRX\"/\"antenna_cfg\": \"ITXIRX\"/g' /etc/quagga/lora/local_conf.json
	sed -i.sav 's/\"antenna_cfg\": \"OTXORX\"/\"antenna_cfg\": \"ITXIRX\"/g' /etc/quagga/lora/local_conf.json
	sleep 1
	/etc/init.d/lora_pkt_fwd restart
	/etc/init.d/lora_gateway_ubus restart
	count=0
	snr_success=0
	snr_failed=0
	rssi_success=0
	rssi_failed=0
	sleep 5
	while [ $count -lt $C_LORA_CHECK_TIME ]
	do
		sleep 10
		re=`grep $C_LORA_DATA /etc/urlog/lora-pkt-fwd.log`
		if [ "$re" = "" ];then
			print_log error "count=$count:check lora ITXIRX failed!"
			#echo "check_ITXIRX:no lora data" >> result
			snr_failed=`expr $snr_failed + 1`
			rssi_failed=`expr $rssi_failed + 1`
			count=`expr $count + 10`
			continue
		fi
		ssnr=`grep $C_LORA_DATA /etc/urlog/lora-pkt-fwd.log | tail -n 1 | awk -F 'snr\":' '{print $2}' | awk -F ',' '{print $1}'`
		rssi=`grep $C_LORA_DATA /etc/urlog/lora-pkt-fwd.log | tail -n 1 | awk -F 'rssi\":' '{print $2}' | awk -F ',' '{print $1}'`
		
		snr=`echo $ssnr | awk -F '.' '{print $1}'`
		check_snr=`echo $snr | grep -`
		if [ "$check_snr" = "" ];then
			if [ $snr -ge $C_SNR_THRESHOLD_IN ];then
				snr_success=`expr $snr_success + 1`
				#echo "check_ITXIRX_SNR:success" >> result
				print_log success "count=$count:check lora ITXIRX snr=$ssnr"
			else
				snr_failed=`expr $snr_failed + 1`
				print_log error "count=$count:check lora ITXIRX snr=$ssnr failed!"                                                          
				#echo "check_ITXIRX_SNR:snr=$ssnr(expect:snr>$C_SNR_THRESHOLD_IN)" >> result
			fi
		else
			snr_failed=`expr $snr_failed + 1`
			print_log error "count=$count:check lora ITXIRX snr=$ssnr < 0!"                                                   
			#echo "check_ITXIRX_SNR:snr=$ssnr(expect:snr>$C_SNR_THRESHOLD_IN)" >> result
		fi
		if [[ $rssi -le $C_RSSI_THRESHOLD_IN ]];then                                                                                  
			print_log error "count=$count:check lora ITXIRX rssi=$rssi failed!"                                                                         
			#echo "check_ITXIRX_RSSI:rssi=$rssi(expect:rssi>$C_RSSI_THRESHOLD_IN)" >> result  
			rssi_failed=`expr $rssi_failed + 1`				
		else       
			rssi_success=`expr $rssi_success + 1`
			#echo "check_ITXIRX_RSSI:success" >> result   
			print_log success "count=$count:check lora ITXIRX rssi=$rssi"                                                                                                      
		fi
		count=`expr $count + 10`
	done
	if [ $snr_success -ge $snr_failed ];then
		echo "check_ITXIRX_SNR:success" >> result
		print_log success "check lora ITXIRX snr_success=$snr_success / snr_failed=$snr_failed"
	else                                                    
		echo "check_ITXIRX_SNR:SNR failed" >> result
		print_log error "check lora ITXIRX snr_success=$snr_success / snr_failed=$snr_failed"
	fi
	if [ $rssi_success -ge $rssi_failed ];then
		echo "check_ITXIRX_RSSI:success" >> result
		print_log success "check lora ITXIRX rssi_success=$rssi_success / rssi_failed=$rssi_failed" 
	else                                                    
		echo "check_ITXIRX_RSSI:RSSI failed" >> result
		print_log error "check lora ITXIRX rssi_success=$rssi_success / rssi_failed=$rssi_failed" 
	fi
	count=`expr $C_LORA_CHECK_TIME / 10`
	grep $C_LORA_DATA /etc/urlog/lora-pkt-fwd.log | tail -n $count
}

check_lora_antenna_cfg_OTXORX()             
{                            
	print_log info "check lora OTXORX/OTXRX snr rssi...."                                              
    rm /etc/urlog/lora-pkt-fwd.log
	if [ $PINFO_PRODUCTID -eq 67 ];then
		sed -i.sav 's/\"antenna_cfg\": \"ITXIRX\"/\"antenna_cfg\": \"OTXORX\"/g' /etc/quagga/lora/local_conf.json 
	else
	    sed -i.sav 's/\"antenna_cfg\": \"ITXIRX\"/\"antenna_cfg\": \"OTXRX\"/g' /etc/quagga/lora/local_conf.json
	fi
    /etc/init.d/lora_pkt_fwd restart
	/etc/init.d/lora_gateway_ubus restart                                                                                                         
	count=0
	snr_success=0
	snr_failed=0
	rssi_success=0
	rssi_failed=0
	sleep 5
	while [ $count -lt $C_LORA_CHECK_TIME ]
	do
		sleep 10
        re=`grep $C_LORA_DATA /etc/urlog/lora-pkt-fwd.log`                                             
        if [ "$re" = "" ];then
            print_log error "count=$count:check lora OTXORX/OTXRX failed!"
			#echo "check_OTXORX/OTXRX:no lora data" >> result
			count=`expr $count + 10`
			rssi_failed=`expr $rssi_failed + 1`
			snr_failed=`expr $snr_failed + 1`
            continue                                                                             
        fi         
        ssnr=`grep $C_LORA_DATA /etc/urlog/lora-pkt-fwd.log | tail -n 1 | awk -F 'snr\":' '{print $2}' | awk -F ',' '{print $1}'`
        rssi=`grep $C_LORA_DATA /etc/urlog/lora-pkt-fwd.log | tail -n 1 | awk -F '\"rssi\":' '{print $2}' | awk -F ',' '{print $1}'`
         
        snr=`echo $ssnr | awk -F '.' '{print $1}'`                                                                                   
        check_snr=`echo $snr | grep -`                                                                                               
        if [ "$check_snr" = "" ];then                                                                                                
			if [ $snr -ge $C_SNR_THRESHOLD_OUT ];then                                                                                
				#echo "check_OTXORX/OTXRX_SNR:success" >> result    
				print_log success "count=$count:check loraa OTXORX/OTXRX snr=$ssnr"
				snr_success=`expr $snr_success + 1`				
			else
				snr_failed=`expr $snr_failed + 1`
				print_log error "count=$count:check lora OTXORX/OTXRX snr=$ssnr failed!"                                                  
				#echo "check_OTXORX/OTXRX_SNR:snr=$snr(expect:snr>$C_SNR_THRESHOLD_OUT)" >> result                                      
			fi                                                                                                                   
        else
			snr_failed=`expr $snr_failed + 1`
			print_log error "count=$count:check lora OTXORX/OTXRX snr=$ssnr < 0!"                       
			#echo "check_OTXORX/OTXRX_SNR:snr=$snr(expect:snr>$C_SNR_THRESHOLD_OUT)" >> result        
        fi            
        
        if [ $rssi -le $C_RSSI_THRESHOLD_OUT ];then      
			rssi_failed=`expr $rssi_failed + 1`
			print_log error "count=$count:check lora OTXORX/OTXRX rssi=$rssi failed!"                                                                                  
			#echo "check_OTXORX/OTXRX_RSSI:rssi=$rssi(expect:rssi>$C_RSSI_THRESHOLD_OUT)" >> result                                                                  
        else                                                                                                                                                  
			#echo "check_OTXORX/OTXRX_RSSI:success" >> result    
			print_log success "count=$count:check lora OTXORX/OTXRX rssi=$rssi" 
			rssi_success=`expr $rssi_success + 1`
        fi 
		count=`expr $count + 10`
	done
	if [ $snr_success -ge $snr_failed ];then
		echo "check_OTXORX/OTXRX_SNR:success" >> result
		print_log success "check lora OTXORX/OTXRX snr_success=$snr_success / snr_failed=$snr_failed" 
	else                                                      
		echo "check_OTXORX/OTXRX_SNR:SNR failed" >> result
		print_log error "check lora OTXORX/OTXRX snr_success=$snr_success / snr_failed=$snr_failed" 
	fi
	if [ $rssi_success -ge $rssi_failed ];then
		echo "check_OTXORX/OTXRX_RSSI:success" >> result
		print_log success "check lora OTXORX/OTXRX rssi_success=$rssi_success / rssi_failed=$rssi_failed" 
	else                                                      
		echo "check_OTXORX/OTXRX_RSSI:RSSI failed" >> result
		print_log error "check lora OTXORX/OTXRX rssi_success=$rssi_success / rssi_failed=$rssi_failed" 
	fi
	count=`expr $C_LORA_CHECK_TIME / 10`
	grep $C_LORA_DATA /etc/urlog/lora-pkt-fwd.log | tail -n $count
}
   
check_lora_antenna_cfg()
{
	#ubus call yruo_loragw set '{"base":"yruo_loragw","index":0,"value":{"gateway_id":"24E124FFFEF31D49","servs":[{"id":0,"serv_enabled":true,"serv_addr":"localhost","serv_type":"ursalink","serv_port_up":1700,"serv_port_down":1700,"serv_mqtt_port":1883,"sync_freq_plan":false,"connected":1},{"id":1,"sync_freq_plan":false,"serv_type":"semtech","serv_addr":"iot.cloud.assek.ca","serv_port_up":1700,"serv_port_down":1700,"serv_enabled":false}]},"base":"general_conf"}'
	check_lora_antenna_cfg_ITXIRX
	if [ "$C_ifANT_OUT" = "1" ];then
		check_lora_antenna_cfg_OTXORX
	fi
}

version()
{
	firmware_version=`echo $SUMMARY | awk -F '"firmware_ver": ' '{print $2}' | awk -F '"' '{print $2}'`
	hardware_version=`echo $SUMMARY | awk -F '"hardware_ver": ' '{print $2}' | awk -F '"' '{print $2}'`
	cellular_version=`echo $CELLULAR | awk -F '"version": ' '{print $2}' |awk -F ',' '{print $1}'`
	imei=`echo $CELLULAR | awk -F '"imei": ' '{print $2}' |awk -F ',' '{print $1}' |awk -F ' ' '{print $1}'`
	echo "check_FIRMWARE:success-$firmware_version" >> result
	echo "check_HARDWARE:success-$hardware_version" >> result
	echo "check_CELLULAR_VERSION:success-$cellular_version" >> result
	echo "check_IMEI:success-$imei" >> result
	echo "check_MODEL:success-$DINFO_MODEL" >> result
}

get_product_id
get_product_sn
get_product_pn1
get_product_pn2
get_product_hwver
get_product_oem
get_lorawan_band
get_device_model_name
get_device_cellular_info
get_device_wifi_info
switch_pinfo_to_cellular_name

print_detail_info()
{
	echo $DINFO_WIFI_MAC
	echo $DINFO_WIFI_SSID
	echo $DINFO_CELLULAR_VERSION
	echo $DINFO_MODEL
	echo $PINFO_CELLULAR_NAME
	echo $PINFO_PRODUCTID
	echo $PINFO_SN
	echo $PINFO_PN1
	echo $PINFO_PN2
	echo $PINFO_HWVER
	echo $PINFO_OEM
	echo $PINFO_CELLULAR
	echo $PINFO_WIFI
	echo $PINFO_GPS
	echo $PINFO_WIFICTY
	echo $PINFO_POE
	echo $PINFO_HELIUM
	echo $PINFO_LORAFREQID
	echo $PINFO_LORAREGIONID
	echo $PINFO_ANT
}

source $1
urtool -g
echo "[RESULT]" > result
check_wifi_module_connect
update_lora_freq
#print_detail_info
check_pinfo
version
check_raminfo
check_emmcinfo
if [ "$C_ifCELLULAR" == "1" ];then
	check_cellular_module
fi
if [ "$C_ifCELLULAR_PING" == "1" ];then                                                                     
        check_ping_cellular_network                                                                    
fi
if [ "$C_ifGPS" == "1" ];then
	check_gps_module
fi
check_lora_freq
check_lorawan_band
check_lora_antenna_cfg
if [ "$C_ifWIFI" == "1" ];then                                                                         
        check_wifi_module                                                                              
fi 

echo "MILESIGHT=TEST DONE"
