| 1 | # Copyright (c) 2015 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 | $UAV::Pilot::NavCollector::AckEvents::VERSION = '1.1'; | |||||||||
| 26 | 1 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | |||||||||||
| 30 | 1 | with 'UAV::Pilot::NavCollector'; | |||||||||
| 31 | 1 | with 'UAV::Pilot::Logger'; | |||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | 1 | has 'easy_event' => ( | |||||||||
| 35 | is => 'ro', | ||||||||||
| 36 | isa => 'UAV::Pilot::EasyEvent', | ||||||||||
| 37 | ); | ||||||||||
| 38 | 1 | has '_last_ack_status' => ( | |||||||||
| 39 | is => 'rw', | ||||||||||
| 40 | isa => 'Bool', | ||||||||||
| 41 | default => 0, | ||||||||||
| 42 | ); | ||||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | sub got_new_nav_packet | ||||||||||
| 46 | { | ||||||||||
| 47 | 0 | ▶ | my ($self, $packet) = @_; | ||||||||
|
Subroutine
got_new_nav_packet: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 48 | 0 | my $new_ack = $packet->state_control_received; | |||||||||
| 49 | 0 | my $last_ack = $self->_last_ack_status; | |||||||||
| 50 | 0 | my $event = $self->easy_event; | |||||||||
| 51 | 0 | my $logger = $self->_logger; | |||||||||
| 52 | |||||||||||
| 53 | 0 | $logger->info( "Got nav ACK of $new_ack, old ack is $last_ack" ); | |||||||||
| 54 | 0 | ▶ | my $send_event = $new_ack | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | ? 'nav_ack_on' | ||||||||||
| 56 | : 'nav_ack_off'; | ||||||||||
| 57 | 0 | $logger->info( "Sending $send_event event" ); | |||||||||
| 58 | 0 | $event->send_event( $send_event ); | |||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | if( $new_ack != $last_ack ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | $logger->info( "Sending nav_ack_toggle event" ); | |||||||||
| 62 | 0 | $event->send_event( 'nav_ack_toggle', $new_ack ); | |||||||||
| 63 | 0 | $self->_last_ack_status( $new_ack ); | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | return 1; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | |||||||||||
| 70 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 71 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 72 | 1 | 1; | |||||||||
| 73 | __END__ | ||||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | =head1 NAME | ||||||||||
| 77 | |||||||||||
| 78 | UAV::Pilot::NavCollector::AckEvents | ||||||||||
| 79 | |||||||||||
| 80 | =head1 SYNOPSIS | ||||||||||
| 81 | |||||||||||
| 82 | my $easy_event = UAV::Pilot::EasyEvent->new; | ||||||||||
| 83 | my $ack = UAV::Pilot::NavCollector::AckEvents->new({ | ||||||||||
| 84 | easy_event => $easy_event, | ||||||||||
| 85 | }); | ||||||||||
| 86 | |||||||||||
| 87 | $easy_event->add_event( 'nav_ack_on' => sub { | ||||||||||
| 88 | say "ACK control bit is on"; | ||||||||||
| 89 | }); | ||||||||||
| 90 | $easy_event->add_event( 'nav_ack_off' => sub { | ||||||||||
| 91 | say "ACK control bit is off"; | ||||||||||
| 92 | }); | ||||||||||
| 93 | $easy_event->add_event( 'nav_ack_toggle' => sub { | ||||||||||
| 94 | say "ACK control bit toggled"; | ||||||||||
| 95 | }); | ||||||||||
| 96 | |||||||||||
| 97 | =head1 DESCRIPTION | ||||||||||
| 98 | |||||||||||
| 99 | Does the C<UAV::Pilot::NavCollector> role to fire off events into | ||||||||||
| 100 | C<UAV::Pilot::EasyEvent> based on the ACK control bit. Each nav packet with | ||||||||||
| 101 | the bit on will fire a C<nav_ack_on> event, and C<nav_ack_off> when off. If | ||||||||||
| 102 | the state toggles, C<nav_ack_toggle> is sent. | ||||||||||
| 103 | |||||||||||
| 104 | =cut | ||||||||||