BayEOS-PHP
 All Data Structures Namespaces Files Functions Variables Pages
dumpParserImporter.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3 require_once dirname(__FILE__) . '/BayEOSBinaryTypes.php';
4 
5 if($argc<6)
6  die("Usage: dumpImporter.php BAYEOS.DB.File url name pw timeoffset\n");
7 
8 if(! is_readable($argv[1]))
9  die("File $argv[1] not readable\n");
10 
11 $data="sender=$argv[3]&password=$argv[4]";
13 
14 $fp=fopen($argv[1],"r");
15 if(! isset($argv[5]) ) $argv[5]=0;
16 $pos=0;
17 while(! feof($fp)){
18  //read timestamp, length and bayeosframe
19  $ts_bin=fread($fp,4);
20  $ts=BayEOSType::unpackUINT32($ts_bin)+$argv[5];
21  $ts_bin=BayEOSType::UINT32($ts);
22  $length_bin=fread($fp,1);
23  $length=BayEOSType::unpackUINT8($length_bin);
24  if($length) $bayeosframe=fread($fp,$length);
25  else $bayeosframe='';
26  if($bayeosframe){
27  $bayeosframe=pack("C",0x9).$ts_bin.$bayeosframe;
28  $frames.="&bayeosframes[]=".base64_encode($bayeosframe);
29  }
30  if(strlen($frames)>3000){
31  send($argv[2],$data.$frames);
32  $frames='';
33  }
34 
35 // echo date('Y-m-d h:i:s',$ts+$ref_date->format('U'))." - $length: ";
36 // for($offset=3;$offset<$length;$offset+=4){
37 // echo "ch".(($offset+1)/4).": ".BayEOSType::unpackFLOAT32(substr($bayeosframe,$offset,4))." ";
38 // }
39 // echo "\n";
40 }
41 if(strlen($frames)>0){
42  send($argv[2],$data.$frames);
43  $frames='';
44 }
45 
46 function send($url,$data){
47  while(! $fp = fsockopen($url, 8090)){
48  sleep(1);
49  }
50 // if(! $fp) die("fsockopen failed");
51 
52  fputs($fp, "POST / HTTP/1.1\r\n");
53  fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
54  fputs($fp, "User-Agent: PHP-Importer\r\n");
55  fputs($fp, "Content-length: ". strlen($data) ."\r\n");
56  fputs($fp, "Connection: close\r\n\r\n");
57  fputs($fp, $data);
58 
59  echo "Sending ...";
60 
61  $header=1;
62  while(!feof($fp)) {
63  $res=rtrim(fgets($fp, 128));
64  if(strlen($res)==0) $header=0;
65 
66  if(! $header) echo $res."\n";
67  }
68  fclose($fp);
69 }
70 
71 
72 ?>
while(!feof($fp)) if(strlen($frames)>0) send($url, $data)
static UINT32($value, $endianness=0)
static unpackUINT32($value, $endianness=0)
static unpackUINT8($value)