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
|
|
125911
|
use strict; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
57
|
|
9
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
81
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
10
|
use base qw( IO::Async::Socket ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
990
|
|
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 port => INT |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Optional. Port number to listen for Art-Net packets on. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=back |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _init |
74
|
|
|
|
|
|
|
{ |
75
|
1
|
|
|
1
|
|
4803
|
my $self = shift; |
76
|
1
|
|
|
|
|
9
|
$self->SUPER::_init( @_ ); |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
19
|
$self->{port} = 0x1936; # Art-Net |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub configure |
82
|
|
|
|
|
|
|
{ |
83
|
2
|
|
|
2
|
1
|
49398
|
my $self = shift; |
84
|
2
|
|
|
|
|
7
|
my %params = @_; |
85
|
|
|
|
|
|
|
|
86
|
2
|
|
|
|
|
6
|
foreach (qw( port on_dmx )) { |
87
|
4
|
100
|
|
|
|
16
|
$self->{$_} = delete $params{$_} if exists $params{$_}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
2
|
|
|
|
|
13
|
$self->SUPER::configure( %params ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub on_recv |
94
|
|
|
|
|
|
|
{ |
95
|
1
|
|
|
1
|
1
|
7137
|
my $self = shift; |
96
|
1
|
|
|
|
|
3
|
my ( $packet ) = @_; |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
13
|
my ( $magic, $opcode, $verhi, $verlo ) = |
99
|
|
|
|
|
|
|
unpack( "a8 v C C", substr $packet, 0, 12, "" ); |
100
|
|
|
|
|
|
|
|
101
|
1
|
50
|
|
|
|
5
|
return unless $magic eq "Art-Net\0"; |
102
|
1
|
50
|
33
|
|
|
8
|
return unless $verhi == 0 and $verlo == 14; |
103
|
|
|
|
|
|
|
|
104
|
1
|
50
|
|
|
|
4
|
if( $opcode == 0x5000 ) { |
105
|
1
|
|
|
|
|
4
|
my ( $seq, $phy, $universe, $data ) = |
106
|
|
|
|
|
|
|
unpack( "C C v xx a*", $packet ); |
107
|
1
|
|
|
|
|
11
|
$self->maybe_invoke_event( on_dmx => $seq, $phy, $universe, [ unpack "C*", $data ] ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _add_to_loop |
112
|
|
|
|
|
|
|
{ |
113
|
1
|
|
|
1
|
|
1192
|
my $self = shift; |
114
|
1
|
|
|
|
|
4
|
my ( $loop ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
1
|
50
|
|
|
|
7
|
if( !defined $self->read_handle ) { |
117
|
|
|
|
|
|
|
return $self->bind( |
118
|
|
|
|
|
|
|
service => $self->{port}, |
119
|
1
|
|
|
|
|
14
|
socktype => "dgram", |
120
|
|
|
|
|
|
|
)->get; # Blocking call, but numeric lookup so should be OK |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$self->SUPER::_add_to_loop( @_ ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SEE ALSO |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=over 4 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L - Art-Net - Wikipedia |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=back |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 AUTHOR |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Paul Evans |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
0x55AA; |