defptr moved to modules for a correct CommandReload

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@531 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2010-01-01 13:48:33 +00:00
parent 070289ecd6
commit 2ccd40ac3e
16 changed files with 90 additions and 99 deletions

View File

@ -7,8 +7,6 @@ use Time::HiRes qw(gettimeofday);
use Lirc::Client; use Lirc::Client;
use IO::Select; use IO::Select;
my $def;
##################################### #####################################
# Note: we are a data provider _and_ a consumer at the same time # Note: we are a data provider _and_ a consumer at the same time
sub sub

View File

@ -12,8 +12,6 @@ use warnings;
my $PI= 3.141592653589793238; my $PI= 3.141592653589793238;
my %defptr;
############################# #############################
sub sub
BS_Initialize($) BS_Initialize($)
@ -54,7 +52,7 @@ BS_Define($$)
my $dev= "a5cf $sensor"; my $dev= "a5cf $sensor";
$hash->{DEF}= $dev; $hash->{DEF}= $dev;
$defptr{$dev} = $hash; $modules{BS}{defptr}{$dev} = $hash;
AssignIoPort($hash); AssignIoPort($hash);
} }
@ -63,7 +61,8 @@ sub
BS_Undef($$) BS_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
delete($defptr{$hash->{DEF}});
delete($modules{BS}{defptr}{$hash->{DEF}});
return undef; return undef;
} }
@ -81,7 +80,7 @@ BS_Parse($$)
my $sensor= substr($msg, 20, 2); my $sensor= substr($msg, 20, 2);
my $dev= "a5cf $sensor"; my $dev= "a5cf $sensor";
my $def= $defptr{$dev}; my $def= $modules{BS}{defptr}{$dev};
if(!defined($def)) { if(!defined($def)) {
$sensor =~ s/^0//; $sensor =~ s/^0//;
Log 3, "BS Unknown device $sensor, please define it"; Log 3, "BS Unknown device $sensor, please define it";

View File

@ -74,7 +74,6 @@ my %fhttfk_codes = (
"92" => "Window:Closed, Low Batt", "92" => "Window:Closed, Low Batt",
"12" => "Window:Closed, Low Batt", "12" => "Window:Closed, Low Batt",
"0f" => "Test:Success"); "0f" => "Test:Success");
my %defptr;
# -wusel, 2009-11-09: Map retransmission codes to major (8x) ones (0x) # -wusel, 2009-11-09: Map retransmission codes to major (8x) ones (0x)
# As I'm somewhat lazy, I just list all codes from # As I'm somewhat lazy, I just list all codes from
@ -135,7 +134,7 @@ CUL_FHTTK_Define($$)
# $hash->{SENSOR}= "$sensor"; # $hash->{SENSOR}= "$sensor";
$hash->{CODE} = $sensor; $hash->{CODE} = $sensor;
$defptr{$sensor} = $hash; $modules{CUL_FHTTK}{defptr}{$sensor} = $hash;
# $defs{$hash}{READINGS}{PREV}{STATE}="00"; # $defs{$hash}{READINGS}{PREV}{STATE}="00";
# $defs{$hash}{READINGS}{PREV}{TIMESTAMP} = localtime(); # $defs{$hash}{READINGS}{PREV}{TIMESTAMP} = localtime();
AssignIoPort($hash); AssignIoPort($hash);
@ -148,7 +147,7 @@ sub
CUL_FHTTK_Undef($$) CUL_FHTTK_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
delete($defptr{$hash->{CODE}}) if($hash && $hash->{CODE}); delete($modules{CUL_FHTTK}{defptr}{$hash->{CODE}}) if($hash && $hash->{CODE});
return undef; return undef;
} }
@ -160,15 +159,15 @@ CUL_FHTTK_Parse($$)
my ($hash, $msg) = @_; my ($hash, $msg) = @_;
my $sensor= lc(substr($msg, 1, 6)); my $sensor= lc(substr($msg, 1, 6));
my $state = lc(substr($msg, 7, 2)); my $def = $modules{CUL_FHTTK}{defptr}{$sensor};
my $def = $defptr{$sensor}; if(!$def) {
my $self = $def->{NAME};
if(!defined($defptr{$sensor})) {
Log 3, "FHTTK Unknown device $sensor, please define it"; Log 3, "FHTTK Unknown device $sensor, please define it";
return "UNDEFINED CUL_FHTTK_$sensor CUL_FHTTK $sensor"; return "UNDEFINED CUL_FHTTK_$sensor CUL_FHTTK $sensor";
} }
my $self = $def->{NAME};
my $state = lc(substr($msg, 7, 2));
if(!defined($fhttfk_translatedcodes{$state})) { if(!defined($fhttfk_translatedcodes{$state})) {
Log 3, sprintf("FHTTK $def Unknown state $state"); Log 3, sprintf("FHTTK $def Unknown state $state");
$defs{$self}{READINGS}{"Unknown"}{VAL} = $state; $defs{$self}{READINGS}{"Unknown"}{VAL} = $state;

View File

@ -12,7 +12,6 @@ use warnings;
my $PI= 3.141592653589793238; my $PI= 3.141592653589793238;
my %defptr;
my $dev= "a5ce aa"; my $dev= "a5ce aa";
############################# #############################
@ -71,7 +70,7 @@ USF1000_Define($$)
return $g; return $g;
} }
$defptr{$dev} = $hash; $modules{USF1000}{defptr}{$dev} = $hash;
AssignIoPort($hash); AssignIoPort($hash);
} }
@ -80,7 +79,7 @@ sub
USF1000_Undef($$) USF1000_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
delete($defptr{$dev}); delete($modules{USF1000}{defptr}{$dev});
return undef; return undef;
} }
@ -90,12 +89,12 @@ USF1000_Parse($$)
{ {
my ($hash, $msg) = @_; # hash points to the FHZ, not to the USF1000 my ($hash, $msg) = @_; # hash points to the FHZ, not to the USF1000
if(!defined($defptr{$dev})) { if(!defined($modules{USF1000}{defptr}{$dev})) {
Log 3, "USF1000 Unknown device, please define it"; Log 3, "USF1000 Unknown device, please define it";
return "UNDEFINED USF1000 USF1000 cylv 1 1 0.5"; return "UNDEFINED USF1000 USF1000 cylv 1 1 0.5";
} }
my $def= $defptr{$dev}; my $def= $modules{USF1000}{defptr}{$dev};
my $name= $def->{NAME}; my $name= $def->{NAME};
my $t= TimeNow(); my $t= TimeNow();

View File

@ -48,10 +48,6 @@ my %readonly = (
use vars qw(%fs20_c2b); # Peter would like to access it from outside use vars qw(%fs20_c2b); # Peter would like to access it from outside
# defptr{XMIT BTN}{DEVNAME} -> Ptr to global defs entry for this device
my %defptr;
my %follow;
my $fs20_simple ="off off-for-timer on on-for-timer on-till reset timer toggle"; my $fs20_simple ="off off-for-timer on on-for-timer on-till reset timer toggle";
my %models = ( my %models = (
fs20hgs => 'sender', fs20hgs => 'sender',
@ -215,14 +211,14 @@ FS20_Set($@)
########################################### ###########################################
# Set the state of a device to off if on-for-timer is called # Set the state of a device to off if on-for-timer is called
if($follow{$a[0]}) { if($modules{FS20}{ldata}{$a[0]}) {
CommandDelete(undef, $a[0] . "_timer"); CommandDelete(undef, $a[0] . "_timer");
delete $follow{$a[0]}; delete $modules{FS20}{ldata}{$a[0]};
} }
if($a[1] =~ m/for-timer/ && $na == 3 && if($a[1] =~ m/for-timer/ && $na == 3 &&
defined($attr{$a[0]}) && defined($attr{$a[0]}{"follow-on-for-timer"})) { defined($attr{$a[0]}) && defined($attr{$a[0]}{"follow-on-for-timer"})) {
my $to = sprintf("%02d:%02d:%02d", $val/3600, ($val%3600)/60, $val%60); my $to = sprintf("%02d:%02d:%02d", $val/3600, ($val%3600)/60, $val%60);
$follow{$a[0]} = $to; $modules{FS20}{ldata}{$a[0]} = $to;
Log 4, "Follow: +$to setstate $a[0] off"; Log 4, "Follow: +$to setstate $a[0] off";
CommandDefine(undef, $a[0] . "_timer at +$to setstate $a[0] off"); CommandDefine(undef, $a[0] . "_timer at +$to setstate $a[0] off");
} }
@ -231,9 +227,9 @@ FS20_Set($@)
# Look for all devices with the same code, and set state, timestamp # Look for all devices with the same code, and set state, timestamp
my $code = "$hash->{XMIT} $hash->{BTN}"; my $code = "$hash->{XMIT} $hash->{BTN}";
my $tn = TimeNow(); my $tn = TimeNow();
foreach my $n (keys %{ $defptr{$code} }) { foreach my $n (keys %{ $modules{FS20}{defptr}{$code} }) {
my $lh = $defptr{$code}{$n}; my $lh = $modules{FS20}{defptr}{$code}{$n};
$lh->{CHANGED}[0] = $v; $lh->{CHANGED}[0] = $v;
$lh->{STATE} = $v; $lh->{STATE} = $v;
$lh->{READINGS}{state}{TIME} = $tn; $lh->{READINGS}{state}{TIME} = $tn;
@ -275,7 +271,7 @@ FS20_Define($$)
my $name = $a[0]; my $name = $a[0];
$hash->{CODE}{$ncode++} = $code; $hash->{CODE}{$ncode++} = $code;
$defptr{$code}{$name} = $hash; $modules{FS20}{defptr}{$code}{$name} = $hash;
for(my $i = 4; $i < int(@a); $i += 2) { for(my $i = 4; $i < int(@a); $i += 2) {
@ -302,7 +298,7 @@ FS20_Define($$)
$code = "$housecode $grpcode"; $code = "$housecode $grpcode";
$hash->{CODE}{$ncode++} = $code; $hash->{CODE}{$ncode++} = $code;
$defptr{$code}{$name} = $hash; $modules{FS20}{defptr}{$code}{$name} = $hash;
} }
AssignIoPort($hash); AssignIoPort($hash);
} }
@ -312,13 +308,15 @@ sub
FS20_Undef($$) FS20_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
foreach my $c (keys %{ $hash->{CODE} } ) { foreach my $c (keys %{ $hash->{CODE} } ) {
$c = $hash->{CODE}{$c}; $c = $hash->{CODE}{$c};
# As after a rename the $name my be different from the $defptr{$c}{$n} # As after a rename the $name my be different from the $defptr{$c}{$n}
# we look for the hash. # we look for the hash.
foreach my $dname (keys %{ $defptr{$c} }) { foreach my $dname (keys %{ $modules{FS20}{defptr}{$c} }) {
delete($defptr{$c}{$dname}) if($defptr{$c}{$dname} == $hash); delete($modules{FS20}{defptr}{$c}{$dname})
if($modules{FS20}{defptr}{$c}{$dname} == $hash);
} }
} }
return undef; return undef;
@ -351,7 +349,7 @@ FS20_Parse($$)
$v = "unknown_$cde" if(!defined($v)); $v = "unknown_$cde" if(!defined($v));
$v .= " $dur" if($dur); $v .= " $dur" if($dur);
my $def = $defptr{"$dev $btn"}; my $def = $modules{FS20}{defptr}{"$dev $btn"};
if($def) { if($def) {
my @list; my @list;
foreach my $n (keys %{ $def }) { foreach my $n (keys %{ $def }) {
@ -364,9 +362,9 @@ FS20_Parse($$)
$lh->{READINGS}{state}{VAL} = $v; $lh->{READINGS}{state}{VAL} = $v;
Log GetLogLevel($n,2), "FS20 $n $v"; Log GetLogLevel($n,2), "FS20 $n $v";
if($follow{$n}) { if($modules{FS20}{ldata}{$n}) {
CommandDelete(undef, $n . "_timer"); CommandDelete(undef, $n . "_timer");
delete $follow{$n}; delete $modules{FS20}{ldata}{$n};
} }
if($v =~ m/for-timer/ && if($v =~ m/for-timer/ &&
defined($attr{$n}) && defined($attr{$n}) &&
@ -374,7 +372,7 @@ FS20_Parse($$)
my $to = sprintf("%02d:%02d:%02d", $dur/3600, ($dur%3600)/60, $dur%60); my $to = sprintf("%02d:%02d:%02d", $dur/3600, ($dur%3600)/60, $dur%60);
Log 4, "Follow: +$to setstate $n off"; Log 4, "Follow: +$to setstate $n off";
CommandDefine(undef, $n . "_timer at +$to setstate $n off"); CommandDefine(undef, $n . "_timer at +$to setstate $n off");
$follow{$n} = $to; $modules{FS20}{ldata}{$n} = $to;
} }
push(@list, $n); push(@list, $n);

View File

@ -111,7 +111,6 @@ my %c2m = (0 => "auto", 1 => "manual", 2 => "holiday", 3 => "holiday_short");
my %m2c; # Reverse c2m my %m2c; # Reverse c2m
my %c2b; # command->button hash (reverse of codes) my %c2b; # command->button hash (reverse of codes)
my %c2bset; # command->button hash (settable values) my %c2bset; # command->button hash (settable values)
my %defptr;
my $defmin = 0; # min fhtbuf free bytes before sending commands my $defmin = 0; # min fhtbuf free bytes before sending commands
my $retryafter = 240; # in seconds, only when fhtsoftbuffer is active my $retryafter = 240; # in seconds, only when fhtsoftbuffer is active
@ -305,7 +304,7 @@ FHT_Define($$)
$hash->{CODE} = $a[2]; $hash->{CODE} = $a[2];
$hash->{CODE} = $a[2]; $hash->{CODE} = $a[2];
$defptr{$a[2]} = $hash; $modules{FHT}{defptr}{$a[2]} = $hash;
$attr{$a[0]}{retrycount} = 3; $attr{$a[0]}{retrycount} = 3;
AssignIoPort($hash); AssignIoPort($hash);
@ -321,7 +320,7 @@ sub
FHT_Undef($$) FHT_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
delete($defptr{$hash->{CODE}}) if($hash && $hash->{CODE}); delete($modules{FHT}{defptr}{$hash->{CODE}}) if($hash && $hash->{CODE});
return undef; return undef;
} }
@ -337,12 +336,12 @@ FHT_Parse($$)
my $val = substr($msg, 26, 2) if(length($msg) > 26); my $val = substr($msg, 26, 2) if(length($msg) > 26);
my $confirm = 0; my $confirm = 0;
if(!defined($defptr{$dev})) { if(!defined($modules{FHT}{defptr}{$dev})) {
Log 3, "FHT Unknown device $dev, please define it"; Log 3, "FHT Unknown device $dev, please define it";
return "UNDEFINED FHT_$dev FHT $dev"; return "UNDEFINED FHT_$dev FHT $dev";
} }
my $def = $defptr{$dev}; my $def = $modules{FHT}{defptr}{$dev};
my $name = $def->{NAME}; my $name = $def->{NAME};
# Short message # Short message

View File

@ -16,8 +16,6 @@ my %codes = (
"e" => "HMS100FIT", "e" => "HMS100FIT",
); );
my %defptr;
##################################### #####################################
sub sub
@ -56,7 +54,7 @@ HMS_Define($$)
$hash->{CODE} = $a[2]; $hash->{CODE} = $a[2];
$defptr{$a[2]} = $hash; $modules{HMS}{defptr}{$a[2]} = $hash;
AssignIoPort($hash); AssignIoPort($hash);
return undef; return undef;
} }
@ -66,8 +64,9 @@ sub
HMS_Undef($$) HMS_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
delete($defptr{$hash->{CODE}}) delete($modules{HMS}{defptr}{$hash->{CODE}})
if(defined($hash->{CODE}) && defined($defptr{$hash->{CODE}})); if(defined($hash->{CODE}) &&
defined($modules{HMS}{defptr}{$hash->{CODE}}));
return undef; return undef;
} }
@ -94,19 +93,19 @@ HMS_Parse($$)
# As the HMS devices change their id on each battery change, we offer # As the HMS devices change their id on each battery change, we offer
# a wildcard too for each type: 100<device-code>, # a wildcard too for each type: 100<device-code>,
my $odev = $dev; my $odev = $dev;
if(!defined($defptr{$dev})) { if(!defined($modules{HMS}{defptr}{$dev})) {
Log 4, "HMS device $dev not defined, using the wildcard device 100$cde"; Log 4, "HMS device $dev not defined, using the wildcard device 100$cde";
$dev = "100$cde"; $dev = "100$cde";
} }
if(!defined($defptr{$dev})) { if(!defined($modules{HMS}{defptr}{$dev})) {
Log 3, "Unknown HMS device $dev/$odev, please define it"; Log 3, "Unknown HMS device $dev/$odev, please define it";
$type = "HMS" if(!$type); $type = "HMS" if(!$type);
$type =~ s/-//; # RM100-2, - is special in fhem names $type =~ s/-//; # RM100-2, - is special in fhem names
return "UNDEFINED ${type}_$odev HMS $odev"; return "UNDEFINED ${type}_$odev HMS $odev";
} }
my $def = $defptr{$dev}; my $def = $modules{HMS}{defptr}{$dev};
my (@v, @txt); my (@v, @txt);

View File

@ -4,7 +4,6 @@ package main;
use strict; use strict;
use warnings; use warnings;
my %defptr;
##################################### #####################################
sub sub
@ -42,7 +41,7 @@ KS300_Define($$)
$hash->{CODE} = $a[2]; $hash->{CODE} = $a[2];
$hash->{RAINUNIT} = $rainunit; $hash->{RAINUNIT} = $rainunit;
$hash->{WINDUNIT} = $windunit; $hash->{WINDUNIT} = $windunit;
$defptr{$a[2]} = $hash; $modules{KS300}{defptr}{$a[2]} = $hash;
AssignIoPort($hash); AssignIoPort($hash);
return undef; return undef;
@ -53,7 +52,7 @@ sub
KS300_Undef($$) KS300_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
delete($defptr{$hash->{CODE}}); delete($modules{KS300}{defptr}{$hash->{CODE}});
return undef; return undef;
} }
@ -81,11 +80,11 @@ KS300_Parse($$)
return ""; return "";
} }
if(int(keys %defptr)) { if(int(keys %{ $modules{KS300}{defptr} })) {
my @arr = keys(%defptr); # No code is known yet my @arr = keys(%{ $modules{KS300}{defptr} }); # No code is known yet
my $dev = shift(@arr); my $dev = shift(@arr);
my $def = $defptr{$dev}; my $def = $modules{KS300}{defptr}{$dev};
my $haverain = 0; my $haverain = 0;
my $name= $def->{NAME}; my $name= $def->{NAME};

View File

@ -4,8 +4,6 @@ package main;
use strict; use strict;
use warnings; use warnings;
my %defptr;
# Supports following devices: # Supports following devices:
# KS300TH (this is redirected to the more sophisticated 14_KS300 by 00_CUL) # KS300TH (this is redirected to the more sophisticated 14_KS300 by 00_CUL)
# S300TH # S300TH
@ -47,7 +45,7 @@ CUL_WS_Define($$)
$hash->{corr2} = ((int(@a) > 4) ? $a[4] : 0); $hash->{corr2} = ((int(@a) > 4) ? $a[4] : 0);
$hash->{corr3} = ((int(@a) > 5) ? $a[5] : 0); $hash->{corr3} = ((int(@a) > 5) ? $a[5] : 0);
$hash->{corr4} = ((int(@a) > 6) ? $a[6] : 0); $hash->{corr4} = ((int(@a) > 6) ? $a[6] : 0);
$defptr{$a[2]} = $hash; $modules{CUL_WS}{defptr}{$a[2]} = $hash;
AssignIoPort($hash); AssignIoPort($hash);
return undef; return undef;
} }
@ -57,7 +55,7 @@ sub
CUL_WS_Undef($$) CUL_WS_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
delete($defptr{$hash->{CODE}}) if($hash && $hash->{CODE}); delete($modules{CUL_WS}{defptr}{$hash->{CODE}}) if($hash && $hash->{CODE});
return undef; return undef;
} }
@ -87,8 +85,8 @@ CUL_WS_Parse($$)
# the name in connection with the receiver's name ("CUL868.1", "CUL433.1") # the name in connection with the receiver's name ("CUL868.1", "CUL433.1")
# See attr <name> IODev XX # See attr <name> IODev XX
my $def = $defptr{$hash->{NAME} . "." . $cde}; my $def = $modules{CUL_WS}{defptr}{$hash->{NAME} . "." . $cde};
$def = $defptr{$cde} if(!$def); $def = $modules{CUL_WS}{defptr}{$cde} if(!$def);
if(!$def) { if(!$def) {
Log 1, "CUL_WS UNDEFINED $type sensor detected, code $cde"; Log 1, "CUL_WS UNDEFINED $type sensor detected, code $cde";
return "UNDEFINED CUL_WS_$cde CUL_WS $cde"; return "UNDEFINED CUL_WS_$cde CUL_WS $cde";
@ -256,8 +254,8 @@ CUL_WS_Attr(@)
my $hash = $defs{$a[1]}; my $hash = $defs{$a[1]};
my $iohash = $defs{$a[3]}; my $iohash = $defs{$a[3]};
my $cde = $hash->{CODE}; my $cde = $hash->{CODE};
delete($defptr{$cde}); delete($modules{CUL_WS}{defptr}{$cde});
$defptr{$iohash->{NAME} . "." . $cde} = $hash; $modules{CUL_WS}{defptr}{$iohash->{NAME} . "." . $cde} = $hash;
return undef; return undef;
} }

