Completed
Push — master ( 60bf6d...c26593 )
by Yannick
08:12
created
require/class.APRS.php 2 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@  discard block
 block discarded – undo
2 2
 require_once(dirname(__FILE__).'/settings.php');
3 3
 require_once(dirname(__FILE__).'/class.Common.php');
4 4
 class aprs {
5
-    private $socket;
6
-    private $connected = false;
5
+	private $socket;
6
+	private $connected = false;
7 7
 
8
-    protected $symbols = array('!' => 'Police',
8
+	protected $symbols = array('!' => 'Police',
9 9
 	'#' => 'DIGI',
10 10
 	'$' => 'Phone',
11 11
 	'%' => 'DX Cluster',
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 	'y' => 'Yagi At QTH');
90 90
 	
91 91
 
92
-    private function urshift($n, $s) {
92
+	private function urshift($n, $s) {
93 93
 	return ($n >= 0) ? ($n >> $s) :
94
-	    (($n & 0x7fffffff) >> $s) | 
94
+		(($n & 0x7fffffff) >> $s) | 
95 95
 		(0x40000000 >> ($s - 1));
96
-    }
96
+	}
97 97
 
98
-    public function parse($input) {
98
+	public function parse($input) {
99 99
 	global $globalDebug;
100 100
 	$debug = false;
101 101
 	$result = array();
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
-	    return false;
110
+		if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
+		return false;
112 112
 	}
113 113
 	
114 114
 	if ($debug) echo 'input : '.$input."\n";
@@ -122,31 +122,31 @@  discard block
 block discarded – undo
122 122
 	/* Parse source, target and path. */
123 123
 	//FLRDF0A52>APRS,qAS,LSTB
124 124
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
125
-	    $ident = $matches[1];
126
-	    $all_elements = $matches[2];
127
-	    if ($ident == 'AIRCRAFT') {
125
+		$ident = $matches[1];
126
+		$all_elements = $matches[2];
127
+		if ($ident == 'AIRCRAFT') {
128 128
 		$result['format_source'] = 'famaprs';
129 129
 		$result['source_type'] = 'modes';
130
-	    } elseif ($ident == 'MARINE') {
130
+		} elseif ($ident == 'MARINE') {
131 131
 		$result['format_source'] = 'famaprs';
132 132
 		$result['source_type'] = 'ais';
133
-	    } else {
133
+		} else {
134 134
 		if ($debug) echo 'ident : '.$ident."\n";
135 135
 		$result['ident'] = $ident;
136
-	    }
136
+		}
137 137
 	} else return false;
138 138
 	$elements = explode(',',$all_elements);
139 139
 	$source = end($elements);
140 140
 	$result['source'] = $source;
141 141
 	foreach ($elements as $element) {
142
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
143
-	        //echo "ok";
144
-	        //if ($element == 'TCPIP*') return false;
145
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
142
+		if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
143
+			//echo "ok";
144
+			//if ($element == 'TCPIP*') return false;
145
+		} elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146 146
 		if ($debug) echo 'element : '.$element."\n";
147 147
 		return false;
148
-	    }
149
-	    /*
148
+		}
149
+		/*
150 150
 	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
151 151
 		//echo "ok";
152 152
 	    } else {
@@ -171,49 +171,49 @@  discard block
 block discarded – undo
171 171
 	$body_parse = substr($body,1);
172 172
 	//echo 'Body : '.$body."\n";
173 173
 	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
174
-	    $body_parse = substr($body_parse,10);
175
-	    $find = true;
176
-	    //echo $body_parse."\n";
174
+		$body_parse = substr($body_parse,10);
175
+		$find = true;
176
+		//echo $body_parse."\n";
177 177
 	}
178 178
 	if (preg_match('/^`(.*)\//',$body,$matches)) {
179
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
180
-	    $find = true;
181
-	    //echo $body_parse."\n";
179
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
180
+		$find = true;
181
+		//echo $body_parse."\n";
182 182
 	}
183 183
 	if (preg_match("/^'(.*)\//",$body,$matches)) {
184
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
185
-	    $find = true;
186
-	    //echo $body_parse."\n";
184
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
185
+		$find = true;
186
+		//echo $body_parse."\n";
187 187
 	}
188 188
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
189
-	    $find = true;
190
-	    //print_r($matches);
191
-	    $timestamp = $matches[0];
192
-	    if ($matches[4] == 'h') {
189
+		$find = true;
190
+		//print_r($matches);
191
+		$timestamp = $matches[0];
192
+		if ($matches[4] == 'h') {
193 193
 		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
194 194
 		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
195 195
 		/*
196 196
 		if (time() + 3900 < $timestamp) $timestamp -= 86400;
197 197
 		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
198 198
 		*/
199
-	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
199
+		} elseif ($matches[4] == 'z' || $matches[4] == '/') {
200 200
 		// This work or not ?
201 201
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
202
-	    }
203
-	    $body_parse = substr($body_parse,7);
204
-	    $result['timestamp'] = $timestamp;
205
-	    //echo date('Ymd H:i:s',$timestamp);
202
+		}
203
+		$body_parse = substr($body_parse,7);
204
+		$result['timestamp'] = $timestamp;
205
+		//echo date('Ymd H:i:s',$timestamp);
206 206
 	}
