diff --git a/php-FIT-File-Analysis.php b/php-FIT-File-Analysis.php index 334f01f..1a774c2 100644 --- a/php-FIT-File-Analysis.php +++ b/php-FIT-File-Analysis.php @@ -787,7 +787,8 @@ private function fix_data($options) { $mesg_name = $this->data_mesg_info[$mesg['global_mesg_num']]['mesg_name']; foreach($mesg['field_defns'] as $field) { - if($field['base_type'] === 131) { // Convert uint16 to sint16 + // Convert uint16 to sint16 + if($field['base_type'] === 131 && isset($this->data_mesg_info[$mesg['global_mesg_num']]['field_defns'][$field['field_definition_number']]['field_name'])) { $field_name = $this->data_mesg_info[$mesg['global_mesg_num']]['field_defns'][$field['field_definition_number']]['field_name']; if(is_array($this->data_mesgs[$mesg_name][$field_name])) { foreach($this->data_mesgs[$mesg_name][$field_name] as &$v) { @@ -800,7 +801,8 @@ private function fix_data($options) { $this->data_mesgs[$mesg_name][$field_name] = -1 * ($this->data_mesgs[$mesg_name][$field_name] - 0x7FFF); } } - else if($field['base_type'] === 133) { // Convert uint32 to sint32 + // Convert uint32 to sint32 + else if($field['base_type'] === 133 && isset($this->data_mesg_info[$mesg['global_mesg_num']]['field_defns'][$field['field_definition_number']]['field_name'])) { $field_name = $this->data_mesg_info[$mesg['global_mesg_num']]['field_defns'][$field['field_definition_number']]['field_name']; if(is_array($this->data_mesgs[$mesg_name][$field_name])) { foreach($this->data_mesgs[$mesg_name][$field_name] as &$v) { @@ -936,11 +938,13 @@ private function interpolate_missing_data(&$missing_keys, &$array){ if ($missing_keys[$i] > $max_key) { $array[$missing_keys[$i]] = $array[$max_key]; continue; - } else if ($missing_keys[$i] < $max_key) { + } else if ($missing_keys[$i] < $min_key) { $array[$missing_keys[$i]] = $array[$min_key]; continue; } + reset($array); + while($missing_keys[$i] > key($array)) { $prev_value = current($array); next($array);