BayEOS-PHP
 All Data Structures Namespaces Files Functions Variables Pages
dumpParser.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3 require_once 'BayEOSGatewayClient.php';
4 
5 
6 
7 $options=array();
8 
9 function die_usage(){
10  die("Usage: dumpParserExtractor.php [-o bin|text] [-s YYYY-MM-DD] [-e YYYY-MM-DD] [-k 110] dumpfile\n");
11 }
12 
13 if(count($argv)<2)
14  die_usage();
15 
16 for($i=1;$i<count($argv);$i++){
17  if(preg_match('/-[tsoekh]/',$argv[$i])){
18  if($argv[$i]=='-h') die_usage();
19  $key=$argv[$i];
20  $i++;
21  $value=$argv[$i];
22  $options[$key]=$value;
23  } else
24  $file=$argv[$i];
25 }
26 if(! isset($options['-s'])) $options['-s']="2000-01-01";
27 if(! isset($options['-e'])) $options['-e']=date('Y-m-d',time()+24*3600);
28 if(! isset($options['-k'])) $options['-k']="110";
29 if(! isset($options['-o'])) $options['-o']="";
30 
31 $from=DateTime::createFromFormat('Y-m-d H:i:s P',$options['-s'].' 00:00:00 +01:00');
32 $until=DateTime::createFromFormat('Y-m-d H:i:s P',$options['-e'].' 00:00:00 +01:00');
33 $min_date= DateTime::createFromFormat('Y-m-d H:i:s P','2000-01-01 00:00:00 +00:00');
34 $ref_date= DateTime::createFromFormat('Y-m-d H:i:s P','2000-01-01 00:00:00 +00:00');
35 $min=$from->format('U')-$ref_date->format('U');
36 $max=$until->format('U')-$ref_date->format('U');
37 
38 
39 if(! is_readable($file))
40  die("File $file not readable\n");
41 $fp=fopen($file,"r");
42 $fsize=filesize($file);
43 if(isset($options['-t'])) $t_shift=1*$options['-t'];
44 else $t_shift=0;
45 
46 $sig='';
47 for($i=0;$i<strlen($options['-s']);$i++){
48  $sig.=pack("C",(1*substr($options['-s'],$i,1)));
49 }
50 
51 $pos=0;
54 while(! feof($fp)){
55  //read timestamp, length and bayeosframe
56  $ts_bin=fread($fp,4);
57  $ts=BayEOSType::unpackUINT32($ts_bin);
58  $last_date=date('Y-m-d h:i:s',$ts+$ref_date->format('U'));
59  $length_bin=fread($fp,1);
60  $length=BayEOSType::unpackUINT8($length_bin);
61  if($length) $bayeosframe=fread($fp,$length);
62  else $bayeosframe='';
63  $pos+=5+$length;
64  if($ts>$min && $ts<$max && $bayeosframe){
65  if($options['-o']=='text'){
66  $res=BayEOS::parseFrame($bayeosframe,$ts+$ref_date->format('U'));
67  fwrite(STDOUT,"found frame: ".date('Y-m-d h:i:s',$ts+$ref_date->format('U'))." - ".($ts/3600)."\n");
68  print_r($res);
69  } elseif($options['-o']=='bin') {
70  fwrite(STOUT,$ts_bin.$length_bin.$bayeosframe);
71  }
72  $found++;
73  }
74  fwrite(STDERR,"done: ".round($pos/$fsize*100,2)."% - found: $found ".strlen($bayeosframe)." $last_date\n");
75 }
76 
77 
78 
79 ?>
for($i=0;$i< strlen($options['-s']);$i++) $pos
Definition: dumpParser.php:51
$sig
Definition: dumpParser.php:46
$min
Definition: dumpParser.php:35
$fp
Definition: dumpParser.php:41
static parseFrame($frame, $ts=FALSE, $origin='', $rssi=FALSE)
$last_date
Definition: dumpParser.php:53
static unpackUINT32($value, $endianness=0)
$ref_date
Definition: dumpParser.php:34
$min_date
Definition: dumpParser.php:33
$max
Definition: dumpParser.php:36
$options
Definition: dumpParser.php:7
$found
Definition: dumpParser.php:52
$fsize
Definition: dumpParser.php:42
else $t_shift
Definition: dumpParser.php:44
$until
Definition: dumpParser.php:32
die_usage()
Definition: dumpParser.php:9
$from
Definition: dumpParser.php:31
static unpackUINT8($value)