Note2MPS/PXE/ADS/INA电流电压,i2c设备在位和读,samba/nfs,ntp/log/me/树莓派,pip/office,vr,i2ctool,大数据,pam

Posted 码农编程录

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Note2MPS/PXE/ADS/INA电流电压,i2c设备在位和读,samba/nfs,ntp/log/me/树莓派,pip/office,vr,i2ctool,大数据,pam相关的知识,希望对你有一定的参考价值。

文章目录


1.读MPS5023芯片:0x03ff即将前6位屏蔽

# Read_FPGA_Power.sh  
#!/bin/bash
stop_ipmistack()

    cnt=0
    while true
    do
        /etc/init.d/ipmistack stop >/dev/null  2>&1
        s1=$(ps aux)
        s2="/usr/local/bin/IPMIMain"
        result=$(echo $s1 | grep "$s2")
        if [[ "$result" == "" ]]
        then
            break
        fi
        if [ $cnt -eq 5 ]
        then
           echo "Unable to stop ipmistack !"
           exit 1
        fi
        cnt=$(($cnt+1))
        sleep 10
    done


delete()

    cnt=0
    while true
    do
        echo 0x73 > /sys/bus/i2c/devices/i2c-7/delete_device #将bus7上0x73这设备删除
        if [ $? = 0 ]
        then
            break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to delete device  !"
          exit 1
        fi
        cnt=$(($cnt+1))
    done


access()

    cnt=0
    while true
    do
        i2c-test -b 7 -s 0x73 -w -d 0x08 >/dev/null 2>&1
        if [ $? = 0 ]
        then
            break
        fi
        if [ $cnt -eq 5 ]
        then
          echo $cnt
          echo "Unable to access 9545 !"
          exit 1
        fi
        cnt=$(($cnt+1))
        echo $cnt
    done


OpenChannel()

    cnt=0
    while true
    do
        i2c-test -b 7 -s 0x71 -w -d 0x80 >/dev/null 2>&1   #0x80打开channel8
        if [ $? = 0 ]
        then
            break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to access 9548 channel8 !"
          exit 1
        fi
        cnt=$(($cnt+1))
    done


read_voltage()
    cnt=0
    while true
    do
        val_v=$(i2c-test -b 7 -s 0x40 -m 1 -rc 2 -d 0x8b)
        if [ $? = 0 ]
        then
        hexval_v_h=$val_v:14:2
        hexval_v_l=$val_v:17:2
        hexval_v=$hexval_v_l$hexval_v_h
        #echo $hexval_v  #0183

        dec_v=$((0x$hexval_v & 0x3ff))  #&:有0为0,3ff:10个1, hex->dec
        #echo $dec_v  #388
        dec_v_wv=$((dec_v*3125))  #31.25mV/LSB
        dec_v_v=$((dec_v_wv/100000))
        #echo $dec_v_v   #12
              break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to read voltage !"
          exit 1
        fi
        cnt=$(($cnt+1))
    done


read_power()
    cnt=0
    while true
    do
        val_a=$(i2c-test -b 7 -s 0x40 -m 1 -rc 2 -d 0x8c) #电流
        if [ $? = 0 ]
        then
        hexval_a_h=$val_a:14:2
        hexval_a_l=$val_a:17:2
        hexval_a=$hexval_a_l$hexval_a_h
        #echo $hexval_a  #0054

        dec_a=$((0x$hexval_a & 0x3ff))
        dec_a_wa=$((dec_a*6250))
        dec_a_a=$((dec_a_wa/100000))
		#echo $dec_a_a
        power=$(($dec_v_v * $dec_a_a))
        echo "FPGA Power : "$power"W"
              break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to read electricity !"
          exit 1
        fi
        cnt=$(($cnt+1))
    done


start_ipmistack()

    cnt=0
    while true
    do
        /etc/init.d/ipmistack start >/dev/null 2>&1
        s1=$(ps aux)
        s2="/usr/local/bin/IPMIMain"
        result=$(echo $s1 | grep "$s2")
        if [[ "$result" != "" ]]
        then
            break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to start ipmistack !"
          exit 1
        fi
        cnt=$(($cnt+1))
		    sleep 10
    done


start_ipmistack
stop_ipmistack
delete
access
OpenChannel
read_voltage
read_power
start_ipmistack

2.读PXE1410CDM电压和电流:一个数&0x7ff,将这个数前5位全变为0,其余位不变

ipmitool raw 0x3a 0x10 <bus id> <slave addr> <Read count> <Data to write> (00:第一个状态码不显示)

