Notes15INA220,PXE1410CDM

Posted 码农编程录

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Notes15INA220,PXE1410CDM相关的知识,希望对你有一定的参考价值。


1.读INA220电压和电流

# Read_INA220_Voltage_Current.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-3/delete_device
        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 3 -s 0x73 -w -d 0x08 >/dev/null 2>&1
        if [ $? = 0 ]
        then
            break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to access 9545 !"
          exit 1
        fi
        cnt=$(($cnt+1))
        echo $cnt
    done
}

OpenChannel()
{
    cnt=0
    while true
    do
        i2c-test -b 3 -s 0x71 -w -d 0x02 >/dev/null 2>&1
        if [ $? = 0 ]
        then
            break
		    fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to access 9548 channel2 !"
          exit 1
        fi
        cnt=$(($cnt+1))
    done
}

read_voltage(){
    cnt=0
    while true
    do
        val_v=$(i2c-test -b 3 -s 0x41 -m 1 -rc 2 -d 0x02)
        if [ $? = 0 ]
        then
        #echo $val_v  #08 aa
        hexval_v_h=${val_v:14:2}
        hexval_v_l=${val_v:17:2}
        hexval_v=${hexval_v_h}${hexval_v_l}
        dec_v_v=$((0x$hexval_v>>3))
        dec_v_v=$(($dec_v_v<<2))
        echo "INA220 Voltage : "$dec_v_v"mV"
              break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to read INA220 voltage !"
          exit 1
        fi
        cnt=$(($cnt+1))
    done
}

DIV_ROUND_CLOSEST(){
    if [ $# -ne 2 ]
    then
    echo 0
    else
    __x=$1
    __d=$2
    A=$(((__x) > 0))
    B=$(((__d) > 0))
    C=$(($__d>>1))
    C=$(($__x+$C))
    C=$(($C/$__d))
    D=$(($__d>>1))
    D=$(($__x+$D))
    D=$(($D/$__d))
    E=$(($A==$B))
    echo $(($E?$C:$D))
    fi
}

Read_Reg()
{
    val=$(i2c-test -b 3 -s 0x41 -m 1 -rc 2 -d $1)
    val_h=${val:14:2}
    val_l=${val:17:2}
    val=${val_h}${val_l}
     echo $val
}

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

i2c-test -b 3 -s 0x41 -w -d 0x05 0x03 0x7f >/dev/null 2>&1
config_shunt_div=100
dividend=$(DIV_ROUND_CLOSEST 1000000000 $config_shunt_div)
shunt_val=$(Read_Reg 0x01)
#echo "shunt_val" $shunt_val
current_lsb_uA=$(DIV_ROUND_CLOSEST $dividend 0x$shunt_val)
#echo "current_lsb_uA" $current_lsb_uA

current_val=$(Read_Reg 0x04)
#echo "current_val" $current_val
ret=$((0x$current_val * $current_lsb_uA))
#echo $ret
ret=$(DIV_ROUND_CLOSEST $ret 1000)
echo "INA220 Current : "$ret"mA"
start_ipmistack

2.读PXE1410CDM电压和电流

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

如下用arm编译器(不是x86的gcc)编译成current可执行文件。

//current.c
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char ** argv)
{
    short exponent;
    int mantissa;
    int val_x;

    mantissa = (((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;
}
# Read_PXE1410CDM_0X62_Voltage_Current.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
        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
        if [ $? = 0 ]
        then
            break
	    	fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to access 9548 channel2 !"
          exit 1
        fi
        cnt=$(($cnt+1))
    done
}

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
        fi
        cnt=$(($cnt+1))
    done
}

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

read_ch1_voltage(){
    cnt=0
    while true
    do
        val_v_1=$(i2c-test -b 7 -s 0x60 -m 1 -rc 2 -d 0x8b)
        if [ $? = 0 ]
        then
        hex_v_1_h=${val_v_1:14:2}
        hex_v_1_l=${val_v_1:17:2}
        hex_v_1=${hex_v_1_l}${hex_v_1_h}
        dec_v_1=$((0x$hex_v_1 & 0xff))
        dec_v_1=$(((500 + (dec_v_1 - 1) * 10)/2))
        echo  "PXE_0x60_1_P1V2_VDDQ_CH01 Voltage : "$dec_v_1"mV"
              break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to read ch1 voltage !"
          exit 1
        fi 
        cnt=$(($cnt+1))
    done
}

read_ch1_current(){
    cnt=0
    while true
    do
        val_a_1=$(i2c-test -b 7 -s 0x60 -m 1 -rc 2 -d 0x8c)
        if [ $? = 0 ]
        then
        hex_a_1_h=${val_a_1:14:2}
        hex_a_1_l=${val_a_1:17:2}
        hex_a_1=${hex_a_1_l}${hex_a_1_h}
        dec_a_1=$(./current 0x$hex_a_1)
        echo  "PXE_0x60_1 Current : "$dec_a_1"mA"
              break
        fi
        if [ $cnt -eq 5 ]
        then
          echo "Unable to read ch1 current !"
          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
write_ch0
read_ch0_voltage
read_ch0_current
write_ch1
read_ch1_voltage
read_ch1_current
start_ipmistack

以上是关于Notes15INA220,PXE1410CDM的主要内容,如果未能解决你的问题,请参考以下文章

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

Linux centos PXE无人值守安装 DHCP+TFTP+HTTPD+Kickstart

Linux centos PXE无人值守安装 DHCP+TFTP+FTP+Kickstart

powerdesigner关联的线怎么画

如何在PowerDesigner中画ER图

powerdesigner 实体关系模型CDM与物理数据模型PDM互转