mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-07 22:29:19 +00:00
10_ZWave.pm: add CRC16 (68111)
git-svn-id: https://svn.fhem.de/fhem/trunk@13568 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
4adfa806fd
commit
1fb627edd8
@ -637,6 +637,7 @@ ZWave_Initialize($)
|
|||||||
showtime:noArg
|
showtime:noArg
|
||||||
vclasses
|
vclasses
|
||||||
useMultiCmd:noArg
|
useMultiCmd:noArg
|
||||||
|
useCRC16:noArg
|
||||||
zwaveRoute
|
zwaveRoute
|
||||||
);
|
);
|
||||||
use warnings 'qw';
|
use warnings 'qw';
|
||||||
@ -4096,6 +4097,17 @@ ZWave_isWakeUp($)
|
|||||||
return $h->{isWakeUp};
|
return $h->{isWakeUp};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
ZWave_addCRC16($)
|
||||||
|
{
|
||||||
|
my ($msg) = @_;
|
||||||
|
return $msg if($msg !~ m/13(..)(..)(.*)(....)$/);
|
||||||
|
my ($tgt, $olen, $omsg, $sfx) = ($1, $2, $3, $4);
|
||||||
|
$msg = sprintf("13%s%02x5601%s%s%s", $tgt, length($omsg)/2+4,
|
||||||
|
$omsg, uc(ZWave_CRC16("5601$omsg")), $sfx);
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
# stack contains type:hexcode
|
# stack contains type:hexcode
|
||||||
# type is: set / sentset, get / sentget / sentackget
|
# type is: set / sentset, get / sentget / sentackget
|
||||||
# sentset will be discarded after ack, sentget needs ack (->sentackget) then msg
|
# sentset will be discarded after ack, sentget needs ack (->sentackget) then msg
|
||||||
@ -4168,6 +4180,8 @@ ZWave_processSendStack($$;$)
|
|||||||
|
|
||||||
$ss->[0] =~ m/^([^:]*?):(.*)$/;
|
$ss->[0] =~ m/^([^:]*?):(.*)$/;
|
||||||
my ($type, $msg) = ($1, $2);
|
my ($type, $msg) = ($1, $2);
|
||||||
|
|
||||||
|
$msg = ZWave_addCRC16($msg) if($hash->{useCRC16});
|
||||||
IOWrite($hash,
|
IOWrite($hash,
|
||||||
$hash->{homeId}.($hash->{route}?",".$hash->{route}:""),
|
$hash->{homeId}.($hash->{route}?",".$hash->{route}:""),
|
||||||
"00$msg");
|
"00$msg");
|
||||||
@ -4584,7 +4598,7 @@ ZWave_Parse($$@)
|
|||||||
if($arg =~ /^..5601(.*)(....)/) { # CRC_16_ENCAP: Unwrap encapsulated command
|
if($arg =~ /^..5601(.*)(....)/) { # CRC_16_ENCAP: Unwrap encapsulated command
|
||||||
#Log3 $ioName, 4, "CRC FIX, MSG: ($1)"; # see Forum #23494
|
#Log3 $ioName, 4, "CRC FIX, MSG: ($1)"; # see Forum #23494
|
||||||
my $crc16 = ZWave_CRC16("5601".$1);
|
my $crc16 = ZWave_CRC16("5601".$1);
|
||||||
if ($2 eq $crc16) {
|
if (lc($2) eq lc($crc16)) {
|
||||||
$arg = sprintf("%02x$1", length($1)/2);
|
$arg = sprintf("%02x$1", length($1)/2);
|
||||||
} else {
|
} else {
|
||||||
Log3 $ioName, 4, "$ioName CRC_16 checksum mismatch, received $2," .
|
Log3 $ioName, 4, "$ioName CRC_16 checksum mismatch, received $2," .
|
||||||
@ -4794,7 +4808,7 @@ ZWave_Attr(@)
|
|||||||
|
|
||||||
} elsif($attrName eq "useMultiCmd") {
|
} elsif($attrName eq "useMultiCmd") {
|
||||||
if($type eq "del") {
|
if($type eq "del") {
|
||||||
$hash->{".vclasses"} = {};
|
delete $hash->{useMultiCmd};
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
my $a = ($attr{$devName} ? $attr{$devName}{classes} : "");
|
my $a = ($attr{$devName} ? $attr{$devName}{classes} : "");
|
||||||
@ -4802,6 +4816,18 @@ ZWave_Attr(@)
|
|||||||
if(!$a || !($a =~ m/MULTI_CMD/ && $a =~ m/WAKE_UP/));
|
if(!$a || !($a =~ m/MULTI_CMD/ && $a =~ m/WAKE_UP/));
|
||||||
$hash->{useMultiCmd} = 1;
|
$hash->{useMultiCmd} = 1;
|
||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
|
} elsif($attrName eq "useCRC16") {
|
||||||
|
if($type eq "del") {
|
||||||
|
delete $hash->{useCRC16};
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
my $a = ($attr{$devName} ? $attr{$devName}{classes} : "");
|
||||||
|
return "useCRC16: unsupported device, see help ZWave for details"
|
||||||
|
if(!$a || $a !~ m/CRC_16_ENCAP/ ||
|
||||||
|
ReadingsVal($devName, "SECURITY", "") eq "ENABLED");
|
||||||
|
$hash->{useCRC16} = 1;
|
||||||
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -5938,6 +5964,12 @@ s2Hex($)
|
|||||||
contains the version information for each of the supported classes.
|
contains the version information for each of the supported classes.
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li><a name="useCRC16">useCRC16</a><br>
|
||||||
|
Experimental: if a device supports CRC_16_ENCAP, then add CRC16 to the
|
||||||
|
command. Note: this is not available to SECURITY ENABLED devices, as
|
||||||
|
security has its own CRC.
|
||||||
|
</li>
|
||||||
|
|
||||||
<li><a name="useMultiCmd">useMultiCmd</a><br>
|
<li><a name="useMultiCmd">useMultiCmd</a><br>
|
||||||
Experimental: if a device supports MULTI_CMD and WAKE_UP, then pack
|
Experimental: if a device supports MULTI_CMD and WAKE_UP, then pack
|
||||||
multiple get messages on the SendStack into a single MULTI_CMD to save
|
multiple get messages on the SendStack into a single MULTI_CMD to save
|
||||||
|
Loading…
x
Reference in New Issue
Block a user