@@ -1104,14 +1104,26 @@ class phpFITFileAnalysis
11041104 ];
11051105
11061106 // PHP Constructor - called when an object of the class is instantiated.
1107- public function __construct ($ file_path , $ options = null )
1107+ public function __construct ($ file_path_or_data , $ options = null )
11081108 {
1109- if (empty ($ file_path )) {
1110- throw new \Exception ('phpFITFileAnalysis->__construct(): file_path is empty! ' );
1111- }
1112- if (!file_exists ($ file_path )) {
1113- throw new \Exception ('phpFITFileAnalysis->__construct(): file \'' .$ file_path .'\' does not exist! ' );
1109+ if ( isset ( $ options ['input_is_data ' ] ) ){
1110+ $ this ->file_contents = $ file_path_or_data ;
1111+ }else {
1112+ if (empty ($ file_path_or_data )) {
1113+ throw new \Exception ('phpFITFileAnalysis->__construct(): file_path is empty! ' );
1114+ }
1115+ if (!file_exists ($ file_path_or_data )) {
1116+ throw new \Exception ('phpFITFileAnalysis->__construct(): file \'' .$ file_path_or_data .'\' does not exist! ' );
1117+ }
1118+ /**
1119+ * D00001275 Flexible & Interoperable Data Transfer (FIT) Protocol Rev 1.7.pdf
1120+ * 3.3 FIT File Structure
1121+ * Header . Data Records . CRC
1122+ */
1123+ $ this ->file_contents = file_get_contents ($ file_path_or_data ); // Read the entire file into a string
1124+
11141125 }
1126+
11151127 $ this ->options = $ options ;
11161128 if (isset ($ options ['garmin_timestamps ' ]) && $ options ['garmin_timestamps ' ] == true ) {
11171129 $ this ->garmin_timestamps = true ;
@@ -1122,13 +1134,6 @@ public function __construct($file_path, $options = null)
11221134 }
11231135 $ this ->php_trader_ext_loaded = extension_loaded ('trader ' );
11241136
1125- /**
1126- * D00001275 Flexible & Interoperable Data Transfer (FIT) Protocol Rev 1.7.pdf
1127- * 3.3 FIT File Structure
1128- * Header . Data Records . CRC
1129- */
1130- $ this ->file_contents = file_get_contents ($ file_path ); // Read the entire file into a string
1131-
11321137 // Process the file contents.
11331138 $ this ->readHeader ();
11341139 $ this ->readDataRecords ();
@@ -1190,7 +1195,6 @@ private function readDataRecords()
11901195 $ local_mesg_type = 0 ;
11911196 $ previousTS = 0 ;
11921197
1193-
11941198 while ($ this ->file_header ['header_size ' ] + $ this ->file_header ['data_size ' ] > $ this ->file_pointer ) {
11951199 $ record_header_byte = ord (substr ($ this ->file_contents , $ this ->file_pointer , 1 ));
11961200 $ this ->file_pointer ++;
@@ -1464,6 +1468,7 @@ private function fixData($options)
14641468 if (isset ($ this ->data_mesg_info [$ mesg ['global_mesg_num ' ]])) {
14651469 $ mesg_name = $ this ->data_mesg_info [$ mesg ['global_mesg_num ' ]]['mesg_name ' ];
14661470
1471+
14671472 foreach ($ mesg ['field_defns ' ] as $ field ) {
14681473 // Convert uint16 to sint16
14691474 if ($ field ['base_type ' ] === 131 && isset ($ this ->data_mesg_info [$ mesg ['global_mesg_num ' ]]['field_defns ' ][$ field ['field_definition_number ' ]]['field_name ' ])) {
@@ -1501,8 +1506,11 @@ private function fixData($options)
15011506 } elseif ($ this ->data_mesgs [$ mesg_name ][$ field_name ] > 0x7FFFFFFF ) {
15021507 if (PHP_INT_SIZE === 8 ) {
15031508 $ this ->data_mesgs [$ mesg_name ][$ field_name ] -= 0x100000000 ;
1509+
1510+ }
1511+ if ( $ this ->data_mesgs [$ mesg_name ][$ field_name ] > 0x7FFFFFFF ){
1512+ $ this ->data_mesgs [$ mesg_name ][$ field_name ] = -1 * ($ this ->data_mesgs [$ mesg_name ][$ field_name ] - 0x7FFFFFFF );
15041513 }
1505- $ this ->data_mesgs [$ mesg_name ][$ field_name ] = -1 * ($ this ->data_mesgs [$ mesg_name ][$ field_name ] - 0x7FFFFFFF );
15061514 }
15071515 }
15081516 } // Convert uint64 to sint64
0 commit comments