From 2f5e73812960809639489c6ea130237a9e0d290d Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 25 Jul 2012 18:12:17 +0200 Subject: [PATCH] split echo logger into multiple methods --- src/callnotifier/Logger/Echo.php | 128 ++++++++++++++++++------------- 1 file changed, 75 insertions(+), 53 deletions(-) diff --git a/src/callnotifier/Logger/Echo.php b/src/callnotifier/Logger/Echo.php index 87a9093..9fb0cae 100644 --- a/src/callnotifier/Logger/Echo.php +++ b/src/callnotifier/Logger/Echo.php @@ -3,6 +3,8 @@ namespace callnotifier; class Logger_Echo implements Logger { + public $edss1MsgOnly = false; + public function __construct() { $cc = new \Console_Color2(); @@ -17,66 +19,86 @@ class Logger_Echo implements Logger public function log($type, $arData) { 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"; - } + $this->echoMsgData($arData); } else if ($type == 'edss1msg') { - $msg = $arData['msg']; - echo sprintf( - $this->purple . 'EDSS1_Message' . $this->end - . ' type %02X ' - . $this->purple . '%s' . $this->end - . ' SAPI %d, CR %d, TEI %d, call %d-%s' - . ', %d parameters', - $msg->type, - $msg->getTypeName(), - $msg->sapi, - $msg->callResponse, - $msg->tei, - $msg->callRef, - $msg->callRefType == 0 ? 'source' : 'target', - count($msg->parameters) - ) . "\n"; - foreach ($msg->parameters as $param) { - echo sprintf( - " Parameter type %02X%s, %d bytes: %s\n", - $param->type, - $param->title - ? ' ' . $this->purple . $param->title . $this->end - : '', - $param->length, - preg_replace('/[^[:print:]]/', '?', $param->data) - . (isset($param->number) - ? ' ' . $this->red . $param->number . $this->end - : '' - ) - ); - if ($param instanceof EDSS1_Parameter_INumber) { - echo sprintf( - " Number type: %s, plan: %s\n", - EDSS1_Parameter_Names::$numberTypes[$param->numberType], - EDSS1_Parameter_Names::$numberingPlans[$param->numberingPlan] - ); - } - } + $this->echoEDSS1($arData['msg']); } else { + //other data echo $this->blue . $type . $this->end . ': ' . var_export($arData, true) . "\n"; } } + + protected function echoMsgData($arData) + { + if ($this->edss1MsgOnly + && substr($arData['details'], 16, 4) != ' 08 ' + ) { + //only E-DSS-1, no other packets + return; + } + + echo $this->begin . $arData['type'] . $this->end + . ': ' . $arData['details'] . "\n"; + + //Show bytes of N01|N02|T01|T02 etc + 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"; + } + } + + protected function echoEDSS1($msg) + { + echo sprintf( + $this->purple . 'EDSS1_Message' . $this->end + . ' type %02X ' + . $this->purple . '%s' . $this->end + . ' SAPI %d, CR %d, TEI %d, call %d-%s' + . ', %d parameters', + $msg->type, + $msg->getTypeName(), + $msg->sapi, + $msg->callResponse, + $msg->tei, + $msg->callRef, + $msg->callRefType == 0 ? 'source' : 'target', + count($msg->parameters) + ) . "\n"; + + foreach ($msg->parameters as $param) { + echo sprintf( + " Parameter type %02X%s, %d bytes: %s\n", + $param->type, + $param->title + ? ' ' . $this->purple . $param->title . $this->end + : '', + $param->length, + preg_replace('/[^[:print:]]/', '?', $param->data) + . (isset($param->number) + ? ' ' . $this->red . $param->number . $this->end + : '' + ) + ); + if ($param instanceof EDSS1_Parameter_INumber) { + echo sprintf( + " Number type: %s, plan: %s\n", + EDSS1_Parameter_Names::$numberTypes[$param->numberType], + EDSS1_Parameter_Names::$numberingPlans[$param->numberingPlan] + ); + } + } + } } ?> -- 2.30.2