2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

OT2 add level, add AES key to HMLAN

git-svn-id: https://svn.fhem.de/fhem/trunk@3965 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
martinp876 2013-09-26 20:57:19 +00:00
parent 30370a2bbd
commit 74bc61e7ae
4 changed files with 59 additions and 14 deletions

View File

@ -6,6 +6,7 @@ package main;
use strict;
use warnings;
use Time::HiRes qw(gettimeofday time);
use Digest::MD5 qw(md5);
sub HMLAN_Initialize($);
sub HMLAN_Define($$);
@ -61,7 +62,7 @@ sub HMLAN_Initialize($) {
$hash->{UndefFn} = "HMLAN_Undef";
$hash->{AttrList}= "do_not_notify:1,0 dummy:1,0 " .
"loglevel:0,1,2,3,4,5,6 addvaltrigger " .
"hmId hmKey " .
"hmId hmKey hmKey2 hmKey3 " .
"respTime wdStrokeTime:5,10,15,20,25 " .
"hmProtocolEvents:0_off,1_dump,2_dumpFull,3_dumpTrigger ".
"hmLanQlen:1_min,2_low,3_normal,4_high,5_critical ".
@ -144,6 +145,26 @@ sub HMLAN_Attr(@) {#################################
$defs{$name}{helper}{q}{hmLanQlen} = 1;
}
}
elsif($attrName =~ m /^hmKey/){
my $retVal= "";
if ($cmd eq "set"){
$attr{$name}{$attrName} = ($aVal =~ m /^[0-9A-Fa-f]{32}$/ )?
$aVal:
unpack('H*', md5($aVal));
$retVal = "$attrName set to $attr{$name}{$attrName}";
}
else{
delete $attr{$name}{$attrName};
}
my ($k1,$k2,$k3) =( AttrVal($name,"hmKey","")
,AttrVal($name,"hmKey2","")
,AttrVal($name,"hmKey3","")
);
HMLAN_SimpleWrite($defs{$name}, "Y01,".($k1?"01,$k1":"00,"));
HMLAN_SimpleWrite($defs{$name}, "Y02,".($k2?"02,$k2":"00,"));
HMLAN_SimpleWrite($defs{$name}, "Y03,".($k3?"03,$k3":"00,"));
return $retVal;
}
return;
}
@ -747,6 +768,13 @@ sub HMLAN_condUpdate($$) {#####################################################
<li><a href="#loglevel">loglevel</a></li><br>
<li><a href="#addvaltrigger">addvaltrigger</a></li><br>
<li><a href="#hmId">hmId</a></li><br>
<li><a href="#hmKey">hmKey</a></li><br>
<li><a href="#hmKey2">hmKey2</a></li><br>
<li><a href="#hmKey3">hmKey3</a><br>
AES keys for the HMLAN adapter. <br>
The key is converted to a hash. If a hash is given directly it is not converted but taken directly.
Therefore the original key cannot be converted back<br>
</li>
<li><a href="#hmProtocolEvents">hmProtocolEvents</a></li><br>
<li><a href="#respTime">respTime</a><br>
Define max response time of the HMLAN adapter in seconds. Default is 1 sec.<br/>

View File

@ -898,7 +898,7 @@ sub CUL_HM_Parse($$) {##############################
push @event, "battery:".($err&0x80?"low":"ok") if (defined $err);
}
}
elsif($st eq "KFM100" && $md eq "KFM-Sensor") { ###########################
elsif($md eq "KFM-Sensor") { ################################################
if ($mTp eq "53"){
if($p =~ m/.14(.)0200(..)(..)(..)/) {
my ($seq, $k_v1, $k_v2, $k_v3) = (hex($1),$2,hex($3),hex($4));
@ -961,14 +961,16 @@ sub CUL_HM_Parse($$) {##############################
my ($a,$d) = unpack 'A2A4',$_;
$d = hex($d);
$d -= 0x10000 if($d & 0xC000);
$d = sprintf("T: %0.1f",$d/10);
$d = sprintf("%0.1f",$d/10);
my $chId = sprintf("%02X",hex($a) & 0x3f);
if($modules{CUL_HM}{defptr}{$src.$chId}){
push @entities,CUL_HM_UpdtReadSingle($modules{CUL_HM}{defptr}{$src.$chId}
,'state',$d,1);
my $chnHash = $modules{CUL_HM}{defptr}{$src.$chId};
if ($chnHash){
push @entities,CUL_HM_UpdtReadBulk($chnHash,1
,"state:T: $d"
,"temperature:$d");
}
else{
push @event, "Chan_$chId:$d";
push @event, "Chan_$chId:T: $d";
}
}
}
@ -2410,7 +2412,7 @@ sub CUL_HM_Set($@) {
.(($reg->{l} == 3)?" peer required":"")." : ".$reg->{t}."\n"
if ($data eq "?");
return "value:".$data." out of range for Reg \"".$regName."\""
if (!($reg->{c} eq 'lit'||$reg->{c} eq 'hex')&&
if (!($reg->{c} =~ m/^(lit|hex|min2time)$/)&&
($data < $reg->{min} ||$data > $reg->{max})); # none number
return"invalid value. use:". join(",",keys%{$reg->{lit}})
if ($reg->{c} eq 'lit' && !defined($reg->{lit}{$data}));
@ -2420,6 +2422,7 @@ sub CUL_HM_Set($@) {
if (!$conversion){;# do nothing
}elsif($conversion eq "fltCvT" ){$data = CUL_HM_fltCvT($data);
}elsif($conversion eq "fltCvT60"){$data = CUL_HM_fltCvT60($data);
}elsif($conversion eq "min2time"){$data = CUL_HM_time2min($data);
}elsif($conversion eq "m10s3") {$data = $data*10-3;
}elsif($conversion eq "hex") {$data = hex($data);
}elsif($conversion eq "lit") {$data = $reg->{lit}{$data};
@ -3959,6 +3962,7 @@ sub CUL_HM_getRegFromStore($$$$@) {#read a register from backup data
} elsif($conversion eq "lit" ){$data = $reg->{litInv}{$data}?$reg->{litInv}{$data}:"undef lit";
} elsif($conversion eq "fltCvT" ){$data = CUL_HM_CvTflt($data);
} elsif($conversion eq "fltCvT60"){$data = CUL_HM_CvTflt60($data);
} elsif($conversion eq "min2time"){$data = CUL_HM_min2time($data);
} elsif($conversion eq "m10s3" ){$data = ($data+3)/10;
} elsif($conversion eq "hex" ){$data = sprintf("0x%X",$data);
} else { return " conversion undefined - please contact admin";
@ -4175,6 +4179,19 @@ sub CUL_HM_CvTflt($) { # config time -> float
my ($inValue) = @_;
return ($inValue & 0x1f)*((sort {$a <=> $b} keys(%fltCvT))[$inValue >> 5]);
}
sub CUL_HM_min2time($) { # minutes -> time
my $min = shift;
$min = $min * 30;
return sprintf("%02d:%02d",int($min/60),$min%60);
}
sub CUL_HM_time2min($) { # minutes -> time
my $time = shift;
my ($h,$m) = split ":",$time;
$m = ($h*60 + $m)/30;
$m = 0 if($m < 0);
$m = 47 if($m > 47);
return $m;
}
sub CUL_HM_4DisText($) {# convert text for 4dis
#text1: start at 54 (0x36) length 12 (0x0c)

View File

@ -329,11 +329,11 @@ sub HMinfo_SetFn($@) {#########################################################
my $dispDest = $dest;
if ($dest =~ m/^at_(.*)/){
$dispName = $1;
$dispName =~ s/^rpt_//;
# $dispName =~ s/^rpt_//;
$dispDest = (($dest =~ m/^to_rpt_/)?"rep_":"").$dName;
}
push @rssiList,sprintf("%-15s %-15s %6.1f %6.1f %6.1f<%6.1f %3s"
,$dispName,$dispDest
push @rssiList,sprintf("%-15s:%-15s %-15s %6.1f %6.1f %6.1f<%6.1f %5s"
,$dName,$dispName,$dispDest
,$defs{$dName}{helper}{rssi}{$dest}{lst}
,$defs{$dName}{helper}{rssi}{$dest}{avg}
,$defs{$dName}{helper}{rssi}{$dest}{min}
@ -342,7 +342,7 @@ sub HMinfo_SetFn($@) {#########################################################
);
}
}
$ret = $cmd." done:"."\n "."receive from last avg min<max count"
$ret = $cmd." done:"."\n "."Device :receive from last avg min<max count"
."\n ".(join "\n ",sort @rssiList)
;
}

View File

@ -544,8 +544,8 @@ my %culHmRegDefine = (
tempMax =>{a=> 4 ,s=>0.6,l=>7,min=>15 ,max=>30.5 ,c=>'' ,f=>'2' ,u=>'' ,d=>1,t=>"maximum temperatur"},
tempFallWinOpen =>{a=> 5 ,s=>0.6,l=>7,min=>5 ,max=>30 ,c=>'' ,f=>'2' ,u=>'' ,d=>1,t=>"lowering temp whenWindow is opened"},
tempFallWinPerio=>{a=> 6 ,s=>0.4,l=>7,min=>0 ,max=>60 ,c=>'' ,f=>'0.2' ,u=>'min' ,d=>1,t=>"period lowering when window is open"},
decalcWeekday =>{a=> 7 ,s=>0.3,l=>7,min=>0 ,max=>7 ,c=>'lit' ,f=>'' ,u=>'' ,d=>1,t=>"decalc day" ,lit=>{Sat=>0,Sun=>1,Mon=>2,Tue=>3,Wed=>4,Thu=>5,Fri=>6}},
decalcTime =>{a=> 8 ,s=>0.6,l=>7,min=>0 ,max=>1410 ,c=>'' ,f=>'0.0333',u=>'min' ,d=>1,t=>"decalc hour"},
decalcWeekday =>{a=> 7 ,s=>0.3,l=>7,min=>0 ,max=>7 ,c=>'lit' ,f=>'' ,u=>'' ,d=>1,t=>"decalc at day" ,lit=>{Sat=>0,Sun=>1,Mon=>2,Tue=>3,Wed=>4,Thu=>5,Fri=>6}},
decalcTime =>{a=> 8 ,s=>0.6,l=>7,min=>0 ,max=>1410 ,c=>'min2time' ,f=>'' ,u=>'' ,d=>1,t=>"decalc at hour"},
tempOffset =>{a=> 9 ,s=>0.4,l=>7,min=>0 ,max=>15 ,c=>'lit' ,f=>'' ,u=>'' ,d=>1,t=>"temperature offset",lit=>{"-3.5K"=>0,"-3.0K"=>1,"-2.5K"=>2,"-2.0K"=>3,"-1.5K"=>4,"-1.0K"=>5,"-0.5K"=>6,
"0.0K"=>7, "0.5K"=>8, "1.0K"=>10, "1.5K"=>11, "2.0K"=>12, "2.5K"=>13, "3.0K"=>14, "3.5K"=>15}},
btnNoBckLight =>{a=> 9.4,s=>0.1,l=>7,min=>0 ,max=>1 ,c=>'lit' ,f=>'' ,u=>'' ,d=>1,t=>"button response without backlight",lit=>{off=>0,on=>1}},