Autor Thema: Patch/Erweiterung für 10_IT.pm  (Gelesen 2682 mal)

Offline mehf

  • Jr. Member
  • **
  • Beiträge: 78
Patch/Erweiterung für 10_IT.pm
« am: 03 September 2013, 22:37:01 »
Hallo odroegehorn,

für die Erweiterung des Moduls zum empfangen von IT-messages via CUL möchte ich folgenden Patch zur Verfügung stellen:

siehe Link


--- /tmp/10_IT-HEAD.pm
+++ /home/martin/src/fhemsvn/fhem/FHEM/10_IT.pm
 
@@ -29,7 +29,11 @@
     itswitch    => 'simple',
     itdimmer    => 'dimmer',
 );
-
+my %bintotristate=(
+  "00" => "0",
+  "01" => "F",
+  "11" => "1"
+);
 sub
 IT_Initialize($)
 {
@@ -39,12 +43,12 @@
     $it_c2b{$codes{$k}} = $k;
   }
 
-#  $hash->{Match}     = "";
+  $hash->{Match}     = "^i......\$";
   $hash->{SetFn}     = "IT_Set";
   $hash->{StateFn}   = "IT_SetState";
   $hash->{DefFn}     = "IT_Define";
   $hash->{UndefFn}   = "IT_Undef";
-#  $hash->{ParseFn}   = "IT_Parse";
+  $hash->{ParseFn}   = "IT_Parse";
   $hash->{AttrList}  = "IODev ITfrequency ITrepetition switch_rfmode:1,0 do_not_notify:1,0 ignore:0,1 dummy:1,0 model:itremote,itswitch,itdimmer loglevel:0,1,2,3,4,5,6";
 
 }

@@ -300,7 +304,60 @@
 sub
 IT_Parse($$)
 {
-
+  my ($hash, $msg) = @_;
+  my $housecode;
+  my $cmdcode;
+  my $def;
+  my $newstate;
+  my @list;
+  if (length($msg) != 7) {
+    Log3 undef,3,"message \"$msg\" to short!";
+    return "message \"$msg\" to short!";
+  }
+  # convert hex -> binary
+  my $bin=sprintf("%024b",hex(substr($msg,1,length($msg)-1)));
+  #convert binary -> tristate
+  my $msgcode="";
+  while (length($bin)>=2) {
+    if (substr($bin,0,2) != "10") {
+      $msgcode=$msgcode.$bintotristate{substr($bin,0,2)};
+    } else {
+      Log3 undef,4,"unknown tristate in \"$bin\"";
+      return "unknown tristate in \"$bin\""
+    }
+    $bin=substr($bin,2,length($bin)-2);
+  }
+  
+  $housecode=substr($msgcode,0,length($msgcode)-2);
+  $cmdcode=substr($msgcode,length($msgcode)-2,2);
+
+  #Log3 $hash,3,$msg."->".$msgcode."->".$housecode." ".$cmdcode;
+  if(!defined($modules{IT}{defptr}{lc($housecode)})) {
+    Log3 undef,3,"$housecode not defined!";
+    return "$housecode not defined!";
+  }
+  $def=$modules{IT}{defptr}{lc($housecode)};
+
+  foreach my $name (keys %{$def}) {
+    if ($def->{$name}->{$it_c2b{"on"}} eq lc($cmdcode)) {
+      # ON cmd
+      $newstate="on";
+    } elsif ($def->{$name}->{$it_c2b{"off"}} eq lc($cmdcode)) {
+      #OFF cmd
+      $newstate="off";
+    }
+    # dim cmds not yet supported
+    # elsif ($def->{$name}->{$it_c2b{"dimup"}} eq lc($cmdcode)) {
+    else {
+      Log3 $def->{$name}{NAME},3,"Code $cmdcode not supported by $def->{$name}{NAME}.";
+      next;
+    }
+    Log3 $def->{$name}{NAME},3,"$def->{$name}{NAME} ".$def->{$name}->{STATE}."->".$newstate;
+    push(@list,$def->{$name}{NAME});
+    readingsSingleUpdate($def->{$name},"state",$newstate,1);
+    
+  }
+  return @list;
 }
 
 1;
@@ -312,8 +369,7 @@
 <h3>IT - InterTechno</h3>
 <ul>
   The InterTechno 433MHZ protocol is used by a wide range of devices, which are either of
-  the sender/sensor category or the receiver/actuator category. As we right now are only
-  able to SEND InterTechno commands, but CAN'T receive them, this module at the moment
+  the sender/sensor category or the receiver/actuator category. This module at the moment
   supports just  devices like switches, dimmers, etc. through an <a href="#CUL">CUL</a> device, so this must be defined first.
 
   <br><br>



Viele Grüße
Martin

 

decade-submarginal