207 207
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
208
-	    $find = true;
209
-	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
-	    $body_parse = substr($body_parse,8);
211
-	    $result['timestamp'] = $timestamp;
212
-	    //echo date('Ymd H:i:s',$timestamp);
208
+		$find = true;
209
+		$timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
+		$body_parse = substr($body_parse,8);
211
+		$result['timestamp'] = $timestamp;
212
+		//echo date('Ymd H:i:s',$timestamp);
213 213
 	}
214 214
 	//if (strlen($body_parse) > 19) {
215
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
216
-	    $find = true;
215
+		if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
216
+		$find = true;
217 217
 		// 4658.70N/00707.78Ez
218 218
 		//print_r(str_split($body_parse));
219 219
 		
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		$lon = intval($lon_deg);
231 231
 		if ($lat > 89 || $lon > 179) return false;
232 232
 	    
233
-	    /*
233
+		/*
234 234
 	    $tmp_5b = str_replace('.','',$lat_min);
235 235
 	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
236 236
 	        print_r($matches);
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
 		$result['longitude'] = $longitude;
245 245
 		$body_parse = substr($body_parse,18);
246 246
 		$body_parse_len = strlen($body_parse);
247
-	    }
248
-	    $body_parse_len = strlen($body_parse);
249
-	    if ($body_parse_len > 0) {
247
+		}
248
+		$body_parse_len = strlen($body_parse);
249
+		if ($body_parse_len > 0) {
250 250
 		/*
251 251
 		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
252 252
 			$body_split = str_split($body);
@@ -276,86 +276,86 @@  discard block
 block discarded – undo
276 276
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
277 277
 			if ($symbol_code != '_') {
278 278
 			}
279
-		    //$body_parse = substr($body_parse,1);
280
-		    //$body_parse = trim($body_parse);
281
-		    //$body_parse_len = strlen($body_parse);
282
-		    if ($body_parse_len >= 7) {
279
+			//$body_parse = substr($body_parse,1);
280
+			//$body_parse = trim($body_parse);
281
+			//$body_parse_len = strlen($body_parse);
282
+			if ($body_parse_len >= 7) {
283 283
 			
284
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
-		    	    $course = substr($body_parse,0,3);
286
-		    	    $tmp_s = intval($course);
287
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
-		    	    $speed = substr($body_parse,4,3);
289
-		    	    if ($speed != '...') {
290
-		    		//$result['speed'] = round($speed*1.852);
291
-		    		$result['speed'] = intval($speed);
292
-		    	    }
293
-		    	    $body_parse = substr($body_parse,7);
294
-		        }
295
-		        // Check PHGR, PHG, RNG
296
-		    } 
297
-		    /*
284
+				if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
+					$course = substr($body_parse,0,3);
286
+					$tmp_s = intval($course);
287
+					if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
+					$speed = substr($body_parse,4,3);
289
+					if ($speed != '...') {
290
+					//$result['speed'] = round($speed*1.852);
291
+					$result['speed'] = intval($speed);
292
+					}
293
+					$body_parse = substr($body_parse,7);
294
+				}
295
+				// Check PHGR, PHG, RNG
296
+			} 
297
+			/*
298 298
 		    else if ($body_parse_len > 0) {
299 299
 			$rest = $body_parse;
300 300
 		    }
301 301
 		    */
