diff --git a/sysmngr/Config.in b/sysmngr/Config.in index b50011fcd..6bdfb4b7b 100644 --- a/sysmngr/Config.in +++ b/sysmngr/Config.in @@ -36,4 +36,8 @@ config SYSMNGR_FWBANK_UBUS_SUPPORT bool "Expose fwbank ubus object" default y +config SYSMNGR_TEMPERATURE_STATUS + bool "Enable Device.DeviceInfo.TemperatureStatus. Object" + default y + endif diff --git a/sysmngr/Makefile b/sysmngr/Makefile index 87426f276..444a316cc 100644 --- a/sysmngr/Makefile +++ b/sysmngr/Makefile @@ -5,13 +5,13 @@ include $(TOPDIR)/rules.mk PKG_NAME:=sysmngr -PKG_VERSION:=1.0.13 +PKG_VERSION:=1.0.14 LOCAL_DEV:=0 ifneq ($(LOCAL_DEV),1) PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://dev.iopsys.eu/system/sysmngr.git -PKG_SOURCE_VERSION:=222a188425d70733938e70ee23c55bac62f8a0f4 +PKG_SOURCE_VERSION:=93dfeb49df371685a2e155a3c6d24fe8e9d110b6 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz PKG_MIRROR_HASH:=skip endif @@ -86,6 +86,10 @@ ifeq ($(CONFIG_SYSMNGR_FWBANK_UBUS_SUPPORT),y) MAKE_FLAGS += SYSMNGR_FWBANK_UBUS_SUPPORT=y endif +ifeq ($(CONFIG_SYSMNGR_TEMPERATURE_STATUS),y) +MAKE_FLAGS += SYSMNGR_TEMPERATURE_STATUS=y +endif + define Package/$(PKG_NAME)/install $(INSTALL_DIR) $(1)/etc/config $(INSTALL_CONF) ./files/etc/config/sysmngr $(1)/etc/config/sysmngr @@ -105,6 +109,16 @@ define Package/$(PKG_NAME)/install $(BBFDM_REGISTER_SERVICES) ./bbfdm_service.json $(1) $(PKG_NAME) $(INSTALL_BIN) ./files/etc/sysmngr/fwbank $(1)/etc/sysmngr/fwbank + +ifeq ($(CONFIG_SYSMNGR_TEMPERATURE_STATUS),y) + $(INSTALL_DIR) $(1)/etc/sysmngr +ifeq ($(CONFIG_TARGET_brcmbca),y) + $(INSTALL_BIN) ./files/etc/sysmngr/broadcom.sh $(1)/etc/sysmngr/temperature.sh +else + $(INSTALL_BIN) ./files/etc/sysmngr/default.sh $(1)/etc/sysmngr/temperature.sh +endif +endif + endef $(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/sysmngr/files/etc/sysmngr/broadcom.sh b/sysmngr/files/etc/sysmngr/broadcom.sh new file mode 100644 index 000000000..2f44070f6 --- /dev/null +++ b/sysmngr/files/etc/sysmngr/broadcom.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +. /usr/share/libubox/jshn.sh +. /lib/functions.sh + +function get_wlan_temperature() +{ + add_wlan_temp() { + local temp="$(wlctl -i "$1" phy_tempsense)" + [ -n "$temp" ] || temp='-274' + + json_add_object + json_add_string "name" "wlan-$1" + json_add_int "temperature" "$temp" + json_close_object + } + + config_load wireless + config_foreach add_wlan_temp wifi-device +} + +function get_sfp_temperature() +{ + local temp="" + local sfp="$(ubus call sfp.ddm get-temperature)" + + json_load "$sfp" + json_get_var temp temperature + + [ -n "$temp" ] || temp='-274' + + echo "$temp" +} + +function get_cpu_temperature() +{ + local cpu="$(cat /sys/devices/virtual/thermal/thermal_zone0/temp 2>/dev/null)" + [ -n "$cpu" ] || cpu='-274000' + + echo "${cpu:0:-3}" +} + +function get_temperature_status() +{ + local hasWifi="$(db -q get hw.board.hasWifi)" + local hasSfp="$(db -q get hw.board.hasSfp)" + + json_init + + json_add_array "status" + + json_add_object + json_add_string "name" "cpu" + json_add_int "temperature" "$(get_cpu_temperature)" + json_close_object + + [ "$hasWifi" = "1" ] && get_wlan_temperature + + [ "$hasSfp" = "1" ] && { + json_add_object + json_add_string "name" "sfp" + json_add_int "temperature" "$(get_sfp_temperature)" + json_close_object + } + + json_close_array + + json_dump +} + +function dump_invalid() +{ + json_init + json_add_string "fault" "invalid request" + json_dump +} + +case "$1" in + status) + get_temperature_status + ;; + *) + dump_invalid + ;; +esac diff --git a/sysmngr/files/etc/sysmngr/default.sh b/sysmngr/files/etc/sysmngr/default.sh new file mode 100644 index 000000000..282042904 --- /dev/null +++ b/sysmngr/files/etc/sysmngr/default.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +. /usr/share/libubox/jshn.sh +. /lib/functions.sh + +function get_wlan_temperature() +{ + : +} + +function get_sfp_temperature() +{ + echo "-274" +} + +function get_cpu_temperature() +{ + echo "-274" +} + +function get_temperature_status() +{ + local hasWifi="$(db -q get hw.board.hasWifi)" + local hasSfp="$(db -q get hw.board.hasSfp)" + + json_init + + json_add_array "status" + + json_add_object + json_add_string "name" "cpu" + json_add_int "temperature" "$(get_cpu_temperature)" + json_close_object + + [ "$hasWifi" = "1" ] && get_wlan_temperature + + [ "$hasSfp" = "1" ] && { + json_add_object + json_add_string "name" "sfp" + json_add_int "temperature" "$(get_sfp_temperature)" + json_close_object + } + + json_close_array + + json_dump +} + +function dump_invalid() +{ + json_init + json_add_string "fault" "invalid request" + json_dump +} + +case "$1" in + status) + get_temperature_status + ;; + *) + dump_invalid + ;; +esac