mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-01 20:20:10 +00:00
Sequence added
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@386 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
3c4e69d998
commit
1a8adf7907
@ -87,7 +87,7 @@ CUL_Define($$)
|
||||
my $name = $a[0];
|
||||
my $dev = $a[2];
|
||||
return "FHTID must be H1H2, with H1 and H2 hex and both smaller than 64"
|
||||
if($a[3] !~ m/^[0-6]\d[0-6]\d$/);
|
||||
if(uc($a[3]) !~ m/^[0-6][0-9A-F][0-6][0-9A-F]$/);
|
||||
$hash->{FHTID} = uc($a[3]);
|
||||
$hash->{MOBILE} = 1 if($a[4] && $a[4] eq "mobile");
|
||||
$hash->{STATE} = "defined";
|
||||
@ -555,6 +555,8 @@ CUL_SimpleWrite($$)
|
||||
my ($hash, $msg) = @_;
|
||||
return if(!$hash || !defined($hash->{PortObj}));
|
||||
$hash->{PortObj}->write($msg . "\n");
|
||||
#Log 1, "CUL_SimpleWrite $msg";
|
||||
select(undef, undef, undef, 0.01);
|
||||
}
|
||||
|
||||
#####################################
|
||||
@ -581,7 +583,7 @@ CUL_Write($$$)
|
||||
while(length($msg) > $moff) {
|
||||
my $snd = substr($msg,6,4) .
|
||||
substr($msg,$moff,2) . "79" . substr($msg,$moff+2,2);
|
||||
$hash->{PortObj}->write("T$snd\n");
|
||||
CUL_SimpleWrite($hash, "T$snd");
|
||||
$moff += 4;
|
||||
}
|
||||
return;
|
||||
|
@ -267,6 +267,7 @@ FHT_SetState($$$$)
|
||||
{
|
||||
my ($hash, $tim, $vt, $val) = @_;
|
||||
|
||||
return "Ignoring FHZ state" if($vt =~ m/^FHZ:/);
|
||||
$vt =~ s/^FHZ://;
|
||||
return "Undefined type $vt" if(!defined($c2b{$vt}));
|
||||
return undef;
|
||||
|
117
FHEM/91_sequence.pm
Executable file
117
FHEM/91_sequence.pm
Executable file
@ -0,0 +1,117 @@
|
||||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
|
||||
#####################################
|
||||
sub
|
||||
sequence_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{DefFn} = "sequence_Define";
|
||||
$hash->{UndefFn} = "sequence_Undef";
|
||||
$hash->{NotifyFn} = "sequence_Notify";
|
||||
$hash->{AttrList} = "disable:0,1 loglevel:0,1,2,3,4,5,6";
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
# define sq1 sequence reg1 [timeout reg2]
|
||||
sub
|
||||
sequence_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @def = split("[ \t]+", $def);
|
||||
|
||||
my $name = shift(@def);
|
||||
my $type = shift(@def);
|
||||
|
||||
return "Usage: define <name> sequence <re1> <timeout1> <re2> ".
|
||||
"[<timeout2> <re3> ...]"
|
||||
if(int(@def) % 2 == 0 || int(@def) < 3);
|
||||
|
||||
# "Syntax" checking
|
||||
for(my $i = 0; $i < int(@def); $i += 2) {
|
||||
my $re = $def[$i];
|
||||
my $to = $def[$i+1];
|
||||
eval { "Hallo" =~ m/^$re$/ };
|
||||
return "Bad regexp 1: $@" if($@);
|
||||
return "Bad timeout spec $to"
|
||||
if(defined($to) && $to !~ m/^\d*.?\d$/);
|
||||
}
|
||||
|
||||
$hash->{RE} = $def[0];
|
||||
$hash->{IDX} = 0;
|
||||
$hash->{MAX} = int(@def);
|
||||
$hash->{STATE} = "initialized";
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
sequence_Notify($$)
|
||||
{
|
||||
my ($hash, $dev) = @_;
|
||||
|
||||
my $ln = $hash->{NAME};
|
||||
return "" if($attr{$ln} && $attr{$ln}{disable});
|
||||
|
||||
my $n = $dev->{NAME};
|
||||
my $re = $hash->{RE};
|
||||
my $max = int(@{$dev->{CHANGED}});
|
||||
|
||||
for (my $i = 0; $i < $max; $i++) {
|
||||
my $s = $dev->{CHANGED}[$i];
|
||||
$s = "" if(!defined($s));
|
||||
next if($n !~ m/^$re$/ && "$n:$s" !~ m/^$re$/);
|
||||
|
||||
RemoveInternalTimer($ln);
|
||||
my $idx = $hash->{IDX} + 2;
|
||||
Log GetLogLevel($ln,5), "sequence $ln matched $idx";
|
||||
my @d = split("[ \t]+", $hash->{DEF});
|
||||
|
||||
|
||||
if($idx > $hash->{MAX}) { # Last element reached
|
||||
|
||||
Log GetLogLevel($ln,5), "sequence $ln triggered";
|
||||
DoTrigger($ln, "trigger");
|
||||
$idx = 0;
|
||||
|
||||
} else {
|
||||
|
||||
$hash->{RE} = $d[$idx];
|
||||
my $nt = gettimeofday() + $d[$idx-1];
|
||||
InternalTimer($nt, "sequence_Trigger", $ln, 0);
|
||||
|
||||
}
|
||||
|
||||
$hash->{IDX} = $idx;
|
||||
$hash->{RE} = $d[$idx];
|
||||
last;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
sub
|
||||
sequence_Trigger($)
|
||||
{
|
||||
my ($ln) = @_;
|
||||
my $hash = $defs{$ln};
|
||||
my @d = split("[ \t]+", $hash->{DEF});
|
||||
$hash->{RE} = $d[0];
|
||||
$hash->{IDX} = 0;
|
||||
Log GetLogLevel($ln,5), "sequence $ln timeout";
|
||||
}
|
||||
|
||||
sub
|
||||
sequence_Undef($$)
|
||||
{
|
||||
my ($hash, $name) = @_;
|
||||
RemoveInternalTimer($name);
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
Loading…
x
Reference in New Issue
Block a user