public static function returnByteString2($byteString) { $out = "\n" . str_pad("", 30) . " 0 1 2 3 4 5 6 7 8 9"; $out .= "\n" . str_pad("", 30) . " -----------------------------"; $out .= "\n" . str_pad("", 30) . " 0 | "; $byteArr = mbus_utils::byteStr2byteArray($byteString); $i = 1; foreach ($byteArr as $key => $byte) { //$out .= "\\x"; //$out .= "k" . $key . " "; if (intval($byte) < 16) { $out .= "0"; } $out .= dechex($byte) . " "; if ($i % 10 == 0) { $out .= "\n" . str_pad("", 30) . $i . " | "; } $i++; } return strtoupper($out); }
/** * Entry point, detect message type and direct to appropriate function. */ public function parse(&$data) { $this->data = $data; $this->dataarray = mbus_utils::byteStr2byteArray($this->data); $this->dataarray_len = count($this->dataarray); $this->varframe['DataLength'] = $this->dataarray_len; if ($this->dataarray_len == 0) { mbus_utils::mylog("No data to parse!"); return false; } if (dechex($this->dataarray[0]) == mbus_defs::$MBUS_FRAME_LONG_START) { // $this->varframe['FrameType'] = "Long or Control Frame Detected."; if (!$this->parseLongFrameTypeHeader()) { mbus_utils::mylog("Parse long frame type failed."); return false; } if (!$this->parseFrameData()) { mbus_utils::mylog("Parse parse internal data for long frame type failed."); return false; } } else { mbus_utils::mylog("Unhandled Frame Detected."); return false; } $this->mbus_frame_configured = true; return true; }