read TEI and call reference
[auerswald-callnotifier.git] / src / callnotifier / EDSS1 / Parser.php
index 5a298e5011b51d4a2b67d816782cb1b25f4c7ad5..64a072e91cb6fab891f9094a7265a4e61ad65a94 100644 (file)
@@ -10,9 +10,13 @@ class EDSS1_Parser
     public function parse($bytes)
     {
         $m = new EDSS1_Message();
-        $m->type = ord($bytes{7});
+        $m->tei = ord($bytes{1}) >> 1;//1st bit is always 1 and needs to be removed
+
+        $curpos = 4;
+        list($curpos, $m->callRef) = $this->readLengthDataInt($bytes, ++$curpos);
+        //var_dump($curpos, dechex($m->callRef));
+        $m->type = ord($bytes{++$curpos});
 
-        $curpos = 7;
         $complete = false;
         do {
             //parameter type
@@ -36,6 +40,31 @@ class EDSS1_Parser
 
         return $m;
     }
+
+    /**
+     * Read a datablock preceded with a length byte.
+     *
+     * @return array Array with new cursor position, data and data length
+     */
+    public function readLengthData($bytes, $curpos)
+    {
+        //var_dump('old' . $curpos);
+        $length = ord($bytes{$curpos});
+        $data = substr($bytes, $curpos + 1, $length);
+        return array($curpos + $length, $data, $length);
+    }
+
+    /**
+     * Read a datablock preceded with a length byte, return integer data.
+     *
+     * @return array Array with new cursor position, integer data and data length
+     */
+    public function readLengthDataInt($bytes, $curpos)
+    {
+        $ld = $this->readLengthData($bytes, $curpos);
+        $ld[1] = ord($ld[1]);
+        return $ld;
+    }
 }
 
 ?>