@@ -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(); |