@@ -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,11 +168,15 @@ 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 | - } 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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); |
@@ -323,10 +349,16 @@ discard block |
||
| 323 | 349 | $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
| 324 | 350 | $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
| 325 | 351 | |
| 326 | - if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
|
| 327 | - else $result['latitude'] += $lat_off; |
|
| 328 | - if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
|
| 329 | - else $result['longitude'] += $lon_off; |
|
| 352 | + if ($result['latitude'] < 0) { |
|
| 353 | + $result['latitude'] -= $lat_off; |
|
| 354 | + } else { |
|
| 355 | + $result['latitude'] += $lat_off; |
|
| 356 | + } |
|
| 357 | + if ($result['longitude'] < 0) { |
|
| 358 | + $result['longitude'] -= $lon_off; |
|
| 359 | + } else { |
|
| 360 | + $result['longitude'] += $lon_off; |
|
| 361 | + } |
|
| 330 | 362 | } |
| 331 | 363 | $body_parse = substr($body_parse,6); |
| 332 | 364 | } |
@@ -361,27 +393,48 @@ discard block |
||
| 361 | 393 | $address = substr($id,2); |
| 362 | 394 | //print_r($matches); |
| 363 | 395 | $addressType = (intval(substr($id,0,2),16))&3; |
| 364 | - if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
|
| 365 | - elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
|
| 366 | - elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
|
| 367 | - elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
|
| 396 | + if ($addressType == 0) { |
|
| 397 | + $result['addresstype'] = "RANDOM"; |
|
| 398 | + } elseif ($addressType == 1) { |
|
| 399 | + $result['addresstype'] = "ICAO"; |
|
| 400 | + } elseif ($addressType == 2) { |
|
| 401 | + $result['addresstype'] = "FLARM"; |
|
| 402 | + } elseif ($addressType == 3) { |
|
| 403 | + $result['addresstype'] = "OGN"; |
|
| 404 | + } |
|
| 368 | 405 | $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
| 369 | 406 | $result['aircrafttype_code'] = $aircraftType; |
| 370 | - if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
|
| 371 | - elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
|
| 372 | - elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE"; |
|
| 373 | - elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
| 374 | - elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE"; |
|
| 375 | - elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE"; |
|
| 376 | - elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER"; |
|
| 377 | - elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER"; |
|
| 378 | - elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
| 379 | - elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
| 380 | - elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO"; |
|
| 381 | - elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON"; |
|
| 382 | - elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
|
| 383 | - elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
|
| 384 | - elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
|
| 407 | + if ($aircraftType == 0) { |
|
| 408 | + $result['aircrafttype'] = "UNKNOWN"; |
|
| 409 | + } elseif ($aircraftType == 1) { |
|
| 410 | + $result['aircrafttype'] = "GLIDER"; |
|
| 411 | + } elseif ($aircraftType == 2) { |
|
| 412 | + $result['aircrafttype'] = "TOW_PLANE"; |
|
| 413 | + } elseif ($aircraftType == 3) { |
|
| 414 | + $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
| 415 | + } elseif ($aircraftType == 4) { |
|
| 416 | + $result['aircrafttype'] = "PARACHUTE"; |
|
| 417 | + } elseif ($aircraftType == 5) { |
|
| 418 | + $result['aircrafttype'] = "DROP_PLANE"; |
|
| 419 | + } elseif ($aircraftType == 6) { |
|
| 420 | + $result['aircrafttype'] = "HANG_GLIDER"; |
|
| 421 | + } elseif ($aircraftType == 7) { |
|
| 422 | + $result['aircrafttype'] = "PARA_GLIDER"; |
|
| 423 | + } elseif ($aircraftType == 8) { |
|
| 424 | + $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
| 425 | + } elseif ($aircraftType == 9) { |
|
| 426 | + $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
| 427 | + } elseif ($aircraftType == 10) { |
|
| 428 | + $result['aircrafttype'] = "UFO"; |
|
| 429 | + } elseif ($aircraftType == 11) { |
|
| 430 | + $result['aircrafttype'] = "BALLOON"; |
|
| 431 | + } elseif ($aircraftType == 12) { |
|
| 432 | + $result['aircrafttype'] = "AIRSHIP"; |
|
| 433 | + } elseif ($aircraftType == 13) { |
|
| 434 | + $result['aircrafttype'] = "UAV"; |
|
| 435 | + } elseif ($aircraftType == 15) { |
|
| 436 | + $result['aircrafttype'] = "STATIC_OBJECT"; |
|
| 437 | + } |
|
| 385 | 438 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
| 386 | 439 | $result['stealth'] = $stealth; |
| 387 | 440 | $result['address'] = $address; |
@@ -421,13 +474,21 @@ discard block |
||
| 421 | 474 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
| 422 | 475 | } |
| 423 | 476 | } |
| 424 | - } else $result['comment'] = trim($body_parse); |
|
| 477 | + } else { |
|
| 478 | + $result['comment'] = trim($body_parse); |
|
| 479 | + } |
|
| 425 | 480 | |
| 426 | 481 | } |
| 427 | 482 | //} |
| 428 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
| 429 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
| 430 | - if ($debug) print_r($result); |
|
| 483 | + if (isset($result['latitude'])) { |
|
| 484 | + $result['latitude'] = round($result['latitude'],4); |
|
| 485 | + } |
|
| 486 | + if (isset($result['longitude'])) { |
|
| 487 | + $result['longitude'] = round($result['longitude'],4); |
|
| 488 | + } |
|
| 489 | + if ($debug) { |
|
| 490 | + print_r($result); |
|
| 491 | + } |
|
| 431 | 492 | return $result; |
| 432 | 493 | } |
| 433 | 494 | |
@@ -436,12 +497,21 @@ discard block |
||
| 436 | 497 | $aprs_connect = 0; |
| 437 | 498 | $aprs_keep = 120; |
| 438 | 499 | $aprs_last_tx = time(); |
| 439 | - if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
|
| 440 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
| 441 | - if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid; |
|
| 442 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
| 443 | - if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass; |
|
| 444 | - else $aprs_pass = '-1'; |
|
| 500 | + if (isset($globalAPRSversion)) { |
|
| 501 | + $aprs_version = $globalAPRSversion; |
|
| 502 | + } else { |
|
| 503 | + $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
| 504 | + } |
|
| 505 | + if (isset($globalServerAPRSssid)) { |
|
| 506 | + $aprs_ssid = $globalServerAPRSssid; |
|
| 507 | + } else { |
|
| 508 | + $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
| 509 | + } |
|
| 510 | + if (isset($globalServerAPRSpass)) { |
|
| 511 | + $aprs_pass = $globalServerAPRSpass; |
|
| 512 | + } else { |
|
| 513 | + $aprs_pass = '-1'; |
|
| 514 | + } |
|
| 445 | 515 | |
| 446 | 516 | $aprs_filter = ''; |
| 447 | 517 | $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n"; |
@@ -468,9 +538,13 @@ discard block |
||
| 468 | 538 | } |
| 469 | 539 | |
| 470 | 540 | function send($data) { |
| 471 | - if ($this->connected === false) $this->connect(); |
|
| 541 | + if ($this->connected === false) { |
|
| 542 | + $this->connect(); |
|
| 543 | + } |
|
| 472 | 544 | $send = socket_send( $this->socket , $data , strlen($data),0); |
| 473 | - if ($send === FALSE) $this->connect(); |
|
| 545 | + if ($send === FALSE) { |
|
| 546 | + $this->connect(); |
|
| 547 | + } |
|
| 474 | 548 | } |
| 475 | 549 | } |
| 476 | 550 | |
@@ -487,18 +561,26 @@ discard block |
||
| 487 | 561 | //$w = '00'; |
| 488 | 562 | $custom = ''; |
| 489 | 563 | if ($ident != '') { |
| 490 | - if ($custom != '') $custom .= '/'; |
|
| 564 | + if ($custom != '') { |
|
| 565 | + $custom .= '/'; |
|
| 566 | + } |
|
| 491 | 567 | $custom .= 'CS='.$ident; |
| 492 | 568 | } |
| 493 | 569 | if ($squawk != '') { |
| 494 | - if ($custom != '') $custom .= '/'; |
|
| 570 | + if ($custom != '') { |
|
| 571 | + $custom .= '/'; |
|
| 572 | + } |
|
| 495 | 573 | $custom .= 'SQ='.$squawk; |
| 496 | 574 | } |
| 497 | 575 | if ($aircraft_icao != '' && $aircraft_icao != 'NA') { |
| 498 | - if ($custom != '') $custom .= '/'; |
|
| 576 | + if ($custom != '') { |
|
| 577 | + $custom .= '/'; |
|
| 578 | + } |
|
| 499 | 579 | $custom .= 'AI='.$aircraft_icao; |
| 500 | 580 | } |
| 501 | - if ($custom != '') $custom = ' '.$custom; |
|
| 581 | + if ($custom != '') { |
|
| 582 | + $custom = ' '.$custom; |
|
| 583 | + } |
|
| 502 | 584 | $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"); |
| 503 | 585 | } |
| 504 | 586 | } |
@@ -516,26 +598,38 @@ discard block |
||
| 516 | 598 | //$w = '00'; |
| 517 | 599 | $custom = ''; |
| 518 | 600 | if ($ident != '') { |
| 519 | - if ($custom != '') $custom .= '/'; |
|
| 601 | + if ($custom != '') { |
|
| 602 | + $custom .= '/'; |
|
| 603 | + } |
|
| 520 | 604 | $custom .= 'CS='.$ident; |
| 521 | 605 | } |
| 522 | 606 | if ($typeid != '') { |
| 523 | - if ($custom != '') $custom .= '/'; |
|
| 607 | + if ($custom != '') { |
|
| 608 | + $custom .= '/'; |
|
| 609 | + } |
|
| 524 | 610 | $custom .= 'TI='.$typeid; |
| 525 | 611 | } |
| 526 | 612 | if ($imo != '') { |
| 527 | - if ($custom != '') $custom .= '/'; |
|
| 613 | + if ($custom != '') { |
|
| 614 | + $custom .= '/'; |
|
| 615 | + } |
|
| 528 | 616 | $custom .= 'IMO='.$imo; |
| 529 | 617 | } |
| 530 | 618 | if ($arrival_date != '') { |
| 531 | - if ($custom != '') $custom .= '/'; |
|
| 619 | + if ($custom != '') { |
|
| 620 | + $custom .= '/'; |
|
| 621 | + } |
|
| 532 | 622 | $custom .= 'AD='.strtotime($arrival_date); |
| 533 | 623 | } |
| 534 | 624 | if ($arrival_code != '') { |
| 535 | - if ($custom != '') $custom .= '/'; |
|
| 625 | + if ($custom != '') { |
|
| 626 | + $custom .= '/'; |
|
| 627 | + } |
|
| 536 | 628 | $custom .= 'AC='.$arrival_code; |
| 537 | 629 | } |
| 538 | - if ($custom != '') $custom = ' '.$custom; |
|
| 630 | + if ($custom != '') { |
|
| 631 | + $custom = ' '.$custom; |
|
| 632 | + } |
|
| 539 | 633 | $altitude = 0; |
| 540 | 634 | $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"); |
| 541 | 635 | } |