# Copyright (c) 2022-2023, NVIDIA CORPORATION. All Rights Reserved. # # NVIDIA CORPORATION and its licensors retain all intellectual property # and proprietary rights in and to this software, related documentation # and any modifications thereto. Any use, reproduction, disclosure or # distribution of this software and related documentation without an express # license agreement from NVIDIA CORPORATION is strictly prohibited. # """This package is a wrapper for libjetsonpower (power library written in C). With this wrapper, we don't need to implement a pythonic power library. In addition, when the underlying C function body changes, we don't need to change the function body here. We only need to ensure that the API interface is consistent with the underlying C library (arguments' types and return type), and the docstring is consistent with the C API documentation comment. """ from ctypes import CDLL, POINTER, c_char_p, c_int, c_long, util __all__ = [ "release_libjetsonpower", # board info "platform_get_name", "nvpmodel_get_power_mode", # cpu "cpu_get_nums", "cpu_get_state", "cpu_get_cur_freq", "cpu_get_max_freq", "cpu_get_min_freq", "cpu_get_load", "cpu_set_state", "cpu_set_max_freq", "cpu_set_min_freq", # gpu "igpu_get_cur_freq", "igpu_get_max_freq", "igpu_get_min_freq", "igpu_get_load", "igpu_set_max_freq", "igpu_set_min_freq", # emc "emc_get_cur_freq", "emc_get_max_freq", "emc_get_min_freq", "emc_get_load", "emc_get_mem_size", "emc_get_free_mem_size", "emc_get_buffers_size", "emc_get_cached_size", "emc_get_swap_size", "emc_get_free_swap_size", "emc_get_cached_swap_size", "emc_set_max_freq", "emc_set_min_freq", # engine "engine_get_nums", "engine_get_names", "engine_get_state", "engine_get_cur_freq", "engine_get_max_freq", "engine_get_min_freq", "engine_set_max_freq", "engine_set_min_freq", # thermal "thermal_get_sensor_nums", "thermal_get_sensor_names", "thermal_get_sensor_policy", "thermal_get_sensor_temp", "thermal_get_sensor_sw_throttling_temp", "thermal_get_sensor_sw_shutdown_temp", "thermal_is_temp_valid", "thermal_set_sensor_policy", # power monitor "rail_get_nums", "rail_get_names", "rail_get_current", "rail_get_power", "rail_get_voltage", "rail_get_warn_current", "rail_get_crit_current", "rail_get_avg_power", "rail_set_warn_current", "rail_set_crit_current", "rail_reset_avg_power", # fan "fan_get_nums", "fan_get_names", "fan_get_pwm", "fan_get_speed", "fan_get_tach_enable", "fan_get_profile", "fan_get_governor", "fan_get_control", "fan_set_pwm", "fan_set_tach_enable", # disk "disk_get_total_size", "disk_get_used_size", ] __clib_name = "jetsonpower" __clib_so = util.find_library(__clib_name) if __clib_so == None: print(f"Error: Cannot find lib{__clib_name}") exit(1) __c_power_lib = CDLL(__clib_so) __c_power_lib.init_libjetsonpower.argtypes = [] __c_power_lib.init_libjetsonpower.restype = int __init_status = __c_power_lib.init_libjetsonpower() __encoding = "utf-8" if (__init_status != 0): print("Error: libjetsonpower initialization fail") exit(1) # Define interfaces for power library __c_power_lib.release_libjetsonpower.argtypes = [] __c_power_lib.release_libjetsonpower.restype = None __c_power_lib.platform_get_name.argtypes = [] __c_power_lib.platform_get_name.restype = c_char_p __c_power_lib.nvpmodel_get_power_mode.argtypes = [] __c_power_lib.nvpmodel_get_power_mode.restype = c_char_p __c_power_lib.cpu_get_nums.argtypes = [] __c_power_lib.cpu_get_nums.restype = c_int __c_power_lib.cpu_get_state.argtypes = [c_int] __c_power_lib.cpu_get_state.restype = c_int __c_power_lib.cpu_get_cur_freq.argtypes = [c_int] __c_power_lib.cpu_get_cur_freq.restype = c_long __c_power_lib.cpu_get_max_freq.argtypes = [c_int] __c_power_lib.cpu_get_max_freq.restype = c_long __c_power_lib.cpu_get_min_freq.argtypes = [c_int] __c_power_lib.cpu_get_min_freq.restype = c_long __c_power_lib.cpu_get_load.argtypes = [c_int] __c_power_lib.cpu_get_load.restype = c_int __c_power_lib.cpu_set_state.argtypes = [c_int, c_int] __c_power_lib.cpu_set_state.restype = c_int __c_power_lib.cpu_set_max_freq.argtypes = [c_int, c_long] __c_power_lib.cpu_set_max_freq.restype = c_int __c_power_lib.cpu_set_min_freq.argtypes = [c_int, c_long] __c_power_lib.cpu_set_min_freq.restype = c_int __c_power_lib.igpu_get_cur_freq.argtypes = [c_int] __c_power_lib.igpu_get_cur_freq.restype = c_long __c_power_lib.igpu_get_max_freq.argtypes = [c_int] __c_power_lib.igpu_get_max_freq.restype = c_long __c_power_lib.igpu_get_min_freq.argtypes = [c_int] __c_power_lib.igpu_get_min_freq.restype = c_long __c_power_lib.igpu_get_load.argtypes = [c_int] __c_power_lib.igpu_get_load.restype = c_int __c_power_lib.igpu_set_max_freq.argtypes = [c_int, c_long] __c_power_lib.igpu_set_max_freq.restype = c_int __c_power_lib.igpu_set_min_freq.argtypes = [c_int, c_long] __c_power_lib.igpu_set_min_freq.restype = c_int __c_power_lib.emc_get_cur_freq.argtypes = [] __c_power_lib.emc_get_cur_freq.restype = c_long __c_power_lib.emc_get_max_freq.argtypes = [] __c_power_lib.emc_get_max_freq.restype = c_long __c_power_lib.emc_get_min_freq.argtypes = [] __c_power_lib.emc_get_min_freq.restype = c_long __c_power_lib.emc_get_load.argtypes = [] __c_power_lib.emc_get_load.restype = c_int __c_power_lib.emc_get_mem_size.argtypes = [] __c_power_lib.emc_get_mem_size.restype = c_int __c_power_lib.emc_get_free_mem_size.argtypes = [] __c_power_lib.emc_get_free_mem_size.restype = c_int __c_power_lib.emc_get_buffers_size.argtypes = [] __c_power_lib.emc_get_buffers_size.restype = c_int __c_power_lib.emc_get_cached_size.argtypes = [] __c_power_lib.emc_get_cached_size.restype = c_int __c_power_lib.emc_get_swap_size.argtypes = [] __c_power_lib.emc_get_swap_size.restype = c_int __c_power_lib.emc_get_free_swap_size.argtypes = [] __c_power_lib.emc_get_free_swap_size.restype = c_int __c_power_lib.emc_get_cached_swap_size.argtypes = [] __c_power_lib.emc_get_cached_swap_size.restype = c_int __c_power_lib.emc_set_max_freq.argtypes = [c_long] __c_power_lib.emc_set_max_freq.restype = c_int __c_power_lib.emc_set_min_freq.argtypes = [c_long] __c_power_lib.emc_set_min_freq.restype = c_int __c_power_lib.engine_get_nums.argtypes = [] __c_power_lib.engine_get_nums.restype = c_int __c_power_lib.engine_get_names.argtypes = [] __c_power_lib.engine_get_names.restype = POINTER(c_char_p) __c_power_lib.engine_get_state.argtypes = [c_char_p] __c_power_lib.engine_get_state.restype = c_int __c_power_lib.engine_get_cur_freq.argtypes = [c_char_p] __c_power_lib.engine_get_cur_freq.restype = c_long __c_power_lib.engine_get_max_freq.argtypes = [c_char_p] __c_power_lib.engine_get_max_freq.restype = c_long __c_power_lib.engine_get_min_freq.argtypes = [c_char_p] __c_power_lib.engine_get_min_freq.restype = c_long __c_power_lib.engine_set_max_freq.argtypes = [c_char_p, c_long] __c_power_lib.engine_set_max_freq.restype = c_int __c_power_lib.engine_set_min_freq.argtypes = [c_char_p, c_long] __c_power_lib.engine_set_min_freq.restype = c_int __c_power_lib.thermal_get_sensor_nums.argtypes = [] __c_power_lib.thermal_get_sensor_nums.restype = c_int __c_power_lib.thermal_get_sensor_names.argtypes = [] __c_power_lib.thermal_get_sensor_names.restype = POINTER(c_char_p) __c_power_lib.thermal_get_sensor_policy.argtypes = [c_char_p] __c_power_lib.thermal_get_sensor_policy.restype = c_char_p __c_power_lib.thermal_get_sensor_temp.argtypes = [c_char_p] __c_power_lib.thermal_get_sensor_temp.restype = c_int __c_power_lib.thermal_get_sensor_sw_throttling_temp.argtypes = [c_char_p] __c_power_lib.thermal_get_sensor_sw_throttling_temp.restype = c_int __c_power_lib.thermal_get_sensor_sw_shutdown_temp.argtypes = [c_char_p] __c_power_lib.thermal_get_sensor_sw_shutdown_temp.restype = c_int __c_power_lib.thermal_is_temp_valid.argtypes = [c_int] __c_power_lib.thermal_is_temp_valid.restype = c_int __c_power_lib.thermal_set_sensor_policy.argtypes = [c_char_p, c_char_p] __c_power_lib.thermal_set_sensor_policy.restype = c_int __c_power_lib.rail_get_nums.argtypes = [] __c_power_lib.rail_get_nums.restype = c_int __c_power_lib.rail_get_names.argtypes = [] __c_power_lib.rail_get_names.restype = POINTER(c_char_p) __c_power_lib.rail_get_current.argtypes = [c_char_p] __c_power_lib.rail_get_current.restype = c_int __c_power_lib.rail_get_power.argtypes = [c_char_p] __c_power_lib.rail_get_power.restype = c_int __c_power_lib.rail_get_voltage.argtypes = [c_char_p] __c_power_lib.rail_get_voltage.restype = c_int __c_power_lib.rail_get_warn_current.argtypes = [c_char_p] __c_power_lib.rail_get_warn_current.restype = c_int __c_power_lib.rail_get_crit_current.argtypes = [c_char_p] __c_power_lib.rail_get_crit_current.restype = c_int __c_power_lib.rail_get_avg_power.argtypes = [c_char_p] __c_power_lib.rail_get_avg_power.restype = c_int __c_power_lib.rail_set_warn_current.argtypes = [c_char_p, c_int] __c_power_lib.rail_set_warn_current.restype = c_int __c_power_lib.rail_set_crit_current.argtypes = [c_char_p, c_int] __c_power_lib.rail_set_crit_current.restype = c_int __c_power_lib.rail_reset_avg_power.argtypes = [c_char_p] __c_power_lib.rail_reset_avg_power.restype = c_int __c_power_lib.fan_get_nums.argtypes = [] __c_power_lib.fan_get_nums.restype = c_int __c_power_lib.fan_get_names.argtypes = [] __c_power_lib.fan_get_names.restype = POINTER(c_char_p) __c_power_lib.fan_get_pwm.argtypes = [c_int] __c_power_lib.fan_get_pwm.restype = c_int __c_power_lib.fan_get_speed.argtypes = [c_int] __c_power_lib.fan_get_speed.restype = c_int __c_power_lib.fan_get_tach_enable.argtypes = [c_int] __c_power_lib.fan_get_tach_enable.restype = c_int __c_power_lib.fan_get_profile.argtypes = [c_int] __c_power_lib.fan_get_profile.restype = c_char_p __c_power_lib.fan_get_governor.argtypes = [c_int] __c_power_lib.fan_get_governor.restype = c_char_p __c_power_lib.fan_get_control.argtypes = [c_int] __c_power_lib.fan_get_control.restype = c_char_p __c_power_lib.fan_set_pwm.argtypes = [c_int, c_int] __c_power_lib.fan_set_pwm.restype = c_int __c_power_lib.fan_set_tach_enable.argtypes = [c_int, c_int] __c_power_lib.fan_set_tach_enable.restype = c_int __c_power_lib.disk_get_total_size.argtypes = [c_char_p] __c_power_lib.disk_get_total_size.restype = c_int __c_power_lib.disk_get_used_size.argtypes = [c_char_p] __c_power_lib.disk_get_used_size.restype = c_int def release_libjetsonpower() -> None: """Release the resources in libjetsonpower.""" __c_power_lib.release_libjetsonpower() return def platform_get_name() -> str: """Get name of current platform. Returns: platform name (str): Plarform name on success, None otherwise """ res = __c_power_lib.platform_get_name() return str(res, __encoding) if res else None def nvpmodel_get_power_mode() -> str: """Get power mode of nvpmodel. Returns: power mode of nvpmodel (str): Mode on success, None otherwise """ res = __c_power_lib.nvpmodel_get_power_mode() return str(res, __encoding) if res else None def cpu_get_nums() -> int: """Get number of CPUs on current platform. Returns: number of CPUs (int): Number on success, negative integer otherwise """ return __c_power_lib.cpu_get_nums() def cpu_get_state(core: int) -> int: """Get CPU state. Args: core (int): CPU core Returns: enabled or not (int): 0 on disabled, 1 on enabled, negative integer on error """ return __c_power_lib.cpu_get_state(core) def cpu_get_cur_freq(core: int) -> int: """Get CPU scaling current frequency. Args: core (int): CPU core Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.cpu_get_cur_freq(core) def cpu_get_max_freq(core: int) -> int: """Get CPU scaling max frequency. Args: core (int): CPU core Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.cpu_get_max_freq(core) def cpu_get_min_freq(core: int) -> int: """Get CPU scaling min frequency. Args: core (int): CPU core Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.cpu_get_min_freq(core) def cpu_get_load(core: int) -> int: """Get CPU load percentage. Args: core (int): CPU core Returns: load percentage (int): [0, 100] on success, negative integer otherwise """ return __c_power_lib.cpu_get_load(core) def cpu_set_state(core: int, state: int) -> int: """Set CPU state. Args: core (int): CPU core state (int): State to be set (0 for disabled, 1 for enabled) Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.cpu_set_state(core, state) def cpu_set_max_freq(core: int, frequency_in_khz: int) -> int: """Set CPU scaling max frequency to specified frequency. Args: core (int): CPU core frequency_in_khz (int): Frequency (in KHz) to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.cpu_set_max_freq(core, frequency_in_khz) def cpu_set_min_freq(core: int, frequency_in_khz: int) -> int: """Set CPU scaling min frequency to specified frequency. Args: core (int): CPU core frequency_in_khz (int): Frequency (in KHz) to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.cpu_set_min_freq(core, frequency_in_khz) def igpu_get_cur_freq(core: int) -> int: """Get iGPU current frequency. Args: core (int): iGPU core Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.igpu_get_cur_freq(core) def igpu_get_max_freq(core: int) -> int: """Get iGPU max frequency. Args: core (int): iGPU core Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.igpu_get_max_freq(core) def igpu_get_min_freq(core: int) -> int: """Get iGPU min frequency. Args: core (int): iGPU core Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.igpu_get_min_freq(core) def igpu_get_load(core: int) -> int: """Get iGPU load percentage. Args: core (int): iGPU core Returns: load percentage (int): [0, 100] on success, negative integer otherwise """ return __c_power_lib.igpu_get_load(core) def igpu_set_max_freq(core: int, frequency_in_khz: int) -> int: """Set iGPU max frequency to specified frequency. Args: core (int): iGPU core frequency_in_khz (int): Frequency (in KHz) to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.igpu_set_max_freq(core, frequency_in_khz) def igpu_set_min_freq(core: int, frequency_in_khz: int) -> int: """Set iGPU min frequency to specified frequency. Args: core (int): iGPU core frequency_in_khz (int): Frequency (in KHz) to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.igpu_set_min_freq(core, frequency_in_khz) def emc_get_cur_freq() -> int: """Get emc current frequency. Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.emc_get_cur_freq() def emc_get_max_freq() -> int: """Get emc max frequency. Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.emc_get_max_freq() def emc_get_min_freq() -> int: """Get emc min frequency. Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.emc_get_min_freq() def emc_get_load() -> int: """Get emc load percentage. Returns: load percentage (int): [0, 100] on success, negative integer otherwise """ return __c_power_lib.emc_get_load() def emc_get_mem_size() -> int: """Get memory total size. Returns: size in MB (int): size on success, negative integer otherwise """ return __c_power_lib.emc_get_mem_size() def emc_get_free_mem_size() -> int: """Get memory free size. Returns: size in MB (int): size on success, negative integer otherwise """ return __c_power_lib.emc_get_free_mem_size() def emc_get_buffers_size() -> int: """Get memory buffers size. Returns: size in MB (int): size on success, negative integer otherwise """ return __c_power_lib.emc_get_buffers_size() def emc_get_cached_size() -> int: """Get memory cached size. Returns: size in MB (int): size on success, negative integer otherwise """ return __c_power_lib.emc_get_cached_size() def emc_get_swap_size() -> int: """Get swap total size. Returns: size in MB (int): size on success, negative integer otherwise """ return __c_power_lib.emc_get_swap_size() def emc_get_free_swap_size() -> int: """Get swap free size. Returns: size in MB (int): size on success, negative integer otherwise """ return __c_power_lib.emc_get_free_swap_size() def emc_get_cached_swap_size() -> int: """Get swap cached size. Returns: size in MB (int): size on success, negative integer otherwise """ return __c_power_lib.emc_get_cached_swap_size() def emc_set_max_freq(frequency_in_khz: int) -> int: """Set emc max frequency to specified frequency. Args: frequency_in_khz (int): Frequency (in KHz) to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.emc_set_max_freq(frequency_in_khz) def emc_set_min_freq(frequency_in_khz: int) -> int: """Set emc min frequency to specified frequency. Args: frequency_in_khz (int): Frequency (in KHz) to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.emc_set_min_freq(frequency_in_khz) def engine_get_nums() -> int: """Get number of engines available on current platform. Current implementation only supports these engines if any: dla0, dla1, pva0, pva1, nvdec0, nvdec1, nvenc0, nvenc1, nvjpg, se, ape. Returns: number of engines (int): Number on success, 0 on no engine found """ return __c_power_lib.engine_get_nums() def engine_get_names() -> list: """Get engines names available on current platform. Current implementation only supports these engines if any: dla0, dla1, pva0, pva1, nvdec0, nvdec1, nvenc0, nvenc1, nvjpg, se, ape. Returns: engine names (str list): Engine names on success, empty list otherwise """ engine_names_ptr = __c_power_lib.engine_get_names() if not(engine_names_ptr): return [] engine_nums = engine_get_nums() engine_names = [None] * engine_nums for i in range(engine_nums): if not(engine_names_ptr[i]): return [] engine_names[i] = str(engine_names_ptr[i], __encoding) return engine_names def engine_get_state(engine_name: str) -> int: """Get engine state. Args: engine_name (str): Engine name Returns: enabled or not (int): 0 on disabled, 1 on enabled, negative integer on error """ return __c_power_lib.engine_get_state(bytes(engine_name, __encoding)) def engine_get_cur_freq(engine_name: str) -> int: """Get engine current frequency. Args: engine_name (str): Engine name Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.engine_get_cur_freq(bytes(engine_name, __encoding)) def engine_get_max_freq(engine_name: str) -> int: """Get engine max frequency. Args: engine_name (str): Engine name Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.engine_get_max_freq(bytes(engine_name, __encoding)) def engine_get_min_freq(engine_name: str) -> int: """Get engine min frequency. Args: engine_name (str): Engine name Returns: frequency in KHz (int): Frequency on success, negative integer otherwise """ return __c_power_lib.engine_get_min_freq(bytes(engine_name, __encoding)) def engine_set_max_freq(engine_name: str, frequency_in_khz: int) -> int: """Set engine max frequency to specified frequency. Args: engine_name (str): Engine name frequency_in_khz (int): Frequency (in KHz) to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.engine_set_max_freq(engine_name, frequency_in_khz) def engine_set_min_freq(engine_name: str, frequency_in_khz: int) -> int: """Set engine min frequency to specified frequency. Args: engine_name (str): Engine name frequency_in_khz (int): Frequency (in KHz) to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.engine_set_min_freq(engine_name, frequency_in_khz) def thermal_get_sensor_nums() -> int: """Get number of thermal sensors available on current platform. Returns: number of sensors (int): Number on success, 0 on no sensor found """ return __c_power_lib.thermal_get_sensor_nums() def thermal_get_sensor_names() -> list: """Get thermal sensor names available on current platform. Returns: sensor names (str list): Sensor names on success, empty list otherwise """ sensor_names_ptr = __c_power_lib.thermal_get_sensor_names() if not(sensor_names_ptr): return [] sensor_nums = thermal_get_sensor_nums() sensor_names = [None] * sensor_nums for i in range(sensor_nums): if not(sensor_names_ptr[i]): return [] sensor_names[i] = str(sensor_names_ptr[i], __encoding) return sensor_names def thermal_get_sensor_temp(sensor_name: str) -> int: """Get thermal sensor current temperature. When calling thermal_get_sensor_temp(), please make sure to check the return value by thermal_is_temp_valid(). Args: sensor_name (str): Sensor name Returns: temperature in millidegree Celsius (int): temperature on success, negative integer otherwise """ return __c_power_lib.thermal_get_sensor_temp(bytes(sensor_name, __encoding)) def thermal_get_sensor_policy(sensor_name: str) -> str: """Get thermal sensor current policy. Args: sensor_name (str): Sensor name Returns: policy (str): Policy on success, None otherwise """ res = __c_power_lib.thermal_get_sensor_policy(bytes(sensor_name, __encoding)) return str(res, __encoding) if res else None def thermal_get_sensor_sw_throttling_temp(sensor_name: str) -> int: """Get thermal sensor software throttling temperature. When calling thermal_get_sensor_sw_throttling_temp(), please make sure to check the return value by thermal_is_temp_valid(). Args: sensor_name (str): Sensor name Returns: temperature in millidegree Celsius (int): temperature on success, negative integer otherwise """ return __c_power_lib.thermal_get_sensor_sw_throttling_temp( bytes(sensor_name, __encoding)) def thermal_get_sensor_sw_shutdown_temp(sensor_name: str) -> int: """Get thermal sensor software shutdown temperature. When calling thermal_get_sensor_sw_shutdown_temp(), please make sure to check the return value by thermal_is_temp_valid(). Args: sensor_name (str): Sensor name Returns: temperature in millidegree Celsius (int): temperature on success, negative integer otherwise """ return __c_power_lib.thermal_get_sensor_sw_shutdown_temp( bytes(sensor_name, __encoding)) def thermal_is_temp_valid(temp: int) -> int: """Check if the temperature read by the sensor is valid. The return value of EVERY temperature getter function should be checked by this checker function. Args: temp (int): Temperature (in millidegree Celsius) to be checked Returns: valid or not (int): 0 on temperature is invalid, 1 otherwise """ return __c_power_lib.thermal_is_temp_valid(temp) def thermal_set_sensor_policy(sensor_name: str, policy: str) -> int: """Set thermal sensor current policy. Args: sensor_name (str): Sensor name policy (str): Policy to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.thermal_set_sensor_policy(bytes(sensor_name, __encoding), bytes(policy, __encoding)) def rail_get_nums() -> int: """Get number of rails available on current platform. Returns: number of rails (int): Number on success, 0 on no rail found """ return __c_power_lib.rail_get_nums() def rail_get_names() -> list: """Get rail names available on current platform. Returns: rail names (str list): Rail names on success, empty list otherwise """ rail_names_ptr = __c_power_lib.rail_get_names() if not(rail_names_ptr): return [] rail_nums = rail_get_nums() rail_names = [None] * rail_nums for i in range(rail_nums): if not(rail_names_ptr[i]): return [] rail_names[i] = str(rail_names_ptr[i], __encoding) return rail_names def rail_get_current(rail_name: str) -> int: """Get rail instantaneous current. Args: rail_name (str): Rail name Returns: current in milliampere (int): current on success, negative integer otherwise """ return __c_power_lib.rail_get_current(bytes(rail_name, __encoding)) def rail_get_power(rail_name: str) -> int: """Get rail instantaneous power. Args: rail_name (str): Rail name Returns: power in milliwatt (int): power on success, negative integer otherwise """ return __c_power_lib.rail_get_power(bytes(rail_name, __encoding)) def rail_get_voltage(rail_name: str) -> int: """Get rail instantaneous voltage. Args: rail_name (str): Rail name Returns: voltage in millivolt (int): voltage on success, negative integer otherwise """ return __c_power_lib.rail_get_voltage(bytes(rail_name, __encoding)) def rail_get_warn_current(rail_name: str) -> int: """Get rail average current limit. Args: rail_name (str): Rail name Returns: current in milliampere (int): current on success, negative integer otherwise """ return __c_power_lib.rail_get_warn_current(bytes(rail_name, __encoding)) def rail_get_crit_current(rail_name: str) -> int: """Get rail instantaneous current limit. Args: rail_name (str): Rail name Returns: current in milliampere (int): current on success, negative integer otherwise """ return __c_power_lib.rail_get_crit_current(bytes(rail_name, __encoding)) def rail_get_avg_power(rail_name: str) -> int: """Get rail average power. Args: rail_name (str): Rail name Returns: power in milliwatt (int): power on success, negative integer otherwise """ return __c_power_lib.rail_get_avg_power(bytes(rail_name, __encoding)) def rail_set_warn_current(rail_name: str, limit_in_mA: int) -> int: """Set rail average current limit. Args: rail_name (str): Rail name limit_in_mA (int): Current limit (in milliampere) to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.rail_set_warn_current(bytes(rail_name, __encoding), limit_in_mA) def rail_set_crit_current(rail_name: str, limit_in_mA: int) -> int: """Set rail instantaneous current limit. Args: rail_name (str): Rail name limit_in_mA (int): Current limit (in milliampere) to be set Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.rail_set_crit_current(bytes(rail_name, __encoding), limit_in_mA) def rail_reset_avg_power(rail_name: str) -> int: """Reset rail average power. Args: rail_name (str): Rail name Returns: successfully reset or not (int): 0 on success, negative integer on error """ return __c_power_lib.rail_reset_avg_power(bytes(rail_name, __encoding)) def fan_get_nums() -> int: """Get number of fans available on current platform. Returns: number of fans (int): Number on success, 0 on no fan found """ return __c_power_lib.fan_get_nums() def fan_get_names() -> list: """Get fan names available on current platform. Fan name is simply "fan" + . Like "fan0", "fan1" and so on. Returns: fan names (str list): Fan names on success, empty list otherwise """ fan_names_ptr = __c_power_lib.fan_get_names() if not(fan_names_ptr): return [] fan_nums = fan_get_nums() fan_names = [None] * fan_nums for i in range(fan_nums): if not(fan_names_ptr[i]): return [] fan_names[i] = str(fan_names_ptr[i], __encoding) return fan_names def fan_get_pwm(fan_id: int) -> int: """Get fan pwm. Args: fan_id (int): Fan index (starting from 1) Returns: fan pwm (int): [0, 255] on success, negative integer otherwise """ return __c_power_lib.fan_get_pwm(fan_id) def fan_get_speed(fan_id: int) -> int: """Get fan rpm. Args: fan_id (int): Fan index (starting from 1) Returns: fan rpm (int): rpm on success, negative integer otherwise """ return __c_power_lib.fan_get_speed(fan_id) def fan_get_tach_enable(fan_id: int) -> int: """Get fan tachometer enable state. Args: fan_id (int): Fan index (starting from 1) Returns: fan tachometer enable state (int): 0 on disabled, 1 on enabled, negative integer on error """ return __c_power_lib.fan_get_tach_enable(fan_id) def fan_get_profile(fan_id: int) -> str: """Get fan profile. Args: fan_id (int): Fan index (starting from 1) Returns: fan profile (str): Fan profile on success, None otherwise """ res = __c_power_lib.fan_get_profile(fan_id) return str(res, __encoding) if res else None def fan_get_governor(fan_id: int) -> str: """Get fan governor. Args: fan_id (int): Fan index (starting from 1) Returns: fan governor (str): Fan governor on success, None otherwise """ res = __c_power_lib.fan_get_governor(fan_id) return str(res, __encoding) if res else None def fan_get_control(fan_id: int) -> str: """Get fan control. Args: fan_id (int): Fan index (starting from 1) Returns: fan control (str): Fan control on success, None otherwise """ res = __c_power_lib.fan_get_control(fan_id) return str(res, __encoding) if res else None def fan_set_pwm(fan_id: int, pwm: int) -> int: """Set fan pwm. Args: fan_id (int): Fan index (starting from 1) pwm (int): PWM to be set (range from 0 to 255) Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.fan_set_pwm(fan_id, pwm) def fan_set_tach_enable(fan_id: int, enabled: int) -> int: """Set fan tachometer enable state. Args: fan_id (int): Fan index (starting from 1) enabled (int): Enabled state to be set (0 for disabled, 1 for enabled) Returns: successfully set or not (int): 0 on success, negative integer on error """ return __c_power_lib.fan_set_tach_enable(fan_id, enabled) def disk_get_total_size(disk_name: str) -> int: """Get disk total size. Args: disk_name (str): Disk name Returns: size in MB (int): size on success, negative integer otherwise """ return __c_power_lib.disk_get_total_size(bytes(disk_name, __encoding)) def disk_get_used_size(disk_name: str) -> int: """Get disk used size. Args: disk_name (str): Disk name Returns: size in MB (int): size on success, negative integer otherwise """ return __c_power_lib.disk_get_used_size(bytes(disk_name, __encoding))