Compare commits

...

87 Commits
v1.6 ... master

Author SHA1 Message Date
leimingsheng
775fe461b0 feat(master : tool) 添加自动打包工程工具 2026-04-20 09:31:20 +08:00
leimingsheng
88f871c880 feat(master) update to 1.10 base dev 2
1.[新增功能]解耦脚本参数配置功能, 脚本配置全部放到project.config中
2.[新增功能]增加对pmbus set命令的支持
3.[新增功能]增加setup.sh, 用于一键部署脚本
4.[功能优化]代码结构目录重新归档
2026-04-17 17:09:43 +08:00
leimingsheng
efb7017a53 feat(master : nicsensor) Release Version 1.10 2026-03-12 15:54:06 +08:00
leimingsheng
938adf43be update code 2026-03-12 09:19:37 +08:00
leimingsheng
5095763b6b update code 2026-03-11 14:28:21 +08:00
leimingsheng
3a15c90acf feat(master : nicsensor) 参数配置支持配置fru offset 2026-03-11 14:09:45 +08:00
leimingsheng
8777d0a279 update reademe 2026-03-11 14:00:26 +08:00
leimingsheng
67b07fcf8b feat(master : nicsensor) update to 1.9.8
1.支持get/set配置默认i2cbus
2026-03-11 11:17:37 +08:00
leimingsheng
3a66d3557b Merge branch 'master' of 121.36.59.21:Marcin/nicsensor 2026-03-10 18:35:44 +08:00
leimingsheng
e5a4a4e28d 移除 nicsensor_s.sh 2026-03-10 18:34:39 +08:00
leimingsheng
27ae0a4dc4 feat(master : nicsensor) update to 1.9.7 【重要】
1.原生支持 stress 压力测试
2.新增stress_test插件
2026-03-10 18:22:38 +08:00
leimingsheng
c7730923a1 fix(master : nicsensor) 修复 1.9.4 引入的执行时语法错误 2026-03-10 15:57:18 +08:00
leimingsheng
04c0342367 feat(master : nicsensor.sh) update to 1.9.6
1.增加安全性检查内容
2.pmbus_cmd_list 引入版本号
2026-03-10 15:27:18 +08:00
leimingsheng
f526fa8190 fix(master : nicsensor) update to 1.9.5
修正拼写错误
2026-03-09 09:39:19 +08:00
8119bf1b69 更新 readme.md 2026-02-10 14:42:30 +08:00
leimingsheng
37d328c7f3 refactor(master : nicsensor) update to 1.9.4
优化代码:重构将十六进制转化为十进制的代码,便于阅读代码
2026-02-10 14:35:11 +08:00
leimingsheng
7bb15f6de8 feat(master : nicsensor) update to 1.9.3
新增支持温度传感器 lm95241
2026-02-10 13:58:43 +08:00
leimingsheng
952f281365 optimize(master : nicsensor.sh) update to 1.9.2
优化 help 显示功能
2026-01-15 14:10:19 +08:00
leimingsheng
559263cc2d feat(master : nicsensor) update to 1.9.1 【重要】
1.新增适配传感器ina226
2.优化help功能
3.优化代码可读性
2026-01-09 16:47:11 +08:00
leimingsheng
d91a9f87ae feat(master : nicsensor) Release Version 1.9 2026-01-05 14:36:18 +08:00
leimingsheng
cdb7b9ef5c fix(master : nicsensor) update to 1.8.9
修正pmbus的显示功能
2026-01-04 16:59:30 +08:00
leimingsheng
71a40e88f6 feat(master : nicsensor) update to 1.8.8
get/set操作支持配置fru size
2025-12-26 16:28:52 +08:00
leimingsheng
fe33854677 fix(master : nicsensor) update to 1.8.7
将get/set功能中的detect选项变更为 n_detect , 便于理解
2025-12-26 16:21:16 +08:00
leimingsheng
988d217008 refactor(master : nicsensor) update to 1.8.6
重构pmbus功能
2025-12-26 13:56:08 +08:00
leimingsheng
d584304e10 perf(master : nicsensor) update to 1.8.5
优化部分pmbus功能相关的提示性信息
2025-12-26 09:42:17 +08:00
leimingsheng
6423cc73a3 doc(master : nicsensor) 更新扩展脚本说明.md 2025-12-25 17:35:24 +08:00
leimingsheng
832daa21ab feat(master : nicsensor) update to 1.8.4 [重要]
新增pmbus功能,由于pmbus代码量极大且后期可能需要人为维护,将pmbus作为插件功能加入到nicsensor中.
后期维护 pmbus_cmd_list.sh 即可

遗留事项:pmbus set功能未实现,当前仅支持读取
2025-12-25 17:34:51 +08:00
leimingsheng
523f597353 feat(plugin : nicsensor)同步自动获取服务器类型得功能 2025-12-10 16:05:58 +08:00
leimingsheng
72c0ce073e fix(plugin : platform_5280m7) 修复detect时不显示插槽信息得问题 2025-12-10 16:05:27 +08:00
leimingsheng
625118199f fix(master : nicsensor) fix spell error , update to 1.8.3 2025-12-05 14:01:49 +08:00
2bc1bf05c6 更新 readme.md 2025-12-04 09:41:52 +08:00
leimingsheng
0bb410c72f feat(master : nicsensor) update to version 1.8.2
1.增加配置项fru_size,默认读取大小256字节
2025-12-04 09:21:49 +08:00
leimingsheng
a316ea37ca feat(master : nicsensor) update to version 1.8.1
1.fru写操作支持写入大于256字节的数据
2025-11-24 14:15:25 +08:00
leimingsheng
580de7fa6f feat(master : nicsensor) Release Version 1.8 2025-08-18 14:21:01 +08:00
leimingsheng
b5a0cac6e2 feat(master : nicsensor) 新增脚本nicsensor_s.sh 2025-08-18 14:20:10 +08:00
leimingsheng
2f6078586d feat(master : nicsensor) version change to intest 1.7.7 2025-07-25 15:37:26 +08:00
leimingsheng
ee381afcd6 perf(master : nicsensor) 修正部分变量名称,增强脚本可读性 2025-07-25 15:36:53 +08:00
leimingsheng
9642f77447 doc(master : readme) 更新readme以支持配置关键变量功能 2025-07-25 15:33:58 +08:00
leimingsheng
7b6ae2a932 feat(master : nicsensor) 支持通过命令配置关键变量 2025-07-25 15:23:55 +08:00
leimingsheng
e2ccb19dd3 feat(master : nicsensor) version change to intest 1.7.6 2025-07-07 16:48:16 +08:00
leimingsheng
fbe3fcbe07 style(master : nicsensor) 2025-07-07 16:47:35 +08:00
leimingsheng
85fccf4704 refactor(master : nicsensor) 整合fmt_print功能为一个函数 2025-07-07 16:32:08 +08:00
leimingsheng
86e92f0302 style(master : nicsensor) 精简脚本注释及格式 2025-07-07 16:25:26 +08:00
leimingsheng
3710481735 fix(master : nicsensor)优化try_get_server_type函数 2025-07-04 15:03:31 +08:00
leimingsheng
a49c474ee5 feat(master : nicsensor)version change to intest 1.7.5 2025-07-04 09:27:08 +08:00
leimingsheng
abb16fd798 refactor(master : nicsensor)更新代码结构 2025-07-04 09:25:38 +08:00
leimingsheng
a841ae4363 refactor(master : nicsensor) 更新补充usage 2025-07-04 09:08:37 +08:00
leimingsheng
6b40c9c790 feat(plugin : plugin_%)同步可配置为disable跳过数据转化的功能到V2 2025-07-03 10:08:37 +08:00
leimingsheng
d480139f1d feat(master : test_tool)添加阈值判断脚本 2025-06-27 14:29:53 +08:00
leimingsheng
b17104dc2f refactor(master : nicsensor) 调整部分传感器执行时的显示样式 2025-06-26 14:35:31 +08:00
leimingsheng
5f4c3ea8ac feat(master : nicsensor) version change to intest 1.7.4 2025-06-26 13:58:50 +08:00
leimingsheng
0592c4b786 doc(master : nicsensor)update readme 2025-06-26 13:58:00 +08:00
leimingsheng
9e07465212 refactor(master : nicsensor)重新整理变量结构 2025-06-26 13:53:43 +08:00
leimingsheng
0f24ea84f5 feat(master : nicsensor)当channel name配置为disable时,跳过该channel的解析 2025-06-26 13:44:19 +08:00
leimingsheng
fda6c0ab2b refactor(master : nicsensor) debug模式下跳过服务器识别功能 2025-06-26 11:43:51 +08:00
leimingsheng
58f45494af feat(master : nicsensor) version change to intest 1.7.3 2025-06-26 10:31:06 +08:00
leimingsheng
1eecd40539 refactor(master : nicsensor)提高auto识别服务器的健壮性 2025-06-26 10:27:25 +08:00
leimingsheng
6fce071426 fix(master : nicsensor)修正 parse_nic_slot无法识别两位数槽位号的问题 2025-06-26 10:19:22 +08:00
leimingsheng
d8f8aa9cb0 doc(master : readme) update readme 2025-06-24 10:51:52 +08:00
993bb01922 feat(master : nicsensor)version change to intest 1.7.2 2025-06-21 18:20:49 +08:00
bf9a77ddd2 refactor(master : nicsensor.sh)将触发自动识别服务器的type类型由default变更为auto 2025-06-21 18:19:42 +08:00
leimingsheng
ccce95117a feat(master : nicsensor) version change to intest 1.7.1 2025-06-20 15:42:48 +08:00
leimingsheng
55600bd77e doc(master : readme) 更新server_type的描述 2025-06-20 15:41:30 +08:00
leimingsheng
6eacac1f1a feat(master : nicsensor)添加功能: 根据boardid自动匹配服务器型号 2025-06-20 15:39:03 +08:00
leimingsheng
1e2f32dce3 feat(plugin : platform_%.sh)在platform函数下新增透传i2c命令的功能 2025-06-20 14:01:43 +08:00
leimingsheng
0bc98aa5cd feat(master : nicsensor) Release Version 1.7 2025-06-10 14:20:26 +08:00
leimingsheng
0220e932ce doc(master : readme) 补充描述 2025-06-10 10:52:54 +08:00
leimingsheng
6f1e3f89b2 doc(master : readme) 补充描述 2025-06-10 10:49:51 +08:00
leimingsheng
9c20fcd070 doc(master : 新增扩展脚本方法) 2025-06-05 16:36:47 +08:00
marcinlei@outlook.com
97b42937fb doc(master : code_structure)添加对detect功能的描述 2025-05-13 20:22:37 +08:00
leimingsheng
d5f4a6f0d8 doc(master : readme)添加Project Varible的说明 2025-05-13 10:20:05 +08:00
leimingsheng
aecfcb4ada doc(master : readme)补充2.6描述 2025-05-13 09:55:58 +08:00
leimingsheng
87a625426f feat(master : nicsensor) version change to intest 1.6.5 2025-05-12 14:17:44 +08:00
leimingsheng
03d6900ceb doc(master : readme) 添加扩展功能的说明 2025-05-12 14:17:13 +08:00
leimingsheng
26adc0bda8 feat(master : nicsensor)预留用户自定义功能 2025-05-12 14:09:12 +08:00
8a08250df7 feat(master : nicsensor)version change to intest 1.6.4 2025-05-09 23:04:55 +08:00
d211f41f55 feat(master : nicsensor)预留扩展函数 2025-05-09 23:03:59 +08:00
leimingsheng
c73dba1433 fix(plugin : plugin_ina3221)修正read方法中调用i2c_script的错误参数使用 2025-05-09 14:09:48 +08:00
leimingsheng
333530ac5a feat(plugin : nicsensor)导入操作执行完毕后默认关闭PCA9548的策略 2025-05-09 11:43:23 +08:00
leimingsheng
bba1d037d5 feat(master : nicsensor)version change to intest 1.6.3 2025-05-08 16:57:56 +08:00
leimingsheng
2d663d4ec8 refactor(master : nicsensor)调整init debug log函数 2025-05-08 14:59:33 +08:00
leimingsheng
abd632d4f2 refactor(master : nicsensor) 将所有的‘==’替换为‘=’ 2025-05-08 14:49:01 +08:00
leimingsheng
0f7ee5e040 feat(master : nicsensor)version change to intest 1.6.2 2025-05-08 11:00:27 +08:00
leimingsheng
c4d8503a46 refactor(master : nicsensor) 修正一处help info描述 2025-05-08 10:59:42 +08:00
leimingsheng
b7671e12e1 feat(master : nicsensor) version change to intest 1.6.1 2025-04-27 10:33:12 +08:00
leimingsheng
c11cd9317a refactor(master : nicsensor)将参数校验等功能移入到pre_exec_hook中 2025-04-27 10:31:53 +08:00
leimingsheng
d3ad01482a refactor(master : nicsensor) 整理 配置检查 和 调试日志初始化为同一个接口使用
新接口:pre_exec_hook
2025-04-27 10:21:37 +08:00
25 changed files with 2489 additions and 896 deletions

