File Coverage

blib/lib/Device/IRU_GE.pm
Criterion Covered Total %
statement 15 308 4.8
branch 0 54 0.0
condition 0 18 0.0
subroutine 5 31 16.1
pod 6 18 33.3
total 26 429 6.0


line stmt bran cond sub pod time code
1             package Device::IRU_GE;
2              
3 1     1   37770 use 5.008008;
  1         4  
  1         119  
4             #use strict;
5             #use warnings;
6              
7             #-#use Win32::SerialPort qw(:STAT 0.19 );
8 1     1   1446 use Device::SerialPort qw( :PARAM :STAT 0.07 );
  1         80780  
  1         545  
9              
10 1     1   1297 use Time::HiRes qw(sleep gettimeofday);
  1         2345  
  1         6  
11 1     1   1602 use Data::Dumper;
  1         12095  
  1         93  
12 1     1   73595 use Math::Trig qw(asin rad2deg pi);
  1         45773  
  1         4606  
13              
14             require Exporter;
15             our @ISA = qw(Exporter);
16              
17             our $VERSION = '0.92';
18              
19             our @EXPORT_OK = qw();
20             our @EXPORT = qw();
21              
22             # --- Conversion factors ---
23             my $LL_cnv = pi / 2**30;
24             my $HDG_cnv = (360/6400) / 100;
25              
26             # - - - - - - - - - - - - - - - -
27             sub new
28             {
29 0     0 1   my $caller = shift @_;
30              
31             # In case someone wants to sub-class
32 0           my $caller_is_obj = ref($caller);
33 0   0       my $class = $caller_is_obj || $caller;
34              
35             # Passing reference or hash
36 0           my %arg_hsh;
37 0 0         if ( ref($_[0]) eq "HASH" ) { %arg_hsh = %{ shift @_ } }
  0            
  0            
38 0           else { %arg_hsh = @_ }
39              
40 0   0       my $port = $arg_hsh{'port'} || "COM3";
41            
42 0   0       my $port_obj = new Device::SerialPort ($port) || die "Can't open $port: $^E\n";
43             #-#my $port_obj = new Win32::SerialPort ($port) || die "Can't open $port: $! $^E\n";
44              
45 0   0       my $baudrate = $arg_hsh{baudrate} || 19200;
46            
47 0   0       my $parity = $arg_hsh{parity} || "none";
48 0   0       my $databits = $arg_hsh{databits} || 8;
49 0   0       my $stopbits = $arg_hsh{stopbits} || 1;
50              
51              
52             # After new, must check for failure
53 0           $port_obj->baudrate($baudrate);
54 0           $port_obj->parity($parity);
55 0           $port_obj->databits($databits);
56 0           $port_obj->stopbits($stopbits);
57              
58             #$port_obj->handshake('rts');
59              
60 0 0         if ( $^O =~ /MS/ )
61             {
62 0           $port_obj->read_interval(500); # max time between read char (milliseconds)
63 0           $port_obj->read_const_time(500); # Functions as a timeout
64             }
65            
66             #-# $port_obj->read_interval(1); # max time between read char (milliseconds) Not in Device::SerialPort
67 0           $port_obj->read_const_time(10000); # total = (avg * bytes) + const THIS IS NECESSARY!!!!
68            
69             #$port_obj->handshake("rts");
70             #$port_obj->buffers(4096, 4096);
71            
72 0 0         $port_obj->write_settings || undef $port_obj;
73              
74 0 0         unless ($port_obj) { die "Can't change Device_Control_Block: $^E\n"; }
  0            
75              
76 0   0       my ($BlockingFlags, $InBytes, $OutBytes, $LatchErrorFlags) = $port_obj->status
77             || warn "could not get port status\n";
78              
79 0 0         if ($BlockingFlags)
80             {
81             #warn "Port is blocked $BlockingFlags, $InBytes, $OutBytes, $LatchErrorFlags\n";
82             }
83              
84 0 0         if ($BlockingFlags & BM_fCtsHold) { warn "Waiting for CTS"; }
  0            
85 0 0         if ($LatchErrorFlags & CE_FRAME) { warn "Framing Error"; }
  0            
86              
87 0           $port_obj->purge_all(); # these don't seem to work but try anyway.
88 0           $port_obj->purge_rx();
89              
90             # The object data structure
91 0           my $self = bless {
92             'arg_hsh' => { %arg_hsh },
93             'fh' => $arg_hsh{fh},
94             'continuous_mode' => $arg_hsh{'continuous_mode'},
95             'port_obj' => $port_obj,
96             'cmd' => '',
97             'rsp' => [],
98             'factor' => { %factor }
99             }, $class;
100 0           return $self;
101             }
102              
103             #-----------------------------------------------------
104             # Test using serial plug
105             #-----------------------------------------------------
106             sub plug_test
107             {
108 0     0 1   my $self = shift @_;
109             #my $cmd = shift @_;
110              
111 0           my $cmd = "Round Trip Worked\n";
112            
113 0           my $cnt_out = $self->{'port_obj'}->write($cmd);
114 0 0         unless ($cnt_out) { warn "write failed\n" };
  0            
115              
116 0           my $cmd_len = bytes::length($cmd);
117 0 0         if ( $cnt_out != $cmd_len ) { die "write incomplete only wrote $cnt_out should have written $cmd_len\n"};
  0            
118              
119 0           sleep (1); # Necessary?
120              
121             # ------ Send to unit -----
122 0           my $length = length($cmd);
123 0           my ($count_in, $str_read) = $self->{'port_obj'}->read($length);
124 0 0         if ( $count_in == 0) { warn "Time out on read for $caller\n"; }
  0            
125              
126             #my $char_lst = join "", unpack("C*",$str_read);
127             #print "$length ::: $count_in |$char_lst|$str_read|\n";
128              
129 0           return $str_read;
130             }
131              
132              
133             #----------------------------------------------------------------------
134             sub get_test_sequence
135             {
136 0     0 0   my $self = shift @_;
137              
138             # Word 1: Header = 0009h
139             # Word 2: Data word 1 to be echoed
140             # Word 3: Data word 2 to be echoed
141             # Word 4: Data word 3 to be echoed
142             # Word 5: Data word 4 to be echoed
143             # Word 6: Data word 5 to be echoed
144             # Word 7: Data word 6 to be echoed
145             # Word 8: 16-bit checksum for this message
146              
147 0           my @lst = _transact($self,['0x0009','72','101','76','76','79','33']);
148              
149 0           return @lst;
150             }
151              
152             #----------------------------------------------------------------------
153             sub get_unit_partno
154             {
155 0     0 0   my $self = shift @_;
156             #my @lst = _transact($self,['0x0050','00','00','00','00','00','00']);
157 0           my @lst = _transact($self,['0xF150', '0', '0', '0', '0', '0' ,'0']);
158              
159 0           return @lst;
160             }
161              
162              
163              
164             #----------------------------------------------------------------------
165             sub get_temperature
166             {
167 0     0 0   my $self = shift @_;
168              
169             #Byte 1 Header byte = 0x07
170             #Byte 2 Temp MSB
171             #Byte 3 Temp LSB
172             #Byte 4 TimerTicks MSB
173             #Byte 5 TimerTicks LSB
174             #Byte 6 Checksum MSB
175             #Byte 7 Checksum LSB
176              
177 0           my @lst = _transact($self,['0x07'],7);
178             #shift @lst;
179 0           return @lst;
180              
181             }
182              
183             #----------------------------------------------------------------------
184             sub get_lat_lon
185             {
186             # lat and lon are hardwired :( so I find out.
187            
188 0     0 0   my $self = shift @_;
189              
190 0           my @lst = _transact($self,['0x002A', '0', '0', '0', '0', '0' ,'0']);
191              
192             #Message format from the IRU:
193             #Word 0: Latitude LSW
194             #Word 1: Longitude LSW
195             #Word 2: Grid Heading
196             #Word 3: True Heading
197             #Word 4: Sin of Pitch
198             #Word 5: Sin of Roll
199              
200 0           @w_lst = _conv_short(@lst);
201            
202 0           my %hsh;
203 0           $hsh{'lat'} = $w_lst[0];
204 0           $hsh{'lng'} = $w_lst[1];
205 0           $hsh{'hdg_grid'} = $w_lst[2]/100;
206 0           $hsh{'hdg_true'} = $w_lst[3]/100;
207 0           $hsh{'pitch'} = sprintf( "%5.2f", rad2deg asin($w_lst[4]/10000) );
208 0           $hsh{'roll'} = sprintf( "%5.2f", rad2deg asin($w_lst[5]/10000) );
209              
210             #print Dumper \%hsh;
211 0           return \%hsh;
212             }
213              
214             #---- Reset ---------
215             sub set_01
216             {
217 0     0 1   my $self = shift @_;
218              
219 0           my @lst = _transact($self,['0x0001', '0', '0', '0', '0', '0' ,'0']);
220              
221 0           sleep 180;
222            
223 0           return @lst;
224             }
225              
226             #------ BIT and Reset ------
227             sub set_03
228             {
229 0     0 0   my $self = shift @_;
230              
231 0           my @lst = _transact($self,['0x0003', '0', '0', '0', '0', '0' ,'0']);
232              
233 0           return @lst;
234             }
235              
236             #----------------------------------------------------------------------
237             sub set_04
238             {
239 0     0 0   my $self = shift @_;
240              
241 0           my @lst = _transact($self,['0x0004', '0', '0', '0', '0', '0' ,'0']);
242              
243 0           return @lst;
244             }
245              
246             #----------------------------------------------------------------------
247             sub get_0B
248             {
249 0     0 0   my $self = shift @_;
250              
251 0           my @lst = _transact($self,['0x000B', '0', '0', '0', '0', '0' ,'0']);
252              
253             #Message format from the IRU:
254             # Words 2-3: Latitude
255             # Words 4-5: Longitude
256             # Word 6: True Heading
257             # Word 7: Malfunction BIT (Least Significant Byte (LSByte))
258             # Word 7: IRU Mode/GPS Status/Moving (Most Significant Byte (MSByte))
259              
260 0           my ($lat,$long) = _conv_long(@lst[0..7]);
261 0           my ($hdg_true) = _conv_short(@lst[8..9]);
262            
263 0           my %hsh;
264 0           $hsh{'lat'} = rad2deg ($lat * $LL_cnv) ;
265 0           $hsh{'lng'} = rad2deg ($long * $LL_cnv);
266 0           $hsh{'hdg_true'} = $hdg_true / 100;
267            
268 0           $hsh{'bit'} = unpack("B*",$lst[10]);
269 0           $hsh{'iru_mode'} = unpack("B*",$lst[11]);
270              
271             #print ">>> $hsh{'bit'} $hsh{'iru_mode'} $hsh{'hdg_true'}\n";
272             #print Dumper \%hsh;
273              
274 0           return \%hsh;
275             }
276              
277              
278             #----------------------------------------------------------------------
279             sub get_0F
280             {
281 0     0 1   my $self = shift @_;
282 0           my $mode = shift @_;
283            
284 0           my @lst = _transact($self,['0x000F', '0', '0', '0', '0', '0' ,'0']);
285              
286 0           my $len = scalar @lst;
287 0 0         if ( $len < 1 ) { warn "Status not returned"; return ''; }
  0            
  0            
288            
289             # 2: Box Azimuth alignment
290             # 3: Gyrocompass residual
291             # 4: Gyrocompass state
292             # 5: Gyrocompass time remaining
293             # 6: Moving status
294             # 7: 0000h
295 0           @lst = _conv_short(@lst[0..15]); # 12??
296              
297             ### print Dumper \@lst;
298            
299 0           my @mode_lst;
300 0           $mode_lst[0] = 'CHECK_IF_VALID_TO_GC';
301 0           $mode_lst[1] = 'FIRST_SETTLE_AT_0';
302 0           $mode_lst[2] = 'FIRST_COLLECT_DATA_AT_0';
303 0           $mode_lst[3] = 'MOVE_0_TO_180';
304 0           $mode_lst[4] = 'STOP_AT_180';
305 0           $mode_lst[5] = 'SETTLE_AT_180';
306 0           $mode_lst[6] = 'FIRST_COLLECT_DATA_AT_180';
307 0           $mode_lst[7] = 'SECOND_COLLECT_DATA_AT_180';
308 0           $mode_lst[8] = 'MOVE_FROM_180_TO_0';
309 0           $mode_lst[9] = 'STOP_AT_0';
310 0           $mode_lst[10] = 'SETTLE_AT_0';
311 0           $mode_lst[11] = 'SECOND_COLLECT_DATA_AT_0';
312 0           $mode_lst[12] = 'COMPUTE_FIRST_HEADING_EST';
313 0           $mode_lst[13] = 'GYRO_COMPASS_FAIL';
314 0           $mode_lst[14] = 'END_GYRO_COMPASS';
315 0           $mode_lst[15] = 'RETRY_MOVE_0_TO_180';
316 0           $mode_lst[16] = 'RETRY_MOVE_180_TO_0';
317 0           $mode_lst[17] = 'MOVE_TO_0_NOW';
318 0           $mode_lst[18] = 'RESTART_GYRO_COMPASS';
319 0           $mode_lst[19] = 'ESTIMATE_R_GYRO_BIAS';
320 0           $mode_lst[20] = 'ITERATE_HEADING_ESTIMATE';
321              
322 0           my %hsh;
323 0           $hsh{'gc_time'} = sprintf("%3.0f",$lst[3] / 61);
324 0           $hsh{'gc_mode_num'} = $lst[2];
325 0           $hsh{'gc_mode_str'} = $mode_lst[$lst[2]];
326 0           $hsh{'box_az_align'} = $lst[0];
327 0           $hsh{'residual'} = $lst[1];
328 0           $hsh{'move_stat'} = $lst[4];
329            
330 0           $hsh{'move_stat_str'} = "Not Moving";
331 0 0         if ($hsh{'move_stat'} ) { $hsh{'move_stat_str'} = "Moving" }
  0            
332            
333 0           $hsh{'len'} = $len;
334            
335 0           return \%hsh;
336             }
337              
338             #---- Latitude and Longitude, True Heading, Grid Heading, Sin of Pitch and Sin of Roll ---
339             # Note: The checksum value gets screwed up on this call if there is any movement during aling
340             # The values appear to be correct the checksum is just wrong and requires a power cycle use get_62 if possible
341             sub get_2A
342             {
343 0     0 0   my $self = shift @_;
344              
345 0           my @lst = _transact($self,['0x002A', '0', '0', '0', '0', '0' ,'0']);
346              
347             #Message format from the IRU:
348             #Word 0: Latitude LSW
349             #Word 1: Longitude LSW
350             #Word 2: Grid Heading
351             #Word 3: True Heading
352             #Word 4: Sin of Pitch
353             #Word 5: Sin of Roll
354              
355 0           @w_lst = _conv_short(@lst);
356            
357 0           my %hsh;
358 0           $hsh{'lat'} = $w_lst[0];
359 0           $hsh{'lng'} = $w_lst[1];
360 0           $hsh{'hdg_grid'} = $w_lst[2]/100;
361 0           $hsh{'hdg_true'} = $w_lst[3]/100;
362 0           $hsh{'pitch'} = sprintf( "%5.3f", rad2deg asin($w_lst[4]/10000) );
363 0           $hsh{'roll'} = sprintf( "%5.3f", rad2deg asin($w_lst[5]/10000) );
364              
365 0           return \%hsh;
366             }
367              
368             #----------------------------------------------------------------------
369             sub get_2B
370             {
371 0     0 0   my $self = shift @_;
372              
373 0           my @lst = _transact($self,['0x002B', '0', '0', '0', '0', '0' ,'0']);
374              
375             #Message format from the IRU:
376             # Words 2-3: Latitude
377             # Words 4-5: Longitude
378             # Word 6: True Heading
379             # Word 7: Malfunction BIT (Least Significant Byte (LSByte))
380             # Word 7: IRU Mode/GPS Status/Moving (Most Significant Byte (MSByte))
381              
382 0           my ($lat,$hdg) = _conv_long(@lst[0..7]);
383 0           my ($hdg_var,$hdg_var_est) = _conv_short(@lst[8..11]);
384            
385 0           my %hsh;
386 0           $hsh{'lat'} = rad2deg ($lat * $LL_cnv) ;
387 0           $hsh{'hdg_true'} = $hdg * $HDG_cnv;
388              
389 0           $hsh{'hdg_var'} = rad2deg ( $hdg_var / (100 * 1000) );
390 0           $hsh{'hdg_var_est'} = rad2deg ( $hdg_var_est/ (100 * 1000) );
391            
392 0           print Dumper \%hsh;
393              
394 0           return @lst;
395             }
396              
397             #----------------------------------------------------------------------
398             sub set_5D
399             {
400 0     0 1   my $self = shift @_;
401 0           my $mode = shift @_;
402              
403             # 3 – Gyrocompass Mode (GC)
404             # 6 – Navigation Mode (NAV)
405             # 8 – In-Vehicle Calibration Mode (IVC)
406             # 9 – Base Motion Compensated Coarse Align Mode (BMCCOARSE)
407             # 12 – Fast Base Motion Compensated Coarse Align Mode (FASTBMCCOARSE)
408            
409 0 0         unless ( $mode =~/(3|6|8|9|12)/ ) { return 0 }
  0            
410              
411 0           my @lst = _transact($self,['0x005D', $mode, '0', '0', '0', '0' ,'0']);
412              
413             #my ($lat,$hdg) = _conv_long(@lst[0..7]);
414             #my ($hdg_var,$hdg_var_est) = _conv_short(@lst[8..11]);
415            
416 0           return @lst;
417             }
418              
419             #---- Heading and Attitude -----------------
420             sub get_62
421             {
422 0     0 1   my $self = shift @_;
423              
424 0           my @lst = _transact($self,['0x062', '0', '0', '0', '0', '0' ,'0']);
425              
426             #Message format from the IRU:
427             #Word 0: Grid Heading
428             #Word 1: True Heading
429             #Word 2: Pitch
430             #Word 3: Roll
431              
432 0           @w_lst = _conv_short(@lst);
433            
434 0           my %hsh;
435 0           $hsh{'hdg_grid'} = $w_lst[0]/100;
436 0           $hsh{'hdg_true'} = $w_lst[1]/100;
437 0           $hsh{'pitch'} = $w_lst[2]/100;
438 0           $hsh{'roll'} = $w_lst[3]/100;
439              
440 0           return \%hsh;
441             }
442              
443             #----------------------------------------------------------------------
444             sub _transact
445             {
446 0     0     my $self = shift @_;
447 0           my @cmd_lst = @{ shift @_ };
  0            
448              
449 0           my $str = join '', @cmd_lst;
450 0 0         if ( grep { !/\d+/ } $str ){ die "Commands must be numeric" }
  0            
  0            
451            
452 0           $cmd_lst[0] = hex( $cmd_lst[0] ); # Command header is given in hex
453              
454 0           my $word_cmd; my $checksum;
455 0           foreach my $cmd (@cmd_lst)
456             {
457 0           my $bn = pack("n",$cmd);
458 0           $word_cmd .= $bn;
459 0           $checksum ^= $bn;
460             }
461            
462 0           $word_cmd .= $checksum;
463            
464 0           my $cnt_out = $self->{'port_obj'}->write($word_cmd);
465 0 0         unless ($cnt_out) { warn "write failed\n" };
  0            
466              
467 0           my $cmd_len = bytes::length($word_cmd);
468 0 0         if ( $cnt_out != $cmd_len ) { die "write incomplete only wrote $cnt_out should have written $cmd_len\n"};
  0            
469              
470 0           sleep (.20); # Necessary?
471              
472 0           my $caller = (caller(1) )[3];
473 0 0         unless ( $caller =~ /get/ ) { return 1; } # return if this was a set command, continue if we are getting something
  0            
474              
475             #$self->{'port_obj'}->read_char_time(0); # don't wait for each character
476             #$self->{'port_obj'}->read_const_time(900); # 1 second per unfulfilled "read" call
477              
478             # ------ Send to unit -----
479 0           my ($count_in, $str_read) = $self->{'port_obj'}->read(16);
480 0 0         if ( $count_in == 0) { warn "Time out on read for $caller\n"; }
  0            
481              
482             # If we are not requesting data then just return.
483            
484 0           my $cmd_rtn = unpack("s",$str_read);
485 0 0         if ( $cmd_rtn != $cmd_lst[0] ) { warn "Return header does not match command sent for $caller $cmd_lst[0] != $cmd_rtn\n" }
  0            
486            
487             # -------- Calculate checksum ----------
488 0           my @wrd_lst = $str_read =~ /.{2}/g;
489            
490 0           my $cksum_rtn = pop @wrd_lst;
491 0           my $cksum_rtn_s = unpack("s", $cksum_rtn);
492            
493 0           my $cksum_clc;
494 0           foreach ( @wrd_lst ) { $cksum_clc ^= $_; }
  0            
495              
496 0           my $cksum_clc_s = unpack("s",$cksum_clc);
497 0 0         if ( $cksum_clc_s != $cksum_rtn_s ) { warn "CHCKSUM FAILED (calc=rtn) $cksum_clc_s != $cksum_rtn_s" }
  0            
498              
499             # --------------------------------------
500             #_debug($str_read);
501              
502 0           my @byte_lst = split(//, substr($str_read,2,12,) ); # Remove header
503 0           return @byte_lst;
504             }
505              
506             sub err_clr
507             {
508 0     0 0   print "alarm clock restart\n";
509 0           die;
510             }
511              
512             sub clear_buf
513             {
514              
515 0     0 0   my $self = shift;
516              
517 0           $self->{'port_obj'}->purge_all(); # doesn't seem to work but no harm
518              
519 0           ($count_in, $string_read) = $self->{'port_obj'}->read($rsp_bytes);
520              
521 0           return;
522             }
523              
524             sub close
525             {
526 0     0 0   $self = shift @_;
527              
528 0           $self->{port_obj}->purge_all();
529 0           $self->{port_obj}->purge_rx();
530 0           $self->{port_obj}->close();
531              
532             }
533              
534             #----------------------------------------------------------------------
535             sub _send_cmd
536             {
537 0     0     my $self = shift;
538 0           my $cmd_str = shift @_;
539 0           my $rsp_bytes = shift @_;
540              
541             ####print unpack("B*",$byte_cmd) . " size incoming $rsp_bytes \n";
542              
543 0           my $count_out = $self->{'port_obj'}->write($cmd_str);
544              
545 0 0         unless ($count_out) { warn "write failed\n" };
  0            
546              
547 0           my $cmd_len = length($cmd_str);
548 0 0         if ( $count_out != $cmd_len ) { warn "write incomplete only wrote $count_out should have written $cmd_len\n"};
  0            
549              
550 0           return 1;
551             }
552             #----------------------------------------------------------------------
553             sub _read_rsp
554             {
555              
556 0     0     my $self = shift;
557 0           my $rsp_bytes = shift @_;
558              
559 0           my ($count_in, $string_read) = $self->{'port_obj'}->read($rsp_bytes);
560              
561 0           my ($tod_sec, $tod_usec) = gettimeofday();
562 0           $self->{'tod_sec'} = $tod_sec;
563 0           $self->{'tod_usec'} = $tod_usec;
564              
565 0           my $format = "Cn*";
566              
567 0           @lst = unpack($format,$string_read);
568              
569             # Calculate checksum and add signedness (perl needs a new pack format)
570 0           my $cksum;
571 0           foreach my $v ( @lst[0..$#lst-1] )
572             {
573 0           $cksum += $v;
574 0 0         if ( $v > 32767 ) { $v = $v - 65536; }
  0            
575             }
576              
577 0           $cksum = unpack("n",pack("n",$cksum));
578              
579 0 0         unless ( $cksum == $lst[$#lst] )
580             {
581 0           print "# checksum did not check $cksum $lst[$#lst]\n";
582              
583 0           $self->clear_buf();
584 0           @lst = ();
585             }
586              
587 0 0         if ( $lst[$#lst-1] < 0 ) { $lst[$#lst-1] = $lst[$#lst-1] + 65536; } #ssshhh....
  0            
588              
589 0           return @lst;
590             }
591              
592             sub _debug
593             {
594 0     0     my $string = shift;
595              
596 0           @chars = split(//, $string);
597              
598 0           print "----------------------------------------\n";
599              
600             #my $hdg = shift @chars;
601             #print unpack("B8",$hdg) . " " . unpack("H*",$hdg) . "\n";
602              
603 0           my $i;
604 0           foreach (@chars)
605             {
606 0           $end = " ";
607 0 0         if ( $i++ % 2 ) { $end = "\n"; }
  0            
608 0           print unpack("B8",$_) . $end;
609             }
610              
611 0           foreach (@chars)
612             {
613 0           $end = " ";
614 0 0         if ( $i++ % 2 ) { $end = "\n"; }
  0            
615 0           print unpack("C*",$_) . $end;
616             }
617            
618             # Words .... ... .... .... ....
619 0           print "----\n";
620              
621 0           my @b_lst = _conv_long(@chars);
622 0           print Dumper \@b_lst;
623             }
624              
625             # - - - - - - - - - - - - - - - - - - -
626             sub _conv_long
627             {
628 0     0     my @b_lst = @_;
629              
630 0           my @l_lst;
631 0           for ( my $i=0; $i<=$#b_lst; $i = $i + 4 )
632             {
633 0           push @l_lst, unpack( "l",$b_lst[$i+2] . $b_lst[$i+3] . $b_lst[$i] . $b_lst[$i+1] );
634             }
635              
636 0           return @l_lst;
637             }
638              
639             # - - - - - - - - - - - - - - - - - - -
640             sub _conv_short
641             {
642 0     0     my @b_lst = @_;
643              
644 0           my @l_lst;
645 0           for ( my $i=0; $i<=$#b_lst; $i = $i + 2 )
646             {
647 0           push @l_lst, unpack("s",$b_lst[$i] . $b_lst[$i+1]);
648             }
649              
650 0           return @l_lst;
651             }
652              
653             # - - - - - - - - - - - - - - - - - - -
654             sub _conv_hex
655             {
656 0     0     my @b_lst = @_;
657              
658 0           my @h_lst;
659 0           for ( my $i=0; $i<=$#b_lst; $i++ )
660             {
661 0           push @h_lst, unpack("H",$b_lst[$i]);
662             }
663              
664 0           return @h_lst;
665             }
666              
667              
668             # - - - - - - - - - - - - - - - - - - -
669             sub _get_cmd_params
670             {
671 0     0     my $self = shift;
672 0           my $cmd = shift;
673              
674 0           my %param = ( '0x02'=>{ 'cmd_lst'=>[ '0x02' ],
675             'rsp_bytes'=>23 },
676             '0x03'=>{ 'cmd_lst'=>[ '0x03' ],
677             'rsp_bytes'=>23 },
678             '0x07'=>{ 'cmd_lst'=>[ '0x07' ],
679             'rsp_bytes'=>7 }
680             );
681              
682 0           my $cmd_str;
683              
684 0           foreach my $cmd_byte ( @{ $param{$cmd}->{'cmd_lst'} } ) { $cmd_str = pack("C",hex($cmd_byte) ); }
  0            
  0            
685              
686 0           $param{$cmd}->{cmd_str} = $cmd_str;
687              
688 0           return %{ $param{$cmd} };
  0            
689             }
690              
691             1;
692              
693             __END__