2 namespace callnotifier;
10 public function parse($bytes)
12 $m = new EDSS1_Message();
13 $m->sapi = ord($bytes{0}) >> 2;
14 $m->callResponse = (int) ((ord($bytes{0}) & 2) == 2);
15 $m->tei = ord($bytes{1}) >> 1;
18 list($curpos, $cCallRef, $crLen) = $this->readLengthData($bytes, ++$curpos);
22 $m->callRefType = ord($cCallRef{0}) >> 7;
23 $nCallRef = ord($cCallRef{0}) & 127;
25 $nCallRef = ord($cCallRef{1}) + ($nCallRef << 8);
27 $nCallRef = ord($cCallRef{2}) + ($nCallRef << 8);
30 $m->callRef = $nCallRef;
31 //var_dump($curpos, dechex($m->callRef));
32 $m->type = ord($bytes{++$curpos});
37 $curbit = $bytes{++$curpos};
38 if ($curbit == "\xFF" && $bytes{$curpos + 1} == "\n") {
43 $paramType = ord($curbit);
44 $param = $this->getParameterByType($paramType);
45 $m->parameters[] = $param;
48 $curbit = $bytes{++$curpos};
49 $param->length = ord($curbit);
52 $param->setData(substr($bytes, $curpos + 1, $param->length));
53 $curpos += $param->length;
54 } while ($curpos < strlen($bytes) - 1);
60 * Read a datablock preceded with a length byte.
62 * @return array Array with new cursor position, data and data length
64 public function readLengthData($bytes, $curpos)
66 //var_dump('old' . $curpos);
67 $length = ord($bytes{$curpos});
68 if ($length != 0xFF) {
69 $data = substr($bytes, $curpos + 1, $length);
73 return array($curpos + $length, $data, $length);
77 * @param integer $type Parameter type ID
79 public function getParameterByType($type)
81 $supported = array(0x28, 0x2C, 0x4C, 0x6C, 0x70);
82 if (!in_array($type, $supported)) {
83 return new EDSS1_Parameter($type);
86 $typeHex = sprintf('%02X', $type);
87 $class = 'callnotifier\EDSS1_Parameter_' . $typeHex;
89 return new $class($type);