line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
######################################################################################### |
2
|
|
|
|
|
|
|
# Package HiPi::Interface::EnergenieSwitch |
3
|
|
|
|
|
|
|
# Description: Control Energenie OOK switches |
4
|
|
|
|
|
|
|
# Copyright : Copyright (c) 2013-2017 Mark Dootson |
5
|
|
|
|
|
|
|
# License : This is free software; you can redistribute it and/or modify it under |
6
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
7
|
|
|
|
|
|
|
######################################################################################### |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package HiPi::Interface::EnergenieSwitch; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
######################################################################################### |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
1050
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
14
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
15
|
1
|
|
|
1
|
|
5
|
use parent qw( HiPi::Interface ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
16
|
1
|
|
|
1
|
|
56
|
use HiPi qw( :energenie ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
247
|
|
17
|
1
|
|
|
1
|
|
9
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
854
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
__PACKAGE__->create_accessors( qw( groupid backend repeat ) ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION ='0.81'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Switch Data |
24
|
|
|
|
|
|
|
# $data = $switchmask->[$socketnum - 1]->[$offon]; |
25
|
|
|
|
|
|
|
# where $socketnum == 0 | 1 | 2 | 3 | 4 and $offon == 0|1; |
26
|
|
|
|
|
|
|
# when $socketnum == 0 then $offon is applied to all sockets |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $_switchdata = [ |
29
|
|
|
|
|
|
|
[ 0b1100, 0b1101 ], # off / on all sockets |
30
|
|
|
|
|
|
|
[ 0b1110, 0b1111 ], # off / on socket 1 |
31
|
|
|
|
|
|
|
[ 0b0110, 0b0111 ], # off / on socket 2 |
32
|
|
|
|
|
|
|
[ 0b1010, 0b1011 ], # off / on socket 3 |
33
|
|
|
|
|
|
|
[ 0b0010, 0b0011 ], # off / on socket 4 |
34
|
|
|
|
|
|
|
]; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
0
|
|
|
0
|
0
|
|
my( $class, %userparams ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my %params = ( |
40
|
|
|
|
|
|
|
backend => 'ENER314_RT', |
41
|
|
|
|
|
|
|
groupid => 0x6C6C6, |
42
|
|
|
|
|
|
|
device => undef, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
foreach my $key (sort keys(%userparams)) { |
46
|
0
|
|
|
|
|
|
$params{$key} = $userparams{$key}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
unless( defined($params{device}) ) { |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ( $params{backend} eq 'ENER314_RT' ) { |
|
|
0
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Two way configurable board |
53
|
0
|
|
|
|
|
|
require HiPi::Energenie::ENER314_RT; |
54
|
0
|
|
0
|
|
|
|
$params{repeat} //= ENERGENIE_TXOOK_REPEAT_RATE; |
55
|
0
|
|
|
|
|
|
my $dev = HiPi::Energenie::ENER314_RT->new(); |
56
|
0
|
|
|
|
|
|
$params{device} = $dev; |
57
|
|
|
|
|
|
|
} elsif( $params{backend} eq 'ENER314' ) { |
58
|
|
|
|
|
|
|
# simple 1 way single group board |
59
|
0
|
|
|
|
|
|
require HiPi::Energenie::ENER314; |
60
|
0
|
|
|
|
|
|
my $dev = HiPi::Energenie::ENER314->new(); |
61
|
0
|
|
|
|
|
|
$params{device} = $dev; |
62
|
|
|
|
|
|
|
} else { |
63
|
0
|
|
|
|
|
|
croak qq(Invalid backend $params{backend} specified); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(%params); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub pair_socket { |
73
|
0
|
|
|
0
|
0
|
|
my($self, $socket, $seconds) = @_; |
74
|
0
|
0
|
|
|
|
|
croak(qq(Invalid socket $socket)) unless $socket =~ /^1|2|3|4$/; |
75
|
0
|
|
0
|
|
|
|
$seconds ||= 10; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# broadcast for $seconds seconds; |
78
|
0
|
|
|
|
|
|
my $endtime = time() + $seconds; |
79
|
0
|
|
|
|
|
|
my $data = $_switchdata->[$socket]->[0]; # broadcast 'off' message for socket |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
while ( $endtime >= time() ) { |
82
|
0
|
|
|
|
|
|
$self->device->switch_ook_socket( $self->groupid, $data, $self->repeat ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub switch_socket { |
89
|
0
|
|
|
0
|
0
|
|
my($self, $socket, $offon) = @_; |
90
|
0
|
0
|
|
|
|
|
croak(qq(Invalid socket $socket)) unless $socket =~ /^0|1|2|3|4$/; |
91
|
0
|
0
|
|
|
|
|
$offon = ( $offon ) ? 1 : 0; |
92
|
0
|
|
|
|
|
|
my $data = $_switchdata->[$socket]->[$offon]; |
93
|
0
|
|
|
|
|
|
$self->device->switch_ook_socket( $self->groupid, $data, $self->repeat ); |
94
|
0
|
|
|
|
|
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# test what we actually send |
98
|
|
|
|
|
|
|
sub dump_message { |
99
|
0
|
|
|
0
|
0
|
|
my($self, $socket, $offon) = @_; |
100
|
0
|
0
|
|
|
|
|
croak(q(Method requires backend 'ENER314_RT')) if $self->backend ne 'ENER314_RT'; |
101
|
0
|
0
|
|
|
|
|
croak(qq(Invalid socket $socket)) unless $socket =~ /^0|1|2|3|4$/; |
102
|
0
|
0
|
|
|
|
|
$offon = ( $offon ) ? 1 : 0; |
103
|
0
|
|
|
|
|
|
my $data = $_switchdata->[$socket]->[$offon]; |
104
|
0
|
|
|
|
|
|
my @tvals = $self->device->make_ook_message( $self->groupid, $data ); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# print preamble |
107
|
0
|
|
|
|
|
|
print sprintf("preamble : 0x%x, 0x%x, 0x%x, 0x%x\n", @tvals[0..3]); |
108
|
|
|
|
|
|
|
# print group id |
109
|
0
|
|
|
|
|
|
print sprintf("group id : 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", @tvals[4..13]); |
110
|
|
|
|
|
|
|
# print data |
111
|
0
|
|
|
|
|
|
print sprintf("set data : 0x%x, 0x%x\n", @tvals[14..15]); |
112
|
0
|
|
|
|
|
|
return; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |