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);
23 $m->callRefType = ord($cCallRef{0}) >> 7;
24 $nCallRef = ord($cCallRef{0}) & 127;
26 $nCallRef = ord($cCallRef{1}) + ($nCallRef << 8);
28 $nCallRef = ord($cCallRef{2}) + ($nCallRef << 8);
31 $m->callRef = $nCallRef;
33 $m->type = ord($bytes{++$curpos});
38 $curbit = $bytes{++$curpos};
39 if ($curbit == "\xFF" && $bytes{$curpos + 1} == "\n") {
44 $paramType = ord($curbit);
45 $param = $this->getParameterByType($paramType);
46 $m->parameters[] = $param;
49 $curbit = $bytes{++$curpos};
50 $param->length = ord($curbit);
53 $param->setData(substr($bytes, $curpos + 1, $param->length));
54 $curpos += $param->length;
55 } while ($curpos < strlen($bytes) - 1);
61 * Read a datablock preceded with a length byte.
63 * @return array Array with new cursor position, data and data length
65 public function readLengthData($bytes, $curpos)
67 //var_dump('old' . $curpos);
68 $length = ord($bytes{$curpos});
69 if ($length != 0xFF) {
70 $data = substr($bytes, $curpos + 1, $length);
74 return array($curpos + $length, $data, $length);
78 * @param integer $type Parameter type ID
80 public function getParameterByType($type)
82 $supported = array(0x28, 0x2C, 0x4C, 0x6C, 0x70);
83 if (!in_array($type, $supported)) {
84 return new EDSS1_Parameter($type);
87 $typeHex = sprintf('%02X', $type);
88 $class = 'callnotifier\EDSS1_Parameter_' . $typeHex;
90 return new $class($type);