Completed
Push — master ( 0f8d98...73aa54 )
by Yannick
35:19
created
require/class.AIS.php 3 patches
Doc Comments   +25 added lines patch added patch discarded remove patch
@@ -68,6 +68,10 @@  discard block
 block discarded – undo
68 68
        't', 'u', 'v', 'w' // 119
69 69
     ); // char 64
70 70
     */
71
+
72
+	/**
73
+	 * @param integer $ascii
74
+	 */
71 75
 	private function asciidec_2_8bit($ascii) {
72 76
 		//only process in the following range: 48-87, 96-119
73 77
 		if ($ascii < 48) { }
@@ -93,6 +97,10 @@  discard block
 block discarded – undo
93 97
 		return(substr($bin, -6)); 
94 98
 	}
95 99
 
100
+	/**
101
+	 * @param integer $_start
102
+	 * @param integer $_size
103
+	 */
96 104
 	private function binchar($_str, $_start, $_size) {
97 105
 		//  ' ' --- '?', // 0x20 - 0x3F
98 106
 		//  '@' --- '_', // 0x40 - 0x5F
@@ -118,6 +126,10 @@  discard block
 block discarded – undo
118 126
 	}
119 127
 
120 128
 	// function for decoding the AIS Message ITU Payload
129
+
130
+	/**
131
+	 * @param string $_aisdata
132
+	 */
121 133
 	private function decode_ais($_aisdata) {
122 134
 		$ro = new stdClass(); // return object
123 135
 		$ro->cls = 0; // AIS class undefined, also indicate unparsed msg
@@ -351,6 +363,12 @@  discard block
 block discarded – undo
351 363
 		elseif ($code == 99) return 'Other Type, no additional information';
352 364
 	}
353 365
 
366
+	/**
367
+	 * @param string $_itu
368
+	 * @param integer $_len
369
+	 * @param integer $_filler
370
+	 * @param string $aux
371
+	 */
354 372
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
355 373
 		global $port; // tcpip port...
356 374
 		
@@ -371,6 +389,10 @@  discard block
 block discarded – undo
371 389
 
372 390
 	// char* - AIS \r terminated string
373 391
 	// TCP based streams which send messages in full can use this instead of calling process_ais_buf
392
+
393
+	/**
394
+	 * @param string $rawdata
395
+	 */
374 396
 	public function process_ais_raw($rawdata, $aux = '') { // return int
375 397
 		static $num_seq; // 1 to 9
376 398
 		static $seq; // 1 to 9
@@ -589,6 +611,9 @@  discard block
 block discarded – undo
589 611
 		return $result;
590 612
 	}
591 613
 
614
+	/**
615
+	 * @param string $mmsi
616
+	 */
592 617
 	public function mmsitype($mmsi) {
593 618
 		if (strlen($mmsi) == 9) {
594 619
 			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
Please login to merge, or discard this patch.
Spacing   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -29,31 +29,31 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,24 +385,24 @@  discard block
 block discarded – undo
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 397
 			if (!isset($pcs[1])) {
398 398
 				echo "ERROR,INVALID_DATA ".time()." $rawdata\n";
399 399
 				return -1;
400 400
 			}
401
-			$num_seq = (int)$pcs[1]; // number of sequences
402
-			$seq = (int)$pcs[2]; // get sequence
401
+			$num_seq = (int) $pcs[1]; // number of sequences
402
+			$seq = (int) $pcs[2]; // get sequence
403 403
 			// get msg sequence id
404 404
 			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
405
-			else $msg_sid = (int)$pcs[3]; // multipart message
405
+			else $msg_sid = (int) $pcs[3]; // multipart message
406 406
 			$ais_ch = $pcs[4]; // get AIS channel
407 407
 			// message sequence checking
408 408
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 					}
436 436
 				}
437 437
 				$itu = $itu.$pcs[5]; // get itu message
