Completed
Push — master ( bbb05e...031847 )
by Yannick
08:59
created
require/class.APRS.php 1 patch
Spacing   +64 added lines, -65 removed lines patch added patch discarded remove patch
@@ -85,8 +85,7 @@  discard block
 block discarded – undo
85 85
 	
86 86
 
87 87
     private function urshift($n, $s) {
88
-	return ($n >= 0) ? ($n >> $s) :
89
-	    (($n & 0x7fffffff) >> $s) | 
88
+	return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| 
90 89
 		(0x40000000 >> ($s - 1));
91 90
     }
92 91
 
@@ -98,7 +97,7 @@  discard block
 block discarded – undo
98 97
 	//$split_input = str_split($input);
99 98
 
100 99
 	/* Find the end of header checking for NULL bytes while doing it. */
101
-	$splitpos = strpos($input,':');
100
+	$splitpos = strpos($input, ':');
102 101
 	
103 102
 	/* Check that end was found and body has at least one byte. */
104 103
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
@@ -108,28 +107,28 @@  discard block
 block discarded – undo
108 107
 	
109 108
 	if ($debug) echo 'input : '.$input."\n";
110 109
 	/* Save header and body. */
111
-	$body = substr($input,$splitpos+1,$input_len);
110
+	$body = substr($input, $splitpos + 1, $input_len);
112 111
 	$body_len = strlen($body);
113
-	$header = substr($input,0,$splitpos);
112
+	$header = substr($input, 0, $splitpos);
114 113
 	//$header_len = strlen($header);
115 114
 	if ($debug) echo 'header : '.$header."\n";
116 115
 	
117 116
 	/* Parse source, target and path. */
118 117
 	//FLRDF0A52>APRS,qAS,LSTB
119
-	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
118
+	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) {
120 119
 	    $ident = $matches[1];
121 120
 	    $all_elements = $matches[2];
122 121
 	    if ($debug) echo 'ident : '.$ident."\n";
123 122
 	    $result['ident'] = $ident;
124 123
 	} else return false;
125
-	$elements = explode(',',$all_elements);
124
+	$elements = explode(',', $all_elements);
126 125
 	$source = end($elements);
127 126
 	$result['source'] = $source;
128 127
 	foreach ($elements as $element) {
129
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
128
+	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) {
130 129
 	        //echo "ok";
131 130
 	        //if ($element == 'TCPIP*') return false;
132
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
131
+	    } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) {
133 132
 		if ($debug) echo 'element : '.$element."\n";
134 133
 		return false;
135 134
 	    }
@@ -142,10 +141,10 @@  discard block
 block discarded – undo
142 141
 	    */
143 142
 	}
144 143
 	
145
-	$type = substr($body,0,1);
144
+	$type = substr($body, 0, 1);
146 145
 	if ($debug) echo 'type : '.$type."\n";
147 146
 	if ($type == ';') {
148
-		$result['ident'] = trim(substr($body,1,9));
147
+		$result['ident'] = trim(substr($body, 1, 9));
149 148
 	} elseif ($type == ',') {
150 149
 		// Invalid data or test data
151 150
 		return false;
@@ -153,24 +152,24 @@  discard block
 block discarded – undo
153 152
 	
154 153
 	// Check for Timestamp
155 154
 	$find = false;
156
-	$body_parse = substr($body,1);
155
+	$body_parse = substr($body, 1);
157 156
 	//echo 'Body : '.$body."\n";
158
-	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
159
-	    $body_parse = substr($body_parse,10);
157
+	if (preg_match('/^;(.){9}\*/', $body, $matches)) {
158
+	    $body_parse = substr($body_parse, 10);
160 159
 	    $find = true;
161 160
 	    //echo $body_parse."\n";
162 161
 	}
163
-	if (preg_match('/^`(.*)\//',$body,$matches)) {
164
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
162
+	if (preg_match('/^`(.*)\//', $body, $matches)) {
163
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
165 164
 	    $find = true;
166 165
 	    //echo $body_parse."\n";
167 166
 	}
168
-	if (preg_match("/^'(.*)\//",$body,$matches)) {
169
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
167
+	if (preg_match("/^'(.*)\//", $body, $matches)) {
168
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
170 169
 	    $find = true;
171 170
 	    //echo $body_parse."\n";
172 171
 	}
173
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
172
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) {
174 173
 	    $find = true;
175 174
 	    //print_r($matches);
176 175
 	    $timestamp = $matches[0];
@@ -185,19 +184,19 @@  discard block
 block discarded – undo
185 184
 		// This work or not ?
186 185
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
187 186
 	    }
188
-	    $body_parse = substr($body_parse,7);
187
+	    $body_parse = substr($body_parse, 7);
189 188
 	    $result['timestamp'] = $timestamp;
190 189
 	    //echo date('Ymd H:i:s',$timestamp);
191 190
 	}
192
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
191
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $body_parse, $matches)) {
193 192
 	    $find = true;
194 193
 	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
195
-	    $body_parse = substr($body_parse,8);
194
+	    $body_parse = substr($body_parse, 8);
196 195
 	    $result['timestamp'] = $timestamp;
197 196
 	    //echo date('Ymd H:i:s',$timestamp);
198 197
 	}