status , log_psu1 = run_command("sudo bash -c 'a=$(ipmitool raw 0x3a 0x10 14 0xb0 2 0x88) ; b=$a:1:2 ; c=$a:4:5 ; d=$c$b ; \\
    f=`../utility/diag-tools/pmbus_tool/line11 0x$d` ; echo $f'")  # psu1 输入电压
status , log_psu2 = run_command("sudo bash -c 'a=$(ipmitool raw 0x3a 0x10 15 0xb0 2 0x88) ; b=$a:1:2 ; c=$a:4:5 ; d=$c$b ; \\
    f=`../utility/diag-tools/pmbus_tool/line11 0x$d` ; echo $f'")  # psu2 输入电压


status , log_psu11 = run_command("sudo bash -c 'a=$(ipmitool raw 0x3a 0x10 14 0xb0 2 0x8b) ; b=$a:1:2 ; c=$a:4:5 ; d=$c$b ; \\
    f=`../utility/diag-tools/pmbus_tool/line16 0x$d` ; echo $f'")  # psu1 输出电压
status , log_psu22 = run_command("sudo bash -c 'a=$(ipmitool raw 0x3a 0x10 15 0xb0 2 0x8b) ; b=$a:1:2 ; c=$a:4:5 ; d=$c$b ; \\
    f=`../utility/diag-tools/pmbus_tool/line16 0x$d` ; echo $f'") # psu2 输出电压
输入电压(mv):
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x60 0x88 w
0xe9b6
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x61 0x88 w
0xe9b5
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x62 0x88 w
0xe9b6
root@gnr5713bb:/var/log/abak# ./line11_arm 0xe9b6
54750

输出电压(mv):
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x60 0x8b w
0xc2ad
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x61 0x8b w
0xc395
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x62 0x8b w
0xc0f8
VOUT_MODE:
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x60 0x20
0x14
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x61 0x20
0x14
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x62 0x20
0x14
root@gnr5713bb:/var/log/abak# ./line16_arm 0xc2ad 0x14
12167
root@gnr5713bb:/var/log/abak# ./line16_arm 0xc395 0x14
12223
root@gnr5713bb:/var/log/abak# ./line16_arm 0xc0f8 0x14
12060

2.1 1ine11


如下计算机以补码形式存放负数,0010+1=0011(十进制3)。

438乘2的-3次方 = 54.8(V)。

2.2 1ine16:一种方法

如下十六进制HEX c2ad ,49837乘2的-12次方 = 12.1(A)(不用0x20寄存器,0x14取反加1就是-12)。

2.3 1ine16:另一种方法

如下是0x20读出来是0x17的电源芯片:

如下取反加1后,十进制和十六进制都为9。



如下是c语言的线性转换,0x0184十六进制printf输出为十进制388。

//current.c  arm编译器arm-linux-gcc (不是x86的gcc)编译成current(电流)可执行文件, linear11
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char ** argv)

    short exponent;
    int mantissa;
    int val_x;

    mantissa = ((signed short)((strtoul(argv[1],0,0) & 0x7ff) << 5)) >> 5;
    // printf("%x\\n",mantissa);
    exponent = ((signed short)strtoul(argv[1],0,0))>>11;
    // printf("%d\\n",exponent);
    val_x = mantissa * 1000L;

    if (exponent >= 0)
        val_x <<= exponent;
    else
        val_x >>= -exponent;
   printf("%d\\n",val_x);
   return 0;

// linear16
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char ** argv)

    short exponent;
    int mantissa;
    int val_x;

    mantissa = (signed short)strtoul(argv[1],0,0);
    exponent = ((signed short)(0x17 << 11)) >> 11 ;

    val_x = mantissa * 1000L;
    if (exponent >= 0)
        val_x <<= exponent;
    else
        val_x >>= -exponent;
   printf("%d\\n",val_x);
   return 0;

linear16_convert()

    mantissa=$(printf %d "$1") # 有符号,也需像上面一样判断
    if [ $((($2 >> 4) & 0x1)) == 1 ] ; then
        exponent=$(((((($2 << 11)) >> 11)) & 0xf))
        exponent=$(($exponent ^ 0xf))
        exponent=$((~$exponent))
    else
        exponent=$(printf %d "$2")
    fi
    val_x=$((mantissa * 1000))
    if [ $exponent -ge 0 ]; then
        val_x=$(($val_x<<$exponent))
    else
        val_x=$(($val_x>>$((-$exponent))))
    fi
    echo $val_x

i2ctransfer -f -y $bus w1@$address $BLACKBOX_ADDRESS r51  # 读出的第一个byte是字节数即0x33即51字节

# Read_PXE1410CDM_0X62_Voltage_Current.sh
#!/bin/bash

write_ch0()

    cnt=0
    while true
    do
        i2c-test -b 7 -s 0x60 -w -d 0x0 0x00 >/dev/null 2>&1
        if [ $? = 0 ]
        then
            break
		    fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to write PXE CH0!"
          exit 1
        fi
        cnt=$(($cnt+1))
    done


read_ch0_voltage()
    cnt=0
    while true
    do
        val_v_0=$(i2c-test -b 7 -s 0x60 -m 1 -rc 2 -d 0x8b)
        if [ $? = 0 ]
        then
        hex_v_h_0=$val_v_0:14:2
        hex_v_l_0=$val_v_0:17:2
        hex_v_0=$hex_v_l_0$hex_v_h_0
        dec_v_0=$((0x$hex_v_0 & 0xff))
        #echo $dec_v_0
        dec_v_0=$(((500 + (dec_v_0 - 1) * 10)/2))
        echo  "PXE_0x60_0_P0V9_VCCH Voltage : "$dec_v_0"mV"
              break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to read ch0 voltage !"
          exit 1
        fi
        cnt=$(($cnt+1))
    done


read_ch0_current()
    cnt=0
    while true
    do
        val_a_0=$(i2c-test -b 7 -s 0x60 -m 1 -rc 2 -d 0x8c)
        if [ $? = 0 ]
        then
        hex_a_h_0=$val_a_0:14:2
        hex_a_l_0=$val_a_0:17:2
        hex_a_0=$hex_a_l_0$hex_a_h_0
        dec_a_0=$(./current 0x$hex_a_0)
        echo  "PXE_0x60_0 Current : "$dec_a_0"mA"
              break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to read ch0 current !"
          exit 1
        以上是关于Note2MPS/PXE/ADS/INA电流电压,i2c设备在位和读,samba/nfs,ntp/log/me/树莓派,pip/office,vr,i2ctool,大数据,pam的主要内容,如果未能解决你的问题,请参考以下文章

电流电压功率的计算方式

微弱直流电压/电流信号的采样电路

大功率和小功率LED的驱动电压和驱动电流各是 多少

怎样通过PLC采集交流电压的电流信号和电压信号?

MOS管该如何精准控制电流?

单片机怎样对交流电压电流取样