call reference type parsing
authorChristian Weiske <cweiske@cweiske.de>
Mon, 23 Jul 2012 16:18:33 +0000 (18:18 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 23 Jul 2012 16:18:33 +0000 (18:18 +0200)
src/callnotifier/EDSS1/Message.php
src/callnotifier/EDSS1/Parser.php
tests/callnotifier/EDSS1/ParserTest.php

index d49000525e92d3f7dd5ec3d11c0be7bb25573f9f..421df79d213502fb9e01a2d64078689f07359e23 100644 (file)
@@ -27,6 +27,17 @@ class EDSS1_Message
      */
     public $callRef;
 
+    /**
+     * If the message is from the call originating device, or the
+     * other side.
+     *
+     * - 0 = device that originated the call
+     * - 1 = device that answers to orignator requests
+     *
+     * @var integer
+     */
+    public $callRefType;
+
     /**
      * Service AccessPoint Identifier
      *
index 0c9b86adfcc7a4fc90fa2833133366f65114df7f..f3ebebafd8035ea95ce2b2a24fba4ab7308bd0f0 100644 (file)
@@ -19,7 +19,15 @@ class EDSS1_Parser
         if ($crLen == 0xFF) {
             return $m;
         }
-        $m->callRef = ord($cCallRef);
+        $m->callRefType = ord($cCallRef{0}) >> 7;
+        $nCallRef = ord($cCallRef{0}) & 127;
+        if ($crLen > 1) {
+            $nCallRef = ord($cCallRef{1}) + ($nCallRef << 8);
+            if ($crLen > 2) {
+                $nCallRef = ord($cCallRef{2}) + ($nCallRef << 8);
+            }
+        }
+        $m->callRef = $nCallRef;
         //var_dump($curpos, dechex($m->callRef));
         $m->type = ord($bytes{++$curpos});
 
index 2846f7b86ba202e6889f5b38bf9252cf39b2fd96..e31367d3a482795d4cd710b1b6a6f025c61a7fe7 100644 (file)
@@ -3,17 +3,27 @@ namespace callnotifier;
 
 class EDSS1_ParserTest extends \PHPUnit_Framework_TestCase
 {
-    public function testParse()
+    protected function parseMsg($bs)
     {
-        $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);
+        return $msg;
+    }
+
+    public function testParse()
+    {
+        $msg = $this->parseMsg(
+            '00 A3 02 02 08 01 01 7B 70 0C 81 30 31 36 33 34 37 37 39 38 37 38 FF 0A'
+        );
+
         self::assertEquals(0, $msg->sapi, 'SAPI is wrong');
         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(0, $msg->callRefType, 'Call reference type is wrong');
+
         self::assertEquals(1, count($msg->parameters), 'Wrong parameter count');
         $p = $msg->parameters[0];
         self::assertInstanceOf('callnotifier\EDSS1_Parameter', $p);
@@ -23,11 +33,8 @@ class EDSS1_ParserTest extends \PHPUnit_Framework_TestCase
 
     public function testParseSAPI()
     {
-        $bs = 'FC A3 02 02 08 FF 0A';
-        $p = new EDSS1_Parser();
-        $msg = $p->parse(MessageHandler::getBytesFromHexString($bs));
+        $msg = $this->parseMsg('FC A3 02 02 08 FF 0A');
 
-        self::assertInstanceOf('callnotifier\EDSS1_Message', $msg);
         //SAPI: 0xFC = 252. 252 >> 2 = 63
         self::assertEquals(63, $msg->sapi, 'SAPI is wrong');
         self::assertEquals(0, $msg->callResponse, 'CR-bit is wrong');
@@ -35,15 +42,42 @@ class EDSS1_ParserTest extends \PHPUnit_Framework_TestCase
 
     public function testParseCallResponse()
     {
-        $bs = 'FE A3 02 02 08 FF 0A';
-        $p = new EDSS1_Parser();
-        $msg = $p->parse(MessageHandler::getBytesFromHexString($bs));
+        $msg = $this->parseMsg('FE A3 02 02 08 FF 0A');
 
-        self::assertInstanceOf('callnotifier\EDSS1_Message', $msg);
         //SAPI: 0xFE = 254. 254 & 2 = 2 -> cr bit set
         self::assertEquals(63, $msg->sapi, 'SAPI is wrong');
         self::assertEquals(1, $msg->callResponse, 'CR-bit is wrong');
     }
+
+    public function testParseCallRefType()
+    {
+        $msg = $this->parseMsg('00 97 16 4C 08 01 81 45 08 02 80 90 FF 0A');
+        self::assertEquals(1, $msg->callRef, 'Call reference is wrong');
+        self::assertEquals(1, $msg->callRefType, 'Call reference type is wrong');
+
+        $msg = $this->parseMsg('00 97 16 4C 08 01 85 45 08 02 80 90 FF 0A');
+        self::assertEquals(5, $msg->callRef, 'Call reference is wrong');
+        self::assertEquals(1, $msg->callRefType, 'Call reference type is wrong');
+
+        $msg = $this->parseMsg('00 97 16 4C 08 01 05 45 08 02 80 90 FF 0A');
+        self::assertEquals(5, $msg->callRef, 'Call reference is wrong');
+        self::assertEquals(0, $msg->callRefType, 'Call reference type is wrong');
+    }
+
+    public function testParseCallRefLong()
+    {
+        $msg = $this->parseMsg('00 97 16 4C 08 02 05 06 45 08 02 80 90 FF 0A');
+        self::assertEquals(0x0506, $msg->callRef, 'Call reference is wrong');
+        self::assertEquals(0, $msg->callRefType, 'Call reference type is wrong');
+
+        $msg = $this->parseMsg('00 97 16 4C 08 02 85 06 45 08 02 80 90 FF 0A');
+        self::assertEquals(0x0506, $msg->callRef, 'Call reference is wrong');
+        self::assertEquals(1, $msg->callRefType, 'Call reference type is wrong');
+
+        $msg = $this->parseMsg('00 97 16 4C 08 03 85 06 07 45 08 02 80 90 FF 0A');
+        self::assertEquals(0x050607, $msg->callRef, 'Call reference is wrong');
+        self::assertEquals(1, $msg->callRefType, 'Call reference type is wrong');
+    }
 }
 
 ?>