302
-		    if (strlen($body_parse) > 0) {
303
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
304
-		            $altitude = intval($matches[1]);
305
-		            //$result['altitude'] = round($altitude*0.3048);
306
-		            $result['altitude'] = $altitude;
307
-		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
308
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
309
-		        }
310
-		    }
302
+			if (strlen($body_parse) > 0) {
303
+				if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
304
+					$altitude = intval($matches[1]);
305
+					//$result['altitude'] = round($altitude*0.3048);
306
+					$result['altitude'] = $altitude;
307
+					//$body_parse = trim(substr($body_parse,strlen($matches[0])));
308
+					$body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
309
+				}
310
+			}
311 311
 		    
312
-		    // Telemetry
313
-		    /*
312
+			// Telemetry
313
+			/*
314 314
 		    if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) {
315 315
 		        // Nothing yet...
316 316
 		    }
317 317
 		    */
318
-		    // DAO
319
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
320
-			    $dao = $matches[1];
321
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
318
+			// DAO
319
+			if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
320
+				$dao = $matches[1];
321
+				if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
322 322
 				$dao_split = str_split($dao);
323
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
323
+					$lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324
+					$lon_off = (($dao_split[2])-48.0)*0.001/60.0;
325 325
 			    
326 326
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
327 327
 				else $result['latitude'] += $lat_off;
328 328
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
329 329
 				else $result['longitude'] += $lon_off;
330
-			    }
331
-		            $body_parse = substr($body_parse,6);
332
-		    }
330
+				}
331
+					$body_parse = substr($body_parse,6);
332
+			}
333 333
 		    
334
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
334
+			if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
335 335
 			$result['ident'] = $matches[1];
336
-		    }
337
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
336
+			}
337
+			if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
338 338
 			$result['squawk'] = $matches[1];
339
-		    }
340
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
339
+			}
340
+			if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
341 341
 			$result['aircraft_icao'] = $matches[1];
342
-		    }
343
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
342
+			}
343
+			if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
344 344
 			$result['typeid'] = $matches[1];
345
-		    }
346
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
345
+			}
346
+			if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
347 347
 			$result['imo'] = $matches[1];
348
-		    }
349
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
348
+			}
349
+			if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
350 350
 			$result['arrival_date'] = $matches[1];
351
-		    }
352
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
351
+			}
352
+			if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
353 353
 			$result['arrival_code'] = $matches[1];
354
-		    }
355
-		    // OGN comment
354
+			}
355
+			// OGN comment
356 356
 		   // echo "Before OGN : ".$body_parse."\n";
357
-		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
358
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
357
+			//if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
358
+			if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
359 359
 			$id = $matches[1];
360 360
 			//$mode = substr($id,0,2);
361 361
 			$address = substr($id,2);
@@ -385,53 +385,53 @@  discard block
 block discarded – undo
385 385
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
386 386
 			$result['stealth'] = $stealth;
387 387
 			$result['address'] = $address;
388
-		    }
388
+			}
389 389
 		    
