@@ -2,10 +2,10 @@ discard block |
||
| 2 | 2 | require_once(dirname(__FILE__).'/settings.php'); |
| 3 | 3 | require_once(dirname(__FILE__).'/class.Common.php'); |
| 4 | 4 | class aprs { |
| 5 | - private $socket; |
|
| 6 | - private $connected = false; |
|
| 5 | + private $socket; |
|
| 6 | + private $connected = false; |
|
| 7 | 7 | |
| 8 | - protected $symbols = array('!' => 'Police', |
|
| 8 | + protected $symbols = array('!' => 'Police', |
|
| 9 | 9 | '#' => 'DIGI', |
| 10 | 10 | '$' => 'Phone', |
| 11 | 11 | '%' => 'DX Cluster', |
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | 'y' => 'Yagi At QTH'); |
| 90 | 90 | |
| 91 | 91 | |
| 92 | - private function urshift($n, $s) { |
|
| 92 | + private function urshift($n, $s) { |
|
| 93 | 93 | return ($n >= 0) ? ($n >> $s) : |
| 94 | - (($n & 0x7fffffff) >> $s) | |
|
| 94 | + (($n & 0x7fffffff) >> $s) | |
|
| 95 | 95 | (0x40000000 >> ($s - 1)); |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - public function parse($input) { |
|
| 98 | + public function parse($input) { |
|
| 99 | 99 | global $globalDebug; |
| 100 | 100 | $debug = false; |
| 101 | 101 | $result = array(); |
@@ -107,8 +107,8 @@ 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"; |
|
| 111 | - return false; |
|
| 110 | + if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
| 111 | + return false; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | if ($debug) echo 'input : '.$input."\n"; |
@@ -122,31 +122,31 @@ discard block |
||
| 122 | 122 | /* Parse source, target and path. */ |
| 123 | 123 | //FLRDF0A52>APRS,qAS,LSTB |
| 124 | 124 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
| 125 | - $ident = $matches[1]; |
|
| 126 | - $all_elements = $matches[2]; |
|
| 127 | - if ($ident == 'AIRCRAFT') { |
|
| 125 | + $ident = $matches[1]; |
|
| 126 | + $all_elements = $matches[2]; |
|
| 127 | + if ($ident == 'AIRCRAFT') { |
|
| 128 | 128 | $result['format_source'] = 'famaprs'; |
| 129 | 129 | $result['source_type'] = 'modes'; |
| 130 | - } elseif ($ident == 'MARINE') { |
|
| 130 | + } elseif ($ident == 'MARINE') { |
|
| 131 | 131 | $result['format_source'] = 'famaprs'; |
| 132 | 132 | $result['source_type'] = 'ais'; |
| 133 | - } else { |
|
| 133 | + } else { |
|
| 134 | 134 | if ($debug) echo 'ident : '.$ident."\n"; |
| 135 | 135 | $result['ident'] = $ident; |
| 136 | - } |
|
| 136 | + } |
|
| 137 | 137 | } else return false; |
| 138 | 138 | $elements = explode(',',$all_elements); |
| 139 | 139 | $source = end($elements); |
| 140 | 140 | $result['source'] = $source; |
| 141 | 141 | foreach ($elements as $element) { |
| 142 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
| 143 | - //echo "ok"; |
|
| 144 | - //if ($element == 'TCPIP*') return false; |
|
| 145 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
| 142 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
| 143 | + //echo "ok"; |
|
| 144 | + //if ($element == 'TCPIP*') return false; |
|
| 145 | + } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
| 146 | 146 | if ($debug) echo 'element : '.$element."\n"; |
| 147 | 147 | return false; |
| 148 | - } |
|
| 149 | - /* |
|
| 148 | + } |
|
| 149 | + /* |
|
| 150 | 150 | } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) { |
| 151 | 151 | //echo "ok"; |
| 152 | 152 | } else { |
@@ -173,49 +173,49 @@ discard block |
||
| 173 | 173 | $body_parse = substr($body,1); |
| 174 | 174 | //echo 'Body : '.$body."\n"; |
| 175 | 175 | if (preg_match('/^;(.){9}\*/',$body,$matches)) { |
| 176 | - $body_parse = substr($body_parse,10); |
|
| 177 | - $find = true; |
|
| 178 | - //echo $body_parse."\n"; |
|
| 176 | + $body_parse = substr($body_parse,10); |
|
| 177 | + $find = true; |
|
| 178 | + //echo $body_parse."\n"; |
|
| 179 | 179 | } |
| 180 | 180 | if (preg_match('/^`(.*)\//',$body,$matches)) { |
| 181 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 182 | - $find = true; |
|
| 183 | - //echo $body_parse."\n"; |
|
| 181 | + $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 182 | + $find = true; |
|
| 183 | + //echo $body_parse."\n"; |
|
| 184 | 184 | } |
| 185 | 185 | if (preg_match("/^'(.*)\//",$body,$matches)) { |
| 186 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 187 | - $find = true; |
|
| 188 | - //echo $body_parse."\n"; |
|
| 186 | + $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 187 | + $find = true; |
|
| 188 | + //echo $body_parse."\n"; |
|
| 189 | 189 | } |
| 190 | 190 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
| 191 | - $find = true; |
|
| 192 | - //print_r($matches); |
|
| 193 | - $timestamp = $matches[0]; |
|
| 194 | - if ($matches[4] == 'h') { |
|
| 191 | + $find = true; |
|
| 192 | + //print_r($matches); |
|
| 193 | + $timestamp = $matches[0]; |
|
| 194 | + if ($matches[4] == 'h') { |
|
| 195 | 195 | $timestamp = strtotime(date('Ymd').' '.$matches[1].':'.$matches[2].':'.$matches[3]); |
| 196 | 196 | //echo 'timestamp : '.$timestamp.' - now : '.time()."\n"; |
| 197 | 197 | /* |
| 198 | 198 | if (time() + 3900 < $timestamp) $timestamp -= 86400; |
| 199 | 199 | elseif (time() - 82500 > $timestamp) $timestamp += 86400; |
| 200 | 200 | */ |
| 201 | - } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
| 201 | + } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
| 202 | 202 | // This work or not ? |
| 203 | 203 | $timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]); |
| 204 | - } |
|
| 205 | - $body_parse = substr($body_parse,7); |
|
| 206 | - $result['timestamp'] = $timestamp; |
|
| 207 | - //echo date('Ymd H:i:s',$timestamp); |
|
| 204 | + } |
|
| 205 | + $body_parse = substr($body_parse,7); |
|
| 206 | + $result['timestamp'] = $timestamp; |
|
| 207 | + //echo date('Ymd H:i:s',$timestamp); |
|
| 208 | 208 | } |
| 209 | 209 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) { |
| 210 | - $find = true; |
|
| 211 | - $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
|
| 212 | - $body_parse = substr($body_parse,8); |
|
| 213 | - $result['timestamp'] = $timestamp; |
|
| 214 | - //echo date('Ymd H:i:s',$timestamp); |
|
| 210 | + $find = true; |
|
| 211 | + $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
|
| 212 | + $body_parse = substr($body_parse,8); |
|
| 213 | + $result['timestamp'] = $timestamp; |
|
| 214 | + //echo date('Ymd H:i:s',$timestamp); |
|
| 215 | 215 | } |
| 216 | 216 | //if (strlen($body_parse) > 19) { |
| 217 | - 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)) { |
|
| 218 | - $find = true; |
|
| 217 | + 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)) { |
|
| 218 | + $find = true; |
|
| 219 | 219 | // 4658.70N/00707.78Ez |
| 220 | 220 | //print_r(str_split($body_parse)); |
| 221 | 221 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | $lon = intval($lon_deg); |
| 233 | 233 | if ($lat > 89 || $lon > 179) return false; |
| 234 | 234 | |
| 235 | - /* |
|
| 235 | + /* |
|
| 236 | 236 | $tmp_5b = str_replace('.','',$lat_min); |
| 237 | 237 | if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) { |
| 238 | 238 | print_r($matches); |
@@ -246,9 +246,9 @@ discard block |
||
| 246 | 246 | $result['longitude'] = $longitude; |
| 247 | 247 | $body_parse = substr($body_parse,18); |
| 248 | 248 | $body_parse_len = strlen($body_parse); |
| 249 | - } |
|
| 250 | - $body_parse_len = strlen($body_parse); |
|
| 251 | - if ($body_parse_len > 0) { |
|
| 249 | + } |
|
| 250 | + $body_parse_len = strlen($body_parse); |
|
| 251 | + if ($body_parse_len > 0) { |
|
| 252 | 252 | /* |
| 253 | 253 | if (!isset($result['timestamp']) && !isset($result['latitude'])) { |
| 254 | 254 | $body_split = str_split($body); |
@@ -278,89 +278,89 @@ discard block |
||
| 278 | 278 | if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
| 279 | 279 | if ($symbol_code != '_') { |
| 280 | 280 | } |
| 281 | - //$body_parse = substr($body_parse,1); |
|
| 282 | - //$body_parse = trim($body_parse); |
|
| 283 | - //$body_parse_len = strlen($body_parse); |
|
| 284 | - if ($body_parse_len >= 7) { |
|
| 281 | + //$body_parse = substr($body_parse,1); |
|
| 282 | + //$body_parse = trim($body_parse); |
|
| 283 | + //$body_parse_len = strlen($body_parse); |
|
| 284 | + if ($body_parse_len >= 7) { |
|
| 285 | 285 | |
| 286 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
| 287 | - $course = substr($body_parse,0,3); |
|
| 288 | - $tmp_s = intval($course); |
|
| 289 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
| 290 | - $speed = substr($body_parse,4,3); |
|
| 291 | - if ($speed != '...') { |
|
| 292 | - //$result['speed'] = round($speed*1.852); |
|
| 293 | - $result['speed'] = intval($speed); |
|
| 294 | - } |
|
| 295 | - $body_parse = substr($body_parse,7); |
|
| 296 | - } |
|
| 297 | - // Check PHGR, PHG, RNG |
|
| 298 | - } |
|
| 299 | - /* |
|
| 286 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
| 287 | + $course = substr($body_parse,0,3); |
|
| 288 | + $tmp_s = intval($course); |
|
| 289 | + if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
| 290 | + $speed = substr($body_parse,4,3); |
|
| 291 | + if ($speed != '...') { |
|
| 292 | + //$result['speed'] = round($speed*1.852); |
|
| 293 | + $result['speed'] = intval($speed); |
|
| 294 | + } |
|
| 295 | + $body_parse = substr($body_parse,7); |
|
| 296 | + } |
|
| 297 | + // Check PHGR, PHG, RNG |
|
| 298 | + } |
|
| 299 | + /* |
|
| 300 | 300 | else if ($body_parse_len > 0) { |
| 301 | 301 | $rest = $body_parse; |
| 302 | 302 | } |
| 303 | 303 | */ |
| 304 | - if (strlen($body_parse) > 0) { |
|
| 305 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
| 306 | - $altitude = intval($matches[1]); |
|
| 307 | - //$result['altitude'] = round($altitude*0.3048); |
|
| 308 | - $result['altitude'] = $altitude; |
|
| 309 | - //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
| 310 | - $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
|
| 311 | - } |
|
| 312 | - } |
|
| 304 | + if (strlen($body_parse) > 0) { |
|
| 305 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
| 306 | + $altitude = intval($matches[1]); |
|
| 307 | + //$result['altitude'] = round($altitude*0.3048); |
|
| 308 | + $result['altitude'] = $altitude; |
|
| 309 | + //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
| 310 | + $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - // Telemetry |
|
| 315 | - /* |
|
| 314 | + // Telemetry |
|
| 315 | + /* |
|
| 316 | 316 | 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)) { |
| 317 | 317 | // Nothing yet... |
| 318 | 318 | } |
| 319 | 319 | */ |
| 320 | - // DAO |
|
| 320 | + // DAO |
|
| 321 | 321 | |
| 322 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
| 322 | + if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
| 323 | 323 | |
| 324 | - $dao = $matches[1]; |
|
| 325 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
| 324 | + $dao = $matches[1]; |
|
| 325 | + if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
| 326 | 326 | $dao_split = str_split($dao); |
| 327 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
| 328 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
| 327 | + $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
| 328 | + $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
| 329 | 329 | |
| 330 | 330 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
| 331 | 331 | else $result['latitude'] += $lat_off; |
| 332 | 332 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
| 333 | 333 | else $result['longitude'] += $lon_off; |
| 334 | - } |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - $body_parse = substr($body_parse,6); |
|
| 337 | - } |
|
| 336 | + $body_parse = substr($body_parse,6); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) { |
|
| 339 | + if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) { |
|
| 340 | 340 | $result['ident'] = $matches[1]; |
| 341 | - } |
|
| 342 | - if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) { |
|
| 341 | + } |
|
| 342 | + if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) { |
|
| 343 | 343 | $result['squawk'] = $matches[1]; |
| 344 | - } |
|
| 345 | - if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) { |
|
| 344 | + } |
|
| 345 | + if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) { |
|
| 346 | 346 | $result['aircraft_icao'] = $matches[1]; |
| 347 | - } |
|
| 348 | - if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) { |
|
| 347 | + } |
|
| 348 | + if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) { |
|
| 349 | 349 | $result['typeid'] = $matches[1]; |
| 350 | - } |
|
| 351 | - if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
|
| 350 | + } |
|
| 351 | + if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
|
| 352 | 352 | $result['imo'] = $matches[1]; |
| 353 | - } |
|
| 354 | - if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
|
| 353 | + } |
|
| 354 | + if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
|
| 355 | 355 | $result['arrival_date'] = $matches[1]; |
| 356 | - } |
|
| 357 | - if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) { |
|
| 356 | + } |
|
| 357 | + if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) { |
|
| 358 | 358 | $result['arrival_code'] = $matches[1]; |
| 359 | - } |
|
| 360 | - // OGN comment |
|
| 359 | + } |
|
| 360 | + // OGN comment |
|
| 361 | 361 | // echo "Before OGN : ".$body_parse."\n"; |
| 362 | - //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
| 363 | - if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
| 362 | + //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
| 363 | + if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
| 364 | 364 | $id = $matches[1]; |
| 365 | 365 | //$mode = substr($id,0,2); |
| 366 | 366 | $address = substr($id,2); |
@@ -390,53 +390,53 @@ discard block |
||
| 390 | 390 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
| 391 | 391 | $result['stealth'] = $stealth; |
| 392 | 392 | $result['address'] = $address; |
| 393 | - } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - //Comment |
|
| 396 | - $result['comment'] = trim($body_parse); |
|
| 395 | + //Comment |
|
| 396 | + $result['comment'] = trim($body_parse); |
|
| 397 | 397 | } else { |
| 398 | - // parse weather |
|
| 399 | - //$body_parse = substr($body_parse,1); |
|
| 400 | - //$body_parse_len = strlen($body_parse); |
|
| 398 | + // parse weather |
|
| 399 | + //$body_parse = substr($body_parse,1); |
|
| 400 | + //$body_parse_len = strlen($body_parse); |
|
| 401 | 401 | |
| 402 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 403 | - $result['wind_dir'] = intval($matches[1]); |
|
| 404 | - $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
| 405 | - $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
| 406 | - $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
|
| 407 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 408 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 402 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 403 | + $result['wind_dir'] = intval($matches[1]); |
|
| 404 | + $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
| 405 | + $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
| 406 | + $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
|
| 407 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 408 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 409 | 409 | $result['wind_dir'] = intval($matches[1]); |
| 410 | 410 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 411 | 411 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 412 | 412 | $result['temp'] = round(5/9*(($matches[4])-32),1); |
| 413 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 414 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 413 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 414 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 415 | 415 | $result['wind_dir'] = intval($matches[1]); |
| 416 | 416 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 417 | 417 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 418 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 419 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 418 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 419 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 420 | 420 | $result['wind_dir'] = intval($matches[1]); |
| 421 | 421 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 422 | 422 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 423 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 424 | - } |
|
| 425 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
| 423 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 424 | + } |
|
| 425 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
| 426 | 426 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
| 427 | - } |
|
| 427 | + } |
|
| 428 | 428 | } |
| 429 | 429 | } else $result['comment'] = trim($body_parse); |
| 430 | 430 | |
| 431 | - } |
|
| 431 | + } |
|
| 432 | 432 | //} |
| 433 | 433 | if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
| 434 | 434 | if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
| 435 | 435 | if ($debug) print_r($result); |
| 436 | 436 | return $result; |
| 437 | - } |
|
| 437 | + } |
|
| 438 | 438 | |
| 439 | - public function connect() { |
|
| 439 | + public function connect() { |
|
| 440 | 440 | global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport; |
| 441 | 441 | $aprs_connect = 0; |
| 442 | 442 | $aprs_keep = 120; |
@@ -459,32 +459,32 @@ discard block |
||
| 459 | 459 | $send = socket_send( $this->socket , $aprs_login , strlen($aprs_login) , 0 ); |
| 460 | 460 | while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) { |
| 461 | 461 | if (strpos($msgin, "$aprs_ssid verified") !== FALSE) { |
| 462 | - echo 'APRS user verified !'."\n"; |
|
| 463 | - $this->connected = true; |
|
| 464 | - return true; |
|
| 465 | - break; |
|
| 462 | + echo 'APRS user verified !'."\n"; |
|
| 463 | + $this->connected = true; |
|
| 464 | + return true; |
|
| 465 | + break; |
|
| 466 | 466 | } |
| 467 | 467 | if (time()-$authstart > 5) { |
| 468 | - echo 'APRS timeout'."\n"; |
|
| 469 | - break; |
|
| 468 | + echo 'APRS timeout'."\n"; |
|
| 469 | + break; |
|
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | socket_set_option($this->socket,SOL_SOCKET,SO_KEEPALIVE); |
| 473 | 473 | } |
| 474 | - } |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | - public function disconnect() { |
|
| 476 | + public function disconnect() { |
|
| 477 | 477 | socket_close($this->socket); |
| 478 | - } |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - public function send($data) { |
|
| 480 | + public function send($data) { |
|
| 481 | 481 | if ($this->connected === false) $this->connect(); |
| 482 | 482 | $send = socket_send( $this->socket , $data , strlen($data),0); |
| 483 | 483 | if ($send === FALSE) { |
| 484 | 484 | socket_close($this->socket); |
| 485 | 485 | $this->connect(); |
| 486 | 486 | } |
| 487 | - } |
|
| 487 | + } |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | class APRSSpotter extends APRS { |