| 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; | ||||||||||
| 25 | 2 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 2 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 2 | ▶ | use File::ShareDir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 2 | ▶ | use File::HomeDir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 2 | ▶ | use Log::Log4perl; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | 2 | ▶ | use constant DIST_NAME => 'UAV-Pilot'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 2 | ▶ | use constant LOG_CONF_FILE => 'log4perl.conf'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | |||||||||||
| 36 | 2 | our $VERSION = 1.0; | |||||||||
| 37 | 2 | our $LOG_WAS_INITD = 0; | |||||||||
| 38 | |||||||||||
| 39 | # ABSTRACT: Base library for controlling UAVs | ||||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | sub default_module_dir | ||||||||||
| 43 | { | ||||||||||
| 44 | 0 | ▶ | my ($class) = @_; | ||||||||
|
Subroutine
default_module_dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 45 | 0 | my $dir = File::ShareDir::dist_dir( $class->DIST_NAME ); | |||||||||
| 46 | 0 | return $dir; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | sub default_config_dir | ||||||||||
| 50 | { | ||||||||||
| 51 | 0 | ▶ | my ($class) = @_; | ||||||||
|
Subroutine
default_config_dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 52 | 0 | my $dir = File::HomeDir->my_dist_config( $class->DIST_NAME, { | |||||||||
| 53 | create => 1, | ||||||||||
| 54 | }); | ||||||||||
| 55 | 0 | return $dir, | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | sub init_log | ||||||||||
| 59 | { | ||||||||||
| 60 | 0 | ▶ | my ($class) = @_; | ||||||||
|
Subroutine
init_log: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 61 | 0 | ▶ | return if $LOG_WAS_INITD; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | my $conf_dir = $class->default_config_dir; | |||||||||
| 63 | 0 | my $log_conf = File::Spec->catfile( $conf_dir, $class->LOG_CONF_FILE ); | |||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | $class->_make_default_log_conf( $log_conf ) if ! -e $log_conf; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | |||||||||||
| 67 | 0 | Log::Log4perl::init( $log_conf ); | |||||||||
| 68 | 0 | return 1; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | sub checksum_fletcher8 | ||||||||||
| 72 | { | ||||||||||
| 73 | 0 | ▶ | my ($class, @bytes) = @_; | ||||||||
|
Subroutine
checksum_fletcher8: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 74 | 0 | my $ck_a = 0; | |||||||||
| 75 | 0 | my $ck_b = 0; | |||||||||
| 76 | |||||||||||
| 77 | 0 | foreach (@bytes) { | |||||||||
| 78 | 0 | $ck_a = ($ck_a + $_) & 0xFF; | |||||||||
| 79 | 0 | $ck_b = ($ck_b + $ck_a) & 0xFF; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 0 | return ($ck_a, $ck_b); | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | sub convert_32bit_LE | ||||||||||
| 86 | { | ||||||||||
| 87 | 0 | ▶ | my ($class, @bytes) = @_; | ||||||||
|
Subroutine
convert_32bit_LE: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 88 | 0 | my $val = $bytes[0] | |||||||||
| 89 | | ($bytes[1] << 8) | ||||||||||
| 90 | | ($bytes[2] << 16) | ||||||||||
| 91 | | ($bytes[3] << 24); | ||||||||||
| 92 | 0 | return $val; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | sub convert_16bit_LE | ||||||||||
| 96 | { | ||||||||||
| 97 | 0 | ▶ | my ($class, @bytes) = @_; | ||||||||
|
Subroutine
convert_16bit_LE: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 98 | 0 | my $val = $bytes[0] | ($bytes[1] << 8); | |||||||||
| 99 | 0 | return $val; | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | sub convert_32bit_BE | ||||||||||
| 103 | { | ||||||||||
| 104 | 0 | ▶ | my ($class, @bytes) = @_; | ||||||||
|
Subroutine
convert_32bit_BE: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 105 | 0 | my $val = ($bytes[0] << 24) | |||||||||
| 106 | | ($bytes[1] << 16) | ||||||||||
| 107 | | ($bytes[2] << 8) | ||||||||||
| 108 | | $bytes[3]; | ||||||||||
| 109 | 0 | return $val; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | sub convert_16bit_BE | ||||||||||
| 113 | { | ||||||||||
| 114 | 0 | ▶ | my ($class, @bytes) = @_; | ||||||||
|
Subroutine
convert_16bit_BE: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 115 | 0 | my $val = ($bytes[0] << 8) | $bytes[1]; | |||||||||
| 116 | 0 | return $val; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | sub _make_default_log_conf | ||||||||||
| 120 | { | ||||||||||
| 121 | 0 | ▶ | my ($class, $out_file) = @_; | ||||||||
|
Subroutine
_make_default_log_conf: not called CC=2 SCAR=17.9
| |||||||||||
| 122 | |||||||||||
| 123 | 0 | ▶ | open( my $out, '>', $out_file ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | or die "Can't open [$out_file] for writing: $!\n"; | ||||||||||
| 125 | |||||||||||
| 126 | 0 | print $out "log4j.rootLogger=WARN, A1\n"; | |||||||||
| 127 | 0 | print $out "log4j.appender.A1=Log::Log4perl::Appender::Screen\n"; | |||||||||
| 128 | 0 | print $out "log4j.appender.A1.layout=org.apache.log4j.PatternLayout\n"; | |||||||||
| 129 | 0 | print $out "log4j.appender.A1.layout.ConversionPattern=" | |||||||||
| 130 | . '%-4r [%t] %-5p %c %t - %m%n' . "\n"; | ||||||||||
| 131 | |||||||||||
| 132 | 0 | close $out; | |||||||||
| 133 | 0 | return 1; | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | |||||||||||
| 137 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 138 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 139 | 2 | 1; | |||||||||
| 140 | __END__ | ||||||||||
| 141 | |||||||||||
| 142 | |||||||||||
| 143 | =head1 NAME | ||||||||||
| 144 | |||||||||||
| 145 | UAV::Pilot - Base library for controlling UAVs | ||||||||||
| 146 | |||||||||||
| 147 | =head1 DESCRIPTION | ||||||||||
| 148 | |||||||||||
| 149 | This library does not support controlling any UAVs on its own. Rather, it | ||||||||||
| 150 | provides the basic support for implementing other UAV libraries, much the same | ||||||||||
| 151 | way DBI provides support for implementing different database drivers. | ||||||||||
| 152 | |||||||||||
| 153 | If you would like to control the Parrot AR.Drone, you should also install | ||||||||||
| 154 | C<UAV::Pilot::ARDrone>, and probably C<UAV::Pilot::SDL> and | ||||||||||
| 155 | C<UAV::Pilot::Video::Ffmpeg> as well. | ||||||||||
| 156 | |||||||||||
| 157 | =head1 LICENSE | ||||||||||
| 158 | |||||||||||
| 159 | Copyright (c) 2014 Timm Murray | ||||||||||
| 160 | All rights reserved. | ||||||||||
| 161 | |||||||||||
| 162 | Redistribution and use in source and binary forms, with or without modification, are | ||||||||||
| 163 | permitted provided that the following conditions are met: | ||||||||||
| 164 | |||||||||||
| 165 | * Redistributions of source code must retain the above copyright notice, this list of | ||||||||||
| 166 | conditions and the following disclaimer. | ||||||||||
| 167 | * Redistributions in binary form must reproduce the above copyright notice, this list of | ||||||||||
| 168 | conditions and the following disclaimer in the documentation and/or other materials | ||||||||||
| 169 | provided with the distribution. | ||||||||||
| 170 | |||||||||||
| 171 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS | ||||||||||
| 172 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||||||||||
| 173 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||||||||||
| 174 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||||||||||
| 175 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||||||||||
| 176 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||||||||
| 177 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||||||||||
| 178 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||||||||||
| 179 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||
| 180 | |||||||||||
| 181 | |||||||||||
| 182 | =cut | ||||||||||