예제 #1
0
 /**
  * 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;
     }
 }
예제 #2
0
    /**
     * 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>');
        }
    }