2 namespace callnotifier;
9 public function __construct($config, $log, $callMonitor)
11 $this->config = $config;
14 $this->callMonitor = $callMonitor;
17 public function handle($msg)
19 if ($this->config->dumpFile !== null) {
22 if (substr($msg, 0, 9) != '[DKANPROT') {
23 //unknown message type
26 $regex = '#^\\[DKANPROT-([^ ]+) ([0-9]+)\\] (.*)$#';
27 if (!preg_match($regex, $msg, $matches)) {
28 //message should always be that way
31 list(, $type, $someid, $details) = $matches;
41 if ($type == 'Debug') {
42 $msg = $this->parseEDSS1($details);
43 if (is_object($msg)) {
44 $this->log->log('edss1msg', array('msg' => $msg));
45 $this->callMonitor->handle($msg);
51 * Example string: "T02: 00 A3 06 0A 08 01 01 5A FF 0A"
53 * @param string $details Detail string of a debug message
55 * @return EDSS1_Message The retrieved message, NULL if none.
57 protected function parseEDSS1($details)
59 if ($details{0} != 'T' && $details{0} != 'N') {
60 //we only want byte data
63 if (substr($details, 16, 4) != ' 08 ') {
64 //only E-DSS-1, no other packets
68 $bytestring = substr($details, 5);
69 $bytes = static::getBytesFromHexString($bytestring);
71 $mp = new EDSS1_Parser();
72 return $mp->parse($bytes);
75 public static function getBytesFromHexString($bytestring)
78 foreach (explode(' ', $bytestring) as $strbyte) {
79 $bytes .= chr(hexdec($strbyte));
84 protected function prepareDump()
86 if ($this->config->dumpFile === null) {
89 $this->dumpHdl = fopen($this->config->dumpFile, 'w');
90 if (!$this->dumpHdl) {
91 throw new \Exception('Cannot open dump file for writing');
95 protected function dump($msg)
97 fwrite($this->dumpHdl, $msg . "\n");