From 31db2f4851718a033436165a04d31bc20fbcd2f5 Mon Sep 17 00:00:00 2001 From: mgehre Date: Tue, 19 Feb 2013 01:03:50 +0000 Subject: [PATCH] CUL_MAX: Warn when no IODev is set git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2764 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/14_CUL_MAX.pm | 55 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/FHEM/14_CUL_MAX.pm b/FHEM/14_CUL_MAX.pm index ab07cf5e4..43fb37952 100644 --- a/FHEM/14_CUL_MAX.pm +++ b/FHEM/14_CUL_MAX.pm @@ -41,6 +41,32 @@ CUL_MAX_Initialize($) } ############################# + +sub +CUL_MAX_SetupCUL($) +{ + my $hash = $_[0]; + AssignIoPort($hash); + if(!defined($hash->{IODev})) { + Log 1, "$hash->{NAME}: did not find suitable IODev (CUL etc. in rfmode MAX)! You may want to execute 'attr $hash->{NAME} IODev SomeCUL'"; + return 0; + } + + if(CUL_MAX_Check($hash) >= 152) { + #Doing this on older firmware disables MAX mode + IOWrite($hash, "", "Za". $hash->{addr}); + #Append to initString, so this is resend if cul disappears and then reappears + $hash->{IODev}{initString} .= "\nZa". $hash->{addr}; + } + if(CUL_MAX_Check($hash) >= 153) { + #Doing this on older firmware disables MAX mode + my $cmd = "Zw". CUL_MAX_fakeWTaddr($hash); + IOWrite($hash, "", $cmd); + $hash->{IODev}{initString} .= "\n".$cmd; + } + return 1 +} + sub CUL_MAX_Define($$) { @@ -61,20 +87,7 @@ CUL_MAX_Define($$) $hash->{pairmode} = 0; $hash->{retryCount} = 0; $hash->{sendQueue} = []; - AssignIoPort($hash); - - if(CUL_MAX_Check($hash) >= 152) { - #Doing this on older firmware disables MAX mode - IOWrite($hash, "", "Za". $hash->{addr}); - #Append to initString, so this is resend if cul disappears and then reappears - $hash->{IODev}{initString} .= "\nZa". $hash->{addr}; - } - if(CUL_MAX_Check($hash) >= 153) { - #Doing this on older firmware disables MAX mode - my $cmd = "Zw". CUL_MAX_fakeWTaddr($hash); - IOWrite($hash, "", $cmd); - $hash->{IODev}{initString} .= "\n".$cmd; - } + CUL_MAX_SetupCUL($hash); #This interface is shared with 00_MAXLAN.pm $hash->{Send} = \&CUL_MAX_Send; @@ -370,6 +383,20 @@ CUL_MAX_SendQueueHandler($) return if(!@{$hash->{sendQueue}}); #nothing to do my $timeout = gettimeofday(); #reschedule immediatly + + #Check if we have an IODev + if(!defined($hash->{IODev})) { + Log 1, "$hash->{NAME}: did not find suitable IODev (CUL etc. in rfmode MAX), cannot send! You may want to execute 'attr $hash->{NAME} IODev SomeCUL'"; + #Maybe some CUL will appear magically in some seconds + #At least we cannot quit here with an non-empty queue, so we have two alternatives: + #1. Delete the packet from queue and quit -> packet is lost + #2. Wait, recheck, wait, recheck ... -> a lot of logs + + #InternalTimer($timeout+60, "CUL_MAX_SendQueueHandler", $hash, 0); + $hash->{sendQueue} = []; + return undef; + } + my $packet = $hash->{sendQueue}[0]; if( $packet->{sent} == 0 ) { #Need to send it first