@@ -3,10 +3,10 @@ discard block |
||
3 | 3 | require_once(dirname(__FILE__).'/class.Common.php'); |
4 | 4 | require_once(dirname(__FILE__).'/class.GeoidHeight.php'); |
5 | 5 | class aprs { |
6 | - private $socket; |
|
7 | - private $connected = false; |
|
6 | + private $socket; |
|
7 | + private $connected = false; |
|
8 | 8 | |
9 | - protected $symbols = array('/!' => 'Police', |
|
9 | + protected $symbols = array('/!' => 'Police', |
|
10 | 10 | '/#' => 'DIGI', |
11 | 11 | '/$' => 'Phone', |
12 | 12 | '/%' => 'DX Cluster', |
@@ -166,13 +166,13 @@ discard block |
||
166 | 166 | '\~' => 'TNC Stream SW'); |
167 | 167 | |
168 | 168 | |
169 | - private function urshift($n, $s) { |
|
169 | + private function urshift($n, $s) { |
|
170 | 170 | return ($n >= 0) ? ($n >> $s) : |
171 | - (($n & 0x7fffffff) >> $s) | |
|
171 | + (($n & 0x7fffffff) >> $s) | |
|
172 | 172 | (0x40000000 >> ($s - 1)); |
173 | - } |
|
173 | + } |
|
174 | 174 | |
175 | - public function parse($input) { |
|
175 | + public function parse($input) { |
|
176 | 176 | global $globalDebug; |
177 | 177 | $debug = false; |
178 | 178 | $result = array(); |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | |
185 | 185 | /* Check that end was found and body has at least one byte. */ |
186 | 186 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
187 | - if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
188 | - return false; |
|
187 | + if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
188 | + return false; |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | if ($debug) echo 'input : '.$input."\n"; |
@@ -199,34 +199,34 @@ discard block |
||
199 | 199 | /* Parse source, target and path. */ |
200 | 200 | //FLRDF0A52>APRS,qAS,LSTB |
201 | 201 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
202 | - $ident = $matches[1]; |
|
203 | - $all_elements = $matches[2]; |
|
204 | - if ($ident == 'AIRCRAFT') { |
|
202 | + $ident = $matches[1]; |
|
203 | + $all_elements = $matches[2]; |
|
204 | + if ($ident == 'AIRCRAFT') { |
|
205 | 205 | $result['format_source'] = 'famaprs'; |
206 | 206 | $result['source_type'] = 'modes'; |
207 | - } elseif ($ident == 'MARINE') { |
|
207 | + } elseif ($ident == 'MARINE') { |
|
208 | 208 | $result['format_source'] = 'famaprs'; |
209 | 209 | $result['source_type'] = 'ais'; |
210 | - } else { |
|
210 | + } else { |
|
211 | 211 | if ($debug) echo 'ident : '.$ident."\n"; |
212 | 212 | $result['ident'] = $ident; |
213 | - } |
|
213 | + } |
|
214 | 214 | } else { |
215 | - if ($debug) 'No ident'."\n"; |
|
216 | - return false; |
|
215 | + if ($debug) 'No ident'."\n"; |
|
216 | + return false; |
|
217 | 217 | } |
218 | 218 | $elements = explode(',',$all_elements); |
219 | 219 | $source = end($elements); |
220 | 220 | $result['source'] = $source; |
221 | 221 | foreach ($elements as $element) { |
222 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
223 | - //echo "ok"; |
|
224 | - //if ($element == 'TCPIP*') return false; |
|
225 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
222 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
223 | + //echo "ok"; |
|
224 | + //if ($element == 'TCPIP*') return false; |
|
225 | + } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
226 | 226 | if ($debug) echo 'element : '.$element."\n"; |
227 | 227 | return false; |
228 | - } |
|
229 | - /* |
|
228 | + } |
|
229 | + /* |
|
230 | 230 | } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) { |
231 | 231 | //echo "ok"; |
232 | 232 | } else { |
@@ -253,48 +253,48 @@ discard block |
||
253 | 253 | $body_parse = substr($body,1); |
254 | 254 | //echo 'Body : '.$body."\n"; |
255 | 255 | if (preg_match('/^;(.){9}\*/',$body,$matches)) { |
256 | - $body_parse = substr($body_parse,10); |
|
257 | - $find = true; |
|
258 | - //echo $body_parse."\n"; |
|
256 | + $body_parse = substr($body_parse,10); |
|
257 | + $find = true; |
|
258 | + //echo $body_parse."\n"; |
|
259 | 259 | } |
260 | 260 | if (preg_match('/^`(.*)\//',$body,$matches)) { |
261 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
262 | - $find = true; |
|
263 | - //echo $body_parse."\n"; |
|
261 | + $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
262 | + $find = true; |
|
263 | + //echo $body_parse."\n"; |
|
264 | 264 | } |
265 | 265 | if (preg_match("/^'(.*)\//",$body,$matches)) { |
266 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
267 | - $find = true; |
|
268 | - //echo $body_parse."\n"; |
|
266 | + $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
267 | + $find = true; |
|
268 | + //echo $body_parse."\n"; |
|
269 | 269 | } |
270 | 270 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
271 | - $find = true; |
|
272 | - //print_r($matches); |
|
273 | - $timestamp = $matches[0]; |
|
274 | - if ($matches[4] == 'h') { |
|
271 | + $find = true; |
|
272 | + //print_r($matches); |
|
273 | + $timestamp = $matches[0]; |
|
274 | + if ($matches[4] == 'h') { |
|
275 | 275 | $timestamp = strtotime(date('Ymd').' '.$matches[1].':'.$matches[2].':'.$matches[3]); |
276 | 276 | //echo 'timestamp : '.$timestamp.' - now : '.time()."\n"; |
277 | 277 | /* |
278 | 278 | if (time() + 3900 < $timestamp) $timestamp -= 86400; |
279 | 279 | elseif (time() - 82500 > $timestamp) $timestamp += 86400; |
280 | 280 | */ |
281 | - } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
281 | + } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
282 | 282 | // This work or not ? |
283 | 283 | $timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]); |
284 | - } |
|
285 | - $body_parse = substr($body_parse,7); |
|
286 | - $result['timestamp'] = $timestamp; |
|
287 | - //echo date('Ymd H:i:s',$timestamp); |
|
284 | + } |
|
285 | + $body_parse = substr($body_parse,7); |
|
286 | + $result['timestamp'] = $timestamp; |
|
287 | + //echo date('Ymd H:i:s',$timestamp); |
|
288 | 288 | } |
289 | 289 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) { |
290 | - $find = true; |
|
291 | - $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
|
292 | - $body_parse = substr($body_parse,8); |
|
293 | - $result['timestamp'] = $timestamp; |
|
294 | - //echo date('Ymd H:i:s',$timestamp); |
|
290 | + $find = true; |
|
291 | + $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
|
292 | + $body_parse = substr($body_parse,8); |
|
293 | + $result['timestamp'] = $timestamp; |
|
294 | + //echo date('Ymd H:i:s',$timestamp); |
|
295 | 295 | } |
296 | 296 | //if (strlen($body_parse) > 19) { |
297 | - 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)) { |
|
297 | + 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)) { |
|
298 | 298 | $find = true; |
299 | 299 | // 4658.70N/00707.78Ez |
300 | 300 | //print_r(str_split($body_parse)); |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | $lon = intval($lon_deg); |
314 | 314 | if ($lat > 89 || $lon > 179) return false; |
315 | 315 | |
316 | - /* |
|
316 | + /* |
|
317 | 317 | $tmp_5b = str_replace('.','',$lat_min); |
318 | 318 | if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) { |
319 | 319 | print_r($matches); |
@@ -327,9 +327,9 @@ discard block |
||
327 | 327 | $result['longitude'] = $longitude; |
328 | 328 | $body_parse = substr($body_parse,18); |
329 | 329 | $body_parse_len = strlen($body_parse); |
330 | - } |
|
331 | - $body_parse_len = strlen($body_parse); |
|
332 | - if ($body_parse_len > 0) { |
|
330 | + } |
|
331 | + $body_parse_len = strlen($body_parse); |
|
332 | + if ($body_parse_len > 0) { |
|
333 | 333 | /* |
334 | 334 | if (!isset($result['timestamp']) && !isset($result['latitude'])) { |
335 | 335 | $body_split = str_split($body); |
@@ -363,95 +363,95 @@ discard block |
||
363 | 363 | if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
364 | 364 | if ($symbol_code != '_') { |
365 | 365 | } |
366 | - //$body_parse = substr($body_parse,1); |
|
367 | - //$body_parse = trim($body_parse); |
|
368 | - //$body_parse_len = strlen($body_parse); |
|
369 | - if ($body_parse_len >= 7) { |
|
366 | + //$body_parse = substr($body_parse,1); |
|
367 | + //$body_parse = trim($body_parse); |
|
368 | + //$body_parse_len = strlen($body_parse); |
|
369 | + if ($body_parse_len >= 7) { |
|
370 | 370 | |
371 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
372 | - $course = substr($body_parse,0,3); |
|
373 | - $tmp_s = intval($course); |
|
374 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
375 | - $speed = substr($body_parse,4,3); |
|
376 | - if ($speed != '...') { |
|
377 | - //$result['speed'] = round($speed*1.852); |
|
378 | - $result['speed'] = intval($speed); |
|
379 | - } |
|
380 | - $body_parse = substr($body_parse,7); |
|
381 | - } |
|
382 | - // Check PHGR, PHG, RNG |
|
383 | - } |
|
384 | - /* |
|
371 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
372 | + $course = substr($body_parse,0,3); |
|
373 | + $tmp_s = intval($course); |
|
374 | + if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
375 | + $speed = substr($body_parse,4,3); |
|
376 | + if ($speed != '...') { |
|
377 | + //$result['speed'] = round($speed*1.852); |
|
378 | + $result['speed'] = intval($speed); |
|
379 | + } |
|
380 | + $body_parse = substr($body_parse,7); |
|
381 | + } |
|
382 | + // Check PHGR, PHG, RNG |
|
383 | + } |
|
384 | + /* |
|
385 | 385 | else if ($body_parse_len > 0) { |
386 | 386 | $rest = $body_parse; |
387 | 387 | } |
388 | 388 | */ |
389 | - if (strlen($body_parse) > 0) { |
|
390 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
391 | - $altitude = intval($matches[1]); |
|
392 | - //$result['altitude'] = round($altitude*0.3048); |
|
393 | - $result['altitude'] = $altitude; |
|
394 | - //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
395 | - $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
|
396 | - } |
|
397 | - } |
|
389 | + if (strlen($body_parse) > 0) { |
|
390 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
391 | + $altitude = intval($matches[1]); |
|
392 | + //$result['altitude'] = round($altitude*0.3048); |
|
393 | + $result['altitude'] = $altitude; |
|
394 | + //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
395 | + $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
|
396 | + } |
|
397 | + } |
|
398 | 398 | |
399 | - // Telemetry |
|
400 | - /* |
|
399 | + // Telemetry |
|
400 | + /* |
|
401 | 401 | 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)) { |
402 | 402 | // Nothing yet... |
403 | 403 | } |
404 | 404 | */ |
405 | - // DAO |
|
405 | + // DAO |
|
406 | 406 | |
407 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
407 | + if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
408 | 408 | |
409 | - $dao = $matches[1]; |
|
410 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
409 | + $dao = $matches[1]; |
|
410 | + if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
411 | 411 | $dao_split = str_split($dao); |
412 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
413 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
412 | + $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
413 | + $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
414 | 414 | |
415 | 415 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
416 | 416 | else $result['latitude'] += $lat_off; |
417 | 417 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
418 | 418 | else $result['longitude'] += $lon_off; |
419 | - } |
|
419 | + } |
|
420 | 420 | |
421 | - $body_parse = substr($body_parse,6); |
|
422 | - } |
|
423 | - //echo 'bodyparse : '.$body_parse."\n"; |
|
424 | - if (preg_match('/CS=([0-9A-Z_]*)/',$body_parse,$matches)) { |
|
421 | + $body_parse = substr($body_parse,6); |
|
422 | + } |
|
423 | + //echo 'bodyparse : '.$body_parse."\n"; |
|
424 | + if (preg_match('/CS=([0-9A-Z_]*)/',$body_parse,$matches)) { |
|
425 | 425 | $result['ident'] = str_replace('_',' ',$matches[1]); |
426 | - } |
|
427 | - if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) { |
|
426 | + } |
|
427 | + if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) { |
|
428 | 428 | $result['squawk'] = $matches[1]; |
429 | - } |
|
430 | - if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) { |
|
429 | + } |
|
430 | + if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) { |
|
431 | 431 | $result['aircraft_icao'] = $matches[1]; |
432 | - } |
|
433 | - if (preg_match('/VR=([0-9]*)/',$body_parse,$matches)) { |
|
432 | + } |
|
433 | + if (preg_match('/VR=([0-9]*)/',$body_parse,$matches)) { |
|
434 | 434 | $result['verticalrate'] = $matches[1]; |
435 | - } |
|
436 | - if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) { |
|
435 | + } |
|
436 | + if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) { |
|
437 | 437 | $result['typeid'] = $matches[1]; |
438 | - } |
|
439 | - if (preg_match('/SI=([0-9]*)/',$body_parse,$matches)) { |
|
438 | + } |
|
439 | + if (preg_match('/SI=([0-9]*)/',$body_parse,$matches)) { |
|
440 | 440 | $result['statusid'] = $matches[1]; |
441 | - } |
|
442 | - if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
|
441 | + } |
|
442 | + if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
|
443 | 443 | $result['imo'] = $matches[1]; |
444 | - } |
|
445 | - if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
|
444 | + } |
|
445 | + if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
|
446 | 446 | $result['arrival_date'] = $matches[1]; |
447 | - } |
|
448 | - if (preg_match('/AC=([0-9A-Z_]*)/',$body_parse,$matches)) { |
|
447 | + } |
|
448 | + if (preg_match('/AC=([0-9A-Z_]*)/',$body_parse,$matches)) { |
|
449 | 449 | $result['arrival_code'] = str_replace('_',' ',$matches[1]); |
450 | - } |
|
451 | - // OGN comment |
|
450 | + } |
|
451 | + // OGN comment |
|
452 | 452 | // echo "Before OGN : ".$body_parse."\n"; |
453 | - //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
454 | - if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
453 | + //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
454 | + if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
455 | 455 | $id = $matches[1]; |
456 | 456 | //$mode = substr($id,0,2); |
457 | 457 | $address = substr($id,2); |
@@ -481,42 +481,42 @@ discard block |
||
481 | 481 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
482 | 482 | $result['stealth'] = $stealth; |
483 | 483 | $result['address'] = $address; |
484 | - } |
|
484 | + } |
|
485 | 485 | |
486 | - //Comment |
|
487 | - $result['comment'] = trim($body_parse); |
|
486 | + //Comment |
|
487 | + $result['comment'] = trim($body_parse); |
|
488 | 488 | //} else { |
489 | - // parse weather |
|
490 | - //$body_parse = substr($body_parse,1); |
|
491 | - //$body_parse_len = strlen($body_parse); |
|
492 | - //echo 'weather'."\n"; |
|
493 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
494 | - $result['wind_dir'] = intval($matches[1]); |
|
495 | - $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
496 | - $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
497 | - $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
|
498 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
499 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
489 | + // parse weather |
|
490 | + //$body_parse = substr($body_parse,1); |
|
491 | + //$body_parse_len = strlen($body_parse); |
|
492 | + //echo 'weather'."\n"; |
|
493 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
494 | + $result['wind_dir'] = intval($matches[1]); |
|
495 | + $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
496 | + $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
497 | + $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
|
498 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
499 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
500 | 500 | $result['wind_dir'] = intval($matches[1]); |
501 | 501 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
502 | 502 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
503 | 503 | $result['temp'] = round(5/9*(($matches[4])-32),1); |
504 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
505 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
504 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
505 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
506 | 506 | $result['wind_dir'] = intval($matches[1]); |
507 | 507 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
508 | 508 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
509 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
510 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
509 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
510 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
511 | 511 | $result['wind_dir'] = intval($matches[1]); |
512 | 512 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
513 | 513 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
514 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
515 | - } |
|
516 | - //if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
517 | - //g012t088r000p000P000h38b10110 |
|
518 | - //g011t086r000p000P000h29b10198 |
|
519 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3,4})r([0-9 \\.]{3})p([0-9 \\.]{3})P([0-9 \\.]{3})h([0-9 \\.]{2,3})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
514 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
515 | + } |
|
516 | + //if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
517 | + //g012t088r000p000P000h38b10110 |
|
518 | + //g011t086r000p000P000h29b10198 |
|
519 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3,4})r([0-9 \\.]{3})p([0-9 \\.]{3})P([0-9 \\.]{3})h([0-9 \\.]{2,3})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
520 | 520 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
521 | 521 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
522 | 522 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
@@ -524,8 +524,8 @@ discard block |
||
524 | 524 | if ($matches[5] != '...') $result['precipitation24h'] = round((intval($matches[5])/100)*25.1,1); |
525 | 525 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
526 | 526 | if ($matches[7] != '...') $result['pressure'] = round((intval($matches[7])/10),1); |
527 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
528 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3,4})r([0-9 \\.]{3})P([0-9 \\.]{3})p([0-9 \\.]{3})h([0-9 \\.]{2,3})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
527 | + $body_parse = substr($body_parse,strlen($matches[0])); |
|
528 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3,4})r([0-9 \\.]{3})P([0-9 \\.]{3})p([0-9 \\.]{3})h([0-9 \\.]{2,3})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
529 | 529 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
530 | 530 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
531 | 531 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
@@ -533,8 +533,8 @@ discard block |
||
533 | 533 | if ($matches[4] != '...') $result['precipitation24h'] = round((intval($matches[4])/100)*25.1,1); |
534 | 534 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
535 | 535 | if ($matches[7] != '...') $result['pressure'] = round((intval($matches[7])/10),1); |
536 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
537 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})P([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
|
536 | + $body_parse = substr($body_parse,strlen($matches[0])); |
|
537 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})P([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
|
538 | 538 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
539 | 539 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
540 | 540 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
@@ -542,58 +542,58 @@ discard block |
||
542 | 542 | if ($matches[5] != '...') $result['precipitation24h'] = round((intval($matches[5])/100)*25.1,1); |
543 | 543 | if ($matches[7] != '...') $result['humidity'] = intval($matches[7]); |
544 | 544 | if ($matches[6] != '...') $result['pressure'] = round((intval($matches[6])/10),1); |
545 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
546 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})P([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
|
545 | + $body_parse = substr($body_parse,strlen($matches[0])); |
|
546 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})P([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
|
547 | 547 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
548 | 548 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
549 | 549 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
550 | 550 | if ($matches[4] != '...') $result['precipitation24h'] = round((intval($matches[4])/100)*25.1,1); |
551 | 551 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
552 | 552 | if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10),1); |
553 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
554 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
|
553 | + $body_parse = substr($body_parse,strlen($matches[0])); |
|
554 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
|
555 | 555 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
556 | 556 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
557 | 557 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
558 | 558 | if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1,1); |
559 | 559 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
560 | 560 | if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10),1); |
561 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
562 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
561 | + $body_parse = substr($body_parse,strlen($matches[0])); |
|
562 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
563 | 563 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
564 | 564 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
565 | 565 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
566 | 566 | if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1,1); |
567 | 567 | if ($matches[5] != '...') $result['humidity'] = intval($matches[5]); |
568 | 568 | if ($matches[6] != '...') $result['pressure'] = round((intval($matches[6])/10),1); |
569 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
570 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
569 | + $body_parse = substr($body_parse,strlen($matches[0])); |
|
570 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
571 | 571 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
572 | 572 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
573 | 573 | if ($matches[2] != '...') $result['humidity'] = intval($matches[3]); |
574 | 574 | if ($matches[4] != '...') $result['pressure'] = round((intval($matches[4])/10),1); |
575 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
576 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{2,3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
575 | + $body_parse = substr($body_parse,strlen($matches[0])); |
|
576 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{2,3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
577 | 577 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
578 | 578 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
579 | 579 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
580 | 580 | if ($matches[4] != '...') $result['humidity'] = intval($matches[4]); |
581 | 581 | if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10),1); |
582 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
583 | - } |
|
584 | - $result['comment'] = trim($body_parse); |
|
582 | + $body_parse = substr($body_parse,strlen($matches[0])); |
|
583 | + } |
|
584 | + $result['comment'] = trim($body_parse); |
|
585 | 585 | } |
586 | 586 | } else $result['comment'] = trim($body_parse); |
587 | 587 | |
588 | - } |
|
588 | + } |
|
589 | 589 | //} |
590 | 590 | if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
591 | 591 | if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
592 | 592 | if ($debug) print_r($result); |
593 | 593 | return $result; |
594 | - } |
|
594 | + } |
|
595 | 595 | |
596 | - public function connect() { |
|
596 | + public function connect() { |
|
597 | 597 | global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport; |
598 | 598 | $aprs_connect = 0; |
599 | 599 | $aprs_keep = 120; |
@@ -617,24 +617,24 @@ discard block |
||
617 | 617 | socket_set_option($this->socket,SOL_SOCKET,SO_KEEPALIVE,1); |
618 | 618 | while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) { |
619 | 619 | if (strpos($msgin, "$aprs_ssid verified") !== FALSE) { |
620 | - echo 'APRS user verified !'."\n"; |
|
621 | - $this->connected = true; |
|
622 | - return true; |
|
623 | - break; |
|
620 | + echo 'APRS user verified !'."\n"; |
|
621 | + $this->connected = true; |
|
622 | + return true; |
|
623 | + break; |
|
624 | 624 | } |
625 | 625 | if (time()-$authstart > 5) { |
626 | - echo 'APRS timeout'."\n"; |
|
627 | - break; |
|
626 | + echo 'APRS timeout'."\n"; |
|
627 | + break; |
|
628 | 628 | } |
629 | 629 | } |
630 | 630 | } |
631 | - } |
|
631 | + } |
|
632 | 632 | |
633 | - public function disconnect() { |
|
633 | + public function disconnect() { |
|
634 | 634 | socket_close($this->socket); |
635 | - } |
|
635 | + } |
|
636 | 636 | |
637 | - public function send($data) { |
|
637 | + public function send($data) { |
|
638 | 638 | global $globalDebug; |
639 | 639 | if ($this->connected === false) $this->connect(); |
640 | 640 | $send = socket_send( $this->socket , $data , strlen($data),0); |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | socket_close($this->socket); |
644 | 644 | $this->connect(); |
645 | 645 | } |
646 | - } |
|
646 | + } |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | class APRSSpotter extends APRS { |
@@ -167,8 +167,7 @@ discard block |
||
167 | 167 | |
168 | 168 | |
169 | 169 | private function urshift($n, $s) { |
170 | - return ($n >= 0) ? ($n >> $s) : |
|
171 | - (($n & 0x7fffffff) >> $s) | |
|
170 | + return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| |
|
172 | 171 | (0x40000000 >> ($s - 1)); |
173 | 172 | } |
174 | 173 | |
@@ -180,7 +179,7 @@ discard block |
||
180 | 179 | //$split_input = str_split($input); |
181 | 180 | |
182 | 181 | /* Find the end of header checking for NULL bytes while doing it. */ |
183 | - $splitpos = strpos($input,':'); |
|
182 | + $splitpos = strpos($input, ':'); |
|
184 | 183 | |
185 | 184 | /* Check that end was found and body has at least one byte. */ |
186 | 185 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
@@ -190,15 +189,15 @@ discard block |
||
190 | 189 | |
191 | 190 | if ($debug) echo 'input : '.$input."\n"; |
192 | 191 | /* Save header and body. */ |
193 | - $body = substr($input,$splitpos+1,$input_len); |
|
192 | + $body = substr($input, $splitpos + 1, $input_len); |
|
194 | 193 | $body_len = strlen($body); |
195 | - $header = substr($input,0,$splitpos); |
|
194 | + $header = substr($input, 0, $splitpos); |
|
196 | 195 | //$header_len = strlen($header); |
197 | 196 | if ($debug) echo 'header : '.$header."\n"; |
198 | 197 | |
199 | 198 | /* Parse source, target and path. */ |
200 | 199 | //FLRDF0A52>APRS,qAS,LSTB |
201 | - if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
|
200 | + if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) { |
|
202 | 201 | $ident = $matches[1]; |
203 | 202 | $all_elements = $matches[2]; |
204 | 203 | if ($ident == 'AIRCRAFT') { |
@@ -215,14 +214,14 @@ discard block |
||
215 | 214 | if ($debug) 'No ident'."\n"; |
216 | 215 | return false; |
217 | 216 | } |
218 | - $elements = explode(',',$all_elements); |
|
217 | + $elements = explode(',', $all_elements); |
|
219 | 218 | $source = end($elements); |
220 | 219 | $result['source'] = $source; |
221 | 220 | foreach ($elements as $element) { |
222 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
221 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) { |
|
223 | 222 | //echo "ok"; |
224 | 223 | //if ($element == 'TCPIP*') return false; |
225 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
224 | + } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) { |
|
226 | 225 | if ($debug) echo 'element : '.$element."\n"; |
227 | 226 | return false; |
228 | 227 | } |
@@ -235,14 +234,14 @@ discard block |
||
235 | 234 | */ |
236 | 235 | } |
237 | 236 | |
238 | - $type = substr($body,0,1); |
|
237 | + $type = substr($body, 0, 1); |
|
239 | 238 | if ($debug) echo 'type : '.$type."\n"; |
240 | 239 | if ($type == ';') { |
241 | 240 | if (isset($result['source_type']) && $result['source_type'] == 'modes') { |
242 | - $result['address'] = trim(substr($body,1,9)); |
|
241 | + $result['address'] = trim(substr($body, 1, 9)); |
|
243 | 242 | } elseif (isset($result['source_type']) && $result['source_type'] == 'ais') { |
244 | - $result['mmsi'] = trim(substr($body,1,9)); |
|
245 | - } else $result['ident'] = trim(substr($body,1,9)); |
|
243 | + $result['mmsi'] = trim(substr($body, 1, 9)); |
|
244 | + } else $result['ident'] = trim(substr($body, 1, 9)); |
|
246 | 245 | } elseif ($type == ',') { |
247 | 246 | // Invalid data or test data |
248 | 247 | return false; |
@@ -250,24 +249,24 @@ discard block |
||
250 | 249 | |
251 | 250 | // Check for Timestamp |
252 | 251 | $find = false; |
253 | - $body_parse = substr($body,1); |
|
252 | + $body_parse = substr($body, 1); |
|
254 | 253 | //echo 'Body : '.$body."\n"; |
255 | - if (preg_match('/^;(.){9}\*/',$body,$matches)) { |
|
256 | - $body_parse = substr($body_parse,10); |
|
254 | + if (preg_match('/^;(.){9}\*/', $body, $matches)) { |
|
255 | + $body_parse = substr($body_parse, 10); |
|
257 | 256 | $find = true; |
258 | 257 | //echo $body_parse."\n"; |
259 | 258 | } |
260 | - if (preg_match('/^`(.*)\//',$body,$matches)) { |
|
261 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
259 | + if (preg_match('/^`(.*)\//', $body, $matches)) { |
|
260 | + $body_parse = substr($body_parse, strlen($matches[1]) - 1); |
|
262 | 261 | $find = true; |
263 | 262 | //echo $body_parse."\n"; |
264 | 263 | } |
265 | - if (preg_match("/^'(.*)\//",$body,$matches)) { |
|
266 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
264 | + if (preg_match("/^'(.*)\//", $body, $matches)) { |
|
265 | + $body_parse = substr($body_parse, strlen($matches[1]) - 1); |
|
267 | 266 | $find = true; |
268 | 267 | //echo $body_parse."\n"; |
269 | 268 | } |
270 | - if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
|
269 | + if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) { |
|
271 | 270 | $find = true; |
272 | 271 | //print_r($matches); |
273 | 272 | $timestamp = $matches[0]; |
@@ -282,19 +281,19 @@ discard block |
||
282 | 281 | // This work or not ? |
283 | 282 | $timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]); |
284 | 283 | } |
285 | - $body_parse = substr($body_parse,7); |
|
284 | + $body_parse = substr($body_parse, 7); |
|
286 | 285 | $result['timestamp'] = $timestamp; |
287 | 286 | //echo date('Ymd H:i:s',$timestamp); |
288 | 287 | } |
289 | - if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) { |
|
288 | + if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $body_parse, $matches)) { |
|
290 | 289 | $find = true; |
291 | 290 | $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
292 | - $body_parse = substr($body_parse,8); |
|
291 | + $body_parse = substr($body_parse, 8); |
|
293 | 292 | $result['timestamp'] = $timestamp; |
294 | 293 | //echo date('Ymd H:i:s',$timestamp); |
295 | 294 | } |
296 | 295 | //if (strlen($body_parse) > 19) { |
297 | - 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)) { |
|
296 | + 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)) { |
|
298 | 297 | $find = true; |
299 | 298 | // 4658.70N/00707.78Ez |
300 | 299 | //print_r(str_split($body_parse)); |
@@ -321,11 +320,11 @@ discard block |
||
321 | 320 | */ |
322 | 321 | $latitude = $lat + floatval($lat_min)/60; |
323 | 322 | $longitude = $lon + floatval($lon_min)/60; |
324 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
325 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
323 | + if ($sind == 'S') $latitude = 0 - $latitude; |
|
324 | + if ($wind == 'W') $longitude = 0 - $longitude; |
|
326 | 325 | $result['latitude'] = $latitude; |
327 | 326 | $result['longitude'] = $longitude; |
328 | - $body_parse = substr($body_parse,18); |
|
327 | + $body_parse = substr($body_parse, 18); |
|
329 | 328 | $body_parse_len = strlen($body_parse); |
330 | 329 | } |
331 | 330 | $body_parse_len = strlen($body_parse); |
@@ -357,7 +356,7 @@ discard block |
||
357 | 356 | //echo $body_parse; |
358 | 357 | //if ($type != ';' && $type != '>') { |
359 | 358 | if ($type != '') { |
360 | - $body_parse = substr($body_parse,1); |
|
359 | + $body_parse = substr($body_parse, 1); |
|
361 | 360 | $body_parse_len = strlen($body_parse); |
362 | 361 | $result['symbol_code'] = $symbol_code; |
363 | 362 | if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
@@ -368,16 +367,16 @@ discard block |
||
368 | 367 | //$body_parse_len = strlen($body_parse); |
369 | 368 | if ($body_parse_len >= 7) { |
370 | 369 | |
371 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
372 | - $course = substr($body_parse,0,3); |
|
370 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) { |
|
371 | + $course = substr($body_parse, 0, 3); |
|
373 | 372 | $tmp_s = intval($course); |
374 | 373 | if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
375 | - $speed = substr($body_parse,4,3); |
|
374 | + $speed = substr($body_parse, 4, 3); |
|
376 | 375 | if ($speed != '...') { |
377 | 376 | //$result['speed'] = round($speed*1.852); |
378 | 377 | $result['speed'] = intval($speed); |
379 | 378 | } |
380 | - $body_parse = substr($body_parse,7); |
|
379 | + $body_parse = substr($body_parse, 7); |
|
381 | 380 | } |
382 | 381 | // Check PHGR, PHG, RNG |
383 | 382 | } |
@@ -387,12 +386,12 @@ discard block |
||
387 | 386 | } |
388 | 387 | */ |
389 | 388 | if (strlen($body_parse) > 0) { |
390 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
389 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) { |
|
391 | 390 | $altitude = intval($matches[1]); |
392 | 391 | //$result['altitude'] = round($altitude*0.3048); |
393 | 392 | $result['altitude'] = $altitude; |
394 | 393 | //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
395 | - $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
|
394 | + $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/', '', $body_parse)); |
|
396 | 395 | } |
397 | 396 | } |
398 | 397 | |
@@ -404,13 +403,13 @@ discard block |
||
404 | 403 | */ |
405 | 404 | // DAO |
406 | 405 | |
407 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
406 | + if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) { |
|
408 | 407 | |
409 | 408 | $dao = $matches[1]; |
410 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
409 | + if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) { |
|
411 | 410 | $dao_split = str_split($dao); |
412 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
413 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
411 | + $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0; |
|
412 | + $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0; |
|
414 | 413 | |
415 | 414 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
416 | 415 | else $result['latitude'] += $lat_off; |
@@ -418,50 +417,50 @@ discard block |
||
418 | 417 | else $result['longitude'] += $lon_off; |
419 | 418 | } |
420 | 419 | |
421 | - $body_parse = substr($body_parse,6); |
|
420 | + $body_parse = substr($body_parse, 6); |
|
422 | 421 | } |
423 | 422 | //echo 'bodyparse : '.$body_parse."\n"; |
424 | - if (preg_match('/CS=([0-9A-Z_]*)/',$body_parse,$matches)) { |
|
425 | - $result['ident'] = str_replace('_',' ',$matches[1]); |
|
423 | + if (preg_match('/CS=([0-9A-Z_]*)/', $body_parse, $matches)) { |
|
424 | + $result['ident'] = str_replace('_', ' ', $matches[1]); |
|
426 | 425 | } |
427 | - if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) { |
|
426 | + if (preg_match('/SQ=([0-9]{4})/', $body_parse, $matches)) { |
|
428 | 427 | $result['squawk'] = $matches[1]; |
429 | 428 | } |
430 | - if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) { |
|
429 | + if (preg_match('/AI=([0-9A-Z]{4})/', $body_parse, $matches)) { |
|
431 | 430 | $result['aircraft_icao'] = $matches[1]; |
432 | 431 | } |
433 | - if (preg_match('/VR=([0-9]*)/',$body_parse,$matches)) { |
|
432 | + if (preg_match('/VR=([0-9]*)/', $body_parse, $matches)) { |
|
434 | 433 | $result['verticalrate'] = $matches[1]; |
435 | 434 | } |
436 | - if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) { |
|
435 | + if (preg_match('/TI=([0-9]*)/', $body_parse, $matches)) { |
|
437 | 436 | $result['typeid'] = $matches[1]; |
438 | 437 | } |
439 | - if (preg_match('/SI=([0-9]*)/',$body_parse,$matches)) { |
|
438 | + if (preg_match('/SI=([0-9]*)/', $body_parse, $matches)) { |
|
440 | 439 | $result['statusid'] = $matches[1]; |
441 | 440 | } |
442 | - if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
|
441 | + if (preg_match('/IMO=([0-9]{7})/', $body_parse, $matches)) { |
|
443 | 442 | $result['imo'] = $matches[1]; |
444 | 443 | } |
445 | - if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
|
444 | + if (preg_match('/AD=([0-9]*)/', $body_parse, $matches)) { |
|
446 | 445 | $result['arrival_date'] = $matches[1]; |
447 | 446 | } |
448 | - if (preg_match('/AC=([0-9A-Z_]*)/',$body_parse,$matches)) { |
|
449 | - $result['arrival_code'] = str_replace('_',' ',$matches[1]); |
|
447 | + if (preg_match('/AC=([0-9A-Z_]*)/', $body_parse, $matches)) { |
|
448 | + $result['arrival_code'] = str_replace('_', ' ', $matches[1]); |
|
450 | 449 | } |
451 | 450 | // OGN comment |
452 | 451 | // echo "Before OGN : ".$body_parse."\n"; |
453 | 452 | //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
454 | - if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
453 | + if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) { |
|
455 | 454 | $id = $matches[1]; |
456 | 455 | //$mode = substr($id,0,2); |
457 | - $address = substr($id,2); |
|
456 | + $address = substr($id, 2); |
|
458 | 457 | //print_r($matches); |
459 | - $addressType = (intval(substr($id,0,2),16))&3; |
|
458 | + $addressType = (intval(substr($id, 0, 2), 16))&3; |
|
460 | 459 | if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
461 | 460 | elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
462 | 461 | elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
463 | 462 | elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
464 | - $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
|
463 | + $aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2); |
|
465 | 464 | $result['aircrafttype_code'] = $aircraftType; |
466 | 465 | if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
467 | 466 | elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
@@ -478,7 +477,7 @@ discard block |
||
478 | 477 | elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
479 | 478 | elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
480 | 479 | elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
481 | - $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
|
480 | + $stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0; |
|
482 | 481 | $result['stealth'] = $stealth; |
483 | 482 | $result['address'] = $address; |
484 | 483 | } |
@@ -490,96 +489,96 @@ discard block |
||
490 | 489 | //$body_parse = substr($body_parse,1); |
491 | 490 | //$body_parse_len = strlen($body_parse); |
492 | 491 | //echo 'weather'."\n"; |
493 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
492 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
494 | 493 | $result['wind_dir'] = intval($matches[1]); |
495 | - $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
496 | - $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
497 | - $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
|
498 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
499 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
494 | + $result['wind_speed'] = round(intval($matches[2])*1.60934, 1); |
|
495 | + $result['wind_gust'] = round(intval($matches[3])*1.60934, 1); |
|
496 | + $result['temp'] = round(5/9*((intval($matches[4])) - 32), 1); |
|
497 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
498 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
500 | 499 | $result['wind_dir'] = intval($matches[1]); |
501 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
502 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
503 | - $result['temp'] = round(5/9*(($matches[4])-32),1); |
|
504 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
505 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
500 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
501 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
502 | + $result['temp'] = round(5/9*(($matches[4]) - 32), 1); |
|
503 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
504 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
506 | 505 | $result['wind_dir'] = intval($matches[1]); |
507 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
508 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
509 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
510 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
506 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
507 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
508 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
509 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) { |
|
511 | 510 | $result['wind_dir'] = intval($matches[1]); |
512 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
513 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
514 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
511 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
512 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
513 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
515 | 514 | } |
516 | 515 | //if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
517 | 516 | //g012t088r000p000P000h38b10110 |
518 | 517 | //g011t086r000p000P000h29b10198 |
519 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3,4})r([0-9 \\.]{3})p([0-9 \\.]{3})P([0-9 \\.]{3})h([0-9 \\.]{2,3})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
520 | - if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
|
521 | - if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
|
522 | - if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
|
523 | - if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1,1); |
|
524 | - if ($matches[5] != '...') $result['precipitation24h'] = round((intval($matches[5])/100)*25.1,1); |
|
518 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3,4})r([0-9 \\.]{3})p([0-9 \\.]{3})P([0-9 \\.]{3})h([0-9 \\.]{2,3})b([0-9 \\.]{5})/', $body_parse, $matches)) { |
|
519 | + if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934, 1); |
|
520 | + if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2])) - 32), 1); |
|
521 | + if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1, 1); |
|
522 | + if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1, 1); |
|
523 | + if ($matches[5] != '...') $result['precipitation24h'] = round((intval($matches[5])/100)*25.1, 1); |
|
525 | 524 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
526 | - if ($matches[7] != '...') $result['pressure'] = round((intval($matches[7])/10),1); |
|
527 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
528 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3,4})r([0-9 \\.]{3})P([0-9 \\.]{3})p([0-9 \\.]{3})h([0-9 \\.]{2,3})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
529 | - if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
|
530 | - if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
|
531 | - if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
|
532 | - if ($matches[5] != '...') $result['precipitation'] = round((intval($matches[5])/100)*25.1,1); |
|
533 | - if ($matches[4] != '...') $result['precipitation24h'] = round((intval($matches[4])/100)*25.1,1); |
|
525 | + if ($matches[7] != '...') $result['pressure'] = round((intval($matches[7])/10), 1); |
|
526 | + $body_parse = substr($body_parse, strlen($matches[0])); |
|
527 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3,4})r([0-9 \\.]{3})P([0-9 \\.]{3})p([0-9 \\.]{3})h([0-9 \\.]{2,3})b([0-9 \\.]{5})/', $body_parse, $matches)) { |
|
528 | + if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934, 1); |
|
529 | + if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2])) - 32), 1); |
|
530 | + if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1, 1); |
|
531 | + if ($matches[5] != '...') $result['precipitation'] = round((intval($matches[5])/100)*25.1, 1); |
|
532 | + if ($matches[4] != '...') $result['precipitation24h'] = round((intval($matches[4])/100)*25.1, 1); |
|
534 | 533 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
535 | - if ($matches[7] != '...') $result['pressure'] = round((intval($matches[7])/10),1); |
|
536 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
537 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})P([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
|
538 | - if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
|
539 | - if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
|
540 | - if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
|
541 | - if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1,1); |
|
542 | - if ($matches[5] != '...') $result['precipitation24h'] = round((intval($matches[5])/100)*25.1,1); |
|
534 | + if ($matches[7] != '...') $result['pressure'] = round((intval($matches[7])/10), 1); |
|
535 | + $body_parse = substr($body_parse, strlen($matches[0])); |
|
536 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})P([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/', $body_parse, $matches)) { |
|
537 | + if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934, 1); |
|
538 | + if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2])) - 32), 1); |
|
539 | + if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1, 1); |
|
540 | + if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1, 1); |
|
541 | + if ($matches[5] != '...') $result['precipitation24h'] = round((intval($matches[5])/100)*25.1, 1); |
|
543 | 542 | if ($matches[7] != '...') $result['humidity'] = intval($matches[7]); |
544 | - if ($matches[6] != '...') $result['pressure'] = round((intval($matches[6])/10),1); |
|
545 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
546 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})P([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
|
547 | - if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
|
548 | - if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
|
549 | - if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
|
550 | - if ($matches[4] != '...') $result['precipitation24h'] = round((intval($matches[4])/100)*25.1,1); |
|
543 | + if ($matches[6] != '...') $result['pressure'] = round((intval($matches[6])/10), 1); |
|
544 | + $body_parse = substr($body_parse, strlen($matches[0])); |
|
545 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})P([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/', $body_parse, $matches)) { |
|
546 | + if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934, 1); |
|
547 | + if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2])) - 32), 1); |
|
548 | + if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1, 1); |
|
549 | + if ($matches[4] != '...') $result['precipitation24h'] = round((intval($matches[4])/100)*25.1, 1); |
|
551 | 550 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
552 | - if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10),1); |
|
553 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
554 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
|
555 | - if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
|
556 | - if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
|
557 | - if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
|
558 | - if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1,1); |
|
551 | + if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10), 1); |
|
552 | + $body_parse = substr($body_parse, strlen($matches[0])); |
|
553 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/', $body_parse, $matches)) { |
|
554 | + if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934, 1); |
|
555 | + if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2])) - 32), 1); |
|
556 | + if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1, 1); |
|
557 | + if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1, 1); |
|
559 | 558 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
560 | - if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10),1); |
|
561 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
562 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
563 | - if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
|
564 | - if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
|
565 | - if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
|
566 | - if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1,1); |
|
559 | + if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10), 1); |
|
560 | + $body_parse = substr($body_parse, strlen($matches[0])); |
|
561 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})h([0-9 \\.]{2})b([0-9 \\.]{5})/', $body_parse, $matches)) { |
|
562 | + if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934, 1); |
|
563 | + if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2])) - 32), 1); |
|
564 | + if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1, 1); |
|
565 | + if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1, 1); |
|
567 | 566 | if ($matches[5] != '...') $result['humidity'] = intval($matches[5]); |
568 | - if ($matches[6] != '...') $result['pressure'] = round((intval($matches[6])/10),1); |
|
569 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
570 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
571 | - if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
|
572 | - if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
|
567 | + if ($matches[6] != '...') $result['pressure'] = round((intval($matches[6])/10), 1); |
|
568 | + $body_parse = substr($body_parse, strlen($matches[0])); |
|
569 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})h([0-9 \\.]{2})b([0-9 \\.]{5})/', $body_parse, $matches)) { |
|
570 | + if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934, 1); |
|
571 | + if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2])) - 32), 1); |
|
573 | 572 | if ($matches[2] != '...') $result['humidity'] = intval($matches[3]); |
574 | - if ($matches[4] != '...') $result['pressure'] = round((intval($matches[4])/10),1); |
|
575 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
576 | - } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{2,3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
|
577 | - if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
|
578 | - if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
|
579 | - if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
|
573 | + if ($matches[4] != '...') $result['pressure'] = round((intval($matches[4])/10), 1); |
|
574 | + $body_parse = substr($body_parse, strlen($matches[0])); |
|
575 | + } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{2,3})h([0-9 \\.]{2})b([0-9 \\.]{5})/', $body_parse, $matches)) { |
|
576 | + if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934, 1); |
|
577 | + if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2])) - 32), 1); |
|
578 | + if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1, 1); |
|
580 | 579 | if ($matches[4] != '...') $result['humidity'] = intval($matches[4]); |
581 | - if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10),1); |
|
582 | - $body_parse = substr($body_parse,strlen($matches[0])); |
|
580 | + if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10), 1); |
|
581 | + $body_parse = substr($body_parse, strlen($matches[0])); |
|
583 | 582 | } |
584 | 583 | $result['comment'] = trim($body_parse); |
585 | 584 | } |
@@ -587,42 +586,42 @@ discard block |
||
587 | 586 | |
588 | 587 | } |
589 | 588 | //} |
590 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
591 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
589 | + if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4); |
|
590 | + if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4); |
|
592 | 591 | if ($debug) print_r($result); |
593 | 592 | return $result; |
594 | 593 | } |
595 | 594 | |
596 | 595 | public function connect() { |
597 | - global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport; |
|
596 | + global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass, $globalName, $globalServerAPRShost, $globalServerAPRSport; |
|
598 | 597 | $aprs_connect = 0; |
599 | 598 | $aprs_keep = 120; |
600 | 599 | $aprs_last_tx = time(); |
601 | 600 | if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
602 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
601 | + else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName); |
|
603 | 602 | if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid; |
604 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
603 | + else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8); |
|
605 | 604 | if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass; |
606 | 605 | else $aprs_pass = '-1'; |
607 | 606 | |
608 | - $aprs_filter = ''; |
|
607 | + $aprs_filter = ''; |
|
609 | 608 | $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n"; |
610 | 609 | $Common = new Common(); |
611 | - $s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr); |
|
610 | + $s = $Common->create_socket($globalServerAPRShost, $globalServerAPRSport, $errno, $errstr); |
|
612 | 611 | if ($s !== false) { |
613 | 612 | echo 'Connected to APRS server! '."\n"; |
614 | 613 | $authstart = time(); |
615 | 614 | $this->socket = $s; |
616 | - $send = socket_send( $this->socket , $aprs_login , strlen($aprs_login) , 0 ); |
|
617 | - socket_set_option($this->socket,SOL_SOCKET,SO_KEEPALIVE,1); |
|
618 | - while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) { |
|
615 | + $send = socket_send($this->socket, $aprs_login, strlen($aprs_login), 0); |
|
616 | + socket_set_option($this->socket, SOL_SOCKET, SO_KEEPALIVE, 1); |
|
617 | + while ($msgin = socket_read($this->socket, 1000, PHP_NORMAL_READ)) { |
|
619 | 618 | if (strpos($msgin, "$aprs_ssid verified") !== FALSE) { |
620 | 619 | echo 'APRS user verified !'."\n"; |
621 | 620 | $this->connected = true; |
622 | 621 | return true; |
623 | 622 | break; |
624 | 623 | } |
625 | - if (time()-$authstart > 5) { |
|
624 | + if (time() - $authstart > 5) { |
|
626 | 625 | echo 'APRS timeout'."\n"; |
627 | 626 | break; |
628 | 627 | } |
@@ -637,7 +636,7 @@ discard block |
||
637 | 636 | public function send($data) { |
638 | 637 | global $globalDebug; |
639 | 638 | if ($this->connected === false) $this->connect(); |
640 | - $send = socket_send( $this->socket , $data , strlen($data),0); |
|
639 | + $send = socket_send($this->socket, $data, strlen($data), 0); |
|
641 | 640 | if ($send === FALSE) { |
642 | 641 | if ($globalDebug) echo 'Reconnect...'; |
643 | 642 | socket_close($this->socket); |
@@ -647,17 +646,17 @@ discard block |
||
647 | 646 | } |
648 | 647 | |
649 | 648 | class APRSSpotter extends APRS { |
650 | - public function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$altitude_real,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) { |
|
649 | + public function addLiveSpotterData($id, $ident, $aircraft_icao, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $altitude_real, $heading, $speed, $datetime, $departure_airport_time, $arrival_airport_time, $squawk, $route_stop, $hex, $putinarchive, $registration, $pilot_id, $pilot_name, $verticalrate, $noarchive, $ground, $format_source, $source_name, $over_country) { |
|
651 | 650 | $Common = new Common(); |
652 | 651 | date_default_timezone_set('UTC'); |
653 | 652 | if ($latitude != '' && $longitude != '') { |
654 | 653 | $lat = $latitude; |
655 | 654 | $long = $longitude; |
656 | - $latitude = $Common->convertDM($latitude,'latitude'); |
|
657 | - $longitude = $Common->convertDM($longitude,'longitude'); |
|
658 | - $coordinate = sprintf("%02d",$latitude['deg']).str_pad(number_format($latitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d",$longitude['deg']).str_pad(number_format($longitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$longitude['NSEW']; |
|
659 | - $w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000)); |
|
660 | - $w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000)); |
|
655 | + $latitude = $Common->convertDM($latitude, 'latitude'); |
|
656 | + $longitude = $Common->convertDM($longitude, 'longitude'); |
|
657 | + $coordinate = sprintf("%02d", $latitude['deg']).str_pad(number_format($latitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d", $longitude['deg']).str_pad(number_format($longitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$longitude['NSEW']; |
|
658 | + $w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000)); |
|
659 | + $w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000)); |
|
661 | 660 | $w = $w1.$w2; |
662 | 661 | //$w = '00'; |
663 | 662 | $custom = ''; |
@@ -684,26 +683,26 @@ discard block |
||
684 | 683 | $geoid= round($GeoidClass->get($lat,$long)*3.28084,2); |
685 | 684 | $altitude_real = round($altitude_real + $geoid); |
686 | 685 | */ |
687 | - $this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.' *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n"); |
|
686 | + $this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.' *'.date('His', strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude_real, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n"); |
|
688 | 687 | } |
689 | 688 | } |
690 | 689 | } |
691 | 690 | class APRSMarine extends APRS { |
692 | - public function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$statusid,$noarchive,$format_source,$source_name,$over_country) { |
|
691 | + public function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed, $datetime, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $statusid, $noarchive, $format_source, $source_name, $over_country) { |
|
693 | 692 | $Common = new Common(); |
694 | 693 | date_default_timezone_set('UTC'); |
695 | 694 | if ($latitude != '' && $longitude != '') { |
696 | - $latitude = $Common->convertDM($latitude,'latitude'); |
|
697 | - $longitude = $Common->convertDM($longitude,'longitude'); |
|
698 | - $coordinate = sprintf("%02d",$latitude['deg']).str_pad(number_format($latitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d",$longitude['deg']).str_pad(number_format($longitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$longitude['NSEW']; |
|
699 | - $w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000)); |
|
700 | - $w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000)); |
|
695 | + $latitude = $Common->convertDM($latitude, 'latitude'); |
|
696 | + $longitude = $Common->convertDM($longitude, 'longitude'); |
|
697 | + $coordinate = sprintf("%02d", $latitude['deg']).str_pad(number_format($latitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d", $longitude['deg']).str_pad(number_format($longitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$longitude['NSEW']; |
|
698 | + $w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000)); |
|
699 | + $w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000)); |
|
701 | 700 | $w = $w1.$w2; |
702 | 701 | //$w = '00'; |
703 | 702 | $custom = ''; |
704 | 703 | if ($ident != '') { |
705 | 704 | if ($custom != '') $custom .= '/'; |
706 | - $custom .= 'CS='.str_replace(' ','_',$ident); |
|
705 | + $custom .= 'CS='.str_replace(' ', '_', $ident); |
|
707 | 706 | } |
708 | 707 | if ($typeid != '') { |
709 | 708 | if ($custom != '') $custom .= '/'; |
@@ -723,11 +722,11 @@ discard block |
||
723 | 722 | } |
724 | 723 | if ($arrival_code != '') { |
725 | 724 | if ($custom != '') $custom .= '/'; |
726 | - $custom .= 'AC='.str_replace(' ','_',$arrival_code); |
|
725 | + $custom .= 'AC='.str_replace(' ', '_', $arrival_code); |
|
727 | 726 | } |
728 | 727 | if ($custom != '') $custom = ' '.$custom; |
729 | 728 | $altitude = 0; |
730 | - $this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n"); |
|
729 | + $this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His', strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n"); |
|
731 | 730 | } |
732 | 731 | } |
733 | 732 | } |
@@ -9,25 +9,25 @@ discard block |
||
9 | 9 | require_once(dirname(__FILE__).'/class.Stats.php'); |
10 | 10 | require_once(dirname(__FILE__).'/class.Source.php'); |
11 | 11 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
12 | - require_once(dirname(__FILE__).'/class.APRS.php'); |
|
12 | + require_once(dirname(__FILE__).'/class.APRS.php'); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | class MarineImport { |
16 | - private $all_tracked = array(); |
|
17 | - private $last_delete_hourly = 0; |
|
18 | - private $last_delete = 0; |
|
19 | - private $stats = array(); |
|
20 | - private $tmd = 0; |
|
21 | - private $source_location = array(); |
|
22 | - public $db = null; |
|
23 | - public $nb = 0; |
|
16 | + private $all_tracked = array(); |
|
17 | + private $last_delete_hourly = 0; |
|
18 | + private $last_delete = 0; |
|
19 | + private $stats = array(); |
|
20 | + private $tmd = 0; |
|
21 | + private $source_location = array(); |
|
22 | + public $db = null; |
|
23 | + public $nb = 0; |
|
24 | 24 | |
25 | - public function __construct($dbc = null) { |
|
25 | + public function __construct($dbc = null) { |
|
26 | 26 | global $globalBeta, $globalServerAPRS, $APRSMarine, $globalNoDB; |
27 | 27 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
28 | - $Connection = new Connection($dbc); |
|
29 | - $this->db = $Connection->db(); |
|
30 | - date_default_timezone_set('UTC'); |
|
28 | + $Connection = new Connection($dbc); |
|
29 | + $this->db = $Connection->db(); |
|
30 | + date_default_timezone_set('UTC'); |
|
31 | 31 | } |
32 | 32 | // Get previous source stats |
33 | 33 | /* |
@@ -46,57 +46,57 @@ discard block |
||
46 | 46 | } |
47 | 47 | */ |
48 | 48 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
49 | - $APRSMarine = new APRSMarine(); |
|
50 | - //$APRSSpotter->connect(); |
|
49 | + $APRSMarine = new APRSMarine(); |
|
50 | + //$APRSSpotter->connect(); |
|
51 | + } |
|
51 | 52 | } |
52 | - } |
|
53 | 53 | |
54 | - public function checkAll() { |
|
54 | + public function checkAll() { |
|
55 | 55 | global $globalDebug, $globalNoDB; |
56 | 56 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
57 | - if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
58 | - foreach ($this->all_tracked as $key => $flight) { |
|
57 | + if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
58 | + foreach ($this->all_tracked as $key => $flight) { |
|
59 | 59 | if (isset($this->all_tracked[$key]['id'])) { |
60 | - //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
|
61 | - $Marine = new Marine($this->db); |
|
62 | - $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
|
60 | + //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
|
61 | + $Marine = new Marine($this->db); |
|
62 | + $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
|
63 | 63 | } |
64 | - } |
|
64 | + } |
|
65 | + } |
|
65 | 66 | } |
66 | - } |
|
67 | 67 | |
68 | - public function del() { |
|
68 | + public function del() { |
|
69 | 69 | global $globalDebug, $globalNoDB, $globalNoImport; |
70 | 70 | // Delete old infos |
71 | 71 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
72 | 72 | foreach ($this->all_tracked as $key => $flight) { |
73 | - if (isset($flight['lastupdate'])) { |
|
74 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
75 | - if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
|
76 | - if (isset($this->all_tracked[$key]['id'])) { |
|
77 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
78 | - /* |
|
73 | + if (isset($flight['lastupdate'])) { |
|
74 | + if ($flight['lastupdate'] < (time()-3000)) { |
|
75 | + if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
|
76 | + if (isset($this->all_tracked[$key]['id'])) { |
|
77 | + if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
78 | + /* |
|
79 | 79 | $MarineLive = new MarineLive(); |
80 | 80 | $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
81 | 81 | $MarineLive->db = null; |
82 | 82 | */ |
83 | - //$real_arrival = $this->arrival($key); |
|
84 | - $Marine = new Marine($this->db); |
|
85 | - if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
|
83 | + //$real_arrival = $this->arrival($key); |
|
84 | + $Marine = new Marine($this->db); |
|
85 | + if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
|
86 | 86 | $result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
87 | 87 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
88 | - } |
|
89 | - // Put in archive |
|
88 | + } |
|
89 | + // Put in archive |
|
90 | 90 | // $Marine->db = null; |
91 | 91 | } |
92 | - } |
|
93 | - unset($this->all_tracked[$key]); |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
92 | + } |
|
93 | + unset($this->all_tracked[$key]); |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | - public function add($line) { |
|
99 | + public function add($line) { |
|
100 | 100 | global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine; |
101 | 101 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
102 | 102 | date_default_timezone_set('UTC'); |
@@ -105,83 +105,83 @@ discard block |
||
105 | 105 | |
106 | 106 | // SBS format is CSV format |
107 | 107 | if(is_array($line) && isset($line['mmsi'])) { |
108 | - //print_r($line); |
|
109 | - if (isset($line['mmsi'])) { |
|
108 | + //print_r($line); |
|
109 | + if (isset($line['mmsi'])) { |
|
110 | 110 | |
111 | 111 | |
112 | 112 | // Increment message number |
113 | 113 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
114 | - $current_date = date('Y-m-d'); |
|
115 | - if (isset($line['source_name'])) $source = $line['source_name']; |
|
116 | - else $source = ''; |
|
117 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
118 | - if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
119 | - $this->stats[$current_date][$source]['msg']['date'] = time(); |
|
120 | - $this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
121 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
114 | + $current_date = date('Y-m-d'); |
|
115 | + if (isset($line['source_name'])) $source = $line['source_name']; |
|
116 | + else $source = ''; |
|
117 | + if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
118 | + if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
119 | + $this->stats[$current_date][$source]['msg']['date'] = time(); |
|
120 | + $this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
121 | + } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | |
125 | 125 | $Common = new Common(); |
126 | 126 | $AIS = new AIS(); |
127 | - if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
128 | - else $id = trim($line['id']); |
|
127 | + if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
128 | + else $id = trim($line['id']); |
|
129 | 129 | |
130 | 130 | if (!isset($this->all_tracked[$id])) { |
131 | - $this->all_tracked[$id] = array(); |
|
132 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
133 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '')); |
|
134 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
135 | - if (!isset($line['id'])) { |
|
131 | + $this->all_tracked[$id] = array(); |
|
132 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
133 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '')); |
|
134 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
135 | + if (!isset($line['id'])) { |
|
136 | 136 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
137 | 137 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
138 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
139 | - if ($globalAllTracked !== FALSE) $dataFound = true; |
|
138 | + } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
139 | + if ($globalAllTracked !== FALSE) $dataFound = true; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
143 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
144 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
143 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
144 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
145 | 145 | $Marine = new Marine($this->db); |
146 | 146 | $identity = $Marine->getIdentity($line['mmsi']); |
147 | 147 | if (!empty($identity)) { |
148 | - $this->all_tracked[$id]['ident'] = $identity['ship_name']; |
|
149 | - $this->all_tracked[$id]['type'] = $identity['type']; |
|
148 | + $this->all_tracked[$id]['ident'] = $identity['ship_name']; |
|
149 | + $this->all_tracked[$id]['type'] = $identity['type']; |
|
150 | 150 | } |
151 | 151 | //print_r($identity); |
152 | 152 | unset($Marine); |
153 | 153 | //$dataFound = true; |
154 | - } |
|
154 | + } |
|
155 | 155 | } |
156 | 156 | if (isset($line['type_id'])) { |
157 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
158 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id'])); |
|
157 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
158 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id'])); |
|
159 | 159 | } |
160 | 160 | if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') { |
161 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
161 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
162 | 162 | } |
163 | 163 | if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') { |
164 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type'])); |
|
164 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type'])); |
|
165 | 165 | } |
166 | 166 | if (isset($line['imo']) && $line['imo'] != '') { |
167 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
167 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
168 | 168 | } |
169 | 169 | if (isset($line['callsign']) && $line['callsign'] != '') { |
170 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
170 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
171 | 171 | } |
172 | 172 | if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
173 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
|
173 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
|
174 | 174 | } |
175 | 175 | if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
176 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
176 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | //if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) { |
180 | 180 | if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) { |
181 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
182 | - if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
181 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
182 | + if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
183 | 183 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
184 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
184 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
185 | 185 | $timeelapsed = microtime(true); |
186 | 186 | $Marine = new Marine($this->db); |
187 | 187 | $fromsource = NULL; |
@@ -190,20 +190,20 @@ discard block |
||
190 | 190 | $Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']); |
191 | 191 | $Marine->db = null; |
192 | 192 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
193 | - } |
|
193 | + } |
|
194 | 194 | } |
195 | - } |
|
196 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
195 | + } |
|
196 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) { |
200 | - if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
|
200 | + if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
|
201 | 201 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
202 | - } else { |
|
202 | + } else { |
|
203 | 203 | if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
204 | 204 | elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
205 | 205 | return ''; |
206 | - } |
|
206 | + } |
|
207 | 207 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) { |
208 | 208 | if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
209 | 209 | return ''; |
@@ -220,24 +220,24 @@ discard block |
||
220 | 220 | |
221 | 221 | |
222 | 222 | if (isset($line['speed'])) { |
223 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
224 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
223 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
224 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
225 | 225 | } else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) { |
226 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
227 | - if ($distance > 1000 && $distance < 10000) { |
|
226 | + $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
227 | + if ($distance > 1000 && $distance < 10000) { |
|
228 | 228 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
229 | 229 | $speed = $speed*3.6; |
230 | 230 | if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
231 | 231 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
232 | - } |
|
232 | + } |
|
233 | 233 | } |
234 | 234 | |
235 | - if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
236 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
237 | - else unset($timediff); |
|
238 | - if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) { |
|
235 | + if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
236 | + if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
237 | + else unset($timediff); |
|
238 | + if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) { |
|
239 | 239 | if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) { |
240 | - if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
|
240 | + if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
|
241 | 241 | $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
242 | 242 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
243 | 243 | $this->all_tracked[$id]['putinarchive'] = true; |
@@ -245,211 +245,211 @@ discard block |
||
245 | 245 | if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
246 | 246 | $timeelapsed = microtime(true); |
247 | 247 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
248 | - $Marine = new Marine($this->db); |
|
249 | - $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
250 | - if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
251 | - $Marine->db = null; |
|
252 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
248 | + $Marine = new Marine($this->db); |
|
249 | + $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
250 | + if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
251 | + $Marine->db = null; |
|
252 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
253 | 253 | } |
254 | 254 | $this->tmd = 0; |
255 | 255 | if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
256 | - } |
|
256 | + } |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
260 | 260 | if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
261 | 261 | if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
262 | - $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
|
263 | - $dataFound = true; |
|
264 | - $this->all_tracked[$id]['time_last_coord'] = time(); |
|
262 | + $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
|
263 | + $dataFound = true; |
|
264 | + $this->all_tracked[$id]['time_last_coord'] = time(); |
|
265 | 265 | } |
266 | 266 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
267 | 267 | } |
268 | 268 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
269 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
269 | + if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
270 | 270 | if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
271 | 271 | if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
272 | - $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
|
273 | - $dataFound = true; |
|
274 | - $this->all_tracked[$id]['time_last_coord'] = time(); |
|
272 | + $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
|
273 | + $dataFound = true; |
|
274 | + $this->all_tracked[$id]['time_last_coord'] = time(); |
|
275 | 275 | } |
276 | 276 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude'])); |
277 | 277 | } |
278 | 278 | |
279 | - } else if ($globalDebug && $timediff > 20) { |
|
279 | + } else if ($globalDebug && $timediff > 20) { |
|
280 | 280 | $this->tmd = $this->tmd + 1; |
281 | 281 | echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n"; |
282 | 282 | echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -"; |
283 | 283 | echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
284 | 284 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n"; |
285 | - } |
|
285 | + } |
|
286 | 286 | } |
287 | 287 | if (isset($line['last_update']) && $line['last_update'] != '') { |
288 | - if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
289 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
288 | + if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
289 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
290 | 290 | } |
291 | 291 | if (isset($line['format_source']) && $line['format_source'] != '') { |
292 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
292 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
293 | 293 | } |
294 | 294 | if (isset($line['source_name']) && $line['source_name'] != '') { |
295 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
295 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
296 | 296 | } |
297 | 297 | if (isset($line['status']) && $line['status'] != '') { |
298 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
298 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
299 | 299 | } |
300 | 300 | if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) { |
301 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id'])); |
|
302 | - if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
301 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id'])); |
|
302 | + if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
303 | 303 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
304 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
304 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
305 | 305 | $Marine = new Marine($this->db); |
306 | 306 | $Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']); |
307 | 307 | unset($Marine); |
308 | - } |
|
308 | + } |
|
309 | + } |
|
309 | 310 | } |
310 | - } |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
314 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
314 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | if (isset($line['heading']) && $line['heading'] != '') { |
318 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
319 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
320 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
321 | - //$dataFound = true; |
|
318 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
319 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
320 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
321 | + //$dataFound = true; |
|
322 | 322 | } elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) { |
323 | - $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
324 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
325 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
326 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
323 | + $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
324 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
325 | + if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
326 | + if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
327 | 327 | } |
328 | 328 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
329 | 329 | |
330 | 330 | |
331 | 331 | |
332 | 332 | if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) { |
333 | - $this->all_tracked[$id]['lastupdate'] = time(); |
|
334 | - if ($this->all_tracked[$id]['addedMarine'] == 0) { |
|
335 | - if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
336 | - if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
|
333 | + $this->all_tracked[$id]['lastupdate'] = time(); |
|
334 | + if ($this->all_tracked[$id]['addedMarine'] == 0) { |
|
335 | + if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
336 | + if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
|
337 | 337 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
338 | - if ($globalDebug) echo "Check if vessel is already in DB..."; |
|
339 | - $timeelapsed = microtime(true); |
|
340 | - $MarineLive = new MarineLive($this->db); |
|
341 | - if (isset($line['id'])) { |
|
338 | + if ($globalDebug) echo "Check if vessel is already in DB..."; |
|
339 | + $timeelapsed = microtime(true); |
|
340 | + $MarineLive = new MarineLive($this->db); |
|
341 | + if (isset($line['id'])) { |
|
342 | 342 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
343 | 343 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
344 | - } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
|
344 | + } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
|
345 | 345 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
346 | 346 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
347 | - } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
|
347 | + } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
|
348 | 348 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
349 | 349 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
350 | - } else $recent_ident = ''; |
|
351 | - $MarineLive->db=null; |
|
352 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
353 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
350 | + } else $recent_ident = ''; |
|
351 | + $MarineLive->db=null; |
|
352 | + if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
353 | + elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
354 | 354 | } else $recent_ident = ''; |
355 | - } else { |
|
355 | + } else { |
|
356 | 356 | $recent_ident = ''; |
357 | 357 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
358 | - } |
|
359 | - //if there was no vessel with the same callsign within the last hour and go post it into the archive |
|
360 | - if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
361 | - { |
|
358 | + } |
|
359 | + //if there was no vessel with the same callsign within the last hour and go post it into the archive |
|
360 | + if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
361 | + { |
|
362 | 362 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
363 | 363 | //adds the spotter data for the archive |
364 | - $highlight = ''; |
|
365 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
366 | - if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
364 | + $highlight = ''; |
|
365 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
366 | + if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
367 | 367 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
368 | - $timeelapsed = microtime(true); |
|
369 | - $Marine = new Marine($this->db); |
|
370 | - $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
|
371 | - $Marine->db = null; |
|
372 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
373 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
368 | + $timeelapsed = microtime(true); |
|
369 | + $Marine = new Marine($this->db); |
|
370 | + $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
|
371 | + $Marine->db = null; |
|
372 | + if ($globalDebug && isset($result)) echo $result."\n"; |
|
373 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
374 | + } |
|
374 | 375 | } |
375 | - } |
|
376 | - if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
|
376 | + if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
|
377 | 377 | // Add source stat in DB |
378 | 378 | $Stats = new Stats($this->db); |
379 | 379 | if (!empty($this->stats)) { |
380 | - if ($globalDebug) echo 'Add source stats : '; |
|
381 | - foreach($this->stats as $date => $data) { |
|
380 | + if ($globalDebug) echo 'Add source stats : '; |
|
381 | + foreach($this->stats as $date => $data) { |
|
382 | 382 | foreach($data as $source => $sourced) { |
383 | - //print_r($sourced); |
|
384 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
385 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
386 | - if (isset($sourced['msg'])) { |
|
387 | - if (time() - $sourced['msg']['date'] > 10) { |
|
388 | - $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
389 | - echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date); |
|
390 | - unset($this->stats[$date][$source]['msg']); |
|
391 | - } |
|
392 | - } |
|
393 | - } |
|
394 | - if ($date != date('Y-m-d')) { |
|
395 | - unset($this->stats[$date]); |
|
396 | - } |
|
397 | - } |
|
398 | - if ($globalDebug) echo 'Done'."\n"; |
|
383 | + //print_r($sourced); |
|
384 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
385 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
386 | + if (isset($sourced['msg'])) { |
|
387 | + if (time() - $sourced['msg']['date'] > 10) { |
|
388 | + $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
389 | + echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date); |
|
390 | + unset($this->stats[$date][$source]['msg']); |
|
391 | + } |
|
392 | + } |
|
393 | + } |
|
394 | + if ($date != date('Y-m-d')) { |
|
395 | + unset($this->stats[$date]); |
|
396 | + } |
|
397 | + } |
|
398 | + if ($globalDebug) echo 'Done'."\n"; |
|
399 | 399 | } |
400 | 400 | $Stats->db = null; |
401 | - } |
|
401 | + } |
|
402 | 402 | |
403 | - $this->del(); |
|
403 | + $this->del(); |
|
404 | 404 | //$ignoreImport = false; |
405 | 405 | $this->all_tracked[$id]['addedMarine'] = 1; |
406 | 406 | //print_r($this->all_tracked[$id]); |
407 | 407 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
408 | - if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
409 | - //MarineLive->deleteLiveMarineDataNotUpdated(); |
|
410 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
408 | + if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
409 | + //MarineLive->deleteLiveMarineDataNotUpdated(); |
|
410 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
411 | 411 | $MarineLive = new MarineLive($this->db); |
412 | 412 | $MarineLive->deleteLiveMarineData(); |
413 | 413 | $MarineLive->db=null; |
414 | 414 | if ($globalDebug) echo " Done\n"; |
415 | - } |
|
416 | - $this->last_delete = time(); |
|
415 | + } |
|
416 | + $this->last_delete = time(); |
|
417 | 417 | } |
418 | - } elseif ($recent_ident != '') { |
|
418 | + } elseif ($recent_ident != '') { |
|
419 | 419 | $this->all_tracked[$id]['id'] = $recent_ident; |
420 | 420 | $this->all_tracked[$id]['addedMarine'] = 1; |
421 | 421 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
422 | - if (isset($globalDaemon) && !$globalDaemon) { |
|
422 | + if (isset($globalDaemon) && !$globalDaemon) { |
|
423 | 423 | $Marine = new Marine($this->db); |
424 | 424 | $Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']); |
425 | 425 | $Marine->db = null; |
426 | - } |
|
426 | + } |
|
427 | 427 | } |
428 | 428 | |
429 | - } |
|
429 | + } |
|
430 | + } |
|
430 | 431 | } |
431 | - } |
|
432 | - //adds the spotter LIVE data |
|
433 | - if ($globalDebug) { |
|
432 | + //adds the spotter LIVE data |
|
433 | + if ($globalDebug) { |
|
434 | 434 | echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n"; |
435 | - } |
|
436 | - $ignoreImport = false; |
|
435 | + } |
|
436 | + $ignoreImport = false; |
|
437 | 437 | |
438 | - if (!$ignoreImport) { |
|
438 | + if (!$ignoreImport) { |
|
439 | 439 | if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
440 | 440 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
441 | 441 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
442 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
442 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
443 | 443 | $timeelapsed = microtime(true); |
444 | 444 | $MarineLive = new MarineLive($this->db); |
445 | 445 | $result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
446 | 446 | $MarineLive->db = null; |
447 | 447 | if ($globalDebug) echo $result."\n"; |
448 | 448 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
449 | - } |
|
449 | + } |
|
450 | 450 | } |
451 | 451 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) { |
452 | - $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
452 | + $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
453 | 453 | } |
454 | 454 | $this->all_tracked[$id]['putinarchive'] = false; |
455 | 455 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | if ($stats_heading == 16) $stats_heading = 0; |
482 | 482 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
483 | 483 | for ($i=0;$i<=15;$i++) { |
484 | - $this->stats[$current_date][$source]['polar'][$i] = 0; |
|
484 | + $this->stats[$current_date][$source]['polar'][$i] = 0; |
|
485 | 485 | } |
486 | 486 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
487 | 487 | } else { |
@@ -494,11 +494,11 @@ discard block |
||
494 | 494 | //var_dump($this->stats); |
495 | 495 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
496 | 496 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
497 | - end($this->stats[$current_date][$source]['hist']); |
|
498 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
497 | + end($this->stats[$current_date][$source]['hist']); |
|
498 | + $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
499 | 499 | } else $mini = 0; |
500 | 500 | for ($i=$mini;$i<=$distance;$i+=10) { |
501 | - $this->stats[$current_date][$source]['hist'][$i] = 0; |
|
501 | + $this->stats[$current_date][$source]['hist'][$i] = 0; |
|
502 | 502 | } |
503 | 503 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
504 | 504 | } else { |
@@ -514,24 +514,24 @@ discard block |
||
514 | 514 | |
515 | 515 | |
516 | 516 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
517 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
517 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
518 | 518 | if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
519 | 519 | $MarineLive = new MarineLive($this->db); |
520 | 520 | $MarineLive->deleteLiveMarineDataNotUpdated(); |
521 | 521 | $MarineLive->db = null; |
522 | 522 | //MarineLive->deleteLiveMarineData(); |
523 | 523 | if ($globalDebug) echo " Done\n"; |
524 | - } |
|
525 | - $this->last_delete_hourly = time(); |
|
524 | + } |
|
525 | + $this->last_delete_hourly = time(); |
|
526 | 526 | } |
527 | 527 | |
528 | - } |
|
529 | - //$ignoreImport = false; |
|
528 | + } |
|
529 | + //$ignoreImport = false; |
|
530 | 530 | } |
531 | 531 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
532 | 532 | if ($send) return $this->all_tracked[$id]; |
533 | - } |
|
533 | + } |
|
534 | + } |
|
534 | 535 | } |
535 | - } |
|
536 | 536 | } |
537 | 537 | ?> |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | if (isset($this->all_tracked[$key]['id'])) { |
60 | 60 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
61 | 61 | $Marine = new Marine($this->db); |
62 | - $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
|
62 | + $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
72 | 72 | foreach ($this->all_tracked as $key => $flight) { |
73 | 73 | if (isset($flight['lastupdate'])) { |
74 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
74 | + if ($flight['lastupdate'] < (time() - 3000)) { |
|
75 | 75 | if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
76 | 76 | if (isset($this->all_tracked[$key]['id'])) { |
77 | 77 | if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | //$real_arrival = $this->arrival($key); |
84 | 84 | $Marine = new Marine($this->db); |
85 | 85 | if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
86 | - $result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
|
86 | + $result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']); |
|
87 | 87 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
88 | 88 | } |
89 | 89 | // Put in archive |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | public function add($line) { |
100 | - global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine; |
|
100 | + global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS, $APRSMarine; |
|
101 | 101 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
102 | 102 | date_default_timezone_set('UTC'); |
103 | 103 | $dataFound = false; |
104 | 104 | $send = false; |
105 | 105 | |
106 | 106 | // SBS format is CSV format |
107 | - if(is_array($line) && isset($line['mmsi'])) { |
|
107 | + if (is_array($line) && isset($line['mmsi'])) { |
|
108 | 108 | //print_r($line); |
109 | 109 | if (isset($line['mmsi'])) { |
110 | 110 | |
@@ -129,18 +129,18 @@ discard block |
||
129 | 129 | |
130 | 130 | if (!isset($this->all_tracked[$id])) { |
131 | 131 | $this->all_tracked[$id] = array(); |
132 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
133 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '')); |
|
134 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
132 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0)); |
|
133 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'typeid' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'status_id' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => '', 'mmsi_type' => '')); |
|
134 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time())); |
|
135 | 135 | if (!isset($line['id'])) { |
136 | 136 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
137 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
138 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
137 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi'))); |
|
138 | + } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id'])); |
|
139 | 139 | if ($globalAllTracked !== FALSE) $dataFound = true; |
140 | 140 | } |
141 | 141 | |
142 | 142 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
143 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
143 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi'])); |
|
144 | 144 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
145 | 145 | $Marine = new Marine($this->db); |
146 | 146 | $identity = $Marine->getIdentity($line['mmsi']); |
@@ -154,65 +154,65 @@ discard block |
||
154 | 154 | } |
155 | 155 | } |
156 | 156 | if (isset($line['type_id'])) { |
157 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
158 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id'])); |
|
157 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id']))); |
|
158 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $line['type_id'])); |
|
159 | 159 | } |
160 | 160 | if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') { |
161 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
161 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type'])); |
|
162 | 162 | } |
163 | 163 | if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') { |
164 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type'])); |
|
164 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type'])); |
|
165 | 165 | } |
166 | 166 | if (isset($line['imo']) && $line['imo'] != '') { |
167 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
167 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo'])); |
|
168 | 168 | } |
169 | 169 | if (isset($line['callsign']) && $line['callsign'] != '') { |
170 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
170 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign'])); |
|
171 | 171 | } |
172 | 172 | if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
173 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
|
173 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code'])); |
|
174 | 174 | } |
175 | 175 | if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
176 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
176 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date'])); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | //if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) { |
180 | 180 | if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) { |
181 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
181 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident']))); |
|
182 | 182 | if ($this->all_tracked[$id]['addedMarine'] == 1) { |
183 | 183 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
184 | 184 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
185 | 185 | $timeelapsed = microtime(true); |
186 | 186 | $Marine = new Marine($this->db); |
187 | 187 | $fromsource = NULL; |
188 | - $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
|
188 | + $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource); |
|
189 | 189 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
190 | - $Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']); |
|
190 | + $Marine->addIdentity($this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['type']); |
|
191 | 191 | $Marine->db = null; |
192 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
192 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
196 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
196 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident'])); |
|
197 | 197 | } |
198 | 198 | |
199 | - if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) { |
|
199 | + if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 30*60 && strtotime($line['datetime']) < time() + 20*60) { |
|
200 | 200 | if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
201 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
|
201 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime'])); |
|
202 | 202 | } else { |
203 | 203 | if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
204 | 204 | elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
205 | 205 | return ''; |
206 | 206 | } |
207 | - } elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) { |
|
207 | + } elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time() - 30*60) { |
|
208 | 208 | if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
209 | 209 | return ''; |
210 | - } elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) { |
|
210 | + } elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time() + 20*60) { |
|
211 | 211 | if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
212 | 212 | return ''; |
213 | 213 | } elseif (!isset($line['datetime'])) { |
214 | 214 | date_default_timezone_set('UTC'); |
215 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
215 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s'))); |
|
216 | 216 | } else { |
217 | 217 | if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!"; |
218 | 218 | return ''; |
@@ -220,24 +220,24 @@ discard block |
||
220 | 220 | |
221 | 221 | |
222 | 222 | if (isset($line['speed'])) { |
223 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
224 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
223 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed']))); |
|
224 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true)); |
|
225 | 225 | } else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) { |
226 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
226 | + $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm'); |
|
227 | 227 | if ($distance > 1000 && $distance < 10000) { |
228 | 228 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
229 | 229 | $speed = $speed*3.6; |
230 | - if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
230 | + if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed))); |
|
231 | 231 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | 235 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
236 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
236 | + if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']); |
|
237 | 237 | else unset($timediff); |
238 | - if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) { |
|
238 | + if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')))) { |
|
239 | 239 | if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) { |
240 | - if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
|
240 | + if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'], $this->all_tracked[$id]['archive_longitude'], $this->all_tracked[$id]['livedb_latitude'], $this->all_tracked[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) { |
|
241 | 241 | $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
242 | 242 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
243 | 243 | $this->all_tracked[$id]['putinarchive'] = true; |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | $timeelapsed = microtime(true); |
247 | 247 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
248 | 248 | $Marine = new Marine($this->db); |
249 | - $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
249 | + $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']); |
|
250 | 250 | if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
251 | 251 | $Marine->db = null; |
252 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
252 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
253 | 253 | } |
254 | 254 | $this->tmd = 0; |
255 | 255 | if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
@@ -258,52 +258,52 @@ discard block |
||
258 | 258 | |
259 | 259 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
260 | 260 | if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
261 | - if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
|
261 | + if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
|
262 | 262 | $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
263 | 263 | $dataFound = true; |
264 | 264 | $this->all_tracked[$id]['time_last_coord'] = time(); |
265 | 265 | } |
266 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
|
266 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude'])); |
|
267 | 267 | } |
268 | 268 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
269 | 269 | if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
270 | 270 | if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
271 | - if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
|
271 | + if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
|
272 | 272 | $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
273 | 273 | $dataFound = true; |
274 | 274 | $this->all_tracked[$id]['time_last_coord'] = time(); |
275 | 275 | } |
276 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude'])); |
|
276 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude'])); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | } else if ($globalDebug && $timediff > 20) { |
280 | 280 | $this->tmd = $this->tmd + 1; |
281 | 281 | echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n"; |
282 | - echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -"; |
|
283 | - echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
|
282 | + echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -"; |
|
283 | + echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - "; |
|
284 | 284 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n"; |
285 | 285 | } |
286 | 286 | } |
287 | 287 | if (isset($line['last_update']) && $line['last_update'] != '') { |
288 | 288 | if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
289 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
289 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update'])); |
|
290 | 290 | } |
291 | 291 | if (isset($line['format_source']) && $line['format_source'] != '') { |
292 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
292 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source'])); |
|
293 | 293 | } |
294 | 294 | if (isset($line['source_name']) && $line['source_name'] != '') { |
295 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
295 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name'])); |
|
296 | 296 | } |
297 | 297 | if (isset($line['status']) && $line['status'] != '') { |
298 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
298 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status'])); |
|
299 | 299 | } |
300 | 300 | if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) { |
301 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id'])); |
|
301 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id'])); |
|
302 | 302 | if ($this->all_tracked[$id]['addedMarine'] == 1) { |
303 | 303 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
304 | 304 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
305 | 305 | $Marine = new Marine($this->db); |
306 | - $Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']); |
|
306 | + $Marine->updateStatusMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['status']); |
|
307 | 307 | unset($Marine); |
308 | 308 | } |
309 | 309 | } |
@@ -311,18 +311,18 @@ discard block |
||
311 | 311 | } |
312 | 312 | |
313 | 313 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
314 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
314 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true)); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | if (isset($line['heading']) && $line['heading'] != '') { |
318 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
319 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
320 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
318 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
319 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading']))); |
|
320 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true)); |
|
321 | 321 | //$dataFound = true; |
322 | 322 | } elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) { |
323 | - $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
324 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
325 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
323 | + $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'], $this->all_tracked[$id]['archive_longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']); |
|
324 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading))); |
|
325 | + if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
326 | 326 | if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
327 | 327 | } |
328 | 328 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) { |
333 | 333 | $this->all_tracked[$id]['lastupdate'] = time(); |
334 | 334 | if ($this->all_tracked[$id]['addedMarine'] == 0) { |
335 | - if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
335 | + if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
336 | 336 | if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
337 | 337 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
338 | 338 | if ($globalDebug) echo "Check if vessel is already in DB..."; |
@@ -340,37 +340,37 @@ discard block |
||
340 | 340 | $MarineLive = new MarineLive($this->db); |
341 | 341 | if (isset($line['id'])) { |
342 | 342 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
343 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
343 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
344 | 344 | } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
345 | 345 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
346 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
346 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
347 | 347 | } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
348 | 348 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
349 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
349 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
350 | 350 | } else $recent_ident = ''; |
351 | - $MarineLive->db=null; |
|
351 | + $MarineLive->db = null; |
|
352 | 352 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
353 | 353 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
354 | 354 | } else $recent_ident = ''; |
355 | 355 | } else { |
356 | 356 | $recent_ident = ''; |
357 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
|
357 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0)); |
|
358 | 358 | } |
359 | 359 | //if there was no vessel with the same callsign within the last hour and go post it into the archive |
360 | - if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
360 | + if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
361 | 361 | { |
362 | 362 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
363 | 363 | //adds the spotter data for the archive |
364 | 364 | $highlight = ''; |
365 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
365 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
366 | 366 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
367 | 367 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
368 | 368 | $timeelapsed = microtime(true); |
369 | 369 | $Marine = new Marine($this->db); |
370 | - $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
|
370 | + $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name']); |
|
371 | 371 | $Marine->db = null; |
372 | 372 | if ($globalDebug && isset($result)) echo $result."\n"; |
373 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
373 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
374 | 374 | } |
375 | 375 | } |
376 | 376 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
@@ -378,15 +378,15 @@ discard block |
||
378 | 378 | $Stats = new Stats($this->db); |
379 | 379 | if (!empty($this->stats)) { |
380 | 380 | if ($globalDebug) echo 'Add source stats : '; |
381 | - foreach($this->stats as $date => $data) { |
|
382 | - foreach($data as $source => $sourced) { |
|
381 | + foreach ($this->stats as $date => $data) { |
|
382 | + foreach ($data as $source => $sourced) { |
|
383 | 383 | //print_r($sourced); |
384 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
385 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
384 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar_marine', $date); |
|
385 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist_marine', $date); |
|
386 | 386 | if (isset($sourced['msg'])) { |
387 | 387 | if (time() - $sourced['msg']['date'] > 10) { |
388 | 388 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
389 | - echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date); |
|
389 | + echo $Stats->addStatSource($nbmsg, $source, 'msg_marine', $date); |
|
390 | 390 | unset($this->stats[$date][$source]['msg']); |
391 | 391 | } |
392 | 392 | } |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
411 | 411 | $MarineLive = new MarineLive($this->db); |
412 | 412 | $MarineLive->deleteLiveMarineData(); |
413 | - $MarineLive->db=null; |
|
413 | + $MarineLive->db = null; |
|
414 | 414 | if ($globalDebug) echo " Done\n"; |
415 | 415 | } |
416 | 416 | $this->last_delete = time(); |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
422 | 422 | if (isset($globalDaemon) && !$globalDaemon) { |
423 | 423 | $Marine = new Marine($this->db); |
424 | - $Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']); |
|
424 | + $Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime']); |
|
425 | 425 | $Marine->db = null; |
426 | 426 | } |
427 | 427 | } |
@@ -436,20 +436,20 @@ discard block |
||
436 | 436 | $ignoreImport = false; |
437 | 437 | |
438 | 438 | if (!$ignoreImport) { |
439 | - if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
439 | + if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
440 | 440 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
441 | 441 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
442 | 442 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
443 | 443 | $timeelapsed = microtime(true); |
444 | 444 | $MarineLive = new MarineLive($this->db); |
445 | - $result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
445 | + $result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']); |
|
446 | 446 | $MarineLive->db = null; |
447 | 447 | if ($globalDebug) echo $result."\n"; |
448 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
448 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) { |
452 | - $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
452 | + $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']); |
|
453 | 453 | } |
454 | 454 | $this->all_tracked[$id]['putinarchive'] = false; |
455 | 455 | |
@@ -468,19 +468,19 @@ discard block |
||
468 | 468 | $latitude = $globalCenterLatitude; |
469 | 469 | $longitude = $globalCenterLongitude; |
470 | 470 | } |
471 | - $this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude); |
|
471 | + $this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude); |
|
472 | 472 | } else { |
473 | 473 | $latitude = $this->source_location[$source]['latitude']; |
474 | 474 | $longitude = $this->source_location[$source]['longitude']; |
475 | 475 | } |
476 | - $stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
476 | + $stats_heading = $Common->getHeading($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']); |
|
477 | 477 | //$stats_heading = $stats_heading%22.5; |
478 | 478 | $stats_heading = round($stats_heading/22.5); |
479 | - $stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
479 | + $stats_distance = $Common->distance($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']); |
|
480 | 480 | $current_date = date('Y-m-d'); |
481 | 481 | if ($stats_heading == 16) $stats_heading = 0; |
482 | 482 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
483 | - for ($i=0;$i<=15;$i++) { |
|
483 | + for ($i = 0; $i <= 15; $i++) { |
|
484 | 484 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
485 | 485 | } |
486 | 486 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
@@ -495,9 +495,9 @@ discard block |
||
495 | 495 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
496 | 496 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
497 | 497 | end($this->stats[$current_date][$source]['hist']); |
498 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
498 | + $mini = key($this->stats[$current_date][$source]['hist']) + 10; |
|
499 | 499 | } else $mini = 0; |
500 | - for ($i=$mini;$i<=$distance;$i+=10) { |
|
500 | + for ($i = $mini; $i <= $distance; $i += 10) { |
|
501 | 501 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
502 | 502 | } |
503 | 503 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | |
510 | 510 | $this->all_tracked[$id]['lastupdate'] = time(); |
511 | 511 | if ($this->all_tracked[$id]['putinarchive']) $send = true; |
512 | - } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
512 | + } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n"; |
|
513 | 513 | //$this->del(); |
514 | 514 | |
515 | 515 |
@@ -54,7 +54,9 @@ discard block |
||
54 | 54 | public function checkAll() { |
55 | 55 | global $globalDebug, $globalNoDB; |
56 | 56 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
57 | - if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
57 | + if ($globalDebug) { |
|
58 | + echo "Update last seen tracked data...\n"; |
|
59 | + } |
|
58 | 60 | foreach ($this->all_tracked as $key => $flight) { |
59 | 61 | if (isset($this->all_tracked[$key]['id'])) { |
60 | 62 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
@@ -68,13 +70,17 @@ discard block |
||
68 | 70 | public function del() { |
69 | 71 | global $globalDebug, $globalNoDB, $globalNoImport; |
70 | 72 | // Delete old infos |
71 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
73 | + if ($globalDebug) { |
|
74 | + echo 'Delete old values and update latest data...'."\n"; |
|
75 | + } |
|
72 | 76 | foreach ($this->all_tracked as $key => $flight) { |
73 | 77 | if (isset($flight['lastupdate'])) { |
74 | 78 | if ($flight['lastupdate'] < (time()-3000)) { |
75 | 79 | if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
76 | 80 | if (isset($this->all_tracked[$key]['id'])) { |
77 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
81 | + if ($globalDebug) { |
|
82 | + echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
83 | + } |
|
78 | 84 | /* |
79 | 85 | $MarineLive = new MarineLive(); |
80 | 86 | $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
@@ -84,7 +90,9 @@ discard block |
||
84 | 90 | $Marine = new Marine($this->db); |
85 | 91 | if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
86 | 92 | $result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
87 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
93 | + if ($globalDebug && $result != 'success') { |
|
94 | + echo '!!! ERROR : '.$result."\n"; |
|
95 | + } |
|
88 | 96 | } |
89 | 97 | // Put in archive |
90 | 98 | // $Marine->db = null; |
@@ -98,7 +106,9 @@ discard block |
||
98 | 106 | |
99 | 107 | public function add($line) { |
100 | 108 | global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine; |
101 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
|
109 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
110 | + $globalCoordMinChange = '0.02'; |
|
111 | + } |
|
102 | 112 | date_default_timezone_set('UTC'); |
103 | 113 | $dataFound = false; |
104 | 114 | $send = false; |
@@ -112,20 +122,30 @@ discard block |
||
112 | 122 | // Increment message number |
113 | 123 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
114 | 124 | $current_date = date('Y-m-d'); |
115 | - if (isset($line['source_name'])) $source = $line['source_name']; |
|
116 | - else $source = ''; |
|
117 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
125 | + if (isset($line['source_name'])) { |
|
126 | + $source = $line['source_name']; |
|
127 | + } else { |
|
128 | + $source = ''; |
|
129 | + } |
|
130 | + if ($source == '' || $line['format_source'] == 'aprs') { |
|
131 | + $source = $line['format_source']; |
|
132 | + } |
|
118 | 133 | if (!isset($this->stats[$current_date][$source]['msg'])) { |
119 | 134 | $this->stats[$current_date][$source]['msg']['date'] = time(); |
120 | 135 | $this->stats[$current_date][$source]['msg']['nb'] = 1; |
121 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
136 | + } else { |
|
137 | + $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
138 | + } |
|
122 | 139 | } |
123 | 140 | |
124 | 141 | |
125 | 142 | $Common = new Common(); |
126 | 143 | $AIS = new AIS(); |
127 | - if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
128 | - else $id = trim($line['id']); |
|
144 | + if (!isset($line['id'])) { |
|
145 | + $id = trim($line['mmsi']); |
|
146 | + } else { |
|
147 | + $id = trim($line['id']); |
|
148 | + } |
|
129 | 149 | |
130 | 150 | if (!isset($this->all_tracked[$id])) { |
131 | 151 | $this->all_tracked[$id] = array(); |
@@ -133,10 +153,16 @@ discard block |
||
133 | 153 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '')); |
134 | 154 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
135 | 155 | if (!isset($line['id'])) { |
136 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
156 | + if (!isset($globalDaemon)) { |
|
157 | + $globalDaemon = TRUE; |
|
158 | + } |
|
137 | 159 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
138 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
139 | - if ($globalAllTracked !== FALSE) $dataFound = true; |
|
160 | + } else { |
|
161 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
162 | + } |
|
163 | + if ($globalAllTracked !== FALSE) { |
|
164 | + $dataFound = true; |
|
165 | + } |
|
140 | 166 | } |
141 | 167 | |
142 | 168 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
@@ -186,35 +212,50 @@ discard block |
||
186 | 212 | $Marine = new Marine($this->db); |
187 | 213 | $fromsource = NULL; |
188 | 214 | $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
189 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
215 | + if ($globalDebug && $result != 'success') { |
|
216 | + echo '!!! ERROR : '.$result."\n"; |
|
217 | + } |
|
190 | 218 | $Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']); |
191 | 219 | $Marine->db = null; |
192 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
220 | + if ($globalDebugTimeElapsed) { |
|
221 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
222 | + } |
|
193 | 223 | } |
194 | 224 | } |
195 | 225 | } |
196 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
226 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
227 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
228 | + } |
|
197 | 229 | } |
198 | 230 | |
199 | 231 | if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) { |
200 | 232 | if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
201 | 233 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
202 | 234 | } else { |
203 | - if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
|
204 | - elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
235 | + if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
236 | + echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
|
237 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
238 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
239 | + } |
|
205 | 240 | return ''; |
206 | 241 | } |
207 | 242 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) { |
208 | - if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
|
243 | + if ($globalDebug) { |
|
244 | + echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
|
245 | + } |
|
209 | 246 | return ''; |
210 | 247 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) { |
211 | - if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
|
248 | + if ($globalDebug) { |
|
249 | + echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
|
250 | + } |
|
212 | 251 | return ''; |
213 | 252 | } elseif (!isset($line['datetime'])) { |
214 | 253 | date_default_timezone_set('UTC'); |
215 | 254 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s'))); |
216 | 255 | } else { |
217 | - if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!"; |
|
256 | + if ($globalDebug) { |
|
257 | + echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!"; |
|
258 | + } |
|
218 | 259 | return ''; |
219 | 260 | } |
220 | 261 | |
@@ -227,14 +268,21 @@ discard block |
||
227 | 268 | if ($distance > 1000 && $distance < 10000) { |
228 | 269 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
229 | 270 | $speed = $speed*3.6; |
230 | - if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
231 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
271 | + if ($speed < 1000) { |
|
272 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
273 | + } |
|
274 | + if ($globalDebug) { |
|
275 | + echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
276 | + } |
|
232 | 277 | } |
233 | 278 | } |
234 | 279 | |
235 | 280 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
236 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
237 | - else unset($timediff); |
|
281 | + if (isset($this->all_tracked[$id]['time_last_coord'])) { |
|
282 | + $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
283 | + } else { |
|
284 | + unset($timediff); |
|
285 | + } |
|
238 | 286 | if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) { |
239 | 287 | if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) { |
240 | 288 | if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
@@ -242,22 +290,32 @@ discard block |
||
242 | 290 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
243 | 291 | $this->all_tracked[$id]['putinarchive'] = true; |
244 | 292 | |
245 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
293 | + if ($globalDebug) { |
|
294 | + echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
295 | + } |
|
246 | 296 | $timeelapsed = microtime(true); |
247 | 297 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
248 | 298 | $Marine = new Marine($this->db); |
249 | 299 | $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
250 | - if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
300 | + if (!empty($all_country)) { |
|
301 | + $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
302 | + } |
|
251 | 303 | $Marine->db = null; |
252 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
304 | + if ($globalDebugTimeElapsed) { |
|
305 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
306 | + } |
|
253 | 307 | } |
254 | 308 | $this->tmd = 0; |
255 | - if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
309 | + if ($globalDebug) { |
|
310 | + echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
311 | + } |
|
256 | 312 | } |
257 | 313 | } |
258 | 314 | |
259 | 315 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
260 | - if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
316 | + if (!isset($this->all_tracked[$id]['archive_latitude'])) { |
|
317 | + $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
318 | + } |
|
261 | 319 | if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
262 | 320 | $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
263 | 321 | $dataFound = true; |
@@ -266,8 +324,12 @@ discard block |
||
266 | 324 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
267 | 325 | } |
268 | 326 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
269 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
270 | - if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
327 | + if ($line['longitude'] > 180) { |
|
328 | + $line['longitude'] = $line['longitude'] - 360; |
|
329 | + } |
|
330 | + if (!isset($this->all_tracked[$id]['archive_longitude'])) { |
|
331 | + $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
332 | + } |
|
271 | 333 | if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
272 | 334 | $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
273 | 335 | $dataFound = true; |
@@ -285,7 +347,9 @@ discard block |
||
285 | 347 | } |
286 | 348 | } |
287 | 349 | if (isset($line['last_update']) && $line['last_update'] != '') { |
288 | - if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
350 | + if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) { |
|
351 | + $dataFound = true; |
|
352 | + } |
|
289 | 353 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
290 | 354 | } |
291 | 355 | if (isset($line['format_source']) && $line['format_source'] != '') { |
@@ -315,15 +379,21 @@ discard block |
||
315 | 379 | } |
316 | 380 | |
317 | 381 | if (isset($line['heading']) && $line['heading'] != '') { |
318 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
382 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) { |
|
383 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
384 | + } |
|
319 | 385 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
320 | 386 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
321 | 387 | //$dataFound = true; |
322 | 388 | } elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) { |
323 | 389 | $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
324 | 390 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
325 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
326 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
391 | + if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) { |
|
392 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
393 | + } |
|
394 | + if ($globalDebug) { |
|
395 | + echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
396 | + } |
|
327 | 397 | } |
328 | 398 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
329 | 399 | |
@@ -335,23 +405,38 @@ discard block |
||
335 | 405 | if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
336 | 406 | if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
337 | 407 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
338 | - if ($globalDebug) echo "Check if vessel is already in DB..."; |
|
408 | + if ($globalDebug) { |
|
409 | + echo "Check if vessel is already in DB..."; |
|
410 | + } |
|
339 | 411 | $timeelapsed = microtime(true); |
340 | 412 | $MarineLive = new MarineLive($this->db); |
341 | 413 | if (isset($line['id'])) { |
342 | 414 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
343 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
415 | + if ($globalDebugTimeElapsed) { |
|
416 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
417 | + } |
|
344 | 418 | } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
345 | 419 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
346 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
420 | + if ($globalDebugTimeElapsed) { |
|
421 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
422 | + } |
|
347 | 423 | } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
348 | 424 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
349 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
350 | - } else $recent_ident = ''; |
|
425 | + if ($globalDebugTimeElapsed) { |
|
426 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
427 | + } |
|
428 | + } else { |
|
429 | + $recent_ident = ''; |
|
430 | + } |
|
351 | 431 | $MarineLive->db=null; |
352 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
353 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
354 | - } else $recent_ident = ''; |
|
432 | + if ($globalDebug && $recent_ident == '') { |
|
433 | + echo " Not in DB.\n"; |
|
434 | + } elseif ($globalDebug && $recent_ident != '') { |
|
435 | + echo " Already in DB.\n"; |
|
436 | + } |
|
437 | + } else { |
|
438 | + $recent_ident = ''; |
|
439 | + } |
|
355 | 440 | } else { |
356 | 441 | $recent_ident = ''; |
357 | 442 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
@@ -359,30 +444,44 @@ discard block |
||
359 | 444 | //if there was no vessel with the same callsign within the last hour and go post it into the archive |
360 | 445 | if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
361 | 446 | { |
362 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
447 | + if ($globalDebug) { |
|
448 | + echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
449 | + } |
|
363 | 450 | //adds the spotter data for the archive |
364 | 451 | $highlight = ''; |
365 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
452 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
453 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
454 | + } |
|
366 | 455 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
367 | 456 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
368 | 457 | $timeelapsed = microtime(true); |
369 | 458 | $Marine = new Marine($this->db); |
370 | 459 | $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
371 | 460 | $Marine->db = null; |
372 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
373 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
461 | + if ($globalDebug && isset($result)) { |
|
462 | + echo $result."\n"; |
|
463 | + } |
|
464 | + if ($globalDebugTimeElapsed) { |
|
465 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
466 | + } |
|
374 | 467 | } |
375 | 468 | } |
376 | 469 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
377 | 470 | // Add source stat in DB |
378 | 471 | $Stats = new Stats($this->db); |
379 | 472 | if (!empty($this->stats)) { |
380 | - if ($globalDebug) echo 'Add source stats : '; |
|
473 | + if ($globalDebug) { |
|
474 | + echo 'Add source stats : '; |
|
475 | + } |
|
381 | 476 | foreach($this->stats as $date => $data) { |
382 | 477 | foreach($data as $source => $sourced) { |
383 | 478 | //print_r($sourced); |
384 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
385 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
479 | + if (isset($sourced['polar'])) { |
|
480 | + echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
481 | + } |
|
482 | + if (isset($sourced['hist'])) { |
|
483 | + echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
484 | + } |
|
386 | 485 | if (isset($sourced['msg'])) { |
387 | 486 | if (time() - $sourced['msg']['date'] > 10) { |
388 | 487 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
@@ -395,7 +494,9 @@ discard block |
||
395 | 494 | unset($this->stats[$date]); |
396 | 495 | } |
397 | 496 | } |
398 | - if ($globalDebug) echo 'Done'."\n"; |
|
497 | + if ($globalDebug) { |
|
498 | + echo 'Done'."\n"; |
|
499 | + } |
|
399 | 500 | } |
400 | 501 | $Stats->db = null; |
401 | 502 | } |
@@ -405,13 +506,17 @@ discard block |
||
405 | 506 | $this->all_tracked[$id]['addedMarine'] = 1; |
406 | 507 | //print_r($this->all_tracked[$id]); |
407 | 508 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
408 | - if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
509 | + if ($globalDebug) { |
|
510 | + echo "---- Deleting Live Marine data older than 9 hours..."; |
|
511 | + } |
|
409 | 512 | //MarineLive->deleteLiveMarineDataNotUpdated(); |
410 | 513 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
411 | 514 | $MarineLive = new MarineLive($this->db); |
412 | 515 | $MarineLive->deleteLiveMarineData(); |
413 | 516 | $MarineLive->db=null; |
414 | - if ($globalDebug) echo " Done\n"; |
|
517 | + if ($globalDebug) { |
|
518 | + echo " Done\n"; |
|
519 | + } |
|
415 | 520 | } |
416 | 521 | $this->last_delete = time(); |
417 | 522 | } |
@@ -437,15 +542,21 @@ discard block |
||
437 | 542 | |
438 | 543 | if (!$ignoreImport) { |
439 | 544 | if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
440 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
545 | + if ($globalDebug) { |
|
546 | + echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
547 | + } |
|
441 | 548 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
442 | 549 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
443 | 550 | $timeelapsed = microtime(true); |
444 | 551 | $MarineLive = new MarineLive($this->db); |
445 | 552 | $result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
446 | 553 | $MarineLive->db = null; |
447 | - if ($globalDebug) echo $result."\n"; |
|
448 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
554 | + if ($globalDebug) { |
|
555 | + echo $result."\n"; |
|
556 | + } |
|
557 | + if ($globalDebugTimeElapsed) { |
|
558 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
559 | + } |
|
449 | 560 | } |
450 | 561 | } |
451 | 562 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) { |
@@ -457,7 +568,9 @@ discard block |
||
457 | 568 | |
458 | 569 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
459 | 570 | $source = $this->all_tracked[$id]['source_name']; |
460 | - if ($source == '') $source = $this->all_tracked[$id]['format_source']; |
|
571 | + if ($source == '') { |
|
572 | + $source = $this->all_tracked[$id]['format_source']; |
|
573 | + } |
|
461 | 574 | if (!isset($this->source_location[$source])) { |
462 | 575 | $Location = new Source($this->db); |
463 | 576 | $coord = $Location->getLocationInfobySourceName($source); |
@@ -478,7 +591,9 @@ discard block |
||
478 | 591 | $stats_heading = round($stats_heading/22.5); |
479 | 592 | $stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
480 | 593 | $current_date = date('Y-m-d'); |
481 | - if ($stats_heading == 16) $stats_heading = 0; |
|
594 | + if ($stats_heading == 16) { |
|
595 | + $stats_heading = 0; |
|
596 | + } |
|
482 | 597 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
483 | 598 | for ($i=0;$i<=15;$i++) { |
484 | 599 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
@@ -496,7 +611,9 @@ discard block |
||
496 | 611 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
497 | 612 | end($this->stats[$current_date][$source]['hist']); |
498 | 613 | $mini = key($this->stats[$current_date][$source]['hist'])+10; |
499 | - } else $mini = 0; |
|
614 | + } else { |
|
615 | + $mini = 0; |
|
616 | + } |
|
500 | 617 | for ($i=$mini;$i<=$distance;$i+=10) { |
501 | 618 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
502 | 619 | } |
@@ -508,19 +625,27 @@ discard block |
||
508 | 625 | |
509 | 626 | |
510 | 627 | $this->all_tracked[$id]['lastupdate'] = time(); |
511 | - if ($this->all_tracked[$id]['putinarchive']) $send = true; |
|
512 | - } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
628 | + if ($this->all_tracked[$id]['putinarchive']) { |
|
629 | + $send = true; |
|
630 | + } |
|
631 | + } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
632 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
633 | + } |
|
513 | 634 | //$this->del(); |
514 | 635 | |
515 | 636 | |
516 | 637 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
517 | 638 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
518 | - if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
639 | + if ($globalDebug) { |
|
640 | + echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
641 | + } |
|
519 | 642 | $MarineLive = new MarineLive($this->db); |
520 | 643 | $MarineLive->deleteLiveMarineDataNotUpdated(); |
521 | 644 | $MarineLive->db = null; |
522 | 645 | //MarineLive->deleteLiveMarineData(); |
523 | - if ($globalDebug) echo " Done\n"; |
|
646 | + if ($globalDebug) { |
|
647 | + echo " Done\n"; |
|
648 | + } |
|
524 | 649 | } |
525 | 650 | $this->last_delete_hourly = time(); |
526 | 651 | } |
@@ -529,7 +654,9 @@ discard block |
||
529 | 654 | //$ignoreImport = false; |
530 | 655 | } |
531 | 656 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
532 | - if ($send) return $this->all_tracked[$id]; |
|
657 | + if ($send) { |
|
658 | + return $this->all_tracked[$id]; |
|
659 | + } |
|
533 | 660 | } |
534 | 661 | } |
535 | 662 | } |