예제 #1
0
 /**
  * @param array $spec
  *
  * @return int
  */
 public function init(array $spec)
 {
     $dl = Specifications::rsDataCodes1($spec);
     $el = Specifications::rsEccCodes1($spec);
     $rs = Rs::initRs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
     $blockNo = 0;
     $dataPos = 0;
     $eccPos = 0;
     for ($i = 0; $i < Specifications::rsBlockNum1($spec); $i++) {
         $ecc = array_slice($this->eccCode, $eccPos);
         $this->rsBlocks[$blockNo] = new Block($dl, array_slice($this->dataCode, $dataPos), $el, $ecc, $rs);
         $this->eccCode = array_merge(array_slice($this->eccCode, 0, $eccPos), $ecc);
         $dataPos += $dl;
         $eccPos += $el;
         $blockNo++;
     }
     if (Specifications::rsBlockNum2($spec) == 0) {
         return 0;
     }
     $dl = Specifications::rsDataCodes2($spec);
     $el = Specifications::rsEccCodes2($spec);
     $rs = Rs::initRs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
     if ($rs == null) {
         return -1;
     }
     for ($i = 0; $i < Specifications::rsBlockNum2($spec); $i++) {
         $ecc = array_slice($this->eccCode, $eccPos);
         $this->rsBlocks[$blockNo] = new Block($dl, array_slice($this->dataCode, $dataPos), $el, $ecc, $rs);
         $this->eccCode = array_merge(array_slice($this->eccCode, 0, $eccPos), $ecc);
         $dataPos += $dl;
         $eccPos += $el;
         $blockNo++;
     }
     return 0;
 }