first try on E-DSS-1 ISDN d-channel parsing
[auerswald-callnotifier.git] / src / callnotifier / Logger / Echo.php
1 <?php
2 namespace callnotifier;
3
4 class Logger_Echo implements Logger
5 {
6     public function __construct()
7     {
8         $cc = new \Console_Color2();
9         $this->begin = $cc->convert('%y');
10         $this->end = $cc->convert('%n');
11         $this->blue = $cc->convert('%b');
12         $this->red = $cc->convert('%r');
13         $this->white = $cc->convert('%w');
14         $this->purple = $cc->convert('%p');
15     }
16
17     public function log($type, $arData)
18     {
19         if ($type == 'msgData') {
20             echo $this->begin . $arData['type'] . $this->end
21                 . ': ' . $arData['details'] . "\n";
22             if (preg_match('#^[A-Z][0-9]{2}: (.+)$#', $arData['details'], $matches)) {
23                 $bytestring = $matches[1];
24                 $line = '';
25                 foreach (explode(' ', $bytestring) as $strbyte) {
26                     $line .= chr(hexdec($strbyte));
27                 }
28                 $line = preg_replace(
29                     '/[^[:print:]]/',
30                     $this->white . '?' . $this->end,
31                     $line
32                 );
33                 echo $this->red . '     bytes' . $this->end . ': ' . $line . "\n";
34             }
35         } else if ($type == 'edss1msg') {
36             $msg = $arData['msg'];
37             echo sprintf(
38                 $this->purple . 'EDSS1_Message' . $this->end
39                 . ' type %02X '
40                 . $this->purple . '%s' . $this->end
41                 . ', %d parameters',
42                 $msg->type,
43                 $msg->getTypeName(),
44                 count($msg->parameters)
45             ) . "\n";
46             foreach ($msg->parameters as $param) {
47                 echo sprintf(
48                     " Parameter type %02X, %d bytes: %s\n",
49                     $param->type,
50                     $param->length,
51                     preg_replace('/[^[:print:]]/', '?', $param->data)
52                 );
53             }
54         } else {
55             echo $this->blue . $type . $this->end . ': '
56                 . var_export($arData, true) . "\n";
57         }
58     }
59
60 }
61
62 ?>