File Coverage

blib/lib/Rinchi/CIGIPP/SensorControl.pm
Criterion Covered Total %
statement 91 134 67.9
branch 21 52 40.3
condition 9 42 21.4
subroutine 21 23 91.3
pod 19 19 100.0
total 161 270 59.6


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78ae02a-200e-11de-bdb1-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::SensorControl;
8              
9 1     1   31 use 5.006;
  1         4  
  1         44  
10 1     1   7 use strict;
  1         2  
  1         38  
11 1     1   8 use warnings;
  1         1  
  1         275  
12 1     1   8 use Carp;
  1         2  
  1         6399  
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::SensorControl - Perl extension for the Common Image Generator
42             Interface - Sensor Control data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::SensorControl;
47             my $sensor_ctl = Rinchi::CIGIPP::SensorControl->new();
48              
49             $packet_type = $sensor_ctl->packet_type();
50             $packet_size = $sensor_ctl->packet_size();
51             $view_ident = $sensor_ctl->view_ident(53486);
52             $sensor_ident = $sensor_ctl->sensor_ident(190);
53             $track_mode = $sensor_ctl->track_mode(Rinchi::CIGIPP->Off);
54             $track_white_black = $sensor_ctl->track_white_black(Rinchi::CIGIPP->Black);
55             $automatic_gain_enable = $sensor_ctl->automatic_gain_enable(Rinchi::CIGIPP->Enable);
56             $line_by_line_dropout_enable = $sensor_ctl->line_by_line_dropout_enable(Rinchi::CIGIPP->Enable);
57             $polarity = $sensor_ctl->polarity(Rinchi::CIGIPP->WhiteHot);
58             $sensor_on_off = $sensor_ctl->sensor_on_off(Rinchi::CIGIPP->Off);
59             $response_type = $sensor_ctl->response_type(Rinchi::CIGIPP->ExtendedSRT);
60             $gain = $sensor_ctl->gain(62.89);
61             $level = $sensor_ctl->level(54.416);
62             $ac_coupling = $sensor_ctl->ac_coupling(61.664);
63             $noise = $sensor_ctl->noise(42.664);
64              
65             =head1 DESCRIPTION
66              
67             The Sensor Control packet is used to control sensor modes and display behavior
68             for sensor-based weapons systems and other sensor applications. It is typically
69             used in conjunction the View Control packet, which moves the sensor camera
70             eyepoint. The View Definition and Component Control packets can also be used to
71             control various aspects of camera and sensor behavior.
72              
73             A sensor is associated with a view through the View ID attribute. A sensor may
74             be associated with more than one view to allow the sensor imagery to be
75             displayed on multiple displays; however, this may evoke multiple Sensor
76             Response or Sensor Extended Response packets from the IG.
77              
78             In a typical scenario, the sensor will be inactive until the user turns the
79             sensor on. The Host will send a Sensor Control packet with the Sensor On/Off
80             attribute set to On (1). Because the sensor is not yet tracking a target, the
81             Track Mode attribute of this packet should be set to Off (0). The Host might
82             also send a View Control packet to make sure the initial sensor camera position
83             is set. Additional View Control packets will be sent as the user slews the
84             sensor view.
85              
86             When the user attempts to lock onto a target, the Host will send a Sensor
87             Control packet, setting the Track Mode attribute to the appropriate value.
88             Because the Host will need the position of the track point to determine which
89             entity is the target, it sets the Response Type attribute to Gate and Target
90             Position (1).
91              
92             The IG will immediately begin sending response packets (in this case, Sensor
93             Extended Response packets) that contain the gate symbol position and, if
94             appropriate, the sensor target position. A response packet will be sent every
95             frame until the IG is directed to do otherwise by the Host.
96              
97             The Sensor Status attribute of the response packets will indicate whether the
98             sensor was able to establish a lock. If the sensor was unable to do so, the
99             Sensor Status attribute will be set to zero (0). The Host then should reset the
100             Track Mode attribute to Off (0) before the user again tries to lock onto the
101             target. If, on the other hand, the lock was successful, then the Sensor Status
102             attribute will be set to one (1).
103              
104             The Entity ID attribute of the Sensor Extended Response packet contains the ID
105             of the target entity. If the IG cannot determine the target, or if the sensor
106             is tracking non-entity geometry, then the Entity ID Valid attribute of the
107             response packet will be set to Invalid (0). The Host must then use the target
108             position returned by the IG to determine which entity or object is being
109             tracked by the sensor. This may occur immediately or over several frames,
110             depending upon the number and proximity of entities along the sensor viewing
111             vector.
112             Once the Host has determined the target, it can send a Sensor Control packet
113             with its Response Type attribute set to Gate Position (1), directing the IG to
114             send Sensor Response packets instead of Sensor Extended Response packets.
115              
116             =head2 EXPORT
117              
118             None by default.
119              
120             #==============================================================================
121              
122             =item new $sensor_ctl = Rinchi::CIGIPP::SensorControl->new()
123              
124             Constructor for Rinchi::SensorControl.
125              
126             =cut
127              
128             sub new {
129 1     1 1 695 my $class = shift;
130 1   33     9 $class = ref($class) || $class;
131              
132 1         20 my $self = {
133             '_Buffer' => '',
134             '_ClassIdent' => 'f78ae02a-200e-11de-bdb1-001c25551abc',
135             '_Pack' => 'CCSCCCCffff',
136             '_Swap1' => 'CCvCCCCVVVV',
137             '_Swap2' => 'CCnCCCCNNNN',
138             'packetType' => 17,
139             'packetSize' => 24,
140             'viewIdent' => 0,
141             'sensorIdent' => 0,
142             '_bitfields1' => 0, # Includes bitfields trackMode, TrackWhtBlk, automaticGainEnable, lineByLineDropoutEnable, polarity, and sensorOnOff.
143             'trackMode' => 0,
144             'trackWhiteBlack' => 0,
145             'automaticGainEnable' => 0,
146             'lineByLineDropoutEnable' => 0,
147             'polarity' => 0,
148             'sensorOnOff' => 0,
149             '_bitfields2' => 0, # Includes bitfields unused30, and responseType.
150             'responseType' => 0,
151             '_unused31' => 0,
152             'gain' => 0,
153             'level' => 0,
154             'acCoupling' => 0,
155             'noise' => 0,
156             };
157              
158 1 50       5 if (@_) {
159 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
160 0         0 $self->{'_Buffer'} = $_[0][0];
161             } elsif (ref($_[0]) eq 'HASH') {
162 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
163 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
164             }
165             }
166             }
167              
168 1         3 bless($self,$class);
169 1         3 return $self;
170             }
171              
172             #==============================================================================
173              
174             =item sub packet_type()
175              
176             $value = $sensor_ctl->packet_type();
177              
178             Data Packet Identifier.
179              
180             This attribute identifies this data packet as the Sensor Control packet. The
181             value of this attribute must be 17.
182              
183             =cut
184              
185             sub packet_type() {
186 1     1 1 7 my ($self) = @_;
187 1         8 return $self->{'packetType'};
188             }
189              
190             #==============================================================================
191              
192             =item sub packet_size()
193              
194             $value = $sensor_ctl->packet_size();
195              
196             Data Packet Size.
197              
198             This attribute indicates the number of bytes in this data packet. The value of
199             this attribute must be 24.
200              
201             =cut
202              
203             sub packet_size() {
204 1     1 1 6 my ($self) = @_;
205 1         3 return $self->{'packetSize'};
206             }
207              
208             #==============================================================================
209              
210             =item sub view_ident([$newValue])
211              
212             $value = $sensor_ctl->view_ident($newValue);
213              
214             View ID.
215              
216             This attribute identifies the view to which the specified sensor is assigned.
217             Note that a sensor cannot be assigned to a view group.
218              
219             =cut
220              
221             sub view_ident() {
222 1     1 1 7 my ($self,$nv) = @_;
223 1 50       13 if (defined($nv)) {
224 1         2 $self->{'viewIdent'} = $nv;
225             }
226 1         4 return $self->{'viewIdent'};
227             }
228              
229             #==============================================================================
230              
231             =item sub sensor_ident([$newValue])
232              
233             $value = $sensor_ctl->sensor_ident($newValue);
234              
235             Sensor ID.
236              
237             This attribute specifies the sensor to which the data in this packet are applied.
238              
239             =cut
240              
241             sub sensor_ident() {
242 1     1 1 6 my ($self,$nv) = @_;
243 1 50       3 if (defined($nv)) {
244 1         2 $self->{'sensorIdent'} = $nv;
245             }
246 1         4 return $self->{'sensorIdent'};
247             }
248              
249             #==============================================================================
250              
251             =item sub track_mode([$newValue])
252              
253             $value = $sensor_ctl->track_mode($newValue);
254              
255             Track Mode.
256              
257             This attribute specifies which track mode the sensor should use:
258              
259             Off – No tracking will occur.
260              
261             Force Correlate – The sensor processes a portion of the view image, establishes
262             an image pattern, and attempts to keep the seeker pointed at the center of that
263             image pattern. This mode is typically used for Maverick sensors.
264              
265             Scene – The sensor processes a portion of the view image, establishes an image
266             pattern, and attempts to keep the seeker pointed at the center of that image
267             pattern. This mode is typically used for FLIR sensors.
268              
269             Target – The sensor uses contrast tracking to lock to a specific target area.
270              
271             Ship – The sensor uses contrast tracking and adjusts the tracking point so that
272             the weapon strikes close to the water line.
273              
274             Off 0
275             ForceCorrelate 1
276             Scene 2
277             Target 3
278             Ship 4
279             IGDefined3 5
280             IGDefined2 6
281             IGDefined1 7
282              
283             =cut
284              
285             sub track_mode() {
286 1     1 1 3 my ($self,$nv) = @_;
287 1 50       4 if (defined($nv)) {
288 1 50 33     6 if (($nv==0) or ($nv==1) or ($nv==2) or ($nv==3) or ($nv==4) or ($nv==5) or ($nv==6) or ($nv==7)) {
      33        
      0        
      0        
      0        
      0        
      0        
289 1         4 $self->{'trackMode'} = $nv;
290 1         4 $self->{'_bitfields1'} |= ($nv << 5) &0xE0;
291             } else {
292 0         0 carp "track_mode must be 0 (Off), 1 (ForceCorrelate), 2 (Scene), 3 (Target), 4 (Ship), 5 (IGDefined3), 6 (IGDefined2), or 7 (IGDefined1).";
293             }
294             }
295 1         4 return (($self->{'_bitfields1'} & 0xE0) >> 5);
296             }
297              
298             #==============================================================================
299              
300             =item sub track_white_black([$newValue])
301              
302             $value = $sensor_ctl->track_white_black($newValue);
303              
304             Track White/Black.
305              
306             This attribute specifies whether the sensor tracks white (0) or black (1).
307             This, along with the Polarity attribute, controls whether the sensor tracks hot
308             or cold spots.
309              
310             White 0
311             Black 1
312              
313             =cut
314              
315             sub track_white_black() {
316 1     1 1 3 my ($self,$nv) = @_;
317 1 50       5 if (defined($nv)) {
318 1 50 33     17 if (($nv==0) or ($nv==1)) {
319 1         3 $self->{'trackWhiteBlack'} = $nv;
320 1         3 $self->{'_bitfields1'} |= ($nv << 4) &0x10;
321             } else {
322 0         0 carp "track_white_black must be 0 (White), or 1 (Black).";
323             }
324             }
325 1         4 return (($self->{'_bitfields1'} & 0x10) >> 4);
326             }
327              
328             #==============================================================================
329              
330             =item sub automatic_gain_enable([$newValue])
331              
332             $value = $sensor_ctl->automatic_gain_enable($newValue);
333              
334             Automatic Gain.
335              
336             This attribute specifies whether the sensor automatically adjusts the gain
337             value to optimize the brightness and contrast of the sensor display.
338              
339             Disable 0
340             Enable 1
341              
342             =cut
343              
344             sub automatic_gain_enable() {
345 1     1 1 3 my ($self,$nv) = @_;
346 1 50       4 if (defined($nv)) {
347 1 50 33     17 if (($nv==0) or ($nv==1)) {
348 1         3 $self->{'automaticGainEnable'} = $nv;
349 1         2 $self->{'_bitfields1'} |= ($nv << 3) &0x08;
350             } else {
351 0         0 carp "automatic_gain_enable must be 0 (Disable), or 1 (Enable).";
352             }
353             }
354 1         4 return (($self->{'_bitfields1'} & 0x08) >> 3);
355             }
356              
357             #==============================================================================
358              
359             =item sub line_by_line_dropout_enable([$newValue])
360              
361             $value = $sensor_ctl->line_by_line_dropout_enable($newValue);
362              
363             Line-by-Line Dropout Enable.
364              
365             This attribute specifies whether line-by-line dropout is enabled.
366              
367             Disable 0
368             Enable 1
369              
370             =cut
371              
372             sub line_by_line_dropout_enable() {
373 1     1 1 2 my ($self,$nv) = @_;
374 1 50       3 if (defined($nv)) {
375 1 50 33     8 if (($nv==0) or ($nv==1)) {
376 1         8 $self->{'lineByLineDropoutEnable'} = $nv;
377 1         2 $self->{'_bitfields1'} |= ($nv << 2) &0x04;
378             } else {
379 0         0 carp "line_by_line_dropout_enable must be 0 (Disable), or 1 (Enable).";
380             }
381             }
382 1         3 return (($self->{'_bitfields1'} & 0x04) >> 2);
383             }
384              
385             #==============================================================================
386              
387             =item sub polarity([$newValue])
388              
389             $value = $sensor_ctl->polarity($newValue);
390              
391             Polarity.
392              
393             This attribute specifies whether the sensor shows white hot (0) or black hot (1).
394              
395             WhiteHot 0
396             BlackHot 1
397              
398             =cut
399              
400             sub polarity() {
401 1     1 1 3 my ($self,$nv) = @_;
402 1 50       3 if (defined($nv)) {
403 1 50 33     8 if (($nv==0) or ($nv==1)) {
404 1         3 $self->{'polarity'} = $nv;
405 1         3 $self->{'_bitfields1'} |= ($nv << 1) &0x02;
406             } else {
407 0         0 carp "polarity must be 0 (WhiteHot), or 1 (BlackHot).";
408             }
409             }
410 1         3 return (($self->{'_bitfields1'} & 0x02) >> 1);
411             }
412              
413             #==============================================================================
414              
415             =item sub sensor_on_off([$newValue])
416              
417             $value = $sensor_ctl->sensor_on_off($newValue);
418              
419             Sensor On/Off.
420              
421             This attribute specifies whether the sensor is turned on or off.
422              
423             Off 0
424             On 1
425              
426             =cut
427              
428             sub sensor_on_off() {
429 1     1 1 2 my ($self,$nv) = @_;
430 1 50       4 if (defined($nv)) {
431 1 50 33     5 if (($nv==0) or ($nv==1)) {
432 1         3 $self->{'sensorOnOff'} = $nv;
433 1         2 $self->{'_bitfields1'} |= $nv &0x01;
434             } else {
435 0         0 carp "sensor_on_off must be 0 (Off), or 1 (On).";
436             }
437             }
438 1         8 return ($self->{'_bitfields1'} & 0x01);
439             }
440              
441             #==============================================================================
442              
443             =item sub response_type([$newValue])
444              
445             $value = $sensor_ctl->response_type($newValue);
446              
447             Response Type.
448              
449             This attribute specifies whether the IG should return a Sensor Response packet
450             or a Sensor Extended Response packet.
451              
452             NormalSRT 0
453             ExtendedSRT 1
454              
455             =cut
456              
457             sub response_type() {
458 1     1 1 2 my ($self,$nv) = @_;
459 1 50       4 if (defined($nv)) {
460 1 50 33     6 if (($nv==0) or ($nv==1)) {
461 1         2 $self->{'responseType'} = $nv;
462 1         2 $self->{'_bitfields2'} |= $nv &0x01;
463             } else {
464 0         0 carp "response_type must be 0 (NormalSRT), or 1 (ExtendedSRT).";
465             }
466             }
467 1         3 return ($self->{'_bitfields2'} & 0x01);
468             }
469              
470             #==============================================================================
471              
472             =item sub gain([$newValue])
473              
474             $value = $sensor_ctl->gain($newValue);
475              
476             Gain.
477              
478             This attribute specifies the contrast for the sensor display.
479              
480             =cut
481              
482             sub gain() {
483 1     1 1 6 my ($self,$nv) = @_;
484 1 50       16 if (defined($nv)) {
485 1         3 $self->{'gain'} = $nv;
486             }
487 1         5 return $self->{'gain'};
488             }
489              
490             #==============================================================================
491              
492             =item sub level([$newValue])
493              
494             $value = $sensor_ctl->level($newValue);
495              
496             Level.
497              
498             This attribute specifies the brightness for the sensor display.
499              
500             =cut
501              
502             sub level() {
503 1     1 1 5 my ($self,$nv) = @_;
504 1 50       4 if (defined($nv)) {
505 1         3 $self->{'level'} = $nv;
506             }
507 1         3 return $self->{'level'};
508             }
509              
510             #==============================================================================
511              
512             =item sub ac_coupling([$newValue])
513              
514             $value = $sensor_ctl->ac_coupling($newValue);
515              
516             AC Coupling.
517              
518             This attribute specifies the AC coupling decay constant for the sensor display.
519              
520             =cut
521              
522             sub ac_coupling() {
523 1     1 1 5 my ($self,$nv) = @_;
524 1 50       4 if (defined($nv)) {
525 1         2 $self->{'acCoupling'} = $nv;
526             }
527 1         3 return $self->{'acCoupling'};
528             }
529              
530             #==============================================================================
531              
532             =item sub noise([$newValue])
533              
534             $value = $sensor_ctl->noise($newValue);
535              
536             Noise.
537              
538             This attribute specifies the amount of detector noise for the sensor.
539              
540             =cut
541              
542             sub noise() {
543 1     1 1 6 my ($self,$nv) = @_;
544 1 50       5 if (defined($nv)) {
545 1         2 $self->{'noise'} = $nv;
546             }
547 1         4 return $self->{'noise'};
548             }
549              
550             #==========================================================================
551              
552             =item sub pack()
553              
554             $value = $sensor_ctl->pack();
555              
556             Returns the packed data packet.
557              
558             =cut
559              
560             sub pack($) {
561 1     1 1 5 my $self = shift ;
562            
563 1         9 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
564             $self->{'packetType'},
565             $self->{'packetSize'},
566             $self->{'viewIdent'},
567             $self->{'sensorIdent'},
568             $self->{'_bitfields1'}, # Includes bitfields trackMode, TrackWhtBlk, automaticGainEnable, lineByLineDropoutEnable, polarity, and sensorOnOff.
569             $self->{'_bitfields2'}, # Includes bitfields unused30, and responseType.
570             $self->{'_unused31'},
571             $self->{'gain'},
572             $self->{'level'},
573             $self->{'acCoupling'},
574             $self->{'noise'},
575             );
576              
577 1         4 return $self->{'_Buffer'};
578             }
579              
580             #==========================================================================
581              
582             =item sub unpack()
583              
584             $value = $sensor_ctl->unpack();
585              
586             Unpacks the packed data packet.
587              
588             =cut
589              
590             sub unpack($) {
591 0     0 1   my $self = shift @_;
592            
593 0 0         if (@_) {
594 0           $self->{'_Buffer'} = shift @_;
595             }
596 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
597 0           $self->{'packetType'} = $a;
598 0           $self->{'packetSize'} = $b;
599 0           $self->{'viewIdent'} = $c;
600 0           $self->{'sensorIdent'} = $d;
601 0           $self->{'_bitfields1'} = $e; # Includes bitfields trackMode, TrackWhtBlk, automaticGainEnable, lineByLineDropoutEnable, polarity, and sensorOnOff.
602 0           $self->{'_bitfields2'} = $f; # Includes bitfields unused30, and responseType.
603 0           $self->{'_unused31'} = $g;
604 0           $self->{'gain'} = $h;
605 0           $self->{'level'} = $i;
606 0           $self->{'acCoupling'} = $j;
607 0           $self->{'noise'} = $k;
608              
609 0           $self->{'trackMode'} = $self->track_mode();
610 0           $self->{'trackWhiteBlack'} = $self->track_white_black();
611 0           $self->{'automaticGainEnable'} = $self->automatic_gain_enable();
612 0           $self->{'lineByLineDropoutEnable'} = $self->line_by_line_dropout_enable();
613 0           $self->{'polarity'} = $self->polarity();
614 0           $self->{'sensorOnOff'} = $self->sensor_on_off();
615 0           $self->{'responseType'} = $self->response_type();
616              
617 0           return $self->{'_Buffer'};
618             }
619              
620             #==========================================================================
621              
622             =item sub byte_swap()
623              
624             $obj_name->byte_swap();
625              
626             Byte swaps the packed data packet.
627              
628             =cut
629              
630             sub byte_swap($) {
631 0     0 1   my $self = shift @_;
632            
633 0 0         if (@_) {
634 0           $self->{'_Buffer'} = shift @_;
635             } else {
636 0           $self->pack();
637             }
638 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
639              
640 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k);
641 0           $self->unpack();
642              
643 0           return $self->{'_Buffer'};
644             }
645              
646             1;
647             __END__