BayEOS-PHP
 All Data Structures Namespaces Files Functions Variables Pages
bayeos-qli.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
3 require 'QLI.php';
4 require 'BayEOSGatewayClient.php';
5 
6 /*
7  * Read configuration file and set some defaults
8  */
9 $config=parse_ini_file('/etc/bayeos-qli.ini');
10 $config['writer_sleep_time']=0;
11 if(! isset($config['names'])){
12  $names=array();
13  for($i=0;$i<count($config['device']);$i++){
14  $names[$i]='QLI.'.$i; //-> storage path /tmp/qliRouter$i ...
15  }
16 } else $names=$config['names'];
17 
18 
20  private $qli;
21  private $read_error_count;
22 
24  $defaults=array('data_type'=>0x41,
25  'datetime_format'=>'d.m.Y H:M:S',
26  'indexmap'=>FALSE,
27  'baud'=>9600,
28  'tz'=>date_default_timezone_get());
29  while(list($key,$value)=each($defaults)){
30  if(! isset($options[$key])){
31  echo "Option '$key' not set using default: ".(is_array($value)?implode(', ',$value):$value)."\n";
32  $options[$key]=$value;
33  }
34  }
35  parent::__construct($names,$options);
36  }
37 
38  //Init Writer
39  protected function initWriter(){
40  $this->qli= new QLI($this->getOption('tz'),$this->getOption('datetime_format'),$this->getOption('indexmap'));
41  $this->qli->confDefaults($this->getOption('device'));
42  $this->qli->confBaudRate($this->getOption('baud'));
43  if($this->qli->open()===FALSE)
44  die("Could not open qli device");
45  }
46 
47  //Generate Data
48  protected function readData(){
49  if($data=$this->qli->getFrame()){
50  $this->read_error_count=0;
51  return $data;
52  }
53  $this->read_error_count++;
54  if($this->read_error_count>2){
55  $this->qli->close();
56  $this->qli->open();
57  $this->read_error_count=0;
58  }
59  return FALSE;
60  }
61 
62  //Save Data as DataFrame with timestamp
63  protected function saveData($data){
64  //print_r($data);
65  $this->writer->saveDataFrame($data['values'],$this->getOption('data_type'),0,$data['ts']);
66  }
67 
68 
69 }
70 
71 
73 $my_client->run();
74 
75 ?>
initWriter()
Definition: bayeos-qli.php:39
saveData($data)
Definition: bayeos-qli.php:63
Definition: QLI.php:12
$my_client
Definition: bayeos-qli.php:72
__construct($names, $options)
Definition: bayeos-qli.php:23
readData()
Definition: bayeos-qli.php:48
getOption($key, $default='')
if(!isset($config['names'])) else $names
Definition: bayeos-qli.php:16
$config
Definition: bayeos-qli.php:9