public function CopyPreview($extBruType, $extFilePath) { $bruType = $extBruType; $file = $extFilePath; $flightInfo['bruType'] = $bruType; $Bru = new Bru(); $bruInfo = $Bru->GetBruInfo($bruType); $frameLength = $bruInfo['frameLength']; $stepLength = $bruInfo['stepLength']; $wordLength = $bruInfo['wordLength']; $headerLength = $bruInfo['headerLength']; $headerScr = $bruInfo['headerScr']; $frameSyncroCode = $bruInfo['frameSyncroCode']; $previewParams = $bruInfo['previewParams']; $cycloAp = $Bru->GetBruApCyclo($bruType, -1, -1, -1); $previewParams = explode(";", $previewParams); $previewParams = array_map('trim', $previewParams); $previewCyclo = array(); $cycloApByPrefixes = array(); foreach ($cycloAp as $row => $val) { if (in_array($val['code'], $previewParams)) { $previewCyclo[] = $val; if (!in_array($val['prefix'], $cycloApByPrefixes)) { $prefixFreqArr[$val['prefix']] = count(explode(",", $val['channel'])); } $cycloApByPrefixes[$val['prefix']][] = $val; } } $prefixFreqArr = $Bru->GetBruApCycloPrefixFreq($bruType); unset($Bru); $Fr = new Frame(); $fileDesc = $Fr->OpenFile($file); $fileSize = $Fr->GetFileSize($file); unset($Fr); if ($headerScr != '' || $headerScr != null) { eval($headerScr); } $startCopyTime = 0; // to be 0 hours /*if(isset($flightInfo['startCopyTime'])) { $startCopyTime = $flightInfo['startCopyTime'] * 1000; }*/ $Fr = new Frame(); $syncroWordOffset = $Fr->SearchSyncroWord($frameSyncroCode, $headerLength, $file); $fileDesc = $Fr->OpenFile($file); $fileSize = $Fr->GetFileSize($file); $frameNum = 0; $totalFrameNum = floor(($fileSize - $headerLength - $syncroWordOffset) / $frameLength); fseek($fileDesc, $syncroWordOffset, SEEK_SET); $curOffset = $syncroWordOffset; $algHeap = array(); $data = array(); while ($frameNum < $totalFrameNum && $curOffset < $fileSize) { $curOffset = ftell($fileDesc); $frame = $Fr->ReadFrame($fileDesc, $frameLength); $unpackedFrame = unpack("H*", $frame); if ($Fr->CheckSyncroWord($frameSyncroCode, $unpackedFrame[1]) === true) { $splitedFrame = str_split($unpackedFrame[1], $wordLength * 2); // div 2 because each byte 2 hex digits. $unpackedFrame[1] - dont know why [1], but hexdec($b[$i]) what we need $apPhisicsByPrefixes = array(); foreach ($cycloApByPrefixes as $prefix => $cycloAp) { $channelFreq = $prefixFreqArr[$prefix]; $phisicsFrame = $Fr->ConvertFrameToPhisics($splitedFrame, $startCopyTime, $stepLength, $channelFreq, $frameNum, $cycloAp, $algHeap); $phisicsFrame = $phisicsFrame[0]; // 0 - ap 1 - bp for ($i = 0; $i < count($cycloAp); $i++) { $data[$cycloAp[$i]['code']][] = array($phisicsFrame[1], $phisicsFrame[$i + 2]); //+2 because 0 - frameNum, 1 - time } } $frameNum++; } else { $syncroWordOffset = $Fr->SearchSyncroWord($frameSyncroCode, $curOffset, $file); fseek($fileDesc, $syncroWordOffset, SEEK_SET); $framesLeft = floor(($fileSize - $syncroWordOffset) / $frameLength); $totalFrameNum = $frameNum + $framesLeft; } } $Fr->CloseFile($fileDesc); unset($Fr); echo json_encode($data); }