View File

@ -4,8 +4,6 @@ package main;
use strict; use strict;
use warnings; use warnings;
my %defptr;
# Adjust TOTAL to you meter: # Adjust TOTAL to you meter:
# {$defs{emwz}{READINGS}{basis}{VAL}=<meter>/<corr2>-<total_cnt> } # {$defs{emwz}{READINGS}{basis}{VAL}=<meter>/<corr2>-<total_cnt> }
@ -63,7 +61,7 @@ CUL_EM_Define($$)
$hash->{CostPerUnit} = (int(@a) > 5 ? $a[5] : 0); $hash->{CostPerUnit} = (int(@a) > 5 ? $a[5] : 0);
$hash->{BasicFeePerMonth} = (int(@a) > 6 ? $a[6] : 0); $hash->{BasicFeePerMonth} = (int(@a) > 6 ? $a[6] : 0);
$defptr{$a[2]} = $hash; $modules{CUL_EM}{defptr}{$a[2]} = $hash;
AssignIoPort($hash); AssignIoPort($hash);
return undef; return undef;
} }
@ -73,7 +71,7 @@ sub
CUL_EM_Undef($$) CUL_EM_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
delete($defptr{$hash->{CODE}}); delete($modules{CUL_EM}{defptr}{$hash->{CODE}});
return undef; return undef;
} }
@ -106,10 +104,10 @@ CUL_EM_Parse($$)
my $val = sprintf("CNT: %d CUM: %d 5MIN: %d TOP: %d", my $val = sprintf("CNT: %d CUM: %d 5MIN: %d TOP: %d",
$seqno, $total_cnt, $current_cnt, $peak_cnt); $seqno, $total_cnt, $current_cnt, $peak_cnt);
if($defptr{$cde}) { if($modules{CUL_EM}{defptr}{$cde}) {
my $def = $defptr{$cde}; my $def = $modules{CUL_EM}{defptr}{$cde};
$hash = $defptr{$cde}; $hash = $def;
my $tn = TimeNow(); # current time my $tn = TimeNow(); # current time
my $c= 0; # count changes my $c= 0; # count changes

View File

@ -4,8 +4,6 @@ package main;
use strict; use strict;
use warnings; use warnings;
my %defptr;
# Adjust TOTAL to you meter: # Adjust TOTAL to you meter:
# {$defs{emwz}{READINGS}{basis}{VAL}=<meter>/<corr2>-<total_cnt> } # {$defs{emwz}{READINGS}{basis}{VAL}=<meter>/<corr2>-<total_cnt> }
@ -45,7 +43,7 @@ CUL_RFR_Define($$)
$a[3] !~ m/[0-9A-F]{2}/i); $a[3] !~ m/[0-9A-F]{2}/i);
$hash->{ID} = $a[2]; $hash->{ID} = $a[2];
$hash->{ROUTERID} = $a[3]; $hash->{ROUTERID} = $a[3];
$defptr{"$a[2]$a[3]"} = $hash; $modules{CUL_RFR}{defptr}{"$a[2]$a[3]"} = $hash;
AssignIoPort($hash); AssignIoPort($hash);
return undef; return undef;
} }
@ -67,7 +65,7 @@ sub
CUL_RFR_Undef($$) CUL_RFR_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
delete($defptr{$hash->{ID} . $hash->{ROUTERID}}); delete($modules{CUL_RFR}{defptr}{$hash->{ID} . $hash->{ROUTERID}});
return undef; return undef;
} }
@ -83,11 +81,11 @@ CUL_RFR_Parse($$)
my ($rid, $id, $smsg) = ($1,$2,$3); my ($rid, $id, $smsg) = ($1,$2,$3);
my $cde = "${id}${rid}"; my $cde = "${id}${rid}";
if(!$defptr{$cde}) { if(!$modules{CUL_RFR}{defptr}{$cde}) {
Log 1, "CUL_RFR detected, Id $id, Router $rid, MSG $smsg"; Log 1, "CUL_RFR detected, Id $id, Router $rid, MSG $smsg";
return "UNDEFINED CUL_RFR_$id CUL_RFR $id $rid"; return "UNDEFINED CUL_RFR_$id CUL_RFR $id $rid";
} }
my $hash = $defptr{$cde}; my $hash = $modules{CUL_RFR}{defptr}{$cde};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
if($smsg =~ m/^T/) { $hash->{NR_TMSG}++ } if($smsg =~ m/^T/) { $hash->{NR_TMSG}++ }

