| 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::ARDrone::Driver::Mock; | ||||||||||
| 25 | 14 | $UAV::Pilot::ARDrone::Driver::Mock::VERSION = '1.0'; | |||||||||
| 26 | 14 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 14 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 14 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 14 | ▶ | use UAV::Pilot::ARDrone::NavPacket; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 14 | extends 'UAV::Pilot::ARDrone::Driver'; | |||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | 14 | has 'last_cmd' => ( | |||||||||
| 35 | is => 'ro', | ||||||||||
| 36 | isa => 'Str', | ||||||||||
| 37 | writer => '_set_last_cmd', | ||||||||||
| 38 | ); | ||||||||||
| 39 | has '_saved_commands' => ( | ||||||||||
| 40 | traits => ['Array'], | ||||||||||
| 41 | is => 'rw', | ||||||||||
| 42 | isa => 'ArrayRef[Str]', | ||||||||||
| 43 | 12 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 14 | handles => { | |||||||||
| 45 | '_add_saved_command' => 'push', | ||||||||||
| 46 | }, | ||||||||||
| 47 | ); | ||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | sub connect | ||||||||||
| 51 | { | ||||||||||
| 52 | 4 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
connect: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 53 | 4 | $self->_init_nav_data; | |||||||||
| 54 | 4 | $self->_init_drone; | |||||||||
| 55 | 4 | return 1; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | sub _send_multi_cmds | ||||||||||
| 60 | { | ||||||||||
| 61 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_send_multi_cmds: not called CC=2 SCAR=17.9
| |||||||||||
| 62 | 0 | my @multi_cmds = @{ $self->_multi_cmds }; | |||||||||
| 63 | 0 | $self->_set_last_cmd( join( '', @multi_cmds ) ); | |||||||||
| 64 | 0 | $self->_add_saved_command( $_ ) for @multi_cmds; | |||||||||
| 65 | 0 | return 1; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | sub _send_cmd | ||||||||||
| 69 | { | ||||||||||
| 70 | 145 | ▶ | my ($self, $cmd) = @_; | ||||||||
|
Subroutine
_send_cmd: called CC=2 SCAR=6.9
| |||||||||||
| 71 | |||||||||||
| 72 | 145 | ▶ | if( $self->_is_multi_cmd_mode ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 3 | $self->_add_multi_cmd( $cmd ); | |||||||||
| 74 | } | ||||||||||
| 75 | else { | ||||||||||
| 76 | 142 | $self->_set_last_cmd( $cmd ); | |||||||||
| 77 | 142 | $self->_add_saved_command( $cmd ); | |||||||||
| 78 | } | ||||||||||
| 79 | 145 | return 1; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | sub read_nav_packet | ||||||||||
| 83 | { | ||||||||||
| 84 | 7 | ▶ | my ($self, @packet) = @_; | ||||||||
|
Subroutine
read_nav_packet: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 85 | 7 | my $packet = pack( 'H*', join('', @packet) ); | |||||||||
| 86 | 7 | my $nav_packet = UAV::Pilot::ARDrone::NavPacket->new({ | |||||||||
| 87 | packet => $packet, | ||||||||||
| 88 | }); | ||||||||||
| 89 | 7 | $self->_set_last_nav_packet( $nav_packet ); | |||||||||
| 90 | 7 | return 1; | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | sub _init_nav_data | ||||||||||
| 94 | { | ||||||||||
| 95 | 4 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_init_nav_data: called CC=1 SCAR=0.0
| |||||||||||
| 96 | |||||||||||
| 97 | 4 | $self->at_config( | |||||||||
| 98 | $self->ARDRONE_CONFIG_GENERAL_NAVDATA_DEMO, | ||||||||||
| 99 | $self->TRUE, | ||||||||||
| 100 | ); | ||||||||||
| 101 | |||||||||||
| 102 | 4 | return 1; | |||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | sub saved_commands | ||||||||||
| 106 | { | ||||||||||
| 107 | 122 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
saved_commands: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 108 | 122 | my @cmds = @{ $self->_saved_commands }; | |||||||||
| 109 | 122 | $self->_saved_commands( [] ); | |||||||||
| 110 | 122 | return @cmds; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | |||||||||||
| 114 | 14 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 115 | 14 | __PACKAGE__->meta->make_immutable; | |||||||||
| 116 | 14 | 1; | |||||||||
| 117 | __END__ | ||||||||||
| 118 | |||||||||||