@@ -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,92 +278,92 @@ 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'] = str_replace('_',' ',$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('/SI=([0-9]*)/',$body_parse,$matches)) { |
|
350 | + } |
|
351 | + if (preg_match('/SI=([0-9]*)/',$body_parse,$matches)) { |
|
352 | 352 | $result['statusid'] = $matches[1]; |
353 | - } |
|
354 | - if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
|
353 | + } |
|
354 | + if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
|
355 | 355 | $result['imo'] = $matches[1]; |
356 | - } |
|
357 | - if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
|
356 | + } |
|
357 | + if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
|
358 | 358 | $result['arrival_date'] = $matches[1]; |
359 | - } |
|
360 | - if (preg_match('/AC=([0-9A-Z_]*)/',$body_parse,$matches)) { |
|
359 | + } |
|
360 | + if (preg_match('/AC=([0-9A-Z_]*)/',$body_parse,$matches)) { |
|
361 | 361 | $result['arrival_code'] = str_replace('_',' ',$matches[1]); |
362 | - } |
|
363 | - // OGN comment |
|
362 | + } |
|
363 | + // OGN comment |
|
364 | 364 | // echo "Before OGN : ".$body_parse."\n"; |
365 | - //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
366 | - if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
365 | + //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
366 | + if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
367 | 367 | $id = $matches[1]; |
368 | 368 | //$mode = substr($id,0,2); |
369 | 369 | $address = substr($id,2); |
@@ -393,53 +393,53 @@ discard block |
||
393 | 393 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
394 | 394 | $result['stealth'] = $stealth; |
395 | 395 | $result['address'] = $address; |
396 | - } |
|
396 | + } |
|
397 | 397 | |
398 | - //Comment |
|
399 | - $result['comment'] = trim($body_parse); |
|
398 | + //Comment |
|
399 | + $result['comment'] = trim($body_parse); |
|
400 | 400 | } else { |
401 | - // parse weather |
|
402 | - //$body_parse = substr($body_parse,1); |
|
403 | - //$body_parse_len = strlen($body_parse); |
|
401 | + // parse weather |
|
402 | + //$body_parse = substr($body_parse,1); |
|
403 | + //$body_parse_len = strlen($body_parse); |
|
404 | 404 | |
405 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
406 | - $result['wind_dir'] = intval($matches[1]); |
|
407 | - $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
408 | - $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
409 | - $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
|
410 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
411 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
405 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
406 | + $result['wind_dir'] = intval($matches[1]); |
|
407 | + $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
408 | + $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
409 | + $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
|
410 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
411 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
412 | 412 | $result['wind_dir'] = intval($matches[1]); |
413 | 413 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
414 | 414 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
415 | 415 | $result['temp'] = round(5/9*(($matches[4])-32),1); |
416 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
417 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
416 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
417 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
418 | 418 | $result['wind_dir'] = intval($matches[1]); |
419 | 419 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
420 | 420 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
421 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
422 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
421 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
422 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
423 | 423 | $result['wind_dir'] = intval($matches[1]); |
424 | 424 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
425 | 425 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
426 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
427 | - } |
|
428 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
426 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
427 | + } |
|
428 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
429 | 429 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
430 | - } |
|
430 | + } |
|
431 | 431 | } |
432 | 432 | } else $result['comment'] = trim($body_parse); |
433 | 433 | |
434 | - } |
|
434 | + } |
|
435 | 435 | //} |
436 | 436 | if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
437 | 437 | if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
438 | 438 | if ($debug) print_r($result); |
439 | 439 | return $result; |
440 | - } |
|
440 | + } |
|
441 | 441 | |
442 | - public function connect() { |
|
442 | + public function connect() { |
|
443 | 443 | global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport; |
444 | 444 | $aprs_connect = 0; |
445 | 445 | $aprs_keep = 120; |
@@ -462,32 +462,32 @@ discard block |
||
462 | 462 | $send = socket_send( $this->socket , $aprs_login , strlen($aprs_login) , 0 ); |
463 | 463 | while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) { |
464 | 464 | if (strpos($msgin, "$aprs_ssid verified") !== FALSE) { |
465 | - echo 'APRS user verified !'."\n"; |
|
466 | - $this->connected = true; |
|
467 | - return true; |
|
468 | - break; |
|
465 | + echo 'APRS user verified !'."\n"; |
|
466 | + $this->connected = true; |
|
467 | + return true; |
|
468 | + break; |
|
469 | 469 | } |
470 | 470 | if (time()-$authstart > 5) { |
471 | - echo 'APRS timeout'."\n"; |
|
472 | - break; |
|
471 | + echo 'APRS timeout'."\n"; |
|
472 | + break; |
|
473 | 473 | } |
474 | 474 | } |
475 | 475 | socket_set_option($this->socket,SOL_SOCKET,SO_KEEPALIVE); |
476 | 476 | } |
477 | - } |
|
477 | + } |
|
478 | 478 | |
479 | - public function disconnect() { |
|
479 | + public function disconnect() { |
|
480 | 480 | socket_close($this->socket); |
481 | - } |
|
481 | + } |
|
482 | 482 | |
483 | - public function send($data) { |
|
483 | + public function send($data) { |
|
484 | 484 | if ($this->connected === false) $this->connect(); |
485 | 485 | $send = socket_send( $this->socket , $data , strlen($data),0); |
486 | 486 | if ($send === FALSE) { |
487 | 487 | socket_close($this->socket); |
488 | 488 | $this->connect(); |
489 | 489 | } |
490 | - } |
|
490 | + } |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | class APRSSpotter extends APRS { |