Example #1
0
 public function getFrameOptions()
 {
     $isChecksum = false;
     while (!$isChecksum) {
         $idOption = hexdec($this->buffer->getUint16LE());
         $nameOption = Option::$optionIds[$idOption];
         $sizeOption = $this->buffer->getUint16LE();
         if ($nameOption === 'checksum') {
             $isChecksum = true;
             $expectedChecksum = 0;
             $checksum = $this->buffer->getUint32LE();
             $data = $this->buffer->getData();
             for ($i = 0; $i < $this->buffer->getLength() - $sizeOption; ++$i) {
                 $expectedChecksum = $expectedChecksum + hexdec(bin2hex($data[$i]));
             }
             $expectedChecksum = dechex($expectedChecksum);
             if ($checksum !== $expectedChecksum) {
                 throw new \Exception('Invalid checksum');
             }
         }
         $option = new Option($idOption, $this->buffer);
         $this->options[$option->getName()] = $option;
     }
 }