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-2020 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Async::ArtNet; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
134147
|
use strict; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
62
|
|
9
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
99
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
12
|
use base qw( IO::Async::Socket ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1051
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
C - use ArtNet with C |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use IO::Async::Loop; |
22
|
|
|
|
|
|
|
use Net::Async::ArtNet; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$loop->add( Net::Async::ArtNet->new( |
27
|
|
|
|
|
|
|
on_dmx => sub { |
28
|
|
|
|
|
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
my ( $seq, $phy, $universe, $data ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
return unless $phy == 0 and $universe == 0; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $ch10 = $data->[10 - 1]; # DMX channels are 1-indexed |
34
|
|
|
|
|
|
|
print "Channel 10 now set to: $ch10\n"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
) ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$loop->run; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This object class allows you to use the Art-Net protocol with C. |
43
|
|
|
|
|
|
|
It receives Art-Net frames containing DMX data. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 EVENTS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 on_dmx $seq, $phy, $uni, $data |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
A new set of DMX control values has been received. C<$seq> contains the |
52
|
|
|
|
|
|
|
sequence number from the packet, C<$phy> and C<$uni> the physical and universe |
53
|
|
|
|
|
|
|
numbers, and C<$data> will be an ARRAY reference containing up to 512 DMX |
54
|
|
|
|
|
|
|
control values. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 PARAMETERS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The following named parameters may be passed to C or C. |
61
|
|
|
|
|
|
|
Additionally, CODE references to set callbacks for events may be passed. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=over 8 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item family => INT or STRING |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item host => INT or STRING |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item service => INT or STRING |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Optional. C parameters to create socket listen for Art-Net |
72
|
|
|
|
|
|
|
packets on. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item port => INT or STRING |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Synonym for C parameter. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=back |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _init |
83
|
|
|
|
|
|
|
{ |
84
|
1
|
|
|
1
|
|
4883
|
my $self = shift; |
85
|
1
|
|
|
|
|
9
|
$self->SUPER::_init( @_ ); |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
19
|
$self->{service} = 0x1936; # Art-Net |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub configure |
91
|
|
|
|
|
|
|
{ |
92
|
2
|
|
|
2
|
1
|
52014
|
my $self = shift; |
93
|
2
|
|
|
|
|
10
|
my %params = @_; |
94
|
|
|
|
|
|
|
|
95
|
2
|
100
|
|
|
|
12
|
$params{service} = delete $params{port} if exists $params{port}; |
96
|
|
|
|
|
|
|
|
97
|
2
|
|
|
|
|
9
|
foreach (qw( family host service on_dmx )) { |
98
|
8
|
100
|
|
|
|
23
|
$self->{$_} = delete $params{$_} if exists $params{$_}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
2
|
|
|
|
|
18
|
$self->SUPER::configure( %params ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub on_recv |
105
|
|
|
|
|
|
|
{ |
106
|
1
|
|
|
1
|
1
|
7455
|
my $self = shift; |
107
|
1
|
|
|
|
|
5
|
my ( $packet ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
15
|
my ( $magic, $opcode, $verhi, $verlo ) = |
110
|
|
|
|
|
|
|
unpack( "a8 v C C", substr $packet, 0, 12, "" ); |
111
|
|
|
|
|
|
|
|
112
|
1
|
50
|
|
|
|
6
|
return unless $magic eq "Art-Net\0"; |
113
|
1
|
50
|
33
|
|
|
10
|
return unless $verhi == 0 and $verlo == 14; |
114
|
|
|
|
|
|
|
|
115
|
1
|
50
|
|
|
|
11
|
if( $opcode == 0x5000 ) { |
116
|
1
|
|
|
|
|
7
|
my ( $seq, $phy, $universe, $data ) = |
117
|
|
|
|
|
|
|
unpack( "C C v xx a*", $packet ); |
118
|
1
|
|
|
|
|
11
|
$self->maybe_invoke_event( on_dmx => $seq, $phy, $universe, [ unpack "C*", $data ] ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _add_to_loop |
123
|
|
|
|
|
|
|
{ |
124
|
1
|
|
|
1
|
|
1215
|
my $self = shift; |
125
|
1
|
|
|
|
|
4
|
my ( $loop ) = @_; |
126
|
|
|
|
|
|
|
|
127
|
1
|
50
|
|
|
|
8
|
if( !defined $self->read_handle ) { |
128
|
|
|
|
|
|
|
return $self->bind( |
129
|
1
|
|
|
|
|
10
|
( map { $_, $self->{$_} } qw( family host service ) ), |
|
3
|
|
|
|
|
14
|
|
130
|
|
|
|
|
|
|
socktype => "dgram", |
131
|
|
|
|
|
|
|
)->get; # Blocking call, but numeric lookup so should be OK |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
$self->SUPER::_add_to_loop( @_ ); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SEE ALSO |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over 4 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L - Art-Net - Wikipedia |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 AUTHOR |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Paul Evans |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
0x55AA; |