From ee9a80cfcb6ff37db82e37d2c5773e1f76bed004 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Mon, 26 Nov 2007 14:56:45 +0000 Subject: [PATCH] Module reorganization / small bugfixes / doc changes git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@110 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- CHANGED | 11 ++++---- FHEM/00_FHZ.pm | 4 +-- FHEM/10_FS20.pm | 64 ++++++++++++++++++++++++++++++++++-------- FHEM/60_EM.pm | 2 +- FHEM/81_M232Counter.pm | 10 ++----- FHEM/98_dummy.pm | 41 +++++++++++++++++++++++++++ FHEM/99_Utils.pm | 1 + FHEM/99_weblink.pm | 34 ---------------------- contrib/README | 4 +++ docs/commandref.html | 34 ++++++++++++++++++---- docs/fhem.html | 8 +++--- fhem.pl | 16 +++++++---- 12 files changed, 151 insertions(+), 78 deletions(-) create mode 100644 FHEM/98_dummy.pm delete mode 100755 FHEM/99_weblink.pm diff --git a/CHANGED b/CHANGED index 635cef004..2d889597c 100644 --- a/CHANGED +++ b/CHANGED @@ -342,22 +342,23 @@ - ==DATE== (4.2) - feature: added archivedir/archivecmd to the the main logfile - feature: 99_Sunrise_EL.pm (does not need any Date modules) - - bugfix: Seldom xmllist error resulting in corrupt xml (Martin/Peter, 4.9) + - bugfix: seldom xmllist error resulting in corrupt xml (Martin/Peter, 4.9) - bugfix: FHT mode holiday_short added (9.9, Dirk) - bugfix: Modifying a device from its own trigger crashes (Klaus, 10.9) - feature: webpgm2 output reformatted - feature: webpgm2 displaying multiple plots - feature: FHT lime-protection code discovered by Dirk (7.10) - - feature: Softwarebuffer for FHT devices (Dirk 17.10) + - feature: softwarebuffer for FHT devices (Dirk 17.10) - feature: FHT low temperatur warning and offset (Dirk 17.10) - - change: Change FHT state into warnings (Dirk 17.10) + - change: change FHT state into warnings (Dirk 17.10) - feature: Softwarebuffer code simplified (Rudi 22.11) - bugfix: bug #12327 doppeltes my - bugfix: set STATE from trigger - bugfix: readings state vs STATE problem (xmllist/trigger) - change: SUNRISE doc changed (99_SUNRISE.pm -> 99_SUNRISE_EL.pm) - - feature: Support for the M232 ELV device (Boris, 25.11) + - feature: support for the M232 ELV device (Boris, 25.11) + - feature: alternativ Quad-based numbers for the FS20 (Matthias, 24.11) + - feature: dummy type added (contrib/99_dummy.pm) - TODO emem -2.5kW / getDevData for emwz -1 - dummy type / dummy attribute diff --git a/FHEM/00_FHZ.pm b/FHEM/00_FHZ.pm index a8ebe0508..801aa2c92 100755 --- a/FHEM/00_FHZ.pm +++ b/FHEM/00_FHZ.pm @@ -69,7 +69,7 @@ FHZ_Initialize($) $hash->{StateFn} = "FHZ_SetState"; $hash->{ParseFn} = "FHZ_Parse"; $hash->{AttrList}= "do_not_notify:1,0 dummy:1,0 filtertimeout repeater:1,0 " . - "showtime:1,0 model:fhz1000,fhz1300 loglevel:0,1,2,3,4,5,6" . + "showtime:1,0 model:fhz1000,fhz1300 loglevel:0,1,2,3,4,5,6 ". "fhtsoftbuffer:1,0"; } @@ -208,7 +208,7 @@ FHZ_Define($$) my $dev = $a[2]; $attr{$name}{savefirst} = 1; - $attr{$name}{fhtsoftbuffer} = 1; + $attr{$name}{fhtsoftbuffer} = 0; if($dev eq "none") { Log 1, "FHZ device is none, commands will be echoed only"; diff --git a/FHEM/10_FS20.pm b/FHEM/10_FS20.pm index 9eee30b94..48e451275 100755 --- a/FHEM/10_FS20.pm +++ b/FHEM/10_FS20.pm @@ -247,15 +247,24 @@ FS20_Define($$) "addr [fg addr] [lm addr] [gm FF]"; return $u if(int(@a) < 4); - return "Define $a[0]: wrong housecode format: specify a 4 digit hex value" - if($a[2] !~ m/^[a-f0-9]{4}$/i); - return "Define $a[0]: wrong btn format: specify a 2 digit hex value" - if($a[3] !~ m/^[a-f0-9]{2}$/i); + return "Define $a[0]: wrong housecode format: specify a 4 digit hex value ". + "or an 8 digit quad value" + if( ($a[2] !~ m/^[a-f0-9]{4}$/i) && ($a[2] !~ m/^[1-4]{8}$/i) ); - $hash->{XMIT} = lc($a[2]); - $hash->{BTN} = lc($a[3]); + return "Define $a[0]: wrong btn format: specify a 2 digit hex value " . + "or a 4 digit quad value" + if( ($a[3] !~ m/^[a-f0-9]{2}$/i) && ($a[3] !~ m/^[1-4]{4}$/i) ); - my $code = lc("$a[2] $a[3]"); + my $housecode = $a[2]; + $housecode = four2hex($housecode,4) if (length($housecode) == 8); + + my $btncode = $a[3]; + $btncode = four2hex($btncode,2) if (length($btncode) == 4); + + $hash->{XMIT} = lc($housecode); + $hash->{BTN} = lc($btncode); + + my $code = "$housecode $btncode"; my $ncode = 1; my $name = $a[0]; @@ -268,16 +277,21 @@ FS20_Define($$) $a[$i] = lc($a[$i]); if($a[$i] eq "fg") { - return "Bad fg address, see the doc" if($a[$i+1] !~ m/^f[a-f0-9]$/); + return "Bad fg address for $name, see the doc" if( ($a[$i+1] !~ m/^f[a-f0-9]$/) && ($a[$i+1] !~ m/^44[1-4][1-4]$/)); } elsif($a[$i] eq "lm") { - return "Bad lm address, see the doc" if($a[$i+1] !~ m/^[a-f0-9]f$/); + return "Bad lm address for $name, see the doc" if( ($a[$i+1] !~ m/^[a-f0-9]f$/) && ($a[$i+1] !~ m/^[1-4][1-4]44$/)); } elsif($a[$i] eq "gm") { - return "Bad gm address, mus be ff" if($a[$i+1] ne "ff"); + return "Bad gm address for $name, must be ff" if( ($a[$i+1] ne "ff") && ($a[$i+1] ne "4444")); } else { return $u; } - $code = lc("$a[2] $a[$i+1]"); + my $grpcode = $a[$i+1]; + if (length($grpcode) == 4) { + $grpcode = four2hex($grpcode,2); + } + + $code = "$housecode $grpcode"; $hash->{CODE}{$ncode++} = $code; $defptr{$code}{$name} = $hash; } @@ -342,12 +356,38 @@ FS20_Parse($$) # it by the second FHZ return "" if($dev eq "0001" && $btn eq "00" && $cde eq "00"); - Log 3, "FS20 Unknown device $dev, Button $btn Code $cde ($v), " . + my $dev_four = hex2four($dev); + my $btn_four = hex2four($btn); + Log 3, "FS20 Unknown device $dev ($dev_four), Button $btn ($btn_four) Code $cde ($v), " . "please define it"; return "UNDEFINED FS20 $dev/$btn/$cde"; } } +############################# +sub +hex2four($) +{ + my $v = shift; + my $r = ""; + foreach my $x (split("", $v)) { + $r .= sprintf("%d%d", (hex($x)/4)+1, (hex($x)%4)+1); + } + return $r; +} + +############################# +sub +four2hex($$) +{ + my ($v,$len) = @_; + my $r = 0; + foreach my $x (split("", $v)) { + $r = $r*4+($x-1); + } + return sprintf("%0*x", $len,$r); +} + 1; diff --git a/FHEM/60_EM.pm b/FHEM/60_EM.pm index 53d21f29a..2557414c5 100755 --- a/FHEM/60_EM.pm +++ b/FHEM/60_EM.pm @@ -28,7 +28,7 @@ EM_Initialize($) $hash->{UndefFn} = "EM_Undef"; $hash->{GetFn} = "EM_Get"; $hash->{SetFn} = "EM_Set"; - $hash->{AttrList}= "model:em1010pc loglevel:0,1,2,3,4,5,6"; + $hash->{AttrList}= "model:em1010pc dummy:1,0 loglevel:0,1,2,3,4,5,6"; } ##################################### diff --git a/FHEM/81_M232Counter.pm b/FHEM/81_M232Counter.pm index 46011316e..221630e56 100644 --- a/FHEM/81_M232Counter.pm +++ b/FHEM/81_M232Counter.pm @@ -31,7 +31,7 @@ M232Counter_GetStatus($) my ($hash) = @_; if(!$hash->{LOCAL}) { - InternalTimer(gettimeofday()+60, "M232Counter_GetStatus", $hash); + InternalTimer(gettimeofday()+60, "M232Counter_GetStatus", $hash, 1); } my $name = $hash->{NAME}; @@ -161,15 +161,9 @@ M232Counter_Define($$) AssignIoPort($hash); - # InternalTimer blocks if init_done is not true - my $oid = $init_done; - $init_done = 1; - if(!$hash->{LOCAL}) { - InternalTimer(gettimeofday()+60, "M232Counter_GetStatus", $hash); + InternalTimer(gettimeofday()+60, "M232Counter_GetStatus", $hash, 0); } - - $init_done = $oid; return undef; } diff --git a/FHEM/98_dummy.pm b/FHEM/98_dummy.pm new file mode 100644 index 000000000..63df8727f --- /dev/null +++ b/FHEM/98_dummy.pm @@ -0,0 +1,41 @@ +############################################## +package main; + +use strict; +use warnings; + +sub +dummy_Initialize($) +{ + my ($hash) = @_; + + $hash->{SetFn} = "dummy_Set"; + $hash->{DefFn} = "dummy_Define"; +} + +################################### +sub +dummy_Set($@) +{ + my ($hash, @a) = @_; + + return "no set value specified" if(int(@a) != 2); + my $v = $a[1]; + $hash->{CHANGED}[0] = $v; + $hash->{STATE} = $v; + $hash->{READINGS}{state}{TIME} = TimeNow(); + $hash->{READINGS}{state}{VAL} = $v; + return undef; +} + +sub +dummy_Define($$) +{ + my ($hash, $def) = @_; + my @a = split("[ \t][ \t]*", $def); + + return "Wrong syntax: use define dummy" if(int(@a) != 2); + return undef; +} + +1; diff --git a/FHEM/99_Utils.pm b/FHEM/99_Utils.pm index 5820ec6ae..f10ddbe30 100644 --- a/FHEM/99_Utils.pm +++ b/FHEM/99_Utils.pm @@ -17,3 +17,4 @@ time_str2num($) return mktime($a[5],$a[4],$a[3],$a[2],$a[1]-1,$a[0]-1900,0,0,-1); } +1; diff --git a/FHEM/99_weblink.pm b/FHEM/99_weblink.pm deleted file mode 100755 index 99c7fe1e9..000000000 --- a/FHEM/99_weblink.pm +++ /dev/null @@ -1,34 +0,0 @@ -############################################## -package main; - -use strict; -use warnings; - -##################################### -sub -weblink_Initialize($) -{ - my ($hash) = @_; - - $hash->{DefFn} = "weblink_Define"; -} - - -##################################### -sub -weblink_Define($$) -{ - my ($hash, $def) = @_; - my ($type, $name, $wltype, $link) = split("[ \t]+", $def, 4); - my %thash = ( link=>1, fileplot=>1 ); - - if(!$link || !$thash{$wltype}) { - return "Usage: define weblink [" . join("|",sort keys %thash) . "] "; - } - $hash->{WLTYPE} = $wltype; - $hash->{LINK} = $link; - $hash->{STATE} = "initial"; - return undef; -} - -1; diff --git a/contrib/README b/contrib/README index 3d906ad32..4313d4139 100755 --- a/contrib/README +++ b/contrib/README @@ -14,6 +14,10 @@ skeleton for self-written perl funtions. - 99_ALARM.pm Example for a Low Budget ALARM System by Martin +- 99_dummy.pm + Used for programming +- 99_weblink.pm + Used by fhemweb2.pl - checkmsg.pl Check header/function/crc of an FS20 hex message - crc.pl diff --git a/docs/commandref.html b/docs/commandref.html index d9e89c3a7..cff6e800f 100644 --- a/docs/commandref.html +++ b/docs/commandref.html @@ -946,15 +946,37 @@ split in multiple lines

