aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-07-20 07:45:53 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-07-20 07:45:53 +0200
commit2039373b7d60786e5b92a79520cecfcfce34c044 (patch)
treed30dac6fa8c58cd5990c6abfa4fc533f890bfaf3 /src
parent0073743d7518e5899f0cd075a1c7755a9d603bbd (diff)
downloadauerswald-callnotifier-2039373b7d60786e5b92a79520cecfcfce34c044.tar.gz
auerswald-callnotifier-2039373b7d60786e5b92a79520cecfcfce34c044.zip
read TEI and call reference
Diffstat (limited to 'src')
-rw-r--r--src/callnotifier/EDSS1/Message.php23
-rw-r--r--src/callnotifier/EDSS1/Parser.php33
-rw-r--r--src/callnotifier/Logger/Echo.php3
-rw-r--r--src/callnotifier/MessageHandler.php14
4 files changed, 66 insertions, 7 deletions
diff --git a/src/callnotifier/EDSS1/Message.php b/src/callnotifier/EDSS1/Message.php
index 3d22a82..08fa44f 100644
--- a/src/callnotifier/EDSS1/Message.php
+++ b/src/callnotifier/EDSS1/Message.php
@@ -12,11 +12,32 @@ class EDSS1_Message
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();
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;
+ }
}
?>
diff --git a/src/callnotifier/Logger/Echo.php b/src/callnotifier/Logger/Echo.php
index 9ce5b09..f0a1a41 100644
--- a/src/callnotifier/Logger/Echo.php
+++ b/src/callnotifier/Logger/Echo.php
@@ -38,9 +38,12 @@ class Logger_Echo implements Logger
$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) {
diff --git a/src/callnotifier/MessageHandler.php b/src/callnotifier/MessageHandler.php
index 6181e3a..9e65b81 100644
--- a/src/callnotifier/MessageHandler.php
+++ b/src/callnotifier/MessageHandler.php
@@ -103,10 +103,7 @@ class MessageHandler
}
$bytestring = substr($details, 5);
- $bytes = '';
- foreach (explode(' ', $bytestring) as $strbyte) {
- $bytes .= chr(hexdec($strbyte));
- }
+ $bytes = static::getBytesFromHexString($bytestring);
$msgtype = $bytes{7};
static $interestingTyps = array(
@@ -137,6 +134,15 @@ class MessageHandler
}
}
+ 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) {