390
-		    //Comment
391
-		    $result['comment'] = trim($body_parse);
390
+			//Comment
391
+			$result['comment'] = trim($body_parse);
392 392
 		} else {
393
-		    // parse weather
394
-		    //$body_parse = substr($body_parse,1);
395
-		    //$body_parse_len = strlen($body_parse);
393
+			// parse weather
394
+			//$body_parse = substr($body_parse,1);
395
+			//$body_parse_len = strlen($body_parse);
396 396
 
397
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
398
-			    $result['wind_dir'] = intval($matches[1]);
399
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
400
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
401
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
402
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
403
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
397
+			if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
398
+				$result['wind_dir'] = intval($matches[1]);
399
+				$result['wind_speed'] = round(intval($matches[2])*1.60934,1);
400
+				$result['wind_gust'] = round(intval($matches[3])*1.60934,1);
401
+				$result['temp'] = round(5/9*((intval($matches[4]))-32),1);
402
+					$body_parse = substr($body_parse,strlen($matches[0])+1);
403
+			} elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
404 404
 			$result['wind_dir'] = intval($matches[1]);
405 405
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
406 406
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
407 407
 			$result['temp'] = round(5/9*(($matches[4])-32),1);
408
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
409
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
408
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
409
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
410 410
 			$result['wind_dir'] = intval($matches[1]);
411 411
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
412 412
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
413
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
414
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
413
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
414
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
415 415
 			$result['wind_dir'] = intval($matches[1]);
416 416
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
417 417
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
418
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
419
-		    }
420
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
418
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
419
+			}
420
+			if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
421 421
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
422
-		    }
422
+			}
423 423
 		}
424 424
 		} else $result['comment'] = trim($body_parse);
425 425
 
426
-	    }
426
+		}
427 427
 	//}
428 428
 	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
429 429
 	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
430 430
 	if ($debug) print_r($result);
431 431
 	return $result;
432
-    }
432
+	}
433 433
     
434
-    function connect() {
434
+	function connect() {
435 435
 	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
436 436
 	$aprs_connect = 0;
437 437
 	$aprs_keep = 120;
@@ -454,24 +454,24 @@  discard block
 block discarded – undo
454 454
 		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
455 455
 		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
456 456
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
457
-			    echo 'APRS user verified !'."\n";
458
-			    $this->connected = true;
459
-			    return true;
460
-			    break;
457
+				echo 'APRS user verified !'."\n";
458
+				$this->connected = true;
459
+				return true;
460
+				break;
461 461
 			}
462 462
 			if (time()-$authstart > 5) {
463
-			    echo 'APRS timeout'."\n";
464
-			    break;
463
+				echo 'APRS timeout'."\n";
464
+				break;
465 465
 			}
466 466
 		}
467 467
 	}
468
-    }
468
+	}
469 469
     
470
-    function send($data) {
470
+	function send($data) {
471 471
 	if ($this->connected === false) $this->connect();
472 472
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
473 473
 	if ($send === FALSE) $this->connect();
474
-    }
474
+	}
475 475
 }
476 476
 
477 477
 class APRSSpotter extends APRS {
Please login to merge, or discard this patch.
Braces   +152 added lines, -58 removed lines patch added patch discarded remove patch
@@ -107,17 +107,23 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+	    if ($globalDebug) {
111
+	    	echo '!!! APRS invalid : '.$input."\n";
112
+	    }
111 113
 	    return false;
112 114
 	}
113 115
 	
114
-	if ($debug) echo 'input : '.$input."\n";
116
+	if ($debug) {
117
+		echo 'input : '.$input."\n";
118
+	}
115 119
 	/* Save header and body. */
116 120
 	$body = substr($input,$splitpos+1,$input_len);
117 121
 	$body_len = strlen($body);
118 122
 	$header = substr($input,0,$splitpos);
119 123
 	//$header_len = strlen($header);
120
-	if ($debug) echo 'header : '.$header."\n";
124
+	if ($debug) {
125
+		echo 'header : '.$header."\n";
126
+	}
121 127
 	
122 128
 	/* Parse source, target and path. */
123 129
 	//FLRDF0A52>APRS,qAS,LSTB
@@ -131,10 +137,14 @@  discard block
 block discarded – undo
131 137
 		$result['format_source'] = 'famaprs';
132 138
 		$result['source_type'] = 'ais';
133 139
 	    } else {
134
-		if ($debug) echo 'ident : '.$ident."\n";
140
+		if ($debug) {
141
+			echo 'ident : '.$ident."\n";
142
+		}
135 143
 		$result['ident'] = $ident;
136 144
 	    }