@ -1,3 +1,42 @@
# Script Version 1.11
#Release Note
1.[新增功能]解耦脚本参数配置功能, 脚本配置全部放到project.config中
2.[新增功能]增加对pmbus set命令的支持
3.[新增功能]增加setup.sh, 用于一键部署脚本
4.[功能优化]代码结构目录重新归档
# Script Verison 1.10
Release Note
1.[新增功能]新增适配传感器 ina226, lm95241
2.[新增功能]增加stress压测插件, 可支持自定义压测读取功能
3.[功能优化]优化help显示功能
4.[功能优化]优化脚本交互, 增加安全性检查
5.[功能优化]插件脚本加入版本号
6.[功能优化]nicsensor配置项全部放置到 /tmp/nicsensor_config 目录下, 便于维护
7.[功能优化]version命令移除debug, n_detect的显示,仅显示脚本版本号
8.[功能优化]默认i2cbus支持在参数配置功能中通过命令配置, 可用于debug模式默认搜索
9.[功能优化]默认fru offset支持在参数配置功能中通过命令配置
# Script Verison 1.9
Release Note
1.[新增功能]添加pmbus插件功能, 可支持对VR芯片的pmbus测试
2.[功能优化]fru size支持在属性配置功能中通过命令配置大小
3.[功能优化]对于 DISABLE_DETECT 的简写由 detect 变更为 n_detect, 便于理解
4.[问题修复]修复nicsensor_v2中5280m7平台的detect功能不显示插槽信息的问题
# Script Version 1.8
Release Note
1.[新增功能]默认server type调整为auto, 通用服务器可自动检索boardid,确认服务器类型
2.[新增功能]新增set get功能, 可使用命令对配置进行修改(详见readme)
3.[问题修复]修正无法识别两位数槽位号的问题
4.[功能优化]添加脚本 nicsensor_s.sh, 是nicsensor主体功能的简化版,删去了相对次要功能来确保功能快速执行
# Script Version 1.7 20250610
Release Note
1.[新增功能]预留扩展函数, 用于自定义选通网卡后的I2C操作
2.[功能优化]优化代码结构
3.[文档完善]新增脚本扩展方法, 用于指导新增适配服务器
# Script Version 1.6 20250422 # Script Version 1.6 20250422
Release Note Release Note
1.[新增功能]添加配置项 DISABLE_DETECT ,默认在执行时不进行i2cdetect 1.[新增功能]添加配置项 DISABLE_DETECT ,默认在执行时不进行i2cdetect

@ -1,4 +1,5 @@
On Version V1.x On Version V1.x
PART I. Sensor读取
start_get_sensor //启动读取Sensor的流程 start_get_sensor //启动读取Sensor的流程
|--->set_configuration |--->set_configuration
| |--->set_configuration_5280m7/5468m7/donghu/yichun //根据服务器类型设置具体I2C相关参数 | |--->set_configuration_5280m7/5468m7/donghu/yichun //根据服务器类型设置具体I2C相关参数
@ -8,3 +9,7 @@ On Version V1.x
|--->sensor_init //传感器可能需要初始化 |--->sensor_init //传感器可能需要初始化
|--->read_sensor_value //读取传感器的数值 |--->read_sensor_value //读取传感器的数值
|--->convert_sensor_value //处理传感器的读值并做可视化处理 |--->convert_sensor_value //处理传感器的读值并做可视化处理
PART II. Detect操作
start_detect_device //启动detect i2c的流程
|--->detect_on_5280m7/5468m7/donghu/yichun //根据服务器类型进行对应的detect操作

119
docs/扩展脚本说明.md Normal file

@ -0,0 +1,119 @@
# 如何扩展脚本?
## 一、前言
> [!tip]
>
> 脚本扩展一般涉及到两部分内容的扩充,包含对于支持服务器类型的扩充,或者对支持读取的传感器类型的扩充。
不论如何修改脚本,请在完成后主要修改后,修改 `SCRIPT_VERSION` 用于和主线脚本进行版本区分。
例如:
- `SCRIPT_VERSION="1.6.5 for project"` 代表基于脚本1.6.5版本为某个项目做特殊定制
## 二、新增支持服务器
### 修改点1-Support_Server_List
``````sh
# 可以在这里添加对应的服务器型号
Support_Server_List="5280m7, 5468m7, 5688m7, donghu, yichun, qiandaohu"
``````
### 修改点2-添加服务器配置入口
``````sh
# 修改函数 set_configuration
set_configuration(){
# ... 省略部分代码
case ${server_type} in
"5280m7")
set_configuration_5280m7
;;
# [开始修改]在这里针对要添加的服务器添加如下语句,将 {server_name} 替换为对应的服务器型号
# 这里修改的意义在于添加一个设置服务器I2C拓扑的入口后面会专门编写 set_configuration_{server_name} 函数
"{server_name}")
set_configuration_{server_name}
;;
# [结束修改]
esac
# ... 省略部分代码
}
``````
### 修改点3-添加I2C拓扑适配函数
``````sh
# 在脚本中找到函数 set_configuration_5280m7在这个函数上面新建一个函数名为
set_configuration_{server_name}(){
# 可以模仿 5280m7 函数的写法,来编写本函数
# 主体编写的内容就是针对卡的类型和槽位来配置通道上正确的I2C属性
# 需要考虑的内容如下:
# 1.是否支持OCP网卡
# 2.I2C链路上是否存在PCA9641
# 3.每个物理slot和I2C Bus的对应关系
# 4.每个物理slot和I2C PCA9546/9548 channel的对应关系
# 5.PCA9641和PCA9546/9548的slave地址
# 提供一种模板
# 首先判断网卡类型是否为 pcie (ocp形态同理)
if [ ${nic_type} = "pcie" ];then
# 根据 SLOT number 做针对性配置
if [ ${slot_number} -eq 0 ];then
i2c_bus=12
is_have_pca9641=1
pca9641_slave=0x41
pca9548_slave=0x70
pca9548_channel="0x01"
elif [ ${slot_number} -eq 1 ]; then
i2c_bus=12
is_have_pca9641=1
pca9641_slave=0x41
pca9548_slave=0x70
pca9548_channel="0x02"
elif [ ${slot_number} -eq 2 ]; then
i2c_bus=12
is_have_pca9641=1
pca9641_slave=0x41
pca9548_slave=0x70
pca9548_channel="0x04"
else
format_print $WARNING "Unspecified card slot!"
fi
fi
}
``````
### 修改点4-添加I2C扫描函数可选
``````sh
# 类似 修改点2, 在 start_detect_device 函数中添加入口函数
# 形如 detect_on_{server_name}
# 随后新建一个对应的函数
detect_on_{server_name}(){
# 首先给定对应 slot 的 i2c bus号码
i2c_bus=12
# 根据链路上是否存在9641来编写如果没有9641跳过这里
pca9641_slave="0x31"
get_pca9641_control
# 调用 do_i2c_detect 函数来执行一次9548的通道切换并做一次i2cdetect
# 参数表如下 i2cbus 9548_slave 9548_channel(hex) 9548_index slot_number
do_i2c_detect $i2c_bus "0x70" "0x01" 0 1
do_i2c_detect $i2c_bus "0x70" "0x02" 1 2
do_i2c_detect $i2c_bus "0x70" "0x04" 2 3
}
``````
### 修改点5-服务器auto选择配置可选
> [!note]
>
> script v1.8 新增特性:
>
> - server_type 配置为 auto 后可以自行搜索boardid进行匹配服务器类型仅限通用服务器
可以针对已知的boardid对 `try_get_server_type`函数中做针对性修改。

195
extension/pmbus_cmd_list.sh Normal file

