Completed
Push — master ( 31d65f...71c11a )
by Yannick
08:06
created
require/class.APRS.php 1 patch
Braces   +152 added lines, -58 removed lines patch added patch discarded remove patch
@@ -107,17 +107,23 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+	    if ($globalDebug) {
111
+	    	echo '!!! APRS invalid : '.$input."\n";
112
+	    }
111 113
 	    return false;
112 114
 	}
113 115
 	
114
-	if ($debug) echo 'input : '.$input."\n";
116
+	if ($debug) {
117
+		echo 'input : '.$input."\n";
118
+	}
115 119
 	/* Save header and body. */
116 120
 	$body = substr($input,$splitpos+1,$input_len);
117 121
 	$body_len = strlen($body);
118 122
 	$header = substr($input,0,$splitpos);
119 123
 	//$header_len = strlen($header);
120
-	if ($debug) echo 'header : '.$header."\n";
124
+	if ($debug) {
125
+		echo 'header : '.$header."\n";
126
+	}
121 127
 	
122 128
 	/* Parse source, target and path. */
123 129
 	//FLRDF0A52>APRS,qAS,LSTB
@@ -131,10 +137,14 @@  discard block
 block discarded – undo
131 137
 		$result['format_source'] = 'famaprs';
132 138
 		$result['source_type'] = 'ais';
133 139
 	    } else {
134
-		if ($debug) echo 'ident : '.$ident."\n";
140
+		if ($debug) {
141
+			echo 'ident : '.$ident."\n";
142
+		}
135 143
 		$result['ident'] = $ident;
136 144
 	    }
137
-	} else return false;
145
+	} else {
146
+		return false;
147
+	}
138 148
 	$elements = explode(',',$all_elements);
139 149
 	$source = end($elements);
140 150
 	$result['source'] = $source;
@@ -143,7 +153,9 @@  discard block
 block discarded – undo
143 153
 	        //echo "ok";
144 154
 	        //if ($element == 'TCPIP*') return false;
145 155
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146
-		if ($debug) echo 'element : '.$element."\n";
156
+		if ($debug) {
157
+			echo 'element : '.$element."\n";
158
+		}
147 159
 		return false;
148 160
 	    }
149 161
 	    /*
@@ -156,11 +168,15 @@  discard block
 block discarded – undo
156 168
 	}
157 169
 	
158 170
 	$type = substr($body,0,1);
159
-	if ($debug) echo 'type : '.$type."\n";
171
+	if ($debug) {
172
+		echo 'type : '.$type."\n";
173
+	}
160 174
 	if ($type == ';') {
161 175
 		if (isset($result['source_type']) && $result['source_type'] == 'sbs') {
162 176
 			$result['address'] = trim(substr($body,1,9));
163
-		} else $result['ident'] = trim(substr($body,1,9));
177
+		} else {
178
+			$result['ident'] = trim(substr($body,1,9));
179
+		}
164 180
 	} elseif ($type == ',') {
165 181
 		// Invalid data or test data
166 182
 		return false;
@@ -228,7 +244,9 @@  discard block
 block discarded – undo
228 244
 		//$symbol_table = $matches[4];
229 245
 		$lat = intval($lat_deg);
230 246
 		$lon = intval($lon_deg);
231
-		if ($lat > 89 || $lon > 179) return false;
247
+		if ($lat > 89 || $lon > 179) {
248
+			return false;
249
+		}
232 250
 	    
233 251
 	    /*
234 252
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -238,8 +256,12 @@  discard block
 block discarded – undo
238 256
 	    */
239 257
 		$latitude = $lat + floatval($lat_min)/60;
240 258
 		$longitude = $lon + floatval($lon_min)/60;
241
-		if ($sind == 'S') $latitude = 0-$latitude;
242
-		if ($wind == 'W') $longitude = 0-$longitude;
259
+		if ($sind == 'S') {
260
+			$latitude = 0-$latitude;
261
+		}
262
+		if ($wind == 'W') {
263
+			$longitude = 0-$longitude;
264
+		}
243 265
 		$result['latitude'] = $latitude;
244 266
 		$result['longitude'] = $longitude;
245 267
 		$body_parse = substr($body_parse,18);
@@ -273,7 +295,9 @@  discard block
 block discarded – undo
273 295
 			$body_parse = substr($body_parse,1);
274 296
 			$body_parse_len = strlen($body_parse);
275 297
 			$result['symbol_code'] = $symbol_code;