137
-	} else return false;
145
+	} else {
146
+		return false;
147
+	}
138 148
 	$elements = explode(',',$all_elements);
139 149
 	$source = end($elements);
140 150
 	$result['source'] = $source;
@@ -143,7 +153,9 @@  discard block
 block discarded – undo
143 153
 	        //echo "ok";
144 154
 	        //if ($element == 'TCPIP*') return false;
145 155
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146
-		if ($debug) echo 'element : '.$element."\n";
156
+		if ($debug) {
157
+			echo 'element : '.$element."\n";
158
+		}
147 159
 		return false;
148 160
 	    }
149 161
 	    /*
@@ -156,11 +168,15 @@  discard block
 block discarded – undo
156 168
 	}
157 169
 	
158 170
 	$type = substr($body,0,1);
159
-	if ($debug) echo 'type : '.$type."\n";
171
+	if ($debug) {
172
+		echo 'type : '.$type."\n";
173
+	}
160 174
 	if ($type == ';') {
161 175
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162 176
 			$result['address'] = trim(substr($body,1,9));
163
-		} else $result['ident'] = trim(substr($body,1,9));
177
+		} else {
178
+			$result['ident'] = trim(substr($body,1,9));
179
+		}
164 180
 	} elseif ($type == ',') {
165 181
 		// Invalid data or test data
166 182
 		return false;
@@ -228,7 +244,9 @@  discard block
 block discarded – undo
228 244
 		//$symbol_table = $matches[4];
229 245
 		$lat = intval($lat_deg);
230 246
 		$lon = intval($lon_deg);
231
-		if ($lat > 89 || $lon > 179) return false;
247
+		if ($lat > 89 || $lon > 179) {
248
+			return false;
249
+		}
232 250
 	    
233 251
 	    /*
234 252
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -238,8 +256,12 @@  discard block
 block discarded – undo
238 256
 	    */
239 257
 		$latitude = $lat + floatval($lat_min)/60;
240 258
 		$longitude = $lon + floatval($lon_min)/60;
241
-		if ($sind == 'S') $latitude = 0-$latitude;
242
-		if ($wind == 'W') $longitude = 0-$longitude;
259
+		if ($sind == 'S') {
260
+			$latitude = 0-$latitude;
261
+		}
262
+		if ($wind == 'W') {
263
+			$longitude = 0-$longitude;
264
+		}
243 265
 		$result['latitude'] = $latitude;
244 266
 		$result['longitude'] = $longitude;
245 267
 		$body_parse = substr($body_parse,18);
@@ -273,7 +295,9 @@  discard block
 block discarded – undo
273 295
 			$body_parse = substr($body_parse,1);
274 296
 			$body_parse_len = strlen($body_parse);
275 297
 			$result['symbol_code'] = $symbol_code;
276
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
298
+			if (isset($this->symbols[$symbol_code])) {
299
+				$result['symbol'] = $this->symbols[$symbol_code];
300
+			}
277 301
 			if ($symbol_code != '_') {
278 302
 			}
279 303
 		    //$body_parse = substr($body_parse,1);
@@ -284,7 +308,9 @@  discard block
 block discarded – undo
284 308
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285 309
 		    	    $course = substr($body_parse,0,3);
286 310
 		    	    $tmp_s = intval($course);
287
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
311
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
312
+		    	    	$result['heading'] = intval($course);
313
+		    	    }
288 314
 		    	    $speed = substr($body_parse,4,3);
289 315
 		    	    if ($speed != '...') {
290 316
 		    		//$result['speed'] = round($speed*1.852);
@@ -323,10 +349,16 @@  discard block
 block discarded – undo
323 349
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324 350
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
325 351
 			    
326
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
327
-				else $result['latitude'] += $lat_off;
328
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
329
-				else $result['longitude'] += $lon_off;
352
+				if ($result['latitude'] < 0) {
353
+					$result['latitude'] -= $lat_off;
354
+				} else {
355
+					$result['latitude'] += $lat_off;
356
+				}
357
+				if ($result['longitude'] < 0) {
358
+					$result['longitude'] -= $lon_off;
359
+				} else {
360
+					$result['longitude'] += $lon_off;
361
+				}
330 362
 			    }
