line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2014 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Async::ArtNet; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
680
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
12
|
use base qw( IO::Async::Socket ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
749
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
61201
|
use IO::Socket::INET; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
15
|
|
16
|
1
|
|
|
1
|
|
827
|
use Socket qw( SOCK_DGRAM ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
439
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
C - use ArtNet with C |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This object class allows you to use the Art-Net protocol with C. |
25
|
|
|
|
|
|
|
It receives Art-Net frames containing DMX data. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 EVENTS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 on_dmx $seq, $phy, $uni, $data |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
A new set of DMX control values has been received. C<$seq> contains the |
34
|
|
|
|
|
|
|
sequence number from the packet, C<$phy> and C<$uni> the physical and universe |
35
|
|
|
|
|
|
|
numbers, and C<$data> will be an ARRAY reference containing up to 512 DMX |
36
|
|
|
|
|
|
|
control values. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 PARAMETERS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The following named parameters may be passed to C or C: |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=over 8 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item port => INT |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Optional. Port number to listen for Art-Net packets on. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=back |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _init |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
0
|
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
$self->SUPER::_init( @_ ); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->{port} = 0x1936; # Art-Net |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub configure |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
65
|
0
|
|
|
|
|
|
my %params = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
foreach (qw( port on_dmx )) { |
68
|
0
|
0
|
|
|
|
|
$self->{$_} = delete $params{$_} if exists $params{$_}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->SUPER::configure( %params ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub on_recv |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
77
|
0
|
|
|
|
|
|
my ( $packet ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my ( $magic, $opcode, $verhi, $verlo ) = |
80
|
|
|
|
|
|
|
unpack( "a8 v C C", substr $packet, 0, 12, "" ); |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
return unless $magic eq "Art-Net\0"; |
83
|
0
|
0
|
0
|
|
|
|
return unless $verhi == 0 and $verlo == 14; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if( $opcode == 0x5000 ) { |
86
|
0
|
|
|
|
|
|
my ( $seq, $phy, $universe, $data ) = |
87
|
|
|
|
|
|
|
unpack( "C C v xx a*", $packet ); |
88
|
0
|
|
|
|
|
|
$self->maybe_invoke_event( on_dmx => $seq, $phy, $universe, [ unpack "C*", $data ] ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _add_to_loop |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
0
|
|
|
my $self = shift; |
95
|
0
|
|
|
|
|
|
my ( $loop ) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if( !defined $self->read_handle ) { |
98
|
|
|
|
|
|
|
# TODO: IP? |
99
|
0
|
0
|
|
|
|
|
my $sock = IO::Socket::INET->new( |
100
|
|
|
|
|
|
|
Proto => "udp", |
101
|
|
|
|
|
|
|
Type => SOCK_DGRAM, |
102
|
|
|
|
|
|
|
ReusePort => 1, |
103
|
|
|
|
|
|
|
ReuseAddr => 1, |
104
|
|
|
|
|
|
|
LocalPort => $self->{port}, |
105
|
|
|
|
|
|
|
) or die "Cannot socket() - $@"; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
$self->set_handle( $sock ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
$self->SUPER::_add_to_loop( @_ ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SEE ALSO |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over 4 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
L - Art-Net - Wikipedia |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHOR |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Paul Evans |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
0x55AA; |