Perl Pastebin - Nopaste - Paste - easy sharing of text and codes

Posted by F2 on Fri 3rd Feb 01:46 (modification of post by F2 view diff)
diff | download | new post

  1. use strict;
  2. my @arr = split(/\s+/,"50 00 9F 11 00 28 82 48 21 84 BC 00 01 02 01 00 09 01 38 00 23 05 08 01 01 02 00 00 18 00 50 05 00 00 00 00 00 00 00 00 02 00 0C FE CE 00 0F 00 FD FF 2D 00 00 00 00 00 04 01 0C FE");
  3. my @hexData;
  4. my $i=0;
  5. foreach my $elem(@arr){
  6.         $hexData[$i]=hex($elem);
  7.         $i++;
  8. }
  9. my $data= pack ('C*', @hexData);
  10.  
  11. my $obj;
  12. $obj=parse119F($data);
  13. my $ts = $obj->{timestamp};
  14. print $ts;
  15.  
  16. ## End of scope of main program.
  17.  
  18.  
  19. ## -- Subroutines defined below.
  20.  
  21. sub getTimestamp{
  22.         my $data1=shift;
  23.         my ($length,$lc,$ts);
  24.         my $len=length($data1);
  25.         $len=$len-12;
  26.         ($length, $lc, $ts, $data1)=unpack("v v a8 a$len",$data1);
  27.         if($length eq ($len+12)){
  28.                 my @timestamp=unpack("v v v v",$ts);
  29.                 my $ret=($timestamp[3]*2**32+$timestamp[2]*2**16+$timestamp[1]+($timestamp[0]%1536)/1536)*(0.00125);
  30.                 return $ret;
  31.         }
  32.         else{
  33.                 return -1;
  34.         }
  35. }
  36.  
  37. sub parse119F{
  38.         my $data=shift;
  39.         my $len=length($data);
  40.         my ($obj,$tmp,$tmp1,$tmp2,$i,$j);
  41.         $obj->{timestamp}=getTimestamp($data);
  42.         $len=$len-12;
  43.         ($tmp,$data)=unpack("a12 a$len",$data);
  44.         $len=$len-8;
  45.    ($obj->{SubPktHeader},$obj->{SlotNo},$obj->{TxfrReason},$obj->{Rate},$tmp,$tmp1,$tmp2,$data)=unpack("V v C C C C v C C a$len",$data);
  46.         $len=$len-12;
  47. return $obj;
  48. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


I'm Human
Remember me



Captcha required for posting