File: ectool.py

package info (click to toggle)
uhd 4.9.0.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 184,180 kB
  • sloc: cpp: 262,887; python: 112,011; ansic: 102,670; vhdl: 57,031; tcl: 19,924; xml: 8,581; makefile: 3,028; sh: 2,812; pascal: 230; javascript: 120; csh: 94; asm: 20; perl: 11
file content (45 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#
# 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))