/** * Constructs the class with given parameters and reads object related data * from the Ogg bitstream. * * @param Zend_Io_Reader $reader The reader object. */ public function __construct($reader) { $this->_reader = $reader; $this->_capturePattern = $this->_reader->read(4); if ($this->_capturePattern != 'OggS') { require_once 'Zend/Media/Ogg/Exception.php'; throw new Zend_Media_Ogg_Exception('Not a valid Ogg bitstream'); } $this->_streamStructureVersion = $this->_reader->readUInt8(); if ($this->_streamStructureVersion != 0) { require_once 'Zend/Media/Ogg/Exception.php'; throw new Zend_Media_Ogg_Exception('Unsupported Ogg stream structure version'); } $this->_headerTypeFlag = $this->_reader->readUInt8(); $this->_granulePosition = $this->_reader->readInt64LE(); $this->_bitstreamSerialNumber = $this->_reader->readUInt32LE(); $this->_pageSequenceNumber = $this->_reader->readUInt32LE(); $this->_crcChecksum = $this->_reader->readUInt32LE(); $this->_numberPageSegments = $this->_reader->readUInt8(); $this->_segmentTable = array(); for ($i = 0; $i < $this->_numberPageSegments; $i++) { $this->_segmentTable[] = $this->_reader->readUInt8(); } $this->_headerSize = $this->_numberPageSegments + 27; $this->_pageSize = array_sum($this->_segmentTable); $this->_size = $this->_headerSize + $this->_pageSize; }
/** * Reads 1 record from the file. */ protected function readRecord() { $record_header = $this->readRecordHeader(); $local_msg_type = $record_header['Local Message Type']; if ($record_header['Message Type'] === true) { //this is a definition message $def = $this->readRecordDefinition(); $this->message_type_definitions[$local_msg_type] = $def; } else { $def = $this->message_type_definitions[$local_msg_type]; $data = array(); /* * Architecture Type * 0: Definition and Data Messages are Little Endian * 1: Definition and Data Message are Big Endian */ $big_endian = $def['architecture'] === 1; if ($this->file_type === null) { //default filetype, file_id is overal hetzelfde $this->file_type = \Fit\FileType::activity; } foreach ($def['fields'] as $field_def) { $profile_field_def = $this->profile->findFieldDefinition($this->file_type, $def['global_msg_number'], $field_def['field_def_number']); if ($profile_field_def) { $field_name = $profile_field_def[\Fit\Field::NAME]; $field_factor = (double) $profile_field_def[\Fit\Field::FACTOR]; $field_unit = $profile_field_def[\Fit\Field::UNIT]; } else { $field_name = 'no:' . $field_def['field_def_number']; $field_factor = 1; $field_unit = ''; } switch ($field_def['base_type']['base_type_definition']['name']) { case 'string': $value = $this->reader->readString8($field_def['size']); break; case 'sint8': $value = $this->reader->readInt8(); break; case 'enum': case 'uint8z': case 'uint8': $value = $this->reader->readUInt8(); break; case 'sint16': $value = $big_endian ? $this->reader->readInt16BE() : $this->reader->readInt16LE(); break; case 'uint16z': case 'uint16': $value = $big_endian ? $this->reader->readUInt16BE() : $this->reader->readUInt16LE(); break; case 'sint32': $value = $big_endian ? $this->reader->readInt32BE() : $this->reader->readInt32LE(); break; case 'uint32z': case 'uint32': $value = $big_endian ? $this->reader->readUInt32BE() : $this->reader->readUInt32LE(); break; case 'float32': $value = $big_endian ? $this->reader->readFloatBE() : $this->reader->readFloatLE(); break; case 'float64': $value = $big_endian ? $this->reader->readDoubleBE() : $this->reader->readDoubleLE(); break; case 'byte': default: $value = $this->reader->read($field_def['size']); } if (is_numeric($value) && $field_factor > 0) { $value *= $field_factor; } $data[$field_name] = array('value' => $value, 'unit' => $field_unit); if ($def['global_msg_number'] === 0 && $field_name === 'type') { $this->file_type = $value; } } $this->records[] = $data; } }
/** * Reads 1 record from the file. */ protected function readRecord() { $record_header = $this->readRecordHeader(); $local_msg_type = $record_header['Local Message Type']; if ($record_header['Message Type'] === true) { //this is a definition message $def = $this->readRecordDefinition(); $this->message_type_definitions[$local_msg_type] = $def; } else { //this is a data message $def = $this->message_type_definitions[$local_msg_type]; $data = array(); /* * Architecture Type * 0: Definition and Data Messages are Little Endian * 1: Definition and Data Message are Big Endian */ $big_endian = $def['architecture'] === 1; if ($this->file_type === null) { //default filetype, file_id is overal hetzelfde $this->file_type = \Fit\FileType::activity; } foreach ($def['fields'] as $field_def) { $profile_field_def = $this->profile->findFieldDefinition($this->file_type, $def['global_msg_number'], $field_def['field_def_number']); if ($profile_field_def) { $field_name = $profile_field_def[\Fit\Field::NAME]; $field_factor = (double) $profile_field_def[\Fit\Field::FACTOR]; $field_unit = $profile_field_def[\Fit\Field::UNIT]; } else { $field_name = 'no:' . $field_def['field_def_number']; $field_factor = 1; $field_unit = ''; } switch ($field_def['base_type']['base_type_definition']['name']) { case 'string': $value = $this->reader->readString8($field_def['size']); break; case 'sint8': $value = $this->reader->readInt8(); break; case 'enum': case 'uint8z': case 'uint8': $value = $this->reader->readUInt8(); break; case 'sint16': $value = $big_endian ? $this->reader->readInt16BE() : $this->reader->readInt16LE(); break; case 'uint16z': case 'uint16': $value = $big_endian ? $this->reader->readUInt16BE() : $this->reader->readUInt16LE(); break; case 'sint32': $value = $big_endian ? $this->reader->readInt32BE() : $this->reader->readInt32LE(); break; case 'uint32z': case 'uint32': $value = $big_endian ? $this->reader->readUInt32BE() : $this->reader->readUInt32LE(); break; case 'float32': $value = $big_endian ? $this->reader->readFloatBE() : $this->reader->readFloatLE(); break; case 'float64': $value = $big_endian ? $this->reader->readDoubleBE() : $this->reader->readDoubleLE(); break; case 'byte': default: $value = $this->reader->read($field_def['size']); } if (is_numeric($value) && $field_factor > 0) { $value *= $field_factor; } $data[$field_name] = array('value' => $value, 'unit' => $field_unit); if ($def['global_msg_number'] === 0 && $field_name === 'type') { $this->file_type = $value; } } $this->records[] = $data; } if ($this->debug) { $style = 'padding:1px 3px;background:white;'; $style2 = 'padding:1px 3px;background:lightgrey;'; $style3 = 'padding:1px 3px;background:darkgrey;'; static::$log->add(' <tr> <td style="' . $style . '">' . intval($this->headerbits[7]) . '</td> <td style="' . $style2 . '">' . intval($this->headerbits[6]) . '</td> <td style="' . $style . '">' . intval($this->headerbits[5]) . '</td> <td style="' . $style . '">' . intval($this->headerbits[4]) . '</td> <td style="' . $style2 . '">' . intval($this->headerbits[3]) . '</td> <td style="' . $style2 . '">' . intval($this->headerbits[2]) . '</td> <td style="' . $style2 . '">' . intval($this->headerbits[1]) . '</td> <td style="' . $style2 . '">' . intval($this->headerbits[0]) . '</td> <td style="' . $style3 . '">' . $local_msg_type . '</td> <td style="' . $style3 . '">' . $def['global_msg_number'] . '</td> <td style="' . $style3 . '">' . $this->file_type . '</td> '); if (isset($data)) { foreach ($data as $k => $d) { $v = $d['value']; if (stripos($k, 'time') !== false && stripos($k, 'total') === false) { $v = strftime('%FT%H:%M:%S%z', \Fit\Data::timeToUnix($v)); } elseif ($d['unit'] === 'deg') { $v = \Fit\Data::positionToDegrees($v); } static::$log->add('<td style="' . $style . '">' . $k . ': ' . $v . $d['unit'] . '</td>'); } } static::$log->add('</tr>'); } }