mirror of
https://github.com/saymrwulf/uhd.git
synced 2026-05-16 21:10:10 +00:00
Co-authored-by: Lars Amsel <lars.amsel@ni.com> Co-authored-by: Michael Auchter <michael.auchter@ni.com> Co-authored-by: Martin Braun <martin.braun@ettus.com> Co-authored-by: Paul Butler <paul.butler@ni.com> Co-authored-by: Cristina Fuentes <cristina.fuentes-curiel@ni.com> Co-authored-by: Humberto Jimenez <humberto.jimenez@ni.com> Co-authored-by: Virendra Kakade <virendra.kakade@ni.com> Co-authored-by: Lane Kolbly <lane.kolbly@ni.com> Co-authored-by: Max Köhler <max.koehler@ni.com> Co-authored-by: Andrew Lynch <andrew.lynch@ni.com> Co-authored-by: Grant Meyerhoff <grant.meyerhoff@ni.com> Co-authored-by: Ciro Nishiguchi <ciro.nishiguchi@ni.com> Co-authored-by: Thomas Vogel <thomas.vogel@ni.com>
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
#
|
|
# Copyright 2020 Ettus Research, a National Instruments Brand
|
|
#
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
#
|
|
"""
|
|
Utilities for interfacing with ectool
|
|
"""
|
|
|
|
import subprocess
|
|
|
|
def run_cmd(cmd):
|
|
"""Run ectool utility's command named cmd."""
|
|
cmd_str = ' '.join(['ectool', cmd])
|
|
try:
|
|
output = subprocess.check_output(
|
|
cmd_str,
|
|
stderr=subprocess.STDOUT,
|
|
shell=True,
|
|
)
|
|
except subprocess.CalledProcessError as ex:
|
|
raise RuntimeError("Failed to execute {} ectool command".format(cmd))
|
|
return output.decode("utf-8")
|
|
|
|
def get_num_fans():
|
|
""" Run ectool utility's command pwmgetnumfans to get number of fans."""
|
|
output = run_cmd('pwmgetnumfans')
|
|
num_fans = [int(s) for s in output.split() if s.isdigit()][0]
|
|
return num_fans
|
|
|
|
def get_fan_rpm():
|
|
"""Run ectool utility's command pwmgetfanrpm to get fan rpm."""
|
|
num_fans = get_num_fans()
|
|
if num_fans == 0:
|
|
raise RuntimeError("Number of fans is zero.")
|
|
output = run_cmd('pwmgetfanrpm')
|
|
fan_rpm_info = [int(s) for s in output.split() if s.isdigit()]
|
|
if len(fan_rpm_info) == 2 * num_fans:
|
|
return {
|
|
"fan{}".format(fan) : fan_rpm_info[fan * 2 + 1]
|
|
for fan in range (0, num_fans)
|
|
}
|
|
else:
|
|
raise RuntimeError("Error getting fan rpm using ectool, at least one fan" \
|
|
" may be stalled. Command output: {}".format(output))
|