File Coverage

blib/lib/Rinchi/CIGIPP/HAT_HOTRequest.pm
Criterion Covered Total %
statement 73 104 70.1
branch 14 38 36.8
condition 4 12 33.3
subroutine 19 21 90.4
pod 17 17 100.0
total 127 192 66.1


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78af2ae-200e-11de-bdb8-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::HAT_HOTRequest;
8              
9 1     1   25 use 5.006;
  1         4  
  1         40  
10 1     1   75 use strict;
  1         3  
  1         31  
11 1     1   6 use warnings;
  1         10  
  1         25  
12 1     1   6 use Carp;
  1         3  
  1         1696  
13              
14             require Exporter;
15              
16             our @ISA = qw(Exporter);
17              
18             # Items to export into callers namespace by default. Note: do not export
19             # names by default without a very good reason. Use EXPORT_OK instead.
20             # Do not simply export all your public functions/methods/constants.
21              
22             # This allows declaration use Rinchi::CIGI::AtmosphereControl ':all';
23             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
24             # will save memory.
25             our %EXPORT_TAGS = ( 'all' => [ qw(
26            
27             ) ] );
28              
29             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
30              
31             our @EXPORT = qw(
32            
33             );
34              
35             our $VERSION = '0.02';
36              
37             # Preloaded methods go here.
38              
39             =head1 NAME
40              
41             Rinchi::CIGIPP::HAT_HOTRequest - Perl extension for the Common Image Generator
42             Interface - HAT/HOTRequest data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::HAT_HOTRequest;
47             my $hgt_rqst = Rinchi::CIGIPP::HAT_HOTRequest->new();
48              
49             $packet_type = $hgt_rqst->packet_type();
50             $packet_size = $hgt_rqst->packet_size();
51             $request_ident = $hgt_rqst->request_ident(13384);
52             $coordinate_system = $hgt_rqst->coordinate_system(Rinchi::CIGIPP->GeodeticCS);
53             $request_type = $hgt_rqst->request_type(Rinchi::CIGIPP->HeightOfTerrain);
54             $update_period = $hgt_rqst->update_period(156);
55             $entity_ident = $hgt_rqst->entity_ident(48093);
56             $latitude = $hgt_rqst->latitude(69.592);
57             $x_offset = $hgt_rqst->x_offset(17.607);
58             $longitude = $hgt_rqst->longitude(68.523);
59             $y_offset = $hgt_rqst->y_offset(20.113);
60             $altitude = $hgt_rqst->altitude(43.044);
61             $z_offset = $hgt_rqst->z_offset(23.044);
62              
63             =head1 DESCRIPTION
64              
65             The HAT/HOT Request packet is used by the Host to request the Height Above
66             Terrain (HAT) of a specified point and/or the Height Of Terrain (HOT) below a
67             specified test point. The test point may be defined with respect to either the
68             Geodetic coordinate system or an entity's body coordinate system.
69              
70             Each request is identified by the HAT/HOT ID attribute. When the IG responds to
71             the request, it will set the HAT/HOT ID attribute of the response packet to
72             match that in the request.
73              
74             The Update Period attribute specifies the number of frames between periodic
75             responses. This allows the Host to send just one HAT/HOT Request packet but
76             receive continuous responses if the test point will not move with respect to
77             the specified coordinate system. If Update Period is set to zero, the request
78             will be treated as a one- shot request and the IG will return a single
79             response. The Host should manipulate the value of HAT/HOT ID so that an ID is
80             not reused before the IG has sufficient time to process and respond to the
81             request. If Update Period is set to some value n greater than zero, the IG will
82             return a request every nth frame until the Entity is destroyed or until the
83             Update Period attribute set to zero.
84              
85             If the Request Type attribute is set to HAT (0) or HOT (1), the IG will respond
86             with a HAT/HOT Response packet (Section 4.2.2) containing the requested datum.
87             If the attribute is set to Extended HAT/HOT (2), the IG will respond with a
88             HAT/HOT Extended Response packet (Section 4.2.3) containing both data, along
89             with the surface material code and normal vector.
90              
91             The IG can only return valid HAT and/or HOT data if the test point is located
92             within the bounds of the current database. If the HAT or HOT cannot be
93             calculated, the Valid attribute of the response packet will be set to Invalid
94             (0).
95             Besides the range of the HAT/HOT ID attribute, there is no restriction on the
96             number of HAT and/or HOT requests that can be sent in a single frame; however,
97             the response time of the IG might be degraded as the number of requests increases.
98              
99             =head2 EXPORT
100              
101             None by default.
102              
103             #==============================================================================
104              
105             =item new $hgt_rqst = Rinchi::CIGIPP::HAT_HOTRequest->new()
106              
107             Constructor for Rinchi::HAT_HOTRequest.
108              
109             =cut
110              
111             sub new {
112 1     1 1 216 my $class = shift;
113 1   33     28 $class = ref($class) || $class;
114              
115 1         16 my $self = {
116             '_Buffer' => '',
117             '_ClassIdent' => 'f78af2ae-200e-11de-bdb8-001c25551abc',
118             '_Pack' => 'CCSCCSddd',
119             '_Swap1' => 'CCvCCvVVVVVV',
120             '_Swap2' => 'CCnCCnNNNNNN',
121             'packetType' => 24,
122             'packetSize' => 32,
123             'requestIdent' => 0,
124             '_bitfields1' => 0, # Includes bitfields unused41, coordinateSystem, and requestType.
125             'coordinateSystem' => 0,
126             'requestType' => 0,
127             'updatePeriod' => 0,
128             'entityIdent' => 0,
129             'latitude_xOffset' => 0,
130             'longitude_yOffset' => 0,
131             'altitude_zOffset' => 0,
132             };
133              
134 1 50       5 if (@_) {
135 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
136 0         0 $self->{'_Buffer'} = $_[0][0];
137             } elsif (ref($_[0]) eq 'HASH') {
138 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
139 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
140             }
141             }
142             }
143              
144 1         4 bless($self,$class);
145 1         3 return $self;
146             }
147              
148             #==============================================================================
149              
150             =item sub packet_type()
151              
152             $value = $hgt_rqst->packet_type();
153              
154             Data Packet Identifier.
155              
156             This attribute identifies this data packet as the HAT/HOT Request packet. The
157             value of this attribute must be 24.
158              
159             =cut
160              
161             sub packet_type() {
162 1     1 1 7 my ($self) = @_;
163 1         9 return $self->{'packetType'};
164             }
165              
166             #==============================================================================
167              
168             =item sub packet_size()
169              
170             $value = $hgt_rqst->packet_size();
171              
172             Data Packet Size.
173              
174             This attribute indicates the number of bytes in this data packet. The value of
175             this attribute must be 32.
176              
177             =cut
178              
179             sub packet_size() {
180 1     1 1 79 my ($self) = @_;
181 1         5 return $self->{'packetSize'};
182             }
183              
184             #==============================================================================
185              
186             =item sub request_ident([$newValue])
187              
188             $value = $hgt_rqst->request_ident($newValue);
189              
190             HAT/HOT ID.
191              
192             This attribute identifies the HAT/HOT request. When the IG returns a HAT/HOT
193             Response or HAT/HOT Extended Response packet in response to this request, the
194             HAT/HOT ID attribute of that packet will contain this value to correlate the
195             response with this request.
196              
197             =cut
198              
199             sub request_ident() {
200 1     1 1 6 my ($self,$nv) = @_;
201 1 50       12 if (defined($nv)) {
202 1         2 $self->{'requestIdent'} = $nv;
203             }
204              
205 1         4 return $self->{'requestIdent'};
206             }
207              
208             #==============================================================================
209              
210             =item sub coordinate_system([$newValue])
211              
212             $value = $hgt_rqst->coordinate_system($newValue);
213              
214             Coordinate System.
215              
216             This attribute specifies the coordinate system within which the test point is
217             defined.
218             If this attribute is set to Geodetic (0), the test point is defined as a
219             Latitude, Longitude, and Altitude. If this attribute is set to Entity (1), the
220             test point is defined as X, Y, and Z offsets from the reference point of the
221             entity specified by Entity ID.
222              
223             GeodeticCS 0
224             EntityCS 1
225              
226             =cut
227              
228             sub coordinate_system() {
229 1     1 1 3 my ($self,$nv) = @_;
230 1 50       4 if (defined($nv)) {
231 1 50 33     7 if (($nv==0) or ($nv==1)) {
232 1         3 $self->{'coordinateSystem'} = $nv;
233 1         2 $self->{'_bitfields1'} |= ($nv << 2) &0x04;
234             } else {
235 0         0 carp "coordinate_system must be 0 (GeodeticCS), or 1 (EntityCS).";
236             }
237             }
238              
239 1         4 return (($self->{'_bitfields1'} & 0x04) >> 2);
240             }
241              
242             #==============================================================================
243              
244             =item sub request_type([$newValue])
245              
246             $value = $hgt_rqst->request_type($newValue);
247              
248             Request Type.
249              
250             This attribute determines what type of response packet the IG should return for
251             this request.
252              
253             If this attribute is set to HAT (0), the IG will respond with a HAT/HOT
254             Response packet containing the Height Above Terrain. If this attribute is set
255             to HOT (1), the IG will respond with a HAT/HOT Response packet containing the
256             Height Of Terrain. If this attribute is set to Extended (2), the IG will
257             respond with a HAT/HOT Extended Response packet, which contains both the Height
258             Above Terrain and the Height Of Terrain.
259              
260             HeightAboveTerrain 0
261             HeightOfTerrain 1
262             Extended 2
263              
264             =cut
265              
266             sub request_type() {
267 1     1 1 2 my ($self,$nv) = @_;
268 1 50       4 if (defined($nv)) {
269 1 50 33     17 if (($nv==0) or ($nv==1) or ($nv==2)) {
      33        
270 1         3 $self->{'requestType'} = $nv;
271 1         3 $self->{'_bitfields1'} |= $nv &0x03;
272             } else {
273 0         0 carp "request_type must be 0 (HeightAboveTerrain), 1 (HeightOfTerrain), or 2 (Extended).";
274             }
275             }
276              
277 1         3 return ($self->{'_bitfields1'} & 0x03);
278             }
279              
280             #==============================================================================
281              
282             =item sub update_period([$newValue])
283              
284             $value = $hgt_rqst->update_period($newValue);
285              
286             Update Period.
287              
288             This attribute specifies the interval between successive responses to this
289             request. A value of zero (0) indicates that the IG should return a single
290             response. A value of n > 0 indicates that the IG should return a response every
291             nth frame.
292              
293             =cut
294              
295             sub update_period() {
296 1     1 1 6 my ($self,$nv) = @_;
297 1 50       4 if (defined($nv)) {
298 1         2 $self->{'updatePeriod'} = $nv;
299             }
300 1         4 return $self->{'updatePeriod'};
301             }
302              
303             #==============================================================================
304              
305             =item sub entity_ident([$newValue])
306              
307             $value = $hgt_rqst->entity_ident($newValue);
308              
309             Entity ID.
310              
311             This attribute specifies the entity relative to which the test point is
312             defined. This attribute is ignored if Coordinate System is set to Geodetic (0).
313              
314             =cut
315              
316             sub entity_ident() {
317 1     1 1 6 my ($self,$nv) = @_;
318 1 50       4 if (defined($nv)) {
319 1         4 $self->{'entityIdent'} = $nv;
320             }
321 1         3 return $self->{'entityIdent'};
322             }
323              
324             #==============================================================================
325              
326             =item sub latitude([$newValue])
327              
328             $value = $hgt_rqst->latitude($newValue);
329              
330             Latitude.
331              
332             This attribute specifies the latitude from which the HAT/HOT request is being made.
333              
334             =cut
335              
336             sub latitude() {
337 1     1 1 6 my ($self,$nv) = @_;
338 1 50       4 if (defined($nv)) {
339 1         3 $self->{'latitude_xOffset'} = $nv;
340             }
341 1         3 return $self->{'latitude_xOffset'};
342             }
343              
344             #==============================================================================
345              
346             =item sub x_offset([$newValue])
347              
348             $value = $hgt_rqst->x_offset($newValue);
349              
350             X Offset.
351              
352             This attribute specifies the latitude from which the HAT/HOT request is being
353             made. This value is given relative to the entity's reference point.
354              
355             =cut
356              
357             sub x_offset() {
358 1     1 1 6 my ($self,$nv) = @_;
359 1 50       10 if (defined($nv)) {
360 1         3 $self->{'latitude_xOffset'} = $nv;
361             }
362 1         4 return $self->{'latitude_xOffset'};
363             }
364              
365             #==============================================================================
366              
367             =item sub longitude([$newValue])
368              
369             $value = $hgt_rqst->longitude($newValue);
370              
371             Longitude.
372              
373             This attribute specifies the longitude from which the HAT/HOT request is being made.
374              
375             =cut
376              
377             sub longitude() {
378 1     1 1 6 my ($self,$nv) = @_;
379 1 50       4 if (defined($nv)) {
380 1         3 $self->{'longitude_yOffset'} = $nv;
381             }
382 1         3 return $self->{'longitude_yOffset'};
383             }
384              
385             #==============================================================================
386              
387             =item sub y_offset([$newValue])
388              
389             $value = $hgt_rqst->y_offset($newValue);
390              
391             Y Offset.
392              
393             This attribute specifies the longitude from which the HAT/HOT request is being
394             made. This value is given relative to the entity's reference point.
395              
396             =cut
397              
398             sub y_offset() {
399 1     1 1 6 my ($self,$nv) = @_;
400 1 50       4 if (defined($nv)) {
401 1         2 $self->{'longitude_yOffset'} = $nv;
402             }
403 1         3 return $self->{'longitude_yOffset'};
404             }
405              
406             #==============================================================================
407              
408             =item sub altitude([$newValue])
409              
410             $value = $hgt_rqst->altitude($newValue);
411              
412             Altitude.
413              
414             This attribute specifies the altitude from which the HAT/HOT request is being
415             made.
416             This attribute is ignored if Request Type is set to HOT (1).
417              
418             =cut
419              
420             sub altitude() {
421 1     1 1 16 my ($self,$nv) = @_;
422 1 50       4 if (defined($nv)) {
423 1         3 $self->{'altitude_zOffset'} = $nv;
424             }
425 1         4 return $self->{'altitude_zOffset'};
426             }
427              
428             #==============================================================================
429              
430             =item sub z_offset([$newValue])
431              
432             $value = $hgt_rqst->z_offset($newValue);
433              
434             Z Offset.
435              
436             This attribute specifies the altitude from which the HAT/HOT request is being
437             made. This value is given relative to the entity's reference point.
438              
439             =cut
440              
441             sub z_offset() {
442 1     1 1 5 my ($self,$nv) = @_;
443 1 50       4 if (defined($nv)) {
444 1         3 $self->{'altitude_zOffset'} = $nv;
445             }
446 1         3 return $self->{'altitude_zOffset'};
447             }
448              
449             #==========================================================================
450              
451             =item sub pack()
452              
453             $value = $hgt_rqst->pack();
454              
455             Returns the packed data packet.
456              
457             =cut
458              
459             sub pack($) {
460 1     1 1 6 my $self = shift ;
461            
462 1         7 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
463             $self->{'packetType'},
464             $self->{'packetSize'},
465             $self->{'requestIdent'},
466             $self->{'_bitfields1'}, # Includes bitfields unused41, coordinateSystem, and requestType.
467             $self->{'updatePeriod'},
468             $self->{'entityIdent'},
469             $self->{'latitude_xOffset'},
470             $self->{'longitude_yOffset'},
471             $self->{'altitude_zOffset'},
472             );
473              
474 1         3 return $self->{'_Buffer'};
475             }
476              
477             #==========================================================================
478              
479             =item sub unpack()
480              
481             $value = $hgt_rqst->unpack();
482              
483             Unpacks the packed data packet.
484              
485             =cut
486              
487             sub unpack($) {
488 0     0 1   my $self = shift @_;
489            
490 0 0         if (@_) {
491 0           $self->{'_Buffer'} = shift @_;
492             }
493 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
494 0           $self->{'packetType'} = $a;
495 0           $self->{'packetSize'} = $b;
496 0           $self->{'requestIdent'} = $c;
497 0           $self->{'_bitfields1'} = $d; # Includes bitfields unused41, coordinateSystem, and requestType.
498 0           $self->{'updatePeriod'} = $e;
499 0           $self->{'entityIdent'} = $f;
500 0           $self->{'latitude_xOffset'} = $g;
501 0           $self->{'longitude_yOffset'} = $h;
502 0           $self->{'altitude_zOffset'} = $i;
503              
504 0           $self->{'coordinateSystem'} = $self->coordinate_system();
505 0           $self->{'requestType'} = $self->request_type();
506              
507 0           return $self->{'_Buffer'};
508             }
509              
510             #==========================================================================
511              
512             =item sub byte_swap()
513              
514             $obj_name->byte_swap();
515              
516             Byte swaps the packed data packet.
517              
518             =cut
519              
520             sub byte_swap($) {
521 0     0 1   my $self = shift @_;
522            
523 0 0         if (@_) {
524 0           $self->{'_Buffer'} = shift @_;
525             } else {
526 0           $self->pack();
527             }
528 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
529              
530 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$h,$g,$j,$i,$l,$k);
531 0           $self->unpack();
532              
533 0           return $self->{'_Buffer'};
534             }
535              
536             1;
537             __END__