#!/bin/sh
#------------------------------------------------------------------------------
# OPT_EMBEDDED  /etc/rrdtool/fscpc.val                             __FLI4LVER__
# Creation:     2005-12-23 gdw
# Last Update:  $Id$
# 
# rrdtool x7sla Datenerfassung
#------------------------------------------------------------------------------

[ -z "$RDTOOL_CONF_LOADED" ] && . /var/run/rrdtool.conf

local source=x7sla
eval local idx='$RRDTOOL_'$source'_ID'
eval local options='$RRDTOOL_'$idx'_OPTIONS_STRING'

#  Pfad bei 2.6er Kernel
x7sla_io_path='/sys/devices/platform/w83627ehf.656'

for item in $options
do
    local db_file=$RRDTOOL_DB_PATH/$source/$item.rrd
    value="U"
    case "$item" in
    "temperature")
        [ -f $x7sla_io_path/temp1_input ]&&value1=`sed 's/\([0-9]\{3\}\)$/.\1/' $x7sla_io_path/temp1_input`
        [ -f $x7sla_io_path/temp2_input ]&&value2=`sed 's/\([0-9]\{3\}\)$/.\1/' $x7sla_io_path/temp2_input`
        rrdtool update $db_file \
        N:$value1:$value2
        ;;
    "voltage")
	[ -f $x7sla_io_path/in0_input ]&&value0=`sed 's/\([0-9]\{3\}\)$/.\1/' $x7sla_io_path/in0_input`
	[ -f $x7sla_io_path/in2_input ]&&value2=`sed 's/\([0-9]\{3\}\)$/.\1/' $x7sla_io_path/in2_input`
	[ -f $x7sla_io_path/in3_input ]&&value3=`sed 's/\([0-9]\{3\}\)$/.\1/' $x7sla_io_path/in3_input`
	[ -f $x7sla_io_path/in4_input ]&&value4=`sed 's/\([0-9]\{3\}\)$/.\1/' $x7sla_io_path/in4_input`
	[ -f $x7sla_io_path/in6_input ]&&value6=`sed 's/\([0-9]\{3\}\)$/.\1/' $x7sla_io_path/in6_input`
	[ -f $x7sla_io_path/in7_input ]&&value7=`sed 's/\([0-9]\{3\}\)$/.\1/' $x7sla_io_path/in7_input`
	[ -f $x7sla_io_path/in8_input ]&&value8=`sed 's/\([0-9]\{3\}\)$/.\1/' $x7sla_io_path/in8_input`

	if [ -f $x7sla_io_path/in1_input ]
	then
	  value1=`cat $x7sla_io_path/in1_input`
	  value1=`expr $value1 \* 663 | sed 's/\([0-9]\{5\}\)$/.\1/'`
	fi
	if [ -f $x7sla_io_path/in5_input ]
	then
	  value5=`cat $x7sla_io_path/in5_input`
	  value5=`expr $value5 \* 4 | sed 's/\([0-9]\{3\}\)$/.\1/'`
	fi
        rrdtool update $db_file \
        N:$value0:$value1:$value2:$value3:$value4:$value5:$value6:$value7:$value8
        ;;
    "cpuspeed")
        [ -f /var/run/scaling_cur_freq ]&&value1=`sed 's/\([0-9]\{3\}\)$/.\1/' /var/run/scaling_cur_freq`
	rrdtool update $db_file \
	N:$value1
	;;
    "fan")
        [ -f $x7sla_io_path/fan1_input ]&&value1=`cat $x7sla_io_path/fan1_input`
        [ -f $x7sla_io_path/fan2_input ]&&value2=`cat $x7sla_io_path/fan2_input`
        [ -f $x7sla_io_path/fan5_input ]&&value3=`cat $x7sla_io_path/fan5_input`
        [ -f $x7sla_io_path/fan4_input ]&&value4=`cat $x7sla_io_path/fan4_input`
        rrdtool update $db_file \
        N:$value1:$value2:$value3:$value4
        ;;
    esac
done
