@@ -29,31 +29,31 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | private function make_latf($temp) { // unsigned long |
| 31 | 31 | $flat = 0.0; // float |
| 32 | - $temp = $temp & 0x07FFFFFF; |
|
| 33 | - if ($temp & 0x04000000) { |
|
| 34 | - $temp = $temp ^ 0x07FFFFFF; |
|
| 32 | + $temp = $temp&0x07FFFFFF; |
|
| 33 | + if ($temp&0x04000000) { |
|
| 34 | + $temp = $temp^0x07FFFFFF; |
|
| 35 | 35 | $temp += 1; |
| 36 | - $flat = (float)($temp / (60.0 * 10000.0)); |
|
| 36 | + $flat = (float) ($temp/(60.0*10000.0)); |
|
| 37 | 37 | $flat *= -1.0; |
| 38 | - } else $flat = (float)($temp / (60.0 * 10000.0)); |
|
| 38 | + } else $flat = (float) ($temp/(60.0*10000.0)); |
|
| 39 | 39 | return $flat; // float |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | private function make_lonf($temp) { // unsigned long |
| 43 | 43 | $flon = 0.0; // float |
| 44 | - $temp = $temp & 0x0FFFFFFF; |
|
| 45 | - if ($temp & 0x08000000) { |
|
| 46 | - $temp = $temp ^ 0x0FFFFFFF; |
|
| 44 | + $temp = $temp&0x0FFFFFFF; |
|
| 45 | + if ($temp&0x08000000) { |
|
| 46 | + $temp = $temp^0x0FFFFFFF; |
|
| 47 | 47 | $temp += 1; |
| 48 | - $flon = (float)($temp / (60.0 * 10000.0)); |
|
| 48 | + $flon = (float) ($temp/(60.0*10000.0)); |
|
| 49 | 49 | $flon *= -1.0; |
| 50 | - } else $flon = (float)($temp / (60.0 * 10000.0)); |
|
| 50 | + } else $flon = (float) ($temp/(60.0*10000.0)); |
|
| 51 | 51 | return $flon; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | private function ascii_2_dec($chr) { |
| 55 | - $dec=ord($chr);//get decimal ascii code |
|
| 56 | - $hex=dechex($dec);//convert decimal to hex |
|
| 55 | + $dec = ord($chr); //get decimal ascii code |
|
| 56 | + $hex = dechex($dec); //convert decimal to hex |
|
| 57 | 57 | return ($dec); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | //only process in the following range: 48-87, 96-119 |
| 73 | 73 | if ($ascii < 48) { } |
| 74 | 74 | else { |
| 75 | - if($ascii>119) { } |
|
| 75 | + if ($ascii > 119) { } |
|
| 76 | 76 | else { |
| 77 | - if ($ascii>87 && $ascii<96) ; |
|
| 77 | + if ($ascii > 87 && $ascii < 96); |
|
| 78 | 78 | else { |
| 79 | - $ascii=$ascii+40; |
|
| 80 | - if ($ascii>128){ |
|
| 81 | - $ascii=$ascii+32; |
|
| 79 | + $ascii = $ascii + 40; |
|
| 80 | + if ($ascii > 128) { |
|
| 81 | + $ascii = $ascii + 32; |
|
| 82 | 82 | } else { |
| 83 | - $ascii=$ascii+40; |
|
| 83 | + $ascii = $ascii + 40; |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | private function dec_2_6bit($dec) { |
| 92 | - $bin=decbin($dec); |
|
| 92 | + $bin = decbin($dec); |
|
| 93 | 93 | return(substr($bin, -6)); |
| 94 | 94 | } |
| 95 | 95 | |
@@ -107,11 +107,11 @@ discard block |
||
| 107 | 107 | ); |
| 108 | 108 | // " |
| 109 | 109 | $rv = ''; |
| 110 | - if ($_size % 6 == 0) { |
|
| 111 | - $len = $_size / 6; |
|
| 112 | - for ($i=0; $i<$len; $i++) { |
|
| 113 | - $offset = $i * 6; |
|
| 114 | - $rv .= $ais_chars[ bindec(substr($_str,$_start + $offset,6)) ]; |
|
| 110 | + if ($_size%6 == 0) { |
|
| 111 | + $len = $_size/6; |
|
| 112 | + for ($i = 0; $i < $len; $i++) { |
|
| 113 | + $offset = $i*6; |
|
| 114 | + $rv .= $ais_chars[bindec(substr($_str, $_start + $offset, 6))]; |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | return $rv; |
@@ -138,93 +138,93 @@ discard block |
||
| 138 | 138 | $ro->eta_hour = ''; |
| 139 | 139 | $ro->eta_minute = ''; |
| 140 | 140 | $ro->ts = time(); |
| 141 | - $ro->id = bindec(substr($_aisdata,0,6)); |
|
| 142 | - $ro->mmsi = bindec(substr($_aisdata,8,30)); |
|
| 141 | + $ro->id = bindec(substr($_aisdata, 0, 6)); |
|
| 142 | + $ro->mmsi = bindec(substr($_aisdata, 8, 30)); |
|
| 143 | 143 | if ($ro->id >= 1 && $ro->id <= 3) { |
| 144 | - $ro->cog = bindec(substr($_aisdata,116,12))/10; |
|
| 145 | - $ro->sog = bindec(substr($_aisdata,50,10))/10; |
|
| 146 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28))); |
|
| 147 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27))); |
|
| 144 | + $ro->cog = bindec(substr($_aisdata, 116, 12))/10; |
|
| 145 | + $ro->sog = bindec(substr($_aisdata, 50, 10))/10; |
|
| 146 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28))); |
|
| 147 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27))); |
|
| 148 | 148 | $ro->cls = 1; // class A |
| 149 | 149 | } else if ($ro->id == 4) { |
| 150 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,79,28))); |
|
| 151 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,107,27))); |
|
| 150 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 79, 28))); |
|
| 151 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 107, 27))); |
|
| 152 | 152 | $ro->cls = 1; // class A |
| 153 | 153 | } else if ($ro->id == 5) { |
| 154 | - $ro->imo = bindec(substr($_aisdata,40,30)); |
|
| 155 | - $ro->callsign = $this->binchar($_aisdata,70,42); |
|
| 156 | - $ro->name = $this->binchar($_aisdata,112,120); |
|
| 157 | - $ro->typeid = bindec(substr($_aisdata,232,8)); |
|
| 154 | + $ro->imo = bindec(substr($_aisdata, 40, 30)); |
|
| 155 | + $ro->callsign = $this->binchar($_aisdata, 70, 42); |
|
| 156 | + $ro->name = $this->binchar($_aisdata, 112, 120); |
|
| 157 | + $ro->typeid = bindec(substr($_aisdata, 232, 8)); |
|
| 158 | 158 | $ro->type = $this->getShipType($ro->typeid); |
| 159 | 159 | //$ro->to_bow = bindec(substr($_aisdata,240,9)); |
| 160 | 160 | //$ro->to_stern = bindec(substr($_aisdata,249,9)); |
| 161 | 161 | //$ro->to_port = bindec(substr($_aisdata,258,6)); |
| 162 | 162 | //$ro->to_starboard = bindec(substr($_aisdata,264,6)); |
| 163 | - $ro->eta_month = bindec(substr($_aisdata,274,4)); |
|
| 164 | - $ro->eta_day = bindec(substr($_aisdata,278,5)); |
|
| 165 | - $ro->eta_hour = bindec(substr($_aisdata,283,5)); |
|
| 166 | - $ro->eta_minute = bindec(substr($_aisdata,288,6)); |
|
| 163 | + $ro->eta_month = bindec(substr($_aisdata, 274, 4)); |
|
| 164 | + $ro->eta_day = bindec(substr($_aisdata, 278, 5)); |
|
| 165 | + $ro->eta_hour = bindec(substr($_aisdata, 283, 5)); |
|
| 166 | + $ro->eta_minute = bindec(substr($_aisdata, 288, 6)); |
|
| 167 | 167 | //$ro->draught = bindec(substr($_aisdata,294,8)); |
| 168 | - $ro->destination = $this->binchar($_aisdata,302,120); |
|
| 168 | + $ro->destination = $this->binchar($_aisdata, 302, 120); |
|
| 169 | 169 | $ro->cls = 1; // class A |
| 170 | 170 | } else if ($ro->id == 9) { |
| 171 | 171 | // Search and Rescue aircraft position report |
| 172 | 172 | } else if ($ro->id == 18) { |
| 173 | - $ro->cog = bindec(substr($_aisdata,112,12))/10; |
|
| 174 | - $ro->sog = bindec(substr($_aisdata,46,10))/10; |
|
| 175 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
|
| 176 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
|
| 177 | - $ro->heading = bindec(substr($_aisdata,124,9)); |
|
| 173 | + $ro->cog = bindec(substr($_aisdata, 112, 12))/10; |
|
| 174 | + $ro->sog = bindec(substr($_aisdata, 46, 10))/10; |
|
| 175 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 57, 28))); |
|
| 176 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 85, 27))); |
|
| 177 | + $ro->heading = bindec(substr($_aisdata, 124, 9)); |
|
| 178 | 178 | if ($ro->heading == 511) $ro->heading = ''; |
| 179 | 179 | $ro->cls = 2; // class B |
| 180 | 180 | } else if ($ro->id == 19) { |
| 181 | - $ro->cog = bindec(substr($_aisdata,112,12))/10; |
|
| 182 | - $ro->sog = bindec(substr($_aisdata,46,10))/10; |
|
| 183 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28))); |
|
| 184 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27))); |
|
| 185 | - $ro->name = $this->binchar($_aisdata,143,120); |
|
| 181 | + $ro->cog = bindec(substr($_aisdata, 112, 12))/10; |
|
| 182 | + $ro->sog = bindec(substr($_aisdata, 46, 10))/10; |
|
| 183 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28))); |
|
| 184 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27))); |
|
| 185 | + $ro->name = $this->binchar($_aisdata, 143, 120); |
|
| 186 | 186 | $ro->cls = 2; // class B |
| 187 | - $ro->heading = bindec(substr($_aisdata,124,9)); |
|
| 187 | + $ro->heading = bindec(substr($_aisdata, 124, 9)); |
|
| 188 | 188 | if ($ro->heading == 511) $ro->heading = ''; |
| 189 | - $ro->typeid = bindec(substr($_aisdata,263,8)); |
|
| 189 | + $ro->typeid = bindec(substr($_aisdata, 263, 8)); |
|
| 190 | 190 | $ro->type = $this->getShipType($ro->typeid); |
| 191 | 191 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
| 192 | 192 | //$ro->to_stern = bindec(substr($_aisdata,280,9)); |
| 193 | 193 | //$ro->to_port = bindec(substr($_aisdata,289,6)); |
| 194 | 194 | //$ro->to_starboard = bindec(substr($_aisdata,295,6)); |
| 195 | 195 | } else if ($ro->id == 21) { |
| 196 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,164,28))); |
|
| 197 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,192,27))); |
|
| 198 | - $ro->name = $this->binchar($_aisdata,43,120); |
|
| 196 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 164, 28))); |
|
| 197 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 192, 27))); |
|
| 198 | + $ro->name = $this->binchar($_aisdata, 43, 120); |
|
| 199 | 199 | //$ro->to_bow = bindec(substr($_aisdata,219,9)); |
| 200 | 200 | //$ro->to_stern = bindec(substr($_aisdata,228,9)); |
| 201 | 201 | //$ro->to_port = bindec(substr($_aisdata,237,6)); |
| 202 | 202 | //$ro->to_starboard = bindec(substr($_aisdata,243,6)); |
| 203 | 203 | $ro->cls = 2; // class B |
| 204 | 204 | } else if ($ro->id == 24) { |
| 205 | - $pn = bindec(substr($_aisdata,38,2)); |
|
| 205 | + $pn = bindec(substr($_aisdata, 38, 2)); |
|
| 206 | 206 | if ($pn == 0) { |
| 207 | - $ro->name = $this->binchar($_aisdata,40,120); |
|
| 207 | + $ro->name = $this->binchar($_aisdata, 40, 120); |
|
| 208 | 208 | } |
| 209 | - $ro->typeid = bindec(substr($_aisdata,40,8)); |
|
| 209 | + $ro->typeid = bindec(substr($_aisdata, 40, 8)); |
|
| 210 | 210 | $ro->type = $this->getShipType($ro->typeid); |
| 211 | - $ro->callsign = $this->binchar($_aisdata,90,42); |
|
| 211 | + $ro->callsign = $this->binchar($_aisdata, 90, 42); |
|
| 212 | 212 | //$ro->to_bow = bindec(substr($_aisdata,132,9)); |
| 213 | 213 | //$ro->to_stern = bindec(substr($_aisdata,141,9)); |
| 214 | 214 | //$ro->to_port = bindec(substr($_aisdata,150,6)); |
| 215 | 215 | //$ro->to_starboard = bindec(substr($_aisdata,156,6)); |
| 216 | 216 | $ro->cls = 2; // class B |
| 217 | 217 | } else if ($ro->id == 27) { |
| 218 | - $ro->cog = bindec(substr($_aisdata,85,9)); |
|
| 218 | + $ro->cog = bindec(substr($_aisdata, 85, 9)); |
|
| 219 | 219 | if ($ro->cog == 511) $ro->cog = 0.0; |
| 220 | - $ro->sog = bindec(substr($_aisdata,79,6)); |
|
| 220 | + $ro->sog = bindec(substr($_aisdata, 79, 6)); |
|
| 221 | 221 | if ($ro->sog == 63) $ro->sog = 0.0; |
| 222 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
|
| 223 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
|
| 222 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 44, 18))*10); |
|
| 223 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 62, 17))*10); |
|
| 224 | 224 | $ro->cls = 1; // class A |
| 225 | 225 | |
| 226 | 226 | } |
| 227 | - $ro->statusid = bindec(substr($_aisdata,38,4)); |
|
| 227 | + $ro->statusid = bindec(substr($_aisdata, 38, 4)); |
|
| 228 | 228 | $ro->status = $this->getStatus($ro->statusid); |
| 229 | 229 | //var_dump($ro); // dump results here for demo purpose |
| 230 | 230 | return $ro; |
@@ -355,14 +355,14 @@ discard block |
||
| 355 | 355 | global $port; // tcpip port... |
| 356 | 356 | |
| 357 | 357 | static $debug_counter = 0; |
| 358 | - $aisdata168='';//six bit array of ascii characters |
|
| 358 | + $aisdata168 = ''; //six bit array of ascii characters |
|
| 359 | 359 | $ais_nmea_array = str_split($_itu); // convert to an array |
| 360 | 360 | foreach ($ais_nmea_array as $value) { |
| 361 | 361 | $dec = $this->ascii_2_dec($value); |
| 362 | 362 | $bit8 = $this->asciidec_2_8bit($dec); |
| 363 | 363 | $bit6 = $this->dec_2_6bit($bit8); |
| 364 | 364 | //echo $value ."-" .$bit6 .""; |
| 365 | - $aisdata168 .=$bit6; |
|
| 365 | + $aisdata168 .= $bit6; |
|
| 366 | 366 | } |
| 367 | 367 | //echo $aisdata168 . "<br/>"; |
| 368 | 368 | //return $this->decode_ais($aisdata168, $aux); |
@@ -385,20 +385,20 @@ discard block |
||
| 385 | 385 | // calculate checksum after ! till * |
| 386 | 386 | // assume 1st ! is valid |
| 387 | 387 | // find * ensure that it is at correct position |
| 388 | - $end = strrpos ( $rawdata , '*' ); |
|
| 388 | + $end = strrpos($rawdata, '*'); |
|
| 389 | 389 | if ($end === FALSE) return -1; // check for NULLS!!! |
| 390 | - $cs = substr( $rawdata, $end + 1 ); |
|
| 391 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
| 392 | - $dcs = (int)hexdec( $cs ); |
|
| 393 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
| 394 | - if ( $chksum == $dcs ) { // NMEA checksum pass |
|
| 390 | + $cs = substr($rawdata, $end + 1); |
|
| 391 | + if (strlen($cs) != 2) return -1; // correct cs length |
|
| 392 | + $dcs = (int) hexdec($cs); |
|
| 393 | + for ($alias = 1; $alias < $end; $alias++) $chksum ^= ord($rawdata[$alias]); // perform XOR for NMEA checksum |
|
| 394 | + if ($chksum == $dcs) { // NMEA checksum pass |
|
| 395 | 395 | $pcs = explode(',', $rawdata); |
| 396 | 396 | // !AI??? identifier |
| 397 | - $num_seq = (int)$pcs[1]; // number of sequences |
|
| 398 | - $seq = (int)$pcs[2]; // get sequence |
|
| 397 | + $num_seq = (int) $pcs[1]; // number of sequences |
|
| 398 | + $seq = (int) $pcs[2]; // get sequence |
|
| 399 | 399 | // get msg sequence id |
| 400 | 400 | if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
| 401 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
| 401 | + else $msg_sid = (int) $pcs[3]; // multipart message |
|
| 402 | 402 | $ais_ch = $pcs[4]; // get AIS channel |
| 403 | 403 | // message sequence checking |
| 404 | 404 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | $itu = $itu.$pcs[5]; // get itu message |
| 434 | - $filler += (int)$pcs[6][0]; // get filler |
|
| 434 | + $filler += (int) $pcs[6][0]; // get filler |
|
| 435 | 435 | if ($num_seq == 1 // valid single message |
| 436 | 436 | || $num_seq == $pseq // valid multi-part message |
| 437 | 437 | ) { |
@@ -451,13 +451,13 @@ discard block |
||
| 451 | 451 | $cbuf = $cbuf.$ibuf; |
| 452 | 452 | $last_pos = 0; |
| 453 | 453 | $result = new stdClass(); |
| 454 | - while ( ($start = strpos($cbuf,"VDM",$last_pos)) !== FALSE) { |
|
| 454 | + while (($start = strpos($cbuf, "VDM", $last_pos)) !== FALSE) { |
|
| 455 | 455 | //while ( ($start = strpos($cbuf,"!AI",$last_pos)) !== FALSE) { |
| 456 | 456 | //DEBUG echo $cbuf; |
| 457 | - if ( ($end = strpos($cbuf,"\r\n", $start)) !== FALSE) { //TBD need to trim? |
|
| 457 | + if (($end = strpos($cbuf, "\r\n", $start)) !== FALSE) { //TBD need to trim? |
|
| 458 | 458 | $tst = substr($cbuf, $start - 3, ($end - $start + 3)); |
| 459 | 459 | //DEBUG echo "[$start $end $tst]\n"; |
| 460 | - $result = $this->process_ais_raw( $tst, "" ); |
|
| 460 | + $result = $this->process_ais_raw($tst, ""); |
|
| 461 | 461 | $last_pos = $end + 1; |
| 462 | 462 | } else break; |
| 463 | 463 | } |
@@ -469,41 +469,41 @@ discard block |
||
| 469 | 469 | // incoming data from serial or IP comms |
| 470 | 470 | public function process_ais_line($cbuf) { |
| 471 | 471 | $result = new stdClass(); |
| 472 | - $start = strpos($cbuf,"VDM"); |
|
| 472 | + $start = strpos($cbuf, "VDM"); |
|
| 473 | 473 | $tst = substr($cbuf, $start - 3); |
| 474 | - $result = $this->process_ais_raw( $tst, "" ); |
|
| 474 | + $result = $this->process_ais_raw($tst, ""); |
|
| 475 | 475 | return $result; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /* AIS Encoding |
| 479 | 479 | */ |
| 480 | - private function mk_ais_lat( $lat ) { |
|
| 480 | + private function mk_ais_lat($lat) { |
|
| 481 | 481 | //$lat = 1.2569; |
| 482 | - if ($lat<0.0) { |
|
| 482 | + if ($lat < 0.0) { |
|
| 483 | 483 | $lat = -$lat; |
| 484 | - $neg=true; |
|
| 485 | - } else $neg=false; |
|
| 484 | + $neg = true; |
|
| 485 | + } else $neg = false; |
|
| 486 | 486 | $latd = 0x00000000; |
| 487 | - $latd = intval ($lat * 600000.0); |
|
| 488 | - if ($neg==true) { |
|
| 487 | + $latd = intval($lat*600000.0); |
|
| 488 | + if ($neg == true) { |
|
| 489 | 489 | $latd = ~$latd; |
| 490 | - $latd+=1; |
|
| 490 | + $latd += 1; |
|
| 491 | 491 | $latd &= 0x07FFFFFF; |
| 492 | 492 | } |
| 493 | 493 | return $latd; |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - private function mk_ais_lon( $lon ) { |
|
| 496 | + private function mk_ais_lon($lon) { |
|
| 497 | 497 | //$lon = 103.851; |
| 498 | - if ($lon<0.0) { |
|
| 498 | + if ($lon < 0.0) { |
|
| 499 | 499 | $lon = -$lon; |
| 500 | - $neg=true; |
|
| 501 | - } else $neg=false; |
|
| 500 | + $neg = true; |
|
| 501 | + } else $neg = false; |
|
| 502 | 502 | $lond = 0x00000000; |
| 503 | - $lond = intval ($lon * 600000.0); |
|
| 504 | - if ($neg==true) { |
|
| 503 | + $lond = intval($lon*600000.0); |
|
| 504 | + if ($neg == true) { |
|
| 505 | 505 | $lond = ~$lond; |
| 506 | - $lond+=1; |
|
| 506 | + $lond += 1; |
|
| 507 | 507 | $lond &= 0x0FFFFFFF; |
| 508 | 508 | } |
| 509 | 509 | return $lond; |
@@ -511,8 +511,8 @@ discard block |
||
| 511 | 511 | |
| 512 | 512 | private function char2bin($name, $max_len) { |
| 513 | 513 | $len = strlen($name); |
| 514 | - if ($len > $max_len) $name = substr($name,0,$max_len); |
|
| 515 | - if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6); |
|
| 514 | + if ($len > $max_len) $name = substr($name, 0, $max_len); |
|
| 515 | + if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len)*6); |
|
| 516 | 516 | else $pad = ''; |
| 517 | 517 | $rv = ''; |
| 518 | 518 | $ais_chars = array( |
@@ -529,26 +529,26 @@ discard block |
||
| 529 | 529 | if ($_a) foreach ($_a as $_1) { |
| 530 | 530 | if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
| 531 | 531 | else $dec = 0; |
| 532 | - $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
|
| 532 | + $bin = str_pad(decbin($dec), 6, '0', STR_PAD_LEFT); |
|
| 533 | 533 | $rv .= $bin; |
| 534 | 534 | //echo "$_1 $dec ($bin)<br/>"; |
| 535 | 535 | } |
| 536 | 536 | return $rv.$pad; |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - private function mk_ais($_enc, $_part=1,$_total=1,$_seq='',$_ch='A') { |
|
| 539 | + private function mk_ais($_enc, $_part = 1, $_total = 1, $_seq = '', $_ch = 'A') { |
|
| 540 | 540 | $len_bit = strlen($_enc); |
| 541 | - $rem6 = $len_bit % 6; |
|
| 541 | + $rem6 = $len_bit%6; |
|
| 542 | 542 | $pad6_len = 0; |
| 543 | 543 | if ($rem6) $pad6_len = 6 - $rem6; |
| 544 | 544 | //echo $pad6_len.'<br>'; |
| 545 | 545 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
| 546 | - $len_enc = strlen($_enc) / 6; |
|
| 546 | + $len_enc = strlen($_enc)/6; |
|
| 547 | 547 | //echo $_enc.' '.$len_enc.'<br/>'; |
| 548 | 548 | $itu = ''; |
| 549 | - for ($i=0; $i<$len_enc; $i++) { |
|
| 550 | - $offset = $i * 6; |
|
| 551 | - $dec = bindec(substr($_enc,$offset,6)); |
|
| 549 | + for ($i = 0; $i < $len_enc; $i++) { |
|
| 550 | + $offset = $i*6; |
|
| 551 | + $dec = bindec(substr($_enc, $offset, 6)); |
|
| 552 | 552 | if ($dec < 40) $dec += 48; |
| 553 | 553 | else $dec += 56; |
| 554 | 554 | //echo chr($dec)." $dec<br/>"; |
@@ -558,15 +558,15 @@ discard block |
||
| 558 | 558 | $chksum = 0; |
| 559 | 559 | $itu = "AIVDM,$_part,$_total,$_seq,$_ch,".$itu.",0"; |
| 560 | 560 | $len_itu = strlen($itu); |
| 561 | - for ($i=0; $i<$len_itu; $i++) { |
|
| 562 | - $chksum ^= ord( $itu[$i] ); |
|
| 561 | + for ($i = 0; $i < $len_itu; $i++) { |
|
| 562 | + $chksum ^= ord($itu[$i]); |
|
| 563 | 563 | } |
| 564 | - $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 565 | - $lsb = $chksum & 0x0F; |
|
| 566 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
| 564 | + $hex_arr = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
|
| 565 | + $lsb = $chksum&0x0F; |
|
| 566 | + if ($lsb >= 0 && $lsb <= 15) $lsbc = $hex_arr[$lsb]; |
|
| 567 | 567 | else $lsbc = '0'; |
| 568 | - $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
|
| 569 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
| 568 | + $msb = (($chksum&0xF0) >> 4)&0x0F; |
|
| 569 | + if ($msb >= 0 && $msb <= 15) $msbc = $hex_arr[$msb]; |
|
| 570 | 570 | else $msbc = '0'; |
| 571 | 571 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
| 572 | 572 | return $itu; |
@@ -591,14 +591,14 @@ discard block |
||
| 591 | 591 | |
| 592 | 592 | public function mmsitype($mmsi) { |
| 593 | 593 | if (strlen($mmsi) == 9) { |
| 594 | - if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
| 595 | - elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device'; |
|
| 596 | - elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
| 597 | - elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
| 598 | - elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
| 599 | - elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation'; |
|
| 600 | - elseif (substr($mmsi,0,2) == '00') return 'Coastal stations'; |
|
| 601 | - elseif (substr($mmsi,0,1) == '0') return 'Group of ships'; |
|
| 594 | + if (substr($mmsi, 0, 3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
| 595 | + elseif (substr($mmsi, 0, 3) == '972') return 'MOB (Man Overboard) device'; |
|
| 596 | + elseif (substr($mmsi, 0, 3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
| 597 | + elseif (substr($mmsi, 0, 3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
| 598 | + elseif (substr($mmsi, 0, 2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
| 599 | + elseif (substr($mmsi, 0, 2) == '99') return 'Aids to Navigation'; |
|
| 600 | + elseif (substr($mmsi, 0, 2) == '00') return 'Coastal stations'; |
|
| 601 | + elseif (substr($mmsi, 0, 1) == '0') return 'Group of ships'; |
|
| 602 | 602 | else return 'Ship'; |
| 603 | 603 | } |
| 604 | 604 | |
@@ -609,19 +609,19 @@ discard block |
||
| 609 | 609 | global $globalDebug; |
| 610 | 610 | $result = array(); |
| 611 | 611 | $data = new stdClass(); |
| 612 | - $start = strpos($buffer,"VDM"); |
|
| 612 | + $start = strpos($buffer, "VDM"); |
|
| 613 | 613 | $tst = substr($buffer, $start - 3); |
| 614 | - $data = $this->process_ais_raw( $tst, "" ); |
|
| 614 | + $data = $this->process_ais_raw($tst, ""); |
|
| 615 | 615 | if (!is_object($data)) { |
| 616 | 616 | //if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n"; |
| 617 | 617 | return array(); |
| 618 | 618 | } |
| 619 | 619 | if ($data->lon != 0) $result['longitude'] = $data->lon; |
| 620 | 620 | if ($data->lat != 0) $result['latitude'] = $data->lat; |
| 621 | - $result['ident'] = trim(str_replace('@','',$data->name)); |
|
| 621 | + $result['ident'] = trim(str_replace('@', '', $data->name)); |
|
| 622 | 622 | $result['timestamp'] = $data->ts; |
| 623 | 623 | $result['mmsi'] = $data->mmsi; |
| 624 | - if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
| 624 | + if (strlen($result['mmsi']) == 8 && substr($result['mmsi'], 0, 3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
| 625 | 625 | $result['mmsi_type'] = $this->mmsitype($result['mmsi']); |
| 626 | 626 | if ($data->sog != -1.0) $result['speed'] = $data->sog; |
| 627 | 627 | if ($data->heading !== '') $result['heading'] = $data->heading; |
@@ -631,16 +631,16 @@ discard block |
||
| 631 | 631 | if ($data->type !== '') $result['type'] = $data->type; |
| 632 | 632 | if ($data->typeid !== '') $result['typeid'] = $data->typeid; |
| 633 | 633 | if ($data->imo !== '') $result['imo'] = $data->imo; |
| 634 | - if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
| 634 | + if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@', '', $data->callsign)); |
|
| 635 | 635 | if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') { |
| 636 | - $eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
|
| 636 | + $eta_ts = strtotime(date('Y').'-'.sprintf("%02d", $data->eta_month).'-'.sprintf("%02d", $data->eta_day).' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00'); |
|
| 637 | 637 | if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
| 638 | 638 | } elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) { |
| 639 | - $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
|
| 639 | + $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00'); |
|
| 640 | 640 | if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
| 641 | 641 | } |
| 642 | 642 | if ($data->destination != '') { |
| 643 | - $dest = trim(str_replace('@','',$data->destination)); |
|
| 643 | + $dest = trim(str_replace('@', '', $data->destination)); |
|
| 644 | 644 | if ($dest != '') $result['destination'] = $dest; |
| 645 | 645 | } |
| 646 | 646 | $result['all'] = (array) $data; |
@@ -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,55 +46,55 @@ 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; |
| 56 | 56 | if ($globalDebug) echo "Update last seen tracked data...\n"; |
| 57 | 57 | foreach ($this->all_tracked as $key => $flight) { |
| 58 | - if (isset($this->all_tracked[$key]['id'])) { |
|
| 58 | + if (isset($this->all_tracked[$key]['id'])) { |
|
| 59 | 59 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
| 60 | - $Marine = new Marine($this->db); |
|
| 61 | - $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 | - } |
|
| 60 | + $Marine = new Marine($this->db); |
|
| 61 | + $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 | + } |
|
| 63 | + } |
|
| 63 | 64 | } |
| 64 | - } |
|
| 65 | 65 | |
| 66 | - public function del() { |
|
| 66 | + public function del() { |
|
| 67 | 67 | global $globalDebug, $globalNoDB, $globalNoImport; |
| 68 | 68 | // Delete old infos |
| 69 | 69 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
| 70 | 70 | foreach ($this->all_tracked as $key => $flight) { |
| 71 | - if (isset($flight['lastupdate'])) { |
|
| 72 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
| 73 | - if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
|
| 74 | - if (isset($this->all_tracked[$key]['id'])) { |
|
| 75 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
| 76 | - /* |
|
| 71 | + if (isset($flight['lastupdate'])) { |
|
| 72 | + if ($flight['lastupdate'] < (time()-3000)) { |
|
| 73 | + if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
|
| 74 | + if (isset($this->all_tracked[$key]['id'])) { |
|
| 75 | + if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
| 76 | + /* |
|
| 77 | 77 | $MarineLive = new MarineLive(); |
| 78 | 78 | $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
| 79 | 79 | $MarineLive->db = null; |
| 80 | 80 | */ |
| 81 | - //$real_arrival = $this->arrival($key); |
|
| 82 | - $Marine = new Marine($this->db); |
|
| 83 | - if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
|
| 81 | + //$real_arrival = $this->arrival($key); |
|
| 82 | + $Marine = new Marine($this->db); |
|
| 83 | + if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
|
| 84 | 84 | $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']); |
| 85 | 85 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 86 | - } |
|
| 87 | - // Put in archive |
|
| 86 | + } |
|
| 87 | + // Put in archive |
|
| 88 | 88 | // $Marine->db = null; |
| 89 | 89 | } |
| 90 | - } |
|
| 91 | - unset($this->all_tracked[$key]); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 90 | + } |
|
| 91 | + unset($this->all_tracked[$key]); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - public function add($line) { |
|
| 97 | + public function add($line) { |
|
| 98 | 98 | global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine; |
| 99 | 99 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
| 100 | 100 | date_default_timezone_set('UTC'); |
@@ -103,8 +103,8 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | // SBS format is CSV format |
| 105 | 105 | if(is_array($line) && isset($line['mmsi'])) { |
| 106 | - //print_r($line); |
|
| 107 | - if (isset($line['mmsi'])) { |
|
| 106 | + //print_r($line); |
|
| 107 | + if (isset($line['mmsi'])) { |
|
| 108 | 108 | |
| 109 | 109 | /* |
| 110 | 110 | // Increment message number |
@@ -121,64 +121,64 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | $Common = new Common(); |
| 123 | 123 | $AIS = new AIS(); |
| 124 | - if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
| 125 | - else $id = trim($line['id']); |
|
| 124 | + if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
| 125 | + else $id = trim($line['id']); |
|
| 126 | 126 | |
| 127 | 127 | if (!isset($this->all_tracked[$id])) { |
| 128 | - $this->all_tracked[$id] = array(); |
|
| 129 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
| 130 | - $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' => '')); |
|
| 131 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
| 132 | - if (!isset($line['id'])) { |
|
| 128 | + $this->all_tracked[$id] = array(); |
|
| 129 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
| 130 | + $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' => '')); |
|
| 131 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
| 132 | + if (!isset($line['id'])) { |
|
| 133 | 133 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
| 134 | 134 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
| 135 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
| 136 | - if ($globalAllTracked !== FALSE) $dataFound = true; |
|
| 135 | + } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
| 136 | + if ($globalAllTracked !== FALSE) $dataFound = true; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
| 140 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
| 141 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 140 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
| 141 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 142 | 142 | $Marine = new Marine($this->db); |
| 143 | 143 | $identity = $Marine->getIdentity($line['mmsi']); |
| 144 | 144 | if (!empty($identity)) { |
| 145 | - $this->all_tracked[$id]['ident'] = $identity['ship_name']; |
|
| 146 | - $this->all_tracked[$id]['type'] = $identity['type']; |
|
| 145 | + $this->all_tracked[$id]['ident'] = $identity['ship_name']; |
|
| 146 | + $this->all_tracked[$id]['type'] = $identity['type']; |
|
| 147 | 147 | } |
| 148 | 148 | //print_r($identity); |
| 149 | 149 | unset($Marine); |
| 150 | 150 | //$dataFound = true; |
| 151 | - } |
|
| 151 | + } |
|
| 152 | 152 | } |
| 153 | 153 | if (isset($line['type_id'])) { |
| 154 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
| 154 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
| 155 | 155 | } |
| 156 | 156 | if (isset($line['type']) && $line['type'] != '') { |
| 157 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
| 157 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
| 158 | 158 | } |
| 159 | 159 | if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') { |
| 160 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type'])); |
|
| 160 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type'])); |
|
| 161 | 161 | } |
| 162 | 162 | if (isset($line['imo']) && $line['imo'] != '') { |
| 163 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
| 163 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
| 164 | 164 | } |
| 165 | 165 | if (isset($line['callsign']) && $line['callsign'] != '') { |
| 166 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
| 166 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
| 167 | 167 | } |
| 168 | 168 | if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
| 169 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
|
| 169 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
|
| 170 | 170 | } |
| 171 | 171 | if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
| 172 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
| 172 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
| 176 | 176 | //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'])) { |
| 177 | 177 | if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) { |
| 178 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
| 179 | - if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
| 178 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
| 179 | + if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
| 180 | 180 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 181 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 181 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 182 | 182 | $timeelapsed = microtime(true); |
| 183 | 183 | $Marine = new Marine($this->db); |
| 184 | 184 | $fromsource = NULL; |
@@ -186,20 +186,20 @@ discard block |
||
| 186 | 186 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 187 | 187 | $Marine->db = null; |
| 188 | 188 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 189 | - } |
|
| 189 | + } |
|
| 190 | 190 | } |
| 191 | - } |
|
| 192 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
| 191 | + } |
|
| 192 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) { |
| 196 | - if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
|
| 196 | + if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
|
| 197 | 197 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
| 198 | - } else { |
|
| 198 | + } else { |
|
| 199 | 199 | 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"; |
| 200 | 200 | 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"; |
| 201 | 201 | return ''; |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) { |
| 204 | 204 | if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
| 205 | 205 | return ''; |
@@ -216,24 +216,24 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | |
| 218 | 218 | if (isset($line['speed'])) { |
| 219 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
| 220 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
| 219 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
| 220 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
| 221 | 221 | } 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'])) { |
| 222 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
| 223 | - if ($distance > 1000 && $distance < 10000) { |
|
| 222 | + $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
| 223 | + if ($distance > 1000 && $distance < 10000) { |
|
| 224 | 224 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
| 225 | 225 | $speed = $speed*3.6; |
| 226 | 226 | if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
| 227 | 227 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
| 228 | - } |
|
| 228 | + } |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
| 232 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
| 233 | - else unset($timediff); |
|
| 234 | - 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')))) { |
|
| 231 | + if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
| 232 | + if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
| 233 | + else unset($timediff); |
|
| 234 | + 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 | 235 | 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'])) { |
| 236 | - 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'])) { |
|
| 236 | + 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'])) { |
|
| 237 | 237 | $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
| 238 | 238 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
| 239 | 239 | $this->all_tracked[$id]['putinarchive'] = true; |
@@ -241,126 +241,126 @@ discard block |
||
| 241 | 241 | if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
| 242 | 242 | $timeelapsed = microtime(true); |
| 243 | 243 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 244 | - $Marine = new Marine($this->db); |
|
| 245 | - $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
| 246 | - if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
| 247 | - $Marine->db = null; |
|
| 248 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 244 | + $Marine = new Marine($this->db); |
|
| 245 | + $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
| 246 | + if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
| 247 | + $Marine->db = null; |
|
| 248 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 249 | 249 | } |
| 250 | 250 | $this->tmd = 0; |
| 251 | 251 | if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
| 252 | - } |
|
| 252 | + } |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
| 256 | 256 | if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
| 257 | 257 | 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') { |
| 258 | - $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
|
| 259 | - $dataFound = true; |
|
| 260 | - $this->all_tracked[$id]['time_last_coord'] = time(); |
|
| 258 | + $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
|
| 259 | + $dataFound = true; |
|
| 260 | + $this->all_tracked[$id]['time_last_coord'] = time(); |
|
| 261 | 261 | } |
| 262 | 262 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
| 263 | 263 | } |
| 264 | 264 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
| 265 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 265 | + if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 266 | 266 | if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
| 267 | 267 | 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') { |
| 268 | - $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
|
| 269 | - $dataFound = true; |
|
| 270 | - $this->all_tracked[$id]['time_last_coord'] = time(); |
|
| 268 | + $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
|
| 269 | + $dataFound = true; |
|
| 270 | + $this->all_tracked[$id]['time_last_coord'] = time(); |
|
| 271 | 271 | } |
| 272 | 272 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude'])); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - } else if ($globalDebug && $timediff > 20) { |
|
| 275 | + } else if ($globalDebug && $timediff > 20) { |
|
| 276 | 276 | $this->tmd = $this->tmd + 1; |
| 277 | 277 | echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n"; |
| 278 | 278 | echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -"; |
| 279 | 279 | echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
| 280 | 280 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n"; |
| 281 | - } |
|
| 281 | + } |
|
| 282 | 282 | } |
| 283 | 283 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 284 | - if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 285 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
| 284 | + if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 285 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
| 286 | 286 | } |
| 287 | 287 | if (isset($line['format_source']) && $line['format_source'] != '') { |
| 288 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
| 288 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
| 289 | 289 | } |
| 290 | 290 | if (isset($line['source_name']) && $line['source_name'] != '') { |
| 291 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
| 291 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
| 292 | 292 | } |
| 293 | 293 | if (isset($line['status']) && $line['status'] != '') { |
| 294 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
| 294 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
| 295 | 295 | } |
| 296 | 296 | if (isset($line['status_id'])) { |
| 297 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id'])); |
|
| 297 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id'])); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
| 301 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
| 301 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | if (isset($line['heading']) && $line['heading'] != '') { |
| 305 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 306 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
| 307 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
| 308 | - //$dataFound = true; |
|
| 305 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 306 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
| 307 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
| 308 | + //$dataFound = true; |
|
| 309 | 309 | } 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']) { |
| 310 | - $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']); |
|
| 311 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
| 312 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 313 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
| 310 | + $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']); |
|
| 311 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
| 312 | + if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 313 | + if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
| 314 | 314 | } |
| 315 | 315 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
| 316 | 316 | |
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) { |
| 320 | - $this->all_tracked[$id]['lastupdate'] = time(); |
|
| 321 | - if ($this->all_tracked[$id]['addedMarine'] == 0) { |
|
| 322 | - 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'])) { |
|
| 323 | - if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
|
| 320 | + $this->all_tracked[$id]['lastupdate'] = time(); |
|
| 321 | + if ($this->all_tracked[$id]['addedMarine'] == 0) { |
|
| 322 | + 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'])) { |
|
| 323 | + if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
|
| 324 | 324 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 325 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
| 326 | - $timeelapsed = microtime(true); |
|
| 327 | - $MarineLive = new MarineLive($this->db); |
|
| 328 | - if (isset($line['id'])) { |
|
| 325 | + if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
| 326 | + $timeelapsed = microtime(true); |
|
| 327 | + $MarineLive = new MarineLive($this->db); |
|
| 328 | + if (isset($line['id'])) { |
|
| 329 | 329 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
| 330 | 330 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 331 | - } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
|
| 331 | + } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
|
| 332 | 332 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
| 333 | 333 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 334 | - } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
|
| 334 | + } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
|
| 335 | 335 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
| 336 | 336 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 337 | - } else $recent_ident = ''; |
|
| 338 | - $MarineLive->db=null; |
|
| 339 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
| 340 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
| 337 | + } else $recent_ident = ''; |
|
| 338 | + $MarineLive->db=null; |
|
| 339 | + if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
| 340 | + elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
| 341 | 341 | } else $recent_ident = ''; |
| 342 | - } else { |
|
| 342 | + } else { |
|
| 343 | 343 | $recent_ident = ''; |
| 344 | 344 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
| 345 | - } |
|
| 346 | - //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
| 347 | - if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
| 348 | - { |
|
| 345 | + } |
|
| 346 | + //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
| 347 | + if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
| 348 | + { |
|
| 349 | 349 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
| 350 | 350 | //adds the spotter data for the archive |
| 351 | - $highlight = ''; |
|
| 352 | - 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'))); |
|
| 353 | - if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
| 351 | + $highlight = ''; |
|
| 352 | + 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'))); |
|
| 353 | + if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
| 354 | 354 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 355 | - $timeelapsed = microtime(true); |
|
| 356 | - $Marine = new Marine($this->db); |
|
| 357 | - $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']); |
|
| 358 | - $Marine->db = null; |
|
| 359 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 360 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 355 | + $timeelapsed = microtime(true); |
|
| 356 | + $Marine = new Marine($this->db); |
|
| 357 | + $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']); |
|
| 358 | + $Marine->db = null; |
|
| 359 | + if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 360 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 361 | 361 | } |
| 362 | - } |
|
| 363 | - /* |
|
| 362 | + } |
|
| 363 | + /* |
|
| 364 | 364 | // Add source stat in DB |
| 365 | 365 | $Stats = new Stats($this->db); |
| 366 | 366 | if (!empty($this->stats)) { |
@@ -387,56 +387,56 @@ discard block |
||
| 387 | 387 | } |
| 388 | 388 | $Stats->db = null; |
| 389 | 389 | */ |
| 390 | - $this->del(); |
|
| 390 | + $this->del(); |
|
| 391 | 391 | //$ignoreImport = false; |
| 392 | 392 | $this->all_tracked[$id]['addedMarine'] = 1; |
| 393 | 393 | //print_r($this->all_tracked[$id]); |
| 394 | 394 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
| 395 | - if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
| 396 | - //MarineLive->deleteLiveMarineDataNotUpdated(); |
|
| 397 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 395 | + if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
| 396 | + //MarineLive->deleteLiveMarineDataNotUpdated(); |
|
| 397 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 398 | 398 | $MarineLive = new MarineLive($this->db); |
| 399 | 399 | $MarineLive->deleteLiveMarineData(); |
| 400 | 400 | $MarineLive->db=null; |
| 401 | 401 | if ($globalDebug) echo " Done\n"; |
| 402 | - } |
|
| 403 | - $this->last_delete = time(); |
|
| 402 | + } |
|
| 403 | + $this->last_delete = time(); |
|
| 404 | 404 | } |
| 405 | - } elseif ($recent_ident != '') { |
|
| 405 | + } elseif ($recent_ident != '') { |
|
| 406 | 406 | $this->all_tracked[$id]['id'] = $recent_ident; |
| 407 | 407 | $this->all_tracked[$id]['addedMarine'] = 1; |
| 408 | 408 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 409 | - if (isset($globalDaemon) && !$globalDaemon) { |
|
| 409 | + if (isset($globalDaemon) && !$globalDaemon) { |
|
| 410 | 410 | $Marine = new Marine($this->db); |
| 411 | 411 | $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']); |
| 412 | 412 | $Marine->db = null; |
| 413 | - } |
|
| 413 | + } |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - } |
|
| 416 | + } |
|
| 417 | 417 | } |
| 418 | - } |
|
| 419 | - //adds the spotter LIVE data |
|
| 420 | - if ($globalDebug) { |
|
| 418 | + } |
|
| 419 | + //adds the spotter LIVE data |
|
| 420 | + if ($globalDebug) { |
|
| 421 | 421 | 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"; |
| 422 | - } |
|
| 423 | - $ignoreImport = false; |
|
| 422 | + } |
|
| 423 | + $ignoreImport = false; |
|
| 424 | 424 | |
| 425 | - if (!$ignoreImport) { |
|
| 425 | + if (!$ignoreImport) { |
|
| 426 | 426 | 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'])) { |
| 427 | 427 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
| 428 | 428 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 429 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 429 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 430 | 430 | $timeelapsed = microtime(true); |
| 431 | 431 | $MarineLive = new MarineLive($this->db); |
| 432 | 432 | $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']); |
| 433 | 433 | $MarineLive->db = null; |
| 434 | 434 | if ($globalDebug) echo $result."\n"; |
| 435 | 435 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 436 | - } |
|
| 436 | + } |
|
| 437 | 437 | } |
| 438 | 438 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) { |
| 439 | - $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']); |
|
| 439 | + $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']); |
|
| 440 | 440 | } |
| 441 | 441 | $this->all_tracked[$id]['putinarchive'] = false; |
| 442 | 442 | |
@@ -501,24 +501,24 @@ discard block |
||
| 501 | 501 | |
| 502 | 502 | |
| 503 | 503 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
| 504 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 504 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 505 | 505 | if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
| 506 | 506 | $MarineLive = new MarineLive($this->db); |
| 507 | 507 | $MarineLive->deleteLiveMarineDataNotUpdated(); |
| 508 | 508 | $MarineLive->db = null; |
| 509 | 509 | //MarineLive->deleteLiveMarineData(); |
| 510 | 510 | if ($globalDebug) echo " Done\n"; |
| 511 | - } |
|
| 512 | - $this->last_delete_hourly = time(); |
|
| 511 | + } |
|
| 512 | + $this->last_delete_hourly = time(); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - } |
|
| 516 | - //$ignoreImport = false; |
|
| 515 | + } |
|
| 516 | + //$ignoreImport = false; |
|
| 517 | 517 | } |
| 518 | 518 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
| 519 | 519 | if ($send) return $this->all_tracked[$id]; |
| 520 | - } |
|
| 520 | + } |
|
| 521 | + } |
|
| 521 | 522 | } |
| 522 | - } |
|
| 523 | 523 | } |
| 524 | 524 | ?> |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | if (isset($this->all_tracked[$key]['id'])) { |
| 59 | 59 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
| 60 | 60 | $Marine = new Marine($this->db); |
| 61 | - $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']); |
|
| 61 | + $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 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
| 70 | 70 | foreach ($this->all_tracked as $key => $flight) { |
| 71 | 71 | if (isset($flight['lastupdate'])) { |
| 72 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
| 72 | + if ($flight['lastupdate'] < (time() - 3000)) { |
|
| 73 | 73 | if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
| 74 | 74 | if (isset($this->all_tracked[$key]['id'])) { |
| 75 | 75 | if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | //$real_arrival = $this->arrival($key); |
| 82 | 82 | $Marine = new Marine($this->db); |
| 83 | 83 | if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
| 84 | - $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']); |
|
| 84 | + $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']); |
|
| 85 | 85 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 86 | 86 | } |
| 87 | 87 | // Put in archive |
@@ -95,14 +95,14 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public function add($line) { |
| 98 | - global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine; |
|
| 98 | + global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS, $APRSMarine; |
|
| 99 | 99 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
| 100 | 100 | date_default_timezone_set('UTC'); |
| 101 | 101 | $dataFound = false; |
| 102 | 102 | $send = false; |
| 103 | 103 | |
| 104 | 104 | // SBS format is CSV format |
| 105 | - if(is_array($line) && isset($line['mmsi'])) { |
|
| 105 | + if (is_array($line) && isset($line['mmsi'])) { |
|
| 106 | 106 | //print_r($line); |
| 107 | 107 | if (isset($line['mmsi'])) { |
| 108 | 108 | |
@@ -126,18 +126,18 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | if (!isset($this->all_tracked[$id])) { |
| 128 | 128 | $this->all_tracked[$id] = array(); |
| 129 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
| 130 | - $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' => '')); |
|
| 131 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
| 129 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0)); |
|
| 130 | + $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' => '')); |
|
| 131 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time())); |
|
| 132 | 132 | if (!isset($line['id'])) { |
| 133 | 133 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
| 134 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 135 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
| 134 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi'))); |
|
| 135 | + } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id'])); |
|
| 136 | 136 | if ($globalAllTracked !== FALSE) $dataFound = true; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
| 140 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
| 140 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi'])); |
|
| 141 | 141 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 142 | 142 | $Marine = new Marine($this->db); |
| 143 | 143 | $identity = $Marine->getIdentity($line['mmsi']); |
@@ -151,64 +151,64 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | if (isset($line['type_id'])) { |
| 154 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
| 154 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id']))); |
|
| 155 | 155 | } |
| 156 | 156 | if (isset($line['type']) && $line['type'] != '') { |
| 157 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
| 157 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type'])); |
|
| 158 | 158 | } |
| 159 | 159 | if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') { |
| 160 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type'])); |
|
| 160 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type'])); |
|
| 161 | 161 | } |
| 162 | 162 | if (isset($line['imo']) && $line['imo'] != '') { |
| 163 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
| 163 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo'])); |
|
| 164 | 164 | } |
| 165 | 165 | if (isset($line['callsign']) && $line['callsign'] != '') { |
| 166 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
| 166 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign'])); |
|
| 167 | 167 | } |
| 168 | 168 | if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
| 169 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
|
| 169 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code'])); |
|
| 170 | 170 | } |
| 171 | 171 | if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
| 172 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
| 172 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date'])); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
| 176 | 176 | //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'])) { |
| 177 | 177 | if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) { |
| 178 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
| 178 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident']))); |
|
| 179 | 179 | if ($this->all_tracked[$id]['addedMarine'] == 1) { |
| 180 | 180 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 181 | 181 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 182 | 182 | $timeelapsed = microtime(true); |
| 183 | 183 | $Marine = new Marine($this->db); |
| 184 | 184 | $fromsource = NULL; |
| 185 | - $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
|
| 185 | + $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource); |
|
| 186 | 186 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 187 | 187 | $Marine->db = null; |
| 188 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 188 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
| 192 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident'])); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) { |
|
| 195 | + if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60 && strtotime($line['datetime']) < time() + 20*60) { |
|
| 196 | 196 | if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
| 197 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
|
| 197 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime'])); |
|
| 198 | 198 | } else { |
| 199 | 199 | 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"; |
| 200 | 200 | 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"; |
| 201 | 201 | return ''; |
| 202 | 202 | } |
| 203 | - } elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) { |
|
| 203 | + } elseif (isset($line['datetime']) && strtotime($line['datetime']) < time() - 20*60) { |
|
| 204 | 204 | if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
| 205 | 205 | return ''; |
| 206 | - } elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) { |
|
| 206 | + } elseif (isset($line['datetime']) && strtotime($line['datetime']) > time() + 20*60) { |
|
| 207 | 207 | if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
| 208 | 208 | return ''; |
| 209 | 209 | } elseif (!isset($line['datetime'])) { |
| 210 | 210 | date_default_timezone_set('UTC'); |
| 211 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
| 211 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s'))); |
|
| 212 | 212 | } else { |
| 213 | 213 | if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!"; |
| 214 | 214 | return ''; |
@@ -216,24 +216,24 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | |
| 218 | 218 | if (isset($line['speed'])) { |
| 219 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
| 220 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
| 219 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed']))); |
|
| 220 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true)); |
|
| 221 | 221 | } 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'])) { |
| 222 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
| 222 | + $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm'); |
|
| 223 | 223 | if ($distance > 1000 && $distance < 10000) { |
| 224 | 224 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
| 225 | 225 | $speed = $speed*3.6; |
| 226 | - if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
| 226 | + if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed))); |
|
| 227 | 227 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
| 232 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
| 232 | + if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']); |
|
| 233 | 233 | else unset($timediff); |
| 234 | - 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')))) { |
|
| 234 | + 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 | 235 | 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'])) { |
| 236 | - 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'])) { |
|
| 236 | + 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'])) { |
|
| 237 | 237 | $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
| 238 | 238 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
| 239 | 239 | $this->all_tracked[$id]['putinarchive'] = true; |
@@ -242,10 +242,10 @@ discard block |
||
| 242 | 242 | $timeelapsed = microtime(true); |
| 243 | 243 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 244 | 244 | $Marine = new Marine($this->db); |
| 245 | - $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
| 245 | + $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']); |
|
| 246 | 246 | if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
| 247 | 247 | $Marine->db = null; |
| 248 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 248 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 249 | 249 | } |
| 250 | 250 | $this->tmd = 0; |
| 251 | 251 | if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
@@ -254,62 +254,62 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
| 256 | 256 | if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
| 257 | - 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') { |
|
| 257 | + 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') { |
|
| 258 | 258 | $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
| 259 | 259 | $dataFound = true; |
| 260 | 260 | $this->all_tracked[$id]['time_last_coord'] = time(); |
| 261 | 261 | } |
| 262 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
|
| 262 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude'])); |
|
| 263 | 263 | } |
| 264 | 264 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
| 265 | 265 | if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
| 266 | 266 | if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
| 267 | - 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') { |
|
| 267 | + 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') { |
|
| 268 | 268 | $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
| 269 | 269 | $dataFound = true; |
| 270 | 270 | $this->all_tracked[$id]['time_last_coord'] = time(); |
| 271 | 271 | } |
| 272 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude'])); |
|
| 272 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude'])); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | } else if ($globalDebug && $timediff > 20) { |
| 276 | 276 | $this->tmd = $this->tmd + 1; |
| 277 | 277 | echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n"; |
| 278 | - echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -"; |
|
| 279 | - echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
|
| 278 | + echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -"; |
|
| 279 | + echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - "; |
|
| 280 | 280 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n"; |
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 284 | 284 | if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
| 285 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
| 285 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update'])); |
|
| 286 | 286 | } |
| 287 | 287 | if (isset($line['format_source']) && $line['format_source'] != '') { |
| 288 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
| 288 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source'])); |
|
| 289 | 289 | } |
| 290 | 290 | if (isset($line['source_name']) && $line['source_name'] != '') { |
| 291 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
| 291 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name'])); |
|
| 292 | 292 | } |
| 293 | 293 | if (isset($line['status']) && $line['status'] != '') { |
| 294 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
| 294 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status'])); |
|
| 295 | 295 | } |
| 296 | 296 | if (isset($line['status_id'])) { |
| 297 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id'])); |
|
| 297 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id'])); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
| 301 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
| 301 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true)); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | if (isset($line['heading']) && $line['heading'] != '') { |
| 305 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 306 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
| 307 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
| 305 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 306 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading']))); |
|
| 307 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true)); |
|
| 308 | 308 | //$dataFound = true; |
| 309 | 309 | } 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']) { |
| 310 | - $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']); |
|
| 311 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
| 312 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 310 | + $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']); |
|
| 311 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading))); |
|
| 312 | + if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 313 | 313 | if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
| 314 | 314 | } |
| 315 | 315 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) { |
| 320 | 320 | $this->all_tracked[$id]['lastupdate'] = time(); |
| 321 | 321 | if ($this->all_tracked[$id]['addedMarine'] == 0) { |
| 322 | - 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'])) { |
|
| 322 | + 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'])) { |
|
| 323 | 323 | if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
| 324 | 324 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 325 | 325 | if ($globalDebug) echo "Check if aircraft is already in DB..."; |
@@ -327,37 +327,37 @@ discard block |
||
| 327 | 327 | $MarineLive = new MarineLive($this->db); |
| 328 | 328 | if (isset($line['id'])) { |
| 329 | 329 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
| 330 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 330 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 331 | 331 | } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
| 332 | 332 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
| 333 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 333 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 334 | 334 | } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
| 335 | 335 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
| 336 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 336 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 337 | 337 | } else $recent_ident = ''; |
| 338 | - $MarineLive->db=null; |
|
| 338 | + $MarineLive->db = null; |
|
| 339 | 339 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
| 340 | 340 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
| 341 | 341 | } else $recent_ident = ''; |
| 342 | 342 | } else { |
| 343 | 343 | $recent_ident = ''; |
| 344 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
|
| 344 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0)); |
|
| 345 | 345 | } |
| 346 | 346 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
| 347 | - if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
| 347 | + if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
| 348 | 348 | { |
| 349 | 349 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
| 350 | 350 | //adds the spotter data for the archive |
| 351 | 351 | $highlight = ''; |
| 352 | - 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'))); |
|
| 352 | + 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'))); |
|
| 353 | 353 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 354 | 354 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 355 | 355 | $timeelapsed = microtime(true); |
| 356 | 356 | $Marine = new Marine($this->db); |
| 357 | - $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']); |
|
| 357 | + $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']); |
|
| 358 | 358 | $Marine->db = null; |
| 359 | 359 | if ($globalDebug && isset($result)) echo $result."\n"; |
| 360 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 360 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | 363 | /* |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 398 | 398 | $MarineLive = new MarineLive($this->db); |
| 399 | 399 | $MarineLive->deleteLiveMarineData(); |
| 400 | - $MarineLive->db=null; |
|
| 400 | + $MarineLive->db = null; |
|
| 401 | 401 | if ($globalDebug) echo " Done\n"; |
| 402 | 402 | } |
| 403 | 403 | $this->last_delete = time(); |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 409 | 409 | if (isset($globalDaemon) && !$globalDaemon) { |
| 410 | 410 | $Marine = new Marine($this->db); |
| 411 | - $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']); |
|
| 411 | + $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']); |
|
| 412 | 412 | $Marine->db = null; |
| 413 | 413 | } |
| 414 | 414 | } |
@@ -423,20 +423,20 @@ discard block |
||
| 423 | 423 | $ignoreImport = false; |
| 424 | 424 | |
| 425 | 425 | if (!$ignoreImport) { |
| 426 | - 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'])) { |
|
| 426 | + 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'])) { |
|
| 427 | 427 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
| 428 | 428 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 429 | 429 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 430 | 430 | $timeelapsed = microtime(true); |
| 431 | 431 | $MarineLive = new MarineLive($this->db); |
| 432 | - $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']); |
|
| 432 | + $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']); |
|
| 433 | 433 | $MarineLive->db = null; |
| 434 | 434 | if ($globalDebug) echo $result."\n"; |
| 435 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 435 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) { |
| 439 | - $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']); |
|
| 439 | + $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']); |
|
| 440 | 440 | } |
| 441 | 441 | $this->all_tracked[$id]['putinarchive'] = false; |
| 442 | 442 | |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | $this->all_tracked[$id]['lastupdate'] = time(); |
| 498 | 498 | if ($this->all_tracked[$id]['putinarchive']) $send = true; |
| 499 | - } 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"; |
|
| 499 | + } 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"; |
|
| 500 | 500 | //$this->del(); |
| 501 | 501 | |
| 502 | 502 | |