| 1 | # ABSTRACT: A class representing a state from the OpenSky Network API | ||||||||||||
| 2 | |||||||||||||
| 3 | package OpenSky::API::Core::StateVector; | ||||||||||||
| 4 | |||||||||||||
| 5 | 5 | our $VERSION = '0.004'; | |||||||||||
| 6 | 5 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 5 | ▶ | use experimental qw(signatures); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 5 | my @PARAMS = qw( | |||||||||||
| 10 | icao24 | ||||||||||||
| 11 | callsign | ||||||||||||
| 12 | origin_country | ||||||||||||
| 13 | time_position | ||||||||||||
| 14 | last_contact | ||||||||||||
| 15 | longitude | ||||||||||||
| 16 | latitude | ||||||||||||
| 17 | baro_altitude | ||||||||||||
| 18 | on_ground | ||||||||||||
| 19 | velocity | ||||||||||||
| 20 | true_track | ||||||||||||
| 21 | vertical_rate | ||||||||||||
| 22 | sensors | ||||||||||||
| 23 | geo_altitude | ||||||||||||
| 24 | squawk | ||||||||||||
| 25 | spi | ||||||||||||
| 26 | position_source | ||||||||||||
| 27 | category | ||||||||||||
| 28 | ); | ||||||||||||
| 29 | |||||||||||||
| 30 | ▶ | around 'BUILDARGS' => sub ( $orig, $class, $state ) { | |||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 31 | 0 | my %value_for; | |||||||||||
| 32 | 0 | @value_for{ $class->_get_params } = @$state; | |||||||||||
| 33 | 0 | return $class->$orig(%value_for); | |||||||||||
| 34 | 5 | }; | |||||||||||
| 35 | |||||||||||||
| 36 | 5 | has [@PARAMS] => ( is => 'ro', required => 1 ); | |||||||||||
| 37 | |||||||||||||
| 38 | ▶ | sub _get_params ($class) { | |||||||||||
|
Subroutine
_get_params: not called CC=1 SCAR=6.9
| |||||||||||||
| 39 | 0 | return @PARAMS; | |||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | ▶ | sub category_name ($self) { | |||||||||||
|
Subroutine
category_name: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 43 | 0 | ▶ | my $category = $self->category // 0; | ||||||||||
|
Condition0%0/2
$self->category // 0
MC/DC0%0/1
$self->category // 0
$self->category
Truth table0%0/2
A
A= $self->category
| |||||||||||||
| 44 | 0 | ▶ | $category = 0 if $category > 20; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 0 | ▶ | return '' unless $category; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 0 | my @names = ( | |||||||||||
| 47 | 'No information at all', | ||||||||||||
| 48 | 'No ADS-B Emitter Category Information', | ||||||||||||
| 49 | 'Light (< 15500 lbs)', | ||||||||||||
| 50 | 'Small (15500 to 75000 lbs)', | ||||||||||||
| 51 | 'Large (75000 to 300000 lbs)', | ||||||||||||
| 52 | 'High Vortex Large (aircraft such as B-757)', | ||||||||||||
| 53 | 'Heavy (> 300000 lbs)', | ||||||||||||
| 54 | 'High Performance (> 5g acceleration and 400 kts)', | ||||||||||||
| 55 | 'Rotorcraft', | ||||||||||||
| 56 | 'Glider / sailplane', | ||||||||||||
| 57 | 'Lighter-than-air', | ||||||||||||
| 58 | 'Parachutist / Skydiver', | ||||||||||||
| 59 | 'Ultralight / hang-glider / paraglider', | ||||||||||||
| 60 | 'Reserved', | ||||||||||||
| 61 | 'Unmanned Aerial Vehicle', | ||||||||||||
| 62 | 'Space / Trans-atmospheric vehicle', | ||||||||||||
| 63 | 'Surface Vehicle – Emergency Vehicle', | ||||||||||||
| 64 | 'Surface Vehicle – Service Vehicle', | ||||||||||||
| 65 | 'Point Obstacle (includes tethered balloons)', | ||||||||||||
| 66 | 'Cluster Obstacle', | ||||||||||||
| 67 | 'Line Obstacle', | ||||||||||||
| 68 | ); | ||||||||||||
| 69 | 0 | return $names[$category]; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | ▶ | sub position_source_name ($self) { | |||||||||||
|
Subroutine
position_source_name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 73 | 0 | ▶ | my $source = $self->position_source // return 'Uknown'; | ||||||||||
|
Condition0%0/2
$self->position_source // (return "Uknown")
MC/DC0%0/1
$self->position_source // (return "Uknown")
$self->position_source
Truth table0%0/2
A
A= $self->position_source
| |||||||||||||
| 74 | 0 | my @sources = ( | |||||||||||
| 75 | 'ADS-B', | ||||||||||||
| 76 | 'ASTERIX', | ||||||||||||
| 77 | 'MLAT', | ||||||||||||
| 78 | 'FLARM', | ||||||||||||
| 79 | ); | ||||||||||||
| 80 | 0 | return $sources[$source]; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 84 | |||||||||||||
| 85 | __END__ | ||||||||||||
| 86 | |||||||||||||
| 87 | =pod | ||||||||||||
| 88 | |||||||||||||
| 89 | =encoding UTF-8 | ||||||||||||
| 90 | |||||||||||||
| 91 | =head1 NAME | ||||||||||||
| 92 | |||||||||||||
| 93 | OpenSky::API::Core::StateVector - A class representing a state from the OpenSky Network API | ||||||||||||
| 94 | |||||||||||||
| 95 | =head1 VERSION | ||||||||||||
| 96 | |||||||||||||
| 97 | version 0.004 | ||||||||||||
| 98 | |||||||||||||
| 99 | =head1 SYNOPSIS | ||||||||||||
| 100 | |||||||||||||
| 101 | use OpenSky::API; | ||||||||||||
| 102 | my $opensky = OpenSky::API->new; | ||||||||||||
| 103 | my $states = $opensky->get_states; | ||||||||||||
| 104 | my $state = $states->[0]; | ||||||||||||
| 105 | say $state->callsign; | ||||||||||||
| 106 | |||||||||||||
| 107 | =head1 DESCRIPTION | ||||||||||||
| 108 | |||||||||||||
| 109 | This class is not to be instantiated directly. It is a read-only class representing an | ||||||||||||
| 110 | L<OpenSky state vector|https://openskynetwork.github.io/opensky-api/index.html#state-vectors>. | ||||||||||||
| 111 | |||||||||||||
| 112 | All attributes are read-only. | ||||||||||||
| 113 | |||||||||||||
| 114 | =head2 C<icao24> | ||||||||||||
| 115 | |||||||||||||
| 116 | Unique ICAO 24-bit address of the transponder in hex string representation. | ||||||||||||
| 117 | |||||||||||||
| 118 | =head2 C<callsign> | ||||||||||||
| 119 | |||||||||||||
| 120 | Callsign of the vehicle (8 chars). Can be null if no callsign has been received. | ||||||||||||
| 121 | |||||||||||||
| 122 | =head2 C<origin_country> | ||||||||||||
| 123 | |||||||||||||
| 124 | Country name inferred from the ICAO 24-bit address. | ||||||||||||
| 125 | |||||||||||||
| 126 | =head2 C<time_position> | ||||||||||||
| 127 | |||||||||||||
| 128 | Unix timestamp (seconds) for the last position update. Can be null if no position report was received by OpenSky within the past 15s. | ||||||||||||
| 129 | |||||||||||||
| 130 | =head2 C<last_contact> | ||||||||||||
| 131 | |||||||||||||
| 132 | Unix timestamp (seconds) for the last update in general. This field is updated for any new, valid message received from the transponder. | ||||||||||||
| 133 | |||||||||||||
| 134 | =head2 C<longitude> | ||||||||||||
| 135 | |||||||||||||
| 136 | WGS-84 longitude in decimal degrees. Can be null. | ||||||||||||
| 137 | |||||||||||||
| 138 | =head2 C<latitude> | ||||||||||||
| 139 | |||||||||||||
| 140 | WGS-84 latitude in decimal degrees. Can be null. | ||||||||||||
| 141 | |||||||||||||
| 142 | =head2 C<baro_altitude> | ||||||||||||
| 143 | |||||||||||||
| 144 | Barometric altitude in meters. Can be null. | ||||||||||||
| 145 | |||||||||||||
| 146 | =head2 C<on_ground> | ||||||||||||
| 147 | |||||||||||||
| 148 | Boolean value which indicates if the position was retrieved from a surface position report. | ||||||||||||
| 149 | |||||||||||||
| 150 | =head2 C<velocity> | ||||||||||||
| 151 | |||||||||||||
| 152 | Velocity over ground in m/s. Can be null. | ||||||||||||
| 153 | |||||||||||||
| 154 | =head2 C<true_track> | ||||||||||||
| 155 | |||||||||||||
| 156 | True track in decimal degrees clockwise from north (north=0°). Can be null. | ||||||||||||
| 157 | |||||||||||||
| 158 | =head2 C<vertical_rate> | ||||||||||||
| 159 | |||||||||||||
| 160 | Vertical rate in m/s. A positive value indicates that the airplane is climbing, a negative value indicates that it descends. Can be null. | ||||||||||||
| 161 | |||||||||||||
| 162 | =head2 C<sensors> | ||||||||||||
| 163 | |||||||||||||
| 164 | IDs of the receivers which contributed to this state vector. Is null if no filtering for sensor was used in the request. | ||||||||||||
| 165 | |||||||||||||
| 166 | =head2 C<geo_altitude> | ||||||||||||
| 167 | |||||||||||||
| 168 | Geometric altitude in meters. Can be null. | ||||||||||||
| 169 | |||||||||||||
| 170 | =head2 C<squawk> | ||||||||||||
| 171 | |||||||||||||
| 172 | The transponder code aka Squawk. Can be null. | ||||||||||||
| 173 | |||||||||||||
| 174 | =head2 C<spi> | ||||||||||||
| 175 | |||||||||||||
| 176 | Whether flight status indicates special purpose indicator. | ||||||||||||
| 177 | |||||||||||||
| 178 | =head2 C<position_source_name> | ||||||||||||
| 179 | |||||||||||||
| 180 | Returns the name of the position source. Can be an empty string. | ||||||||||||
| 181 | |||||||||||||
| 182 | =head2 C<position_source> | ||||||||||||
| 183 | |||||||||||||
| 184 | Integer. Origin of this state’s position: | ||||||||||||
| 185 | |||||||||||||
| 186 | 0 = ADS-B | ||||||||||||
| 187 | 1 = ASTERIX | ||||||||||||
| 188 | 2 = MLAT | ||||||||||||
| 189 | 3 = FLARM | ||||||||||||
| 190 | |||||||||||||
| 191 | =head2 C<category_name> | ||||||||||||
| 192 | |||||||||||||
| 193 | Returns the name of the aircraft category. Can be an empty string. | ||||||||||||
| 194 | |||||||||||||
| 195 | If C<< $opensky->get_states >> is called without C<extended> set to true, this | ||||||||||||
| 196 | method will always return an empty string. | ||||||||||||
| 197 | |||||||||||||
| 198 | =head2 C<category> | ||||||||||||
| 199 | |||||||||||||
| 200 | Integer. Aircraft category. Can be null. | ||||||||||||
| 201 | |||||||||||||
| 202 | 0 = No information at all | ||||||||||||
| 203 | 1 = No ADS-B Emitter Category Information | ||||||||||||
| 204 | 2 = Light (< 15500 lbs) | ||||||||||||
| 205 | 3 = Small (15500 to 75000 lbs) | ||||||||||||
| 206 | 4 = Large (75000 to 300000 lbs) | ||||||||||||
| 207 | 5 = High Vortex Large (aircraft such as B-757) | ||||||||||||
| 208 | 6 = Heavy (> 300000 lbs) | ||||||||||||
| 209 | 7 = High Performance (> 5g acceleration and 400 kts) | ||||||||||||
| 210 | 8 = Rotorcraft | ||||||||||||
| 211 | 9 = Glider / sailplane | ||||||||||||
| 212 | 10 = Lighter-than-air | ||||||||||||
| 213 | 11 = Parachutist / Skydiver | ||||||||||||
| 214 | 12 = Ultralight / hang-glider / paraglider | ||||||||||||
| 215 | 13 = Reserved | ||||||||||||
| 216 | 14 = Unmanned Aerial Vehicle | ||||||||||||
| 217 | 15 = Space / Trans-atmospheric vehicle | ||||||||||||
| 218 | 16 = Surface Vehicle – Emergency Vehicle | ||||||||||||
| 219 | 17 = Surface Vehicle – Service Vehicle | ||||||||||||
| 220 | 18 = Point Obstacle (includes tethered balloons) | ||||||||||||
| 221 | 19 = Cluster Obstacle | ||||||||||||
| 222 | 20 = Line Obstacle | ||||||||||||
| 223 | |||||||||||||
| 224 | =head1 AUTHOR | ||||||||||||
| 225 | |||||||||||||
| 226 | Curtis "Ovid" Poe <curtis.poe@gmail.com> | ||||||||||||
| 227 | |||||||||||||
| 228 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 229 | |||||||||||||
| 230 | This software is Copyright (c) 2023 by Curtis "Ovid" Poe. | ||||||||||||
| 231 | |||||||||||||
| 232 | This is free software, licensed under: | ||||||||||||
| 233 | |||||||||||||
| 234 | The Artistic License 2.0 (GPL Compatible) | ||||||||||||
| 235 | |||||||||||||
| 236 | =cut | ||||||||||||