@ -0,0 +1,195 @@
#!/bin/sh
# Desc : This script used to find pmbus code and read size
# Changelist : 2025-12-25|v0.1 Create this file
# 2026-04-17|v1.1 Add PAGE command support
# How to use this pmbus plugin?
# Follow readme.md file to use this plugin or use setup.sh to install this plugin
EXTENSION_VERSION="v1.1"
# ---------------------------------------------------------
# Varible Define
# ---------------------------------------------------------
operation_type=$1
str_cmd=$2
hex_cmd=0xff
read_size=0
PMBUS_BYTE=1
PMBUS_WORD=2
PMBUS_BLOCK=3
PMBUS_RAW=4
# ---------------------------------------------------------
# Function Define
# ---------------------------------------------------------
pmbus_command_help(){
echo " Extend Function - PMBUS command test"
echo " Version : $EXTENSION_VERSION"
echo " 1) Command Format : ./nicsensor.sh [slot] pmbus [slave] [command] <data>"
echo " 2) Option Detail"
echo " - [slot] : 0 1 2 3 4 5 ..."
echo " - [slave] : power manage chip slave address , please provide 7 bit address"
echo " - [command] : The pmbus command which will set to the power manage chip"
echo " - <data> : The data which will set to the power manage chip, only set operation type is set"
echo " 3) E.G. : ./nicsensor.sh pcie1 pmbus 0x60 READ_TEMPERATURE_1"
echo " : ./nicsensor.sh pcie1 pmbus 0x60 PAGE 0x00"
echo ""
echo " *****************Pmbus Support Command List********************"
echo " Command Name Code op_type Read Size "
echo " PAGE 0x00 set Byte "
echo " READ_VIN 0x88 get Word "
echo " READ_IIN 0x89 get Word "
echo " READ_VOUT 0x8b get Word "
echo " READ_IOUT 0x8c get Word "
echo " READ_TEMPERATURE_1 0x8d get Word "
echo " READ_TEMPERATURE_2 0x8e get Word "
echo " READ_TEMPERATURE_3 0x8f get Word "
echo " READ_POUT 0x96 get Word "
echo " READ_PIN 0x97 get Word "
echo " ***************************************************************"
echo ""
}
find_pmbus_hex_code(){
case ${str_cmd} in
"PAGE")
hex_cmd=0x00
;;
"READ_VIN")
hex_cmd=0x88
;;
"READ_IIN")
hex_cmd=0x89
;;
"READ_VOUT")
hex_cmd=0x8b
;;
"READ_IOUT")
hex_cmd=0x8c
;;
"READ_TEMPERATURE_1")
hex_cmd=0x8d
;;
"READ_TEMPERATURE_2")
hex_cmd=0x8e
;;
"READ_TEMPERATURE_3")
hex_cmd=0x8f
;;
"READ_POUT")
hex_cmd=0x96
;;
"READ_PIN")
hex_cmd=0x97
;;
*)
hex_cmd=0xff
;;
esac
echo $hex_cmd
}
find_pmbus_operation_type(){
case ${str_cmd} in
"PAGE")
op_type="set"
;;
"READ_VIN")
op_type="get"
;;
"READ_IIN")
op_type="get"
;;
"READ_VOUT")
op_type="get"
;;
"READ_IOUT")
op_type="get"
;;
"READ_TEMPERATURE_1")
op_type="get"
;;
"READ_TEMPERATURE_2")
op_type="get"
;;
"READ_TEMPERATURE_3")
op_type="get"
;;
"READ_POUT")
op_type="get"
;;
"READ_PIN")
op_type="get"
;;
*)
op_type=""
;;
esac
echo $op_type
}
find_pmbus_read_size(){
case ${str_cmd} in
"PAGE")
read_size=$PMBUS_BYTE
;;
"READ_VIN")
read_size=$PMBUS_WORD
;;
"READ_IIN")
read_size=$PMBUS_WORD
;;
"READ_VOUT")
read_size=$PMBUS_WORD
;;
"READ_IOUT")
read_size=$PMBUS_WORD
;;
"READ_TEMPERATURE_1")
read_size=$PMBUS_WORD
;;
"READ_TEMPERATURE_2")
read_size=$PMBUS_WORD
;;
"READ_TEMPERATURE_3")
read_size=$PMBUS_WORD
;;
"READ_POUT")
read_size=$PMBUS_WORD
;;
"READ_PIN")
read_size=$PMBUS_WORD
;;
*)
read_size=0
;;
esac
echo $read_size
}
main(){
case ${operation_type} in
"code")
find_pmbus_hex_code
;;
"operation")
find_pmbus_operation_type
;;
"size")
find_pmbus_read_size
;;
"help")
pmbus_command_help
;;
*)
echo "Error command type"
;;
esac
}
# ---------------------------------------------------------
# Start Execute Script(main)
# ---------------------------------------------------------
main

209
extension/stress_test.sh Normal file

@ -0,0 +1,209 @@
#!/bin/sh
# Desc: Stress test script for nicsensor
# Detail: This script will stress test the nicsensor by reading the sensor data
# and print the result to the console.
EXTENSION_VERSION="v1.0 Base Dev 1"
# ---------------------------------------------------------
# Varible Define
# ---------------------------------------------------------
Param1=$1
Param2=$2
CONFIG_DIR="/tmp/nicsensor_config"
CONFIG_NICSENSOR="${CONFIG_DIR}/stress_tool"
CONFIG_SLOT="${CONFIG_DIR}/stress_slot"
CONFIG_SENSOR="${CONFIG_DIR}/stress_sensor"
CONFIG_ROUND="${CONFIG_DIR}/stress_round"
CONFIG_INTERVAL="${CONFIG_DIR}/stress_interval"
CONFIG_SLAVE="${CONFIG_DIR}/stress_slave"
config_tool=""
# ---------------------------------------------------------
# Function Define
# ---------------------------------------------------------
print_usage(){
echo " Extend Function - Stress Test"
echo " Version: $EXTENSION_VERSION"
echo " 1) Description"
echo " This plugin will stress test the nicsensor by reading the sensor data"
echo " and print the result to the console."
echo " 2) Command Format : ./nicsensor.sh [slot] stress [option] [data]"
echo " 3) Option Detail"
echo " - [slot] : The nicsensor slot number"
echo " - [option] : start|show|round|tool|interval|slot|sensor|slave"
echo " - [data] : The option data"
echo " 4) Example"
echo " Case: Test PCIe1 Nic's INA3221, slave=0x42, round=1000, interval=3s"
echo " Step 1 : Set the stress test parameter"
echo " ./nicsensor.sh pcie1 stress slot pcie1"
echo " ./nicsensor.sh pcie1 stress round 1000"
echo " ./nicsensor.sh pcie1 stress interval 3"
echo " ./nicsensor.sh pcie1 stress sensor ina3221"
echo " ./nicsensor.sh pcie1 stress slave 0x42"
echo " Step 2 : Check the stress test configuration"
echo " ./nicsensor.sh pcie1 stress show"
echo " Step 3 : Start the stress test"
echo " ./nicsensor.sh pcie1 stress start"
}
set_stress_config(){
case ${Param1} in
"round")
echo "Set the stress test round to ${Param2}"
echo ${Param2} > ${CONFIG_ROUND}
;;
"interval")
echo "Set the stress test interval to ${Param2}s"
echo ${Param2} > ${CONFIG_INTERVAL}
;;
"sensor")
echo "Set the stress test sensor to ${Param2}"
echo ${Param2} > ${CONFIG_SENSOR}
;;
"slave")
echo "Set the stress test slave to ${Param2}"
echo ${Param2} > ${CONFIG_SLAVE}
;;
"slot")
echo "Set the stress test slot to ${Param2}"
echo ${Param2} > ${CONFIG_SLOT}
;;
"tool")
echo "Set the stress test tool to ${Param2}"
echo ${Param2} > ${CONFIG_NICSENSOR}
;;
*)
echo "Invalid option: ${Param1}"
;;
esac
}
get_stress_all_config(){
echo "Stress Test Config:"
if [ -f ${CONFIG_NICSENSOR} ]; then
echo " Tool : $(cat ${CONFIG_NICSENSOR})"
else
echo " Tool : nicsensor.sh"
fi
if [ -f ${CONFIG_ROUND} ]; then
echo " Round : $(cat ${CONFIG_ROUND})"
else
echo " Round : Not Set"
fi
if [ -f ${CONFIG_INTERVAL} ]; then
echo " Interval: $(cat ${CONFIG_INTERVAL})s"
else
echo " Interval: Not Set"
fi
if [ -f ${CONFIG_SLOT} ]; then
echo " Slot : $(cat ${CONFIG_SLOT})"
else
echo " Slot : Not Set"
fi
if [ -f ${CONFIG_SENSOR} ]; then
echo " Sensor : $(cat ${CONFIG_SENSOR})"
else
echo " Sensor : Not Set"
fi
if [ -f ${CONFIG_SLAVE} ]; then
echo " Slave : $(cat ${CONFIG_SLAVE})"
else
echo " Slave : Not Set"
fi
}
start_stress_test(){
# nicsensor tool check
if [ -f ${CONFIG_NICSENSOR} ]; then
config_tool=$(cat ${CONFIG_NICSENSOR})
else
config_tool="/extlog/nicsensor/nicsensor.sh"
fi
if [ ! -f "${config_tool}" ]; then
echo "Error: ${config_tool} tool not found"
echo "Info : Please check the nicsensor tool path and name"
return 1
fi
# option check
if [ ! -f ${CONFIG_ROUND} ]; then
echo "Error: Round is not set"
echo "Info : Please set the stress test round first, use command: ${config_tool} [slot] stress round [data]"
return 1
fi
if [ ! -f ${CONFIG_INTERVAL} ]; then
echo "Error: Interval is not set"
echo "Info : Please set the stress test interval first, use command: ${config_tool} [slot] stress interval [data]"
return 1
fi
if [ ! -f ${CONFIG_SLOT} ]; then
echo "Error: Slot is not set"
echo "Info : Please set the stress test slot first, use command: ${config_tool} [slot] stress slot [data]"
return 1
fi
if [ ! -f ${CONFIG_SENSOR} ]; then
echo "Error: Sensor is not set"
echo "Info : Please set the stress test sensor first, use command: ${config_tool} [slot] stress sensor [data]"
return 1
fi
if [ ! -f ${CONFIG_SLAVE} ]; then
echo "Error: Slave is not set"
echo "Info : Please set the stress test slave first, use command: ${config_tool} [slot] stress slave [data]"
return 1
fi
# start stress test
echo "Stress Test Config Info:"
config_round=$(cat ${CONFIG_ROUND})
config_interval=$(cat ${CONFIG_INTERVAL})
config_slot=$(cat ${CONFIG_SLOT})
config_sensor=$(cat ${CONFIG_SENSOR})
config_slave=$(cat ${CONFIG_SLAVE})
echo " Round : ${config_round}"
echo " Interval: ${config_interval}s"
echo " Slot : ${config_slot}"
echo " Sensor : ${config_sensor}"
echo " Slave : ${config_slave}"
run_count=1
while [ ${run_count} -le ${config_round} ]; do
echo ""
timestamp=$(date +"%Y-%m-%dT%H:%M:%S")
echo "====== ${timestamp}, Run Count: ${run_count}"
exec_cmd="${config_tool} ${config_slot} ${config_sensor} ${config_slave}"
${exec_cmd}
sleep ${config_interval}
run_count=$((run_count+1))
done
echo "==========================================="
echo " Stress Test Completed"
}
main(){
cmd=${Param1}
case ${cmd} in
"start")
echo "Start the stress test"
start_stress_test
;;
"show")
echo "Show the stress test configuration"
get_stress_all_config
;;
"help")
print_usage
;;
*)
echo "Set Stress Config"
set_stress_config
;;
esac
}
# ---------------------------------------------------------
# Start Execute Script(main)
# ---------------------------------------------------------
main

File diff suppressed because it is too large Load Diff

56
project.config Normal file

@ -0,0 +1,56 @@
# ADC128 Division factor
votage_division_factor_0="1"
votage_division_factor_1="1"
votage_division_factor_2="1"
votage_division_factor_3="0.8"
votage_division_factor_4="0.6"
votage_division_factor_5="0.6"
votage_division_factor_6="0.2326"
votage_division_factor_7="1"
# ADC128 channel name
ADC128_Channel0_name="Channel0"
ADC128_Channel1_name="Channel1"
ADC128_Channel2_name="Channel2"
ADC128_Channel3_name="Channel3"
ADC128_Channel4_name="Channel4"
ADC128_Channel5_name="Channel5"
ADC128_Channel6_name="Channel6"
ADC128_Channel7_name="Channel7"
# INA3221 shunt resistor(unit: mohm)
shunt_resistor_0="2"
shunt_resistor_1="2"
shunt_resistor_2="5"
# INA3221 channel name
INA3221_Channel0_name="Channel0"
INA3221_Channel1_name="Channel1"
INA3221_Channel2_name="Channel2"
# EMC1413 channel name
EMC1413_Channel0_name="Channel0"
EMC1413_Channel1_name="Channel1"
EMC1413_Channel2_name="Channel2"
# TMP468 channel name
TMP468_Channel0_name="Local"
TMP468_Channel1_name="Remote1"
TMP468_Channel2_name="Remote2"
TMP468_Channel3_name="Remote3"
TMP468_Channel4_name="Remote4"
TMP468_Channel5_name="Remote5"
TMP468_Channel6_name="Remote6"
TMP468_Channel7_name="Remote7"
TMP468_Channel8_name="Remote8"
# TMP112 sensor name
TMP112_Sensor_name="Temperature"
# INA226 channel name
INA226_Channel0_name="Channel0"
# LM95241 channel name
LM95241_Local_name="Local"
LM95241_Remote1_name="Remote1"
LM95241_Remote2_name="Remote2"

347
readme.md

