feat(dbus): Add RevPiConfig class for device information handling
This commit introduces a new `RevPiConfig` class to manage RevPi device configuration details, such as model, serial, compute module type, WiFi, and ConBridge detection. It parses CPU info from `/proc/cpuinfo` and leverages helper methods for hardware-specific checks, enhancing the middleware's ability to identify and manage hardware features.
This commit is contained in:
@@ -0,0 +1,92 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
from enum import IntEnum
|
||||||
|
from logging import getLogger
|
||||||
|
|
||||||
|
from ..dbus_helper import grep
|
||||||
|
|
||||||
|
log = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class ComputeModuleTypes(IntEnum):
|
||||||
|
UNKNOWN = 0
|
||||||
|
CM1 = 6
|
||||||
|
CM3 = 10
|
||||||
|
CM4 = 20
|
||||||
|
CM4S = 21
|
||||||
|
CM5 = 24
|
||||||
|
|
||||||
|
|
||||||
|
class RevPiConfig:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._cm_type = ComputeModuleTypes.UNKNOWN
|
||||||
|
self._cm_with_wifi = False
|
||||||
|
|
||||||
|
self._revpi_with_con_bridge = False
|
||||||
|
|
||||||
|
self.serial = ""
|
||||||
|
self.model = ""
|
||||||
|
|
||||||
|
self._init_device_info()
|
||||||
|
|
||||||
|
def _init_device_info(self):
|
||||||
|
dc_cpuinfo = {}
|
||||||
|
|
||||||
|
# Extract CPU information
|
||||||
|
with open("/proc/cpuinfo", "r") as f:
|
||||||
|
line = "\n"
|
||||||
|
while line:
|
||||||
|
line = f.readline()
|
||||||
|
if line.startswith(("Revision", "Serial", "Model")):
|
||||||
|
key, value = line.split(":", 1)
|
||||||
|
key = key.strip().lower()
|
||||||
|
value = value.strip()
|
||||||
|
dc_cpuinfo[key] = value
|
||||||
|
|
||||||
|
self.model = dc_cpuinfo.get("model", "")
|
||||||
|
self.serial = dc_cpuinfo.get("serial", "")
|
||||||
|
|
||||||
|
# Detect Compute Module type
|
||||||
|
revision = dc_cpuinfo.get("revision", "")
|
||||||
|
if revision:
|
||||||
|
revision = int(revision, 16)
|
||||||
|
mask = 4080 # 0xFF0 in dezimal
|
||||||
|
try:
|
||||||
|
self._cm_type = ComputeModuleTypes((revision & mask) >> 4)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Detect WiFi
|
||||||
|
could_have_wifi = self._cm_type in (ComputeModuleTypes.CM4, ComputeModuleTypes.CM5)
|
||||||
|
if could_have_wifi:
|
||||||
|
lst_grep = grep("DRIVER=brcmfmac", "/sys/class/ieee80211/phy0/device/uevent")
|
||||||
|
self._cm_with_wifi = len(lst_grep) > 0 and self._cm_type in (ComputeModuleTypes)
|
||||||
|
|
||||||
|
# Detect ConBridge
|
||||||
|
could_have_con_bridge = self._cm_type in (ComputeModuleTypes.CM3, ComputeModuleTypes.CM4S)
|
||||||
|
if could_have_con_bridge:
|
||||||
|
lst_grep = grep("kunbus,revpi-connect", "/proc/device-tree/compatible")
|
||||||
|
self._revpi_with_con_bridge = len(lst_grep) > 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cm_type(self) -> ComputeModuleTypes:
|
||||||
|
return self._cm_type
|
||||||
|
|
||||||
|
@property
|
||||||
|
def with_con_bridge(self) -> bool:
|
||||||
|
return self._revpi_with_con_bridge
|
||||||
|
|
||||||
|
@property
|
||||||
|
def with_wifi(self) -> bool:
|
||||||
|
return self._cm_with_wifi
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
rc = RevPiConfig()
|
||||||
|
print("Model:", rc.model)
|
||||||
|
print("Serial: ", rc.serial)
|
||||||
|
print("CM Type: ", rc.cm_type.name)
|
||||||
|
print("With wifi: ", rc.with_wifi)
|
||||||
|
print("With con-bridge:", rc.with_con_bridge)
|
||||||
Reference in New Issue
Block a user