438
-				$filler += (int)$pcs[6][0]; // get filler
438
+				$filler += (int) $pcs[6][0]; // get filler
439 439
 				if ($num_seq == 1 // valid single message
440 440
 				    || $num_seq == $pseq // valid multi-part message
441 441
 				) {
@@ -455,13 +455,13 @@  discard block
 block discarded – undo
455 455
 		$cbuf = $cbuf.$ibuf;
456 456
 		$last_pos = 0;
457 457
 		$result = new stdClass();
458
-		while ( ($start = strpos($cbuf,"VDM",$last_pos)) !== FALSE) {
458
+		while (($start = strpos($cbuf, "VDM", $last_pos)) !== FALSE) {
459 459
 		//while ( ($start = strpos($cbuf,"!AI",$last_pos)) !== FALSE) {
460 460
 			//DEBUG echo $cbuf;
461
-			if ( ($end = strpos($cbuf,"\r\n", $start)) !== FALSE) { //TBD need to trim?
461
+			if (($end = strpos($cbuf, "\r\n", $start)) !== FALSE) { //TBD need to trim?
462 462
 				$tst = substr($cbuf, $start - 3, ($end - $start + 3));
463 463
 				//DEBUG echo "[$start $end $tst]\n";
464
-				$result = $this->process_ais_raw( $tst, "" );
464
+				$result = $this->process_ais_raw($tst, "");
465 465
 				$last_pos = $end + 1;
466 466
 			} else break;
467 467
 		}
@@ -473,41 +473,41 @@  discard block
 block discarded – undo
473 473
 	// incoming data from serial or IP comms
474 474
 	public function process_ais_line($cbuf) {
475 475
 		$result = new stdClass();
476
-		$start = strpos($cbuf,"VDM");
476
+		$start = strpos($cbuf, "VDM");
477 477
 		$tst = substr($cbuf, $start - 3);
478
-		$result = $this->process_ais_raw( $tst, "" );
478
+		$result = $this->process_ais_raw($tst, "");
479 479
 		return $result;
480 480
 	}
481 481
 
482 482
 	/* AIS Encoding
483 483
 	*/
484
-	private function mk_ais_lat( $lat ) {
484
+	private function mk_ais_lat($lat) {
485 485
 		//$lat = 1.2569;
486
-		if ($lat<0.0) {
486
+		if ($lat < 0.0) {
487 487
 			$lat = -$lat;
488
-			$neg=true;
489
-		} else $neg=false;
488
+			$neg = true;
489
+		} else $neg = false;
490 490
 		$latd = 0x00000000;
491
-		$latd = intval ($lat * 600000.0);
492
-		if ($neg==true) {
491
+		$latd = intval($lat*600000.0);
492
+		if ($neg == true) {
493 493
 			$latd = ~$latd;
494
-			$latd+=1;
494
+			$latd += 1;
495 495
 			$latd &= 0x07FFFFFF;
496 496
 		}
497 497
 		return $latd;
498 498
 	}
499 499
 
500
-	private function mk_ais_lon( $lon ) {
500
+	private function mk_ais_lon($lon) {
501 501
 		//$lon = 103.851;
502
-		if ($lon<0.0) {
502
+		if ($lon < 0.0) {
503 503
 			$lon = -$lon;
504
-			$neg=true;
505
-		} else $neg=false;
504
+			$neg = true;
505
+		} else $neg = false;
506 506
 		$lond = 0x00000000;
507
-		$lond = intval ($lon * 600000.0);
508
-		if ($neg==true) {
507
+		$lond = intval($lon*600000.0);
508
+		if ($neg == true) {
509 509
 			$lond = ~$lond;
510
-			$lond+=1;
510
+			$lond += 1;
511 511
 			$lond &= 0x0FFFFFFF;
512 512
 		}
513 513
 		return $lond;
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
 
516 516
 	private function char2bin($name, $max_len) {
517 517
 		$len = strlen($name);
518
-		if ($len > $max_len) $name = substr($name,0,$max_len);
519
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
518
+		if ($len > $max_len) $name = substr($name, 0, $max_len);
519
+		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len)*6);
520 520
 		else $pad = '';
521 521
 		$rv = '';
522 522
 		$ais_chars = array(
@@ -533,26 +533,26 @@  discard block
 block discarded – undo
533 533
 		if ($_a) foreach ($_a as $_1) {
534 534
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
535 535
 			else $dec = 0;
536
-			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
536
+			$bin = str_pad(decbin($dec), 6, '0', STR_PAD_LEFT);
537 537
 			$rv .= $bin;
538 538
 			//echo "$_1 $dec ($bin)<br/>";
539 539
 		}
540 540
 		return $rv.$pad;
541 541
 	}
542 542
 
543
-	private function mk_ais($_enc, $_part=1,$_total=1,$_seq='',$_ch='A') {
543
+	private function mk_ais($_enc, $_part = 1, $_total = 1, $_seq = '', $_ch = 'A') {
544 544
 		$len_bit = strlen($_enc);
545
-		$rem6 = $len_bit % 6;
545
+		$rem6 = $len_bit%6;
546 546
 		$pad6_len = 0;
547 547
 		if ($rem6) $pad6_len = 6 - $rem6;
548 548
 		//echo  $pad6_len.'<br>';
549 549
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
550
-		$len_enc = strlen($_enc) / 6;
550
+		$len_enc = strlen($_enc)/6;
551 551
 		//echo $_enc.' '.$len_enc.'<br/>';
552 552
 		$itu = '';
553
-		for ($i=0; $i<$len_enc; $i++) {
554
-			$offset = $i * 6;
555
-			$dec = bindec(substr($_enc,$offset,6));
553
+		for ($i = 0; $i < $len_enc; $i++) {
554
+			$offset = $i*6;
555
+			$dec = bindec(substr($_enc, $offset, 6));
556 556
 			if ($dec < 40) $dec += 48;
557 557
 			else $dec += 56;
558 558
 			//echo chr($dec)." $dec<br/>";
@@ -562,15 +562,15 @@  discard block
 block discarded – undo
562 562
 		$chksum = 0;
563 563
 		$itu = "AIVDM,$_part,$_total,$_seq,$_ch,".$itu.",0";
564 564
 		$len_itu = strlen($itu);
565
-		for ($i=0; $i<$len_itu; $i++) {
566
-			$chksum ^= ord( $itu[$i] );
565
+		for ($i = 0; $i < $len_itu; $i++) {
566
+			$chksum ^= ord($itu[$i]);
567 567
 		}
568
-		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
569
-		$lsb = $chksum & 0x0F;
570
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
568
+		$hex_arr = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
569
+		$lsb = $chksum&0x0F;
570
+		if ($lsb >= 0 && $lsb <= 15) $lsbc = $hex_arr[$lsb];
571 571
 		else $lsbc = '0';
572
-		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
573
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
572
+		$msb = (($chksum&0xF0) >> 4)&0x0F;
573
+		if ($msb >= 0 && $msb <= 15) $msbc = $hex_arr[$msb];
574 574
 		else $msbc = '0';
575 575
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
576 576
 		return $itu;
@@ -595,14 +595,14 @@  discard block
 block discarded – undo
595 595
 
596 596
 	public function mmsitype($mmsi) {
597 597
 		if (strlen($mmsi) == 9) {
598
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
599
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
600
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
601
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
602
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
603
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
604
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
605
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
598
+			if (substr($mmsi, 0, 3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
599
+			elseif (substr($mmsi, 0, 3) == '972') return 'MOB (Man Overboard) device';
600
+			elseif (substr($mmsi, 0, 3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
601
+			elseif (substr($mmsi, 0, 3) == '111') return 'SAR (Search and Rescue) aircraft';
602
+			elseif (substr($mmsi, 0, 2) == '98') return 'Auxiliary craft associated with a parent ship';
603
+			elseif (substr($mmsi, 0, 2) == '99') return 'Aids to Navigation';
604
+			elseif (substr($mmsi, 0, 2) == '00') return 'Coastal stations';
605
+			elseif (substr($mmsi, 0, 1) == '0') return 'Group of ships';
606 606
 			else return 'Ship';
607 607
 		}
608 608
 
@@ -613,19 +613,19 @@  discard block
 block discarded – undo
613 613
 		global $globalDebug;
614 614
 		$result = array();
615 615
 		$data = new stdClass();
616
-		$start = strpos($buffer,"VDM");
616
+		$start = strpos($buffer, "VDM");
617 617
 		$tst = substr($buffer, $start - 3);
618
-		$data = $this->process_ais_raw( $tst, "" );
618
+		$data = $this->process_ais_raw($tst, "");
619 619
 		if (!is_object($data)) {
620 620
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
621 621
 			return array();
622 622
 		}
623 623
 		if ($data->lon != 0) $result['longitude'] = $data->lon;
624 624
 		if ($data->lat != 0) $result['latitude'] = $data->lat;
625
-		$result['ident'] = trim(str_replace('@','',$data->name));
625
+		$result['ident'] = trim(str_replace('@', '', $data->name));
626 626
 		$result['timestamp'] = $data->ts;
627 627
 		$result['mmsi'] = $data->mmsi;
628
-		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
628
+		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'], 0, 3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
629 629
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
630 630
 		if ($data->sog != -1.0) $result['speed'] = $data->sog;
631 631
 		if ($data->heading !== '') $result['heading'] = $data->heading;
@@ -635,16 +635,16 @@  discard block
 block discarded – undo
635 635
 		if ($data->type !== '') $result['type'] = $data->type;
636 636
 		if ($data->typeid !== '') $result['typeid'] = $data->typeid;
637 637
 		if ($data->imo !== '') $result['imo'] = $data->imo;
638
-		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign));
638
+		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@', '', $data->callsign));
639 639
 		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 !== '') {
640
-			$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');
640
+			$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');
641 641
 			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
642 642
 		} elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) {
643
-			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
643
+			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00');
644 644
 			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
645 645
 		}
646 646
 		if ($data->destination != '') {
647
-			$dest = trim(str_replace('@','',$data->destination));
647
+			$dest = trim(str_replace('@', '', $data->destination));
648 648
 			if ($dest != '') $result['destination'] = $dest;
649 649
 		}
650 650
 		$result['all'] = (array) $data;
Please login to merge, or discard this patch.
Braces   +331 added lines, -143 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,11 +479,20 @@  discard block
 block discarded – undo
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
@@ -401,8 +503,14 @@  discard block
 block discarded – undo
401 503
 			$num_seq = (int)$pcs[1]; // number of sequences
402 504
 			$seq = (int)$pcs[2]; // get sequence
403 505
 			// get msg sequence id
404
-			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
405
-			else $msg_sid = (int)$pcs[3]; // multipart message
506
+			if ($pcs[3] == '') {
507
+				$msg_sid = -1;
508
+			}
509
+			// non-multipart message, set to -1
510
+			else {
511
+				$msg_sid = (int)$pcs[3];
512
+			}
513
+			// multipart message
406 514
 			$ais_ch = $pcs[4]; // get AIS channel
407 515
 			// message sequence checking
408 516
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -463,10 +571,18 @@  discard block
 block discarded – undo
463 571
 				//DEBUG echo "[$start $end $tst]\n";
464 572
 				$result = $this->process_ais_raw( $tst, "" );
465 573
 				$last_pos = $end + 1;
466
-			} else break;
574
+			} else {
575
+				break;
576
+			}
467 577
 		}
468
-		if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move...
469
-		if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode...
578
+		if ($last_pos > 0) {
579
+			$cbuf = substr($cbuf, $last_pos);
580
+		}
581
+		// move...
582
+		if (strlen($cbuf) > 1024) {
583
+			$cbuf = "";
584
+		}
585
+		// prevent overflow simple mode...
470 586
 		return $result;
471 587
 	}
472 588
 
@@ -486,7 +602,9 @@  discard block
 block discarded – undo
486 602
 		if ($lat<0.0) {
487 603
 			$lat = -$lat;
488 604
 			$neg=true;
489
-		} else $neg=false;
605
+		} else {
606
+			$neg=false;
607
+		}
490 608
 		$latd = 0x00000000;
491 609
 		$latd = intval ($lat * 600000.0);
492 610
 		if ($neg==true) {
@@ -502,7 +620,9 @@  discard block
 block discarded – undo
502 620
 		if ($lon<0.0) {
503 621
 			$lon = -$lon;
504 622
 			$neg=true;
505
-		} else $neg=false;
623
+		} else {
624
+			$neg=false;
625
+		}
506 626
 		$lond = 0x00000000;
507 627
 		$lond = intval ($lon * 600000.0);
508 628
 		if ($neg==true) {
@@ -515,9 +635,14 @@  discard block
 block discarded – undo
515 635
 
516 636
 	private function char2bin($name, $max_len) {
517 637
 		$len = strlen($name);
518
-		if ($len > $max_len) $name = substr($name,0,$max_len);
519
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
520
-		else $pad = '';
638
+		if ($len > $max_len) {
639
+			$name = substr($name,0,$max_len);
640
+		}
641
+		if ($len < $max_len) {
642
+			$pad = str_repeat('0', ($max_len - $len) * 6);
643
+		} else {
644
+			$pad = '';
645
+		}
521 646
 		$rv = '';
522 647
 		$ais_chars = array(
523 648
 		    '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
@@ -530,9 +655,12 @@  discard block
 block discarded – undo
530 655
 		);
531 656
 		// "
532 657
 		$_a = str_split($name);
533
-		if ($_a) foreach ($_a as $_1) {
658
+		if ($_a) {
659
+			foreach ($_a as $_1) {
534 660
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
535
-			else $dec = 0;
661
+		} else {
662
+				$dec = 0;
663
+			}
536 664
 			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
537 665
 			$rv .= $bin;
538 666
 			//echo "$_1 $dec ($bin)<br/>";
@@ -544,7 +672,9 @@  discard block
 block discarded – undo
544 672
 		$len_bit = strlen($_enc);
545 673
 		$rem6 = $len_bit % 6;
546 674
 		$pad6_len = 0;
547
-		if ($rem6) $pad6_len = 6 - $rem6;
675
+		if ($rem6) {
676
+			$pad6_len = 6 - $rem6;
677
+		}
548 678
 		//echo  $pad6_len.'<br>';
549 679
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
550 680
 		$len_enc = strlen($_enc) / 6;
@@ -553,8 +683,11 @@  discard block
 block discarded – undo
553 683
 		for ($i=0; $i<$len_enc; $i++) {
554 684
 			$offset = $i * 6;
555 685
 			$dec = bindec(substr($_enc,$offset,6));
556
-			if ($dec < 40) $dec += 48;
557
-			else $dec += 56;
686
+			if ($dec < 40) {
687
+				$dec += 48;
688
+			} else {
689
+				$dec += 56;
690
+			}
558 691
 			//echo chr($dec)." $dec<br/>";
559 692
 			$itu .= chr($dec);
560 693
 		}
@@ -567,25 +700,41 @@  discard block
 block discarded – undo
567 700
 		}
568 701
 		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
569 702
 		$lsb = $chksum & 0x0F;
570
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
571
-		else $lsbc = '0';
703
+		if ($lsb >=0 && $lsb <= 15 ) {
704
+			$lsbc = $hex_arr[$lsb];
705
+		} else {
706
+			$lsbc = '0';
707
+		}
572 708
 		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
573
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
574
-		else $msbc = '0';
709
+		if ($msb >=0 && $msb <= 15 ) {
710
+			$msbc = $hex_arr[$msb];
711
+		} else {
712
+			$msbc = '0';
713
+		}
575 714
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
576 715
 		return $itu;
577 716
 	}
578 717
 
579 718
 	public function parse($buffer) {
580 719
 		$data = $this->process_ais_buf($buffer);
581
-		if (!is_object($data)) return array();
582
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
583
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
720
+		if (!is_object($data)) {
721
+			return array();
722
+		}
723
+		if ($data->lon != 0) {
724
+			$result['longitude'] = $data->lon;
725
+		}
726
+		if ($data->lat != 0) {
727
+			$result['latitude'] = $data->lat;
728
+		}
584 729
 		$result['ident'] = trim($data->name);
585 730
 		$result['timestamp'] = $data->ts;
586 731
 		$result['mmsi'] = $data->mmsi;
587
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
588
-		if ($data->cog != 0) $result['heading'] = $data->cog;
732
+		if ($data->sog != -1.0) {
733
+			$result['speed'] = $data->sog;
734
+		}
735
+		if ($data->cog != 0) {
736
+			$result['heading'] = $data->cog;
737
+		}
589 738
 		/*
590 739
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
591 740
 		    $ro->id = bindec(substr($_aisdata,0,6));
@@ -595,15 +744,25 @@  discard block
 block discarded – undo
595 744
 
596 745
 	public function mmsitype($mmsi) {
597 746
 		if (strlen($mmsi) == 9) {
598
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
599
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
600
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
601
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
602
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
603
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
604
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
605
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
606
-			else return 'Ship';
747
+			if (substr($mmsi,0,3) == '974') {
748
+				return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
749
+			} elseif (substr($mmsi,0,3) == '972') {
750
+				return 'MOB (Man Overboard) device';
751
+			} elseif (substr($mmsi,0,3) == '970') {
752
+				return 'AIS SART (Search and Rescue Transmitter)';
753
+			} elseif (substr($mmsi,0,3) == '111') {
754
+				return 'SAR (Search and Rescue) aircraft';
755
+			} elseif (substr($mmsi,0,2) == '98') {
756
+				return 'Auxiliary craft associated with a parent ship';
757
+			} elseif (substr($mmsi,0,2) == '99') {
758
+				return 'Aids to Navigation';
759
+			} elseif (substr($mmsi,0,2) == '00') {
760
+				return 'Coastal stations';
761
+			} elseif (substr($mmsi,0,1) == '0') {
762
+				return 'Group of ships';
763
+			} else {
764
+				return 'Ship';
765
+			}
607 766
 		}
608 767
 
609 768
 	
@@ -620,32 +779,61 @@  discard block
 block discarded – undo
620 779
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
621 780
 			return array();
622 781
 		}
623
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
624
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
782
+		if ($data->lon != 0) {
783
+			$result['longitude'] = $data->lon;
784
+		}
785
+		if ($data->lat != 0) {
786
+			$result['latitude'] = $data->lat;
787
+		}
625 788
 		$result['ident'] = trim(str_replace('@','',$data->name));
626 789
 		$result['timestamp'] = $data->ts;
627 790
 		$result['mmsi'] = $data->mmsi;
628
-		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
791
+		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') {
792
+			$result['mmsi'] = '3'.$result['mmsi'];
793
+		}
629 794
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
630
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
631
-		if ($data->heading !== '') $result['heading'] = $data->heading;
632
-		elseif ($data->cog != 0) $result['heading'] = $data->cog;
633
-		if ($data->status != '') $result['status'] = $data->status;
634
-		if ($data->statusid !== '') $result['statusid'] = $data->statusid;
635
-		if ($data->type !== '') $result['type'] = $data->type;
636
-		if ($data->typeid !== '') $result['typeid'] = $data->typeid;
637
-		if ($data->imo !== '') $result['imo'] = $data->imo;
638
-		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign));
795
+		if ($data->sog != -1.0) {
796
+			$result['speed'] = $data->sog;
797
+		}
798
+		if ($data->heading !== '') {
799
+			$result['heading'] = $data->heading;
800
+		} elseif ($data->cog != 0) {
801
+			$result['heading'] = $data->cog;
802
+		}
803
+		if ($data->status != '') {
804
+			$result['status'] = $data->status;
805
+		}
806
+		if ($data->statusid !== '') {
807
+			$result['statusid'] = $data->statusid;
808
+		}
809
+		if ($data->type !== '') {
810
+			$result['type'] = $data->type;
811
+		}
812
+		if ($data->typeid !== '') {
813
+			$result['typeid'] = $data->typeid;
814
+		}
815
+		if ($data->imo !== '') {
816
+			$result['imo'] = $data->imo;
817
+		}
818
+		if ($data->callsign !== '') {
819
+			$result['callsign'] = trim(str_replace('@','',$data->callsign));
820
+		}
639 821
 		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 !== '') {
640 822
 			$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');
641
-			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
823
+			if ($eta_ts != '') {
824
+				$result['eta_ts'] = $eta_ts;
825
+			}
642 826
 		} elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) {
643 827
 			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
644
-			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
828
+			if ($eta_ts != '') {
829
+				$result['eta_ts'] = $eta_ts;
830
+			}
645 831
 		}
646 832
 		if ($data->destination != '') {
647 833
 			$dest = trim(str_replace('@','',$data->destination));
648
-			if ($dest != '') $result['destination'] = $dest;
834
+			if ($dest != '') {
835
+				$result['destination'] = $dest;
836
+			}
649 837
 		}
650 838
 		$result['all'] = (array) $data;
651 839
 		/*
Please login to merge, or discard this patch.