276
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
298
+			if (isset($this->symbols[$symbol_code])) {
299
+				$result['symbol'] = $this->symbols[$symbol_code];
300
+			}
277 301
 			if ($symbol_code != '_') {
278 302
 			}
279 303
 		    //$body_parse = substr($body_parse,1);
@@ -284,7 +308,9 @@  discard block
 block discarded – undo
284 308
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285 309
 		    	    $course = substr($body_parse,0,3);
286 310
 		    	    $tmp_s = intval($course);
287
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
311
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
312
+		    	    	$result['heading'] = intval($course);
313
+		    	    }
288 314
 		    	    $speed = substr($body_parse,4,3);
289 315
 		    	    if ($speed != '...') {
290 316
 		    		    $result['speed'] = round($speed*1.852);
@@ -322,10 +348,16 @@  discard block
 block discarded – undo
322 348
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
323 349
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
324 350
 			    
325
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
326
-				else $result['latitude'] += $lat_off;
327
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
328
-				else $result['longitude'] += $lon_off;
351
+				if ($result['latitude'] < 0) {
352
+					$result['latitude'] -= $lat_off;
353
+				} else {
354
+					$result['latitude'] += $lat_off;
355
+				}
356
+				if ($result['longitude'] < 0) {
357
+					$result['longitude'] -= $lon_off;
358
+				} else {
359
+					$result['longitude'] += $lon_off;
360
+				}
329 361
 			    }
330 362
 		            $body_parse = substr($body_parse,6);
331 363
 		    }
@@ -360,27 +392,48 @@  discard block
 block discarded – undo
360 392
 			$address = substr($id,2);
361 393
 			//print_r($matches);
362 394
 			$addressType = (intval(substr($id,0,2),16))&3;
363
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
364
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
365
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
366
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
395
+			if ($addressType == 0) {
396
+				$result['addresstype'] = "RANDOM";
397
+			} elseif ($addressType == 1) {
398
+				$result['addresstype'] = "ICAO";
399
+			} elseif ($addressType == 2) {
400
+				$result['addresstype'] = "FLARM";
401
+			} elseif ($addressType == 3) {
402
+				$result['addresstype'] = "OGN";
403
+			}
367 404
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
368 405
 			$result['aircrafttype_code'] = $aircraftType;
369
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
370
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
371
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
372
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
373
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
374
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
375
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
376
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
377
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
378
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
379
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
380
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
381
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
382
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
383
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
406
+			if ($aircraftType == 0) {
407
+				$result['aircrafttype'] = "UNKNOWN";
408
+			} elseif ($aircraftType == 1) {
409
+				$result['aircrafttype'] = "GLIDER";
410
+			} elseif ($aircraftType == 2) {
411
+				$result['aircrafttype'] = "TOW_PLANE";
412
+			} elseif ($aircraftType == 3) {
413
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
414
+			} elseif ($aircraftType == 4) {
415
+				$result['aircrafttype'] = "PARACHUTE";
416
+			} elseif ($aircraftType == 5) {
417
+				$result['aircrafttype'] = "DROP_PLANE";
418
+			} elseif ($aircraftType == 6) {
419
+				$result['aircrafttype'] = "HANG_GLIDER";
420
+			} elseif ($aircraftType == 7) {
421
+				$result['aircrafttype'] = "PARA_GLIDER";
422
+			} elseif ($aircraftType == 8) {
423
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
424
+			} elseif ($aircraftType == 9) {
425
+				$result['aircrafttype'] = "JET_AIRCRAFT";
426
+			} elseif ($aircraftType == 10) {
427
+				$result['aircrafttype'] = "UFO";
428
+			} elseif ($aircraftType == 11) {
429
+				$result['aircrafttype'] = "BALLOON";
430
+			} elseif ($aircraftType == 12) {
431
+				$result['aircrafttype'] = "AIRSHIP";
432
+			} elseif ($aircraftType == 13) {
433
+				$result['aircrafttype'] = "UAV";
434
+			} elseif ($aircraftType == 15) {
435
+				$result['aircrafttype'] = "STATIC_OBJECT";
436
+			}
384 437
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
385 438
 			$result['stealth'] = $stealth;
386 439
 			$result['address'] = $address;
@@ -420,13 +473,21 @@  discard block
 block discarded – undo
420 473
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
421 474
 		    }
422 475
 		}
423
-		} else $result['comment'] = trim($body_parse);
476
+		} else {
477
+			$result['comment'] = trim($body_parse);
478
+		}
424 479
 
425 480
 	    }
426 481
 	//}