Notes:
    - Normally you won't have to define fileplot weblinks manually, as fhemweb.pl - (webpgm2) makes it easy for you, just plot a logfile (see logtype) and convert it to weblink. Now you can - group these weblinks by putting them into rooms. - If you convert the current logfile to a weblink, it will always refer to the - current file (and not the one you originally specified). +
  • Normally you won't have to define fileplot weblinks manually, as + fhemweb.pl (webpgm2) makes it easy for you, just plot a logfile (see + logtype) and convert it to weblink. Now you + can group these weblinks by putting them into rooms. If you convert + the current logfile to a weblink, it will always refer to the current + file (and not the one you originally specified).
  • +
  • The 99_weblink.pm module is in the contrib directory, you have + to "install" it manually by copying it into the FHEM directory.
+ +

Type dummy

+
    + define <name> dummy +

    + + Define a dummy. A dummy can take via set any values. + Used for programming. + Example: +
      + define myvar dummy
      + set myvar 7
      +
    + Notes: +
      +
    • The 99_dummy.pm module is in the contrib directory, you have + to "install" it manually by copying it into the FHEM directory.
    • +
    > +
+ diff --git a/docs/fhem.html b/docs/fhem.html index 844761148..1f8d2bee3 100644 --- a/docs/fhem.html +++ b/docs/fhem.html @@ -164,11 +164,11 @@ description and faq.html for the F.A.Q. else everybody will be able to set your devices -

Web frontend 2 (webfrontend/pgm2, the simple one)

+

Web frontend 2 (webfrontend/pgm2)

    This frontend is CGI/CSS based. It has support for rooms, and FHT/KS300 logs.
    - Screenshots: overview, details - and KS300 temperature logs

    + Screenshots: one, two. +

    • Copy the file fhemweb.pl and *.gplot to your cgi-bin directory @@ -189,7 +189,7 @@ description and faq.html for the F.A.Q. For special features like assigning devices to rooms see the README file.
    -

    Web frontend 3 (webfrontend/pgm3, the professional one)

    +

    Web frontend 3 (webfrontend/pgm3)

      This frontend is PHP based and was contributed by Martin Haas. Look at the webfrontends/pgm3/docs for more documentation or at diff --git a/fhem.pl b/fhem.pl index ec0cde85d..ab4fbc714 100755 --- a/fhem.pl +++ b/fhem.pl @@ -135,7 +135,7 @@ my %intAt; # Internal at timer hash. my $intAtCnt=0; my $reread_active = 0; my $AttrList = "room comment"; -my $cvsid = '$Id: fhem.pl,v 1.29 2007-11-26 08:27:04 rudolfkoenig Exp $'; +my $cvsid = '$Id: fhem.pl,v 1.30 2007-11-26 14:56:45 rudolfkoenig Exp $'; $init_done = 0; @@ -745,9 +745,13 @@ CommandSave($$) print SFH "\ndefattr" . ($r ne "~" ? " room $r" : "") . "\n"; foreach my $d (sort keys %{$rooms{$r}} ) { next if($defs{$d}{VOLATILE}); - my $def = $defs{$d}{DEF}; - $def =~ s/;/;;/g; - print SFH "define $d $defs{$d}{TYPE} $def\n"; + if($defs{$d}{DEF}) { + my $def = $defs{$d}{DEF}; + $def =~ s/;/;;/g; + print SFH "define $d $defs{$d}{TYPE} $def\n"; + } else { + print SFH "define $d $defs{$d}{TYPE}\n"; + } foreach my $a (sort keys %{$attr{$d}}) { next if($a eq "room"); print SFH "attr $d $a $attr{$d}{$a}\n"; @@ -915,7 +919,7 @@ CommandDefine($$) $hash{NAME} = $a[0]; $hash{TYPE} = $a[1]; $hash{STATE} = "???"; - $hash{DEF} = $a[2]; + $hash{DEF} = $a[2] if(int(@a) > 2); $hash{NR} = $devcount++; # If the device wants to issue initialization gets/sets, then it needs to be @@ -1233,7 +1237,7 @@ CommandAttr($$) my $list = getAllAttr($a[0]); return "Unknown argument $a[1], choose one of $list" if($a[1] eq "?"); - return "Unknown attribute $a[1], use attr global userattr" + return "Unknown attribute $a[1], use attr global userattr ($list)" if(" $list " !~ m/ ${a[1]}[ :;]/);