Pilot/NavCollector/AckEvents.pm

filter: Statementstmt 54.8% 17 / 31 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 51.2% 21 / 41 CC 3 SCAR 17.4
CC
3
Cov
49%
got_new_nav_packet
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.7
↑ Summary Pilot/Video/FileDump.pm »
1 # Copyright (c) 2014 Timm Murray
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # * Redistributions of source code must retain the above copyright notice,
8 # this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 #
13 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 # POSSIBILITY OF SUCH DAMAGE.
24 package UAV::Pilot::NavCollector::AckEvents;
25 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 with 'UAV::Pilot::NavCollector';
30 1 with 'UAV::Pilot::Logger';
31  
32  
33 1 has 'easy_event' => (
34 is => 'ro',
35 isa => 'UAV::Pilot::EasyEvent',
36 );
37 1 has '_last_ack_status' => (
38 is => 'rw',
39 isa => 'Bool',
40 default => 0,
41 );
42  
43  
44 sub got_new_nav_packet
45 {
46 0 ▶ my ($self, $packet) = @_;
Subroutine got_new_nav_packet: not called CC=3 SCAR=24.8
Pod undocumented
47 0 my $new_ack = $packet->state_control_received;
48 0 my $last_ack = $self->_last_ack_status;
49 0 my $event = $self->easy_event;
50 0 my $logger = $self->_logger;
51  
52 0 $logger->info( "Got nav ACK of $new_ack, old ack is $last_ack" );
53 0 ▶ my $send_event = $new_ack
Branch: 1 branch
BranchTrueFalseTotal
$new_ack ? : 0 0 0
54 ? 'nav_ack_on'
55 : 'nav_ack_off';
56 0 $logger->info( "Sending $send_event event" );
57 0 $event->send_event( $send_event );
58  
59 0 ▶ if( $new_ack != $last_ack ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_ack != $last_ack) 0 0 0
60 0 $logger->info( "Sending nav_ack_toggle event" );
61 0 $event->send_event( 'nav_ack_toggle', $new_ack );
62 0 $self->_last_ack_status( $new_ack );
63 }
64  
65 0 return 1;
66 }
67  
68  
69 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 1 __PACKAGE__->meta->make_immutable;
71 1 1;
72 __END__
73  
74  
75 =head1 NAME
76  
77 UAV::Pilot::NavCollector::AckEvents
78  
79 =head1 SYNOPSIS
80  
81 my $easy_event = UAV::Pilot::EasyEvent->new;
82 my $ack = UAV::Pilot::NavCollector::AckEvents->new({
83 easy_event => $easy_event,
84 });
85  
86 $easy_event->add_event( 'nav_ack_on' => sub {
87 say "ACK control bit is on";
88 });
89 $easy_event->add_event( 'nav_ack_off' => sub {
90 say "ACK control bit is off";
91 });
92 $easy_event->add_event( 'nav_ack_toggle' => sub {
93 say "ACK control bit toggled";
94 });
95  
96 =head1 DESCRIPTION
97  
98 Does the C<UAV::Pilot::NavCollector> role to fire off events into
99 C<UAV::Pilot::EasyEvent> based on the ACK control bit. Each nav packet with
100 the bit on will fire a C<nav_ack_on> event, and C<nav_ack_off> when off. If
101 the state toggles, C<nav_ack_toggle> is sent.
102  
103 =cut
↑ Summary Pilot/Video/FileDump.pm »