#!/bin/ash

# script to print temperature sensor values for barbados board
# Temperature sensor table
#-----------------------------------------------------------
#     |   Barbados       |       Milos            |  comment
#------------------------------------------------------------
#     |   Refdes | addr  |     Refdes  |   addr   |
#------------------------------------------------------------
#i2c0 |   U82    | 0x4f  |      U81    |   0x49   | Located on mb
#i2c2 |   -      |  -    |      U2     |   0x49   | Located on radio Module
#i2c2 |   -      |  -    |      U3     |   0x4b   | Located on radio Module
#--------------------------------------------------------------

AP_PLATFORM=`cat /COOKIE_PID`
if [ ! -z "$AP_PLATFORM" ]; then
    case $AP_PLATFORM in
         *3802*|*2802*)
                #Barbados
                f1="/sys/class/thermal/thermal_zone0/temp"
                f2="/sys/bus/i2c/devices/0-004f/temp1_input"
                #
                # Print temperatures
                #
                read t1 < $f1
                echo "A38x CPU temp = $((t1/1000)) C"
                read t2 < $f2
                echo "I2C-0-4f temp = $((t2/1000)) C"
                ;;
         *1562*|*6300*)
                f1="/sys/class/thermal/thermal_zone0/temp"
                f2="/sys/bus/i2c/devices/0-0049/temp1_input"
                f3="/sys/bus/i2c/devices/2-0049/temp1_input"
                f4="/sys/bus/i2c/devices/2-004b/temp1_input"
                #temp1 max
                f5="/sys/bus/i2c/devices/0-0049/temp1_max"
                f6="/sys/bus/i2c/devices/2-0049/temp1_max"
                f7="/sys/bus/i2c/devices/2-004b/temp1_max"
                #temp1 max hyst
                f8="/sys/bus/i2c/devices/0-0049/temp1_max_hyst"
                f9="/sys/bus/i2c/devices/2-0049/temp1_max_hyst"
                fA="/sys/bus/i2c/devices/2-004b/temp1_max_hyst"
                #
                # Print temperatures
                #
                read t1 < $f1
                echo "A38x CPU temp = $((t1/1000)) C"
                read t2 < $f2
                echo "I2C-0-49 temp = $((t2/1000)) C"
                read t3 < $f3
                echo "I2C-2-49 temp = $((t3/1000)) C"
                read t4 < $f4
                echo "I2C-2-4b temp = $((t4/1000)) C"
                #
                # print max thresholds
                #
                read t2 < $f5
                echo "I2C-0-49 Max temp threshold = $((t2/1000)) C"
                read t3 < $f6
                echo "I2C-2-49 Max temp threshold = $((t3/1000)) C"
                read t4 < $f7
                echo "I2C-2-4b Max temp threshold = $((t4/1000)) C"
                #
                # print max hyst thresholds
                #
                read t2 < $f8
                echo "I2C-0-49 Max hyst temp threshold = $((t2/1000)) C"
                read t3 < $f9
                echo "I2C-2-49 Max hyst temp threshold = $((t3/1000)) C"
                read t4 < $fA
                echo "I2C-2-4b Max hyst temp threshold = $((t4/1000)) C"
                ;;
         *)
            echo "Unknown AP type"
            ;;
        esac
fi

if [ -f /meraki_gpio/em_detect ]; then
    if [ `cat /meraki_gpio/em_detect` -eq "0" ]; then
        f5="/sys/bus/i2c/devices/1-004f/temp1_input"
        read t5 < $f5
        echo "I2C-1-4F temp = $((t5/1000)) C"
    fi
fi

