From 2039373b7d60786e5b92a79520cecfcfce34c044 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 20 Jul 2012 07:45:53 +0200 Subject: read TEI and call reference --- src/callnotifier/EDSS1/Parser.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'src/callnotifier/EDSS1/Parser.php') diff --git a/src/callnotifier/EDSS1/Parser.php b/src/callnotifier/EDSS1/Parser.php index 5a298e5..64a072e 100644 --- a/src/callnotifier/EDSS1/Parser.php +++ b/src/callnotifier/EDSS1/Parser.php @@ -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; + } } ?> -- cgit v1.2.3