From 01df83ad642dcf8f864234511e92d2af1d44efec Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sun, 6 Nov 2016 18:22:36 +0000 Subject: [PATCH] 16_STACKABLE_CC.pm: add TCM option (Forum #60028) git-svn-id: https://svn.fhem.de/fhem/trunk@12515 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/16_STACKABLE_CC.pm | 54 +++++++++++++++++++++++++++++++----- fhem/FHEM/DevIo.pm | 12 ++++++-- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/fhem/FHEM/16_STACKABLE_CC.pm b/fhem/FHEM/16_STACKABLE_CC.pm index e7b68b6fb..5ebea1c45 100644 --- a/fhem/FHEM/16_STACKABLE_CC.pm +++ b/fhem/FHEM/16_STACKABLE_CC.pm @@ -26,6 +26,10 @@ STACKABLE_CC_Initialize($) $hash->{DelPrefix} = "STACKABLE_CC_DelPrefix"; $hash->{noRawInform} = 1; # Our message was already sent as raw. $hash->{noAutocreatedFilelog} = 1; + + $hash->{IOOpenFn} = "STACKABLE_IOOpenFn"; + $hash->{IOReadFn} = "STACKABLE_IOReadFn"; + $hash->{IOWriteFn} = "STACKABLE_IOWriteFn"; } ##################################### @@ -35,7 +39,9 @@ STACKABLE_CC_Define($$) my ($hash, $def) = @_; my @a = split("[ \t][ \t]*", $def); - return "wrong syntax: define STACKABLE_CC [CUL|SCC]" + $hash->{TCM} = pop @a if(int(@a) == 4 && $a[3] eq "TCM"); + + return "wrong syntax: define STACKABLE_CC [CUL|SCC] [TCM]" if(int(@a) != 3); my $io = $defs{$a[2]}; @@ -48,15 +54,19 @@ STACKABLE_CC_Define($$) $io->{STACKED} = $hash->{NAME}; $hash->{IODev} = $io; delete($io->{".clientArray"}); # Force a recompute - $hash->{initString} = $io->{initString}; - $hash->{CMDS} = ""; - $hash->{Clients} = $io->{Clients}; - $hash->{MatchList} = $io->{MatchList}; + + if(!$hash->{TCM}) { + $hash->{initString} = $io->{initString}; + $hash->{CMDS} = ""; + $hash->{Clients} = $io->{Clients}; + $hash->{MatchList} = $io->{MatchList}; + CUL_DoInit($hash); + } + $hash->{StackLevel} = $io->{StackLevel} ? $io->{StackLevel}+1 : 1; $hash->{STATE} = "Defined"; notifyRegexpChanged($hash, $a[2]); - CUL_DoInit($hash); return undef; } @@ -123,7 +133,7 @@ STACKABLE_CC_Parse($$) } sub -STACKABLE_CC_DelPrefix($) +STACKABLE_CC_DelPrefix($$) { my ($hash, $msg) = @_; $msg =~ s/^.//; @@ -146,6 +156,36 @@ STACKABLE_CC_Undef($$) return undef; } +sub +STACKABLE_IOOpenFn($) +{ + my ($hash) = @_; + $hash->{FD} = $hash->{IODev}{IODev}{FD}; # Lets fool the TCM + $hash->{IOReadFn} = "STACKABLE_IOReadFn"; + return 1; +} + +sub +STACKABLE_IOReadFn($) +{ + my ($hash) = @_; + my $me = $hash->{IODev}; + my $buf = ""; + while($buf !~ m/\n/) { + $buf .= DevIo_SimpleRead($me->{IODev}); # may block + } + $buf =~ s/[\r\n]//g; + $buf = STACKABLE_CC_DelPrefix($me, $buf); + return pack("H*",$buf); +} + +sub +STACKABLE_IOWriteFn($$) +{ + my ($hash, $msg) = @_; + return IOWrite($hash, "", unpack("H*",$msg)); +} + 1; diff --git a/fhem/FHEM/DevIo.pm b/fhem/FHEM/DevIo.pm index 22ba0a4f5..6bcb7c249 100644 --- a/fhem/FHEM/DevIo.pm +++ b/fhem/FHEM/DevIo.pm @@ -39,9 +39,15 @@ DevIo_DoSimpleRead($) $buf = "" if(!defined($res)); } elsif($hash->{IODev}) { - $buf = $hash->{IODevRxBuffer}; - $hash->{IODevRxBuffer} = ""; - $buf = "" if(!defined($buf)); + + if($hash->{IOReadFn}) { + $buf = CallFn($hash->{IODev}{NAME},"IOReadFn",$hash); + + } else { + $buf = $hash->{IODevRxBuffer}; + $hash->{IODevRxBuffer} = ""; + $buf = "" if(!defined($buf)); + } } return $buf;