| 1 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package Device::RFXCOM::Decoder::X10Security; | ||||||||||||||||||||||||||||
| 4 | 4 | $Device::RFXCOM::Decoder::X10Security::VERSION = '1.142010'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Device::RFXCOM::Decoder::X10Security decode X10 Security RF messages | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use constant DEBUG => $ENV{DEVICE_RFXCOM_DECODER_X10_SECURITY_DEBUG}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use base 'Device::RFXCOM::Decoder'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Device::RFXCOM::Response::Security; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Device::RFXCOM::Response::Sensor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub decode { | ||||||||||||||||||||||||||||
| 17 | 34 | ▶ | my ($self, $parent, $message, $bytes, $bits, $result) = @_; | ||||||||||||||||||||||||||
|
Subroutine
decode: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 34 | ▶ | ($bits == 32 || $bits == 41) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$bits == 32 or $bits == 41
MC/DC100%2/2
$bits == 32 or $bits == 41
$bits == 32
$bits == 41
Truth table100%3/3
A or B
A= $bits == 32B= $bits == 41
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # bits are not reversed yet! | ||||||||||||||||||||||||||||
| 21 | 13 | ▶ | (($bytes->[0]^0x0f) == $bytes->[1] && ($bytes->[2]^0xff) == $bytes->[3]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
($bytes->[0] ^ 15) == $bytes->[1] and ($bytes->[2] ^ 255) == $bytes->[3]
MC/DC100%2/2
($bytes->[0] ^ 15) == $bytes->[1] and ($bytes->[2] ^ 255) == $bytes->[3]
($bytes->[0] ^ 15) == $bytes->[1]
($bytes->[2] ^ 255) == $bytes->[3]
Truth table100%3/3
A and B
A= ($bytes->[0] ^ 15) == $bytes->[1]B= ($bytes->[2] ^ 255) == $bytes->[3]
| |||||||||||||||||||||||||||||
| 22 | or return; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 6 | $self->reverse_bits($bytes); # TOFIX: corrupts the input data? | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 6 | my $device = sprintf 'x10sec%02x', $bytes->[0]; | |||||||||||||||||||||||||||
| 27 | 6 | my $short_device = $bytes->[0]; | |||||||||||||||||||||||||||
| 28 | 6 | my $data = $bytes->[2]; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 6 | my %not_supported_yet = | |||||||||||||||||||||||||||
| 31 | ( | ||||||||||||||||||||||||||||
| 32 | # See: http://www.wgldesigns.com/protocols/w800rf32_protocol.txt | ||||||||||||||||||||||||||||
| 33 | 0x70 => 'SH624 arm home (min)', | ||||||||||||||||||||||||||||
| 34 | #0x60 => 'SH624 arm away (min)', | ||||||||||||||||||||||||||||
| 35 | 0x50 => 'SH624 arm home (max)', | ||||||||||||||||||||||||||||
| 36 | 0x40 => 'SH624 arm away (max)', | ||||||||||||||||||||||||||||
| 37 | 0x41 => 'SH624 disarm', | ||||||||||||||||||||||||||||
| 38 | 0x42 => 'SH624 sec light on', | ||||||||||||||||||||||||||||
| 39 | 0x43 => 'SH624 sec light off', | ||||||||||||||||||||||||||||
| 40 | 0x44 => 'SH624 panic', | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 6 | my %x10_security = | |||||||||||||||||||||||||||
| 44 | ( | ||||||||||||||||||||||||||||
| 45 | 0x60 => ['arm-away', 'min'], | ||||||||||||||||||||||||||||
| 46 | 0x61 => 'disarm', | ||||||||||||||||||||||||||||
| 47 | 0x62 => 'lights-on', | ||||||||||||||||||||||||||||
| 48 | 0x63 => 'lights-off', | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 6 | my $command; | |||||||||||||||||||||||||||
| 52 | my $tamper; | ||||||||||||||||||||||||||||
| 53 | 6 | my $min_delay; | |||||||||||||||||||||||||||
| 54 | 6 | my $low_battery; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 6 | ▶ | if (exists $x10_security{$data}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 57 | 2 | my $rec = $x10_security{$data}; | |||||||||||||||||||||||||||
| 58 | 2 | ▶ | if (ref $rec) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 1 | ($command, $min_delay) = @$rec; | |||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||
| 61 | 1 | $command = $rec; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } elsif (exists $not_supported_yet{$data}) { | ||||||||||||||||||||||||||||
| 64 | 1 | warn sprintf "Not supported: %02x %s\n", $data, $not_supported_yet{$data}; | |||||||||||||||||||||||||||
| 65 | 1 | return 1; | |||||||||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 3 | my $alert = !($data&0x1); | |||||||||||||||||||||||||||
| 69 | 3 | ▶ | $command = $alert ? 'alert' : 'normal', | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | $tamper = $data&0x2; | ||||||||||||||||||||||||||||
| 71 | 3 | $min_delay = $data&0x20; | |||||||||||||||||||||||||||
| 72 | 3 | $low_battery = $data&0x80; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 5 | my %args = | |||||||||||||||||||||||||||
| 76 | ( | ||||||||||||||||||||||||||||
| 77 | event => $command, | ||||||||||||||||||||||||||||
| 78 | device => $device, | ||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||
| 80 | 5 | ▶ | $args{tamper} = 1 if ($tamper); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 5 | ▶ | $args{min_delay} = 1 if ($min_delay); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 5 | ▶ | push @{$result->{messages}}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | Device::RFXCOM::Response::Security->new(%args), | ||||||||||||||||||||||||||||
| 84 | Device::RFXCOM::Response::Sensor->new(device => $device, | ||||||||||||||||||||||||||||
| 85 | measurement => 'battery', | ||||||||||||||||||||||||||||
| 86 | value => $low_battery ? 10 : 90, | ||||||||||||||||||||||||||||
| 87 | units => '%'); | ||||||||||||||||||||||||||||
| 88 | 5 | return 1; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub reverse_bits { | ||||||||||||||||||||||||||||
| 93 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
reverse_bits: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 6 | my $bytes = shift; | |||||||||||||||||||||||||||
| 95 | 6 | foreach (@$bytes) { | |||||||||||||||||||||||||||
| 96 | 32 | $_ = unpack 'C',(pack 'B8', (unpack 'b8', (pack 'C',$_))); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 6 | return 1; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 4 | 1; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||