Пример #1
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");
     }
 }
Пример #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;
 }