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->callRef = ord($cCallRef);
23 //var_dump($curpos, dechex($m->callRef));
24 $m->type = ord($bytes{++$curpos});
29 $curbit = $bytes{++$curpos};
30 if ($curbit == "\xFF" && $bytes{$curpos + 1} == "\n") {
35 $paramType = ord($curbit);
36 $param = $this->getParameterByType($paramType);
37 $m->parameters[] = $param;
40 $curbit = $bytes{++$curpos};
41 $param->length = ord($curbit);
44 $param->setData(substr($bytes, $curpos + 1, $param->length));
45 $curpos += $param->length;
46 } while ($curpos < strlen($bytes) - 1);
52 * Read a datablock preceded with a length byte.
54 * @return array Array with new cursor position, data and data length
56 public function readLengthData($bytes, $curpos)
58 //var_dump('old' . $curpos);
59 $length = ord($bytes{$curpos});
60 if ($length != 0xFF) {
61 $data = substr($bytes, $curpos + 1, $length);
65 return array($curpos + $length, $data, $length);
69 * @param integer $type Parameter type ID
71 public function getParameterByType($type)
73 $supported = array(0x28, 0x2C, 0x4C, 0x6C, 0x70);
74 if (!in_array($type, $supported)) {
75 return new EDSS1_Parameter($type);
78 $typeHex = sprintf('%02X', $type);
79 $class = 'callnotifier\EDSS1_Parameter_' . $typeHex;
81 return new $class($type);