199 198
 	//if (strlen($body_parse) > 19) {
200
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
199
+	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/', $body_parse, $matches)) {
201 200
 	    $find = true;
202 201
 		// 4658.70N/00707.78Ez
203 202
 		//print_r(str_split($body_parse));
@@ -223,11 +222,11 @@  discard block
 block discarded – undo
223 222
 	    */
224 223
 		$latitude = $lat + floatval($lat_min)/60;
225 224
 		$longitude = $lon + floatval($lon_min)/60;
226
-		if ($sind == 'S') $latitude = 0-$latitude;
227
-		if ($wind == 'W') $longitude = 0-$longitude;
225
+		if ($sind == 'S') $latitude = 0 - $latitude;
226
+		if ($wind == 'W') $longitude = 0 - $longitude;
228 227
 		$result['latitude'] = $latitude;
229 228
 		$result['longitude'] = $longitude;
230
-		$body_parse = substr($body_parse,18);
229
+		$body_parse = substr($body_parse, 18);
231 230
 		$body_parse_len = strlen($body_parse);
232 231
 	    }
233 232
 	    $body_parse_len = strlen($body_parse);
@@ -251,7 +250,7 @@  discard block
 block discarded – undo
251 250
 		if ($find) {
252 251
 			$body_split = str_split($body_parse);
253 252
 			$symbol_code = $body_split[0];
254
-			$body_parse = substr($body_parse,1);
253
+			$body_parse = substr($body_parse, 1);
255 254
 			$body_parse_len = strlen($body_parse);
256 255
 		//}
257 256
 		//echo $body_parse;
@@ -265,15 +264,15 @@  discard block
 block discarded – undo
265 264
 		    //$body_parse_len = strlen($body_parse);
266 265
 		    if ($body_parse_len >= 7) {
267 266
 			
268
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
269
-		    	    $course = substr($body_parse,0,3);
267
+		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) {
268
+		    	    $course = substr($body_parse, 0, 3);
270 269
 		    	    $tmp_s = intval($course);
271 270
 		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
272
-		    	    $speed = substr($body_parse,4,3);
271
+		    	    $speed = substr($body_parse, 4, 3);
273 272
 		    	    if ($speed != '...') {
274 273
 		    		    $result['speed'] = round($speed*1.852);
275 274
 		    	    }
276
-		    	    $body_parse = substr($body_parse,7);
275
+		    	    $body_parse = substr($body_parse, 7);
277 276
 		        }
278 277
 		        // Check PHGR, PHG, RNG
279 278
 		    } 
@@ -283,12 +282,12 @@  discard block
 block discarded – undo
283 282
 		    }
284 283
 		    */
285 284
 		    if (strlen($body_parse) > 0) {
286
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
285
+		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) {
287 286
 		            $altitude = intval($matches[1]);
288 287
 		            //$result['altitude'] = round($altitude*0.3048);
289 288
 		            $result['altitude'] = $altitude;
290 289
 		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
291
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
290
+		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/', '', $body_parse));
292 291
 		        }