@ -1,72 +1,105 @@
# nicsensor工具使用说明 # nicsensor工具使用说明
> 本说明仅针对 nicsensorv1.x系列脚本 > 本说明仅针对 nicsensorv1.x系列脚本
> 1.x系列工具本体: [nicsensor.sh](./nicsensor.sh)
## 快速使用
工具Usage `./nicsensor.sh help`
工具版本查询 `./nicsensor.sh version`
读取传感器:`./nicsensor.sh pcie0 ina3221 0x42` (读取PCIE_0 上网卡的 INA3221 传感器slave地址0x42)
## 目录 ## 目录
- [nicsensor工具使用说明](#nicsensor工具使用说明) - [nicsensor工具使用说明](#nicsensor工具使用说明)
- [目录](#目录) - [目录](#目录)
- [1\_简介](#1_简介) - [1.简介](#1_简介)
- [2\_使用方法](#2_使用方法) - [2.使用方法](#2_使用方法)
- [2\_1\_传感器读取](#2_1_传感器读取) - [2.1 传感器读取](#2_1_传感器读取)
- [2\_2\_FRU相关操作](#2_2_fru相关操作) - [2.2 FRU读写](#2_2_fru读写)
- [2\_3\_命令透传](#2_3_命令透传) - [2.3 命令透传](#2_3_命令透传)
- [2\_4\_插槽I2C信息遍历](#2_4_插槽i2c信息遍历) - [2.4 服务器网卡通道I2C信息扫描](#2_4_服务器网卡通道I2C信息扫描)
- [2\_5\_调试模式使用](#2_5_调试模式使用) - [2.5 调试模式](#2_5_调试模式)
- [3\_常见问题](#3_常见问题) - [2.6 扩展功能](#2_6_扩展功能)
- [3\_1\_ADC128传感器读值为0](#3_1_adc128传感器读值为0) - [2.7 参数配置](#2_7_参数配置)
- [3\_2\_脚本执行时出现大批量语法错误](#3_2_脚本执行时出现大批量语法错误) - [2.8 PMBUS功能测试](#2_8_pmbus功能)
- [4\_附属工具](#4_附属工具) - [2.9 压力测试stress](#2_9_压力测试stress)
- [4\_1\_FruParse](#4_1_fruparse) - [3.常见问题](#3_常见问题)
- [5\_关于nicsensor\_v2](#5_关于nicsensor_v2) - [3.1 ADC128传感器读值为0](#3_1_adc128传感器读值为0)
- [3.2 脚本执行时出现大批量语法错误](#3_2_脚本执行时出现大批量语法错误)
- [3.3 传感器读值不正确](#3_3_传感器读值不正确)
- [4.附属工具](#4_附属工具)
- [4.1 FruParse](#4_1_fruparse)
- [4.2 nicsensor\_s(已停用)](#4_2_nicsensor_s)
- [5.关于nicsensor\_v2](#5_关于nicsensor_v2)
- [6.附录](#6_附录)
- [6.1 Project变量说明](#6_1_project变量说明)
## 1_简介 ## 1_简介
nicsensor工具是在带有i2ctool工具(i2ctransfer、i2cdetect)的BMC下用于测试网卡I2C功能的工具。 nicsensor工具是在带有i2ctool工具(i2ctransfer、i2cdetect)的BMC下用于测试网卡I2C功能的工具。
**当前支持的功能有:** **当前支持的功能有:**
- 读取网卡上的I2C传感器 - 读取网卡上的I2C传感器
- 读取并修改网卡上的FRU - 读取并修改网卡上的FRU
- 透传I2C命令到网卡的芯片上 - 透传I2C命令到网卡的芯片上
- 遍历服务器上的PCIE插槽的I2C信息 - 遍历服务器上的PCIE插槽的I2C信息
- 部分服务器类型支持读取OCP卡 - 部分服务器类型支持读取OCP卡
- 支持记录单次运行日志
- 支持测试PMBUS功能**(new)**
- 支持进行压力测试**(new)**
**当前支持测试的传感器类型** **当前支持测试的传感器类型**
- adc128 - adc128
- ina3221 - ina3221
- ina226**(new)**
- emc1413 - emc1413
- tmp468 - tmp468
- tmp112 - tmp112
- lm95241**(new)**
> [!tip]
> 每次执行脚本都可以在 `/tmp/nicsensor_debug.log` 查询详细的命令执行记录
## 2_使用方法 ## 2_使用方法
> [!warning] > [!warning]
> 在使用时针对网卡的硬件特性需要定制化修改脚本的 `Project Varible` > 在使用时针对网卡的硬件特性需要定制化修改脚本的 `Project Varible` ,变量的对应关系及说明见[Project变量说明](#6_1_project变量说明)
### 2_1_传感器读取 ### 2_1_传感器读取
**命令格式** **命令格式**
``` shell ``` shell
./nicsensor.sh <pcie_slot> <sensor_tpye> <sensor_slave> ./nicsensor.sh <pcie_slot> <sensor_tpye> <sensor_slave>
``` ```
**参数说明** **参数说明**
- `pcie slot`:网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型
- `sensor type`:传感器类型 | Properties | type | 说明 |
- `sensor slave`:传感器的slave地址 | -------------- | ------- | ------------------------------------------------------------ |
| `pcie slot` | string | 网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型 |
| `sensor type` | string | 传感器类型 |
| `sensor slave` | hex num | 传感器的slave地址(7 bit) |
**命令示例** **命令示例**
``` shell ``` shell
# 读取pcie2槽位上的adc128的信息, adc128芯片的地址为0x1f(7bit) # 读取pcie2槽位上的adc128的信息, adc128芯片的地址为0x1f(7bit)
./nicsensor.sh pcie2 adc128 0x1f ./nicsensor.sh pcie2 adc128 0x1f
# 读取pcie3槽位上的ina3221的信息, ina3221芯片的地址为0x40(7bit)
./nicsensor.sh 3 ina3221 0x40
# 读取ocp0槽位上的tmp112的信息, tmp112芯片的地址为0x48(7bit)
./nicsensor.sh ocp0 tmp112 0x48
``` ```
### 2_2_FRU相关操作
### 2_2_FRU读写
> [!warning] > [!warning]
> 在写入网卡FRU操作时受限于服务器PCA9641的影响需要将服务器关机后执行 > 在写入网卡FRU操作时受限于服务器PCA9641的影响**建议**将服务器关机后执行
**命令格式** **命令格式**
``` shell ``` shell
@ -78,9 +111,12 @@ nicsensor工具是在带有i2ctool工具(i2ctransfer、i2cdetect)的BMC下用于
``` ```
**参数说明** **参数说明**
- `pcie slot`:网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型
- `eeprom slave`: FRU所在的eeprom芯片的slave地址 | Properties | type | 说明 |
- `filename`: 仅在写入FRU时提供, 要写入的FRU bin文件 | -------------- | ------- | ------------------------------------------------------------ |
| `pcie slot` | string | 网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型 |
| `eeprom slave` | hex num | FRU所在的eeprom芯片的slave地址(7 bit) |
| `filename` | string | 仅在写入FRU时提供, 要写入的FRU bin文件路径 |
**命令示例** **命令示例**
``` shell ``` shell
@ -91,16 +127,24 @@ nicsensor工具是在带有i2ctool工具(i2ctransfer、i2cdetect)的BMC下用于
./nicsensor.sh pcie2 fru 0x50 write fru.bin ./nicsensor.sh pcie2 fru 0x50 write fru.bin
``` ```
### 2_3_命令透传 ### 2_3_命令透传
提供对芯片直接执行i2c命令的能力通常用于访问网卡核心芯片如FPGANic Controller等。
**命令格式** **命令格式**
``` shell ``` shell
./nicsensor.sh <pcie_slot> chip <chip slave> <command> ./nicsensor.sh <pcie_slot> chip <chip slave> <command>
``` ```
**参数说明** **参数说明**
- `pcie slot`:网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型
- `chip slave`: 芯片的slave地址 | Properties | type | 说明 |
- `command`: 要透传执行的I2C命令 | ------------ | ------- | ------------------------------------------------------------ |
| `pcie slot` | string | 网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型 |
| `chip slave` | hex num | 芯片的slave地址(7 bit) |
| `command` | string | 要透传执行的I2C命令 |
**命令示例** **命令示例**
``` shell ``` shell
@ -108,7 +152,9 @@ nicsensor工具是在带有i2ctool工具(i2ctransfer、i2cdetect)的BMC下用于
./nicsensor.sh pcie2 chip 0x11 "i2ctransfer -y 12 w2@0x11 0x00 0x00 r2" ./nicsensor.sh pcie2 chip 0x11 "i2ctransfer -y 12 w2@0x11 0x00 0x00 r2"
``` ```
### 2_4_插槽I2C信息遍历
### 2_4_服务器网卡通道I2C信息扫描
**命令格式** **命令格式**
``` shell ``` shell
@ -123,34 +169,261 @@ nicsensor工具是在带有i2ctool工具(i2ctransfer、i2cdetect)的BMC下用于
./nicsensor.sh detect pcie ./nicsensor.sh detect pcie
``` ```
### 2_5_调试模式使用
> 关联变量 `DEBUG_MODE`, 启用调试模式时需要将该变量的值配置为1
### 2_5_调试模式
如果不需要借助脚本来选通服务器上对应的channel, 仅需要做传感器数值测试, 可以启用调试模式。 如果不需要借助脚本来选通服务器上对应的channel, 仅需要做传感器数值测试, 可以启用调试模式。
在调试模式下, 脚本不会执行选通PCA9641以及PCA9546/9548的操作。仅直接测试传感器。因此需要手动调整两个变量 在调试模式下, 脚本不会执行选通PCA9641以及PCA9546/9548的操作。仅直接测试传感器。
- `DEBUG_MODE`
- `i2c_bus` **开启调试模式**
``````sh
./nicsensor.sh set debug 1
``````
**关闭调试模式**
``````sh
./nicsensor.sh set debug 0
``````
### 2_6_扩展功能
脚本中预留了函数 `handle_reserve` 用于扩展功能。针对有特殊需求的项目可能会使用。
`handle_reserve` 中可以自定义需要对网卡实现的功能。在调用该函数之前脚本会将 PCA9641及PCA9548选通。扩展功能时无需考虑PCA9641和PCA9548的状态。
### 2_7_参数配置
可以通过一组名为 `get/set` 的指令对脚本中的如下变量做即时修改而无需修改脚本(下电后恢复默认)。支持修改的变量如下:
| Properties | 对应脚本变量 | 说明 |
| ------------ | ---------------- | ---------------------------------------- |
| `server` | `server_type` | 脚本应用的服务器类型 |
| `debug` | `DEBUG_MODE` | 是否启用调试模式 |
| `n_detect` | `DISABLE_DETECT` | 是否禁止执行时的i2c detect操作 |
| `fru_size` | `fru_size` | 默认fru的读取字节数 |
| `fru_offset` | `fru_offset` | 默认fru在eeprom的起始偏移地址 |
| `i2cbus` | `i2c_bus` | 默认的i2c bus通常需要搭配debug一起使用 |
**命令格式**
``` shell
./nicsensor.sh <get/set> <property> <value>
```
**命令示例**
``` shell
./nicsensor.sh set server 5280m7
./nicsneosr.sh get debug
```
### 2_8_PMBUS功能
> [!warning]
> 支持的脚本版本v1.9及以上
> PMBUS功能属于额外的功能,需要将 [pmbus_cmd_list.sh](./pmbus_cmd_list.sh) 拷贝到和nicsensor脚本相同的目录。
> 如果不添加该脚本, 该功能无法正常使用
**命令格式**
``` shell
./nicsensor.sh <pcie slot> pmbus <chip slave> <pmbus cmd>
```
**参数说明**
- `pcie slot`: 网卡位于的PCIE SLOT槽位,需要指定pcie/ocp, 不指定时默认为pcie类型
- `chip slave`: 芯片的slave地址
- `pmbus cmd`: 要读取的pmbus命令码, 支持列表请使用命令 `./nicsensor.sh help` 查询
**命令示例**
``` shell
./nicsensor.sh pcie1 pmbus 0x60 READ_TEMPERATURE_1
```
### 2_9_压力测试stress
> [!Warning]
>
> 支持的脚本版本v1.10及以上
>
> 压力测试属于额外的功能,需要将 [stress_test.sh](./stress_test.sh) 拷贝到和nicsensor脚本相同的目录。
>
> 如果不添加该脚本,该功能无法正常使用
**功能介绍**
一个模块化的压力测试工具通过配置文件管理测试参数支持灵活设置测试轮次、间隔、传感器类型等方便用户进行nicsensor的稳定性测试。
**命令格式**
``````sh
./nicsensor.sh <pcie slot> stress <option> <option data>
``````
**参数说明**
| 参数名称 | 数据类型 | 说明 |
| ------------- | -------- | ------------------------------------------------------------ |
| `pcie slot` | string | nicsensor工具通用格式在这里无特殊含义 |
| `option` | string | 要执行的stress命令类型有如下取值<br>`start` : 开始执行压力测试无需option data<br>`show`: 显示压力测试的配置项, 无需option data<br>`round`: 要执行的压力测试圈数<br>`tool`: 要使用的nicsensor脚本默认为nicsensor.sh<br>`interval`: 每一圈执行的时间间隔,单位为秒(s)<br>`slot`: 目标测试的插槽号<br>`sensor`: 需要测试的传感器类型<br>`slave`: 目标传感器的slave地址 |
| `option data` | string | 依据option类型决定是否需要该字段 |
**命令示例**
``````sh
#场景说明对pcie1的网卡压测 ina3221(0x42) 100次, 读取间隔2s
# step 1 配置测试项
./nicsensor.sh pcie1 stress round 100
./nicsensor.sh pcie1 stress interval 2
./nicsensor.sh pcie1 stress slot pcie1
./nicsensor.sh pcie1 stress sensor ina3221
./nicsensor.sh pcie1 stress slave 0x42
# step 2 查看测试项是否符合预期
./nicsensor.sh pcie1 stress show
# step 3 开始测试
./nicsensor.sh pcie1 stress start
``````
> 关联变量 `DISABLE_DETECT`, 启用时配置为1, 将不会在切换PCA9641和PCA9548时进行i2cdetect
## 3_常见问题 ## 3_常见问题
### 3_1_ADC128传感器读值为0 ### 3_1_ADC128传感器读值为0
ADC128传感器在使用时需要初始化, 因此第一次读取时传感器可能并未完成初始化, 所以读值为0 ADC128传感器在使用时需要初始化, 因此第一次读取时传感器可能并未完成初始化, 所以读值为0
### 3_2_脚本执行时出现大批量语法错误 ### 3_2_脚本执行时出现大批量语法错误
通常是因为服务器上含有PCA9641切断了BMC的I2C控制权导致重试即可 通常是因为服务器上含有PCA9641切断了BMC的I2C控制权导致, 重试即可
### 3_3_传感器读值不正确
常见于ina3221传感器读值明显不正确, 因为ina3221的i2c slave地址比较敏感, 容易和pca9641产生冲突, 可首先按照i2c地址冲突的方向去排查问题。
## 4_附属工具 ## 4_附属工具
### 4_1_FruParse ### 4_1_FruParse
提供了一个简单python脚本用于解析FRU的数据, 将nicsensor读取到的FRU数据拷贝到frudata.txt后, 执行 提供了一个简单python脚本用于解析FRU的数据, 将nicsensor读取到的FRU数据拷贝到frudata.txt后, 执行
`python fru_parse.py`即可将读取到的数据转化为FRU内容 `python fru_parse.py`即可将读取到的数据转化为FRU内容
**工具路径**:[fru_parse.py](./tool/fru_parse/fru_parse.py)
### 4_2_nicsensor_s
该工具已于`nicsensor v1.10` 移除
~~基于脚本版本1.8, 剔除了所有记日志的操作, 用于加速i2c的执行, 确保在9641工作的生命周期内尽快完成i2c任务~~
~~**工具路径**:[nicsensor_s.sh](./nicsensor_s.sh)~~
## 5_关于nicsensor_v2 ## 5_关于nicsensor_v2
nicsensor_v2将服务器选通channel和读取传感器数值的功能解耦因此在单独使用某个功能时可以直接找到对应的脚本进行测试。 nicsensor_v2将服务器选通channel和读取传感器数值的功能解耦, 因此在单独使用某个功能时可以直接找到对应的脚本进行测试。
详见[nicsensor_v2](./nicsensor_v2/readme.md) 详见[nicsensor_v2](./nicsensor_v2/readme.md)
## 6_附录
### 6_1_Project变量说明
> [!important]
> 对于所有传感器的`xxx_Channel_name`, 将其配置为`disable`即可跳过对应的channel的数据解析。
> 推荐在硬件上空置的Channel将其配置为 `disable`,防止脚本解析数据时出现混淆
**ADC128**相关
| 变量 | 定义 |
| -------------------------- | ----------------------------------- |
| `votage_division_factor_0` | ADC128芯片Channel 0的分压系数 |
| `votage_division_factor_1` | ADC128芯片Channel 1的分压系数 |
| `votage_division_factor_2` | ADC128芯片Channel 2的分压系数 |
| `votage_division_factor_3` | ADC128芯片Channel 3的分压系数 |
| `votage_division_factor_4` | ADC128芯片Channel 4的分压系数 |
| `votage_division_factor_5` | ADC128芯片Channel 5的分压系数 |
| `votage_division_factor_6` | ADC128芯片Channel 6的分压系数 |
| `votage_division_factor_7` | ADC128芯片Channel 7的分压系数 |
| `ADC128_Channel0_name` | 定制化ADC128芯片Channel 0的电压名称 |
| `ADC128_Channel1_name` | 定制化ADC128芯片Channel 1的电压名称 |
| `ADC128_Channel2_name` | 定制化ADC128芯片Channel 2的电压名称 |
| `ADC128_Channel3_name` | 定制化ADC128芯片Channel 3的电压名称 |
| `ADC128_Channel4_name` | 定制化ADC128芯片Channel 4的电压名称 |
| `ADC128_Channel5_name` | 定制化ADC128芯片Channel 5的电压名称 |
| `ADC128_Channel6_name` | 定制化ADC128芯片Channel 6的电压名称 |
| `ADC128_Channel7_name` | 定制化ADC128芯片Channel 7的电压名称 |
**INA3221**相关
| 变量 | 定义 |
| ----------------------- | ----------------------------------------------------- |
| `shunt_resistor_0` | INA3221芯片的Channel 0外接的分流电阻的大小(单位:毫欧) |
| `shunt_resistor_1` | INA3221芯片的Channel 1外接的分流电阻的大小(单位:毫欧) |
| `shunt_resistor_2` | INA3221芯片的Channel 2外接的分流电阻的大小(单位:毫欧) |
| `INA3221_Channel0_name` | 定制化INA3221芯片Channel 0的名称 |
| `INA3221_Channel1_name` | 定制化INA3221芯片Channel 1的名称 |
| `INA3221_Channel2_name` | 定制化INA3221芯片Channel 2的名称 |
**EMC1413**相关
| 变量 | 定义 |
| ----------------------- | ------------------------------------ |
| `EMC1413_Channel0_name` | 定制化EMC1413芯片Channel 0的温度名称 |
| `EMC1413_Channel1_name` | 定制化EMC1413芯片Channel 1的温度名称 |
| `EMC1413_Channel2_name` | 定制化EMC1413芯片Channel 2的温度名称 |
**TMP468**相关
| 变量 | 定义 |
| ---------------------- | ----------------------------------------- |
| `TMP468_Channel0_name` | 定制化TMP468芯片Loacl Channel的温度名称 |
| `TMP468_Channel1_name` | 定制化TMP468芯片Remote1 Channel的温度名称 |
| `TMP468_Channel2_name` | 定制化TMP468芯片Remote2 Channel的温度名称 |
| `TMP468_Channel3_name` | 定制化TMP468芯片Remote3 Channel的温度名称 |
| `TMP468_Channel4_name` | 定制化TMP468芯片Remote4 Channel的温度名称 |
| `TMP468_Channel5_name` | 定制化TMP468芯片Remote5 Channel的温度名称 |
| `TMP468_Channel6_name` | 定制化TMP468芯片Remote6 Channel的温度名称 |
| `TMP468_Channel7_name` | 定制化TMP468芯片Remote7 Channel的温度名称 |
| `TMP468_Channel8_name` | 定制化TMP468芯片Remote8 Channel的温度名称 |
**TMP112**相关
| 变量 | 定义 |
| -------------------- | ---------------------- |
| `TMP112_Sensor_name` | 定制化TMP112对应的名称 |
**INA226**相关
| 变量 | 定义 |
| ---------------------- | ------------------------------- |
| `INA226_Channel0_name` | 定制化INA226芯片Channel 0的名称 |
**LM95241**相关
| 变量 | 定义 |
| ---------------------- | ------------------------------------------ |
| `LM95241_Local_name` | 定制化LM95241芯片Loacl Channel的温度名称 |
| `LM95241_Remote1_name` | 定制化LM95241芯片Remote1 Channel的温度名称 |
| `LM95241_Remote2_name` | 定制化LM95241芯片Remote2 Channel的温度名称 |

57
setup.sh Normal file

@ -0,0 +1,57 @@
#!/bin/sh
# Script Description:
# This script is used to auto setup the nicsensor tool and its extensions.
SCRIPT_VERSION="1.0.0"
SUPPORT_TOOL_VERSION="1.11"
# Default values
source_extension_dir="./extension"
destination_tool_dir="/extlog/nicsensor"
destination_extension_dir="/extlog/nicsensor/extension"
exec_path="/extlog/nicsensor/nicsensor.sh"
# PRINT SCRIPT INFO
echo "=== Nicsensor Quick Setup Script! ==="
echo "Setup Tool Version : $SCRIPT_VERSION"
echo "Support nicsensor tool Version : $SUPPORT_TOOL_VERSION"
# Check if the destination extension directory exists, if not, create it
if [ ! -d "$destination_extension_dir" ]; then
echo "Step 0 : Create directory $destination_extension_dir"
mkdir -p "$destination_extension_dir"
fi
# Get script Path
script_dir=$(pwd)
source_extension_dir="$script_dir/extension"
# check if the source extension directory exists, if not, exit
if [ ! -d "$source_extension_dir" ]; then
echo "Error : Source extension directory $source_extension_dir does not exist"
exit 1
fi
# copy the extension files to the destination directory
echo "Step 1 : Copy extension files to $destination_extension_dir"
cp -rf "$source_extension_dir"/* "$destination_extension_dir"
# Add execute permission for extension files
echo "Step 2 : Add execute permission for extension files"
chmod +x "$destination_extension_dir"/*
# copy the project config to the destination directory
echo "Step 3 : Copy project.config to $destination_tool_dir"
cp -f "./project.config" "$destination_tool_dir"
# copy the exec file to the destination directory
echo "Step 4 : Copy nicsensor to $exec_path"
cp -f "./nicsensor.sh" "$exec_path"
# Add execute permission for exec file
echo "Step 5 : Add execute permission for nicsensor"
chmod +x "$exec_path"
echo "Complete auto setup nicsensor tool and its extensions."

@ -0,0 +1,122 @@
import os
import zipfile
import sys
# ===================== 【可配置项】 =====================
# 输出目录(可自定义修改,例如 D:/release / /home/user/release
OUTPUT_DIR = ""
# 最小打包内容
MIN_FILES = [
"extension",
"nicsensor.sh",
"project.config",
"setup.sh"
]
# 完整工程打包内容(所有文件)
FULL_FILES = [
"docs",
"extension",
"tool",
"nicsensor.sh",
"project.config",
"readme.md",
"setup.sh"
]
# ======================================================
def get_project_root():
"""
自动获取工程根目录脚本在 tool/auto_package/
"""
# 当前脚本目录tool/auto_package
current_dir = os.path.dirname(os.path.abspath(__file__))
# 工程根目录 = 往上两级
project_root = os.path.abspath(os.path.join(current_dir, "../.."))
return project_root
def pack_files(zip_path, file_list, project_root):
"""
统一打包函数
"""
os.chdir(project_root) # 切换到工程根目录,保证打包路径正确
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
for item in file_list:
if not os.path.exists(item):
print(f"⚠️ 跳过不存在:{item}")
continue
# 递归打包文件夹
if os.path.isdir(item):
for root, dirs, files_in_dir in os.walk(item):
for f in files_in_dir:
file_path = os.path.join(root, f)
arc_path = os.path.relpath(file_path, project_root)
zipf.write(file_path, arc_path)
print(f"{arc_path}")
else:
zipf.write(item, item)
print(f"{item}")
def build_all(version):
"""
一次性构建 min + full 两个包
"""
project_root = get_project_root()
OUTPUT_DIR = os.path.join(project_root, "Release")
output_abs = os.path.abspath(OUTPUT_DIR)
# 创建输出目录
if not os.path.exists(output_abs):
os.makedirs(output_abs)
# 文件名
zip_min = os.path.join(output_abs, f"nicsensor-{version}-min.zip")
zip_full = os.path.join(output_abs, f"nicsensor-{version}-full.zip")
print("=" * 60)
print(" 开始自动打包")
print(f"版本号:{version}")
print(f"工程根目录:{project_root}")
print(f"输出目录:{output_abs}")
print("=" * 60)
# 打包最小版
print("\n📦 开始打包【最小版本】")
pack_files(zip_min, MIN_FILES, project_root)
# 打包完整版
print("\n📦 开始打包【完整工程】")
pack_files(zip_full, FULL_FILES, project_root)
print("\n✅ 全部打包完成!")
print(f"📍 最小包:{zip_min}")
print(f"📍 完整包:{zip_full}")
print("=" * 60)
def show_usage():
print("=" * 50)
print(" Nicsensor 一键打包脚本")
print("=" * 50)
print("使用方法:")
print(" python pack.py 版本号")
print()
print("示例:")
print(" python pack.py v1.0.0")
print(" python pack.py 2.5.0")
print("=" * 50)
if __name__ == "__main__":
if len(sys.argv) != 2:
show_usage()
sys.exit(1)
version = sys.argv[1]
build_all(version)

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
script_version="v2.0" script_version="v2.0"
server_type="5688m7" default_server_type="5688m7"
server_platform="m7" server_platform="m7"
slot_name=$1 slot_name=$1
@ -11,12 +11,46 @@ param_num=$#
nic_type="" nic_type=""
slot_id="" slot_id=""
server_type=""
path=`pwd`
server_script=""
sensor_script=""
i2c_script="${path}/i2c_${server_platform}.sh"
fmt_print="${path}/format_print.sh"
# According to boardid, parse server_type
# Only valid on Gen 7 series
try_get_server_type(){
if [ -e "/tmp/ns_servertype" ];then
server_type=`cat /tmp/ns_servertype`
else
boardid=`cat /proc/cmdline | awk -F 'boardid=' '{split($2, a," "); print a[1]}'`
if [ "$boardid" = "" ];then
server_type=$default_server_type
return
fi
if [ $boardid -eq 130 ];then
server_type="5280m7"
elif [ $boardid -eq 150 ];then
server_type="5468m7"
elif [ $boardid -eq 152 ];then
server_type="5688m7"
else
server_type=$default_server_type
exit 1
fi
echo $server_type > /tmp/ns_servertype
fi
}
script_info_load(){
path=`pwd` path=`pwd`
server_script="${path}/platform_${server_type}.sh" server_script="${path}/platform_${server_type}.sh"
sensor_script="${path}/plugin_${sensor_type}.sh" sensor_script="${path}/plugin_${sensor_type}.sh"
i2c_script="${path}/i2c_${server_platform}.sh" }
fmt_print="${path}/format_print.sh"
print_helper(){ print_helper(){
echo "======>>> nicsensor Scirpt Usage <<<======" echo "======>>> nicsensor Scirpt Usage <<<======"
@ -52,10 +86,13 @@ conf_pre_check(){
exit 1 exit 1
fi fi
# If action is detect , skip this check
if [ $param_num -gt 3 ];then
if [ ! -e $sensor_script ];then if [ ! -e $sensor_script ];then
$fmt_print "console" "Error" "Sensor Script $sensor_script not exist! Maybe unsupport for now!" $fmt_print "console" "Error" "Sensor Script $sensor_script not exist! Maybe unsupport for now!"
exit 1 exit 1
fi fi
fi
if [ ! -e $i2c_script ];then if [ ! -e $i2c_script ];then
$fmt_print "console" "Error" "$i2c_script not exist!" $fmt_print "console" "Error" "$i2c_script not exist!"
@ -100,15 +137,22 @@ connect_i2c(){
start_sensor_reading(){ start_sensor_reading(){
$fmt_print "log" "Info" "start sensor reading" $fmt_print "log" "Info" "start sensor reading"
$sensor_script "read" "${i2c_bus}" "${chip_slave}" "${server_platform}" $sensor_script "read" "${i2c_bus}" "${chip_slave}" "${server_platform}" "${server_type}"
} }
# ---------------------------------------------------------
# Start Execute Script pre_exec_hook(){
# ---------------------------------------------------------
# init debug log # init debug log
if [ -e "/tmp/nicsensor_debug.log" ];then if [ -e "/tmp/nicsensor_debug.log" ];then
rm /tmp/nicsensor_debug.log rm /tmp/nicsensor_debug.log
fi fi
try_get_server_type
script_info_load
conf_pre_check
}
# ---------------------------------------------------------
# Start Execute Script
# ---------------------------------------------------------
pre_exec_hook
# check if is detect option # check if is detect option
if [ "$1" = "detect" ];then if [ "$1" = "detect" ];then
@ -116,8 +160,6 @@ if [ "$1" = "detect" ];then
exit 0 exit 0
fi fi
conf_pre_check
parse_slot_name parse_slot_name
i2c_bus=`connect_i2c` i2c_bus=`connect_i2c`

@ -4,6 +4,9 @@ action=$1
nic_type=$2 nic_type=$2
slot_id=$3 slot_id=$3
# Param: i2c_command only valid for function 'send'
i2c_command=$4
path=`pwd` path=`pwd`
i2c_script="${path}/i2c_m7.sh" i2c_script="${path}/i2c_m7.sh"
fmt_print="${path}/format_print.sh" fmt_print="${path}/format_print.sh"
@ -125,9 +128,9 @@ build_i2c_connect(){
# @Param5 pcie slot number # @Param5 pcie slot number
do_i2c_detect(){ do_i2c_detect(){
if [ "${nic_type}" == "ocp" ];then if [ "${nic_type}" == "ocp" ];then
$fmt_print "log" "Info" "OCP slot $5 : bus$1 9548channel$4" $fmt_print "console" "Info" "OCP slot $5 : bus$1 9548channel$4"
else else
$fmt_print "log" "Info" "PCIe slot $5 : bus$1 9548channel$4" $fmt_print "console" "Info" "PCIe slot $5 : bus$1 9548channel$4"
fi fi
i2ctransfer -y $1 w1@$2 $3 i2ctransfer -y $1 w1@$2 $3
i2cdetect -y $1 i2cdetect -y $1
@ -141,6 +144,7 @@ detect_on_server(){
do_i2c_detect 3 0x70 0x01 0 0 do_i2c_detect 3 0x70 0x01 0 0
do_i2c_detect 3 0x70 0x02 1 1 do_i2c_detect 3 0x70 0x02 1 1
do_i2c_detect 3 0x70 0x04 2 2 do_i2c_detect 3 0x70 0x04 2 2
i2ctransfer -y 3 w1@0x70 0x00
else else
i2c_bus=12 i2c_bus=12
pca9641_slave="0x41" pca9641_slave="0x41"
@ -149,6 +153,7 @@ detect_on_server(){
do_i2c_detect 12 0x72 0x02 1 0 do_i2c_detect 12 0x72 0x02 1 0
do_i2c_detect 12 0x72 0x04 2 1 do_i2c_detect 12 0x72 0x04 2 1
do_i2c_detect 12 0x72 0x08 3 2 do_i2c_detect 12 0x72 0x08 3 2
i2ctransfer -y 12 w1@0x72 0x00
i2c_bus=13 i2c_bus=13
pca9641_slave="0x42" pca9641_slave="0x42"
@ -157,9 +162,26 @@ detect_on_server(){
do_i2c_detect 13 0x72 0x02 1 3 do_i2c_detect 13 0x72 0x02 1 3
do_i2c_detect 13 0x72 0x04 2 4 do_i2c_detect 13 0x72 0x04 2 4
do_i2c_detect 13 0x72 0x08 3 5 do_i2c_detect 13 0x72 0x08 3 5
i2ctransfer -y 13 w1@0x72 0x00
fi fi
} }
reset_all_pca9548(){
$fmt_print "log" "Info" "[platform_5280m7] Bypass reset pca9548"
}
send_i2c_command(){
$fmt_print "log" "Info" "[platform_5280m7] Send an i2c command"
set_i2c_config
if [ $is_have_pca9641 -eq 1 ];then
get_pca9641_control
fi
select_pca9548_channel
$i2c_command
}
# --------------------------------------------------- # ---------------------------------------------------
# Start Execute Script # Start Execute Script
# --------------------------------------------------- # ---------------------------------------------------
@ -170,6 +192,12 @@ case "${action}" in
"detect") "detect")
detect_on_server detect_on_server
;; ;;
"reset")
reset_all_pca9548
;;
"send")
send_i2c_command
;;
*) *)
$fmt_print "console" "Error" "[platform_5280m7] Unspecified Operation : $action" $fmt_print "console" "Error" "[platform_5280m7] Unspecified Operation : $action"
exit 1 exit 1

@ -4,6 +4,9 @@ action=$1
nic_type=$2 nic_type=$2
slot_id=$3 slot_id=$3
# Param: i2c_command only valid for function 'send'
i2c_command=$4
path=`pwd` path=`pwd`
i2c_script="${path}/i2c_m7.sh" i2c_script="${path}/i2c_m7.sh"
fmt_print="${path}/format_print.sh" fmt_print="${path}/format_print.sh"
@ -141,13 +144,33 @@ detect_on_server(){
do_i2c_detect $i2c_bus 0x71 0x02 1 1 do_i2c_detect $i2c_bus 0x71 0x02 1 1
do_i2c_detect $i2c_bus 0x71 0x04 2 2 do_i2c_detect $i2c_bus 0x71 0x04 2 2
do_i2c_detect $i2c_bus 0x71 0x08 3 3 do_i2c_detect $i2c_bus 0x71 0x08 3 3
i2ctransfer -y $i2c_bus w1@0x71 0x00
do_i2c_detect $i2c_bus 0x72 0x01 0 4 do_i2c_detect $i2c_bus 0x72 0x01 0 4
do_i2c_detect $i2c_bus 0x72 0x02 1 5 do_i2c_detect $i2c_bus 0x72 0x02 1 5
do_i2c_detect $i2c_bus 0x72 0x04 2 6 do_i2c_detect $i2c_bus 0x72 0x04 2 6
do_i2c_detect $i2c_bus 0x72 0x08 3 7 do_i2c_detect $i2c_bus 0x72 0x08 3 7
i2ctransfer -y $i2c_bus w1@0x72 0x00
fi fi
} }
reset_all_pca9548(){
i2ctransfer -y 12 w1@0x71 0x00
i2ctransfer -y 12 w1@0x72 0x00
}
send_i2c_command(){
$fmt_print "log" "Info" "[platform_5280m7] Send an i2c command"
set_i2c_config
if [ $is_have_pca9641 -eq 1 ];then
get_pca9641_control
fi
select_pca9548_channel
$i2c_command
}
# --------------------------------------------------- # ---------------------------------------------------
# Start Execute Script # Start Execute Script
# --------------------------------------------------- # ---------------------------------------------------
@ -158,6 +181,12 @@ case "${action}" in
"detect") "detect")
detect_on_server detect_on_server
;; ;;
"reset")
reset_all_pca9548
;;
"send")
send_i2c_command
;;
*) *)
$fmt_print "console" "Error" "[platform_5688m7] Unspecified Operation : $action" $fmt_print "console" "Error" "[platform_5688m7] Unspecified Operation : $action"
exit 1 exit 1

@ -24,6 +24,7 @@ mode=$1
i2c_bus=$2 i2c_bus=$2
chip_slave=$3 chip_slave=$3
server_platform=$4 server_platform=$4
server_type=$5
# Only for test purpose # Only for test purpose
test_data1=$2 test_data1=$2
@ -33,6 +34,7 @@ test_factor=$4
path=`pwd` path=`pwd`
fmt_print="${path}/format_print.sh" fmt_print="${path}/format_print.sh"
i2c_script="${path}/i2c_${server_platform}.sh" i2c_script="${path}/i2c_${server_platform}.sh"
server_script="${path}/platform_${server_type}.sh"
REG_adc128_config="0x00" REG_adc128_config="0x00"
REG_adc128_advance="0x0b" REG_adc128_advance="0x0b"
@ -87,6 +89,10 @@ check_adc128_init(){
# @Param 3 customization channel name # @Param 3 customization channel name
# @Param 4 division factor # @Param 4 division factor
convert_adc128_data(){ convert_adc128_data(){
if [ "$3" = "disable" ];then
return
fi
# remove data prefix '0x' # remove data prefix '0x'
hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}') hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}')
hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}') hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}')
@ -124,6 +130,9 @@ read_adc128_data(){
res_ch6=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch6 2` res_ch6=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch6 2`
res_ch7=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch7 2` res_ch7=`$i2c_script $i2c_bus 1 $chip_slave $REG_adc128_ch7 2`
# After read option , reset pca9548
$server_script reset
# record i2c raw data to log # record i2c raw data to log
$fmt_print "log" "Info" "[plugin_adc128] channel0 : $res_ch0" $fmt_print "log" "Info" "[plugin_adc128] channel0 : $res_ch0"
$fmt_print "log" "Info" "[plugin_adc128] channel1 : $res_ch1" $fmt_print "log" "Info" "[plugin_adc128] channel1 : $res_ch1"

@ -4,6 +4,7 @@ mode=$1
i2c_bus=$2 i2c_bus=$2
chip_slave=$3 chip_slave=$3
server_platform=$4 server_platform=$4
server_type=$5
test_data1=$2 test_data1=$2
test_data2=$3 test_data2=$3
@ -11,6 +12,7 @@ test_data2=$3
path=`pwd` path=`pwd`
fmt_print="${path}/format_print.sh" fmt_print="${path}/format_print.sh"
i2c_script="${path}/i2c_${server_platform}.sh" i2c_script="${path}/i2c_${server_platform}.sh"
server_script="${path}/platform_${server_type}.sh"
# EMC1413 channel name # EMC1413 channel name
EMC1413_Channel0_name="Channel0" EMC1413_Channel0_name="Channel0"
@ -44,6 +46,10 @@ print_help(){
# @Param2 emc1413 data low 8bit # @Param2 emc1413 data low 8bit
# @Param3 customization channel name # @Param3 customization channel name
convert_emc1413_data(){ convert_emc1413_data(){
if [ "$3" = "disable" ];then
return
fi
# remove data prefix '0x' # remove data prefix '0x'
hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}') hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}')
hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}') hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}')
@ -90,6 +96,9 @@ read_emc1413_data(){
res_td3_h=`$i2c_script $i2c_bus 1 $chip_slave $REG_emc1413_TD3_H 1` res_td3_h=`$i2c_script $i2c_bus 1 $chip_slave $REG_emc1413_TD3_H 1`
res_td3_l=`$i2c_script $i2c_bus 1 $chip_slave $REG_emc1413_TD3_L 1` res_td3_l=`$i2c_script $i2c_bus 1 $chip_slave $REG_emc1413_TD3_L 1`
# After read option , reset pca9548
$server_script reset
$fmt_print "log" "Info" "[plugin_emc1413] TD1 : $res_td1_h $res_td1_l" $fmt_print "log" "Info" "[plugin_emc1413] TD1 : $res_td1_h $res_td1_l"
$fmt_print "log" "Info" "[plugin_emc1413] TD2 : $res_td2_h $res_td2_l" $fmt_print "log" "Info" "[plugin_emc1413] TD2 : $res_td2_h $res_td2_l"
$fmt_print "log" "Info" "[plugin_emc1413] TD3 : $res_td3_h $res_td3_l" $fmt_print "log" "Info" "[plugin_emc1413] TD3 : $res_td3_h $res_td3_l"

@ -4,6 +4,7 @@ mode=$1
i2c_bus=$2 i2c_bus=$2
chip_slave=$3 chip_slave=$3
server_platform=$4 server_platform=$4
server_type=$5
test_data1=$2 test_data1=$2
test_data2=$3 test_data2=$3
@ -12,6 +13,7 @@ test_resistor=$4
path=`pwd` path=`pwd`
fmt_print="${path}/format_print.sh" fmt_print="${path}/format_print.sh"
i2c_script="${path}/i2c_${server_platform}.sh" i2c_script="${path}/i2c_${server_platform}.sh"
server_script="${path}/platform_${server_type}.sh"
# INA3221 shunt resistor(unit: mohm) # INA3221 shunt resistor(unit: mohm)
shunt_resistor_0="2" shunt_resistor_0="2"
@ -66,6 +68,10 @@ print_help(){
# @Param6 customization channel name # @Param6 customization channel name
convert_ina3221_data(){ convert_ina3221_data(){
if [ "$6" = "disable" ];then
return
fi
hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}') hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}')
hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}') hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}')
merge_value="${hex_value1}${hex_value2}" merge_value="${hex_value1}${hex_value2}"
@ -134,12 +140,15 @@ convert_ina3221_data(){
} }
read_ina3221_data(){ read_ina3221_data(){
res_ch0=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_ch1 r2` res_ch0=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_ch1 2`
res_ch1=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_ch2 r2` res_ch1=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_ch2 2`
res_ch2=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_ch3 r2` res_ch2=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_ch3 2`
res_bus0=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_bus1 r2` res_bus0=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_bus1 2`
res_bus1=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_bus2 r2` res_bus1=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_bus2 2`
res_bus2=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_bus3 r2` res_bus2=`$i2c_script $i2c_bus 1 $chip_slave $REG_ina3221_bus3 2`
# After read option , reset pca9548
$server_script reset
$fmt_print "log" "Info" "[plugin_ina3221] channel 0 shunt volt: $res_ch0" $fmt_print "log" "Info" "[plugin_ina3221] channel 0 shunt volt: $res_ch0"
$fmt_print "log" "Info" "[plugin_ina3221] channel 1 shunt volt: $res_ch1" $fmt_print "log" "Info" "[plugin_ina3221] channel 1 shunt volt: $res_ch1"

@ -4,6 +4,7 @@ mode=$1
i2c_bus=$2 i2c_bus=$2
chip_slave=$3 chip_slave=$3
server_platform=$4 server_platform=$4
server_type=$5
test_data1=$2 test_data1=$2
test_data2=$3 test_data2=$3
@ -11,6 +12,7 @@ test_data2=$3
path=`pwd` path=`pwd`
fmt_print="${path}/format_print.sh" fmt_print="${path}/format_print.sh"
i2c_script="${path}/i2c_${server_platform}.sh" i2c_script="${path}/i2c_${server_platform}.sh"
server_script="${path}/platform_${server_type}.sh"
sensor_name="TMP112" sensor_name="TMP112"
@ -34,6 +36,10 @@ print_help(){
# @Param2 tmp112 data low 8bit # @Param2 tmp112 data low 8bit
# @Param3 customization sensor name # @Param3 customization sensor name
convert_tmp112_data(){ convert_tmp112_data(){
if [ "$3" = "disable" ];then
return
fi
hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}') hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}')
hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}') hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}')
merge_value="${hex_value1}${hex_value2}" merge_value="${hex_value1}${hex_value2}"
@ -70,6 +76,10 @@ convert_tmp112_data(){
read_tmp112_data(){ read_tmp112_data(){
res=`$i2c_script $i2c_bus "1" "$chip_slave" "0x00" "2"` res=`$i2c_script $i2c_bus "1" "$chip_slave" "0x00" "2"`
# After read option , reset pca9548
$server_script reset
convert_tmp112_data $res "$sensor_name" convert_tmp112_data $res "$sensor_name"
} }

@ -4,6 +4,7 @@ mode=$1
i2c_bus=$2 i2c_bus=$2
chip_slave=$3 chip_slave=$3
server_platform=$4 server_platform=$4
server_type=$5
test_data1=$2 test_data1=$2
test_data2=$3 test_data2=$3
@ -11,6 +12,7 @@ test_data2=$3
path=`pwd` path=`pwd`
fmt_print="${path}/format_print.sh" fmt_print="${path}/format_print.sh"
i2c_script="${path}/i2c_${server_platform}.sh" i2c_script="${path}/i2c_${server_platform}.sh"
server_script="${path}/platform_${server_type}.sh"
REG_tmp468="0x80" REG_tmp468="0x80"
# TMP468 channel name # TMP468 channel name
@ -45,6 +47,10 @@ print_help(){
# @Param2 tmp468 data high 8bit # @Param2 tmp468 data high 8bit
# @Param3 customization channel name # @Param3 customization channel name
convert_tmp468_data(){ convert_tmp468_data(){
if [ "$3" = "disable" ];then
return
fi
hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}') hex_value1=$(echo "$1" | awk '{sub(/^0x/,""); print}')
hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}') hex_value2=$(echo "$2" | awk '{sub(/^0x/,""); print}')
merge_value="${hex_value1}${hex_value2}" merge_value="${hex_value1}${hex_value2}"
@ -70,6 +76,9 @@ convert_tmp468_data(){
read_tmp468_data(){ read_tmp468_data(){
res_tmp468=`$i2c_script $i2c_bus 1 $chip_slave $REG_tmp468 18` res_tmp468=`$i2c_script $i2c_bus 1 $chip_slave $REG_tmp468 18`
# After read option , reset pca9548
$server_script reset
$fmt_print "log" "Info" "[plugin_tmp468] Read Raw Data : $res_tmp468" $fmt_print "log" "Info" "[plugin_tmp468] Read Raw Data : $res_tmp468"
tmp468_res1_h=`echo $res_tmp468 | awk '{print $1}'` tmp468_res1_h=`echo $res_tmp468 | awk '{print $1}'`

@ -0,0 +1,45 @@
#!/bin/sh
# 20250627
# A tool script to test a value greater or less than threhold
data=$1
direction=$2
threhold=$3
param_num=$#
print_usage(){
echo " Script Usage"
echo " ./check_threhold.sh <value> <direction> <threhold>"
echo " @Param direction : greater , >"
echo " less , <"
echo " equal , ="
echo ""
echo " E.G. ./check_threhold.sh 500 > 1000"
echo " +--> Result : 0"
echo ""
echo " About Result: 1 means true, 0 means fault"
echo ""
}
main(){
if [ ${param_num} -ne 3 ];then
print_usage
exit 0
fi
if [ "${direction}" = "great" ] || [ "${direction}" = ">" ];then
res= `echo " $data > $threhold" | bc -l`
elif [ "${direction}" = "less" ] || [ "${direction}" = "<" ];then
res= `echo " $data < $threhold" | bc -l`
elif [ "${direction}" = "equal" ] || [ "${direction}" = "=" ];then
res= `echo " $data = $threhold" | bc -l`
else
echo "Invalid direction"
print_usage
fi
echo $res
}
main

19
tool/test/readme.md Normal file

@ -0,0 +1,19 @@
# 测试治具说明
> [!info]
> nicsensor提供了一部分测试治具脚本用于辅助编写测试脚本
## 阈值校验脚本-check_threhold.sh
阈值校验脚本提供了判断数值是否大于目标阈值的方法, 可进行整数和小数的比较。使用方法如下:
```shell
# 测试数据大于阈值
# 例如测试数据是否大于100有如下使用方法
res=`./check_threhold.sh ${data} > 100`
if [ $res -eq 1 ];then
echo "data is greater than threholds"
else
echo "data isn't greater than threholds"
fi
```