@@ -35,7 +35,9 @@ discard block |
||
35 | 35 | $temp += 1; |
36 | 36 | $flat = (float)($temp / (60.0 * 10000.0)); |
37 | 37 | $flat *= -1.0; |
38 | - } else $flat = (float)($temp / (60.0 * 10000.0)); |
|
38 | + } else { |
|
39 | + $flat = (float)($temp / (60.0 * 10000.0)); |
|
40 | + } |
|
39 | 41 | return $flat; // float |
40 | 42 | } |
41 | 43 | |
@@ -47,7 +49,9 @@ discard block |
||
47 | 49 | $temp += 1; |
48 | 50 | $flon = (float)($temp / (60.0 * 10000.0)); |
49 | 51 | $flon *= -1.0; |
50 | - } else $flon = (float)($temp / (60.0 * 10000.0)); |
|
52 | + } else { |
|
53 | + $flon = (float)($temp / (60.0 * 10000.0)); |
|
54 | + } |
|
51 | 55 | return $flon; |
52 | 56 | } |
53 | 57 | |
@@ -70,10 +74,8 @@ discard block |
||
70 | 74 | */ |
71 | 75 | private function asciidec_2_8bit($ascii) { |
72 | 76 | //only process in the following range: 48-87, 96-119 |
73 | - if ($ascii < 48) { } |
|
74 | - else { |
|
75 | - if($ascii>119) { } |
|
76 | - else { |
|
77 | + if ($ascii < 48) { } else { |
|
78 | + if($ascii>119) { } else { |
|
77 | 79 | if ($ascii>87 && $ascii<96) ; |
78 | 80 | else { |
79 | 81 | $ascii=$ascii+40; |
@@ -175,7 +177,9 @@ discard block |
||
175 | 177 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
176 | 178 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
177 | 179 | $ro->heading = bindec(substr($_aisdata,124,9)); |
178 | - if ($ro->heading == 511) $ro->heading = ''; |
|
180 | + if ($ro->heading == 511) { |
|
181 | + $ro->heading = ''; |
|
182 | + } |
|
179 | 183 | $ro->cls = 2; // class B |
180 | 184 | } else if ($ro->id == 19) { |
181 | 185 | $ro->cog = bindec(substr($_aisdata,112,12))/10; |
@@ -185,7 +189,9 @@ discard block |
||
185 | 189 | $ro->name = $this->binchar($_aisdata,143,120); |
186 | 190 | $ro->cls = 2; // class B |
187 | 191 | $ro->heading = bindec(substr($_aisdata,124,9)); |
188 | - if ($ro->heading == 511) $ro->heading = ''; |
|
192 | + if ($ro->heading == 511) { |
|
193 | + $ro->heading = ''; |
|
194 | + } |
|
189 | 195 | $ro->typeid = bindec(substr($_aisdata,263,8)); |
190 | 196 | $ro->type = $this->getShipType($ro->typeid); |
191 | 197 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
@@ -216,9 +222,13 @@ discard block |
||
216 | 222 | $ro->cls = 2; // class B |
217 | 223 | } else if ($ro->id == 27) { |
218 | 224 | $ro->cog = bindec(substr($_aisdata,85,9)); |
219 | - if ($ro->cog == 511) $ro->cog = 0.0; |
|
225 | + if ($ro->cog == 511) { |
|
226 | + $ro->cog = 0.0; |
|
227 | + } |
|
220 | 228 | $ro->sog = bindec(substr($_aisdata,79,6)); |
221 | - if ($ro->sog == 63) $ro->sog = 0.0; |
|
229 | + if ($ro->sog == 63) { |
|
230 | + $ro->sog = 0.0; |
|
231 | + } |
|
222 | 232 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
223 | 233 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
224 | 234 | $ro->cls = 1; // class A |
@@ -267,88 +277,171 @@ discard block |
||
267 | 277 | } |
268 | 278 | |
269 | 279 | public function getShipType($code) { |
270 | - if ($code == 0) return 'Not available (default)'; |
|
271 | - elseif ($code >= 1 && $code <= 19) return 'Reserved for future use'; |
|
272 | - elseif ($code == 20) return 'Wing in ground (WIG), all ships of this type'; |
|
273 | - elseif ($code == 21) return 'Wing in ground (WIG), Hazardous category A'; |
|
274 | - elseif ($code == 22) return 'Wing in ground (WIG), Hazardous category B'; |
|
275 | - elseif ($code == 23) return 'Wing in ground (WIG), Hazardous category C'; |
|
276 | - elseif ($code == 24) return 'Wing in ground (WIG), Hazardous category D'; |
|
277 | - elseif ($code == 25) return 'Wing in ground (WIG), Reserved for future use'; |
|
278 | - elseif ($code == 26) return 'Wing in ground (WIG), Reserved for future use'; |
|
279 | - elseif ($code == 27) return 'Wing in ground (WIG), Reserved for future use'; |
|
280 | - elseif ($code == 28) return 'Wing in ground (WIG), Reserved for future use'; |
|
281 | - elseif ($code == 29) return 'Wing in ground (WIG), Reserved for future use'; |
|
282 | - elseif ($code == 30) return 'Fishing'; |
|
283 | - elseif ($code == 31) return 'Towing'; |
|
284 | - elseif ($code == 32) return 'Towing: length exceeds 200m or breadth exceeds 25m'; |
|
285 | - elseif ($code == 33) return 'Dredging or underwater ops'; |
|
286 | - elseif ($code == 34) return 'Diving ops'; |
|
287 | - elseif ($code == 35) return 'Military ops'; |
|
288 | - elseif ($code == 36) return 'Sailing'; |
|
289 | - elseif ($code == 37) return 'Pleasure Craft'; |
|
290 | - elseif ($code == 38) return 'Reserved'; |
|
291 | - elseif ($code == 39) return 'Reserved'; |
|
292 | - elseif ($code == 40) return 'High speed craft (HSC), all ships of this type'; |
|
293 | - elseif ($code == 41) return 'High speed craft (HSC), Hazardous category A'; |
|
294 | - elseif ($code == 42) return 'High speed craft (HSC), Hazardous category B'; |
|
295 | - elseif ($code == 43) return 'High speed craft (HSC), Hazardous category C'; |
|
296 | - elseif ($code == 44) return 'High speed craft (HSC), Hazardous category D'; |
|
297 | - elseif ($code == 45) return 'High speed craft (HSC), Reserved for future use'; |
|
298 | - elseif ($code == 46) return 'High speed craft (HSC), Reserved for future use'; |
|
299 | - elseif ($code == 47) return 'High speed craft (HSC), Reserved for future use'; |
|
300 | - elseif ($code == 48) return 'High speed craft (HSC), Reserved for future use'; |
|
301 | - elseif ($code == 49) return 'High speed craft (HSC), No additional information'; |
|
302 | - elseif ($code == 50) return 'Pilot Vessel'; |
|
303 | - elseif ($code == 51) return 'Search and Rescue vessel'; |
|
304 | - elseif ($code == 52) return 'Tug'; |
|
305 | - elseif ($code == 53) return 'Port Tender'; |
|
306 | - elseif ($code == 54) return 'Anti-pollution equipment'; |
|
307 | - elseif ($code == 55) return 'Law Enforcement'; |
|
308 | - elseif ($code == 56) return 'Spare - Local Vessel'; |
|
309 | - elseif ($code == 57) return 'Spare - Local Vessel'; |
|
310 | - elseif ($code == 58) return 'Medical Transport'; |
|
311 | - elseif ($code == 59) return 'Noncombatant ship according to RR Resolution No. 18'; |
|
312 | - elseif ($code == 60) return 'Passenger, all ships of this type'; |
|
313 | - elseif ($code == 61) return 'Passenger, Hazardous category A'; |
|
314 | - elseif ($code == 62) return 'Passenger, Hazardous category B'; |
|
315 | - elseif ($code == 63) return 'Passenger, Hazardous category C'; |
|
316 | - elseif ($code == 64) return 'Passenger, Hazardous category D'; |
|
317 | - elseif ($code == 65) return 'Passenger, Reserved for future use'; |
|
318 | - elseif ($code == 66) return 'Passenger, Reserved for future use'; |
|
319 | - elseif ($code == 67) return 'Passenger, Reserved for future use'; |
|
320 | - elseif ($code == 68) return 'Passenger, Reserved for future use'; |
|
321 | - elseif ($code == 69) return 'Passenger, No additional information'; |
|
322 | - elseif ($code == 70) return 'Cargo, all ships of this type'; |
|
323 | - elseif ($code == 71) return 'Cargo, Hazardous category A'; |
|
324 | - elseif ($code == 72) return 'Cargo, Hazardous category B'; |
|
325 | - elseif ($code == 73) return 'Cargo, Hazardous category C'; |
|
326 | - elseif ($code == 74) return 'Cargo, Hazardous category D'; |
|
327 | - elseif ($code == 75) return 'Cargo, Reserved for future use'; |
|
328 | - elseif ($code == 76) return 'Cargo, Reserved for future use'; |
|
329 | - elseif ($code == 77) return 'Cargo, Reserved for future use'; |
|
330 | - elseif ($code == 78) return 'Cargo, Reserved for future use'; |
|
331 | - elseif ($code == 79) return 'Cargo, No additional information'; |
|
332 | - elseif ($code == 80) return 'Tanker, all ships of this type'; |
|
333 | - elseif ($code == 81) return 'Tanker, Hazardous category A'; |
|
334 | - elseif ($code == 82) return 'Tanker, Hazardous category B'; |
|
335 | - elseif ($code == 83) return 'Tanker, Hazardous category C'; |
|
336 | - elseif ($code == 84) return 'Tanker, Hazardous category D'; |
|
337 | - elseif ($code == 85) return 'Tanker, Reserved for future use'; |
|
338 | - elseif ($code == 86) return 'Tanker, Reserved for future use'; |
|
339 | - elseif ($code == 87) return 'Tanker, Reserved for future use'; |
|
340 | - elseif ($code == 88) return 'Tanker, Reserved for future use'; |
|
341 | - elseif ($code == 89) return 'Tanker, No additional information'; |
|
342 | - elseif ($code == 90) return 'Other Type, all ships of this type'; |
|
343 | - elseif ($code == 91) return 'Other Type, Hazardous category A'; |
|
344 | - elseif ($code == 92) return 'Other Type, Hazardous category B'; |
|
345 | - elseif ($code == 93) return 'Other Type, Hazardous category C'; |
|
346 | - elseif ($code == 94) return 'Other Type, Hazardous category D'; |
|
347 | - elseif ($code == 95) return 'Other Type, Reserved for future use'; |
|
348 | - elseif ($code == 96) return 'Other Type, Reserved for future use'; |
|
349 | - elseif ($code == 97) return 'Other Type, Reserved for future use'; |
|
350 | - elseif ($code == 98) return 'Other Type, Reserved for future use'; |
|
351 | - elseif ($code == 99) return 'Other Type, no additional information'; |
|
280 | + if ($code == 0) { |
|
281 | + return 'Not available (default)'; |
|
282 | + } elseif ($code >= 1 && $code <= 19) { |
|
283 | + return 'Reserved for future use'; |
|
284 | + } elseif ($code == 20) { |
|
285 | + return 'Wing in ground (WIG), all ships of this type'; |
|
286 | + } elseif ($code == 21) { |
|
287 | + return 'Wing in ground (WIG), Hazardous category A'; |
|
288 | + } elseif ($code == 22) { |
|
289 | + return 'Wing in ground (WIG), Hazardous category B'; |
|
290 | + } elseif ($code == 23) { |
|
291 | + return 'Wing in ground (WIG), Hazardous category C'; |
|
292 | + } elseif ($code == 24) { |
|
293 | + return 'Wing in ground (WIG), Hazardous category D'; |
|
294 | + } elseif ($code == 25) { |
|
295 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
296 | + } elseif ($code == 26) { |
|
297 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
298 | + } elseif ($code == 27) { |
|
299 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
300 | + } elseif ($code == 28) { |
|
301 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
302 | + } elseif ($code == 29) { |
|
303 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
304 | + } elseif ($code == 30) { |
|
305 | + return 'Fishing'; |
|
306 | + } elseif ($code == 31) { |
|
307 | + return 'Towing'; |
|
308 | + } elseif ($code == 32) { |
|
309 | + return 'Towing: length exceeds 200m or breadth exceeds 25m'; |
|
310 | + } elseif ($code == 33) { |
|
311 | + return 'Dredging or underwater ops'; |
|
312 | + } elseif ($code == 34) { |
|
313 | + return 'Diving ops'; |
|
314 | + } elseif ($code == 35) { |
|
315 | + return 'Military ops'; |
|
316 | + } elseif ($code == 36) { |
|
317 | + return 'Sailing'; |
|
318 | + } elseif ($code == 37) { |
|
319 | + return 'Pleasure Craft'; |
|
320 | + } elseif ($code == 38) { |
|
321 | + return 'Reserved'; |
|
322 | + } elseif ($code == 39) { |
|
323 | + return 'Reserved'; |
|
324 | + } elseif ($code == 40) { |
|
325 | + return 'High speed craft (HSC), all ships of this type'; |
|
326 | + } elseif ($code == 41) { |
|
327 | + return 'High speed craft (HSC), Hazardous category A'; |
|
328 | + } elseif ($code == 42) { |
|
329 | + return 'High speed craft (HSC), Hazardous category B'; |
|
330 | + } elseif ($code == 43) { |
|
331 | + return 'High speed craft (HSC), Hazardous category C'; |
|
332 | + } elseif ($code == 44) { |
|
333 | + return 'High speed craft (HSC), Hazardous category D'; |
|
334 | + } elseif ($code == 45) { |
|
335 | + return 'High speed craft (HSC), Reserved for future use'; |
|
336 | + } elseif ($code == 46) { |
|
337 | + return 'High speed craft (HSC), Reserved for future use'; |
|
338 | + } elseif ($code == 47) { |
|
339 | + return 'High speed craft (HSC), Reserved for future use'; |
|
340 | + } elseif ($code == 48) { |
|
341 | + return 'High speed craft (HSC), Reserved for future use'; |
|
342 | + } elseif ($code == 49) { |
|
343 | + return 'High speed craft (HSC), No additional information'; |
|
344 | + } elseif ($code == 50) { |
|
345 | + return 'Pilot Vessel'; |
|
346 | + } elseif ($code == 51) { |
|
347 | + return 'Search and Rescue vessel'; |
|
348 | + } elseif ($code == 52) { |
|
349 | + return 'Tug'; |
|
350 | + } elseif ($code == 53) { |
|
351 | + return 'Port Tender'; |
|
352 | + } elseif ($code == 54) { |
|
353 | + return 'Anti-pollution equipment'; |
|
354 | + } elseif ($code == 55) { |
|
355 | + return 'Law Enforcement'; |
|
356 | + } elseif ($code == 56) { |
|
357 | + return 'Spare - Local Vessel'; |
|
358 | + } elseif ($code == 57) { |
|
359 | + return 'Spare - Local Vessel'; |
|
360 | + } elseif ($code == 58) { |
|
361 | + return 'Medical Transport'; |
|
362 | + } elseif ($code == 59) { |
|
363 | + return 'Noncombatant ship according to RR Resolution No. 18'; |
|
364 | + } elseif ($code == 60) { |
|
365 | + return 'Passenger, all ships of this type'; |
|
366 | + } elseif ($code == 61) { |
|
367 | + return 'Passenger, Hazardous category A'; |
|
368 | + } elseif ($code == 62) { |
|
369 | + return 'Passenger, Hazardous category B'; |
|
370 | + } elseif ($code == 63) { |
|
371 | + return 'Passenger, Hazardous category C'; |
|
372 | + } elseif ($code == 64) { |
|
373 | + return 'Passenger, Hazardous category D'; |
|
374 | + } elseif ($code == 65) { |
|
375 | + return 'Passenger, Reserved for future use'; |
|
376 | + } elseif ($code == 66) { |
|
377 | + return 'Passenger, Reserved for future use'; |
|
378 | + } elseif ($code == 67) { |
|
379 | + return 'Passenger, Reserved for future use'; |
|
380 | + } elseif ($code == 68) { |
|
381 | + return 'Passenger, Reserved for future use'; |
|
382 | + } elseif ($code == 69) { |
|
383 | + return 'Passenger, No additional information'; |
|
384 | + } elseif ($code == 70) { |
|
385 | + return 'Cargo, all ships of this type'; |
|
386 | + } elseif ($code == 71) { |
|
387 | + return 'Cargo, Hazardous category A'; |
|
388 | + } elseif ($code == 72) { |
|
389 | + return 'Cargo, Hazardous category B'; |
|
390 | + } elseif ($code == 73) { |
|
391 | + return 'Cargo, Hazardous category C'; |
|
392 | + } elseif ($code == 74) { |
|
393 | + return 'Cargo, Hazardous category D'; |
|
394 | + } elseif ($code == 75) { |
|
395 | + return 'Cargo, Reserved for future use'; |
|
396 | + } elseif ($code == 76) { |
|
397 | + return 'Cargo, Reserved for future use'; |
|
398 | + } elseif ($code == 77) { |
|
399 | + return 'Cargo, Reserved for future use'; |
|
400 | + } elseif ($code == 78) { |
|
401 | + return 'Cargo, Reserved for future use'; |
|
402 | + } elseif ($code == 79) { |
|
403 | + return 'Cargo, No additional information'; |
|
404 | + } elseif ($code == 80) { |
|
405 | + return 'Tanker, all ships of this type'; |
|
406 | + } elseif ($code == 81) { |
|
407 | + return 'Tanker, Hazardous category A'; |
|
408 | + } elseif ($code == 82) { |
|
409 | + return 'Tanker, Hazardous category B'; |
|
410 | + } elseif ($code == 83) { |
|
411 | + return 'Tanker, Hazardous category C'; |
|
412 | + } elseif ($code == 84) { |
|
413 | + return 'Tanker, Hazardous category D'; |
|
414 | + } elseif ($code == 85) { |
|
415 | + return 'Tanker, Reserved for future use'; |
|
416 | + } elseif ($code == 86) { |
|
417 | + return 'Tanker, Reserved for future use'; |
|
418 | + } elseif ($code == 87) { |
|
419 | + return 'Tanker, Reserved for future use'; |
|
420 | + } elseif ($code == 88) { |
|
421 | + return 'Tanker, Reserved for future use'; |
|
422 | + } elseif ($code == 89) { |
|
423 | + return 'Tanker, No additional information'; |
|
424 | + } elseif ($code == 90) { |
|
425 | + return 'Other Type, all ships of this type'; |
|
426 | + } elseif ($code == 91) { |
|
427 | + return 'Other Type, Hazardous category A'; |
|
428 | + } elseif ($code == 92) { |
|
429 | + return 'Other Type, Hazardous category B'; |
|
430 | + } elseif ($code == 93) { |
|
431 | + return 'Other Type, Hazardous category C'; |
|
432 | + } elseif ($code == 94) { |
|
433 | + return 'Other Type, Hazardous category D'; |
|
434 | + } elseif ($code == 95) { |
|
435 | + return 'Other Type, Reserved for future use'; |
|
436 | + } elseif ($code == 96) { |
|
437 | + return 'Other Type, Reserved for future use'; |
|
438 | + } elseif ($code == 97) { |
|
439 | + return 'Other Type, Reserved for future use'; |
|
440 | + } elseif ($code == 98) { |
|
441 | + return 'Other Type, Reserved for future use'; |
|
442 | + } elseif ($code == 99) { |
|
443 | + return 'Other Type, no additional information'; |
|
444 | + } |
|
352 | 445 | } |
353 | 446 | |
354 | 447 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
@@ -386,19 +479,34 @@ discard block |
||
386 | 479 | // assume 1st ! is valid |
387 | 480 | // find * ensure that it is at correct position |
388 | 481 | $end = strrpos ( $rawdata , '*' ); |
389 | - if ($end === FALSE) return -1; // check for NULLS!!! |
|
482 | + if ($end === FALSE) { |
|
483 | + return -1; |
|
484 | + } |
|
485 | + // check for NULLS!!! |
|
390 | 486 | $cs = substr( $rawdata, $end + 1 ); |
391 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
487 | + if ( strlen($cs) != 2 ) { |
|
488 | + return -1; |
|
489 | + } |
|
490 | + // correct cs length |
|
392 | 491 | $dcs = (int)hexdec( $cs ); |
393 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
492 | + for ( $alias=1; $alias<$end; $alias++) { |
|
493 | + $chksum ^= ord( $rawdata[$alias] ); |
|
494 | + } |
|
495 | + // perform XOR for NMEA checksum |
|
394 | 496 | if ( $chksum == $dcs ) { // NMEA checksum pass |
395 | 497 | $pcs = explode(',', $rawdata); |
396 | 498 | // !AI??? identifier |
397 | 499 | $num_seq = (int)$pcs[1]; // number of sequences |
398 | 500 | $seq = (int)$pcs[2]; // get sequence |
399 | 501 | // get msg sequence id |
400 | - if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
|
401 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
502 | + if ($pcs[3] == '') { |
|
503 | + $msg_sid = -1; |
|
504 | + } |
|
505 | + // non-multipart message, set to -1 |
|
506 | + else { |
|
507 | + $msg_sid = (int)$pcs[3]; |
|
508 | + } |
|
509 | + // multipart message |
|
402 | 510 | $ais_ch = $pcs[4]; // get AIS channel |
403 | 511 | // message sequence checking |
404 | 512 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -459,10 +567,18 @@ discard block |
||
459 | 567 | //DEBUG echo "[$start $end $tst]\n"; |
460 | 568 | $result = $this->process_ais_raw( $tst, "" ); |
461 | 569 | $last_pos = $end + 1; |
462 | - } else break; |
|
570 | + } else { |
|
571 | + break; |
|
572 | + } |
|
573 | + } |
|
574 | + if ($last_pos > 0) { |
|
575 | + $cbuf = substr($cbuf, $last_pos); |
|
463 | 576 | } |
464 | - if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move... |
|
465 | - if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode... |
|
577 | + // move... |
|
578 | + if (strlen($cbuf) > 1024) { |
|
579 | + $cbuf = ""; |
|
580 | + } |
|
581 | + // prevent overflow simple mode... |
|
466 | 582 | return $result; |
467 | 583 | } |
468 | 584 | |
@@ -482,7 +598,9 @@ discard block |
||
482 | 598 | if ($lat<0.0) { |
483 | 599 | $lat = -$lat; |
484 | 600 | $neg=true; |
485 | - } else $neg=false; |
|
601 | + } else { |
|
602 | + $neg=false; |
|
603 | + } |
|
486 | 604 | $latd = 0x00000000; |
487 | 605 | $latd = intval ($lat * 600000.0); |
488 | 606 | if ($neg==true) { |
@@ -498,7 +616,9 @@ discard block |
||
498 | 616 | if ($lon<0.0) { |
499 | 617 | $lon = -$lon; |
500 | 618 | $neg=true; |
501 | - } else $neg=false; |
|
619 | + } else { |
|
620 | + $neg=false; |
|
621 | + } |
|
502 | 622 | $lond = 0x00000000; |
503 | 623 | $lond = intval ($lon * 600000.0); |
504 | 624 | if ($neg==true) { |
@@ -511,9 +631,14 @@ discard block |
||
511 | 631 | |
512 | 632 | private function char2bin($name, $max_len) { |
513 | 633 | $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); |
|
516 | - else $pad = ''; |
|
634 | + if ($len > $max_len) { |
|
635 | + $name = substr($name,0,$max_len); |
|
636 | + } |
|
637 | + if ($len < $max_len) { |
|
638 | + $pad = str_repeat('0', ($max_len - $len) * 6); |
|
639 | + } else { |
|
640 | + $pad = ''; |
|
641 | + } |
|
517 | 642 | $rv = ''; |
518 | 643 | $ais_chars = array( |
519 | 644 | '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
@@ -526,9 +651,12 @@ discard block |
||
526 | 651 | ); |
527 | 652 | // " |
528 | 653 | $_a = str_split($name); |
529 | - if ($_a) foreach ($_a as $_1) { |
|
654 | + if ($_a) { |
|
655 | + foreach ($_a as $_1) { |
|
530 | 656 | if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
531 | - else $dec = 0; |
|
657 | + } else { |
|
658 | + $dec = 0; |
|
659 | + } |
|
532 | 660 | $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
533 | 661 | $rv .= $bin; |
534 | 662 | //echo "$_1 $dec ($bin)<br/>"; |
@@ -540,7 +668,9 @@ discard block |
||
540 | 668 | $len_bit = strlen($_enc); |
541 | 669 | $rem6 = $len_bit % 6; |
542 | 670 | $pad6_len = 0; |
543 | - if ($rem6) $pad6_len = 6 - $rem6; |
|
671 | + if ($rem6) { |
|
672 | + $pad6_len = 6 - $rem6; |
|
673 | + } |
|
544 | 674 | //echo $pad6_len.'<br>'; |
545 | 675 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
546 | 676 | $len_enc = strlen($_enc) / 6; |
@@ -549,8 +679,11 @@ discard block |
||
549 | 679 | for ($i=0; $i<$len_enc; $i++) { |
550 | 680 | $offset = $i * 6; |
551 | 681 | $dec = bindec(substr($_enc,$offset,6)); |
552 | - if ($dec < 40) $dec += 48; |
|
553 | - else $dec += 56; |
|
682 | + if ($dec < 40) { |
|
683 | + $dec += 48; |
|
684 | + } else { |
|
685 | + $dec += 56; |
|
686 | + } |
|
554 | 687 | //echo chr($dec)." $dec<br/>"; |
555 | 688 | $itu .= chr($dec); |
556 | 689 | } |
@@ -563,25 +696,41 @@ discard block |
||
563 | 696 | } |
564 | 697 | $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
565 | 698 | $lsb = $chksum & 0x0F; |
566 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
567 | - else $lsbc = '0'; |
|
699 | + if ($lsb >=0 && $lsb <= 15 ) { |
|
700 | + $lsbc = $hex_arr[$lsb]; |
|
701 | + } else { |
|
702 | + $lsbc = '0'; |
|
703 | + } |
|
568 | 704 | $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
569 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
570 | - else $msbc = '0'; |
|
705 | + if ($msb >=0 && $msb <= 15 ) { |
|
706 | + $msbc = $hex_arr[$msb]; |
|
707 | + } else { |
|
708 | + $msbc = '0'; |
|
709 | + } |
|
571 | 710 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
572 | 711 | return $itu; |
573 | 712 | } |
574 | 713 | |
575 | 714 | public function parse($buffer) { |
576 | 715 | $data = $this->process_ais_buf($buffer); |
577 | - if (!is_object($data)) return array(); |
|
578 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
579 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
716 | + if (!is_object($data)) { |
|
717 | + return array(); |
|
718 | + } |
|
719 | + if ($data->lon != 0) { |
|
720 | + $result['longitude'] = $data->lon; |
|
721 | + } |
|
722 | + if ($data->lat != 0) { |
|
723 | + $result['latitude'] = $data->lat; |
|
724 | + } |
|
580 | 725 | $result['ident'] = trim($data->name); |
581 | 726 | $result['timestamp'] = $data->ts; |
582 | 727 | $result['mmsi'] = $data->mmsi; |
583 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
584 | - if ($data->cog != 0) $result['heading'] = $data->cog; |
|
728 | + if ($data->sog != -1.0) { |
|
729 | + $result['speed'] = $data->sog; |
|
730 | + } |
|
731 | + if ($data->cog != 0) { |
|
732 | + $result['heading'] = $data->cog; |
|
733 | + } |
|
585 | 734 | /* |
586 | 735 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |
587 | 736 | $ro->id = bindec(substr($_aisdata,0,6)); |
@@ -591,15 +740,25 @@ discard block |
||
591 | 740 | |
592 | 741 | public function mmsitype($mmsi) { |
593 | 742 | 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'; |
|
602 | - else return 'Ship'; |
|
743 | + if (substr($mmsi,0,3) == '974') { |
|
744 | + return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
745 | + } elseif (substr($mmsi,0,3) == '972') { |
|
746 | + return 'MOB (Man Overboard) device'; |
|
747 | + } elseif (substr($mmsi,0,3) == '970') { |
|
748 | + return 'AIS SART (Search and Rescue Transmitter)'; |
|
749 | + } elseif (substr($mmsi,0,3) == '111') { |
|
750 | + return 'SAR (Search and Rescue) aircraft'; |
|
751 | + } elseif (substr($mmsi,0,2) == '98') { |
|
752 | + return 'Auxiliary craft associated with a parent ship'; |
|
753 | + } elseif (substr($mmsi,0,2) == '99') { |
|
754 | + return 'Aids to Navigation'; |
|
755 | + } elseif (substr($mmsi,0,2) == '00') { |
|
756 | + return 'Coastal stations'; |
|
757 | + } elseif (substr($mmsi,0,1) == '0') { |
|
758 | + return 'Group of ships'; |
|
759 | + } else { |
|
760 | + return 'Ship'; |
|
761 | + } |
|
603 | 762 | } |
604 | 763 | |
605 | 764 | |
@@ -616,25 +775,48 @@ discard block |
||
616 | 775 | //if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n"; |
617 | 776 | return array(); |
618 | 777 | } |
619 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
620 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
778 | + if ($data->lon != 0) { |
|
779 | + $result['longitude'] = $data->lon; |
|
780 | + } |
|
781 | + if ($data->lat != 0) { |
|
782 | + $result['latitude'] = $data->lat; |
|
783 | + } |
|
621 | 784 | $result['ident'] = trim(str_replace('@','',$data->name)); |
622 | 785 | $result['timestamp'] = $data->ts; |
623 | 786 | $result['mmsi'] = $data->mmsi; |
624 | - if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
787 | + if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') { |
|
788 | + $result['mmsi'] = '3'.$result['mmsi']; |
|
789 | + } |
|
625 | 790 | $result['mmsi_type'] = $this->mmsitype($result['mmsi']); |
626 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
627 | - if ($data->heading != '') $result['heading'] = $data->heading; |
|
628 | - elseif ($data->cog != 0) $result['heading'] = $data->cog; |
|
629 | - if ($data->status != '') $result['status'] = $data->status; |
|
630 | - if ($data->type != '') $result['type'] = $data->type; |
|
631 | - if ($data->typeid != '') $result['typeid'] = $data->typeid; |
|
632 | - if ($data->imo != '') $result['imo'] = $data->imo; |
|
633 | - if ($data->callsign != '') $result['callsign'] = $data->callsign; |
|
791 | + if ($data->sog != -1.0) { |
|
792 | + $result['speed'] = $data->sog; |
|
793 | + } |
|
794 | + if ($data->heading != '') { |
|
795 | + $result['heading'] = $data->heading; |
|
796 | + } elseif ($data->cog != 0) { |
|
797 | + $result['heading'] = $data->cog; |
|
798 | + } |
|
799 | + if ($data->status != '') { |
|
800 | + $result['status'] = $data->status; |
|
801 | + } |
|
802 | + if ($data->type != '') { |
|
803 | + $result['type'] = $data->type; |
|
804 | + } |
|
805 | + if ($data->typeid != '') { |
|
806 | + $result['typeid'] = $data->typeid; |
|
807 | + } |
|
808 | + if ($data->imo != '') { |
|
809 | + $result['imo'] = $data->imo; |
|
810 | + } |
|
811 | + if ($data->callsign != '') { |
|
812 | + $result['callsign'] = $data->callsign; |
|
813 | + } |
|
634 | 814 | if ($data->eta_month != '' && $data->eta_day != '' && $data->eta_hour != '' && $data->eta_minute != '') { |
635 | 815 | $result['eta_ts'] = strtotime(date('Y').'-'.$data->eta_month.'-'.$data->eta_day.' '.$data->eta_hour.':'.$data->eta_minute.':00'); |
636 | 816 | } |
637 | - if ($data->destination != '') $result['destination'] = $data->destination; |
|
817 | + if ($data->destination != '') { |
|
818 | + $result['destination'] = $data->destination; |
|
819 | + } |
|
638 | 820 | $result['all'] = (array) $data; |
639 | 821 | /* |
640 | 822 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |