File Coverage

blib/lib/Rinchi/CIGIPP/PositionResponse.pm
Criterion Covered Total %
statement 84 122 68.8
branch 21 52 40.3
condition 11 36 30.5
subroutine 21 23 91.3
pod 19 19 100.0
total 156 252 61.9


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78b2e04-200e-11de-bdce-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::PositionResponse;
8              
9 1     1   90 use 5.006;
  1         4  
  1         43  
10 1     1   7 use strict;
  1         2  
  1         68  
11 1     1   6 use warnings;
  1         1  
  1         30  
12 1     1   5 use Carp;
  1         3  
  1         2452  
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::PositionResponse - Perl extension for the Common Image
42             Generator Interface - Position Response data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::PositionResponse;
47             my $pos_resp = Rinchi::CIGIPP::PositionResponse->new();
48              
49             $packet_type = $pos_resp->packet_type();
50             $packet_size = $pos_resp->packet_size();
51             $object_ident = $pos_resp->object_ident(8699);
52             $articulated_part_ident = $pos_resp->articulated_part_ident(116);
53             $coordinate_system = $pos_resp->coordinate_system(Rinchi::CIGIPP->ParentEntityCS);
54             $object_class = $pos_resp->object_class(Rinchi::CIGIPP->ArticulatedPartOC);
55             $latitude = $pos_resp->latitude(27.645);
56             $x_offset = $pos_resp->x_offset(26.409);
57             $longitude = $pos_resp->longitude(55.496);
58             $y_offset = $pos_resp->y_offset(48.675);
59             $altitude = $pos_resp->altitude(24.851);
60             $z_offset = $pos_resp->z_offset(47.335);
61             $roll = $pos_resp->roll(8.422);
62             $pitch = $pos_resp->pitch(84.2);
63             $yaw = $pos_resp->yaw(42.084);
64              
65             =head1 DESCRIPTION
66              
67             The Position Response packet is sent by the IG in response to a Position
68             Request packet. This packet describes the position and orientation of an
69             entity, articulated part, view, view group, or motion tracker.
70              
71             =head2 EXPORT
72              
73             None by default.
74              
75             #==============================================================================
76              
77             =item new $pos_resp = Rinchi::CIGIPP::PositionResponse->new()
78              
79             Constructor for Rinchi::PositionResponse.
80              
81             =cut
82              
83             sub new {
84 1     1 1 99 my $class = shift;
85 1   33     8 $class = ref($class) || $class;
86              
87 1         15 my $self = {
88             '_Buffer' => '',
89             '_ClassIdent' => 'f78b2e04-200e-11de-bdce-001c25551abc',
90             '_Pack' => 'CCSCCSdddfffI',
91             '_Swap1' => 'CCvCCvVVVVVVVVVV',
92             '_Swap2' => 'CCnCCnNNNNNNNNNN',
93             'packetType' => 108,
94             'packetSize' => 48,
95             '_objectIdent' => 0,
96             '_articulatedPartIdent' => 0,
97             '_bitfields1' => 0, # Includes bitfields coordinateSystem, and objectClass.
98             '_unused78' => 0,
99             'latitude_xOffset' => 0,
100             'longitude_yOffset' => 0,
101             'altitude_zOffset' => 0,
102             'roll' => 0,
103             'pitch' => 0,
104             'yaw' => 0,
105             '_unused79' => 0,
106             };
107              
108 1 50       4 if (@_) {
109 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
110 0         0 $self->{'_Buffer'} = $_[0][0];
111             } elsif (ref($_[0]) eq 'HASH') {
112 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
113 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
114             }
115             }
116             }
117              
118 1         3 bless($self,$class);
119 1         2 return $self;
120             }
121              
122             #==============================================================================
123              
124             =item sub packet_type()
125              
126             $value = $pos_resp->packet_type();
127              
128             Data Packet Identifier.
129              
130             This attribute identifies this data packet as the Position Response packet. The
131             value of this attribute must be 108.
132              
133             =cut
134              
135             sub packet_type() {
136 1     1 1 6 my ($self) = @_;
137 1         7 return $self->{'packetType'};
138             }
139              
140             #==============================================================================
141              
142             =item sub packet_size()
143              
144             $value = $pos_resp->packet_size();
145              
146             Data Packet Size.
147              
148             This attribute indicates the number of bytes in this data packet. The value of
149             this attribute must be 48.
150              
151             =cut
152              
153             sub packet_size() {
154 1     1 1 5 my ($self) = @_;
155 1         3 return $self->{'packetSize'};
156             }
157              
158             #==============================================================================
159              
160             =item sub object_ident([$newValue])
161              
162             $value = $pos_resp->object_ident($newValue);
163              
164             Object ID.
165              
166             This attribute identifies the entity, view, view group, or motion tracking
167             device whose position is being reported. If Object Class is set to Articulated
168             Part (1), this attribute indicates the entity whose part is identified by the
169             Articulated Part ID attribute.
170              
171             =cut
172              
173             sub object_ident() {
174 1     1 1 5 my ($self,$nv) = @_;
175 1 50       3 if (defined($nv)) {
176 1         2 $self->{'_objectIdent'} = $nv;
177             }
178 1         3 return $self->{'_objectIdent'};
179             }
180              
181             #==============================================================================
182              
183             =item sub articulated_part_ident([$newValue])
184              
185             $value = $pos_resp->articulated_part_ident($newValue);
186              
187             Articulated Part ID.
188              
189             This attribute identifies the articulated part whose position is being
190             reported. The entity to which the part belongs is specified by the Object ID
191             attribute.
192             This attribute is valid only when Object Class is set to Articulated Part (1).
193              
194             =cut
195              
196             sub articulated_part_ident() {
197 1     1 1 4 my ($self,$nv) = @_;
198 1 50       4 if (defined($nv)) {
199 1         3 $self->{'_articulatedPartIdent'} = $nv;
200             }
201 1         3 return $self->{'_articulatedPartIdent'};
202             }
203              
204             #==============================================================================
205              
206             =item sub coordinate_system([$newValue])
207              
208             $value = $pos_resp->coordinate_system($newValue);
209              
210             Coordinate System.
211              
212             This attribute indicates the coordinate system in which the position and
213             orientation are specified.
214              
215             Geodetic – Position is specified as a geodetic latitude, longitude, and
216             altitude. Orientation is given with respect to the reference plane.
217              
218             Parent Entity – Position and orientation are with respect to the entity to
219             which the specified child entity, articulated part, view, or view group is
220             attached. This value is invalid for top-level entities.
221              
222             Submodel – Position and orientation are with respect to the articulated part's
223             reference coordinate system. This value is valid only when Object Class is set
224             to Articulated Part (1).
225              
226             Note: If Object Class is set to Motion Tracker (4), this attribute is ignored
227             and the positional and rotational data are relative to the tracking device
228             boresight state.
229              
230             GeodeticCS 0
231             ParentEntityCS 1
232             SubmodelCS 2
233              
234             =cut
235              
236             sub coordinate_system() {
237 1     1 1 2 my ($self,$nv) = @_;
238 1 50       4 if (defined($nv)) {
239 1 50 33     21 if (($nv==0) or ($nv==1) or ($nv==2)) {
      33        
240 1         3 $self->{'_bitfields1'} |= ($nv << 3) &0x18;
241             } else {
242 0         0 carp "coordinate_system must be 0 (GeodeticCS), 1 (ParentEntityCS), or 2 (SubmodelCS).";
243             }
244             }
245 1         4 return (($self->{'_bitfields1'} & 0x18) >> 3);
246             }
247              
248             #==============================================================================
249              
250             =item sub object_class([$newValue])
251              
252             $value = $pos_resp->object_class($newValue);
253              
254             Object Class.
255              
256             This attribute indicates the type of object whose position is being reported.
257              
258             EntityOC 0
259             ArticulatedPartOC 1
260             ViewOC 2
261             ViewGroupOC 3
262             MotionTrackerOC 4
263              
264             =cut
265              
266             sub object_class() {
267 1     1 1 3 my ($self,$nv) = @_;
268 1 50       3 if (defined($nv)) {
269 1 50 33     11 if (($nv==0) or ($nv==1) or ($nv==2) or ($nv==3) or ($nv==4)) {
      33        
      33        
      0        
270 1         4 $self->{'_bitfields1'} |= $nv &0x07;
271             } else {
272 0         0 carp "object_class must be 0 (EntityOC), 1 (ArticulatedPartOC), 2 (ViewOC), 3 (ViewGroupOC), or 4 (MotionTrackerOC).";
273             }
274             }
275 1         3 return ($self->{'_bitfields1'} & 0x07);
276             }
277              
278             #==============================================================================
279              
280             =item sub latitude([$newValue])
281              
282             $value = $pos_resp->latitude($newValue);
283              
284             Latitude.
285              
286             If Coordinate System is set to Geodetic (0), this attribute indicates the
287             geodetic latitude of the entity, articulated part, view, or view group.
288              
289             =cut
290              
291             sub latitude() {
292 1     1 1 5 my ($self,$nv) = @_;
293 1 50       3 if (defined($nv)) {
294 1 50 33     8 if (($nv>=-90) and ($nv<=90.0)) {
295 1         2 $self->{'latitude_xOffset'} = $nv;
296             } else {
297 0         0 carp "latitude must be from -90.0 to +90.0.";
298             }
299             }
300 1         3 return $self->{'latitude_xOffset'};
301             }
302              
303             #==============================================================================
304              
305             =item sub x_offset([$newValue])
306              
307             $value = $pos_resp->x_offset($newValue);
308              
309             X Offset.
310              
311             If Coordinate System is set to Parent Entity (1), this attribute indicates the
312             X offset from the parent entity's origin to the child entity, articulated part,
313             view, or view group.
314              
315             If Coordinate System is set to Submodel (2), this attribute indicates the X
316             offset from the articulated part submodel's reference point.
317              
318             If Object Class is set to Motion Tracker (4), this attribute indicates the X
319             position reported by the tracking device.
320              
321             =cut
322              
323             sub x_offset() {
324 1     1 1 5 my ($self,$nv) = @_;
325 1 50       4 if (defined($nv)) {
326 1         2 $self->{'latitude_xOffset'} = $nv;
327             }
328 1         4 return $self->{'latitude_xOffset'};
329             }
330              
331             #==============================================================================
332              
333             =item sub longitude([$newValue])
334              
335             $value = $pos_resp->longitude($newValue);
336              
337             Longitude.
338              
339             If Coordinate System is set to Geodetic (0), this attribute indicates the
340             geodetic longitude of the entity, articulated part, view, or view group.
341              
342             =cut
343              
344             sub longitude() {
345 1     1 1 5 my ($self,$nv) = @_;
346 1 50       4 if (defined($nv)) {
347 1 50 33     7 if (($nv>=-180.0) and ($nv<=180.0)) {
348 1         2 $self->{'longitude_yOffset'} = $nv;
349             } else {
350 0         0 carp "longitude must be from -180.0 to +180.0.";
351             }
352             }
353 1         3 return $self->{'longitude_yOffset'};
354             }
355              
356             #==============================================================================
357              
358             =item sub y_offset([$newValue])
359              
360             $value = $pos_resp->y_offset($newValue);
361              
362             Y Offset.
363              
364             If Coordinate System is set to Parent Entity (1), this attribute indicates the
365             Y offset from the parent entity's origin to the child entity, articulated part,
366             view, or view group.
367              
368             If Coordinate System is set to Submodel (2), this attribute indicates the Y
369             offset from the articulated part submodel's reference point.
370              
371             If Object Class is set to Motion Tracker (4), this attribute indicates the Y
372             position reported by the tracking device.
373              
374             =cut
375              
376             sub y_offset() {
377 1     1 1 4 my ($self,$nv) = @_;
378 1 50       3 if (defined($nv)) {
379 1         2 $self->{'longitude_yOffset'} = $nv;
380             }
381 1         2 return $self->{'longitude_yOffset'};
382             }
383              
384             #==============================================================================
385              
386             =item sub altitude([$newValue])
387              
388             $value = $pos_resp->altitude($newValue);
389              
390             Altitude.
391              
392             If Coordinate System is set to Geodetic (0), this attribute indicates the
393             geodetic altitude of the entity, articulated part, view, or view group.
394              
395             =cut
396              
397             sub altitude() {
398 1     1 1 4 my ($self,$nv) = @_;
399 1 50       2 if (defined($nv)) {
400 1         2 $self->{'altitude_zOffset'} = $nv;
401             }
402 1         3 return $self->{'altitude_zOffset'};
403             }
404              
405             #==============================================================================
406              
407             =item sub z_offset([$newValue])
408              
409             $value = $pos_resp->z_offset($newValue);
410              
411             Z Offset.
412              
413             If Coordinate System is set to Parent Entity (1), this attribute indicates the
414             Z offset from the parent entity's origin to the child entity, articulated part,
415             view, or view group.
416              
417             If Coordinate System is set to Submodel (2), this attribute indicates the Z
418             offset from the articulated part submodel's reference point.
419              
420             If Object Class is set to Motion Tracker (4), this attribute indicates the Z
421             position reported by the tracking device.
422              
423             =cut
424              
425             sub z_offset() {
426 1     1 1 4 my ($self,$nv) = @_;
427 1 50       3 if (defined($nv)) {
428 1         2 $self->{'altitude_zOffset'} = $nv;
429             }
430 1         2 return $self->{'altitude_zOffset'};
431             }
432              
433             #==============================================================================
434              
435             =item sub roll([$newValue])
436              
437             $value = $pos_resp->roll($newValue);
438              
439             Roll.
440              
441             This attribute indicates the roll angle of the specified entity, articulated
442             part, view, or view group.
443              
444             If Object Class is set to Motion Tracker (4), this attribute indicates the roll
445             angle reported by the tracking device.
446              
447             =cut
448              
449             sub roll() {
450 1     1 1 4 my ($self,$nv) = @_;
451 1 50       3 if (defined($nv)) {
452 1 50 33     7 if (($nv>=-180.0) and ($nv<=180.0)) {
453 1         2 $self->{'roll'} = $nv;
454             } else {
455 0         0 carp "roll must be from -180.0 to +180.0.";
456             }
457             }
458 1         3 return $self->{'roll'};
459             }
460              
461             #==============================================================================
462              
463             =item sub pitch([$newValue])
464              
465             $value = $pos_resp->pitch($newValue);
466              
467             Pitch.
468              
469             This attribute indicates the pitch angle of the specified entity, articulated
470             part, view, or view group.
471              
472             If Object Class is set to Motion Tracker (4), this attribute indicates the
473             pitch angle reported by the tracking device.
474              
475             =cut
476              
477             sub pitch() {
478 1     1 1 5 my ($self,$nv) = @_;
479 1 50       3 if (defined($nv)) {
480 1 50 33     6 if (($nv>=-90) and ($nv<=90.0)) {
481 1         3 $self->{'pitch'} = $nv;
482             } else {
483 0         0 carp "pitch must be from -90.0 to +90.0.";
484             }
485             }
486 1         3 return $self->{'pitch'};
487             }
488              
489             #==============================================================================
490              
491             =item sub yaw([$newValue])
492              
493             $value = $pos_resp->yaw($newValue);
494              
495             Yaw.
496              
497             This attribute indicates the yaw angle of the specified entity, articulated
498             part, view, or view group.
499              
500             If Object Class is set to Motion Tracker (4), this attribute indicates the yaw
501             angle reported by the tracking device.
502              
503             =cut
504              
505             sub yaw() {
506 1     1 1 6 my ($self,$nv) = @_;
507 1 50       2 if (defined($nv)) {
508 1 50 33     74 if (($nv>=0) and ($nv<=360.0)) {
509 1         3 $self->{'yaw'} = $nv;
510             } else {
511 0         0 carp "yaw must be from 0.0 to +360.0.";
512             }
513             }
514 1         3 return $self->{'yaw'};
515             }
516              
517             #==========================================================================
518              
519             =item sub pack()
520              
521             $value = $pos_resp->pack();
522              
523             Returns the packed data packet.
524              
525             =cut
526              
527             sub pack($) {
528 1     1 1 5 my $self = shift ;
529            
530 1         9 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
531             $self->{'packetType'},
532             $self->{'packetSize'},
533             $self->{'_objectIdent'},
534             $self->{'_articulatedPartIdent'},
535             $self->{'_bitfields1'}, # Includes bitfields unused77, coordinateSystem, and objectClass.
536             $self->{'_unused78'},
537             $self->{'latitude_xOffset'},
538             $self->{'longitude_yOffset'},
539             $self->{'altitude_zOffset'},
540             $self->{'roll'},
541             $self->{'pitch'},
542             $self->{'yaw'},
543             $self->{'_unused79'},
544             );
545              
546 1         3 return $self->{'_Buffer'};
547             }
548              
549             #==========================================================================
550              
551             =item sub unpack()
552              
553             $value = $pos_resp->unpack();
554              
555             Unpacks the packed data packet.
556              
557             =cut
558              
559             sub unpack($) {
560 0     0 1   my $self = shift @_;
561            
562 0 0         if (@_) {
563 0           $self->{'_Buffer'} = shift @_;
564             }
565 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
566 0           $self->{'packetType'} = $a;
567 0           $self->{'packetSize'} = $b;
568 0           $self->{'_objectIdent'} = $c;
569 0           $self->{'_articulatedPartIdent'} = $d;
570 0           $self->{'_bitfields1'} = $e; # Includes bitfields unused77, coordinateSystem, and objectClass.
571 0           $self->{'_unused78'} = $f;
572 0           $self->{'latitude_xOffset'} = $g;
573 0           $self->{'longitude_yOffset'} = $h;
574 0           $self->{'altitude_zOffset'} = $i;
575 0           $self->{'roll'} = $j;
576 0           $self->{'pitch'} = $k;
577 0           $self->{'yaw'} = $l;
578 0           $self->{'_unused79'} = $m;
579              
580 0           return $self->{'_Buffer'};
581             }
582              
583             #==========================================================================
584              
585             =item sub byte_swap()
586              
587             $obj_name->byte_swap();
588              
589             Byte swaps the packed data packet.
590              
591             =cut
592              
593             sub byte_swap($) {
594 0     0 1   my $self = shift @_;
595            
596 0 0         if (@_) {
597 0           $self->{'_Buffer'} = shift @_;
598             } else {
599 0           $self->pack();
600             }
601 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
602              
603 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$h,$g,$j,$i,$l,$k,$m,$n,$o,$p);
604 0           $self->unpack();
605              
606 0           return $self->{'_Buffer'};
607             }
608              
609             1;
610             __END__