sysmngr: Added TemperatureStatus DM

This commit is contained in:
Suvendhu Hansa 2024-12-30 20:19:45 +05:30 committed by Vivek Kumar Dutta
parent eff826ac39
commit 0f5f018e99
4 changed files with 168 additions and 2 deletions

View file

@ -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

View file

@ -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)))

View file

@ -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

View file

@ -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