git-svn-id: https://svn.fhem.de/fhem/trunk@1383 2b470e98-0d58-463d-a4d8-8e2adae1ed80

This commit is contained in:
pahenning
2012-03-25 10:48:59 +00:00
parent ac809d543e
commit f1c783612c
5 changed files with 72 additions and 65 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.09 - March, 2012 # Version 1.10 - March, 2012
# #
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# #
@@ -118,7 +118,7 @@ sub OWX_Initialize ($) {
my ($hash) = @_; my ($hash) = @_;
#-- Provider #-- Provider
#$hash->{Clients} = ":OWCOUNT:OWHUB:OWLCD:OWMULTI:OWSWITCH:OWTEMP:"; #$hash->{Clients} = ":OWCOUNT:OWHUB:OWLCD:OWMULTI:OWSWITCH:OWTEMP:";
$hash->{Clients} = ":OWAD:OWID:OWTEMP:"; $hash->{Clients} = ":OWAD:OWID:OWLCD:OWTEMP:";
#-- Normal Devices #-- Normal Devices
$hash->{DefFn} = "OWX_Define"; $hash->{DefFn} = "OWX_Define";
@@ -313,7 +313,10 @@ sub OWX_Define ($$) {
my ($hash, $def) = @_; my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def); my @a = split("[ \t][ \t]*", $def);
if(@a == 3){ if(int(@a) >= 3){
#-- check syntax
Log 1,"OWX: Warning - Some parameter(s) ignored, must be define <name> OWX"
if(int(@a) > 3);
#-- If this line contains 3 parameters, it is the bus master definition #-- If this line contains 3 parameters, it is the bus master definition
my $dev = $a[2]; my $dev = $a[2];
$hash->{DeviceName} = $dev; $hash->{DeviceName} = $dev;
@@ -366,6 +369,9 @@ sub OWX_Define ($$) {
$init_done = $oid; $init_done = $oid;
$hash->{STATE} = "Active"; $hash->{STATE} = "Active";
return undef; return undef;
} else {
#-- check syntax
return "OWX: Syntax error - must be define <name> OWX"
} }
} }
@@ -402,7 +408,7 @@ sub OWX_Detect ($) {
#Log 1, $ress; #Log 1, $ress;
#-- process 4/5-byte string for detection #-- process 4/5-byte string for detection
if( $res eq "\x16\x44\x5A\x00\x93"){ if( ($res eq "\x16\x44\x5A\x00\x90") || ($res eq "\x16\x44\x5A\x00\x93")){
Log 1, "OWX: 1-Wire bus master DS2480 detected for the first time"; Log 1, "OWX: 1-Wire bus master DS2480 detected for the first time";
$owx_interface="DS2480"; $owx_interface="DS2480";
$ret=1; $ret=1;
@@ -482,15 +488,26 @@ sub OWX_Discover ($) {
#-- all OW types start with OW #-- all OW types start with OW
next if( substr($main::defs{$fhem_dev}{TYPE},0,2) ne "OW"); next if( substr($main::defs{$fhem_dev}{TYPE},0,2) ne "OW");
my $id_fhem = substr($main::defs{$fhem_dev}{ROM_ID},0,15); my $id_fhem = substr($main::defs{$fhem_dev}{ROM_ID},0,15);
#-- skip interface device
next if( length($id_fhem) != 15 );
#-- testing if present in defined devices #-- testing if present in defined devices
if( $id_fhem eq $id_owx ){ # even with improper family
#print " FHEM-Device = ".substr($id_fhem,3,12)." OWX discovered device ".substr($id_owx,3,12)."\n";
if( substr($id_fhem,3,12) eq substr($id_owx,3,12) ) {
#-- warn if improper family id
if( substr($id_fhem,0,2) ne substr($id_owx,0,2) ){
Log 1, "OWX: Warning, $fhem_dev is defined with improper family id ".substr($id_fhem,0,2).
", correcting to ".substr($id_owx,0,2);
$main::defs{$fhem_dev}{OW_FAMILY} = substr($id_owx,0,2);
}
push(@owx_names,$main::defs{$fhem_dev}{NAME}); push(@owx_names,$main::defs{$fhem_dev}{NAME});
#-- replace the ROM ID by the proper value #-- replace the ROM ID by the proper value including CRC
$main::defs{$fhem_dev}{ROM_ID}=$owx_dev; $main::defs{$fhem_dev}{ROM_ID}=$owx_dev;
$main::defs{$fhem_dev}{PRESENT}=1; $main::defs{$fhem_dev}{PRESENT}=1;
$match = 1; $match = 1;
last; last;
} }
#
} }
#-- autocreate the device #-- autocreate the device
@@ -509,6 +526,9 @@ sub OWX_Discover ($) {
#-- Family 10 28 = Temperature sensor, assume DS18B20 as default #-- Family 10 28 = Temperature sensor, assume DS18B20 as default
}elsif( $owx_f eq "28" ){ }elsif( $owx_f eq "28" ){
CommandDefine(undef,"$name OWTEMP DS18B20 $owx_rnf"); CommandDefine(undef,"$name OWTEMP DS18B20 $owx_rnf");
#-- Family FF = LCD display
}elsif( $owx_f eq "FF" ){
CommandDefine(undef,"$name OWLCD $owx_rnf");
#-- All unknown families are ID only #-- All unknown families are ID only
} else { } else {
CommandDefine(undef,"$name OWID $owx_f $owx_rnf"); CommandDefine(undef,"$name OWID $owx_f $owx_rnf");

View File

@@ -14,7 +14,7 @@
# #
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# #
# Version 1.09 - March, 2012 # Version 1.10 - March, 2012
# #
# Setup bus device in fhem.cfg as # Setup bus device in fhem.cfg as
# #
@@ -206,13 +206,13 @@ sub OWAD_Define ($$) {
} }
#-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY" #-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY"
# YY must be determined from id # determine CRC Code - only if this is a direct interface
$crc = sprintf("%02x",OWX_CRC("20.".$id."00")); $crc = defined($hash->{IODev}->{INTERFACE}) ? sprintf("%02x",OWX_CRC("20.".$id."00")) : "00";
#-- Define device internals #-- Define device internals
$hash->{ROM_ID} = "20.".$id.$crc; $hash->{ROM_ID} = "20.".$id.$crc;
$hash->{OW_ID} = $id; $hash->{OW_ID} = $id;
$hash->{OW_FAMILY} = 20; $hash->{OW_FAMILY} = "20";
$hash->{PRESENT} = 0; $hash->{PRESENT} = 0;
$hash->{INTERVAL} = $interval; $hash->{INTERVAL} = $interval;
@@ -300,7 +300,9 @@ sub OWAD_InitializeDevice($) {
my $interface= $hash->{IODev}->{TYPE}; my $interface= $hash->{IODev}->{TYPE};
#-- OWX interface #-- OWX interface
if( $interface eq "OWX" ){ if( !defined($interface) ){
return "OWAD: Interface missing";
} elsif( $interface eq "OWX" ){
OWXAD_SetPage($hash,"alarm"); OWXAD_SetPage($hash,"alarm");
OWXAD_SetPage($hash,"status"); OWXAD_SetPage($hash,"status");
#-- OWFS interface #-- OWFS interface
@@ -957,9 +959,6 @@ sub OWXAD_SetPage($$) {
my ($hash,$page) = @_; my ($hash,$page) = @_;
#-- For now, switch on conversion command
my $con=1;
my ($select, $res, $res2, $res3, @data); my ($select, $res, $res2, $res3, @data);
#-- ID of the device #-- ID of the device
@@ -982,7 +981,7 @@ sub OWXAD_SetPage($$) {
} }
#=============== set the alarm values =============================== #=============== set the alarm values ===============================
if ( $page eq "alarm" ) { if ( $page eq "test" ) {
#-- issue the match ROM command \x55 and the set alarm page command #-- issue the match ROM command \x55 and the set alarm page command
# \x55\x10\x00 reading 8 data bytes and 2 CRC bytes # \x55\x10\x00 reading 8 data bytes and 2 CRC bytes
$select=sprintf("\x55%c%c%c%c%c%c%c%c\x55\x10\x00", $select=sprintf("\x55%c%c%c%c%c%c%c%c\x55\x10\x00",
@@ -990,7 +989,6 @@ sub OWXAD_SetPage($$) {
for( $i=0;$i<4;$i++){ for( $i=0;$i<4;$i++){
$select .= sprintf "%c\xFF\xFF\xFF",int($owg_vlow[$i]*255000/$owg_range[$i]); $select .= sprintf "%c\xFF\xFF\xFF",int($owg_vlow[$i]*255000/$owg_range[$i]);
$select .= sprintf "%c\xFF\xFF\xFF",int($owg_vhigh[$i]*255000/$owg_range[$i]); $select .= sprintf "%c\xFF\xFF\xFF",int($owg_vhigh[$i]*255000/$owg_range[$i]);
#print "XXXXXX> Setting alarm values to ".int($owg_vlow[$i]*255000/$owg_range[$i])." ".int($owg_vhigh[$i]*255000/$owg_range[$i])."\n";
} }
#=============== set the status =============================== #=============== set the status ===============================
} elsif ( $page eq "status" ) { } elsif ( $page eq "status" ) {
@@ -1015,9 +1013,8 @@ sub OWXAD_SetPage($$) {
} }
$select .= sprintf "%c\xFF\xFF\xFF",$sb1; $select .= sprintf "%c\xFF\xFF\xFF",$sb1;
$select .= sprintf "%c\xFF\xFF\xFF",$sb2; $select .= sprintf "%c\xFF\xFF\xFF",$sb2;
#print "YYYYYYYYYYY>setting status bytes $sb1 $sb2\n";
} }
#=============== wrong value requested =============================== #=============== wrong pag ewrit eattempt ===============================
} else { } else {
return "OWXAD: Wrong memory page write attempt"; return "OWXAD: Wrong memory page write attempt";
} }
@@ -1027,7 +1024,7 @@ sub OWXAD_SetPage($$) {
#-- process results #-- process results
if( $res eq 0 ){ if( $res eq 0 ){
return "OWXAD: Device $owx_dev not accessible for initialization"; return "OWXAD: Device $owx_dev not accessible for writing";
} }
return undef; return undef;

View File

@@ -12,7 +12,7 @@
# #
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# #
# Version 1.09 - March, 2012 # Version 1.10 - March, 2012
# #
# Setup bus device in fhem.cfg as # Setup bus device in fhem.cfg as
# #
@@ -109,7 +109,7 @@ sub OWID_Define ($$) {
$ret = ""; $ret = "";
#-- check syntax #-- check syntax
return "OWID: Wrong syntax, must be define <name> OWID <id>" return "OWID: Wrong syntax, must be define <name> OWID <fam> <id>"
if(int(@a) !=4 ); if(int(@a) !=4 );
#-- check id #-- check id
@@ -125,8 +125,8 @@ sub OWID_Define ($$) {
} }
#-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY" #-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY"
# YY must be determined from id # determine CRC Code YY - only if this is a direct interface
$crc = sprintf("%02x",OWX_CRC($fam.".".$id."00")); $crc = defined($hash->{IODev}->{INTERFACE}) ? sprintf("%02x",OWX_CRC($fam.".".$id."00")) : "00";
#-- Define device internals #-- Define device internals
$hash->{ROM_ID} = $fam.".".$id.$crc; $hash->{ROM_ID} = $fam.".".$id.$crc;

View File

@@ -13,10 +13,10 @@
# OWFS = 1-Wire file system (Martin Fischer) # OWFS = 1-Wire file system (Martin Fischer)
# OWX = 1-Wire bus master interface (Peter Henning) # OWX = 1-Wire bus master interface (Peter Henning)
# #
# Martin Fischer, 2011
# Prof. Dr. Peter A. Henning, 2012 # Prof. Dr. Peter A. Henning, 2012
# Martin Fischer, 2011
# #
# Version 1.09 - March, 2012 # Version 1.10 - March, 2012
# #
# Setup bus device in fhem.cfg as # Setup bus device in fhem.cfg as
# #
@@ -69,9 +69,6 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
######################################################################################## ########################################################################################
#
# TODO: offset in alarm values
#
package main; package main;
#-- Prototypes to make komodo happy #-- Prototypes to make komodo happy
@@ -190,11 +187,11 @@ sub OWTEMP_Define ($$) {
# FF = family id follows from the model # FF = family id follows from the model
# YY must be determined from id # YY must be determined from id
if( $model eq "DS1820" ){ if( $model eq "DS1820" ){
$fam = 10; $fam = "10";
}elsif( $model eq "DS1822" ){ }elsif( $model eq "DS1822" ){
$fam = 22; $fam = "22";
}elsif( $model eq "DS18B20" ){ }elsif( $model eq "DS18B20" ){
$fam = 28; $fam = "28";
}else{ }else{
return "OWTEMP: Wrong 1-Wire device model $model"; return "OWTEMP: Wrong 1-Wire device model $model";
} }

View File

@@ -15,8 +15,7 @@
# is a serial (USB) device or the keyword "emulator". # is a serial (USB) device or the keyword "emulator".
# In the latter case, a 4.5 kWP solar installation is simulated # In the latter case, a 4.5 kWP solar installation is simulated
# #
# Attributes are set as (examples !) # Additional attributes are defined in fhem.cfg as
#
# attr nt5000 room Solaranlage # attr nt5000 room Solaranlage
# Area of solar installation # Area of solar installation
# attr nt5000 Area 32.75 # attr nt5000 Area 32.75
@@ -63,14 +62,14 @@ use strict;
use warnings; use warnings;
use Device::SerialPort; use Device::SerialPort;
# Prototypes to make komodo happy #-- Prototypes to make komodo happy
use vars qw{%attr %defs}; use vars qw{%attr %defs};
sub Log($$); sub Log($$);
# Line counter #-- Line counter
my $cline=0; my $cline=0;
# These we may get on request #-- These we may get on request
my %gets = ( my %gets = (
"reading" => "R", "reading" => "R",
"month" => "M", "month" => "M",
@@ -79,12 +78,12 @@ my %gets = (
"proto" => "P" "proto" => "P"
); );
# These occur in a pulldown menu as settable values #-- These occur in a pulldown menu as settable values
my %sets = ( my %sets = (
"time" => "T" "time" => "T"
); );
# These we may get on request #-- These we may get on request
my %attrs = ( my %attrs = (
"Wyx" => "R", "Wyx" => "R",
); );
@@ -113,7 +112,10 @@ sub NT5000_Initialize ($) {
# which is the following one. # which is the following one.
# WxM1 .. WxM12 = Expected yield from January .. December # WxM1 .. WxM12 = Expected yield from January .. December
# WxY = Expected yield per year # WxY = Expected yield per year
$hash->{AttrList}= "Area PSP MERR Wx_M1 Wx_M2 Wx_M3 Wx_M4 Wx_M5 Wx_M6 Wx_M7 Wx_M8 Wx_M9 Wx_M10 Wx_M11 Wx_M12 Wx_Y loglevel:0,1,2,3,4,5,6"; $hash->{AttrList}= "Area PSP MERR ".
"Wx_M1 Wx_M2 Wx_M3 Wx_M4 Wx_M5 Wx_M6 Wx_M7 Wx_M8 Wx_M9 Wx_M10 Wx_M11 Wx_M12 ".
"Wx_Y ".
"loglevel:0,1,2,3,4,5,6";
} }
####################################################################################### #######################################################################################
@@ -152,22 +154,16 @@ sub NT5000_Define($$) {
} }
$hash->{DeviceName} = $dev; $hash->{DeviceName} = $dev;
$hash->{Timer} = 60; # call every 60 seconds $hash->{Timer} = 60; # call every 60 seconds
$hash->{Cmd} = "reading"; # get all data, min/max unchange $hash->{Cmd} = "reading"; # get all data, min/max unchange
$hash->{SerialNumber} = ""; $hash->{SerialNumber} = "";
$hash->{Protocol} = ""; $hash->{Protocol} = "";
$hash->{Firmware} = ""; $hash->{Firmware} = "";
$hash->{STATE} = "offline"; $hash->{STATE} = "offline";
my $tn = TimeNow(); my $tn = TimeNow();
#$hash->{READINGS}{"freq"}{TIME} = $tn;
#$hash->{READINGS}{"freq"}{VAL} = $hash->{Timer};
#$hash->{READINGS}{"cmd"}{TIME} = $tn;
#$hash->{READINGS}{"cmd"}{VAL} = $hash->{Cmd};
#$hash->{CHANGED}[$main::cline++] = "freq: $hash->{Timer}";
#$hash->{CHANGED}[$main::cline++] = "cmd: $hash->{Cmd}";
# InternalTimer blocks if init_done is not true #-- InternalTimer blocks if init_done is not true
my $oid = $init_done; my $oid = $init_done;
$init_done = 1; $init_done = 1;
NT5000_GetStatus($hash); NT5000_GetStatus($hash);
@@ -303,7 +299,7 @@ sub NT5000_GetStatus ($) {
my $tn = TimeNow(); my $tn = TimeNow();
my @names = ("Udc", "Idc", "Pdc", "Uac", "Iac", "Pac", "Temp", "S", "Wd", "Wtot", "Eta"); my @names = ("Udc", "Idc", "Pdc", "Uac", "Iac", "Pac", "Temp", "S", "Wd", "Wtot", "Eta");
if( $hash->{STATE} ne "online" ) { if( !($hash->{STATE} =~ m/.*kW/) ) {
# we have turned online recently # we have turned online recently
Log GetLogLevel($name,2), "NT5000 inverter is online"; Log GetLogLevel($name,2), "NT5000 inverter is online";
$hash->{STATE} = "starting"; $hash->{STATE} = "starting";
@@ -315,8 +311,8 @@ sub NT5000_GetStatus ($) {
my $proto = NT5000_GetLine($hash, "proto"); my $proto = NT5000_GetLine($hash, "proto");
$proto =~ s/^.*P://; $proto =~ s/^.*P://;
$proto =~ s/[\r\n ]//g; $proto =~ s/[\r\n ]//g;
$hash->{Protocol} = substr($proto,0,1).".".substr($proto,1,1); $hash->{Firmware} = substr($proto,0,1).".".substr($proto,1,1);
$hash->{Firmware} = substr($proto,2,1).".".substr($proto,4,2); $hash->{Protocol} = substr($proto,2,1).".".substr($proto,4,2);
# Obtain monthly readings in 70 seconds - only once # Obtain monthly readings in 70 seconds - only once
InternalTimer(gettimeofday()+ 20, "NT5000_GetMonth", $hash,1); InternalTimer(gettimeofday()+ 20, "NT5000_GetMonth", $hash,1);
@@ -332,10 +328,6 @@ sub NT5000_GetStatus ($) {
$hash->{CHANGED}[$main::cline++] = "$resmod"; $hash->{CHANGED}[$main::cline++] = "$resmod";
}; };
$hash->{STATE} = "online";
#$result =~ s/^.*R://;
#$result =~ s/[\r\n ]//g;
#$result=~ s/,/./g;
#-- Log level 5 #-- Log level 5
Log GetLogLevel($name,5), "NT5000 online result = $result"; Log GetLogLevel($name,5), "NT5000 online result = $result";
@@ -346,10 +338,11 @@ sub NT5000_GetStatus ($) {
#-- split result for writing into hash #-- split result for writing into hash
my @data = split(' ',$result); my @data = split(' ',$result);
$hash->{STATE} = sprintf("%5.3f kW",$data[5]);
for(my $i = 0; $i < int(@names); $i++) { for(my $i = 0; $i < int(@names); $i++) {
# This puts individual pairs into the tabular view # This puts individual pairs into the tabular view
$hash->{READINGS}{$names[$i]}{TIME} = $tn;
$hash->{READINGS}{$names[$i]}{VAL} = $data[$i]; $hash->{READINGS}{$names[$i]}{VAL} = $data[$i];
$hash->{READINGS}{$names[$i]}{TIME} = $tn;
} }
DoTrigger($name, undef) if($init_done); DoTrigger($name, undef) if($init_done);