Example #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);
 }
Example #2
0
 public static function parse($isAddress = TRUE)
 {
     $SCA = new self($isAddress);
     $size = hexdec(PDU::getPduSubstr(2));
     if ($size) {
         // if is OA or DA size in digits
         if ($isAddress) {
             if ($size % 2 != 0) {
                 $size++;
             }
             // else size in octets
         } else {
             $size--;
             $size *= 2;
         }
         $SCA->setType(new SCA\Type(hexdec(PDU::getPduSubstr(2))));
         $hex = PDU::getPduSubstr($size);
         switch ($SCA->getType()->getType()) {
             case SCA\Type::TYPE_UNKNOWN:
             case SCA\Type::TYPE_INTERNATIONAL:
             case SCA\Type::TYPE_ACCEPTER_INTO_NET:
             case SCA\Type::TYPE_SUBSCRIBER_NET:
             case SCA\Type::TYPE_TRIMMED:
                 $SCA->setPhone(rtrim(implode("", array_map('strrev', array_map(array('self', '_map_filter_decode'), str_split($hex, 2)))), 'F'));
                 break;
             case SCA\Type::TYPE_ALPHANUMERICAL:
                 $SCA->setPhone(PDU\Helper::decode7bit($hex));
                 break;
         }
     }
     return $SCA;
 }
Example #3
0
 /**
  * parse pdu string
  * @param PDU $pdu
  * @return \self
  * @throws Exception
  */
 public static function parse(Submit $pdu)
 {
     $vp = new self($pdu);
     switch ($pdu->getType()->getVpf()) {
         case Type::VPF_NONE:
             return $vp;
         case Type::VPF_ABSOLUTE:
             return SCTS::parse();
         case Type::VPF_RELATIVE:
             $byte = hexdec(PDU::getPduSubstr(2));
             if ($byte <= 143) {
                 $vp->_interval = ($byte + 1) * (5 * 60);
             } else {
                 if ($byte <= 167) {
                     $vp->_interval = 3600 * 24 * 12 + ($byte - 143) * (30 * 60);
                 } else {
                     if ($byte <= 196) {
                         $vp->_interval = ($byte - 166) * (3600 * 24);
                     } else {
                         $vp->_interval = ($byte - 192) * (3600 * 24 * 7);
                     }
                 }
             }
             return $vp;
         default:
             throw new Exception("Unknown VPF");
     }
 }
Example #4
0
 /**
  * parse pdu string
  * @return \self
  */
 public static function parse()
 {
     $hex = PDU::getPduSubstr(14);
     $params = array_merge(array("20%02d-%02d-%02d %02d:%02d:%02d"), array_map('intval', array_map('strrev', str_split($hex, 2))));
     $dtime = call_user_func_array('sprintf', $params);
     return new self($dtime);
 }
Example #5
0
 /**
  * parse sms type
  * @return PDU\Type
  * @throws Exception
  */
 public static function parse()
 {
     $byte = hexdec(PDU::getPduSubstr(2));
     $type = NULL;
     switch (3 & $byte) {
         case self::SMS_DELIVER:
             $type = new Type\Deliver();
             break;
         case self::SMS_SUBMIT:
             $type = new Type\Submit();
             break;
         case self::SMS_REPORT:
             $type = new Type\Report();
             break;
         default:
             throw new Exception("Unknown type sms");
     }
     $type->_rp = 1 & $byte >> 7;
     $type->_udhi = 1 & $byte >> 6;
     $type->_srr = 1 & $byte >> 5;
     $type->_vpf = 3 & $byte >> 3;
     $type->_rd = 1 & $byte >> 2;
     $type->_mti = 3 & $byte;
     return $type;
 }
Example #6
0
 public static function parse()
 {
     $byte = hexdec(PDU::getPduSubstr(2));
     $self = new self();
     $self->setPid($byte >> 6);
     $self->setIndicates($byte >> 5);
     $self->setType($byte);
     return $self;
 }
Example #7
0
 /**
  * parse header
  * @return \self
  */
 public static function parse()
 {
     $udhl = hexdec(PDU::getPduSubstr(2));
     $type = hexdec(PDU::getPduSubstr(2));
     $psize = hexdec(PDU::getPduSubstr(2));
     $pointer = hexdec(PDU::getPduSubstr(($psize - 2) * 2));
     // psize is pointer + segments + current
     $sergments = hexdec(PDU::getPduSubstr(2));
     $current = hexdec(PDU::getPduSubstr(2));
     $self = new self(array('UDHL' => $udhl, 'TYPE' => $type, 'PSIZE' => $psize, 'POINTER' => $pointer, 'SEGMENTS' => $sergments, 'CURRENT' => $current));
     return $self;
 }
Example #8
0
 /**
  * parse pdu string
  * @return \self
  */
 public static function parse()
 {
     $DCS = new self();
     $byte = hexdec(PDU::getPduSubstr(2));
     $DCS->_encodeGroup = 0xf & $byte >> 4;
     $DCS->_dataEncoding = 0xf & $byte;
     $DCS->_alphabet = 3 & $DCS->_dataEncoding >> 2;
     $DCS->_classMessage = 3 & $DCS->_dataEncoding;
     switch ($DCS->_encodeGroup) {
         case 0xc:
             $DCS->_discardMessage = TRUE;
             break;
         case 0xd:
             $DCS->_storeMessage = TRUE;
             break;
         case 0xe:
             $DCS->_storeMessageUCS2 = TRUE;
             break;
         case 0xf:
             $DCS->_dataCodingAndMessageClass = TRUE;
             if ($DCS->_dataEncoding & 1 << 2) {
                 $DCS->_alphabet = self::ALPHABET_8BIT;
             }
             break;
         default:
             if ($DCS->_encodeGroup & 1 << 4) {
                 $DCS->_useMessageClass = TRUE;
             }
             if ($DCS->_encodeGroup & 1 << 5) {
                 $DCS->_compressedText = TRUE;
             }
     }
     if ($DCS->_discardMessage || $DCS->_storeMessage || $DCS->_storeMessageUCS2) {
         if ($DCS->_dataEncoding & 1 << 3) {
             $DCS->_messageIndication = TRUE;
             $DCS->_messageIndicationType = 3 & $DCS->_dataEncoding;
         }
     }
     return $DCS;
 }
Example #9
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;
 }