const RELEASE = "\x4D";
const RELEASE_COMPLETE = "\x5A";
const INFORMATION = "\x7B";
-
+
/**
+ * Message type, see the class constants
* @var integer
*/
public $type;
+
+ /**
+ * Call reference number to distinguish concurrent calls
+ *
+ * @var integer
+ */
+ public $callRef;
+
+ /**
+ * Terminal Endpoint Identifier (internal Telephone ID)
+ *
+ * @var integer
+ */
+ public $tei;
+
+ /**
+ * Array of EDSS1_Parameter objects
+ *
+ * @var array
+ */
public $parameters = array();
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
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;
+ }
}
?>
$this->purple . 'EDSS1_Message' . $this->end
. ' type %02X '
. $this->purple . '%s' . $this->end
+ . ' TEI %d, call %d'
. ', %d parameters',
$msg->type,
$msg->getTypeName(),
+ $msg->tei,
+ $msg->callRef,
count($msg->parameters)
) . "\n";
foreach ($msg->parameters as $param) {
}
$bytestring = substr($details, 5);
- $bytes = '';
- foreach (explode(' ', $bytestring) as $strbyte) {
- $bytes .= chr(hexdec($strbyte));
- }
+ $bytes = static::getBytesFromHexString($bytestring);
$msgtype = $bytes{7};
static $interestingTyps = array(
}
}
+ public static function getBytesFromHexString($bytestring)
+ {
+ $bytes = '';
+ foreach (explode(' ', $bytestring) as $strbyte) {
+ $bytes .= chr(hexdec($strbyte));
+ }
+ return $bytes;
+ }
+
protected function prepareDump()
{
if ($this->config->dumpFile === null) {
--- /dev/null
+<?php
+
+set_include_path(
+ __DIR__ . '/../src/'
+ . PATH_SEPARATOR . get_include_path()
+);
+spl_autoload_register(
+ function ($class) {
+ $file = str_replace(array('\\', '_'), '/', $class) . '.php';
+ $hdl = @fopen($file, 'r', true);
+ if ($hdl !== false) {
+ fclose($hdl);
+ require $file;
+ }
+ }
+);
+
+?>
--- /dev/null
+<?php
+namespace callnotifier;
+
+class EDSS1_ParserTest extends \PHPUnit_Framework_TestCase
+{
+
+ public function testParse()
+ {
+ $bs = '00 A3 02 02 08 01 01 7B 70 0C 81 30 31 36 33 34 37 37 39 38 37 38 FF 0A';
+ $p = new EDSS1_Parser();
+ $msg = $p->parse(MessageHandler::getBytesFromHexString($bs));
+
+ self::assertInstanceOf('callnotifier\EDSS1_Message', $msg);
+ self::assertEquals(81, $msg->tei, 'TEI is wrong');
+ self::assertEquals(123, $msg->type, 'Message type is wrong');
+ self::assertEquals(1, $msg->callRef, 'Call reference is wrong');
+ self::assertEquals(1, count($msg->parameters), 'Wrong parameter count');
+ $p = $msg->parameters[0];
+ self::assertInstanceOf('callnotifier\EDSS1_Parameter', $p);
+ self::assertEquals(112, $p->type, 'Type of 1st parameter is wrong');
+ self::assertEquals("\x8101634779878", $p->data, 'Parameter data is wrong');
+ }
+
+}
+
+?>
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<phpunit strict="true" colors="true"
+ bootstrap="bootstrap.php"
+>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../src/</directory>
+ </whitelist>
+ </filter>
+</phpunit>