first try on E-DSS-1 ISDN d-channel parsing
[auerswald-callnotifier.git] / src / callnotifier / Logger / Echo.php
index eec9bb15dae3d14c11df7966ef8702469b114a48..9ce5b090d653672547accd0228ce9dd40079710a 100644 (file)
@@ -9,6 +9,9 @@ class Logger_Echo implements Logger
         $this->begin = $cc->convert('%y');
         $this->end = $cc->convert('%n');
         $this->blue = $cc->convert('%b');
+        $this->red = $cc->convert('%r');
+        $this->white = $cc->convert('%w');
+        $this->purple = $cc->convert('%p');
     }
 
     public function log($type, $arData)
@@ -16,6 +19,38 @@ class Logger_Echo implements Logger
         if ($type == 'msgData') {
             echo $this->begin . $arData['type'] . $this->end
                 . ': ' . $arData['details'] . "\n";
+            if (preg_match('#^[A-Z][0-9]{2}: (.+)$#', $arData['details'], $matches)) {
+                $bytestring = $matches[1];
+                $line = '';
+                foreach (explode(' ', $bytestring) as $strbyte) {
+                    $line .= chr(hexdec($strbyte));
+                }
+                $line = preg_replace(
+                    '/[^[:print:]]/',
+                    $this->white . '?' . $this->end,
+                    $line
+                );
+                echo $this->red . '     bytes' . $this->end . ': ' . $line . "\n";
+            }
+        } else if ($type == 'edss1msg') {
+            $msg = $arData['msg'];
+            echo sprintf(
+                $this->purple . 'EDSS1_Message' . $this->end
+                . ' type %02X '
+                . $this->purple . '%s' . $this->end
+                . ', %d parameters',
+                $msg->type,
+                $msg->getTypeName(),
+                count($msg->parameters)
+            ) . "\n";
+            foreach ($msg->parameters as $param) {
+                echo sprintf(
+                    " Parameter type %02X, %d bytes: %s\n",
+                    $param->type,
+                    $param->length,
+                    preg_replace('/[^[:print:]]/', '?', $param->data)
+                );
+            }
         } else {
             echo $this->blue . $type . $this->end . ': '
                 . var_export($arData, true) . "\n";