line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UAV::Pilot::NavCollector::AckEvents; |
2
|
1
|
|
|
1
|
|
1742
|
use v5.14; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
37
|
|
3
|
1
|
|
|
1
|
|
451
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use namespace::autoclean; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'UAV::Pilot::NavCollector'; |
7
|
|
|
|
|
|
|
with 'UAV::Pilot::Logger'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'easy_event' => ( |
11
|
|
|
|
|
|
|
is => 'ro', |
12
|
|
|
|
|
|
|
isa => 'UAV::Pilot::EasyEvent', |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
has '_last_ack_status' => ( |
15
|
|
|
|
|
|
|
is => 'rw', |
16
|
|
|
|
|
|
|
isa => 'Bool', |
17
|
|
|
|
|
|
|
default => 0, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub got_new_nav_packet |
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
my ($self, $packet) = @_; |
24
|
|
|
|
|
|
|
my $new_ack = $packet->state_control_received; |
25
|
|
|
|
|
|
|
my $last_ack = $self->_last_ack_status; |
26
|
|
|
|
|
|
|
my $event = $self->easy_event; |
27
|
|
|
|
|
|
|
my $logger = $self->_logger; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$logger->info( "Got nav ACK of $new_ack, old ack is $last_ack" ); |
30
|
|
|
|
|
|
|
my $send_event = $new_ack |
31
|
|
|
|
|
|
|
? 'nav_ack_on' |
32
|
|
|
|
|
|
|
: 'nav_ack_off'; |
33
|
|
|
|
|
|
|
$logger->info( "Sending $send_event event" ); |
34
|
|
|
|
|
|
|
$event->send_event( $send_event ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if( $new_ack != $last_ack ) { |
37
|
|
|
|
|
|
|
$logger->info( "Sending nav_ack_toggle event" ); |
38
|
|
|
|
|
|
|
$event->send_event( 'nav_ack_toggle', $new_ack ); |
39
|
|
|
|
|
|
|
$self->_last_ack_status( $new_ack ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
no Moose; |
47
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
UAV::Pilot::NavCollector::AckEvents |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $easy_event = UAV::Pilot::EasyEvent->new; |
59
|
|
|
|
|
|
|
my $ack = UAV::Pilot::NavCollector::AckEvents->new({ |
60
|
|
|
|
|
|
|
easy_event => $easy_event, |
61
|
|
|
|
|
|
|
}); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$easy_event->add_event( 'nav_ack_on' => sub { |
64
|
|
|
|
|
|
|
say "ACK control bit is on"; |
65
|
|
|
|
|
|
|
}); |
66
|
|
|
|
|
|
|
$easy_event->add_event( 'nav_ack_off' => sub { |
67
|
|
|
|
|
|
|
say "ACK control bit is off"; |
68
|
|
|
|
|
|
|
}); |
69
|
|
|
|
|
|
|
$easy_event->add_event( 'nav_ack_toggle' => sub { |
70
|
|
|
|
|
|
|
say "ACK control bit toggled"; |
71
|
|
|
|
|
|
|
}); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 DESCRIPTION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Does the C<UAV::Pilot::NavCollector> role to fire off events into |
76
|
|
|
|
|
|
|
C<UAV::Pilot::EasyEvent> based on the ACK control bit. Each nav packet with |
77
|
|
|
|
|
|
|
the bit on will fire a C<nav_ack_on> event, and C<nav_ack_off> when off. If |
78
|
|
|
|
|
|
|
the state toggles, C<nav_ack_toggle> is sent. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |