File Coverage

blib/lib/Rinchi/CIGIPP/ShortComponentControl.pm
Criterion Covered Total %
statement 63 167 37.7
branch 13 68 19.1
condition 4 48 8.3
subroutine 16 31 51.6
pod 27 27 100.0
total 123 341 36.0


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78abfbe-200e-11de-bda5-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::ShortComponentControl;
8              
9 1     1   34 use 5.006;
  1         3  
  1         44  
10 1     1   8 use strict;
  1         1  
  1         36  
11 1     1   8 use warnings;
  1         2  
  1         32  
12 1     1   5 use Carp;
  1         2  
  1         7579  
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::ShortComponentControl - Perl extension for the Common Image
42             Generator Interface - Short Component Control data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::ShortComponentControl;
47             my $scmp_ctl = Rinchi::CIGIPP::ShortComponentControl->new();
48              
49             $packet_type = $scmp_ctl->packet_type();
50             $packet_size = $scmp_ctl->packet_size();
51             $component_ident = $scmp_ctl->component_ident(8600);
52             $instance_ident = $scmp_ctl->instance_ident(3133);
53             $component_class = $scmp_ctl->component_class(Rinchi::CIGIPP->ViewCC);
54             $component_state = $scmp_ctl->component_state(67);
55             $data1 = $scmp_ctl->data1(43182);
56             $data2 = $scmp_ctl->data2(31535);
57              
58             =head1 DESCRIPTION
59              
60             The Short Component Control packet, like the Component Control packet, is a
61             generic packet used to control a variety of objects or functions on the IG.
62             This packet is provided as a lower-bandwidth alternative to the Component
63             Control packet for components that do not require more than two words of
64             component data.
65              
66             This packet uses the same Component ID and Instance ID mappings as the
67             Component Control packet. If the additional data fields offered by the
68             Component Control packet are not necessary for a component, then the two packet
69             types should be interchangeable. In other words, all components that can be
70             controlled with the Short Component Control packet can also be controlled with
71             the Component Control packet.
72              
73             When receiving a Short Component Control packet, the IG may copy the contents
74             of the packet into a Component Control structure, padding the remainder of the
75             packet with zeros (0). The two packet types can then be processed by the same
76             packet-handling routine.
77              
78             The Component Data 1 and Component Data 2 fields will be byte-swapped, if
79             necessary, as 32-bit data types. Data should be packed into 32-bit units as
80             described for the Component Control packet.
81              
82             =head2 EXPORT
83              
84             None by default.
85              
86             #==============================================================================
87              
88             =item new $scmp_ctl = Rinchi::CIGIPP::ShortComponentControl->new()
89              
90             Constructor for Rinchi::ShortComponentControl.
91              
92             =cut
93              
94             sub new {
95 1     1 1 238 my $class = shift;
96 1   33     7 $class = ref($class) || $class;
97              
98 1         10 my $self = {
99             '_Buffer' => '',
100             '_ClassIdent' => 'f78abfbe-200e-11de-bda5-001c25551abc',
101             '_Pack' => 'CCSSCCII',
102             '_Swap1' => 'CCvvCCVV',
103             '_Swap2' => 'CCnnCCNN',
104             'packetType' => 5,
105             'packetSize' => 16,
106             'componentIdent' => 0,
107             'instanceIdent' => 0,
108             '_bitfields1' => 0, # Includes bitfields unused7, and componentClass.
109             'componentClass' => 0,
110             'componentState' => 0,
111             'data1' => 0,
112             'data2' => 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 1         4 $self->{'_LittleEndian'} = (CORE::unpack('v',CORE::pack('S',0x8000)) == 0x8000);
125              
126 1         2 bless($self,$class);
127 1         3 return $self;
128             }
129              
130             #==============================================================================
131              
132             =item sub packet_type()
133              
134             $value = $scmp_ctl->packet_type();
135              
136             Data Packet Identifier.
137              
138             This attribute identifies this data packet as the Short Component Control
139             packet. The value of this attribute must be 5.
140              
141             =cut
142              
143             sub packet_type() {
144 1     1 1 6 my ($self) = @_;
145 1         8 return $self->{'packetType'};
146             }
147              
148             #==============================================================================
149              
150             =item sub packet_size()
151              
152             $value = $scmp_ctl->packet_size();
153              
154             Data Packet Size.
155              
156             This attribute indicates the number of bytes in this data packet. The value of
157             this attribute must be 16.
158              
159             =cut
160              
161             sub packet_size() {
162 1     1 1 5 my ($self) = @_;
163 1         3 return $self->{'packetSize'};
164             }
165              
166             #==============================================================================
167              
168             =item sub component_ident([$newValue])
169              
170             $value = $scmp_ctl->component_ident($newValue);
171              
172             Component Identifier.
173              
174             This attribute uniquely identifies the component to which the data in this
175             packet should be applied.
176              
177             If Component Class is set to Regional Layered Weather (6), the weather layer ID
178             is specified by the most significant byte of Component ID.
179              
180             =cut
181              
182             sub component_ident() {
183 1     1 1 6 my ($self,$nv) = @_;
184 1 50       10 if (defined($nv)) {
185 1         2 $self->{'componentIdent'} = $nv;
186             }
187 1         3 return $self->{'componentIdent'};
188             }
189              
190             #==============================================================================
191              
192             =item sub instance_ident([$newValue])
193              
194             $value = $scmp_ctl->instance_ident($newValue);
195              
196             Instance Identifier.
197              
198             This attribute uniquely identifies the object to which the component belongs.
199             This value corresponds to an entity ID, a view or view group ID, a sensor ID,
200             environmental region ID, global weather layer ID, or event ID depending upon
201             the value of the Component Class attribute.
202              
203             =cut
204              
205             sub instance_ident() {
206 1     1 1 6 my ($self,$nv) = @_;
207 1 50       4 if (defined($nv)) {
208 1         4 $self->{'instanceIdent'} = $nv;
209             }
210 1         2 return $self->{'instanceIdent'};
211             }
212              
213             #==============================================================================
214              
215             =item sub component_class([$newValue])
216              
217             $value = $scmp_ctl->component_class($newValue);
218              
219             Component Class.
220              
221             This attribute identifies the type of object to which the Instance ID attribute
222             refers. Both of these attributes are used in conjunction with Component ID to
223             uniquely identify a component in the simulation.
224              
225             EntityCC 0
226             ViewCC 1
227             ViewGroupCC 2
228             SensorCC 3
229             RegionalSeaSurfaceCC 4
230             RegionalTerrainSurfaceCC 5
231             RegionalLayeredWeatherCC 6
232             GlobalSeaSurfaceCC 7
233             GlobalTerrainSurfaceCC 8
234             GlobalLayeredWeatherCC 9
235             AtmosphereCC 10
236             CelestialSphereCC 11
237             EventCC 12
238             SystemCC 13
239             SymbolSurfaceCC 14
240             SymbolCC 15
241              
242             =cut
243              
244             sub component_class() {
245 1     1 1 2 my ($self,$nv) = @_;
246 1 50       4 if (defined($nv)) {
247 1 50 33     11 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) or ($nv==12) or ($nv==13) or ($nv==14) or ($nv==15)) {
      33        
      33        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
      0        
248 1         3 $self->{'componentClass'} = $nv;
249 1         3 $self->{'_bitfields1'} |= $nv &0x3F;
250             } else {
251 0         0 carp "component_class must be 0 (EntityCC), 1 (ViewCC), 2 (ViewGroupCC), 3 (SensorCC), 4 (RegionalSeaSurfaceCC), 5 (RegionalTerrainSurfaceCC), 6 (RegionalLayeredWeatherCC), 7 (GlobalSeaSurfaceCC), 8 (GlobalTerrainSurfaceCC), 9 (GlobalLayeredWeatherCC), 10 (AtmosphereCC), 11 (CelestialSphereCC), 12 (EventCC), 13 (SystemCC), 14 (SymbolSurfaceCC), or 15 (SymbolCC).";
252             }
253             }
254 1         3 return ($self->{'_bitfields1'} & 0x3F);
255             }
256              
257             #==============================================================================
258              
259             =item sub component_state([$newValue])
260              
261             $value = $scmp_ctl->component_state($newValue);
262              
263             Component State.
264              
265             This attribute specifies a discrete state for the component. If a discrete
266             state is not applicable to the component, this attribute is ignored.
267              
268             =cut
269              
270             sub component_state() {
271 1     1 1 5 my ($self,$nv) = @_;
272 1 50       3 if (defined($nv)) {
273 1         2 $self->{'componentState'} = $nv;
274             }
275 1         3 return $self->{'componentState'};
276             }
277              
278             #==============================================================================
279              
280             =item sub data1([$newValue])
281              
282             $value = $scmp_ctl->data1($newValue);
283              
284             Component Data 1.
285              
286             This attribute represents one of two 32-bit words used for user-defined
287             component data. If this attribute is not needed by the component, this value is
288             ignored.
289              
290             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
291             sender use different byte ordering schemes. If the attribute is used to store
292             multiple 8- or 16-bit values, the data should be packed so that byte swapping
293             will be performed correctly.
294              
295             =cut
296              
297             sub data1() {
298 1     1 1 4 my ($self,$nv) = @_;
299 1 50       4 if (defined($nv)) {
300 1         2 $self->{'data1'} = $nv;
301             }
302 1         3 return $self->{'data1'};
303             }
304              
305             #==============================================================================
306              
307             =item sub data1_float([$newValue])
308              
309             $value = $scmp_ctl->data1_float($newValue);
310              
311             Component Data 1.
312              
313             This attribute represents as a float one of two 32-bit words used for user-defined
314             component data. If this attribute is not needed by the component, this value is
315             ignored.
316              
317             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
318             sender use different byte ordering schemes. If the attribute is used to store
319             multiple 8- or 16-bit values, the data should be packed so that byte swapping
320             will be performed correctly.
321              
322             =cut
323              
324             sub data1_float() {
325 1     1 1 5 my ($self,$nv) = @_;
326 1 50       4 if (defined($nv)) {
327 0         0 my $nvp = CORE::pack('f',$nv);
328 0 0       0 if($self->{'_LittleEndian'}) {
329 0         0 $self->{'data1'} = CORE::unpack('V',$nvp);
330             } else {
331 0         0 $self->{'data1'} = CORE::unpack('N',$nvp);
332             }
333             }
334 1 50       4 if($self->{'_LittleEndian'}) {
335 1         6 return CORE::unpack('f',CORE::pack('V',$self->{'data1'}));
336             } else {
337 0         0 return CORE::unpack('f',CORE::pack('N',$self->{'data1'}));
338             }
339             }
340              
341             #==============================================================================
342              
343             =item sub data1_short1([$newValue])
344              
345             $value = $scmp_ctl->data1_short1($newValue);
346              
347             Component Data 1.
348              
349             This attribute represents as a short the two most significant bytes of one of
350             two 32-bit words used for user-defined component data. If this attribute is not
351             needed by the component, this value is ignored.
352              
353             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
354             sender use different byte ordering schemes. If the attribute is used to store
355             multiple 8- or 16-bit values, the data should be packed so that byte swapping
356             will be performed correctly.
357              
358             =cut
359              
360             sub data1_short1() {
361 0     0 1 0 my ($self,$nv) = @_;
362 0 0       0 if (defined($nv)) {
363 0         0 $nv = (($nv & 0xFFFF) << 16) | ($self->{'data1'} & 0xFFFF);
364 0         0 $self->{'data1'} = $nv;
365             }
366 0         0 return ($self->{'data1'} >> 16) & 0xFFFF;
367             }
368              
369             #==============================================================================
370              
371             =item sub data1_short2([$newValue])
372              
373             $value = $scmp_ctl->data1_short2($newValue);
374              
375             Component Data 1.
376              
377             This attribute represents as a short the two least significant bytes of one of
378             two 32-bit words used for user-defined component data. If this attribute is not
379             needed by the component, this value is ignored.
380              
381             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
382             sender use different byte ordering schemes. If the attribute is used to store
383             multiple 8- or 16-bit values, the data should be packed so that byte swapping
384             will be performed correctly.
385              
386             =cut
387              
388             sub data1_short2() {
389 0     0 1 0 my ($self,$nv) = @_;
390 0 0       0 if (defined($nv)) {
391 0         0 $nv = ($nv & 0xFFFF) | ($self->{'data1'} & 0xFFFF0000);
392 0         0 $self->{'data1'} = $nv;
393             }
394 0         0 return $self->{'data1'} & 0xFFFF;
395             }
396              
397             #==============================================================================
398              
399             =item sub data1_byte1([$newValue])
400              
401             $value = $scmp_ctl->data1_byte1($newValue);
402              
403             Component Data 1.
404              
405             This attribute represents the most significant byte of one of
406             two 32-bit words used for user-defined component data. If this attribute is not
407             needed by the component, this value is ignored.
408              
409             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
410             sender use different byte ordering schemes. If the attribute is used to store
411             multiple 8- or 16-bit values, the data should be packed so that byte swapping
412             will be performed correctly.
413              
414             =cut
415              
416             sub data1_byte1() {
417 0     0 1 0 my ($self,$nv) = @_;
418 0 0       0 if (defined($nv)) {
419 0         0 $nv = (($nv & 0xFF) << 24) | ($self->{'data1'} & 0xFFFFFF);
420 0         0 $self->{'data1'} = $nv;
421             }
422 0         0 return ($self->{'data1'} >> 24) & 0xFF;
423             }
424              
425             #==============================================================================
426              
427             =item sub data1_byte2([$newValue])
428              
429             $value = $scmp_ctl->data1_byte2($newValue);
430              
431             Component Data 1.
432              
433             This attribute represents the second most significant byte of one of
434             two 32-bit words used for user-defined component data. If this attribute is not
435             needed by the component, this value is ignored.
436              
437             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
438             sender use different byte ordering schemes. If the attribute is used to store
439             multiple 8- or 16-bit values, the data should be packed so that byte swapping
440             will be performed correctly.
441              
442             =cut
443              
444             sub data1_byte2() {
445 0     0 1 0 my ($self,$nv) = @_;
446 0 0       0 if (defined($nv)) {
447 0         0 $nv = (($nv & 0xFF) << 16) | ($self->{'data1'} & 0xFF00FFFF);
448 0         0 $self->{'data1'} = $nv;
449             }
450 0         0 return ($self->{'data1'} >> 16) & 0xFF;
451             }
452              
453             #==============================================================================
454              
455             =item sub data1_byte3([$newValue])
456              
457             $value = $scmp_ctl->data1_byte3($newValue);
458              
459             Component Data 1.
460              
461             This attribute represents the second least significant byte of one of
462             two 32-bit words used for user-defined component data. If this attribute is not
463             needed by the component, this value is ignored.
464              
465             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
466             sender use different byte ordering schemes. If the attribute is used to store
467             multiple 8- or 16-bit values, the data should be packed so that byte swapping
468             will be performed correctly.
469              
470             =cut
471              
472             sub data1_byte3() {
473 0     0 1 0 my ($self,$nv) = @_;
474 0 0       0 if (defined($nv)) {
475 0         0 $nv = (($nv & 0xFF) << 8) | ($self->{'data1'} & 0xFFFF00FF);
476 0         0 $self->{'data1'} = $nv;
477             }
478 0         0 return ($self->{'data1'} >> 8) & 0xFF;
479             }
480              
481             #==============================================================================
482              
483             =item sub data1_byte4([$newValue])
484              
485             $value = $scmp_ctl->data1_byte4($newValue);
486              
487             Component Data 1.
488              
489             This attribute represents the least significant byte of one of
490             two 32-bit words used for user-defined component data. If this attribute is not
491             needed by the component, this value is ignored.
492              
493             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
494             sender use different byte ordering schemes. If the attribute is used to store
495             multiple 8- or 16-bit values, the data should be packed so that byte swapping
496             will be performed correctly.
497              
498             =cut
499              
500             sub data1_byte4() {
501 0     0 1 0 my ($self,$nv) = @_;
502 0 0       0 if (defined($nv)) {
503 0         0 $nv = ($nv & 0xFF) | ($self->{'data1'} & 0xFFFFFF00);
504 0         0 $self->{'data1'} = $nv;
505             }
506 0         0 return $self->{'data1'} & 0xFF;
507             }
508              
509             #==============================================================================
510              
511             =item sub data1_and_2_double([$newValue])
512              
513             $value = $scmp_ctl->data1_and_2_double($newValue);
514              
515             Component Data 1.
516              
517             This attribute represents as a double both 32-bit words used for user-defined
518             component data. If this attribute is not needed by the component, this value is
519             ignored.
520              
521             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
522             sender use different byte ordering schemes. If the attribute is used to store
523             multiple 8- or 16-bit values, the data should be packed so that byte swapping
524             will be performed correctly.
525              
526             =cut
527              
528             sub data1_and_2_double() {
529 1     1 1 13 my ($self,$nv) = @_;
530 1 50       4 if (defined($nv)) {
531 1         3 my $nvp = CORE::pack('d',$nv);
532 1 50       5 if($self->{'_LittleEndian'}) {
533 1         5 ($self->{'data2'}, $self->{'data1'}) = CORE::unpack('VV',$nvp);
534             } else {
535 0         0 ($self->{'data1'}, $self->{'data2'}) = CORE::unpack('NN',$nvp);
536             }
537             }
538 1 50       4 if($self->{'_LittleEndian'}) {
539 1         6 return CORE::unpack('d',CORE::pack('VV',$self->{'data2'}, $self->{'data1'}));
540             } else {
541 0         0 return CORE::unpack('d',CORE::pack('NV',$self->{'data1'}, $self->{'data2'}));
542             }
543             }
544              
545             #==============================================================================
546              
547             =item sub data2([$newValue])
548              
549             $value = $scmp_ctl->data2($newValue);
550              
551             Component Data 2.
552              
553             This attribute represents one of two 32-bit words used for user-defined
554             component data. If this attribute is not needed by the component, this value is
555             ignored.
556              
557             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
558             sender use different byte ordering schemes. If the attribute is used to store
559             multiple 8- or 16-bit values, the data should be packed so that byte swapping
560             will be performed correctly.
561              
562             =cut
563              
564             sub data2() {
565 1     1 1 294 my ($self,$nv) = @_;
566 1 50       7 if (defined($nv)) {
567 1         2 $self->{'data2'} = $nv;
568             }
569 1         5 return $self->{'data2'};
570             }
571              
572             #==============================================================================
573              
574             =item sub data2_float([$newValue])
575              
576             $value = $scmp_ctl->data1_float($newValue);
577              
578             Component Data 2.
579              
580             This attribute represents as a float one of two 32-bit words used for user-defined
581             component data. If this attribute is not needed by the component, this value is
582             ignored.
583             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
584             sender use different byte ordering schemes. If the attribute is used to store
585             multiple 8- or 16-bit values, the data should be packed so that byte swapping
586             will be performed correctly.
587              
588             =cut
589              
590             sub data2_float() {
591 0     0 1 0 my ($self,$nv) = @_;
592 0 0       0 if (defined($nv)) {
593 0         0 my $nvp = CORE::pack('f',$nv);
594 0 0       0 if($self->{'_LittleEndian'}) {
595 0         0 $self->{'data2'} = CORE::unpack('V',$nvp);
596             } else {
597 0         0 $self->{'data2'} = CORE::unpack('N',$nvp);
598             }
599             }
600 0 0       0 if($self->{'_LittleEndian'}) {
601 0         0 return CORE::unpack('f',CORE::pack('V',$self->{'data2'}));
602             } else {
603 0         0 return CORE::unpack('f',CORE::pack('N',$self->{'data2'}));
604             }
605             }
606              
607             #==============================================================================
608              
609             =item sub data2_short1([$newValue])
610              
611             $value = $scmp_ctl->data2_short1($newValue);
612              
613             Component Data 2.
614              
615             This attribute represents as a short the two most significant bytes of one of
616             two 32-bit words used for user-defined component data. If this attribute is not
617             needed by the component, this value is ignored.
618              
619             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
620             sender use different byte ordering schemes. If the attribute is used to store
621             multiple 8- or 16-bit values, the data should be packed so that byte swapping
622             will be performed correctly.
623              
624             =cut
625              
626             sub data2_short1() {
627 0     0 1 0 my ($self,$nv) = @_;
628 0 0       0 if (defined($nv)) {
629 0         0 $nv = (($nv & 0xFFFF) << 16) | ($self->{'data2'} & 0xFFFF);
630 0         0 $self->{'data2'} = $nv;
631             }
632 0         0 return ($self->{'data2'} >> 16) & 0xFFFF;
633             }
634              
635             #==============================================================================
636              
637             =item sub data2_short2([$newValue])
638              
639             $value = $scmp_ctl->data2_short2($newValue);
640              
641             Component Data 2.
642              
643             This attribute represents as a short the two least significant bytes of one of
644             two 32-bit words used for user-defined component data. If this attribute is not
645             needed by the component, this value is ignored.
646              
647             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
648             sender use different byte ordering schemes. If the attribute is used to store
649             multiple 8- or 16-bit values, the data should be packed so that byte swapping
650             will be performed correctly.
651              
652             =cut
653              
654             sub data2_short2() {
655 0     0 1 0 my ($self,$nv) = @_;
656 0 0       0 if (defined($nv)) {
657 0         0 $nv = ($nv & 0xFFFF) | ($self->{'data2'} & 0xFFFF0000);
658 0         0 $self->{'data2'} = $nv;
659             }
660 0         0 return $self->{'data2'} & 0xFFFF;
661             }
662              
663             #==============================================================================
664              
665             =item sub data2_byte1([$newValue])
666              
667             $value = $scmp_ctl->data2_byte1($newValue);
668              
669             Component Data 2.
670              
671             This attribute represents the most significant byte of one of
672             two 32-bit words used for user-defined component data. If this attribute is not
673             needed by the component, this value is ignored.
674              
675             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
676             sender use different byte ordering schemes. If the attribute is used to store
677             multiple 8- or 16-bit values, the data should be packed so that byte swapping
678             will be performed correctly.
679              
680             =cut
681              
682             sub data2_byte1() {
683 0     0 1 0 my ($self,$nv) = @_;
684 0 0       0 if (defined($nv)) {
685 0         0 $nv = (($nv & 0xFF) << 24) | ($self->{'data2'} & 0xFFFFFF);
686 0         0 $self->{'data2'} = $nv;
687             }
688 0         0 return ($self->{'data2'} >> 24) & 0xFF;
689             }
690              
691             #==============================================================================
692              
693             =item sub data2_byte2([$newValue])
694              
695             $value = $scmp_ctl->data2_byte2($newValue);
696              
697             Component Data 2.
698              
699             This attribute represents the second most significant byte of one of
700             two 32-bit words used for user-defined component data. If this attribute is not
701             needed by the component, this value is ignored.
702              
703             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
704             sender use different byte ordering schemes. If the attribute is used to store
705             multiple 8- or 16-bit values, the data should be packed so that byte swapping
706             will be performed correctly.
707              
708             =cut
709              
710             sub data2_byte2() {
711 0     0 1 0 my ($self,$nv) = @_;
712 0 0       0 if (defined($nv)) {
713 0         0 $nv = (($nv & 0xFF) << 16) | ($self->{'data2'} & 0xFF00FFFF);
714 0         0 $self->{'data2'} = $nv;
715             }
716 0         0 return ($self->{'data2'} >> 16) & 0xFF;
717             }
718              
719             #==============================================================================
720              
721             =item sub data2_byte3([$newValue])
722              
723             $value = $scmp_ctl->data2_byte3($newValue);
724              
725             Component Data 2.
726              
727             This attribute represents the second least significant byte of one of
728             two 32-bit words used for user-defined component data. If this attribute is not
729             needed by the component, this value is ignored.
730              
731             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
732             sender use different byte ordering schemes. If the attribute is used to store
733             multiple 8- or 16-bit values, the data should be packed so that byte swapping
734             will be performed correctly.
735              
736             =cut
737              
738             sub data2_byte3() {
739 0     0 1 0 my ($self,$nv) = @_;
740 0 0       0 if (defined($nv)) {
741 0         0 $nv = (($nv & 0xFF) << 8) | ($self->{'data2'} & 0xFFFF00FF);
742 0         0 $self->{'data2'} = $nv;
743             }
744 0         0 return ($self->{'data2'} >> 8) & 0xFF;
745             }
746              
747             #==============================================================================
748              
749             =item sub data2_byte4([$newValue])
750              
751             $value = $scmp_ctl->data2_byte4($newValue);
752              
753             Component Data 2.
754              
755             This attribute represents the least significant byte of one of
756             two 32-bit words used for user-defined component data. If this attribute is not
757             needed by the component, this value is ignored.
758              
759             Note: This attribute will be byte-swapped as a 32-bit value if the receiver and
760             sender use different byte ordering schemes. If the attribute is used to store
761             multiple 8- or 16-bit values, the data should be packed so that byte swapping
762             will be performed correctly.
763              
764             =cut
765              
766             sub data2_byte4() {
767 0     0 1 0 my ($self,$nv) = @_;
768 0 0       0 if (defined($nv)) {
769 0         0 $nv = ($nv & 0xFF) | ($self->{'data2'} & 0xFFFFFF00);
770 0         0 $self->{'data2'} = $nv;
771             }
772 0         0 return $self->{'data2'} & 0xFF;
773             }
774              
775             #==========================================================================
776              
777             =item sub pack()
778              
779             $value = $scmp_ctl->pack();
780              
781             Returns the packed data packet.
782              
783             =cut
784              
785             sub pack($) {
786 1     1 1 187 my $self = shift ;
787            
788 1         8 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
789             $self->{'packetType'},
790             $self->{'packetSize'},
791             $self->{'componentIdent'},
792             $self->{'instanceIdent'},
793             $self->{'_bitfields1'}, # Includes bitfields unused7, and componentClass.
794             $self->{'componentState'},
795             $self->{'data1'},
796             $self->{'data2'},
797             );
798              
799 1         3 return $self->{'_Buffer'};
800             }
801              
802             #==========================================================================
803              
804             =item sub unpack()
805              
806             $value = $scmp_ctl->unpack();
807              
808             Unpacks the packed data packet.
809              
810             =cut
811              
812             sub unpack($) {
813 0     0 1   my $self = shift @_;
814            
815 0 0         if (@_) {
816 0           $self->{'_Buffer'} = shift @_;
817             }
818 0           my ($a,$b,$c,$d,$e,$f,$g,$h) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
819 0           $self->{'packetType'} = $a;
820 0           $self->{'packetSize'} = $b;
821 0           $self->{'componentIdent'} = $c;
822 0           $self->{'instanceIdent'} = $d;
823 0           $self->{'_bitfields1'} = $e; # Includes bitfields unused7, and componentClass.
824 0           $self->{'componentState'} = $f;
825 0           $self->{'data1'} = $g;
826 0           $self->{'data2'} = $h;
827              
828 0           $self->{'componentClass'} = $self->component_class();
829              
830 0           return $self->{'_Buffer'};
831             }
832              
833             #==========================================================================
834              
835             =item sub byte_swap()
836              
837             $obj_name->byte_swap();
838              
839             Byte swaps the packed data packet.
840              
841             =cut
842              
843             sub byte_swap($) {
844 0     0 1   my $self = shift @_;
845            
846 0 0         if (@_) {
847 0           $self->{'_Buffer'} = shift @_;
848             } else {
849 0           $self->pack();
850             }
851 0           my ($a,$b,$c,$d,$e,$f,$g,$h) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
852              
853 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h);
854 0           $self->unpack();
855              
856 0           return $self->{'_Buffer'};
857             }
858              
859             #==========================================================================
860              
861             1;
862             __END__