This commit is contained in:
pahenning
2012-05-17 19:08:01 +00:00
parent 80b52658ff
commit 04a64808ef
5 changed files with 82 additions and 53 deletions

View File

@@ -6,7 +6,7 @@
# via an active DS2480/DS2490/DS9097U bus master interface or # via an active DS2480/DS2490/DS9097U bus master interface or
# via a passive DS9097 interface # via a passive DS9097 interface
# #
# Version 1.11 - March, 2012 # Version 1.12 - April, 2012
# #
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# #
@@ -348,7 +348,7 @@ sub OWX_Define ($$) {
} }
#-- In 10 seconds discover all devices on the 1-Wire bus #-- In 10 seconds discover all devices on the 1-Wire bus
InternalTimer(gettimeofday()+5, "OWX_Discover", $hash,0); InternalTimer(gettimeofday()+10, "OWX_Discover", $hash,0);
#-- Default settings #-- Default settings
$hash->{interval} = 60; # kick every minute $hash->{interval} = 60; # kick every minute
@@ -358,15 +358,13 @@ sub OWX_Define ($$) {
#-- InternalTimer blocks if init_done is not true #-- InternalTimer blocks if init_done is not true
my $oid = $init_done; my $oid = $init_done;
$hash->{PRESENT} = 1; $hash->{PRESENT} = 1;
#$hash->{TYPE} = "OWX";
#$hash->{T} = "OWX";
$hash->{STATE} = "Initialized"; $hash->{STATE} = "Initialized";
$hash->{INTERFACE} = $owx_interface; $hash->{INTERFACE} = $owx_interface;
$init_done = 1; $init_done = 1;
#-- Intiate first alarm detection and eventually conversion in a minute or so #-- Intiate first alarm detection and eventually conversion in a minute or so
InternalTimer(gettimeofday() + 60, "OWX_Kick", $hash,1); InternalTimer(gettimeofday() + $hash->{interval}, "OWX_Kick", $hash,1);
$init_done = $oid; $init_done = $oid;
$hash->{STATE} = "Active"; $hash->{STATE} = "Active";
return undef; return undef;
} else { } else {

View File

@@ -14,7 +14,7 @@
# #
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# #
# Version 1.11 - March, 2012 # Version 1.12 - April, 2012
# #
# Setup bus device in fhem.cfg as # Setup bus device in fhem.cfg as
# #
@@ -260,7 +260,7 @@ sub OWAD_InitializeDevice($) {
@owg_shigh = (0,0,0,0); @owg_shigh = (0,0,0,0);
#-- Set channel names, channel units and alarm values #-- Set channel names, channel units and alarm values
for( my $i=0;$i<4;$i++) { for( my $i=0;$i<int(@owg_fixed);$i++) {
#-- name #-- name
my $cname = defined($attr{$name}{$owg_fixed[$i]."Name"}) ? $attr{$name}{$owg_fixed[$i]."Name"} : $owg_fixed[$i]."|voltage"; my $cname = defined($attr{$name}{$owg_fixed[$i]."Name"}) ? $attr{$name}{$owg_fixed[$i]."Name"} : $owg_fixed[$i]."|voltage";
my @cnama = split(/\|/,$cname); my @cnama = split(/\|/,$cname);
@@ -336,7 +336,7 @@ sub OWAD_FormatValues($) {
my $tn = TimeNow(); my $tn = TimeNow();
#-- formats for output #-- formats for output
for (my $i=0;$i<4;$i++){ for (my $i=0;$i<int(@owg_fixed);$i++){
$offset = $hash->{READINGS}{"$owg_channel[$i]"}{OFFSET}; $offset = $hash->{READINGS}{"$owg_channel[$i]"}{OFFSET};
$factor = $hash->{READINGS}{"$owg_channel[$i]"}{FACTOR}; $factor = $hash->{READINGS}{"$owg_channel[$i]"}{FACTOR};
#-- correct values for proper offset, factor #-- correct values for proper offset, factor
@@ -395,7 +395,7 @@ sub OWAD_FormatValues($) {
} }
#-- insert comma #-- insert comma
if( $i<3 ){ if( $i<int(@owg_fixed)-1 ){
$value1 .= " "; $value1 .= " ";
$value2 .= ", "; $value2 .= ", ";
$value3 .= ", "; $value3 .= ", ";
@@ -505,7 +505,7 @@ sub OWAD_Get($@) {
#-- output string looks differently here #-- output string looks differently here
$value = ""; $value = "";
for (my $i=0;$i<4;$i++){ for (my $i=0;$i<int(@owg_fixed);$i++){
$value .= sprintf "%s:[%4.2f,%4.2f] ",$owg_channel[$i], $value .= sprintf "%s:[%4.2f,%4.2f] ",$owg_channel[$i],
$hash->{READINGS}{$owg_channel[$i]."Low"}{VAL}, $hash->{READINGS}{$owg_channel[$i]."Low"}{VAL},
$hash->{READINGS}{$owg_channel[$i]."High"}{VAL}; $hash->{READINGS}{$owg_channel[$i]."High"}{VAL};
@@ -610,7 +610,7 @@ sub OWAD_Set($@) {
#-- for the selector: which values are possible #-- for the selector: which values are possible
if (@a == 2){ if (@a == 2){
my $newkeys = join(" ", sort keys %sets); my $newkeys = join(" ", sort keys %sets);
for( my $i=0;$i<4;$i++ ){ for( my $i=0;$i<int(@owg_fixed);$i++ ){
$newkeys .= " ".$owg_channel[$i]."Alarm"; $newkeys .= " ".$owg_channel[$i]."Alarm";
$newkeys .= " ".$owg_channel[$i]."Low"; $newkeys .= " ".$owg_channel[$i]."Low";
$newkeys .= " ".$owg_channel[$i]."High"; $newkeys .= " ".$owg_channel[$i]."High";
@@ -652,13 +652,13 @@ sub OWAD_Set($@) {
#-- find out which channel we have #-- find out which channel we have
my $tc =$key; my $tc =$key;
if( $tc =~ s/(.*)(Alarm|Low|High)/$channel=$1/se ) { if( $tc =~ s/(.*)(Alarm|Low|High)/$channel=$1/se ) {
for (my $i=0;$i<4;$i++){ for (my $i=0;$i<int(@owg_fixed);$i++){
if( $tc eq $owg_channel[$i] ){ if( $tc eq $owg_channel[$i] ){
$channo = $i; $channo = $i;
$channel = $tc; $channel = $tc;
last; last;
} }
} }
} }
return "OWAD: Cannot determine channel from parameter $a[1]" return "OWAD: Cannot determine channel from parameter $a[1]"
if( !(defined($channo))); if( !(defined($channo)));
@@ -869,19 +869,19 @@ sub OWXAD_GetPage($$) {
#=============== get the voltage reading =============================== #=============== get the voltage reading ===============================
if( $page eq "reading"){ if( $page eq "reading"){
for( $i=0;$i<4;$i++){ for( $i=0;$i<int(@owg_fixed);$i++){
$owg_val[$i]= int((ord($data[12+2*$i])+256*ord($data[13+2*$i]))/((1<<$owg_resoln[$i])-1) * $owg_range[$i])/1000; $owg_val[$i]= int((ord($data[12+2*$i])+256*ord($data[13+2*$i]))/((1<<$owg_resoln[$i])-1) * $owg_range[$i])/1000;
} }
#=============== get the alarm reading =============================== #=============== get the alarm reading ===============================
} elsif ( $page eq "alarm" ) { } elsif ( $page eq "alarm" ) {
for( $i=0;$i<4;$i++){ for( $i=0;$i<int(@owg_fixed);$i++){
$owg_vlow[$i] = int(ord($data[12+2*$i])/255 * $owg_range[$i])/1000; $owg_vlow[$i] = int(ord($data[12+2*$i])/255 * $owg_range[$i])/1000;
$owg_vhigh[$i] = int(ord($data[13+2*$i])/255 * $owg_range[$i])/1000; $owg_vhigh[$i] = int(ord($data[13+2*$i])/255 * $owg_range[$i])/1000;
} }
#=============== get the status reading =============================== #=============== get the status reading ===============================
} elsif ( $page eq "status" ) { } elsif ( $page eq "status" ) {
my ($sb1,$sb2); my ($sb1,$sb2);
for( $i=0;$i<4;$i++){ for( $i=0;$i<int(@owg_fixed);$i++){
$sb1 = ord($data[12+2*$i]); $sb1 = ord($data[12+2*$i]);
$sb2 = ord($data[12+2*$i+1]); $sb2 = ord($data[12+2*$i+1]);

View File

@@ -18,7 +18,7 @@
# #
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# #
# Version 1.11 - March, 2012 # Version 1.12 - April, 2012
# #
# Setup bus device in fhem.cfg as # Setup bus device in fhem.cfg as
# #
@@ -35,7 +35,8 @@
# get <name> id => FAM_ID.ROM_ID.CRC # get <name> id => FAM_ID.ROM_ID.CRC
# get <name> present => 1 if device present, 0 if not # get <name> present => 1 if device present, 0 if not
# get <name> interval => query interval # get <name> interval => query interval
# get <name> counter A,B => value for counter # get <name> counter <channel> => value for counter
# get <name> counters => values for countera
# #
# set <name> interval => set period for measurement # set <name> interval => set period for measurement
# #
@@ -85,6 +86,7 @@ my %gets = (
"interval" => "", "interval" => "",
#"page" => "", #"page" => "",
"counter" => "", "counter" => "",
"counters" => ""
); );
my %sets = ( my %sets = (
@@ -292,20 +294,23 @@ sub OWCOUNT_FormatValues($) {
#-- correct values for proper offset, factor #-- correct values for proper offset, factor
if( $factor == 1.0 ){ if( $factor == 1.0 ){
$vval = ($owg_val[$i] + $offset)*$factor; $vval = ($owg_val[$i] + $offset)*$factor;
#-- string buildup for return value and STATE
$value1 .= sprintf( "%s: %d %s", $owg_channel[$i], $vval,$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR});
$value2 .= sprintf( "%s: %d %s ", $owg_channel[$i], $vval,$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR});
} else { } else {
$vval = int(($owg_val[$i] + $offset)*$factor*1000)/1000; $vval = int(($owg_val[$i] + $offset)*$factor*1000)/1000;
#-- string buildup for return value and STATE
$value1 .= sprintf( "%s: %5.3f %s", $owg_channel[$i], $vval,$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR});
$value2 .= sprintf( "%s: %5.2f %s ", $owg_channel[$i], $vval,$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR});
} }
$value3 .= sprintf( "%s: " , $owg_channel[$i]);
#-- put into READINGS #-- put into READINGS
$hash->{READINGS}{"$owg_channel[$i]"}{VAL} = $vval; $hash->{READINGS}{"$owg_channel[$i]"}{VAL} = $vval;
$hash->{READINGS}{"$owg_channel[$i]"}{TIME} = $tn; $hash->{READINGS}{"$owg_channel[$i]"}{TIME} = $tn;
#-- string buildup for return value and STATE
$value1 .= sprintf( "%s: %5.3f %s", $owg_channel[$i], $vval,$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR});
$value2 .= sprintf( "%s: %5.2f %s ", $owg_channel[$i], $vval,$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR});
$value3 .= sprintf( "%s: " , $owg_channel[$i]);
#-- insert comma #-- insert comma
if( $i<3 ){ if( $i<int(@owg_fixed)-1 ){
$value1 .= " "; $value1 .= " ";
$value2 .= ", "; $value2 .= ", ";
$value3 .= ", "; $value3 .= ", ";
@@ -335,6 +340,7 @@ sub OWCOUNT_Get($@) {
my $ret = ""; my $ret = "";
my $offset; my $offset;
my $factor; my $factor;
my $page;
#-- check syntax #-- check syntax
return "OWCOUNT: Get argument is missing @a" return "OWCOUNT: Get argument is missing @a"
@@ -375,10 +381,14 @@ sub OWCOUNT_Get($@) {
if( $reading eq "counter" ){ if( $reading eq "counter" ){
return "OWCOUNT: get needs parameter when reading counter: <channel>" return "OWCOUNT: get needs parameter when reading counter: <channel>"
if( int(@a)<2 ); if( int(@a)<2 );
#-- channle may be addressed by bare channel name (A..D) or by defined channel name #-- find out which channel we have
return "OWCOUNT: invalid counter address, must be A or B" if( ($a[2] eq $owg_channel[0]) || ($a[2] eq "A") ){
if( !($a[2] =~ m/[AB]/) ); $page=14;
my $page = ($a[2] eq "A") ? 14 : 15; }elsif( ($a[2] eq $owg_channel[1]) || ($a[2] eq "B") ){
$page=15;
} else {
return "OWCOUNT: invalid counter address, must be A, B or defined channel name"
}
#-- OWX interface #-- OWX interface
if( $interface eq "OWX" ){ if( $interface eq "OWX" ){
@@ -390,15 +400,26 @@ sub OWCOUNT_Get($@) {
}else{ }else{
return "OWCOUNT: Get with wrong IODev type $interface"; return "OWCOUNT: Get with wrong IODev type $interface";
} }
#-- check syntax for getting counter
#-- process results }elsif( $reading eq "counters" ){
if( defined($ret) ){ return "OWCOUNT: get needs no parameter when reading counters"
return "OWCOUNT: Could not get values from device $name"; if( int(@a)==1 );
if( $interface eq "OWX" ){
$ret = OWXCOUNT_GetPage($hash,14);
$ret = OWXCOUNT_GetPage($hash,15);
#}elsif( $interface eq "OWFS" ){
# $ret = OWFSAD_GetValues($hash);
}else{
return "OWCOUNT: GetValues with wrong IODev type $interface";
} }
$hash->{PRESENT} = 1;
return "OWCOUNT: $name.$reading => ".OWCOUNT_FormatValues($hash);
} }
#-- process results
if( defined($ret) ){
return "OWCOUNT: Could not get values from device $name";
}
$hash->{PRESENT} = 1;
return "OWCOUNT: $name.$reading => ".OWCOUNT_FormatValues($hash);
} }
@@ -431,7 +452,7 @@ sub OWCOUNT_GetValues($) {
#-- reset presence #-- reset presence
$hash->{PRESENT} = 0; $hash->{PRESENT} = 0;
#-- Get readings, alarms and stati according to interface type #-- Get readings according to interface type
my $interface= $hash->{IODev}->{TYPE}; my $interface= $hash->{IODev}->{TYPE};
if( $interface eq "OWX" ){ if( $interface eq "OWX" ){
$ret = OWXCOUNT_GetPage($hash,14); $ret = OWXCOUNT_GetPage($hash,14);
@@ -591,7 +612,7 @@ sub OWXCOUNT_GetPage($$) {
# \xA5 TA1 TA2 reading 40 data bytes and 2 CRC bytes # \xA5 TA1 TA2 reading 40 data bytes and 2 CRC bytes
my $ta2 = ($page*32) >> 8; my $ta2 = ($page*32) >> 8;
my $ta1 = ($page*32) & 255; my $ta1 = ($page*32) & 255;
print "getting page Nr. $ta2 $ ta1\n"; Log 1, "OWXCOUNT: getting page Nr. $ta2 $ta1";
$select=sprintf("\x55%c%c%c%c%c%c%c%c\xA5%c%c", $select=sprintf("\x55%c%c%c%c%c%c%c%c\xA5%c%c",
@owx_ROM_ID,$ta1,$ta2); @owx_ROM_ID,$ta1,$ta2);
#-- reset the bus #-- reset the bus
@@ -603,9 +624,11 @@ sub OWXCOUNT_GetPage($$) {
} }
#-- process results #-- process results
#print "Have received ".length($res)." bytes\n"; if( length($res) != 12 ) {
Log 1, "OWXCOUNT: warning, have received ".length($res)." bytes in first step";
}
#-- get 32 bytes #-- get 32, 36 or 28 bytes
$select=""; $select="";
for( $i=0;$i<42;$i++){ for( $i=0;$i<42;$i++){
$select .= "\xFF"; $select .= "\xFF";
@@ -613,31 +636,39 @@ sub OWXCOUNT_GetPage($$) {
#-- read the data #-- read the data
$res=OWX_Block($master,$select); $res=OWX_Block($master,$select);
#-- process results #-- get remaining bytes
#print "Have received ".length($res)." bytes\n";
#-- get 10 bytes
$select=""; $select="";
for( $i=0;$i<10;$i++){ for( $i=0;$i<10;$i++){
$select .= "\xFF"; $select .= "\xFF";
} }
#-- read the data #-- read the data
$res=OWX_Block($master,$select); $res.=OWX_Block($master,$select);
#-- reset the bus #-- reset the bus
OWX_Reset($master); OWX_Reset($master);
#-- process results #-- process results
#print "Have received ".length($res)." bytes\n"; if( length($res) != 54){
@data=split(//,$res); Log 1, "OWXCOUNT: warning, have received ".length($res)." bytes in second and third step";
}
@data=split(//,substr($res,32));
if ( ($data[4] | $data[5] | $data[6] | $data[7]) ne "\x00" ){ if ( ($data[4] | $data[5] | $data[6] | $data[7]) ne "\x00" ){
Log 1, "OWXCOUNT: Device $owx_dev returns invalid data";
return "OWXCOUNT: Device $owx_dev returns invalid data"; return "OWXCOUNT: Device $owx_dev returns invalid data";
} }
#-- for now ignore memory and only use counter #-- for now ignore memory and only use counter
my $value = ord($data[3])*4096 + ord($data[2])*256 +ord($data[1])*16 + ord($data[0]); my $value = ord($data[3])*4096 + ord($data[2])*256 +ord($data[1])*16 + ord($data[0]);
#print "Value received = $value\n"; #my $ress = "OWXCOUNT: Lowest 8 data bytes are ";
# for($i=0;$i<8;$i++){
# my $j=int(ord($data[$i])/16);
# my $k=ord($data[$i])%16;
# $ress.=sprintf "0x%1x%1x ",$j,$k;
# }
#Log 1, $ress;
#Log 1, "OWXCOUNT: calculating counter value $value";
if( $page == 14) { if( $page == 14) {
$owg_val[0] = $value; $owg_val[0] = $value;
}elsif( $page == 15) { }elsif( $page == 15) {

View File

@@ -12,7 +12,7 @@
# #
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# #
# Version 1.11 - March, 2012 # Version 1.12 - April, 2012
# #
# Setup bus device in fhem.cfg as # Setup bus device in fhem.cfg as
# #

View File

@@ -16,7 +16,7 @@
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# Martin Fischer, 2011 # Martin Fischer, 2011
# #
# Version 1.11 - March, 2012 # Version 1.12 - April, 2012
# #
# Setup bus device in fhem.cfg as # Setup bus device in fhem.cfg as
# #
@@ -48,8 +48,8 @@
# attr <name> stateAH "<string>" = character string for denoting high alarm condition, default is red up triangle # attr <name> stateAH "<string>" = character string for denoting high alarm condition, default is red up triangle
# attr <name> tempOffset <float> = temperature offset in degree Celsius added to the raw temperature reading # attr <name> tempOffset <float> = temperature offset in degree Celsius added to the raw temperature reading
# attr <name> tempUnit <string> = unit of measurement, e.g. Celsius/Kelvin/Fahrenheit or C/K/F, default is Celsius # attr <name> tempUnit <string> = unit of measurement, e.g. Celsius/Kelvin/Fahrenheit or C/K/F, default is Celsius
# attr <name> tempLow <float> = measurement value for low alarm # attr <name> tempLow <float> = value for low alarm
# attr <name> tempHigh <float> = measurement for high alarm # attr <name> tempHigh <float> = value for high alarm
# #
######################################################################################## ########################################################################################
# #