293 292
 		    }
294 293
 		    
@@ -299,35 +298,35 @@  discard block
 block discarded – undo
299 298
 		    }
300 299
 		    */
301 300
 		    // DAO
302
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
301
+		    if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) {
303 302
 			    $dao = $matches[1];
304
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
303
+			    if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) {
305 304
 				$dao_split = str_split($dao);
306
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
307
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
305
+			        $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0;
306
+			        $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0;
308 307
 			    
309 308
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
310 309
 				else $result['latitude'] += $lat_off;
311 310
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
312 311
 				else $result['longitude'] += $lon_off;
313 312
 			    }
314
-		            $body_parse = substr($body_parse,6);
313
+		            $body_parse = substr($body_parse, 6);
315 314
 		    }
316 315
 		    
317 316
 		    // OGN comment
318 317
 		   // echo "Before OGN : ".$body_parse."\n";
319 318
 		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
320
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
319
+		    if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) {
321 320
 			$id = $matches[1];
322 321
 			//$mode = substr($id,0,2);
323
-			$address = substr($id,2);
322
+			$address = substr($id, 2);
324 323
 			//print_r($matches);
325
-			$addressType = (intval(substr($id,0,2),16))&3;
324
+			$addressType = (intval(substr($id, 0, 2), 16))&3;
326 325
 			if ($addressType == 0) $result['addresstype'] = "RANDOM";
327 326
 			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
328 327
 			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
329 328
 			elseif ($addressType == 3) $result['addresstype'] = "OGN";
330
-			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
329
+			$aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2);
331 330
 			$result['aircrafttype_code'] = $aircraftType;
332 331
 			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
333 332
 			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
@@ -344,7 +343,7 @@  discard block
 block discarded – undo
344 343
 			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
345 344
 			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
346 345
 			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
347
-			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
346
+			$stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0;
348 347
 			$result['stealth'] = $stealth;
349 348
 			$result['address'] = $address;
350 349
 		    }
@@ -356,39 +355,39 @@  discard block
 block discarded – undo
356 355
 		    //$body_parse = substr($body_parse,1);
357 356
 		    //$body_parse_len = strlen($body_parse);
358 357
 
359
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
358
+		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
360 359
 			    $result['wind_dir'] = intval($matches[1]);
361
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
362
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
363
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
364
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
365
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
360
+			    $result['wind_speed'] = round(intval($matches[2])*1.60934, 1);
361
+			    $result['wind_gust'] = round(intval($matches[3])*1.60934, 1);
362
+			    $result['temp'] = round(5/9*((intval($matches[4])) - 32), 1);
363
+		    	    $body_parse = substr($body_parse, strlen($matches[0]) + 1);
364
+		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
366 365
 			$result['wind_dir'] = intval($matches[1]);
367
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
368
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
369
-			$result['temp'] = round(5/9*(($matches[4])-32),1);
370
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
371
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
366
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
367
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
368
+			$result['temp'] = round(5/9*(($matches[4]) - 32), 1);
369
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
370
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
372 371
 			$result['wind_dir'] = intval($matches[1]);
373
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
374
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
375
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
376
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
372
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
373
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
374
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
375
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) {
377 376
 			$result['wind_dir'] = intval($matches[1]);
378
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
379
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
380
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
377
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
378
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
379
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
381 380
 		    }
382
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
383
-			$result['temp'] = round(5/9*(($matches[1])-32),1);
381
+		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) {
382
+			$result['temp'] = round(5/9*(($matches[1]) - 32), 1);
384 383
 		    }
385 384
 		}
386 385
 		} else $result['comment'] = trim($body_parse);
387 386
 
388 387
 	    }
389 388
 	//}
390
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
391
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
389
+	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4);
390
+	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4);
392 391
 	if ($debug) print_r($result);
393 392
 	return $result;
394 393
     }
Please login to merge, or discard this patch.