| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Device::W800; | ||||||||||
| 4 | 1 | $Device::W800::VERSION = '1.142010'; | |||||||||
| 5 | # ABSTRACT: Module to support W800 RF receiver | ||||||||||
| 6 | |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use constant DEBUG => $ENV{DEVICE_W800_DEBUG}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Carp qw/croak/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use base 'Device::RFXCOM::RX'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Device::RFXCOM::Response; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | sub new { | ||||||||||
| 16 | 2 | ▶ | my ($pkg, %p) = @_; | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 17 | 2 | my @plugins; | |||||||||
| 18 | # TODO: Make 32-bit support a class method on the decoder so | ||||||||||
| 19 | # this process (to restrict the plugins to a useful set) is | ||||||||||
| 20 | # encapsulated better. | ||||||||||
| 21 | 2 | foreach my $decoder (qw/RFXSensor X10 X10Security/) { | |||||||||
| 22 | 6 | my $module = 'Device::RFXCOM::Decoder::'.$decoder; | |||||||||
| 23 | 6 | my $file = 'Device/RFXCOM/Decoder/'.$decoder.'.pm'; | |||||||||
| 24 | 6 | require $file; import $module; | |||||||||
| 25 | 6 | push @plugins, $module->new(); | |||||||||
| 26 | } | ||||||||||
| 27 | 2 | $pkg->SUPER::new(device => '/dev/w800', plugins => \@plugins, %p); | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | sub _write { | ||||||||||
| 31 | 1 | ▶ | croak "Writes not supported for W800: @_\n"; | ||||||||
|
Subroutine
_write: called CC=1 SCAR=0.0
| |||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | ▶ | sub _write_now { | |||||||||
|
Subroutine
_write_now: called CC=1 SCAR=0.0
| |||||||||||
| 35 | # do nothing | ||||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | sub _init { | ||||||||||
| 39 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 1 | $self->{init} = 1; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | sub read_one { | ||||||||||
| 45 | 5 | ▶ | my ($self, $rbuf) = @_; | ||||||||
|
Subroutine
read_one: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||
| 46 | 5 | ▶ | return unless ($$rbuf); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 4 | print STDERR "rbuf=", (unpack "H*", $$rbuf), "\n" if DEBUG; | |||||||||
| 49 | 4 | my $bits = 32; | |||||||||
| 50 | 4 | my $length = 4; | |||||||||
| 51 | 4 | my %result = | |||||||||
| 52 | ( | ||||||||||
| 53 | master => 1, | ||||||||||
| 54 | header_byte => $bits, | ||||||||||
| 55 | type => 'unknown', | ||||||||||
| 56 | ); | ||||||||||
| 57 | 4 | my $msg = ''; | |||||||||
| 58 | 4 | my @bytes; | |||||||||
| 59 | |||||||||||
| 60 | 4 | ▶ | return if (length $$rbuf < $length); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 2 | $msg = substr $$rbuf, 0, $length, ''; # message from buffer | |||||||||
| 63 | 2 | @bytes = unpack 'C*', $msg; | |||||||||
| 64 | |||||||||||
| 65 | 2 | $result{key} = $bits.'!'.$msg; | |||||||||
| 66 | 2 | my $entry = $self->_cache_get(\%result); | |||||||||
| 67 | 2 | ▶ | if ($entry) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 1 | print STDERR "using cache entry\n" if DEBUG; | |||||||||
| 69 | 1 | @result{qw/messages type/} = @{$entry->{result}}{qw/messages type/}; | |||||||||
| 70 | 1 | $self->_cache_set(\%result); | |||||||||
| 71 | } else { | ||||||||||
| 72 | 1 | foreach my $decoder (@{$self->{plugins}}) { | |||||||||
| 73 | 2 | ▶ | my $matched = $decoder->decode($self, $msg, \@bytes, $bits, \%result) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | or next; | ||||||||||
| 75 | 1 | ($result{type} = lc ref $decoder) =~ s/.*:://; | |||||||||
| 76 | 1 | last; | |||||||||
| 77 | } | ||||||||||
| 78 | 1 | $self->_cache_set(\%result); | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 2 | @result{qw/data bytes/} = ($msg, \@bytes); | |||||||||
| 82 | 2 | return Device::RFXCOM::Response->new(%result); | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 1 | 1; | |||||||||
| 86 | |||||||||||
| 87 | __END__ | ||||||||||