2 require 
'BayEOSSerialPHP.php';
 
    8 define(
"QLI_BEGIN",pack(
"C",0x2));
 
    9 define(
"QLI_END",pack(
"C",0x3));
 
   10 define(
"XON",pack(
"C",0x11));
 
   11 define(
"XOFF",pack(
"C",0x13));
 
   14     private $datetime_format;
 
   22     function QLI($tz,$datetime_format,$indexmap=FALSE) {
 
   25         $this->datetime_format=$datetime_format;
 
   26         $this->indexmap=$indexmap;
 
   52     public function open($waitForOpened=0.1) {
 
   54         usleep((
int) ($waitForOpened * 1000000));
 
   69         if(! 
$data) 
return count($this->stack);
 
   70         if(! isset($this->stack[0])){
 
   72             if($delim_pos===FALSE) 
return 0;
 
   77         $offset=count($this->stack)-1;
 
   78         if($offset==-1) $offset=0;
 
   79         for($i=0;$i<count(
$data);$i++){
 
   81             if(! isset($this->stack[$index][
'frame']))
 
   82                 $this->stack[$index][
'frame']=
'';
 
   83             $this->stack[$index][
'frame'].=
$data[$i];
 
   85             $this->stack[$index][
'ok']=$this->_parseFrame($index);
 
   86             if(! $this->stack[$index][
'ok'] && ($i+1)<count(
$data)){
 
   88                 echo 
"Invalid Frame\n";
 
   89                 unset($this->stack[$index]);
 
   94         $anz=count($this->stack);
 
   97         if(! $this->stack[$anz-1][
'ok']) $anz--;
 
  102     private function _parseFrame($index){
 
  103         $frame=$this->stack[$index][
'frame'];
 
  107         if(strlen(
$frame)>$length) 
return FALSE;
 
  111         $ts_obj=DateTime::createFromFormat($this->datetime_format,$ts,
new DateTimeZone($this->tz));
 
  112         if(! $ts_obj) 
return FALSE;
 
  113         $this->stack[$index][
'ts']=floatval($ts_obj->format(
"U"));
 
  116         $pos=strpos($frame,
"\n");
 
  118         $frame=substr($frame,(
$pos+1),($pos2-
$pos-1));
 
  119         $data=explode(
"\r\n",$frame);
 
  121         $this->stack[$index][
'values']=array();
 
  122         for($i=0;$i<count(
$data);$i++){
 
  123             if(strpos(
$data[$i],
"=")===FALSE) 
continue;
 
  124             $tmp=explode(
"=",
$data[$i]);
 
  126             if(is_numeric($tmp[1])){
 
  127                 if(is_array($this->indexmap)){
 
  128                     if(isset($this->indexmap[$tmp[0]]))
 
  129                         $this->stack[$index][
'values'][$this->indexmap[$tmp[0]]]=$tmp[1];
 
  132                     $this->stack[$index][
'values'][$i]=$tmp[1];
 
  150         while($this->
read()==0 && $timeout>0){
 
  154         if($timeout<0) 
return FALSE;
 
  155         return array_shift($this->stack);
 
confDefaults($device= '/dev/ttyUSB0')
 
QLI($tz, $datetime_format, $indexmap=FALSE)
 
confCharacterLength($int)