21/11/2010, 16:49:05
Bon, mais personne se moque, j'avais prévu de l'optimiser
#!/bin/sh
var=`exec /opt/owfs/bin/owread /1F.156C08000000/main/10.A5A3B5010800/
temperature | tr -d " "`
#var=-22.06
nb=0
var=$(echo "$var*100/1" |bc) #/1 pour suppression de la virgule
if [ $var -gt 0 ]
then
while [ $var -gt 2047 ]
do
nb=$nb+1
var=$(echo "$var/2" |bc)
done
nb=$(echo "$nb*2048" |bc)
var=$(echo "ibase=10;obase=16;$var+$nb"|bc)
elif [ $var -lt 0 ]
then
var=$(echo "$var*-1" |bc) #*1 pour revenir en positif
while [ $var -gt 2047 ]
do
nb=$nb+1
var=$(echo "$var/2" |bc)
done
nb=$(echo "$nb*2048" |bc)
echo $var
var=$(echo "ibase=10;obase=16;4096-$var+$nb+32768-2048"|bc)
fi
#verification si 4 caract
if [ ${#var} = 1 ]
then
var="00 0${var}"
elif [ ${#var} = 2 ]
then
var="00 ${var}"
elif [ ${#var} = 3 ]
then
var="0${var}"
var1=`expr substr $var 1 2`
var2=`expr substr $var 3 2`
var="${var1} ${var2}"
elif [ ${#var} = 4 ]
then
var1=`expr substr $var 1 2`
var2=`expr substr $var 3 2`
var="${var1} ${var2}"
fi
exec /usr/local/bin/groupwrite ip:192.168.5.5 9/5/3 $var
#!/bin/sh
var=`exec /opt/owfs/bin/owread /1F.156C08000000/main/10.A5A3B5010800/
temperature | tr -d " "`
#var=-22.06
nb=0
var=$(echo "$var*100/1" |bc) #/1 pour suppression de la virgule
if [ $var -gt 0 ]
then
while [ $var -gt 2047 ]
do
nb=$nb+1
var=$(echo "$var/2" |bc)
done
nb=$(echo "$nb*2048" |bc)
var=$(echo "ibase=10;obase=16;$var+$nb"|bc)
elif [ $var -lt 0 ]
then
var=$(echo "$var*-1" |bc) #*1 pour revenir en positif
while [ $var -gt 2047 ]
do
nb=$nb+1
var=$(echo "$var/2" |bc)
done
nb=$(echo "$nb*2048" |bc)
echo $var
var=$(echo "ibase=10;obase=16;4096-$var+$nb+32768-2048"|bc)
fi
#verification si 4 caract
if [ ${#var} = 1 ]
then
var="00 0${var}"
elif [ ${#var} = 2 ]
then
var="00 ${var}"
elif [ ${#var} = 3 ]
then
var="0${var}"
var1=`expr substr $var 1 2`
var2=`expr substr $var 3 2`
var="${var1} ${var2}"
elif [ ${#var} = 4 ]
then
var1=`expr substr $var 1 2`
var2=`expr substr $var 3 2`
var="${var1} ${var2}"
fi
exec /usr/local/bin/groupwrite ip:192.168.5.5 9/5/3 $var