331 363
 		            $body_parse = substr($body_parse,6);
332 364
 		    }
@@ -361,27 +393,48 @@  discard block
 block discarded – undo
361 393
 			$address = substr($id,2);
362 394
 			//print_r($matches);
363 395
 			$addressType = (intval(substr($id,0,2),16))&3;
364
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
365
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
366
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
367
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
396
+			if ($addressType == 0) {
397
+				$result['addresstype'] = "RANDOM";
398
+			} elseif ($addressType == 1) {
399
+				$result['addresstype'] = "ICAO";
400
+			} elseif ($addressType == 2) {
401
+				$result['addresstype'] = "FLARM";
402
+			} elseif ($addressType == 3) {
403
+				$result['addresstype'] = "OGN";
404
+			}
368 405
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
369 406
 			$result['aircrafttype_code'] = $aircraftType;
370
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
371
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
372
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
373
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
374
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
375
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
376
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
377
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
378
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
379
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
380
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
381
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
382
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
383
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
384
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
407
+			if ($aircraftType == 0) {
408
+				$result['aircrafttype'] = "UNKNOWN";
409
+			} elseif ($aircraftType == 1) {
410
+				$result['aircrafttype'] = "GLIDER";
411
+			} elseif ($aircraftType == 2) {
412
+				$result['aircrafttype'] = "TOW_PLANE";
413
+			} elseif ($aircraftType == 3) {
414
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
415
+			} elseif ($aircraftType == 4) {
416
+				$result['aircrafttype'] = "PARACHUTE";
417
+			} elseif ($aircraftType == 5) {
418
+				$result['aircrafttype'] = "DROP_PLANE";
419
+			} elseif ($aircraftType == 6) {
420
+				$result['aircrafttype'] = "HANG_GLIDER";
421
+			} elseif ($aircraftType == 7) {
422
+				$result['aircrafttype'] = "PARA_GLIDER";
423
+			} elseif ($aircraftType == 8) {
424
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
425
+			} elseif ($aircraftType == 9) {
426
+				$result['aircrafttype'] = "JET_AIRCRAFT";
427
+			} elseif ($aircraftType == 10) {
428
+				$result['aircrafttype'] = "UFO";
429
+			} elseif ($aircraftType == 11) {
430
+				$result['aircrafttype'] = "BALLOON";
431
+			} elseif ($aircraftType == 12) {
432
+				$result['aircrafttype'] = "AIRSHIP";
433
+			} elseif ($aircraftType == 13) {
434
+				$result['aircrafttype'] = "UAV";
435
+			} elseif ($aircraftType == 15) {
436
+				$result['aircrafttype'] = "STATIC_OBJECT";
437
+			}
385 438
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
386 439
 			$result['stealth'] = $stealth;
387 440
 			$result['address'] = $address;
@@ -421,13 +474,21 @@  discard block
 block discarded – undo
421 474
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
422 475
 		    }
423 476
 		}
424
-		} else $result['comment'] = trim($body_parse);
477
+		} else {
478
+			$result['comment'] = trim($body_parse);
479
+		}
425 480
 
426 481
 	    }
427 482
 	//}
428
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
429
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
430
-	if ($debug) print_r($result);
483
+	if (isset($result['latitude'])) {
484
+		$result['latitude'] = round($result['latitude'],4);
485
+	}
486
+	if (isset($result['longitude'])) {
487
+		$result['longitude'] = round($result['longitude'],4);
488
+	}
489
+	if ($debug) {
490
+		print_r($result);
491
+	}
431 492
 	return $result;
432 493
     }
433 494
     
@@ -436,12 +497,21 @@  discard block
 block discarded – undo
436 497
 	$aprs_connect = 0;
437 498
 	$aprs_keep = 120;
