@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class aprs { |
| 3 | - protected $symbols = array('!' => 'Police', |
|
| 3 | + protected $symbols = array('!' => 'Police', |
|
| 4 | 4 | '#' => 'DIGI', |
| 5 | 5 | '$' => 'Phone', |
| 6 | 6 | '%' => 'DX Cluster', |
@@ -84,13 +84,13 @@ discard block |
||
| 84 | 84 | 'y' => 'Yagi At QTH'); |
| 85 | 85 | |
| 86 | 86 | |
| 87 | - private function urshift($n, $s) { |
|
| 87 | + private function urshift($n, $s) { |
|
| 88 | 88 | return ($n >= 0) ? ($n >> $s) : |
| 89 | - (($n & 0x7fffffff) >> $s) | |
|
| 89 | + (($n & 0x7fffffff) >> $s) | |
|
| 90 | 90 | (0x40000000 >> ($s - 1)); |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function parse($input) { |
|
| 93 | + public function parse($input) { |
|
| 94 | 94 | global $globalDebug; |
| 95 | 95 | $debug = true; |
| 96 | 96 | $result = array(); |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | /* Check that end was found and body has at least one byte. */ |
| 104 | 104 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
| 105 | - if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
| 106 | - return false; |
|
| 105 | + if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
| 106 | + return false; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | if ($debug) echo 'input : '.$input."\n"; |
@@ -117,23 +117,23 @@ discard block |
||
| 117 | 117 | /* Parse source, target and path. */ |
| 118 | 118 | //FLRDF0A52>APRS,qAS,LSTB |
| 119 | 119 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
| 120 | - $ident = $matches[1]; |
|
| 121 | - $all_elements = $matches[2]; |
|
| 122 | - if ($debug) echo 'ident : '.$ident."\n"; |
|
| 123 | - $result['ident'] = $ident; |
|
| 120 | + $ident = $matches[1]; |
|
| 121 | + $all_elements = $matches[2]; |
|
| 122 | + if ($debug) echo 'ident : '.$ident."\n"; |
|
| 123 | + $result['ident'] = $ident; |
|
| 124 | 124 | } else return false; |
| 125 | 125 | $elements = explode(',',$all_elements); |
| 126 | 126 | $source = end($elements); |
| 127 | 127 | $result['source'] = $source; |
| 128 | 128 | foreach ($elements as $element) { |
| 129 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
| 130 | - //echo "ok"; |
|
| 131 | - //if ($element == 'TCPIP*') return false; |
|
| 132 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
| 129 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
| 130 | + //echo "ok"; |
|
| 131 | + //if ($element == 'TCPIP*') return false; |
|
| 132 | + } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
| 133 | 133 | if ($debug) echo 'element : '.$element."\n"; |
| 134 | 134 | return false; |
| 135 | - } |
|
| 136 | - /* |
|
| 135 | + } |
|
| 136 | + /* |
|
| 137 | 137 | } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) { |
| 138 | 138 | //echo "ok"; |
| 139 | 139 | } else { |
@@ -156,49 +156,49 @@ discard block |
||
| 156 | 156 | $body_parse = substr($body,1); |
| 157 | 157 | //echo 'Body : '.$body."\n"; |
| 158 | 158 | if (preg_match('/^;(.){9}\*/',$body,$matches)) { |
| 159 | - $body_parse = substr($body_parse,10); |
|
| 160 | - $find = true; |
|
| 161 | - //echo $body_parse."\n"; |
|
| 159 | + $body_parse = substr($body_parse,10); |
|
| 160 | + $find = true; |
|
| 161 | + //echo $body_parse."\n"; |
|
| 162 | 162 | } |
| 163 | 163 | if (preg_match('/^`(.*)\//',$body,$matches)) { |
| 164 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 165 | - $find = true; |
|
| 166 | - //echo $body_parse."\n"; |
|
| 164 | + $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 165 | + $find = true; |
|
| 166 | + //echo $body_parse."\n"; |
|
| 167 | 167 | } |
| 168 | 168 | if (preg_match("/^'(.*)\//",$body,$matches)) { |
| 169 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 170 | - $find = true; |
|
| 171 | - //echo $body_parse."\n"; |
|
| 169 | + $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 170 | + $find = true; |
|
| 171 | + //echo $body_parse."\n"; |
|
| 172 | 172 | } |
| 173 | 173 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
| 174 | - $find = true; |
|
| 175 | - //print_r($matches); |
|
| 176 | - $timestamp = $matches[0]; |
|
| 177 | - if ($matches[4] == 'h') { |
|
| 174 | + $find = true; |
|
| 175 | + //print_r($matches); |
|
| 176 | + $timestamp = $matches[0]; |
|
| 177 | + if ($matches[4] == 'h') { |
|
| 178 | 178 | $timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]); |
| 179 | 179 | //echo 'timestamp : '.$timestamp.' - now : '.time()."\n"; |
| 180 | 180 | /* |
| 181 | 181 | if (time() + 3900 < $timestamp) $timestamp -= 86400; |
| 182 | 182 | elseif (time() - 82500 > $timestamp) $timestamp += 86400; |
| 183 | 183 | */ |
| 184 | - } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
| 184 | + } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
| 185 | 185 | // This work or not ? |
| 186 | 186 | $timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]); |
| 187 | - } |
|
| 188 | - $body_parse = substr($body_parse,7); |
|
| 189 | - $result['timestamp'] = $timestamp; |
|
| 190 | - //echo date('Ymd H:i:s',$timestamp); |
|
| 187 | + } |
|
| 188 | + $body_parse = substr($body_parse,7); |
|
| 189 | + $result['timestamp'] = $timestamp; |
|
| 190 | + //echo date('Ymd H:i:s',$timestamp); |
|
| 191 | 191 | } |
| 192 | 192 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) { |
| 193 | - $find = true; |
|
| 194 | - $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
|
| 195 | - $body_parse = substr($body_parse,8); |
|
| 196 | - $result['timestamp'] = $timestamp; |
|
| 197 | - //echo date('Ymd H:i:s',$timestamp); |
|
| 193 | + $find = true; |
|
| 194 | + $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
|
| 195 | + $body_parse = substr($body_parse,8); |
|
| 196 | + $result['timestamp'] = $timestamp; |
|
| 197 | + //echo date('Ymd H:i:s',$timestamp); |
|
| 198 | 198 | } |
| 199 | 199 | //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)) { |
|
| 201 | - $find = true; |
|
| 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)) { |
|
| 201 | + $find = true; |
|
| 202 | 202 | // 4658.70N/00707.78Ez |
| 203 | 203 | //print_r(str_split($body_parse)); |
| 204 | 204 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $lon = intval($lon_deg); |
| 216 | 216 | if ($lat > 89 || $lon > 179) return false; |
| 217 | 217 | |
| 218 | - /* |
|
| 218 | + /* |
|
| 219 | 219 | $tmp_5b = str_replace('.','',$lat_min); |
| 220 | 220 | if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) { |
| 221 | 221 | print_r($matches); |
@@ -229,9 +229,9 @@ discard block |
||
| 229 | 229 | $result['longitude'] = $longitude; |
| 230 | 230 | $body_parse = substr($body_parse,18); |
| 231 | 231 | $body_parse_len = strlen($body_parse); |
| 232 | - } |
|
| 233 | - $body_parse_len = strlen($body_parse); |
|
| 234 | - if ($body_parse_len > 0) { |
|
| 232 | + } |
|
| 233 | + $body_parse_len = strlen($body_parse); |
|
| 234 | + if ($body_parse_len > 0) { |
|
| 235 | 235 | /* |
| 236 | 236 | if (!isset($result['timestamp']) && !isset($result['latitude'])) { |
| 237 | 237 | $body_split = str_split($body); |
@@ -260,64 +260,64 @@ discard block |
||
| 260 | 260 | if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
| 261 | 261 | if ($symbol_code != '_') { |
| 262 | 262 | } |
| 263 | - //$body_parse = substr($body_parse,1); |
|
| 264 | - //$body_parse = trim($body_parse); |
|
| 265 | - //$body_parse_len = strlen($body_parse); |
|
| 266 | - if ($body_parse_len >= 7) { |
|
| 263 | + //$body_parse = substr($body_parse,1); |
|
| 264 | + //$body_parse = trim($body_parse); |
|
| 265 | + //$body_parse_len = strlen($body_parse); |
|
| 266 | + if ($body_parse_len >= 7) { |
|
| 267 | 267 | |
| 268 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
| 269 | - $course = substr($body_parse,0,3); |
|
| 270 | - $tmp_s = intval($course); |
|
| 271 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
| 272 | - $speed = substr($body_parse,4,3); |
|
| 273 | - if ($speed != '...') { |
|
| 274 | - $result['speed'] = round($speed*1.852); |
|
| 275 | - } |
|
| 276 | - $body_parse = substr($body_parse,7); |
|
| 277 | - } |
|
| 278 | - // Check PHGR, PHG, RNG |
|
| 279 | - } |
|
| 280 | - /* |
|
| 268 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
| 269 | + $course = substr($body_parse,0,3); |
|
| 270 | + $tmp_s = intval($course); |
|
| 271 | + if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
| 272 | + $speed = substr($body_parse,4,3); |
|
| 273 | + if ($speed != '...') { |
|
| 274 | + $result['speed'] = round($speed*1.852); |
|
| 275 | + } |
|
| 276 | + $body_parse = substr($body_parse,7); |
|
| 277 | + } |
|
| 278 | + // Check PHGR, PHG, RNG |
|
| 279 | + } |
|
| 280 | + /* |
|
| 281 | 281 | else if ($body_parse_len > 0) { |
| 282 | 282 | $rest = $body_parse; |
| 283 | 283 | } |
| 284 | 284 | */ |
| 285 | - if (strlen($body_parse) > 0) { |
|
| 286 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
| 287 | - $altitude = intval($matches[1]); |
|
| 288 | - //$result['altitude'] = round($altitude*0.3048); |
|
| 289 | - $result['altitude'] = $altitude; |
|
| 290 | - //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
| 291 | - $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
|
| 292 | - } |
|
| 293 | - } |
|
| 285 | + if (strlen($body_parse) > 0) { |
|
| 286 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
| 287 | + $altitude = intval($matches[1]); |
|
| 288 | + //$result['altitude'] = round($altitude*0.3048); |
|
| 289 | + $result['altitude'] = $altitude; |
|
| 290 | + //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
| 291 | + $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - // Telemetry |
|
| 296 | - /* |
|
| 295 | + // Telemetry |
|
| 296 | + /* |
|
| 297 | 297 | if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) { |
| 298 | 298 | // Nothing yet... |
| 299 | 299 | } |
| 300 | 300 | */ |
| 301 | - // DAO |
|
| 302 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
| 303 | - $dao = $matches[1]; |
|
| 304 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
| 301 | + // DAO |
|
| 302 | + if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
| 303 | + $dao = $matches[1]; |
|
| 304 | + if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
| 305 | 305 | $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; |
|
| 306 | + $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
| 307 | + $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
| 308 | 308 | |
| 309 | 309 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
| 310 | 310 | else $result['latitude'] += $lat_off; |
| 311 | 311 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
| 312 | 312 | else $result['longitude'] += $lon_off; |
| 313 | - } |
|
| 314 | - $body_parse = substr($body_parse,6); |
|
| 315 | - } |
|
| 313 | + } |
|
| 314 | + $body_parse = substr($body_parse,6); |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - // OGN comment |
|
| 317 | + // OGN comment |
|
| 318 | 318 | // echo "Before OGN : ".$body_parse."\n"; |
| 319 | - //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}) ([+-])([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)) { |
|
| 321 | 321 | $id = $matches[1]; |
| 322 | 322 | //$mode = substr($id,0,2); |
| 323 | 323 | $address = substr($id,2); |
@@ -347,51 +347,51 @@ discard block |
||
| 347 | 347 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
| 348 | 348 | $result['stealth'] = $stealth; |
| 349 | 349 | $result['address'] = $address; |
| 350 | - } |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - //Comment |
|
| 353 | - $result['comment'] = trim($body_parse); |
|
| 352 | + //Comment |
|
| 353 | + $result['comment'] = trim($body_parse); |
|
| 354 | 354 | } else { |
| 355 | - // parse weather |
|
| 356 | - //$body_parse = substr($body_parse,1); |
|
| 357 | - //$body_parse_len = strlen($body_parse); |
|
| 355 | + // parse weather |
|
| 356 | + //$body_parse = substr($body_parse,1); |
|
| 357 | + //$body_parse_len = strlen($body_parse); |
|
| 358 | 358 | |
| 359 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 360 | - $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)) { |
|
| 359 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 360 | + $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)) { |
|
| 366 | 366 | $result['wind_dir'] = intval($matches[1]); |
| 367 | 367 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 368 | 368 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 369 | 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)) { |
|
| 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)) { |
|
| 372 | 372 | $result['wind_dir'] = intval($matches[1]); |
| 373 | 373 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 374 | 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)) { |
|
| 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)) { |
|
| 377 | 377 | $result['wind_dir'] = intval($matches[1]); |
| 378 | 378 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 379 | 379 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 380 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 381 | - } |
|
| 382 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
| 380 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 381 | + } |
|
| 382 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
| 383 | 383 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
| 384 | - } |
|
| 384 | + } |
|
| 385 | 385 | } |
| 386 | 386 | } else $result['comment'] = trim($body_parse); |
| 387 | 387 | |
| 388 | - } |
|
| 388 | + } |
|
| 389 | 389 | //} |
| 390 | 390 | if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
| 391 | 391 | if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
| 392 | 392 | if ($debug) print_r($result); |
| 393 | 393 | return $result; |
| 394 | - } |
|
| 394 | + } |
|
| 395 | 395 | } |
| 396 | 396 | /* |
| 397 | 397 | $aprs = new aprs(); |
@@ -102,26 +102,36 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | /* Check that end was found and body has at least one byte. */ |
| 104 | 104 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
| 105 | - if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
| 105 | + if ($globalDebug) { |
|
| 106 | + echo '!!! APRS invalid : '.$input."\n"; |
|
| 107 | + } |
|
| 106 | 108 | return false; |
| 107 | 109 | } |
| 108 | 110 | |
| 109 | - if ($debug) echo 'input : '.$input."\n"; |
|
| 111 | + if ($debug) { |
|
| 112 | + echo 'input : '.$input."\n"; |
|
| 113 | + } |
|
| 110 | 114 | /* Save header and body. */ |
| 111 | 115 | $body = substr($input,$splitpos+1,$input_len); |
| 112 | 116 | $body_len = strlen($body); |
| 113 | 117 | $header = substr($input,0,$splitpos); |
| 114 | 118 | //$header_len = strlen($header); |
| 115 | - if ($debug) echo 'header : '.$header."\n"; |
|
| 119 | + if ($debug) { |
|
| 120 | + echo 'header : '.$header."\n"; |
|
| 121 | + } |
|
| 116 | 122 | |
| 117 | 123 | /* Parse source, target and path. */ |
| 118 | 124 | //FLRDF0A52>APRS,qAS,LSTB |
| 119 | 125 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
| 120 | 126 | $ident = $matches[1]; |
| 121 | 127 | $all_elements = $matches[2]; |
| 122 | - if ($debug) echo 'ident : '.$ident."\n"; |
|
| 128 | + if ($debug) { |
|
| 129 | + echo 'ident : '.$ident."\n"; |
|
| 130 | + } |
|
| 123 | 131 | $result['ident'] = $ident; |
| 124 | - } else return false; |
|
| 132 | + } else { |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 125 | 135 | $elements = explode(',',$all_elements); |
| 126 | 136 | $source = end($elements); |
| 127 | 137 | $result['source'] = $source; |
@@ -130,7 +140,9 @@ discard block |
||
| 130 | 140 | //echo "ok"; |
| 131 | 141 | //if ($element == 'TCPIP*') return false; |
| 132 | 142 | } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
| 133 | - if ($debug) echo 'element : '.$element."\n"; |
|
| 143 | + if ($debug) { |
|
| 144 | + echo 'element : '.$element."\n"; |
|
| 145 | + } |
|
| 134 | 146 | return false; |
| 135 | 147 | } |
| 136 | 148 | /* |
@@ -143,7 +155,9 @@ discard block |
||
| 143 | 155 | } |
| 144 | 156 | |
| 145 | 157 | $type = substr($body,0,1); |
| 146 | - if ($debug) echo 'type : '.$type."\n"; |
|
| 158 | + if ($debug) { |
|
| 159 | + echo 'type : '.$type."\n"; |
|
| 160 | + } |
|
| 147 | 161 | if ($type == ';') { |
| 148 | 162 | $result['ident'] = trim(substr($body,1,9)); |
| 149 | 163 | } elseif ($type == ',') { |
@@ -213,7 +227,9 @@ discard block |
||
| 213 | 227 | //$symbol_table = $matches[4]; |
| 214 | 228 | $lat = intval($lat_deg); |
| 215 | 229 | $lon = intval($lon_deg); |
| 216 | - if ($lat > 89 || $lon > 179) return false; |
|
| 230 | + if ($lat > 89 || $lon > 179) { |
|
| 231 | + return false; |
|
| 232 | + } |
|
| 217 | 233 | |
| 218 | 234 | /* |
| 219 | 235 | $tmp_5b = str_replace('.','',$lat_min); |
@@ -223,8 +239,12 @@ discard block |
||
| 223 | 239 | */ |
| 224 | 240 | $latitude = $lat + floatval($lat_min)/60; |
| 225 | 241 | $longitude = $lon + floatval($lon_min)/60; |
| 226 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
| 227 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
| 242 | + if ($sind == 'S') { |
|
| 243 | + $latitude = 0-$latitude; |
|
| 244 | + } |
|
| 245 | + if ($wind == 'W') { |
|
| 246 | + $longitude = 0-$longitude; |
|
| 247 | + } |
|
| 228 | 248 | $result['latitude'] = $latitude; |
| 229 | 249 | $result['longitude'] = $longitude; |
| 230 | 250 | $body_parse = substr($body_parse,18); |
@@ -257,7 +277,9 @@ discard block |
||
| 257 | 277 | //echo $body_parse; |
| 258 | 278 | if ($type != ';') { |
| 259 | 279 | $result['symbol_code'] = $symbol_code; |
| 260 | - if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
|
| 280 | + if (isset($this->symbols[$symbol_code])) { |
|
| 281 | + $result['symbol'] = $this->symbols[$symbol_code]; |
|
| 282 | + } |
|
| 261 | 283 | if ($symbol_code != '_') { |
| 262 | 284 | } |
| 263 | 285 | //$body_parse = substr($body_parse,1); |
@@ -268,7 +290,9 @@ discard block |
||
| 268 | 290 | if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
| 269 | 291 | $course = substr($body_parse,0,3); |
| 270 | 292 | $tmp_s = intval($course); |
| 271 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
| 293 | + if ($tmp_s >= 1 && $tmp_s <= 360) { |
|
| 294 | + $result['heading'] = intval($course); |
|
| 295 | + } |
|
| 272 | 296 | $speed = substr($body_parse,4,3); |
| 273 | 297 | if ($speed != '...') { |
| 274 | 298 | $result['speed'] = round($speed*1.852); |
@@ -306,10 +330,16 @@ discard block |
||
| 306 | 330 | $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
| 307 | 331 | $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
| 308 | 332 | |
| 309 | - if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
|
| 310 | - else $result['latitude'] += $lat_off; |
|
| 311 | - if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
|
| 312 | - else $result['longitude'] += $lon_off; |
|
| 333 | + if ($result['latitude'] < 0) { |
|
| 334 | + $result['latitude'] -= $lat_off; |
|
| 335 | + } else { |
|
| 336 | + $result['latitude'] += $lat_off; |
|
| 337 | + } |
|
| 338 | + if ($result['longitude'] < 0) { |
|
| 339 | + $result['longitude'] -= $lon_off; |
|
| 340 | + } else { |
|
| 341 | + $result['longitude'] += $lon_off; |
|
| 342 | + } |
|
| 313 | 343 | } |
| 314 | 344 | $body_parse = substr($body_parse,6); |
| 315 | 345 | } |
@@ -323,27 +353,48 @@ discard block |
||
| 323 | 353 | $address = substr($id,2); |
| 324 | 354 | //print_r($matches); |
| 325 | 355 | $addressType = (intval(substr($id,0,2),16))&3; |
| 326 | - if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
|
| 327 | - elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
|
| 328 | - elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
|
| 329 | - elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
|
| 356 | + if ($addressType == 0) { |
|
| 357 | + $result['addresstype'] = "RANDOM"; |
|
| 358 | + } elseif ($addressType == 1) { |
|
| 359 | + $result['addresstype'] = "ICAO"; |
|
| 360 | + } elseif ($addressType == 2) { |
|
| 361 | + $result['addresstype'] = "FLARM"; |
|
| 362 | + } elseif ($addressType == 3) { |
|
| 363 | + $result['addresstype'] = "OGN"; |
|
| 364 | + } |
|
| 330 | 365 | $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
| 331 | 366 | $result['aircrafttype_code'] = $aircraftType; |
| 332 | - if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
|
| 333 | - elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
|
| 334 | - elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE"; |
|
| 335 | - elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
| 336 | - elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE"; |
|
| 337 | - elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE"; |
|
| 338 | - elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER"; |
|
| 339 | - elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER"; |
|
| 340 | - elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
| 341 | - elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
| 342 | - elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO"; |
|
| 343 | - elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON"; |
|
| 344 | - elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
|
| 345 | - elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
|
| 346 | - elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
|
| 367 | + if ($aircraftType == 0) { |
|
| 368 | + $result['aircrafttype'] = "UNKNOWN"; |
|
| 369 | + } elseif ($aircraftType == 1) { |
|
| 370 | + $result['aircrafttype'] = "GLIDER"; |
|
| 371 | + } elseif ($aircraftType == 2) { |
|
| 372 | + $result['aircrafttype'] = "TOW_PLANE"; |
|
| 373 | + } elseif ($aircraftType == 3) { |
|
| 374 | + $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
| 375 | + } elseif ($aircraftType == 4) { |
|
| 376 | + $result['aircrafttype'] = "PARACHUTE"; |
|
| 377 | + } elseif ($aircraftType == 5) { |
|
| 378 | + $result['aircrafttype'] = "DROP_PLANE"; |
|
| 379 | + } elseif ($aircraftType == 6) { |
|
| 380 | + $result['aircrafttype'] = "HANG_GLIDER"; |
|
| 381 | + } elseif ($aircraftType == 7) { |
|
| 382 | + $result['aircrafttype'] = "PARA_GLIDER"; |
|
| 383 | + } elseif ($aircraftType == 8) { |
|
| 384 | + $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
| 385 | + } elseif ($aircraftType == 9) { |
|
| 386 | + $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
| 387 | + } elseif ($aircraftType == 10) { |
|
| 388 | + $result['aircrafttype'] = "UFO"; |
|
| 389 | + } elseif ($aircraftType == 11) { |
|
| 390 | + $result['aircrafttype'] = "BALLOON"; |
|
| 391 | + } elseif ($aircraftType == 12) { |
|
| 392 | + $result['aircrafttype'] = "AIRSHIP"; |
|
| 393 | + } elseif ($aircraftType == 13) { |
|
| 394 | + $result['aircrafttype'] = "UAV"; |
|
| 395 | + } elseif ($aircraftType == 15) { |
|
| 396 | + $result['aircrafttype'] = "STATIC_OBJECT"; |
|
| 397 | + } |
|
| 347 | 398 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
| 348 | 399 | $result['stealth'] = $stealth; |
| 349 | 400 | $result['address'] = $address; |
@@ -383,13 +434,21 @@ discard block |
||
| 383 | 434 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
| 384 | 435 | } |
| 385 | 436 | } |
| 386 | - } else $result['comment'] = trim($body_parse); |
|
| 437 | + } else { |
|
| 438 | + $result['comment'] = trim($body_parse); |
|
| 439 | + } |
|
| 387 | 440 | |
| 388 | 441 | } |
| 389 | 442 | //} |
| 390 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
| 391 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
| 392 | - if ($debug) print_r($result); |
|
| 443 | + if (isset($result['latitude'])) { |
|
| 444 | + $result['latitude'] = round($result['latitude'],4); |
|
| 445 | + } |
|
| 446 | + if (isset($result['longitude'])) { |
|
| 447 | + $result['longitude'] = round($result['longitude'],4); |
|
| 448 | + } |
|
| 449 | + if ($debug) { |
|
| 450 | + print_r($result); |
|
| 451 | + } |
|
| 393 | 452 | return $result; |
| 394 | 453 | } |
| 395 | 454 | } |