@@ -1104,14 +1104,26 @@ class phpFITFileAnalysis
1104
1104
];
1105
1105
1106
1106
// 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 )
1108
1108
{
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
+
1114
1125
}
1126
+
1115
1127
$ this ->options = $ options ;
1116
1128
if (isset ($ options ['garmin_timestamps ' ]) && $ options ['garmin_timestamps ' ] == true ) {
1117
1129
$ this ->garmin_timestamps = true ;
@@ -1122,13 +1134,6 @@ public function __construct($file_path, $options = null)
1122
1134
}
1123
1135
$ this ->php_trader_ext_loaded = extension_loaded ('trader ' );
1124
1136
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
-
1132
1137
// Process the file contents.
1133
1138
$ this ->readHeader ();
1134
1139
$ this ->readDataRecords ();
@@ -1190,7 +1195,6 @@ private function readDataRecords()
1190
1195
$ local_mesg_type = 0 ;
1191
1196
$ previousTS = 0 ;
1192
1197
1193
-
1194
1198
while ($ this ->file_header ['header_size ' ] + $ this ->file_header ['data_size ' ] > $ this ->file_pointer ) {
1195
1199
$ record_header_byte = ord (substr ($ this ->file_contents , $ this ->file_pointer , 1 ));
1196
1200
$ this ->file_pointer ++;
@@ -1464,6 +1468,7 @@ private function fixData($options)
1464
1468
if (isset ($ this ->data_mesg_info [$ mesg ['global_mesg_num ' ]])) {
1465
1469
$ mesg_name = $ this ->data_mesg_info [$ mesg ['global_mesg_num ' ]]['mesg_name ' ];
1466
1470
1471
+
1467
1472
foreach ($ mesg ['field_defns ' ] as $ field ) {
1468
1473
// Convert uint16 to sint16
1469
1474
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)
1501
1506
} elseif ($ this ->data_mesgs [$ mesg_name ][$ field_name ] > 0x7FFFFFFF ) {
1502
1507
if (PHP_INT_SIZE === 8 ) {
1503
1508
$ 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 );
1504
1513
}
1505
- $ this ->data_mesgs [$ mesg_name ][$ field_name ] = -1 * ($ this ->data_mesgs [$ mesg_name ][$ field_name ] - 0x7FFFFFFF );
1506
1514
}
1507
1515
}
1508
1516
} // Convert uint64 to sint64
0 commit comments