feat(cube : create_nicsensor.py) add create_nicsensor.py
This commit is contained in:
parent
0e0f616bbd
commit
7a85ff088a
65
cube/data/BoardFeature.json
Normal file
65
cube/data/BoardFeature.json
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"adc128": {
|
||||||
|
"status": "enable",
|
||||||
|
"slave": "0x1f",
|
||||||
|
"ch0_name": "Channel0",
|
||||||
|
"ch1_name": "Channel1",
|
||||||
|
"ch2_name": "Channel2",
|
||||||
|
"ch3_name": "Channel3",
|
||||||
|
"ch4_name": "Channel4",
|
||||||
|
"ch5_name": "Channel5",
|
||||||
|
"ch6_name": "Channel6",
|
||||||
|
"ch7_name": "Channel7",
|
||||||
|
"ch0_factor": 1,
|
||||||
|
"ch1_factor": 1,
|
||||||
|
"ch2_factor": 1,
|
||||||
|
"ch3_factor": 1,
|
||||||
|
"ch4_factor": 1,
|
||||||
|
"ch5_factor": 1,
|
||||||
|
"ch6_factor": 1,
|
||||||
|
"ch7_factor": 1
|
||||||
|
},
|
||||||
|
"ina3221": {
|
||||||
|
"status": "enable",
|
||||||
|
"slave": "0x41",
|
||||||
|
"ch0_name": "Channel0",
|
||||||
|
"ch1_name": "Channel1",
|
||||||
|
"ch2_name": "Channel2",
|
||||||
|
"ch0_shunt": 2,
|
||||||
|
"ch1_shunt": 2,
|
||||||
|
"ch2_shunt": 5
|
||||||
|
},
|
||||||
|
"emc1413": {
|
||||||
|
"status": "disable",
|
||||||
|
"slave": "0x4c",
|
||||||
|
"ch0_name": "Channel0",
|
||||||
|
"ch1_name": "Channel1",
|
||||||
|
"ch2_name": "Channel2"
|
||||||
|
},
|
||||||
|
"tmp468": {
|
||||||
|
"status": "enable",
|
||||||
|
"slave": "0x48",
|
||||||
|
"remote_name": "Remote",
|
||||||
|
"ch0_name": "Channel0",
|
||||||
|
"ch1_name": "Channel1",
|
||||||
|
"ch2_name": "Channel2",
|
||||||
|
"ch3_name": "Channel3",
|
||||||
|
"ch4_name": "Channel4",
|
||||||
|
"ch5_name": "Channel5",
|
||||||
|
"ch6_name": "Channel6",
|
||||||
|
"ch7_name": "Channel7"
|
||||||
|
},
|
||||||
|
"tmp112": {
|
||||||
|
"status": "disable",
|
||||||
|
"slave": "0x49",
|
||||||
|
"tmp112_name": "Temperature"
|
||||||
|
},
|
||||||
|
"fru": {
|
||||||
|
"status": "enable",
|
||||||
|
"slave": "0x50"
|
||||||
|
},
|
||||||
|
"chip": {
|
||||||
|
"status": "enable",
|
||||||
|
"slave": "0x10"
|
||||||
|
}
|
||||||
|
}
|
||||||
34
cube/data/ServerHwTopo.json
Normal file
34
cube/data/ServerHwTopo.json
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"maxPcieSlotNum": 8,
|
||||||
|
"PcieSlotProperties":{
|
||||||
|
"busCount":1,
|
||||||
|
"i2c_cs0":{
|
||||||
|
"i2c_bus":13,
|
||||||
|
"is_have_pca9641": "enable",
|
||||||
|
"pca9641_slave": "0x42",
|
||||||
|
"pca9548num": 2,
|
||||||
|
"pca9548_cs0":{
|
||||||
|
"slave": "0x71",
|
||||||
|
"channel0": "pcie0",
|
||||||
|
"channel1": "pcie1",
|
||||||
|
"channel2": "pcie2",
|
||||||
|
"channel3": "pcie3",
|
||||||
|
"channel4": null,
|
||||||
|
"channel5": null,
|
||||||
|
"channel6": null,
|
||||||
|
"channel7": null
|
||||||
|
},
|
||||||
|
"pca9548_cs1":{
|
||||||
|
"slave": "0x72",
|
||||||
|
"channel0": "pcie4",
|
||||||
|
"channel1": "pcie5",
|
||||||
|
"channel2": "pcie6",
|
||||||
|
"channel3": "pcie7",
|
||||||
|
"channel4": null,
|
||||||
|
"channel5": null,
|
||||||
|
"channel6": null,
|
||||||
|
"channel7": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,12 +2,12 @@
|
|||||||
"maxPcieSlotNum": 8,
|
"maxPcieSlotNum": 8,
|
||||||
"PcieSlotProperties":{
|
"PcieSlotProperties":{
|
||||||
"busCount":1,
|
"busCount":1,
|
||||||
"i2c_cs1":{
|
"i2c_cs0":{
|
||||||
"i2c_bus":13,
|
"i2c_bus":13,
|
||||||
"is_have_pca9641": "enable",
|
"is_have_pca9641": "enable",
|
||||||
"pca9641_slave": "0x42",
|
"pca9641_slave": "0x42",
|
||||||
"pca9548num": 2,
|
"pca9548num": 2,
|
||||||
"pca9548_cs1":{
|
"pca9548_cs0":{
|
||||||
"slave": "0x71",
|
"slave": "0x71",
|
||||||
"channel0": "pcie0",
|
"channel0": "pcie0",
|
||||||
"channel1": "pcie1",
|
"channel1": "pcie1",
|
||||||
@ -18,7 +18,7 @@
|
|||||||
"channel6": null,
|
"channel6": null,
|
||||||
"channel7": null
|
"channel7": null
|
||||||
},
|
},
|
||||||
"pca9548_cs2":{
|
"pca9548_cs1":{
|
||||||
"slave": "0x72",
|
"slave": "0x72",
|
||||||
"channel0": "pcie4",
|
"channel0": "pcie4",
|
||||||
"channel1": "pcie5",
|
"channel1": "pcie5",
|
||||||
|
|||||||
103
cube/src/create_nicsensor.py
Normal file
103
cube/src/create_nicsensor.py
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
def get_content_before_substring(a, b):
|
||||||
|
index = a.find(b)
|
||||||
|
if index != -1:
|
||||||
|
return a[:index]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def dbg_print(level, context):
|
||||||
|
# 获取当前时间
|
||||||
|
now = datetime.now()
|
||||||
|
# 将当前时间转换为时间戳
|
||||||
|
timestamp = now.timestamp()
|
||||||
|
dt_object = datetime.fromtimestamp(timestamp)
|
||||||
|
formatted_time = dt_object.strftime("%Y-%m-%dT%H:%M:%S")
|
||||||
|
|
||||||
|
print(f"|{formatted_time}|{level}|{context}")
|
||||||
|
|
||||||
|
file_path = 'create_nicsensor.py'
|
||||||
|
absolute_path = os.path.abspath(file_path)
|
||||||
|
workspace_path = get_content_before_substring(absolute_path, "src")
|
||||||
|
|
||||||
|
model_path = "data\\"
|
||||||
|
board_feature_path = workspace_path + model_path + "BoardFeature.json"
|
||||||
|
hw_topo_path = workspace_path + model_path + "ServerHwTopo.json"
|
||||||
|
|
||||||
|
dbg_print("info", "====== Pre Init ======")
|
||||||
|
dbg_print("info", f"workspace_path={workspace_path}")
|
||||||
|
dbg_print("info", f"board_feature_path={board_feature_path}")
|
||||||
|
dbg_print("info", f"hw_topo_path={hw_topo_path}")
|
||||||
|
|
||||||
|
def process_hw_topo():
|
||||||
|
dbg_print("info", "====== Process Server Hw Topo ======")
|
||||||
|
# open hw topo file
|
||||||
|
try:
|
||||||
|
# 打开JSON文件
|
||||||
|
with open(hw_topo_path, 'r') as file:
|
||||||
|
# 读取并解析JSON数据
|
||||||
|
hw_topo_data = json.load(file)
|
||||||
|
|
||||||
|
# 处理解析后的数据
|
||||||
|
except FileNotFoundError:
|
||||||
|
dbg_print("Error", "错误: 未找到JSON文件。")
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
dbg_print("Error", "错误: JSON文件格式有误。")
|
||||||
|
except Exception as e:
|
||||||
|
dbg_print("Error", f"发生未知错误:{e}")
|
||||||
|
|
||||||
|
maxPcieSlotNum = hw_topo_data['maxPcieSlotNum']
|
||||||
|
dbg_print("info", f"maxPcieSlotNum={maxPcieSlotNum}")
|
||||||
|
|
||||||
|
PcieSlotProperties = hw_topo_data['PcieSlotProperties']
|
||||||
|
# dbg_print("info", f"PcieSlotProperties={PcieSlotProperties}")
|
||||||
|
|
||||||
|
busCount = PcieSlotProperties['busCount']
|
||||||
|
dbg_print("info", f"busCount={busCount}")
|
||||||
|
|
||||||
|
for bus_count_index in range(busCount):
|
||||||
|
i2c_cs_str = f"i2c_cs{bus_count_index}"
|
||||||
|
dbg_print("info", f">>> i2c_cs_str={i2c_cs_str}")
|
||||||
|
|
||||||
|
i2c_cs = PcieSlotProperties[i2c_cs_str]
|
||||||
|
# dbg_print("info", f"i2c_cs={i2c_cs}")
|
||||||
|
|
||||||
|
i2c_bus = i2c_cs['i2c_bus']
|
||||||
|
dbg_print("info", f">>> i2c_bus={i2c_bus}")
|
||||||
|
|
||||||
|
is_have_pca9641 = i2c_cs['is_have_pca9641']
|
||||||
|
|
||||||
|
if is_have_pca9641 == "enable":
|
||||||
|
pca9641_slave = i2c_cs['pca9641_slave']
|
||||||
|
dbg_print("info", f">>> there has pca9641 !!!")
|
||||||
|
dbg_print("info", f">>> pca9641_slave={pca9641_slave}")
|
||||||
|
else:
|
||||||
|
dbg_print("info", f">>> there has no pca9641 !!!")
|
||||||
|
|
||||||
|
pca9548num = i2c_cs['pca9548num']
|
||||||
|
dbg_print("info", f">>> pca9548num={pca9548num}")
|
||||||
|
|
||||||
|
for pca9548_count_index in range(pca9548num):
|
||||||
|
pca9548_cs_str = f"pca9548_cs{pca9548_count_index}"
|
||||||
|
dbg_print("info", f">>>>>> pca9548_cs_str={pca9548_cs_str}")
|
||||||
|
|
||||||
|
pca9548_cs = i2c_cs[pca9548_cs_str]
|
||||||
|
|
||||||
|
pca9548_slave = pca9548_cs['slave']
|
||||||
|
dbg_print("info", f">>>>>> pca9548_slave={pca9548_slave}")
|
||||||
|
|
||||||
|
for i in range(8):
|
||||||
|
channel = f"channel{i}"
|
||||||
|
pca9548_channel = pca9548_cs[channel]
|
||||||
|
|
||||||
|
if pca9548_channel != None :
|
||||||
|
dbg_print("info", f"{channel}={pca9548_channel}")
|
||||||
|
else:
|
||||||
|
dbg_print("info", f"{channel} is null")
|
||||||
|
|
||||||
|
# =====================================================
|
||||||
|
# Start execute script
|
||||||
|
# =====================================================
|
||||||
|
process_hw_topo()
|
||||||
Loading…
Reference in New Issue
Block a user