@@ -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 { |
@@ -171,49 +171,49 @@ discard block |
||
| 171 | 171 | $body_parse = substr($body,1); |
| 172 | 172 | //echo 'Body : '.$body."\n"; |
| 173 | 173 | if (preg_match('/^;(.){9}\*/',$body,$matches)) { |
| 174 | - $body_parse = substr($body_parse,10); |
|
| 175 | - $find = true; |
|
| 176 | - //echo $body_parse."\n"; |
|
| 174 | + $body_parse = substr($body_parse,10); |
|
| 175 | + $find = true; |
|
| 176 | + //echo $body_parse."\n"; |
|
| 177 | 177 | } |
| 178 | 178 | if (preg_match('/^`(.*)\//',$body,$matches)) { |
| 179 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 180 | - $find = true; |
|
| 181 | - //echo $body_parse."\n"; |
|
| 179 | + $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 180 | + $find = true; |
|
| 181 | + //echo $body_parse."\n"; |
|
| 182 | 182 | } |
| 183 | 183 | if (preg_match("/^'(.*)\//",$body,$matches)) { |
| 184 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 185 | - $find = true; |
|
| 186 | - //echo $body_parse."\n"; |
|
| 184 | + $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
| 185 | + $find = true; |
|
| 186 | + //echo $body_parse."\n"; |
|
| 187 | 187 | } |
| 188 | 188 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
| 189 | - $find = true; |
|
| 190 | - //print_r($matches); |
|
| 191 | - $timestamp = $matches[0]; |
|
| 192 | - if ($matches[4] == 'h') { |
|
| 189 | + $find = true; |
|
| 190 | + //print_r($matches); |
|
| 191 | + $timestamp = $matches[0]; |
|
| 192 | + if ($matches[4] == 'h') { |
|
| 193 | 193 | $timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]); |
| 194 | 194 | //echo 'timestamp : '.$timestamp.' - now : '.time()."\n"; |
| 195 | 195 | /* |
| 196 | 196 | if (time() + 3900 < $timestamp) $timestamp -= 86400; |
| 197 | 197 | elseif (time() - 82500 > $timestamp) $timestamp += 86400; |
| 198 | 198 | */ |
| 199 | - } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
| 199 | + } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
| 200 | 200 | // This work or not ? |
| 201 | 201 | $timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]); |
| 202 | - } |
|
| 203 | - $body_parse = substr($body_parse,7); |
|
| 204 | - $result['timestamp'] = $timestamp; |
|
| 205 | - //echo date('Ymd H:i:s',$timestamp); |
|
| 202 | + } |
|
| 203 | + $body_parse = substr($body_parse,7); |
|
| 204 | + $result['timestamp'] = $timestamp; |
|
| 205 | + //echo date('Ymd H:i:s',$timestamp); |
|
| 206 | 206 | } |
| 207 | 207 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) { |
| 208 | - $find = true; |
|
| 209 | - $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
|
| 210 | - $body_parse = substr($body_parse,8); |
|
| 211 | - $result['timestamp'] = $timestamp; |
|
| 212 | - //echo date('Ymd H:i:s',$timestamp); |
|
| 208 | + $find = true; |
|
| 209 | + $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
|
| 210 | + $body_parse = substr($body_parse,8); |
|
| 211 | + $result['timestamp'] = $timestamp; |
|
| 212 | + //echo date('Ymd H:i:s',$timestamp); |
|
| 213 | 213 | } |
| 214 | 214 | //if (strlen($body_parse) > 19) { |
| 215 | - 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)) { |
|
| 216 | - $find = true; |
|
| 215 | + 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)) { |
|
| 216 | + $find = true; |
|
| 217 | 217 | // 4658.70N/00707.78Ez |
| 218 | 218 | //print_r(str_split($body_parse)); |
| 219 | 219 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | $lon = intval($lon_deg); |
| 231 | 231 | if ($lat > 89 || $lon > 179) return false; |
| 232 | 232 | |
| 233 | - /* |
|
| 233 | + /* |
|
| 234 | 234 | $tmp_5b = str_replace('.','',$lat_min); |
| 235 | 235 | if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) { |
| 236 | 236 | print_r($matches); |
@@ -244,9 +244,9 @@ discard block |
||
| 244 | 244 | $result['longitude'] = $longitude; |
| 245 | 245 | $body_parse = substr($body_parse,18); |
| 246 | 246 | $body_parse_len = strlen($body_parse); |
| 247 | - } |
|
| 248 | - $body_parse_len = strlen($body_parse); |
|
| 249 | - if ($body_parse_len > 0) { |
|
| 247 | + } |
|
| 248 | + $body_parse_len = strlen($body_parse); |
|
| 249 | + if ($body_parse_len > 0) { |
|
| 250 | 250 | /* |
| 251 | 251 | if (!isset($result['timestamp']) && !isset($result['latitude'])) { |
| 252 | 252 | $body_split = str_split($body); |
@@ -276,86 +276,86 @@ discard block |
||
| 276 | 276 | if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
| 277 | 277 | if ($symbol_code != '_') { |
| 278 | 278 | } |
| 279 | - //$body_parse = substr($body_parse,1); |
|
| 280 | - //$body_parse = trim($body_parse); |
|
| 281 | - //$body_parse_len = strlen($body_parse); |
|
| 282 | - if ($body_parse_len >= 7) { |
|
| 279 | + //$body_parse = substr($body_parse,1); |
|
| 280 | + //$body_parse = trim($body_parse); |
|
| 281 | + //$body_parse_len = strlen($body_parse); |
|
| 282 | + if ($body_parse_len >= 7) { |
|
| 283 | 283 | |
| 284 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
| 285 | - $course = substr($body_parse,0,3); |
|
| 286 | - $tmp_s = intval($course); |
|
| 287 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
| 288 | - $speed = substr($body_parse,4,3); |
|
| 289 | - if ($speed != '...') { |
|
| 290 | - //$result['speed'] = round($speed*1.852); |
|
| 291 | - $result['speed'] = intval($speed); |
|
| 292 | - } |
|
| 293 | - $body_parse = substr($body_parse,7); |
|
| 294 | - } |
|
| 295 | - // Check PHGR, PHG, RNG |
|
| 296 | - } |
|
| 297 | - /* |
|
| 284 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
| 285 | + $course = substr($body_parse,0,3); |
|
| 286 | + $tmp_s = intval($course); |
|
| 287 | + if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
| 288 | + $speed = substr($body_parse,4,3); |
|
| 289 | + if ($speed != '...') { |
|
| 290 | + //$result['speed'] = round($speed*1.852); |
|
| 291 | + $result['speed'] = intval($speed); |
|
| 292 | + } |
|
| 293 | + $body_parse = substr($body_parse,7); |
|
| 294 | + } |
|
| 295 | + // Check PHGR, PHG, RNG |
|
| 296 | + } |
|
| 297 | + /* |
|
| 298 | 298 | else if ($body_parse_len > 0) { |
| 299 | 299 | $rest = $body_parse; |
| 300 | 300 | } |
| 301 | 301 | */ |
| 302 | - if (strlen($body_parse) > 0) { |
|
| 303 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
| 304 | - $altitude = intval($matches[1]); |
|
| 305 | - //$result['altitude'] = round($altitude*0.3048); |
|
| 306 | - $result['altitude'] = $altitude; |
|
| 307 | - //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
| 308 | - $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
|
| 309 | - } |
|
| 310 | - } |
|
| 302 | + if (strlen($body_parse) > 0) { |
|
| 303 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
| 304 | + $altitude = intval($matches[1]); |
|
| 305 | + //$result['altitude'] = round($altitude*0.3048); |
|
| 306 | + $result['altitude'] = $altitude; |
|
| 307 | + //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
| 308 | + $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | - // Telemetry |
|
| 313 | - /* |
|
| 312 | + // Telemetry |
|
| 313 | + /* |
|
| 314 | 314 | 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)) { |
| 315 | 315 | // Nothing yet... |
| 316 | 316 | } |
| 317 | 317 | */ |
| 318 | - // DAO |
|
| 319 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
| 320 | - $dao = $matches[1]; |
|
| 321 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
| 318 | + // DAO |
|
| 319 | + if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
| 320 | + $dao = $matches[1]; |
|
| 321 | + if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
| 322 | 322 | $dao_split = str_split($dao); |
| 323 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
| 324 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
| 323 | + $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
| 324 | + $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
| 325 | 325 | |
| 326 | 326 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
| 327 | 327 | else $result['latitude'] += $lat_off; |
| 328 | 328 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
| 329 | 329 | else $result['longitude'] += $lon_off; |
| 330 | - } |
|
| 331 | - $body_parse = substr($body_parse,6); |
|
| 332 | - } |
|
| 330 | + } |
|
| 331 | + $body_parse = substr($body_parse,6); |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) { |
|
| 334 | + if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) { |
|
| 335 | 335 | $result['ident'] = $matches[1]; |
| 336 | - } |
|
| 337 | - if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) { |
|
| 336 | + } |
|
| 337 | + if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) { |
|
| 338 | 338 | $result['squawk'] = $matches[1]; |
| 339 | - } |
|
| 340 | - if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) { |
|
| 339 | + } |
|
| 340 | + if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) { |
|
| 341 | 341 | $result['aircraft_icao'] = $matches[1]; |
| 342 | - } |
|
| 343 | - if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) { |
|
| 342 | + } |
|
| 343 | + if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) { |
|
| 344 | 344 | $result['typeid'] = $matches[1]; |
| 345 | - } |
|
| 346 | - if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
|
| 345 | + } |
|
| 346 | + if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
|
| 347 | 347 | $result['imo'] = $matches[1]; |
| 348 | - } |
|
| 349 | - if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
|
| 348 | + } |
|
| 349 | + if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
|
| 350 | 350 | $result['arrival_date'] = $matches[1]; |
| 351 | - } |
|
| 352 | - if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) { |
|
| 351 | + } |
|
| 352 | + if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) { |
|
| 353 | 353 | $result['arrival_code'] = $matches[1]; |
| 354 | - } |
|
| 355 | - // OGN comment |
|
| 354 | + } |
|
| 355 | + // OGN comment |
|
| 356 | 356 | // echo "Before OGN : ".$body_parse."\n"; |
| 357 | - //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
| 358 | - if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
| 357 | + //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
| 358 | + if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
| 359 | 359 | $id = $matches[1]; |
| 360 | 360 | //$mode = substr($id,0,2); |
| 361 | 361 | $address = substr($id,2); |
@@ -385,53 +385,53 @@ discard block |
||
| 385 | 385 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
| 386 | 386 | $result['stealth'] = $stealth; |
| 387 | 387 | $result['address'] = $address; |
| 388 | - } |
|
| 388 | + } |
|
| 389 | 389 | |
| 390 | - //Comment |
|
| 391 | - $result['comment'] = trim($body_parse); |
|
| 390 | + //Comment |
|
| 391 | + $result['comment'] = trim($body_parse); |
|
| 392 | 392 | } else { |
| 393 | - // parse weather |
|
| 394 | - //$body_parse = substr($body_parse,1); |
|
| 395 | - //$body_parse_len = strlen($body_parse); |
|
| 393 | + // parse weather |
|
| 394 | + //$body_parse = substr($body_parse,1); |
|
| 395 | + //$body_parse_len = strlen($body_parse); |
|
| 396 | 396 | |
| 397 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 398 | - $result['wind_dir'] = intval($matches[1]); |
|
| 399 | - $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
| 400 | - $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
| 401 | - $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
|
| 402 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 403 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 397 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 398 | + $result['wind_dir'] = intval($matches[1]); |
|
| 399 | + $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
| 400 | + $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
| 401 | + $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
|
| 402 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 403 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 404 | 404 | $result['wind_dir'] = intval($matches[1]); |
| 405 | 405 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 406 | 406 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 407 | 407 | $result['temp'] = round(5/9*(($matches[4])-32),1); |
| 408 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 409 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 408 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 409 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 410 | 410 | $result['wind_dir'] = intval($matches[1]); |
| 411 | 411 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 412 | 412 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 413 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 414 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([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})g([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 | - } |
|
| 420 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
| 418 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 419 | + } |
|
| 420 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
| 421 | 421 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
| 422 | - } |
|
| 422 | + } |
|
| 423 | 423 | } |
| 424 | 424 | } else $result['comment'] = trim($body_parse); |
| 425 | 425 | |
| 426 | - } |
|
| 426 | + } |
|
| 427 | 427 | //} |
| 428 | 428 | if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
| 429 | 429 | if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
| 430 | 430 | if ($debug) print_r($result); |
| 431 | 431 | return $result; |
| 432 | - } |
|
| 432 | + } |
|
| 433 | 433 | |
| 434 | - function connect() { |
|
| 434 | + function connect() { |
|
| 435 | 435 | global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport; |
| 436 | 436 | $aprs_connect = 0; |
| 437 | 437 | $aprs_keep = 120; |
@@ -454,24 +454,24 @@ discard block |
||
| 454 | 454 | $send = socket_send( $this->socket , $aprs_login , strlen($aprs_login) , 0 ); |
| 455 | 455 | while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) { |
| 456 | 456 | if (strpos($msgin, "$aprs_ssid verified") !== FALSE) { |
| 457 | - echo 'APRS user verified !'."\n"; |
|
| 458 | - $this->connected = true; |
|
| 459 | - return true; |
|
| 460 | - break; |
|
| 457 | + echo 'APRS user verified !'."\n"; |
|
| 458 | + $this->connected = true; |
|
| 459 | + return true; |
|
| 460 | + break; |
|
| 461 | 461 | } |
| 462 | 462 | if (time()-$authstart > 5) { |
| 463 | - echo 'APRS timeout'."\n"; |
|
| 464 | - break; |
|
| 463 | + echo 'APRS timeout'."\n"; |
|
| 464 | + break; |
|
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | - } |
|
| 468 | + } |
|
| 469 | 469 | |
| 470 | - function send($data) { |
|
| 470 | + function send($data) { |
|
| 471 | 471 | if ($this->connected === false) $this->connect(); |
| 472 | 472 | $send = socket_send( $this->socket , $data , strlen($data),0); |
| 473 | 473 | if ($send === FALSE) $this->connect(); |
| 474 | - } |
|
| 474 | + } |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | class APRSSpotter extends APRS { |