438 499
 	$aprs_last_tx = time();
439
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
440
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
441
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
442
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
443
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
444
-	else $aprs_pass = '-1';
500
+	if (isset($globalAPRSversion)) {
501
+		$aprs_version = $globalAPRSversion;
502
+	} else {
503
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
504
+	}
505
+	if (isset($globalServerAPRSssid)) {
506
+		$aprs_ssid = $globalServerAPRSssid;
507
+	} else {
508
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
509
+	}
510
+	if (isset($globalServerAPRSpass)) {
511
+		$aprs_pass = $globalServerAPRSpass;
512
+	} else {
513
+		$aprs_pass = '-1';
514
+	}
445 515
 	
446 516
 	$aprs_filter  = '';
447 517
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -468,9 +538,13 @@  discard block
 block discarded – undo
468 538
     }
469 539
     
470 540
     function send($data) {
471
-	if ($this->connected === false) $this->connect();
541
+	if ($this->connected === false) {
542
+		$this->connect();
543
+	}
472 544
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
473
-	if ($send === FALSE) $this->connect();
545
+	if ($send === FALSE) {
546
+		$this->connect();
547
+	}
474 548
     }
475 549
 }
476 550
 
@@ -487,18 +561,26 @@  discard block
 block discarded – undo
487 561
 			//$w = '00';
488 562
 			$custom = '';
489 563
 			if ($ident != '') {
490
-				if ($custom != '') $custom .= '/';
564
+				if ($custom != '') {
565
+					$custom .= '/';
566
+				}
491 567
 				$custom .= 'CS='.$ident;
492 568
 			}
493 569
 			if ($squawk != '') {
494
-				if ($custom != '') $custom .= '/';
570
+				if ($custom != '') {
571
+					$custom .= '/';
572
+				}
495 573
 				$custom .= 'SQ='.$squawk;
496 574
 			}
497 575
 			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
498
-				if ($custom != '') $custom .= '/';
576
+				if ($custom != '') {
577
+					$custom .= '/';
578
+				}
499 579
 				$custom .= 'AI='.$aircraft_icao;
500 580
 			}
501
-			if ($custom != '') $custom = ' '.$custom;
581
+			if ($custom != '') {
582
+				$custom = ' '.$custom;
583
+			}
502 584
 			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
503 585
 		}
504 586
 	}
@@ -516,26 +598,38 @@  discard block
 block discarded – undo
516 598
 			//$w = '00';
517 599
 			$custom = '';
518 600
 			if ($ident != '') {
519
-				if ($custom != '') $custom .= '/';
601
+				if ($custom != '') {
602
+					$custom .= '/';
603
+				}
520 604
 				$custom .= 'CS='.$ident;
521 605
 			}
522 606
 			if ($typeid != '') {
523
-				if ($custom != '') $custom .= '/';
607
+				if ($custom != '') {
608
+					$custom .= '/';
609
+				}
524 610
 				$custom .= 'TI='.$typeid;
525 611
 			}
526 612
 			if ($imo != '') {
527
-				if ($custom != '') $custom .= '/';
613
+				if ($custom != '') {
614
+					$custom .= '/';
615
+				}
528 616
 				$custom .= 'IMO='.$imo;
529 617
 			}
530 618
 			if ($arrival_date != '') {
531
-				if ($custom != '') $custom .= '/';
619
+				if ($custom != '') {
620
+					$custom .= '/';
621
+				}
532 622
 				$custom .= 'AD='.strtotime($arrival_date);
533 623
 			}
534 624
 			if ($arrival_code != '') {
535
-				if ($custom != '') $custom .= '/';
625
+				if ($custom != '') {
626
+					$custom .= '/';
627
+				}
536 628
 				$custom .= 'AC='.$arrival_code;
537 629
 			}
538
-			if ($custom != '') $custom = ' '.$custom;
630
+			if ($custom != '') {
631
+				$custom = ' '.$custom;
632
+			}
539 633
 			$altitude = 0;
540 634
 			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
541 635
 		}
Please login to merge, or discard this patch.