/** * split message * @param integer $max * @return array */ protected function _splitMessage($max, $header = self::HEADER_SIZE) { // size less or equal max PDU::debug("Size: " . $this->getSize() . " <= " . $max); if ($this->getSize() <= $max) { return array($this->_data); } // parts of message $data = array(); $offset = 0; $size = $max - $header; while (TRUE) { $part = mb_substr($this->_data, $offset, $size, 'UTF-8'); PDU::debug("Part[" . $size . "]: " . $part); $data[] = $part; $offset += $size; if ($offset >= $this->getSize()) { break; } } return $data; }
/** * magic method for cast to string * @return srting|null */ public function __toString() { $PDU = sprintf("%02X", $this->getSize()); if ($this->getSize()) { $PDU .= $this->getType(); if ($this->getType()->getType() != SCA\Type::TYPE_ALPHANUMERICAL) { // reverse octets $l = strlen($this->_encoded); for ($i = 0; $i < $l; $i += 2) { $b1 = substr($this->_encoded, $i, 1); $b2 = $i + 1 >= $l ? 'F' : substr($this->_encoded, $i + 1, 1); // add to pdu $PDU .= $b2 . $b1; } } } PDU::debug("SCA::__toString() " . $PDU); return $PDU; }
/** * magic method for cast part to string * @return string */ public function __toString() { PDU::debug("_getPduString() " . $this->_getPduString()); PDU::debug("_getPartSize() " . $this->_getPartSize()); PDU::debug("getHeader() " . $this->getHeader()); PDU::debug("getData() " . $this->getData()); // concate pdu, size of part, headers, data return $this->_getPduString() . $this->_getPartSize() . $this->getHeader() . $this->getData(); }