Beispiel #1
0
 /**
  * parse pdu string
  * @param \Data $data
  * @return array [decded text, text size, self object]
  * @throws Exception
  */
 public static function parse(Data $data)
 {
     $alphabet = $data->getPdu()->getDcs()->getTextAlphabet();
     $header = NULL;
     $length = $data->getPdu()->getUdl() * ($alphabet == PDU\DCS::ALPHABET_UCS2 ? 4 : 2);
     if ($data->getPdu()->getType()->getUdhi()) {
         PDU::debug("Header::parse()");
         $header = Header::parse();
     }
     $hex = PDU::getPduSubstr($length);
     PDU::debug("Data (hex): " . $hex);
     switch ($alphabet) {
         case PDU\DCS::ALPHABET_DEFAULT:
             PDU::debug("Helper::decode7bit()");
             $text = PDU\Helper::decode7bit($hex);
             break;
         case PDU\DCS::ALPHABET_8BIT:
             PDU::debug("Helper::decode8bit()");
             $text = PDU\Helper::decode8bit($hex);
             break;
         case PDU\DCS::ALPHABET_UCS2:
             PDU::debug("Helper::decode16Bit()");
             $text = PDU\Helper::decode16Bit($hex);
             break;
         default:
             throw new Exception("Unknown alpabet");
     }
     $size = mb_strlen($text, 'UTF-8');
     $self = new self($data, $hex, $size, $header ? $header->toArray() : NULL);
     $self->_text = $text;
     return array($text, $size, $self);
 }
Beispiel #2
0
 public static function initVars(PDU $pdu)
 {
     // if is the report status
     if ($pdu->getType() instanceof Type\Report) {
         // parse timestamp
         $pdu->setDateTime(SCTS::parse());
         // parse discharge
         $pdu->setDischarge(SCTS::parse());
         // get status
         $pdu->setStatus(hexdec(PDU::getPduSubstr(2)));
     } else {
         // get pid
         $pdu->setPid(PDU\PID::parse());
         // parse dcs
         $pdu->setDcs(DCS::parse());
         // if this submit sms
         if ($pdu->getType() instanceof Type\Submit) {
             // parse vp
             $pdu->setVp(VP::parse($pdu));
         } else {
             // parse scts
             $pdu->setScts(SCTS::parse());
         }
         // get data length
         $pdu->setUdl(hexdec(PDU::getPduSubstr(2)));
         // parse data
         $pdu->setData(Data::parse($pdu));
     }
     return $pdu;
 }