@@ -117,31 +117,31 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | private function make_latf($temp) { // unsigned long |
| 119 | 119 | $flat = 0.0; // float |
| 120 | - $temp = $temp & 0x07FFFFFF; |
|
| 121 | - if ($temp & 0x04000000) { |
|
| 122 | - $temp = $temp ^ 0x07FFFFFF; |
|
| 120 | + $temp = $temp&0x07FFFFFF; |
|
| 121 | + if ($temp&0x04000000) { |
|
| 122 | + $temp = $temp^0x07FFFFFF; |
|
| 123 | 123 | $temp += 1; |
| 124 | - $flat = (float)($temp / (60.0 * 10000.0)); |
|
| 124 | + $flat = (float) ($temp/(60.0*10000.0)); |
|
| 125 | 125 | $flat *= -1.0; |
| 126 | - } else $flat = (float)($temp / (60.0 * 10000.0)); |
|
| 126 | + } else $flat = (float) ($temp/(60.0*10000.0)); |
|
| 127 | 127 | return $flat; // float |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | private function make_lonf($temp) { // unsigned long |
| 131 | 131 | $flon = 0.0; // float |
| 132 | - $temp = $temp & 0x0FFFFFFF; |
|
| 133 | - if ($temp & 0x08000000) { |
|
| 134 | - $temp = $temp ^ 0x0FFFFFFF; |
|
| 132 | + $temp = $temp&0x0FFFFFFF; |
|
| 133 | + if ($temp&0x08000000) { |
|
| 134 | + $temp = $temp^0x0FFFFFFF; |
|
| 135 | 135 | $temp += 1; |
| 136 | - $flon = (float)($temp / (60.0 * 10000.0)); |
|
| 136 | + $flon = (float) ($temp/(60.0*10000.0)); |
|
| 137 | 137 | $flon *= -1.0; |
| 138 | - } else $flon = (float)($temp / (60.0 * 10000.0)); |
|
| 138 | + } else $flon = (float) ($temp/(60.0*10000.0)); |
|
| 139 | 139 | return $flon; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | private function ascii_2_dec($chr) { |
| 143 | - $dec=ord($chr);//get decimal ascii code |
|
| 144 | - $hex=dechex($dec);//convert decimal to hex |
|
| 143 | + $dec = ord($chr); //get decimal ascii code |
|
| 144 | + $hex = dechex($dec); //convert decimal to hex |
|
| 145 | 145 | return ($dec); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -160,15 +160,15 @@ discard block |
||
| 160 | 160 | //only process in the following range: 48-87, 96-119 |
| 161 | 161 | if ($ascii < 48) { } |
| 162 | 162 | else { |
| 163 | - if($ascii>119) { } |
|
| 163 | + if ($ascii > 119) { } |
|
| 164 | 164 | else { |
| 165 | - if ($ascii>87 && $ascii<96) ; |
|
| 165 | + if ($ascii > 87 && $ascii < 96); |
|
| 166 | 166 | else { |
| 167 | - $ascii=$ascii+40; |
|
| 168 | - if ($ascii>128){ |
|
| 169 | - $ascii=$ascii+32; |
|
| 167 | + $ascii = $ascii + 40; |
|
| 168 | + if ($ascii > 128) { |
|
| 169 | + $ascii = $ascii + 32; |
|
| 170 | 170 | } else { |
| 171 | - $ascii=$ascii+40; |
|
| 171 | + $ascii = $ascii + 40; |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | private function dec_2_6bit($dec) { |
| 180 | - $bin=decbin($dec); |
|
| 180 | + $bin = decbin($dec); |
|
| 181 | 181 | return(substr($bin, -6)); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -195,11 +195,11 @@ discard block |
||
| 195 | 195 | ); |
| 196 | 196 | // " |
| 197 | 197 | $rv = ''; |
| 198 | - if ($_size % 6 == 0) { |
|
| 199 | - $len = $_size / 6; |
|
| 200 | - for ($i=0; $i<$len; $i++) { |
|
| 201 | - $offset = $i * 6; |
|
| 202 | - $rv .= $ais_chars[ bindec(substr($_str,$_start + $offset,6)) ]; |
|
| 198 | + if ($_size%6 == 0) { |
|
| 199 | + $len = $_size/6; |
|
| 200 | + for ($i = 0; $i < $len; $i++) { |
|
| 201 | + $offset = $i*6; |
|
| 202 | + $rv .= $ais_chars[bindec(substr($_str, $_start + $offset, 6))]; |
|
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | return $rv; |
@@ -226,93 +226,93 @@ discard block |
||
| 226 | 226 | $ro->eta_hour = ''; |
| 227 | 227 | $ro->eta_minute = ''; |
| 228 | 228 | $ro->ts = time(); |
| 229 | - $ro->id = bindec(substr($_aisdata,0,6)); |
|
| 230 | - $ro->mmsi = bindec(substr($_aisdata,8,30)); |
|
| 229 | + $ro->id = bindec(substr($_aisdata, 0, 6)); |
|
| 230 | + $ro->mmsi = bindec(substr($_aisdata, 8, 30)); |
|
| 231 | 231 | if ($ro->id >= 1 && $ro->id <= 3) { |
| 232 | - $ro->cog = bindec(substr($_aisdata,116,12))/10; |
|
| 233 | - $ro->sog = bindec(substr($_aisdata,50,10))/10; |
|
| 234 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28))); |
|
| 235 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27))); |
|
| 232 | + $ro->cog = bindec(substr($_aisdata, 116, 12))/10; |
|
| 233 | + $ro->sog = bindec(substr($_aisdata, 50, 10))/10; |
|
| 234 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28))); |
|
| 235 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27))); |
|
| 236 | 236 | $ro->cls = 1; // class A |
| 237 | 237 | } else if ($ro->id == 4) { |
| 238 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,79,28))); |
|
| 239 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,107,27))); |
|
| 238 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 79, 28))); |
|
| 239 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 107, 27))); |
|
| 240 | 240 | $ro->cls = 1; // class A |
| 241 | 241 | } else if ($ro->id == 5) { |
| 242 | - $ro->imo = bindec(substr($_aisdata,40,30)); |
|
| 243 | - $ro->callsign = $this->binchar($_aisdata,70,42); |
|
| 244 | - $ro->name = $this->binchar($_aisdata,112,120); |
|
| 245 | - $ro->typeid = bindec(substr($_aisdata,232,8)); |
|
| 242 | + $ro->imo = bindec(substr($_aisdata, 40, 30)); |
|
| 243 | + $ro->callsign = $this->binchar($_aisdata, 70, 42); |
|
| 244 | + $ro->name = $this->binchar($_aisdata, 112, 120); |
|
| 245 | + $ro->typeid = bindec(substr($_aisdata, 232, 8)); |
|
| 246 | 246 | $ro->type = $this->getShipType($ro->typeid); |
| 247 | 247 | //$ro->to_bow = bindec(substr($_aisdata,240,9)); |
| 248 | 248 | //$ro->to_stern = bindec(substr($_aisdata,249,9)); |
| 249 | 249 | //$ro->to_port = bindec(substr($_aisdata,258,6)); |
| 250 | 250 | //$ro->to_starboard = bindec(substr($_aisdata,264,6)); |
| 251 | - $ro->eta_month = bindec(substr($_aisdata,274,4)); |
|
| 252 | - $ro->eta_day = bindec(substr($_aisdata,278,5)); |
|
| 253 | - $ro->eta_hour = bindec(substr($_aisdata,283,5)); |
|
| 254 | - $ro->eta_minute = bindec(substr($_aisdata,288,6)); |
|
| 251 | + $ro->eta_month = bindec(substr($_aisdata, 274, 4)); |
|
| 252 | + $ro->eta_day = bindec(substr($_aisdata, 278, 5)); |
|
| 253 | + $ro->eta_hour = bindec(substr($_aisdata, 283, 5)); |
|
| 254 | + $ro->eta_minute = bindec(substr($_aisdata, 288, 6)); |
|
| 255 | 255 | //$ro->draught = bindec(substr($_aisdata,294,8)); |
| 256 | - $ro->destination = $this->binchar($_aisdata,302,120); |
|
| 256 | + $ro->destination = $this->binchar($_aisdata, 302, 120); |
|
| 257 | 257 | $ro->cls = 1; // class A |
| 258 | 258 | } else if ($ro->id == 9) { |
| 259 | 259 | // Search and Rescue aircraft position report |
| 260 | 260 | } else if ($ro->id == 18) { |
| 261 | - $ro->cog = bindec(substr($_aisdata,112,12))/10; |
|
| 262 | - $ro->sog = bindec(substr($_aisdata,46,10))/10; |
|
| 263 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
|
| 264 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
|
| 265 | - $ro->heading = bindec(substr($_aisdata,124,9)); |
|
| 261 | + $ro->cog = bindec(substr($_aisdata, 112, 12))/10; |
|
| 262 | + $ro->sog = bindec(substr($_aisdata, 46, 10))/10; |
|
| 263 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 57, 28))); |
|
| 264 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 85, 27))); |
|
| 265 | + $ro->heading = bindec(substr($_aisdata, 124, 9)); |
|
| 266 | 266 | if ($ro->heading == 511) $ro->heading = ''; |
| 267 | 267 | $ro->cls = 2; // class B |
| 268 | 268 | } else if ($ro->id == 19) { |
| 269 | - $ro->cog = bindec(substr($_aisdata,112,12))/10; |
|
| 270 | - $ro->sog = bindec(substr($_aisdata,46,10))/10; |
|
| 271 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28))); |
|
| 272 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27))); |
|
| 273 | - $ro->name = $this->binchar($_aisdata,143,120); |
|
| 269 | + $ro->cog = bindec(substr($_aisdata, 112, 12))/10; |
|
| 270 | + $ro->sog = bindec(substr($_aisdata, 46, 10))/10; |
|
| 271 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28))); |
|
| 272 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27))); |
|
| 273 | + $ro->name = $this->binchar($_aisdata, 143, 120); |
|
| 274 | 274 | $ro->cls = 2; // class B |
| 275 | - $ro->heading = bindec(substr($_aisdata,124,9)); |
|
| 275 | + $ro->heading = bindec(substr($_aisdata, 124, 9)); |
|
| 276 | 276 | if ($ro->heading == 511) $ro->heading = ''; |
| 277 | - $ro->typeid = bindec(substr($_aisdata,263,8)); |
|
| 277 | + $ro->typeid = bindec(substr($_aisdata, 263, 8)); |
|
| 278 | 278 | $ro->type = $this->getShipType($ro->typeid); |
| 279 | 279 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
| 280 | 280 | //$ro->to_stern = bindec(substr($_aisdata,280,9)); |
| 281 | 281 | //$ro->to_port = bindec(substr($_aisdata,289,6)); |
| 282 | 282 | //$ro->to_starboard = bindec(substr($_aisdata,295,6)); |
| 283 | 283 | } else if ($ro->id == 21) { |
| 284 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,164,28))); |
|
| 285 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,192,27))); |
|
| 286 | - $ro->name = $this->binchar($_aisdata,43,120); |
|
| 284 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 164, 28))); |
|
| 285 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 192, 27))); |
|
| 286 | + $ro->name = $this->binchar($_aisdata, 43, 120); |
|
| 287 | 287 | //$ro->to_bow = bindec(substr($_aisdata,219,9)); |
| 288 | 288 | //$ro->to_stern = bindec(substr($_aisdata,228,9)); |
| 289 | 289 | //$ro->to_port = bindec(substr($_aisdata,237,6)); |
| 290 | 290 | //$ro->to_starboard = bindec(substr($_aisdata,243,6)); |
| 291 | 291 | $ro->cls = 2; // class B |
| 292 | 292 | } else if ($ro->id == 24) { |
| 293 | - $pn = bindec(substr($_aisdata,38,2)); |
|
| 293 | + $pn = bindec(substr($_aisdata, 38, 2)); |
|
| 294 | 294 | if ($pn == 0) { |
| 295 | - $ro->name = $this->binchar($_aisdata,40,120); |
|
| 295 | + $ro->name = $this->binchar($_aisdata, 40, 120); |
|
| 296 | 296 | } |
| 297 | - $ro->typeid = bindec(substr($_aisdata,40,8)); |
|
| 297 | + $ro->typeid = bindec(substr($_aisdata, 40, 8)); |
|
| 298 | 298 | $ro->type = $this->getShipType($ro->typeid); |
| 299 | - $ro->callsign = $this->binchar($_aisdata,90,42); |
|
| 299 | + $ro->callsign = $this->binchar($_aisdata, 90, 42); |
|
| 300 | 300 | //$ro->to_bow = bindec(substr($_aisdata,132,9)); |
| 301 | 301 | //$ro->to_stern = bindec(substr($_aisdata,141,9)); |
| 302 | 302 | //$ro->to_port = bindec(substr($_aisdata,150,6)); |
| 303 | 303 | //$ro->to_starboard = bindec(substr($_aisdata,156,6)); |
| 304 | 304 | $ro->cls = 2; // class B |
| 305 | 305 | } else if ($ro->id == 27) { |
| 306 | - $ro->cog = bindec(substr($_aisdata,85,9)); |
|
| 306 | + $ro->cog = bindec(substr($_aisdata, 85, 9)); |
|
| 307 | 307 | if ($ro->cog == 511) $ro->cog = 0.0; |
| 308 | - $ro->sog = bindec(substr($_aisdata,79,6)); |
|
| 308 | + $ro->sog = bindec(substr($_aisdata, 79, 6)); |
|
| 309 | 309 | if ($ro->sog == 63) $ro->sog = 0.0; |
| 310 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
|
| 311 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
|
| 310 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 44, 18))*10); |
|
| 311 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 62, 17))*10); |
|
| 312 | 312 | $ro->cls = 1; // class A |
| 313 | 313 | |
| 314 | 314 | } |
| 315 | - $ro->statusid = bindec(substr($_aisdata,38,4)); |
|
| 315 | + $ro->statusid = bindec(substr($_aisdata, 38, 4)); |
|
| 316 | 316 | $ro->status = $this->getStatus($ro->statusid); |
| 317 | 317 | return $ro; |
| 318 | 318 | } |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | public function getShipTypeID($type) { |
| 362 | - $typeid = array_search($type,$this->shiptype); |
|
| 362 | + $typeid = array_search($type, $this->shiptype); |
|
| 363 | 363 | if ($typeid !== FALSE) return $typeid; |
| 364 | 364 | elseif ($type == 'Cargo' || $type == 'General Cargo' || $type == 'Bulk Carrier' || $type == 'Container Ship' || $type == 'Cargo A' || $type == 'Reefer' || $type == 'Vehicles Carrier') return 70; |
| 365 | 365 | elseif ($type == 'Passengers Ship' || $type == 'Passenger' || $type == 'Ro-Ro/Passenger Ship' || $type == 'Motor Passenger') return 60; |
@@ -380,14 +380,14 @@ discard block |
||
| 380 | 380 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
| 381 | 381 | global $port; // tcpip port... |
| 382 | 382 | static $debug_counter = 0; |
| 383 | - $aisdata168='';//six bit array of ascii characters |
|
| 383 | + $aisdata168 = ''; //six bit array of ascii characters |
|
| 384 | 384 | $ais_nmea_array = str_split($_itu); // convert to an array |
| 385 | 385 | foreach ($ais_nmea_array as $value) { |
| 386 | 386 | $dec = $this->ascii_2_dec($value); |
| 387 | 387 | $bit8 = $this->asciidec_2_8bit($dec); |
| 388 | 388 | $bit6 = $this->dec_2_6bit($bit8); |
| 389 | 389 | //echo $value ."-" .$bit6 .""; |
| 390 | - $aisdata168 .=$bit6; |
|
| 390 | + $aisdata168 .= $bit6; |
|
| 391 | 391 | } |
| 392 | 392 | //echo $aisdata168 . "<br/>"; |
| 393 | 393 | //return $this->decode_ais($aisdata168, $aux); |
@@ -410,24 +410,24 @@ discard block |
||
| 410 | 410 | // calculate checksum after ! till * |
| 411 | 411 | // assume 1st ! is valid |
| 412 | 412 | // find * ensure that it is at correct position |
| 413 | - $end = strrpos ( $rawdata , '*' ); |
|
| 413 | + $end = strrpos($rawdata, '*'); |
|
| 414 | 414 | if ($end === FALSE) return -1; // check for NULLS!!! |
| 415 | - $cs = substr( $rawdata, $end + 1 ); |
|
| 416 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
| 417 | - $dcs = (int)hexdec( $cs ); |
|
| 418 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
| 419 | - if ( $chksum == $dcs ) { // NMEA checksum pass |
|
| 415 | + $cs = substr($rawdata, $end + 1); |
|
| 416 | + if (strlen($cs) != 2) return -1; // correct cs length |
|
| 417 | + $dcs = (int) hexdec($cs); |
|
| 418 | + for ($alias = 1; $alias < $end; $alias++) $chksum ^= ord($rawdata[$alias]); // perform XOR for NMEA checksum |
|
| 419 | + if ($chksum == $dcs) { // NMEA checksum pass |
|
| 420 | 420 | $pcs = explode(',', $rawdata); |
| 421 | 421 | // !AI??? identifier |
| 422 | 422 | if (!isset($pcs[1])) { |
| 423 | 423 | echo "ERROR,INVALID_DATA ".time()." $rawdata\n"; |
| 424 | 424 | return -1; |
| 425 | 425 | } |
| 426 | - $num_seq = (int)$pcs[1]; // number of sequences |
|
| 427 | - $seq = (int)$pcs[2]; // get sequence |
|
| 426 | + $num_seq = (int) $pcs[1]; // number of sequences |
|
| 427 | + $seq = (int) $pcs[2]; // get sequence |
|
| 428 | 428 | // get msg sequence id |
| 429 | 429 | if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
| 430 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
| 430 | + else $msg_sid = (int) $pcs[3]; // multipart message |
|
| 431 | 431 | $ais_ch = $pcs[4]; // get AIS channel |
| 432 | 432 | // message sequence checking |
| 433 | 433 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | $itu = $itu.$pcs[5]; // get itu message |
| 463 | - $filler += (int)$pcs[6][0]; // get filler |
|
| 463 | + $filler += (int) $pcs[6][0]; // get filler |
|
| 464 | 464 | if ($num_seq == 1 // valid single message |
| 465 | 465 | || $num_seq == $pseq // valid multi-part message |
| 466 | 466 | ) { |
@@ -482,13 +482,13 @@ discard block |
||
| 482 | 482 | $cbuf = $cbuf.$ibuf; |
| 483 | 483 | $last_pos = 0; |
| 484 | 484 | $result = new stdClass(); |
| 485 | - while ( ($start = strpos($cbuf,"VDM",$last_pos)) !== FALSE) { |
|
| 485 | + while (($start = strpos($cbuf, "VDM", $last_pos)) !== FALSE) { |
|
| 486 | 486 | //while ( ($start = strpos($cbuf,"!AI",$last_pos)) !== FALSE) { |
| 487 | 487 | //DEBUG echo $cbuf; |
| 488 | - if ( ($end = strpos($cbuf,"\r\n", $start)) !== FALSE) { //TBD need to trim? |
|
| 488 | + if (($end = strpos($cbuf, "\r\n", $start)) !== FALSE) { //TBD need to trim? |
|
| 489 | 489 | $tst = substr($cbuf, $start - 3, ($end - $start + 3)); |
| 490 | 490 | //DEBUG echo "[$start $end $tst]\n"; |
| 491 | - $result = $this->process_ais_raw( $tst, "" ); |
|
| 491 | + $result = $this->process_ais_raw($tst, ""); |
|
| 492 | 492 | $last_pos = $end + 1; |
| 493 | 493 | } else break; |
| 494 | 494 | } |
@@ -500,41 +500,41 @@ discard block |
||
| 500 | 500 | // incoming data from serial or IP comms |
| 501 | 501 | public function process_ais_line($cbuf) { |
| 502 | 502 | $result = new stdClass(); |
| 503 | - $start = strpos($cbuf,"VDM"); |
|
| 503 | + $start = strpos($cbuf, "VDM"); |
|
| 504 | 504 | $tst = substr($cbuf, $start - 3); |
| 505 | - $result = $this->process_ais_raw( $tst, "" ); |
|
| 505 | + $result = $this->process_ais_raw($tst, ""); |
|
| 506 | 506 | return $result; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | /* AIS Encoding |
| 510 | 510 | */ |
| 511 | - private function mk_ais_lat( $lat ) { |
|
| 511 | + private function mk_ais_lat($lat) { |
|
| 512 | 512 | //$lat = 1.2569; |
| 513 | - if ($lat<0.0) { |
|
| 513 | + if ($lat < 0.0) { |
|
| 514 | 514 | $lat = -$lat; |
| 515 | - $neg=true; |
|
| 516 | - } else $neg=false; |
|
| 515 | + $neg = true; |
|
| 516 | + } else $neg = false; |
|
| 517 | 517 | $latd = 0x00000000; |
| 518 | - $latd = intval ($lat * 600000.0); |
|
| 519 | - if ($neg==true) { |
|
| 518 | + $latd = intval($lat*600000.0); |
|
| 519 | + if ($neg == true) { |
|
| 520 | 520 | $latd = ~$latd; |
| 521 | - $latd+=1; |
|
| 521 | + $latd += 1; |
|
| 522 | 522 | $latd &= 0x07FFFFFF; |
| 523 | 523 | } |
| 524 | 524 | return $latd; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - private function mk_ais_lon( $lon ) { |
|
| 527 | + private function mk_ais_lon($lon) { |
|
| 528 | 528 | //$lon = 103.851; |
| 529 | - if ($lon<0.0) { |
|
| 529 | + if ($lon < 0.0) { |
|
| 530 | 530 | $lon = -$lon; |
| 531 | - $neg=true; |
|
| 532 | - } else $neg=false; |
|
| 531 | + $neg = true; |
|
| 532 | + } else $neg = false; |
|
| 533 | 533 | $lond = 0x00000000; |
| 534 | - $lond = intval ($lon * 600000.0); |
|
| 535 | - if ($neg==true) { |
|
| 534 | + $lond = intval($lon*600000.0); |
|
| 535 | + if ($neg == true) { |
|
| 536 | 536 | $lond = ~$lond; |
| 537 | - $lond+=1; |
|
| 537 | + $lond += 1; |
|
| 538 | 538 | $lond &= 0x0FFFFFFF; |
| 539 | 539 | } |
| 540 | 540 | return $lond; |
@@ -542,8 +542,8 @@ discard block |
||
| 542 | 542 | |
| 543 | 543 | private function char2bin($name, $max_len) { |
| 544 | 544 | $len = strlen($name); |
| 545 | - if ($len > $max_len) $name = substr($name,0,$max_len); |
|
| 546 | - if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6); |
|
| 545 | + if ($len > $max_len) $name = substr($name, 0, $max_len); |
|
| 546 | + if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len)*6); |
|
| 547 | 547 | else $pad = ''; |
| 548 | 548 | $rv = ''; |
| 549 | 549 | $ais_chars = array( |
@@ -560,26 +560,26 @@ discard block |
||
| 560 | 560 | if ($_a) foreach ($_a as $_1) { |
| 561 | 561 | if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
| 562 | 562 | else $dec = 0; |
| 563 | - $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
|
| 563 | + $bin = str_pad(decbin($dec), 6, '0', STR_PAD_LEFT); |
|
| 564 | 564 | $rv .= $bin; |
| 565 | 565 | //echo "$_1 $dec ($bin)<br/>"; |
| 566 | 566 | } |
| 567 | 567 | return $rv.$pad; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - private function mk_ais($_enc, $_part=1,$_total=1,$_seq='',$_ch='A') { |
|
| 570 | + private function mk_ais($_enc, $_part = 1, $_total = 1, $_seq = '', $_ch = 'A') { |
|
| 571 | 571 | $len_bit = strlen($_enc); |
| 572 | - $rem6 = $len_bit % 6; |
|
| 572 | + $rem6 = $len_bit%6; |
|
| 573 | 573 | $pad6_len = 0; |
| 574 | 574 | if ($rem6) $pad6_len = 6 - $rem6; |
| 575 | 575 | //echo $pad6_len.'<br>'; |
| 576 | 576 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
| 577 | - $len_enc = strlen($_enc) / 6; |
|
| 577 | + $len_enc = strlen($_enc)/6; |
|
| 578 | 578 | //echo $_enc.' '.$len_enc.'<br/>'; |
| 579 | 579 | $itu = ''; |
| 580 | - for ($i=0; $i<$len_enc; $i++) { |
|
| 581 | - $offset = $i * 6; |
|
| 582 | - $dec = bindec(substr($_enc,$offset,6)); |
|
| 580 | + for ($i = 0; $i < $len_enc; $i++) { |
|
| 581 | + $offset = $i*6; |
|
| 582 | + $dec = bindec(substr($_enc, $offset, 6)); |
|
| 583 | 583 | if ($dec < 40) $dec += 48; |
| 584 | 584 | else $dec += 56; |
| 585 | 585 | //echo chr($dec)." $dec<br/>"; |
@@ -589,15 +589,15 @@ discard block |
||
| 589 | 589 | $chksum = 0; |
| 590 | 590 | $itu = "AIVDM,$_part,$_total,$_seq,$_ch,".$itu.",0"; |
| 591 | 591 | $len_itu = strlen($itu); |
| 592 | - for ($i=0; $i<$len_itu; $i++) { |
|
| 593 | - $chksum ^= ord( $itu[$i] ); |
|
| 592 | + for ($i = 0; $i < $len_itu; $i++) { |
|
| 593 | + $chksum ^= ord($itu[$i]); |
|
| 594 | 594 | } |
| 595 | - $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 596 | - $lsb = $chksum & 0x0F; |
|
| 597 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
| 595 | + $hex_arr = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
|
| 596 | + $lsb = $chksum&0x0F; |
|
| 597 | + if ($lsb >= 0 && $lsb <= 15) $lsbc = $hex_arr[$lsb]; |
|
| 598 | 598 | else $lsbc = '0'; |
| 599 | - $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
|
| 600 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
| 599 | + $msb = (($chksum&0xF0) >> 4)&0x0F; |
|
| 600 | + if ($msb >= 0 && $msb <= 15) $msbc = $hex_arr[$msb]; |
|
| 601 | 601 | else $msbc = '0'; |
| 602 | 602 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
| 603 | 603 | return $itu; |
@@ -623,14 +623,14 @@ discard block |
||
| 623 | 623 | |
| 624 | 624 | public function mmsitype($mmsi) { |
| 625 | 625 | if (strlen($mmsi) == 9) { |
| 626 | - if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
| 627 | - elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device'; |
|
| 628 | - elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
| 629 | - elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
| 630 | - elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
| 631 | - elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation'; |
|
| 632 | - elseif (substr($mmsi,0,2) == '00') return 'Coastal stations'; |
|
| 633 | - elseif (substr($mmsi,0,1) == '0') return 'Group of ships'; |
|
| 626 | + if (substr($mmsi, 0, 3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
| 627 | + elseif (substr($mmsi, 0, 3) == '972') return 'MOB (Man Overboard) device'; |
|
| 628 | + elseif (substr($mmsi, 0, 3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
| 629 | + elseif (substr($mmsi, 0, 3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
| 630 | + elseif (substr($mmsi, 0, 2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
| 631 | + elseif (substr($mmsi, 0, 2) == '99') return 'Aids to Navigation'; |
|
| 632 | + elseif (substr($mmsi, 0, 2) == '00') return 'Coastal stations'; |
|
| 633 | + elseif (substr($mmsi, 0, 1) == '0') return 'Group of ships'; |
|
| 634 | 634 | else return 'Ship'; |
| 635 | 635 | } |
| 636 | 636 | |
@@ -640,19 +640,19 @@ discard block |
||
| 640 | 640 | public function parse_line($buffer) { |
| 641 | 641 | global $globalDebug; |
| 642 | 642 | $result = array(); |
| 643 | - $start = strpos($buffer,"VDM"); |
|
| 643 | + $start = strpos($buffer, "VDM"); |
|
| 644 | 644 | $tst = substr($buffer, $start - 3); |
| 645 | - $data = $this->process_ais_raw( $tst, "" ); |
|
| 645 | + $data = $this->process_ais_raw($tst, ""); |
|
| 646 | 646 | if (!is_object($data)) { |
| 647 | 647 | //if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n"; |
| 648 | 648 | return array(); |
| 649 | 649 | } |
| 650 | 650 | if ($data->lon != 0) $result['longitude'] = $data->lon; |
| 651 | 651 | if ($data->lat != 0) $result['latitude'] = $data->lat; |
| 652 | - $result['ident'] = trim(str_replace('@','',$data->name)); |
|
| 652 | + $result['ident'] = trim(str_replace('@', '', $data->name)); |
|
| 653 | 653 | $result['timestamp'] = $data->ts; |
| 654 | 654 | $result['mmsi'] = $data->mmsi; |
| 655 | - if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
| 655 | + if (strlen($result['mmsi']) == 8 && substr($result['mmsi'], 0, 3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
| 656 | 656 | $result['mmsi_type'] = $this->mmsitype($result['mmsi']); |
| 657 | 657 | if ($data->sog != -1.0) $result['speed'] = $data->sog; |
| 658 | 658 | if ($data->heading !== '') $result['heading'] = $data->heading; |
@@ -662,16 +662,16 @@ discard block |
||
| 662 | 662 | if ($data->type !== '') $result['type'] = $data->type; |
| 663 | 663 | if ($data->typeid !== '') $result['typeid'] = $data->typeid; |
| 664 | 664 | if ($data->imo !== '') $result['imo'] = $data->imo; |
| 665 | - if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
| 665 | + if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@', '', $data->callsign)); |
|
| 666 | 666 | 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 !== '') { |
| 667 | - $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'); |
|
| 667 | + $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'); |
|
| 668 | 668 | if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
| 669 | 669 | } elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) { |
| 670 | - $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
|
| 670 | + $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00'); |
|
| 671 | 671 | if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
| 672 | 672 | } |
| 673 | 673 | if ($data->destination != '') { |
| 674 | - $dest = trim(str_replace('@','',$data->destination)); |
|
| 674 | + $dest = trim(str_replace('@', '', $data->destination)); |
|
| 675 | 675 | if ($dest != '') $result['destination'] = $dest; |
| 676 | 676 | } |
| 677 | 677 | $result['all'] = (array) $data; |