@@ -107,17 +107,23 @@ discard block |
||
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 |
||
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 |
||
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,13 +168,17 @@ discard block |
||
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'] == 'modes') { |
162 | 176 | $result['address'] = trim(substr($body,1,9)); |
163 | 177 | } elseif (isset($result['source_type']) && $result['source_type'] == 'ais') { |
164 | 178 | $result['mmsi'] = trim(substr($body,1,9)); |
165 | - } else $result['ident'] = trim(substr($body,1,9)); |
|
179 | + } else { |
|
180 | + $result['ident'] = trim(substr($body,1,9)); |
|
181 | + } |
|
166 | 182 | } elseif ($type == ',') { |
167 | 183 | // Invalid data or test data |
168 | 184 | return false; |
@@ -230,7 +246,9 @@ discard block |
||
230 | 246 | //$symbol_table = $matches[4]; |
231 | 247 | $lat = intval($lat_deg); |
232 | 248 | $lon = intval($lon_deg); |
233 | - if ($lat > 89 || $lon > 179) return false; |
|
249 | + if ($lat > 89 || $lon > 179) { |
|
250 | + return false; |
|
251 | + } |
|
234 | 252 | |
235 | 253 | /* |
236 | 254 | $tmp_5b = str_replace('.','',$lat_min); |
@@ -240,8 +258,12 @@ discard block |
||
240 | 258 | */ |
241 | 259 | $latitude = $lat + floatval($lat_min)/60; |
242 | 260 | $longitude = $lon + floatval($lon_min)/60; |
243 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
244 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
261 | + if ($sind == 'S') { |
|
262 | + $latitude = 0-$latitude; |
|
263 | + } |
|
264 | + if ($wind == 'W') { |
|
265 | + $longitude = 0-$longitude; |
|
266 | + } |
|
245 | 267 | $result['latitude'] = $latitude; |
246 | 268 | $result['longitude'] = $longitude; |
247 | 269 | $body_parse = substr($body_parse,18); |
@@ -275,7 +297,9 @@ discard block |
||
275 | 297 | $body_parse = substr($body_parse,1); |
276 | 298 | $body_parse_len = strlen($body_parse); |
277 | 299 | $result['symbol_code'] = $symbol_code; |
278 | - if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
|
300 | + if (isset($this->symbols[$symbol_code])) { |
|
301 | + $result['symbol'] = $this->symbols[$symbol_code]; |
|
302 | + } |
|
279 | 303 | if ($symbol_code != '_') { |
280 | 304 | } |
281 | 305 | //$body_parse = substr($body_parse,1); |
@@ -286,7 +310,9 @@ discard block |
||
286 | 310 | if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
287 | 311 | $course = substr($body_parse,0,3); |
288 | 312 | $tmp_s = intval($course); |
289 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
313 | + if ($tmp_s >= 1 && $tmp_s <= 360) { |
|
314 | + $result['heading'] = intval($course); |
|
315 | + } |
|
290 | 316 | $speed = substr($body_parse,4,3); |
291 | 317 | if ($speed != '...') { |
292 | 318 | //$result['speed'] = round($speed*1.852); |
@@ -327,10 +353,16 @@ discard block |
||
327 | 353 | $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
328 | 354 | $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
329 | 355 | |
330 | - if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
|
331 | - else $result['latitude'] += $lat_off; |
|
332 | - if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
|
333 | - else $result['longitude'] += $lon_off; |
|
356 | + if ($result['latitude'] < 0) { |
|
357 | + $result['latitude'] -= $lat_off; |
|
358 | + } else { |
|
359 | + $result['latitude'] += $lat_off; |
|
360 | + } |
|
361 | + if ($result['longitude'] < 0) { |
|
362 | + $result['longitude'] -= $lon_off; |
|
363 | + } else { |
|
364 | + $result['longitude'] += $lon_off; |
|
365 | + } |
|
334 | 366 | } |
335 | 367 | |
336 | 368 | $body_parse = substr($body_parse,6); |
@@ -372,27 +404,48 @@ discard block |
||
372 | 404 | $address = substr($id,2); |
373 | 405 | //print_r($matches); |
374 | 406 | $addressType = (intval(substr($id,0,2),16))&3; |
375 | - if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
|
376 | - elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
|
377 | - elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
|
378 | - elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
|
407 | + if ($addressType == 0) { |
|
408 | + $result['addresstype'] = "RANDOM"; |
|
409 | + } elseif ($addressType == 1) { |
|
410 | + $result['addresstype'] = "ICAO"; |
|
411 | + } elseif ($addressType == 2) { |
|
412 | + $result['addresstype'] = "FLARM"; |
|
413 | + } elseif ($addressType == 3) { |
|
414 | + $result['addresstype'] = "OGN"; |
|
415 | + } |
|
379 | 416 | $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
380 | 417 | $result['aircrafttype_code'] = $aircraftType; |
381 | - if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
|
382 | - elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
|
383 | - elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE"; |
|
384 | - elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
385 | - elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE"; |
|
386 | - elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE"; |
|
387 | - elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER"; |
|
388 | - elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER"; |
|
389 | - elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
390 | - elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
391 | - elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO"; |
|
392 | - elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON"; |
|
393 | - elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
|
394 | - elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
|
395 | - elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
|
418 | + if ($aircraftType == 0) { |
|
419 | + $result['aircrafttype'] = "UNKNOWN"; |
|
420 | + } elseif ($aircraftType == 1) { |
|
421 | + $result['aircrafttype'] = "GLIDER"; |
|
422 | + } elseif ($aircraftType == 2) { |
|
423 | + $result['aircrafttype'] = "TOW_PLANE"; |
|
424 | + } elseif ($aircraftType == 3) { |
|
425 | + $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
426 | + } elseif ($aircraftType == 4) { |
|
427 | + $result['aircrafttype'] = "PARACHUTE"; |
|
428 | + } elseif ($aircraftType == 5) { |
|
429 | + $result['aircrafttype'] = "DROP_PLANE"; |
|
430 | + } elseif ($aircraftType == 6) { |
|
431 | + $result['aircrafttype'] = "HANG_GLIDER"; |
|
432 | + } elseif ($aircraftType == 7) { |
|
433 | + $result['aircrafttype'] = "PARA_GLIDER"; |
|
434 | + } elseif ($aircraftType == 8) { |
|
435 | + $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
436 | + } elseif ($aircraftType == 9) { |
|
437 | + $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
438 | + } elseif ($aircraftType == 10) { |
|
439 | + $result['aircrafttype'] = "UFO"; |
|
440 | + } elseif ($aircraftType == 11) { |
|
441 | + $result['aircrafttype'] = "BALLOON"; |
|
442 | + } elseif ($aircraftType == 12) { |
|
443 | + $result['aircrafttype'] = "AIRSHIP"; |
|
444 | + } elseif ($aircraftType == 13) { |
|
445 | + $result['aircrafttype'] = "UAV"; |
|
446 | + } elseif ($aircraftType == 15) { |
|
447 | + $result['aircrafttype'] = "STATIC_OBJECT"; |
|
448 | + } |
|
396 | 449 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
397 | 450 | $result['stealth'] = $stealth; |
398 | 451 | $result['address'] = $address; |
@@ -432,13 +485,21 @@ discard block |
||
432 | 485 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
433 | 486 | } |
434 | 487 | } |
435 | - } else $result['comment'] = trim($body_parse); |
|
488 | + } else { |
|
489 | + $result['comment'] = trim($body_parse); |
|
490 | + } |
|
436 | 491 | |
437 | 492 | } |
438 | 493 | //} |
439 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
440 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
441 | - if ($debug) print_r($result); |
|
494 | + if (isset($result['latitude'])) { |
|
495 | + $result['latitude'] = round($result['latitude'],4); |
|
496 | + } |
|
497 | + if (isset($result['longitude'])) { |
|
498 | + $result['longitude'] = round($result['longitude'],4); |
|
499 | + } |
|
500 | + if ($debug) { |
|
501 | + print_r($result); |
|
502 | + } |
|
442 | 503 | return $result; |
443 | 504 | } |
444 | 505 | |
@@ -447,12 +508,21 @@ discard block |
||
447 | 508 | $aprs_connect = 0; |
448 | 509 | $aprs_keep = 120; |
449 | 510 | $aprs_last_tx = time(); |
450 | - if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
|
451 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
452 | - if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid; |
|
453 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
454 | - if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass; |
|
455 | - else $aprs_pass = '-1'; |
|
511 | + if (isset($globalAPRSversion)) { |
|
512 | + $aprs_version = $globalAPRSversion; |
|
513 | + } else { |
|
514 | + $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
515 | + } |
|
516 | + if (isset($globalServerAPRSssid)) { |
|
517 | + $aprs_ssid = $globalServerAPRSssid; |
|
518 | + } else { |
|
519 | + $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
520 | + } |
|
521 | + if (isset($globalServerAPRSpass)) { |
|
522 | + $aprs_pass = $globalServerAPRSpass; |
|
523 | + } else { |
|
524 | + $aprs_pass = '-1'; |
|
525 | + } |
|
456 | 526 | |
457 | 527 | $aprs_filter = ''; |
458 | 528 | $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n"; |
@@ -485,10 +555,14 @@ discard block |
||
485 | 555 | |
486 | 556 | public function send($data) { |
487 | 557 | global $globalDebug; |
488 | - if ($this->connected === false) $this->connect(); |
|
558 | + if ($this->connected === false) { |
|
559 | + $this->connect(); |
|
560 | + } |
|
489 | 561 | $send = socket_send( $this->socket , $data , strlen($data),0); |
490 | 562 | if ($send === FALSE) { |
491 | - if ($globalDebug) echo 'Reconnect...'; |
|
563 | + if ($globalDebug) { |
|
564 | + echo 'Reconnect...'; |
|
565 | + } |
|
492 | 566 | socket_close($this->socket); |
493 | 567 | $this->connect(); |
494 | 568 | } |
@@ -508,22 +582,32 @@ discard block |
||
508 | 582 | //$w = '00'; |
509 | 583 | $custom = ''; |
510 | 584 | if ($ident != '') { |
511 | - if ($custom != '') $custom .= '/'; |
|
585 | + if ($custom != '') { |
|
586 | + $custom .= '/'; |
|
587 | + } |
|
512 | 588 | $custom .= 'CS='.$ident; |
513 | 589 | } |
514 | 590 | if ($squawk != '') { |
515 | - if ($custom != '') $custom .= '/'; |
|
591 | + if ($custom != '') { |
|
592 | + $custom .= '/'; |
|
593 | + } |
|
516 | 594 | $custom .= 'SQ='.$squawk; |
517 | 595 | } |
518 | 596 | if ($verticalrate != '') { |
519 | - if ($custom != '') $custom .= '/'; |
|
597 | + if ($custom != '') { |
|
598 | + $custom .= '/'; |
|
599 | + } |
|
520 | 600 | $custom .= 'VR='.$verticalrate; |
521 | 601 | } |
522 | 602 | if ($aircraft_icao != '' && $aircraft_icao != 'NA') { |
523 | - if ($custom != '') $custom .= '/'; |
|
603 | + if ($custom != '') { |
|
604 | + $custom .= '/'; |
|
605 | + } |
|
524 | 606 | $custom .= 'AI='.$aircraft_icao; |
525 | 607 | } |
526 | - if ($custom != '') $custom = ' '.$custom; |
|
608 | + if ($custom != '') { |
|
609 | + $custom = ' '.$custom; |
|
610 | + } |
|
527 | 611 | $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"); |
528 | 612 | } |
529 | 613 | } |
@@ -541,30 +625,44 @@ discard block |
||
541 | 625 | //$w = '00'; |
542 | 626 | $custom = ''; |
543 | 627 | if ($ident != '') { |
544 | - if ($custom != '') $custom .= '/'; |
|
628 | + if ($custom != '') { |
|
629 | + $custom .= '/'; |
|
630 | + } |
|
545 | 631 | $custom .= 'CS='.str_replace(' ','_',$ident); |
546 | 632 | } |
547 | 633 | if ($typeid != '') { |
548 | - if ($custom != '') $custom .= '/'; |
|
634 | + if ($custom != '') { |
|
635 | + $custom .= '/'; |
|
636 | + } |
|
549 | 637 | $custom .= 'TI='.$typeid; |
550 | 638 | } |
551 | 639 | if ($statusid != '') { |
552 | - if ($custom != '') $custom .= '/'; |
|
640 | + if ($custom != '') { |
|
641 | + $custom .= '/'; |
|
642 | + } |
|
553 | 643 | $custom .= 'SI='.$statusid; |
554 | 644 | } |
555 | 645 | if ($imo != '') { |
556 | - if ($custom != '') $custom .= '/'; |
|
646 | + if ($custom != '') { |
|
647 | + $custom .= '/'; |
|
648 | + } |
|
557 | 649 | $custom .= 'IMO='.$imo; |
558 | 650 | } |
559 | 651 | if ($arrival_date != '') { |
560 | - if ($custom != '') $custom .= '/'; |
|
652 | + if ($custom != '') { |
|
653 | + $custom .= '/'; |
|
654 | + } |
|
561 | 655 | $custom .= 'AD='.strtotime($arrival_date); |
562 | 656 | } |
563 | 657 | if ($arrival_code != '') { |
564 | - if ($custom != '') $custom .= '/'; |
|
658 | + if ($custom != '') { |
|
659 | + $custom .= '/'; |
|
660 | + } |
|
565 | 661 | $custom .= 'AC='.str_replace(' ','_',$arrival_code); |
566 | 662 | } |
567 | - if ($custom != '') $custom = ' '.$custom; |
|
663 | + if ($custom != '') { |
|
664 | + $custom = ' '.$custom; |
|
665 | + } |
|
568 | 666 | $altitude = 0; |
569 | 667 | $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"); |
570 | 668 | } |