| 1 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Device::RFXCOM::Decoder::Visonic; | ||||||||||
| 4 | 3 | $Device::RFXCOM::Decoder::Visonic::VERSION = '1.142010'; | |||||||||
| 5 | # ABSTRACT: Device::RFXCOM::Decoder::Visonic decode Visonic RF messages | ||||||||||
| 6 | |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use constant DEBUG => $ENV{DEVICE_RFXCOM_DECODER_VISONIC_DEBUG}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use Carp qw/croak/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | ▶ | use Device::RFXCOM::Decoder qw/hi_nibble lo_nibble/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 3 | our @ISA = qw(Device::RFXCOM::Decoder); | |||||||||
| 13 | 3 | ▶ | use Device::RFXCOM::Response::Security; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 3 | ▶ | use Device::RFXCOM::Response::Sensor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 3 | my %bits = ( 36 => 'powercode', 66 => 'codesecure' ); | |||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | sub decode { | ||||||||||
| 20 | 44 | ▶ | my ($self, $parent, $message, $bytes, $bits, $result) = @_; | ||||||||
|
Subroutine
decode: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 21 | 44 | ▶ | my $method = $bits{$bits} or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 6 | return $self->$method($parent, $message, $bytes, $bits, $result); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | sub codesecure { | ||||||||||
| 27 | 3 | ▶ | my ($self, $parent, $message, $bytes, $bits, $result) = @_; | ||||||||
|
Subroutine
codesecure: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 28 | # parity check? | ||||||||||
| 29 | |||||||||||
| 30 | 3 | my $code = | |||||||||
| 31 | sprintf '%02x%02x%02x%02x', | ||||||||||
| 32 | $bytes->[0], $bytes->[1], $bytes->[2], $bytes->[3]; | ||||||||||
| 33 | |||||||||||
| 34 | 3 | my $device = | |||||||||
| 35 | sprintf 'codesecure.%02x%02x%02x%x', | ||||||||||
| 36 | $bytes->[4], $bytes->[5], $bytes->[6], hi_nibble($bytes->[7]); | ||||||||||
| 37 | my $event = | ||||||||||
| 38 | { 0x1 => "light", | ||||||||||
| 39 | 0x2 => "arm-away", | ||||||||||
| 40 | 0x4 => "disarm", | ||||||||||
| 41 | 0x8 => "arm-home", | ||||||||||
| 42 | 3 | }->{lo_nibble($bytes->[7])}; | |||||||||
| 43 | 3 | ▶ | unless ($event) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | # probably invalid message | ||||||||||
| 45 | # TOFIX: figure out parity check so this isn't required | ||||||||||
| 46 | 1 | return; | |||||||||
| 47 | } | ||||||||||
| 48 | 2 | my $repeat = $bytes->[8]&0x4; | |||||||||
| 49 | 2 | my $low_bat = $bytes->[8]&0x8; | |||||||||
| 50 | 2 | my %args = | |||||||||
| 51 | ( | ||||||||||
| 52 | event => $event, | ||||||||||
| 53 | device => $device, | ||||||||||
| 54 | ); | ||||||||||
| 55 | 2 | ▶ | $args{repeat} = 1 if ($repeat); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 2 | ▶ | push @{$result->{messages}}, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | Device::RFXCOM::Response::Security->new(%args), | ||||||||||
| 58 | Device::RFXCOM::Response::Sensor->new(device => $device, | ||||||||||
| 59 | measurement => 'battery', | ||||||||||
| 60 | value => $low_bat ? 10 : 90, | ||||||||||
| 61 | units => '%'); | ||||||||||
| 62 | 2 | return 1; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | sub powercode { | ||||||||||
| 67 | 3 | ▶ | my ($self, $parent, $message, $bytes, $bits, $result) = @_; | ||||||||
|
Subroutine
powercode: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||
| 68 | 3 | my $parity; | |||||||||
| 69 | 3 | foreach (0 .. 3) { | |||||||||
| 70 | 12 | $parity ^= hi_nibble($bytes->[$_]); | |||||||||
| 71 | 12 | $parity ^= lo_nibble($bytes->[$_]); | |||||||||
| 72 | } | ||||||||||
| 73 | 3 | ▶ | unless ($parity == hi_nibble($bytes->[4])) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 1 | warn | |||||||||
| 75 | sprintf("Possible Visonic powercode with parity error %x != %x\n", | ||||||||||
| 76 | $parity, hi_nibble($bytes->[4])); | ||||||||||
| 77 | 1 | return; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 2 | my $device = sprintf('powercode.%02x%02x%02x', | |||||||||
| 81 | $bytes->[0], $bytes->[1], $bytes->[2]); | ||||||||||
| 82 | 2 | ▶ | $device .= 's' unless ($bytes->[3] & 0x4); # suffix s for secondary contact | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 2 | my $restore = $bytes->[3] & 0x8; | |||||||||
| 84 | 2 | my $event = $bytes->[3] & 0x10; | |||||||||
| 85 | 2 | my $low_bat = $bytes->[3] & 0x20; | |||||||||
| 86 | 2 | my $alert = $bytes->[3] & 0x40; | |||||||||
| 87 | 2 | my $tamper = $bytes->[3] & 0x80; | |||||||||
| 88 | |||||||||||
| 89 | # I assume $event is to distinguish whether it's a new event or just a | ||||||||||
| 90 | # heartbeat message? | ||||||||||
| 91 | 2 | ▶ | my %args = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | ( | ||||||||||
| 93 | event => $alert ? 'alert' : 'normal', | ||||||||||
| 94 | device => $device, | ||||||||||
| 95 | ); | ||||||||||
| 96 | 2 | ▶ | $args{restore} = 1 if ($restore); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 2 | ▶ | $args{tamper} = 1 if ($tamper); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 2 | ▶ | push @{$result->{messages}}, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | Device::RFXCOM::Response::Security->new(%args), | ||||||||||
| 100 | Device::RFXCOM::Response::Sensor->new(device => $device, | ||||||||||
| 101 | measurement => 'battery', | ||||||||||
| 102 | value => $low_bat ? 10 : 90, | ||||||||||
| 103 | units => '%'); | ||||||||||
| 104 | 2 | return 1; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 3 | 1; | |||||||||
| 108 | |||||||||||
| 109 | __END__ | ||||||||||