File Coverage

blib/lib/Rinchi/CIGIPP/ShortSymbolControl.pm
Criterion Covered Total %
statement 75 124 60.4
branch 18 50 36.0
condition 14 108 12.9
subroutine 17 19 89.4
pod 15 15 100.0
total 139 316 43.9


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78b15b8-200e-11de-bdc5-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::ShortSymbolControl;
8              
9 1     1   23 use 5.006;
  1         4  
  1         60  
10 1     1   8 use strict;
  1         2  
  1         35  
11 1     1   6 use warnings;
  1         2  
  1         28  
12 1     1   6 use Carp;
  1         3  
  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.01';
36              
37             # Preloaded methods go here.
38              
39             =head1 NAME
40              
41             Rinchi::CIGIPP::ShortSymbolControl - Perl extension for the Common Image
42             Generator Interface - Short Symbol Control data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::ShortSymbolControl;
47             my $ssym_ctl = Rinchi::CIGIPP::ShortSymbolControl->new();
48              
49             $packet_type = $ssym_ctl->packet_type();
50             $packet_size = $ssym_ctl->packet_size();
51             $symbol_ident = $ssym_ctl->symbol_ident(48088);
52             $inherit_color = $ssym_ctl->inherit_color(Rinchi::CIGIPP->NotInherited);
53             $flash_control = $ssym_ctl->flash_control(Rinchi::CIGIPP->RestartFlash);
54             $attach_state = $ssym_ctl->attach_state(Rinchi::CIGIPP->Detach);
55             $symbol_state = $ssym_ctl->symbol_state(Rinchi::CIGIPP->Hidden);
56             $attribute_select1 = $ssym_ctl->attribute_select1(Rinchi::CIGIPP->None);
57             $attribute_select2 = $ssym_ctl->attribute_select2(Rinchi::CIGIPP->None);
58             $attribute_value1 = $ssym_ctl->attribute_value1(8789);
59             $attribute_value2 = $ssym_ctl->attribute_value2(27011);
60              
61             =head1 DESCRIPTION
62              
63             The Short Symbol Control packet is provided as a lower-bandwidth alternative to
64             the Symbol Control packet (CIGI ICD Section 4.1.33). It can be used when
65             manipulation of only one or two symbol attributes of a symbol are necessary.
66              
67             This packet allows for up to two symbol attributes to be modified. The
68             attributes are specified by the Attribute Select 1 and Attribute Select 2
69             attributes. The values of these attributes determine what data types are used
70             to interpret the Attribute Value 1 and Attribute Value 2 attributes,
71             respectively.
72             A symbol must be defined before the Host sends a Short Symbol Control packet
73             referencing that symbol. Symbols may be predefined by the IG or may be created
74             by the Host sending any one of the symbol definition packets.
75              
76             Before the Host can send a Short Symbol Control referencing a symbol, the Host
77             must first send a Symbol Control packet referencing that symbol so that all of
78             the symbol's attributes can be set.
79              
80             =head2 EXPORT
81              
82             None by default.
83              
84             #==============================================================================
85              
86             =item new $ssym_ctl = Rinchi::CIGIPP::ShortSymbolControl->new()
87              
88             Constructor for Rinchi::ShortSymbolControl.
89              
90             =cut
91              
92             sub new {
93 1     1 1 58 my $class = shift;
94 1   33     7 $class = ref($class) || $class;
95              
96 1         24 my $self = {
97             '_Buffer' => '',
98             '_ClassIdent' => 'f78b15b8-200e-11de-bdc5-001c25551abc',
99             '_Pack' => 'CCSCCCCff',
100             '_Swap1' => 'CCvCCCCVV',
101             '_Swap2' => 'CCnCCCCNN',
102             'packetType' => 35,
103             'packetSize' => 16,
104             'symbolIdent' => 0,
105             '_bitfields1' => 0, # Includes bitfields unused63, inheritColor, flashControl, attachState, and symbolState.
106             'inheritColor' => 0,
107             'flashControl' => 0,
108             'attachState' => 0,
109             'symbolState' => 0,
110             '_unused64' => 0,
111             'attributeSelect1' => 0,
112             'attributeSelect2' => 0,
113             'attributeValue1' => 0,
114             'attributeValue2' => 0,
115             };
116              
117 1 50       7 if (@_) {
118 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
119 0         0 $self->{'_Buffer'} = $_[0][0];
120             } elsif (ref($_[0]) eq 'HASH') {
121 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
122 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
123             }
124             }
125             }
126              
127 1         3 bless($self,$class);
128 1         11 return $self;
129             }
130              
131             #==============================================================================
132              
133             =item sub packet_type()
134              
135             $value = $ssym_ctl->packet_type();
136              
137             Data Packet Identifier.
138              
139             This attribute identifies this data packet as the Short Symbol Control packet.
140             The value of this attribute must be 35.
141              
142             =cut
143              
144             sub packet_type() {
145 1     1 1 10 my ($self) = @_;
146 1         10 return $self->{'packetType'};
147             }
148              
149             #==============================================================================
150              
151             =item sub packet_size()
152              
153             $value = $ssym_ctl->packet_size();
154              
155             Data Packet Size.
156              
157             This attribute indicates the number of bytes in this data packet. The value of
158             this attribute must be 32.
159              
160             =cut
161              
162             sub packet_size() {
163 1     1 1 7 my ($self) = @_;
164 1         4 return $self->{'packetSize'};
165             }
166              
167             #==============================================================================
168              
169             =item sub symbol_ident([$newValue])
170              
171             $value = $ssym_ctl->symbol_ident($newValue);
172              
173             Symbol ID.
174              
175             This attribute specifies the symbol to which this packet is applied. This value
176             must be unique for each active symbol.
177              
178             =cut
179              
180             sub symbol_ident() {
181 1     1 1 8 my ($self,$nv) = @_;
182 1 50       6 if (defined($nv)) {
183 1         4 $self->{'symbolIdent'} = $nv;
184             }
185 1         3 return $self->{'symbolIdent'};
186             }
187              
188             #==============================================================================
189              
190             =item sub inherit_color([$newValue])
191              
192             $value = $ssym_ctl->inherit_color($newValue);
193              
194             Inherit Color.
195              
196             This attribute specifies whether this symbol inherits its color from the symbol
197             to which it is attached. If color is inherited, then this symbol's color,
198             including the alpha component, is identical to the current color of the parent
199             symbol. Note that the current color of the parent symbol may be inherited from
200             another symbol.
201              
202             If Attach State is set to Detach (0), this attribute is ignored.
203              
204             NotInherited 0
205             Inherited 1
206              
207             =cut
208              
209             sub inherit_color() {
210 1     1 1 2 my ($self,$nv) = @_;
211 1 50       4 if (defined($nv)) {
212 1 50 33     7 if (($nv==0) or ($nv==1)) {
213 1         3 $self->{'inheritColor'} = $nv;
214 1         8 $self->{'_bitfields1'} |= ($nv << 4) &0x10;
215             } else {
216 0         0 carp "inherit_color must be 0 (NotInherited), or 1 (Inherited).";
217             }
218             }
219 1         4 return (($self->{'_bitfields1'} & 0x10) >> 4);
220             }
221              
222             #==============================================================================
223              
224             =item sub flash_control([$newValue])
225              
226             $value = $ssym_ctl->flash_control($newValue);
227              
228             Flash Control.
229              
230             This attribute specifies whether the flash cycle is continued from its present
231             point or whether it is restarted at the beginning.
232              
233             This attribute is ignored if either Flash Duty Cycle Percentage or Flash Period
234             is changed. This attribute may also be ignored if Flash Duty Cycle Percentage
235             is set to 0 or 100.
236              
237             ContinueFlash 0
238             RestartFlash 1
239              
240             =cut
241              
242             sub flash_control() {
243 1     1 1 3 my ($self,$nv) = @_;
244 1 50       4 if (defined($nv)) {
245 1 50 33     15 if (($nv==0) or ($nv==1)) {
246 1         3 $self->{'flashControl'} = $nv;
247 1         4 $self->{'_bitfields1'} |= ($nv << 3) &0x08;
248             } else {
249 0         0 carp "flash_control must be 0 (ContinueFlash), or 1 (RestartFlash).";
250             }
251             }
252 1         3 return (($self->{'_bitfields1'} & 0x08) >> 3);
253             }
254              
255             #==============================================================================
256              
257             =item sub attach_state([$newValue])
258              
259             $value = $ssym_ctl->attach_state($newValue);
260              
261             Attach State.
262              
263             This attribute specifies whether the symbol should be attached as a child to a
264             parent symbol.
265              
266             If this attribute is set to Detach (0), then the symbol becomes or remains a
267             top-level (non-child) symbol. The Parent Symbol attribute is ignored. The U
268             Position, V Position, and Rotation attributes specify the symbol's position and
269             rotation relative to the symbol surface's local coordinate system (see Section
270             3.4.5.1).
271             If this attribute is set to Attach (1), then the symbol becomes or remains
272             attached to the symbol specified by the Parent Symbol ID attribute. The U
273             Position, V Position, and Rotation attributes specify the symbol's position and
274             rotation relative to the parent symbol's local coordinate system (see Section
275             3.4.5.2).
276             The attach state of a symbol may be changed at any time. The attachment or
277             detachment takes place immediately and remains in effect until changed with
278             another Symbol Control packet or Short Symbol Control packet.
279              
280             Detach 0
281             Attach 1
282              
283             =cut
284              
285             sub attach_state() {
286 1     1 1 3 my ($self,$nv) = @_;
287 1 50       4 if (defined($nv)) {
288 1 50 33     7 if (($nv==0) or ($nv==1)) {
289 1         3 $self->{'attachState'} = $nv;
290 1         2 $self->{'_bitfields1'} |= ($nv << 2) &0x04;
291             } else {
292 0         0 carp "attach_state must be 0 (Detach), or 1 (Attach).";
293             }
294             }
295 1         4 return (($self->{'_bitfields1'} & 0x04) >> 2);
296             }
297              
298             #==============================================================================
299              
300             =item sub symbol_state([$newValue])
301              
302             $value = $ssym_ctl->symbol_state($newValue);
303              
304             Symbol State.
305              
306             This attribute specifies whether the symbol should be hidden, visible, or
307             destroyed. This attribute may be set to one of the following values:
308              
309             Hidden – The symbol is hidden from view; however, it can be positioned,
310             rotated, and scaled. It can also be attached to another symbol as a child. It
311             can also be used as a parent by other symbols, although any children are also
312             hidden.
313             Visible – The symbol is drawn on the surface. It can be positioned, rotated,
314             and scaled. It can also be attached to another symbol as a child. It can also
315             be used as a parent by other symbols.
316              
317             Destroyed – The symbol is deleted and any system resources are freed. Any
318             children are also destroyed. All other attributes in this packet are ignored.
319              
320             Note: Although the Symbol Control packet supports destruction of symbols, it is
321             recommended that the Short Symbol Control packet be used for this purpose since
322             all other attributes are ignored.
323              
324             Hidden 0
325             Visible 1
326             Destroyed 2
327              
328             =cut
329              
330             sub symbol_state() {
331 1     1 1 3 my ($self,$nv) = @_;
332 1 50       19 if (defined($nv)) {
333 1 50 33     7 if (($nv==0) or ($nv==1) or ($nv==2)) {
      33        
334 1         3 $self->{'symbolState'} = $nv;
335 1         4 $self->{'_bitfields1'} |= $nv &0x03;
336             } else {
337 0         0 carp "symbol_state must be 0 (Hidden), 1 (Visible), or 2 (Destroyed).";
338             }
339             }
340 1         4 return ($self->{'_bitfields1'} & 0x03);
341             }
342              
343             #==============================================================================
344              
345             =item sub attribute_select1([$newValue])
346              
347             $value = $ssym_ctl->attribute_select1($newValue);
348              
349             Attribute Select 1.
350              
351             This attribute identifies the attribute whose value is specified in the
352             Attribute Value 1 field.
353              
354             If this attribute is set to None (0), then Attribute Value 1 is ignored.
355              
356             None 0
357             SurfaceIdent 1
358             ParentSymbolIdent 2
359             Layer 3
360             FlashDutyCycle 4
361             FlashPeriod 5
362             PositionU 6
363             PositionV 7
364             Rotation 8
365             Color 9
366             ScaleU 10
367             ScaleV 11
368              
369             =cut
370              
371             sub attribute_select1() {
372 1     1 1 10 my ($self,$nv) = @_;
373 1 50       13 if (defined($nv)) {
374 1 50 33     8 if (($nv==0) or ($nv==1) or ($nv==2) or ($nv==3) or ($nv==4) or ($nv==5) or ($nv==6) or ($nv==7) or ($nv==8) or ($nv==9) or ($nv==10) or ($nv==11)) {
      33        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
375 1         3 $self->{'attributeSelect1'} = $nv;
376 1 50 33     8 if($nv >= 5 and $nv <= 10 and $nv !=9) {
      33        
377 0         0 substr($self->{'_Pack'},7,1) = 'f';
378             } else {
379 1         6 substr($self->{'_Pack'},7,1) = 'I';
380             }
381             } else {
382 0         0 carp "attribute_select1 must be 0 (None), 1 (SurfaceIdent), 2 (ParentSymbolIdent), 3 (Layer), 4 (FlashDutyCycle), 5 (FlashPeriod), 6 (PositionU), 7 (PositionV), 8 (Rotation), 9 (Color), 10 (ScaleU), or 11 (ScaleV).";
383             }
384             }
385 1         3 return $self->{'attributeSelect1'};
386             }
387              
388             #==============================================================================
389              
390             =item sub attribute_select2([$newValue])
391              
392             $value = $ssym_ctl->attribute_select2($newValue);
393              
394             Attribute Select 2.
395              
396             This attribute identifies the attribute whose value is specified in the
397             Attribute Value 2 field.
398              
399             If this attribute is set to None (0), then Attribute Value 2 is ignored.
400              
401             None 0
402             SurfaceIdent 1
403             ParentSymbolIdent 2
404             Layer 3
405             FlashDutyCycle 4
406             FlashPeriod 5
407             PositionU 6
408             PositionV 7
409             Rotation 8
410             Color 9
411             ScaleU 10
412             ScaleV 11
413              
414             =cut
415              
416             sub attribute_select2() {
417 1     1 1 4 my ($self,$nv) = @_;
418 1 50       4 if (defined($nv)) {
419 1 50 33     7 if (($nv==0) or ($nv==1) or ($nv==2) or ($nv==3) or ($nv==4) or ($nv==5) or ($nv==6) or ($nv==7) or ($nv==8) or ($nv==9) or ($nv==10) or ($nv==11)) {
      33        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
420 1         3 $self->{'attributeSelect2'} = $nv;
421 1 50 33     8 if($nv >= 5 and $nv <= 10 and $nv !=9) {
      33        
422 0         0 substr($self->{'_Pack'},8,1) = 'f';
423             } else {
424 1         5 substr($self->{'_Pack'},8,1) = 'I';
425             }
426             } else {
427 0         0 carp "attribute_select2 must be 0 (None), 1 (SurfaceIdent), 2 (ParentSymbolIdent), 3 (Layer), 4 (FlashDutyCycle), 5 (FlashPeriod), 6 (PositionU), 7 (PositionV), 8 (Rotation), 9 (Color), 10 (ScaleU), or 11 (ScaleV).";
428             }
429             }
430 1         5 return $self->{'attributeSelect2'};
431             }
432              
433             #==============================================================================
434              
435             =item sub attribute_value1([$newValue])
436              
437             $value = $ssym_ctl->attribute_value1($newValue);
438              
439             Attribute Value 1.
440              
441             This attribute specifies the value of the attribute identified by the Attribute
442             Select 1 field.
443              
444             If Attribute Select 1 is set to Surface ID (1), Parent Symbol ID (2), Layer
445             (3), or Flash Duty Cycle Percentage (4), then Attribute Value 1 is treated as a
446             32-bit integer.
447              
448             If Attribute Select 1 is set to Flash Period (5), Position U (6), Position V
449             (7), Rotation (8), Scale V (10), or Scale V (11), then Attribute Value 1 is
450             treated as a 32-bit single-precision floating-point number.
451              
452             If Attribute Select 1 is Color (9), then Attribute Value 1 is treated as four
453             8-bit integers specifying each of the four color components. The most
454             significant byte specifies the red component, followed by the blue component,
455             then green, and finally alpha.
456              
457             Regardless of the attribute, the IG will byte-swap this attribute as a 32-bit
458             value if byte-swapping is required.
459              
460             =cut
461              
462             sub attribute_value1() {
463 1     1 1 6 my ($self,$nv) = @_;
464 1 50       4 if (defined($nv)) {
465 1         4 $self->{'attributeValue1'} = $nv;
466             }
467 1         9 return $self->{'attributeValue1'};
468             }
469              
470             #==============================================================================
471              
472             =item sub attribute_value2([$newValue])
473              
474             $value = $ssym_ctl->attribute_value2($newValue);
475              
476             Attribute Value 2.
477              
478             This attribute specifies the value of the attribute identified by the Attribute
479             Select 2 field.
480              
481             If Attribute Select 2 is set to Surface ID (1), Parent Symbol ID (2), Layer
482             (3), or Flash Duty Cycle Percentage (4), then Attribute Value 2 is treated as a
483             32-bit integer.
484              
485             If Attribute Select 2 is set to Flash Period (5), Position U (6), Position V
486             (7), Rotation (8), Scale V (10), or Scale V (11), then Attribute Value 2 is
487             treated as a 32-bit single-precision floating-point number.
488              
489             If Attribute Select 2 is Color (9), then Attribute Value 2 is treated as four
490             8-bit integers specifying each of the four color components. The most
491             significant byte specifies the red component, followed by the blue component,
492             then green, and finally alpha.
493              
494             Regardless of the attribute, the IG will byte-swap this attribute as a 32-bit
495             value if byte-swapping is required.
496              
497             =cut
498              
499             sub attribute_value2() {
500 1     1 1 7 my ($self,$nv) = @_;
501 1 50       5 if (defined($nv)) {
502 1         3 $self->{'attributeValue2'} = $nv;
503             }
504 1         3 return $self->{'attributeValue2'};
505             }
506              
507             #==========================================================================
508              
509             =item sub pack()
510              
511             $value = $ssym_ctl->pack();
512              
513             Returns the packed data packet.
514              
515             =cut
516              
517             sub pack($) {
518 1     1 1 7 my $self = shift ;
519            
520 1         8 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
521             $self->{'packetType'},
522             $self->{'packetSize'},
523             $self->{'symbolIdent'},
524             $self->{'_bitfields1'}, # Includes bitfields unused63, inheritColor, flashControl, attachState, and symbolState.
525             $self->{'_unused64'},
526             $self->{'attributeSelect1'},
527             $self->{'attributeSelect2'},
528             $self->{'attributeValue1'},
529             $self->{'attributeValue2'},
530             );
531              
532 1         5 return $self->{'_Buffer'};
533             }
534              
535             #==========================================================================
536              
537             =item sub unpack()
538              
539             $value = $ssym_ctl->unpack();
540              
541             Unpacks the packed data packet.
542              
543             =cut
544              
545             sub unpack($) {
546 0     0 1   my $self = shift @_;
547            
548 0 0         if (@_) {
549 0           $self->{'_Buffer'} = shift @_;
550             }
551 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
552 0 0 0       if($f >= 5 and $f <=10 and $f !=9) {
      0        
553 0           $h = CORE::unpack('f',substr($self->{'_Buffer'},8));
554 0           $self->{'_Pack'} = 'CCSCCCCf';
555             } else {
556 0           $h = CORE::unpack('I',substr($self->{'_Buffer'},8));
557 0           $self->{'_Pack'} = 'CCSCCCCI';
558             }
559 0 0 0       if($g >= 5 and $g <=10 and $g !=9) {
      0        
560 0           $i = CORE::unpack('f',substr($self->{'_Buffer'},12));
561 0           $self->{'_Pack'} .= 'f';
562             } else {
563 0           $i = CORE::unpack('I',substr($self->{'_Buffer'},12));
564 0           $self->{'_Pack'} .= 'I';
565             }
566              
567 0           $self->{'packetType'} = $a;
568 0           $self->{'packetSize'} = $b;
569 0           $self->{'symbolIdent'} = $c;
570 0           $self->{'_bitfields1'} = $d; # Includes bitfields unused63, inheritColor, flashControl, attachState, and symbolState.
571 0           $self->{'_unused64'} = $e;
572 0           $self->{'attributeSelect1'} = $f;
573 0           $self->{'attributeSelect2'} = $g;
574 0           $self->{'attributeValue1'} = $h;
575 0           $self->{'attributeValue2'} = $i;
576              
577 0           $self->{'inheritColor'} = $self->inherit_color();
578 0           $self->{'flashControl'} = $self->flash_control();
579 0           $self->{'attachState'} = $self->attach_state();
580 0           $self->{'symbolState'} = $self->symbol_state();
581              
582 0           return $self->{'_Buffer'};
583             }
584              
585             #==========================================================================
586              
587             =item sub byte_swap()
588              
589             $obj_name->byte_swap();
590              
591             Byte swaps the packed data packet.
592              
593             =cut
594              
595             sub byte_swap($) {
596 0     0 1   my $self = shift @_;
597            
598 0 0         if (@_) {
599 0           $self->{'_Buffer'} = shift @_;
600             } else {
601 0           $self->pack();
602             }
603 0           my ($a,$b,$c,$d,$e,$f,$g) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
604              
605 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g);
606 0           $self->unpack();
607              
608 0           return $self->{'_Buffer'};
609             }
610              
611             1;
612             __END__