View File

@ -76,8 +76,6 @@ my %functions_set = ( "on" => 0,
"on-till" => 1, "on-till" => 1,
); );
# devices{HOUSE}{UNIT} -> Pointer to hash for the device for lookups
my %devices;
my %models = ( my %models = (
lm12 => 'dimmer', lm12 => 'dimmer',
@ -254,13 +252,13 @@ X10_Define($$)
$hash->{HOUSE} = $housecode; $hash->{HOUSE} = $housecode;
$hash->{UNIT} = $unitcode; $hash->{UNIT} = $unitcode;
if(defined($devices{$housecode}{$unitcode})) { if(defined($modules{X10}{defptr}{$housecode}{$unitcode})) {
return "Error: duplicate X10 device $housecode $unitcode definition " . return "Error: duplicate X10 device $housecode $unitcode definition " .
$hash->{NAME} . " (previous: " . $hash->{NAME} . " (previous: " .
$devices{$housecode}{$unitcode}->{NAME} .")"; $modules{X10}{defptr}{$housecode}{$unitcode}->{NAME} .")";
} }
$devices{$housecode}{$unitcode}= $hash; $modules{X10}{defptr}{$housecode}{$unitcode}= $hash;
AssignIoPort($hash); AssignIoPort($hash);
} }
@ -271,7 +269,7 @@ X10_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
if( defined($hash->{HOUSE}) && defined($hash->{UNIT}) ) { if( defined($hash->{HOUSE}) && defined($hash->{UNIT}) ) {
delete($devices{$hash->{HOUSE}}{$hash->{UNIT}}); delete($modules{X10}{defptr}{$hash->{HOUSE}}{$hash->{UNIT}});
} }
return undef; return undef;
} }
@ -302,8 +300,8 @@ X10_Parse($$)
if($all_lights || $all_units) { if($all_lights || $all_units) {
$function= $functions_rewrite{$function}; # translate, all_lights_on -> on $function= $functions_rewrite{$function}; # translate, all_lights_on -> on
$unitcodes= ""; $unitcodes= "";
foreach my $unitcode (keys %{ $devices{$housecode} } ) { foreach my $unitcode (keys %{ $modules{X10}{defptr}{$housecode} } ) {
my $h= $devices{$housecode}{$unitcode}; my $h= $modules{X10}{defptr}{$housecode}{$unitcode};
my $islampmodule= grep { $_ eq $h->{MODEL} } @lampmodules; my $islampmodule= grep { $_ eq $h->{MODEL} } @lampmodules;
if($all_units || $islampmodule ) { if($all_units || $islampmodule ) {
$unitcodes.= " " if($unitcodes ne ""); $unitcodes.= " " if($unitcodes ne "");
@ -346,7 +344,7 @@ X10_Parse($$)
my $unknown_unitcodes= ''; my $unknown_unitcodes= '';
foreach my $unitcode (@unitcodes) { foreach my $unitcode (@unitcodes) {
my $h= $devices{$housecode}{$unitcode}; my $h= $modules{X10}{defptr}{$housecode}{$unitcode};
if($h) { if($h) {
my $name= $h->{NAME}; my $name= $h->{NAME};
$h->{CHANGED}[0] = $value; $h->{CHANGED}[0] = $value;

View File

@ -28,8 +28,6 @@ use warnings;
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use OW; use OW;
my %defptr;
my %gets = ( my %gets = (
"address" => "", "address" => "",
"alias" => "", "alias" => "",
@ -422,7 +420,7 @@ OWTEMP_Define($$)
$hash->{OW_PATH} = $hash->{OW_FAMILY}.".".$hash->{OW_ID}; $hash->{OW_PATH} = $hash->{OW_FAMILY}.".".$hash->{OW_ID};
$hash->{PRESENT} = 0; $hash->{PRESENT} = 0;
$defptr{$a[2]} = $hash; $modules{OWTEMP}{defptr}{$a[2]} = $hash;
# assign IO port # assign IO port
AssignIoPort($hash); AssignIoPort($hash);
@ -483,7 +481,7 @@ OWTEMP_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
delete($defptr{$hash->{NAME}}); delete($modules{OWTEMP}{defptr}{$hash->{NAME}});
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
return undef; return undef;

View File

@ -39,7 +39,6 @@ package main;
use strict; use strict;
use warnings; use warnings;
my %defptr;
my $DeviceName=""; my $DeviceName="";
my $inbuf=""; my $inbuf="";
@ -117,7 +116,7 @@ WS300_Define($$)
my $po; my $po;
if($a[0] eq "WS300Device") if($a[0] eq "WS300Device")
{ {
$defptr{10} = $hash; $modules{WS300}{defptr}{10} = $hash;
return "wrong syntax: define WS300Device WS300 <DeviceName>" if(int(@a) < 3); return "wrong syntax: define WS300Device WS300 <DeviceName>" if(int(@a) < 3);
$DeviceName = $a[2]; $DeviceName = $a[2];
$hash->{STATE} = "Initializing"; $hash->{STATE} = "Initializing";
@ -164,7 +163,7 @@ WS300_Define($$)
return "no device: define WS300Device WS300 <DeviceName> first" if($DeviceName eq ""); return "no device: define WS300Device WS300 <DeviceName> first" if($DeviceName eq "");
return "Define $a[0]: wrong sensor number." if($a[2] !~ m/^[0-9]$/); return "Define $a[0]: wrong sensor number." if($a[2] !~ m/^[0-9]$/);
$hash->{SENSOR} = $a[2]; $hash->{SENSOR} = $a[2];
$defptr{$a[2]} = $hash; $modules{WS300}{defptr}{$a[2]} = $hash;
return undef; return undef;
} }
@ -175,7 +174,7 @@ WS300_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
return undef if(!defined($hash->{SENSOR})); return undef if(!defined($hash->{SENSOR}));
delete($defptr{$hash->{SENSOR}}); delete($modules{WS300}{defptr}{$hash->{SENSOR}});
return undef; return undef;
} }
@ -253,14 +252,14 @@ WS300_Parse($$)
{ {
my $p=($s*6)+$offs; my $p=($s*6)+$offs;
Log $ll,"Sensor $s vorhanden"; Log $ll,"Sensor $s vorhanden";
if(!defined($defptr{$s})) if(!defined($modules{WS300}{defptr}{$s}))
{ {
Log 3, "WS300 Unknown device $s, please define it"; Log 3, "WS300 Unknown device $s, please define it";
return "UNDEFINED WS300_$s WS300 $s"; return "UNDEFINED WS300_$s WS300 $s";
} }
else else
{ {
$def = $defptr{$s}; $def = $modules{WS300}{defptr}{$s};
$def->{READINGS}{$txt[0]}{VAL} = 0 if(!$def->{READINGS}); $def->{READINGS}{$txt[0]}{VAL} = 0 if(!$def->{READINGS});
$ref = $def->{READINGS}; $ref = $def->{READINGS};
@ -445,14 +444,14 @@ WS300_Parse($$)
} }
} }
} }
if(!defined($defptr{9})) if(!defined($modules{WS300}{defptr}{9}))
{ {
Log 3, "WS300 Unknown device 9, please define it"; Log 3, "WS300 Unknown device 9, please define it";
return "UNDEFINED WS300_9 WS300 9"; return "UNDEFINED WS300_9 WS300 9";
} }
else else
{ {
$def = $defptr{9}; $def = $modules{WS300}{defptr}{9};
$def->{READINGS}{$txt[0]}{VAL} = 0 if(!$def->{READINGS}); $def->{READINGS}{$txt[0]}{VAL} = 0 if(!$def->{READINGS});
$ref = $def->{READINGS}; $ref = $def->{READINGS};

View File

@ -459,3 +459,8 @@
- In order to support automatic device creation (coming 98_autocreate.pm), - In order to support automatic device creation (coming 98_autocreate.pm),
the return value in case of an undefined device should contain parameters the return value in case of an undefined device should contain parameters
for a correct define statement. for a correct define statement.
- Fri Jan 1 2010
- my %defptr is no $modules{modname}{defptr} in order for CommandReload to
work. There is also a second parameter $modules{modname}{ldata} which will
be saved over a Reload, used by the FS20 for the follow feature.

View File

@ -157,7 +157,7 @@ my $nextat; # Time when next timer will be triggered.
my $intAtCnt=0; my $intAtCnt=0;
my %duplicate; # Pool of received msg for multi-fhz/cul setups my %duplicate; # Pool of received msg for multi-fhz/cul setups
my $duplidx=0; # helper for the above pool my $duplidx=0; # helper for the above pool
my $cvsid = '$Id: fhem.pl,v 1.94 2009-12-27 18:07:14 rudolfkoenig Exp $'; my $cvsid = '$Id: fhem.pl,v 1.95 2010-01-01 13:48:33 rudolfkoenig Exp $';
my $namedef = my $namedef =
"where <name> is either:\n" . "where <name> is either:\n" .
"- a single device name\n" . "- a single device name\n" .
@ -1305,9 +1305,16 @@ CommandReload($$)
} }
use strict "refs"; use strict "refs";
my ($defptr, $ldata);
if($modules{$m}) {
$defptr = $modules{$m}{defptr};
$ldata = $modules{$m}{ldata};
}
$modules{$m} = \%hash; $modules{$m} = \%hash;
$modules{$m}{ORDER} = $order; $modules{$m}{ORDER} = $order;
$modules{$m}{LOADED} = 1; $modules{$m}{LOADED} = 1;
$modules{$m}{defptr} = $defptr if($defptr);
$modules{$m}{ldata} = $defptr if($ldata);
return undef; return undef;
} }