File Coverage

blib/lib/Rinchi/CIGIPP/SensorExtendedResponse.pm
Criterion Covered Total %
statement 83 121 68.6
branch 18 46 39.1
condition 6 21 28.5
subroutine 21 23 91.3
pod 19 19 100.0
total 147 230 63.9


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78b2b5c-200e-11de-bdcd-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::SensorExtendedResponse;
8              
9 1     1   171 use 5.006;
  1         4  
  1         46  
10 1     1   6 use strict;
  1         2  
  1         109  
11 1     1   6 use warnings;
  1         2  
  1         29  
12 1     1   5 use Carp;
  1         1  
  1         2597  
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::SensorExtendedResponse - Perl extension for the Common Image
42             Generator Interface - Sensor Extended Response data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::SensorExtendedResponse;
47             my $sensor_xresp = Rinchi::CIGIPP::SensorExtendedResponse->new();
48              
49             $packet_type = $sensor_xresp->packet_type();
50             $packet_size = $sensor_xresp->packet_size();
51             $view_ident = $sensor_xresp->view_ident(15496);
52             $sensor_ident = $sensor_xresp->sensor_ident(37242);
53             $entity_ident_valid = $sensor_xresp->entity_ident_valid(Rinchi::CIGIPP->Valid);
54             $sensor_status = $sensor_xresp->sensor_status(Rinchi::CIGIPP->Searching);
55             $entity_ident = $sensor_xresp->entity_ident(64212);
56             $gate_xsize = $sensor_xresp->gate_xsize(22491);
57             $gate_ysize = $sensor_xresp->gate_ysize(15321);
58             $gate_xposition = $sensor_xresp->gate_xposition(9.495);
59             $gate_yposition = $sensor_xresp->gate_yposition(56.78);
60             $host_frame_number = $sensor_xresp->host_frame_number(22764);
61             $track_point_latitude = $sensor_xresp->track_point_latitude(75.221);
62             $track_point_longitude = $sensor_xresp->track_point_longitude(4.123);
63             $track_point_altitude = $sensor_xresp->track_point_altitude(68.142);
64              
65             =head1 DESCRIPTION
66              
67             The Sensor Extended Response packet, like the Sensor Response packet, is used
68             to report the gate size and position on a sensor display to the Host. This
69             packet also contains the geodetic position of the sensor track point and the
70             entity ID of the target.
71              
72             Either this packet or the Sensor Response packet must be sent to the Host
73             during each frame that the specified sensor is active.
74              
75             =head2 EXPORT
76              
77             None by default.
78              
79             #==============================================================================
80              
81             =item new $sensor_xresp = Rinchi::CIGIPP::SensorExtendedResponse->new()
82              
83             Constructor for Rinchi::SensorExtendedResponse.
84              
85             =cut
86              
87             sub new {
88 1     1 1 48 my $class = shift;
89 1   33     6 $class = ref($class) || $class;
90              
91 1         14 my $self = {
92             '_Buffer' => '',
93             '_ClassIdent' => 'f78b2b5c-200e-11de-bdcd-001c25551abc',
94             '_Pack' => 'CCSCCSSSffIddd',
95             '_Swap1' => 'CCvCCvvvVVVVVVVVV',
96             '_Swap2' => 'CCnCCnnnNNNNNNNNN',
97             'packetType' => 107,
98             'packetSize' => 48,
99             'viewIdent' => 0,
100             'sensorIdent' => 0,
101             '_bitfields1' => 0, # Includes bitfields unused76, entityIdentValid, and sensorStatus.
102             'entityIdentValid' => 0,
103             'sensorStatus' => 0,
104             'entityIdent' => 0,
105             'gateXSize' => 0,
106             'gateYSize' => 0,
107             'gateXPosition' => 0,
108             'gateYPosition' => 0,
109             'hostFrameNumber' => 0,
110             'trackPointLatitude' => 0,
111             'trackPointLongitude' => 0,
112             'trackPointAltitude' => 0,
113             };
114              
115 1 50       5 if (@_) {
116 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
117 0         0 $self->{'_Buffer'} = $_[0][0];
118             } elsif (ref($_[0]) eq 'HASH') {
119 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
120 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
121             }
122             }
123             }
124              
125 1         3 bless($self,$class);
126 1         3 return $self;
127             }
128              
129             #==============================================================================
130              
131             =item sub packet_type()
132              
133             $value = $sensor_xresp->packet_type();
134              
135             Data Packet Identifier.
136              
137             This attribute identifies this data packet as the Sensor Extended Response
138             packet. The value of this attribute must be 107.
139              
140             =cut
141              
142             sub packet_type() {
143 1     1 1 8 my ($self) = @_;
144 1         7 return $self->{'packetType'};
145             }
146              
147             #==============================================================================
148              
149             =item sub packet_size()
150              
151             $value = $sensor_xresp->packet_size();
152              
153             Data Packet Size.
154              
155             This attribute indicates the number of bytes in this data packet. The value of
156             this attribute must be 48.
157              
158             =cut
159              
160             sub packet_size() {
161 1     1 1 5 my ($self) = @_;
162 1         3 return $self->{'packetSize'};
163             }
164              
165             #==============================================================================
166              
167             =item sub view_ident([$newValue])
168              
169             $value = $sensor_xresp->view_ident($newValue);
170              
171             View ID.
172              
173             This attribute specifies the view that represents the sensor display.
174              
175             =cut
176              
177             sub view_ident() {
178 1     1 1 818 my ($self,$nv) = @_;
179 1 50       6 if (defined($nv)) {
180 1         2 $self->{'viewIdent'} = $nv;
181             }
182 1         4 return $self->{'viewIdent'};
183             }
184              
185             #==============================================================================
186              
187             =item sub sensor_ident([$newValue])
188              
189             $value = $sensor_xresp->sensor_ident($newValue);
190              
191             Sensor ID.
192              
193             This attribute specifies the sensor to which the data in this packet apply.
194              
195             =cut
196              
197             sub sensor_ident() {
198 1     1 1 5 my ($self,$nv) = @_;
199 1 50       3 if (defined($nv)) {
200 1         2 $self->{'sensorIdent'} = $nv;
201             }
202 1         3 return $self->{'sensorIdent'};
203             }
204              
205             #==============================================================================
206              
207             =item sub entity_ident_valid([$newValue])
208              
209             $value = $sensor_xresp->entity_ident_valid($newValue);
210              
211             Entity ID Valid.
212              
213             This attribute indicates whether the target is an entity or a non-entity
214             object. If this attribute is set to Valid (1), then Entity ID identifies the
215             target entity.
216              
217             Invalid 0
218             Valid 1
219              
220             =cut
221              
222             sub entity_ident_valid() {
223 1     1 1 3 my ($self,$nv) = @_;
224 1 50       3 if (defined($nv)) {
225 1 50 33     8 if (($nv==0) or ($nv==1)) {
226 1         2 $self->{'entityIdentValid'} = $nv;
227 1         3 $self->{'_bitfields1'} |= ($nv << 2) &0x04;
228             } else {
229 0         0 carp "entity_ident_valid must be 0 (Invalid), or 1 (Valid).";
230             }
231             }
232 1         3 return (($self->{'_bitfields1'} & 0x04) >> 2);
233             }
234              
235             #==============================================================================
236              
237             =item sub sensor_status([$newValue])
238              
239             $value = $sensor_xresp->sensor_status($newValue);
240              
241             Sensor Status.
242              
243             This attribute indicates the current tracking state of the sensor.
244              
245             Searching 0
246             Tracking 1
247             ImpendingBreaklock 2
248             Breaklock 3
249              
250             =cut
251              
252             sub sensor_status() {
253 1     1 1 2 my ($self,$nv) = @_;
254 1 50       4 if (defined($nv)) {
255 1 50 33     6 if (($nv==0) or ($nv==1) or ($nv==2) or ($nv==3)) {
      33        
      0        
256 1         2 $self->{'sensorStatus'} = $nv;
257 1         2 $self->{'_bitfields1'} |= $nv &0x03;
258             } else {
259 0         0 carp "sensor_status must be 0 (Searching), 1 (Tracking), 2 (ImpendingBreaklock), or 3 (Breaklock).";
260             }
261             }
262 1         3 return ($self->{'_bitfields1'} & 0x03);
263             }
264              
265             #==============================================================================
266              
267             =item sub entity_ident([$newValue])
268              
269             $value = $sensor_xresp->entity_ident($newValue);
270              
271             Entity ID.
272              
273             This attribute indicates the entity ID of the target. This attribute is ignored
274             if Entity ID Valid is set to Invalid (0).
275              
276             =cut
277              
278             sub entity_ident() {
279 1     1 1 5 my ($self,$nv) = @_;
280 1 50       4 if (defined($nv)) {
281 1         2 $self->{'entityIdent'} = $nv;
282             }
283 1         4 return $self->{'entityIdent'};
284             }
285              
286             #==============================================================================
287              
288             =item sub gate_xsize([$newValue])
289              
290             $value = $sensor_xresp->gate_xsize($newValue);
291              
292             Gate X Size.
293              
294             This attribute specifies the gate symbol size along the view's X axis.
295              
296             Note: This size is specified in either pixels or raster lines depending upon
297             the orientation of the display.
298              
299             =cut
300              
301             sub gate_xsize() {
302 1     1 1 4 my ($self,$nv) = @_;
303 1 50       4 if (defined($nv)) {
304 1         2 $self->{'gateXSize'} = $nv;
305             }
306 1         2 return $self->{'gateXSize'};
307             }
308              
309             #==============================================================================
310              
311             =item sub gate_ysize([$newValue])
312              
313             $value = $sensor_xresp->gate_ysize($newValue);
314              
315             Gate Y Size.
316              
317             This attribute specifies the gate symbol size along the view's Y axis.
318              
319             Note: This size is specified in either pixels or raster lines depending upon
320             the orientation of the display.
321              
322             =cut
323              
324             sub gate_ysize() {
325 1     1 1 5 my ($self,$nv) = @_;
326 1 50       4 if (defined($nv)) {
327 1         1 $self->{'gateYSize'} = $nv;
328             }
329 1         3 return $self->{'gateYSize'};
330             }
331              
332             #==============================================================================
333              
334             =item sub gate_xposition([$newValue])
335              
336             $value = $sensor_xresp->gate_xposition($newValue);
337              
338             Gate X Position.
339              
340             This attribute specifies the gate symbol's position along the view's X axis.
341             This position is given as the horizontal angle formed at the sensor eyepoint
342             between the sensor's viewing vector and the center of the track point.
343              
344             =cut
345              
346             sub gate_xposition() {
347 1     1 1 5 my ($self,$nv) = @_;
348 1 50       3 if (defined($nv)) {
349 1         3 $self->{'gateXPosition'} = $nv;
350             }
351 1         2 return $self->{'gateXPosition'};
352             }
353              
354             #==============================================================================
355              
356             =item sub gate_yposition([$newValue])
357              
358             $value = $sensor_xresp->gate_yposition($newValue);
359              
360             Gate Y Position.
361              
362             This attribute specifies the gate symbol's position along the view's Y axis.
363             This position is given as the vertical angle formed at the sensor eyepoint
364             between the sensor's viewing vector and the center of the track point.
365              
366             =cut
367              
368             sub gate_yposition() {
369 1     1 1 5 my ($self,$nv) = @_;
370 1 50       3 if (defined($nv)) {
371 1         2 $self->{'gateYPosition'} = $nv;
372             }
373 1         3 return $self->{'gateYPosition'};
374             }
375              
376             #==============================================================================
377              
378             =item sub host_frame_number([$newValue])
379              
380             $value = $sensor_xresp->host_frame_number($newValue);
381              
382             Host Frame Number.
383              
384             This attribute indicates the Host frame number at the time that the IG
385             calculates the gate and line-of-sight intersection data.
386              
387             =cut
388              
389             sub host_frame_number() {
390 1     1 1 5 my ($self,$nv) = @_;
391 1 50       3 if (defined($nv)) {
392 1         1 $self->{'hostFrameNumber'} = $nv;
393             }
394 1         3 return $self->{'hostFrameNumber'};
395             }
396              
397             #==============================================================================
398              
399             =item sub track_point_latitude([$newValue])
400              
401             $value = $sensor_xresp->track_point_latitude($newValue);
402              
403             Track Point Latitude.
404              
405             This attribute indicates the geodetic latitude of the point being tracked by
406             the sensor. This attribute is valid only when the Sensor Status attribute is
407             set to one (1) or two (2).
408              
409             =cut
410              
411             sub track_point_latitude() {
412 1     1 1 5 my ($self,$nv) = @_;
413 1 50       4 if (defined($nv)) {
414 1 50 33     11 if (($nv>=-90) and ($nv<=90.0)) {
415 1         2 $self->{'trackPointLatitude'} = $nv;
416             } else {
417 0         0 carp "track_point_latitude must be from -90.0 to +90.0.";
418             }
419             }
420 1         4 return $self->{'trackPointLatitude'};
421             }
422              
423             #==============================================================================
424              
425             =item sub track_point_longitude([$newValue])
426              
427             $value = $sensor_xresp->track_point_longitude($newValue);
428              
429             Track Point Longitude.
430              
431             This attribute indicates the geodetic longitude of the point being tracked by
432             the sensor. This attribute is valid only when the Sensor Status attribute is
433             set to one (1) or two (2).
434              
435             =cut
436              
437             sub track_point_longitude() {
438 1     1 1 5 my ($self,$nv) = @_;
439 1 50       3 if (defined($nv)) {
440 1 50 33     8 if (($nv>=-180.0) and ($nv<=180.0)) {
441 1         2 $self->{'trackPointLongitude'} = $nv;
442             } else {
443 0         0 carp "track_point_longitude must be from -180.0 to +180.0.";
444             }
445             }
446 1         3 return $self->{'trackPointLongitude'};
447             }
448              
449             #==============================================================================
450              
451             =item sub track_point_altitude([$newValue])
452              
453             $value = $sensor_xresp->track_point_altitude($newValue);
454              
455             Track Point Altitude.
456              
457             This attribute indicates the geodetic altitude of the point being tracked by
458             the sensor measured in meters above mean sea level. This attribute is valid
459             only when the Sensor Status attribute is set to one (1) or two (2).
460              
461             =cut
462              
463             sub track_point_altitude() {
464 1     1 1 5 my ($self,$nv) = @_;
465 1 50       4 if (defined($nv)) {
466 1         2 $self->{'trackPointAltitude'} = $nv;
467             }
468 1         2 return $self->{'trackPointAltitude'};
469             }
470              
471             #==========================================================================
472              
473             =item sub pack()
474              
475             $value = $sensor_xresp->pack();
476              
477             Returns the packed data packet.
478              
479             =cut
480              
481             sub pack($) {
482 1     1 1 5 my $self = shift ;
483            
484 1         9 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
485             $self->{'packetType'},
486             $self->{'packetSize'},
487             $self->{'viewIdent'},
488             $self->{'sensorIdent'},
489             $self->{'_bitfields1'}, # Includes bitfields unused76, entityIdentValid, and sensorStatus.
490             $self->{'entityIdent'},
491             $self->{'gateXSize'},
492             $self->{'gateYSize'},
493             $self->{'gateXPosition'},
494             $self->{'gateYPosition'},
495             $self->{'hostFrameNumber'},
496             $self->{'trackPointLatitude'},
497             $self->{'trackPointLongitude'},
498             $self->{'trackPointAltitude'},
499             );
500              
501 1         3 return $self->{'_Buffer'};
502             }
503              
504             #==========================================================================
505              
506             =item sub unpack()
507              
508             $value = $sensor_xresp->unpack();
509              
510             Unpacks the packed data packet.
511              
512             =cut
513              
514             sub unpack($) {
515 0     0 1   my $self = shift @_;
516            
517 0 0         if (@_) {
518 0           $self->{'_Buffer'} = shift @_;
519             }
520 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
521 0           $self->{'packetType'} = $a;
522 0           $self->{'packetSize'} = $b;
523 0           $self->{'viewIdent'} = $c;
524 0           $self->{'sensorIdent'} = $d;
525 0           $self->{'_bitfields1'} = $e; # Includes bitfields unused76, entityIdentValid, and sensorStatus.
526 0           $self->{'entityIdent'} = $f;
527 0           $self->{'gateXSize'} = $g;
528 0           $self->{'gateYSize'} = $h;
529 0           $self->{'gateXPosition'} = $i;
530 0           $self->{'gateYPosition'} = $j;
531 0           $self->{'hostFrameNumber'} = $k;
532 0           $self->{'trackPointLatitude'} = $l;
533 0           $self->{'trackPointLongitude'} = $m;
534 0           $self->{'trackPointAltitude'} = $n;
535              
536 0           $self->{'entityIdentValid'} = $self->entity_ident_valid();
537 0           $self->{'sensorStatus'} = $self->sensor_status();
538              
539 0           return $self->{'_Buffer'};
540             }
541              
542             #==========================================================================
543              
544             =item sub byte_swap()
545              
546             $obj_name->byte_swap();
547              
548             Byte swaps the packed data packet.
549              
550             =cut
551              
552             sub byte_swap($) {
553 0     0 1   my $self = shift @_;
554            
555 0 0         if (@_) {
556 0           $self->{'_Buffer'} = shift @_;
557             } else {
558 0           $self->unpack();
559             }
560             # '_Pack' => 'CCSCCSSSffIddd',
561             # '_Swap1' => 'CCvvCvvvVVVVVVVVV',
562             # '_Swap2' => 'CCnnCnnnNNNNNNNNN',
563 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
564              
565 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$m,$l,$o,$n,$q,$p);
566 0           $self->unpack();
567              
568 0           return $self->{'_Buffer'};
569             }
570              
571             1;
572             __END__