#!/bin/sh
. /lib/dyiot/bin/diag_sys.sh

json_init

# uboot_env=`fw_printenv`
uboot_env=$(factory get)
mac_addr=$(echo "$uboot_env" | awk -F'=' '/^MAC=/{print $2}')
sn=$(echo "$uboot_env" | awk -F'=' '/^SN=/{print $2}')
hwver=$(echo "$uboot_env" | awk -F'=' '/^HWVER=/{print $2}')
fdate=$(echo "$uboot_env" | awk -F'=' '/^DATE=/{print $2}')
echo "HWVER: $hwver"
echo "SN: $sn"
echo "DATE: $date"
echo "SWVER: $(cat /etc/issue)"
json_add_string "sn" "$sn"
json_add_string "product" "$PRODUCT"
json_add_int "timestamp" $(date +%s)
json_add_string "MAC" "$mac_addr"
json_add_string "MAC1" "$mac_addr1"
json_add_string "HWVER": "$hwver"
json_add_string "SWVER": "$(cat /etc/issue)"

prepare_env

json_add_object "data"

json_add_array	"ALL"

msg=$(test_led led-heart led-internet led-pcie1 led-pcie2 led-pcie3 led-pcie4 led-wlan mt76-phy1 mt76-phy0)
ret=$?
json_add_result_to_obj "led" "$ret" "$msg"

msg=$(test_rtc)
ret=$?
json_add_result_to_obj "RTC" "$ret" "$msg"

msg=$(test_internet usb0)
ret=$?
json_add_result_to_obj "4G" "$ret" "$msg"

msg=$(test_internet eth0.4090)
ret=$?
json_add_result_to_obj "WAN" "$ret" "$msg"

msg=$(test_lan)
ret=$?
json_add_result_to_obj "LAN" "$ret" "$msg"

msg=$(test_hci hci0)
ret=$?
json_add_result_to_obj "BLE1" "$ret" "$msg"

msg=$(test_hci hci1)
ret=$?
json_add_result_to_obj "BLE2" "$ret" "$msg"

msg=$(test_hci hci2)
ret=$?
json_add_result_to_obj "BLE3" "$ret" "$msg"

json_close_array
json_close_object

echo ""
echo "---TEST SUMMARY---"
#cat $TEST_SUMMARY
sleep 1
json_str=$(json_dump)
echo "test_result:$json_str"

restore_env