427
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
428
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
429
-	if ($debug) print_r($result);
482
+	if (isset($result['latitude'])) {
483
+		$result['latitude'] = round($result['latitude'],4);
484
+	}
485
+	if (isset($result['longitude'])) {
486
+		$result['longitude'] = round($result['longitude'],4);
487
+	}
488
+	if ($debug) {
489
+		print_r($result);
490
+	}
430 491
 	return $result;
431 492
     }
432 493
     
@@ -435,12 +496,21 @@  discard block
 block discarded – undo
435 496
 	$aprs_connect = 0;
436 497
 	$aprs_keep = 120;
437 498
 	$aprs_last_tx = time();
438
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
439
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
440
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
441
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
442
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
443
-	else $aprs_pass = '-1';
499
+	if (isset($globalAPRSversion)) {
500
+		$aprs_version = $globalAPRSversion;
501
+	} else {
502
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
503
+	}
504
+	if (isset($globalServerAPRSssid)) {
505
+		$aprs_ssid = $globalServerAPRSssid;
506
+	} else {
507
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
508
+	}
509
+	if (isset($globalServerAPRSpass)) {
510
+		$aprs_pass = $globalServerAPRSpass;
511
+	} else {
512
+		$aprs_pass = '-1';
513
+	}
444 514
 	
445 515
 	$aprs_filter  = '';
446 516
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -467,9 +537,13 @@  discard block
 block discarded – undo
467 537
     }
468 538
     
469 539
     function send($data) {
470
-	if ($this->connected === false) $this->connect();
540
+	if ($this->connected === false) {
541
+		$this->connect();
542
+	}
471 543
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
472
-	if ($send === FALSE) $this->connect();
544
+	if ($send === FALSE) {
545
+		$this->connect();
546
+	}
473 547
     }
474 548
 }
475 549
 
@@ -486,18 +560,26 @@  discard block
 block discarded – undo
486 560
 			//$w = '00';
487 561
 			$custom = '';
488 562
 			if ($ident != '') {
489
-				if ($custom != '') $custom .= '/';
563
+				if ($custom != '') {
564
+					$custom .= '/';
565
+				}
490 566
 				$custom .= 'CS='.$ident;
491 567
 			}
492 568
 			if ($squawk != '') {
493
-				if ($custom != '') $custom .= '/';
569
+				if ($custom != '') {
570
+					$custom .= '/';
571
+				}
494 572
 				$custom .= 'SQ='.$squawk;
495 573
 			}
496 574
 			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
497
-				if ($custom != '') $custom .= '/';
575
+				if ($custom != '') {
576
+					$custom .= '/';
577
+				}
498 578
 				$custom .= 'AI='.$aircraft_icao;
499 579
 			}
500
-			if ($custom != '') $custom = ' '.$custom;
580
+			if ($custom != '') {
581
+				$custom = ' '.$custom;
582
+			}
501 583
 			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
502 584
 		}
503 585
 	}
@@ -515,26 +597,38 @@  discard block
 block discarded – undo
515 597
 			//$w = '00';
516 598
 			$custom = '';
517 599
 			if ($ident != '') {
518
-				if ($custom != '') $custom .= '/';
600
+				if ($custom != '') {
601
+					$custom .= '/';
602
+				}
519 603
 				$custom .= 'CS='.$ident;
520 604
 			}
521 605
 			if ($typeid != '') {
522
-				if ($custom != '') $custom .= '/';
606
+				if ($custom != '') {
607
+					$custom .= '/';
608
+				}
523 609
 				$custom .= 'TI='.$typeid;
524 610
 			}
525 611
 			if ($imo != '') {
526
-				if ($custom != '') $custom .= '/';
612
+				if ($custom != '') {
613
+					$custom .= '/';
614
+				}
527 615
 				$custom .= 'IMO='.$imo;
528 616
 			}
529 617
 			if ($arrival_date != '') {
530
-				if ($custom != '') $custom .= '/';
618
+				if ($custom != '') {
619
+					$custom .= '/';
620
+				}
531 621
 				$custom .= 'AD='.strtotime($arrival_date);
532 622
 			}
533 623
 			if ($arrival_code != '') {
534
-				if ($custom != '') $custom .= '/';
624
+				if ($custom != '') {
625
+					$custom .= '/';
626
+				}
535 627
 				$custom .= 'AC='.$arrival_code;
536 628
 			}
537
-			if ($custom != '') $custom = ' '.$custom;
629
+			if ($custom != '') {
630
+				$custom = ' '.$custom;
631
+			}
538 632
 			$altitude = 0;
539 633
 			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
540 634
 		}
Please login to merge, or discard this patch.