Completed
Push — master ( a24ad0...3afeea )
by Yannick
07:21
created

aprs::disconnect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
require_once(dirname(__FILE__).'/settings.php');
3
require_once(dirname(__FILE__).'/class.Common.php');
4
class aprs {
5
    private $socket;
6
    private $connected = false;
7
8
    protected $symbols = array('!' => 'Police',
9
	'#' => 'DIGI',
10
	'$' => 'Phone',
11
	'%' => 'DX Cluster',
12
	'&' => 'HF Gateway',
13
	"'" => 'Aircraft (small)',
14
	'(' => 'Cloudy',
15
	'*' => 'Snowmobile',
16
	'+' => 'Red Cross',
17
	',' => 'Reverse L Shape',
18
	'-' => 'House QTH (VHF)',
19
	'.' => 'X',
20
	'/' => 'Dot',
21
	'0' => '0',
22
	'1' => '1',
23
	'2' => '2',
24
	'3' => '3',
25
	'4' => '4',
26
	'5' => '5',
27
	'6' => '6',
28
	'7' => '7',
29
	'8' => '8',
30
	'9' => '9',
31
	':' => 'Fire',
32
	';' => 'Campground',
33
	'<' => 'Motorcycle',
34
	'=' => 'Railroad Engine',
35
	'>' => 'Car',
36
	'?' => 'Server for Files',
37
	'@' => 'HC Future Predict',
38
	'A' => 'Aid Station',
39
	'B' => 'BBS',
40
	'C' => 'Canoe',
41
	'E' => 'Eyeball',
42
	'G' => 'Grid Square',
43
	'H' => 'Hotel',
44
	'I' => 'TCP-IP',
45
	'K' => 'School',
46
	'M' => 'MacAPRS',
47
	'N' => 'NTS Station',
48
	'O' => 'Balloon',
49
	'P' => 'Police',
50
	'Q' => 'T.B.D.',
51
	'R' => 'Recreational Vehicle',
52
	'S' => 'Shuttle',
53
	'T' => 'SSTV',
54
	'U' => 'Bus',
55
	'V' => 'ATV',
56
	'W' => 'National Weather Service Site',
57
	'X' => 'Helicopter',
58
	'Y' => 'Yacht (Sail)',
59
	'Z' => 'WinAPRS',
60
	'[' => 'Jogger',
61
	']' => 'PBBS',
62
	'^' => 'Large Aircraft',
63
	'_' => 'Weather Station',
64
	'`' => 'Dish Antenna',
65
	'a' => 'Ambulance',
66
	'b' => 'Bike',
67
	'c' => 'T.B.D.',
68
	'd' => 'Dial Garage (Fire Department)',
69
	'e' => 'Horse (Equestrian)',
70
	'f' => 'Firetruck',
71
	'g' => 'Glider',
72
	'h' => 'Hospital',
73
	'i' => 'IOTA (Islands On The Air)',
74
	'j' => 'Jeep',
75
	'k' => 'Truck',
76
	'l' => 'Laptop',
77
	'm' => 'Mic-Repeater',
78
	'n' => 'Node',
79
	'o' => 'EOC',
80
	'p' => 'Rover (Puppy)',
81
	'q' => 'Grid SQ Shown Above 128 Miles',
82
	'r' => 'Antenna',
83
	's' => 'Ship (Power Boat)',
84
	't' => 'Truck Stop',
85
	'u' => 'Truck (18 Wheeler)',
86
	'v' => 'Van',
87
	'w' => 'Water Station',
88
	'x' => 'xAPRS (UNIX)',
89
	'y' => 'Yagi At QTH');
90
	
91
92
    private function urshift($n, $s) {
93
	return ($n >= 0) ? ($n >> $s) :
94
	    (($n & 0x7fffffff) >> $s) | 
95
		(0x40000000 >> ($s - 1));
96
    }
97
98
    public function parse($input) {
99
	global $globalDebug;
100
	$debug = false;
101
	$result = array();
102
	$input_len = strlen($input);
103
	//$split_input = str_split($input);
104
105
	/* Find the end of header checking for NULL bytes while doing it. */
106
	$splitpos = strpos($input,':');
107
	
108
	/* Check that end was found and body has at least one byte. */
109
	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
	    return false;
112
	}
113
	
114
	if ($debug) echo 'input : '.$input."\n";
115
	/* Save header and body. */
116
	$body = substr($input,$splitpos+1,$input_len);
117
	$body_len = strlen($body);
0 ignored issues
show
Unused Code introduced by
$body_len is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
118
	$header = substr($input,0,$splitpos);
119
	//$header_len = strlen($header);
120
	if ($debug) echo 'header : '.$header."\n";
121
	
122
	/* Parse source, target and path. */
123
	//FLRDF0A52>APRS,qAS,LSTB
124
	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
125
	    $ident = $matches[1];
126
	    $all_elements = $matches[2];
127
	    if ($ident == 'AIRCRAFT') {
128
		$result['format_source'] = 'famaprs';
129
		$result['source_type'] = 'modes';
130
	    } elseif ($ident == 'MARINE') {
131
		$result['format_source'] = 'famaprs';
132
		$result['source_type'] = 'ais';
133
	    } else {
134
		if ($debug) echo 'ident : '.$ident."\n";
135
		$result['ident'] = $ident;
136
	    }
137
	} else return false;
138
	$elements = explode(',',$all_elements);
139
	$source = end($elements);
140
	$result['source'] = $source;
141
	foreach ($elements as $element) {
142
	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
143
	        //echo "ok";
144
	        //if ($element == 'TCPIP*') return false;
145
	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146
		if ($debug) echo 'element : '.$element."\n";
147
		return false;
148
	    }
149
	    /*
150
	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
151
		//echo "ok";
152
	    } else {
153
	        return false;
154
	    }
155
	    */
156
	}
157
	
158
	$type = substr($body,0,1);
159
	if ($debug) echo 'type : '.$type."\n";
160
	if ($type == ';') {
161
		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162
			$result['address'] = trim(substr($body,1,9));
163
		} else $result['ident'] = trim(substr($body,1,9));
164
	} elseif ($type == ',') {
165
		// Invalid data or test data
166
		return false;
167
	}
168
	
169
	// Check for Timestamp
170
	$find = false;
171
	$body_parse = substr($body,1);
172
	//echo 'Body : '.$body."\n";
173
	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
174
	    $body_parse = substr($body_parse,10);
175
	    $find = true;
176
	    //echo $body_parse."\n";
177
	}
178
	if (preg_match('/^`(.*)\//',$body,$matches)) {
179
	    $body_parse = substr($body_parse,strlen($matches[1])-1);
180
	    $find = true;
181
	    //echo $body_parse."\n";
182
	}
183
	if (preg_match("/^'(.*)\//",$body,$matches)) {
184
	    $body_parse = substr($body_parse,strlen($matches[1])-1);
185
	    $find = true;
186
	    //echo $body_parse."\n";
187
	}
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') {
193
		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
194
		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
195
		/*
196
		if (time() + 3900 < $timestamp) $timestamp -= 86400;
197
		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
198
		*/
199
	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
200
		// This work or not ?
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);
206
	}
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);
213
	}
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;
217
		// 4658.70N/00707.78Ez
218
		//print_r(str_split($body_parse));
219
		
220
		//$latlon = $matches[0];
221
		$sind = strtoupper($matches[3]);
222
		$wind = strtoupper($matches[7]);
223
		$lat_deg = $matches[1];
224
		$lat_min = $matches[2];
225
		$lon_deg = $matches[5];
226
		$lon_min = $matches[6];
227
	    
228
		//$symbol_table = $matches[4];
229
		$lat = intval($lat_deg);
230
		$lon = intval($lon_deg);
231
		if ($lat > 89 || $lon > 179) return false;
232
	    
233
	    /*
234
	    $tmp_5b = str_replace('.','',$lat_min);
235
	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
236
	        print_r($matches);
237
	    }
238
	    */
239
		$latitude = $lat + floatval($lat_min)/60;
240
		$longitude = $lon + floatval($lon_min)/60;
241
		if ($sind == 'S') $latitude = 0-$latitude;
242
		if ($wind == 'W') $longitude = 0-$longitude;
243
		$result['latitude'] = $latitude;
244
		$result['longitude'] = $longitude;
245
		$body_parse = substr($body_parse,18);
246
		$body_parse_len = strlen($body_parse);
0 ignored issues
show
Unused Code introduced by
$body_parse_len is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
247
	    }
248
	    $body_parse_len = strlen($body_parse);
249
	    if ($body_parse_len > 0) {
250
		/*
251
		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
252
			$body_split = str_split($body);
253
			$symbol_code = $body_split[0];
254
			$body_parse = substr($body,1);
255
			$body_parse_len = strlen($body_parse);
256
		} else { 
257
		*/
258
		/*
259
		if ($find === false) {
260
			$body_split = str_split($body);
261
			$symbol_code = $body_split[0];
262
			$body_parse = substr($body,1);
263
			$body_parse_len = strlen($body_parse);
264
		} else { 
265
		*/
266
		if ($find) {
267
			$body_split = str_split($body_parse);
268
			$symbol_code = $body_split[0];
269
		//}
270
		//echo $body_parse;
271
			//if ($type != ';' && $type != '>') {
272
			if ($type != '') {
273
			$body_parse = substr($body_parse,1);
274
			$body_parse_len = strlen($body_parse);
275
			$result['symbol_code'] = $symbol_code;
276
			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
277
			if ($symbol_code != '_') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
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) {
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
		    /*
298
		    else if ($body_parse_len > 0) {
299
			$rest = $body_parse;
300
		    }
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
		    }
311
		    
312
		    // Telemetry
313
		    /*
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
		        // Nothing yet...
316
		    }
317
		    */
318
		    // DAO
319
		    
320
		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
321
			    
322
			    $dao = $matches[1];
323
			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
324
				$dao_split = str_split($dao);
325
			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
326
			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
327
			    
328
				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
329
				else $result['latitude'] += $lat_off;
330
				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
331
				else $result['longitude'] += $lon_off;
332
			    }
333
			    
334
		            $body_parse = substr($body_parse,6);
335
		    }
336
		    
337
		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
338
			$result['ident'] = $matches[1];
339
		    }
340
		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
341
			$result['squawk'] = $matches[1];
342
		    }
343
		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
344
			$result['aircraft_icao'] = $matches[1];
345
		    }
346
		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
347
			$result['typeid'] = $matches[1];
348
		    }
349
		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
350
			$result['imo'] = $matches[1];
351
		    }
352
		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
353
			$result['arrival_date'] = $matches[1];
354
		    }
355
		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
356
			$result['arrival_code'] = $matches[1];
357
		    }
358
		    // OGN comment
359
		   // echo "Before OGN : ".$body_parse."\n";
360
		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
361
		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
362
			$id = $matches[1];
363
			//$mode = substr($id,0,2);
364
			$address = substr($id,2);
365
			//print_r($matches);
366
			$addressType = (intval(substr($id,0,2),16))&3;
367
			if ($addressType == 0) $result['addresstype'] = "RANDOM";
368
			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
369
			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
370
			elseif ($addressType == 3) $result['addresstype'] = "OGN";
371
			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
372
			$result['aircrafttype_code'] = $aircraftType;
373
			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
374
			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
375
			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
376
			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
377
			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
378
			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
379
			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
380
			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
381
			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
382
			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
383
			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
384
			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
385
			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
386
			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
387
			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
388
			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
389
			$result['stealth'] = $stealth;
390
			$result['address'] = $address;
391
		    }
392
		    
393
		    //Comment
394
		    $result['comment'] = trim($body_parse);
395
		} else {
396
		    // parse weather
397
		    //$body_parse = substr($body_parse,1);
398
		    //$body_parse_len = strlen($body_parse);
399
400
		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
401
			    $result['wind_dir'] = intval($matches[1]);
402
			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
403
			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
404
			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
405
		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
406
		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
407
			$result['wind_dir'] = intval($matches[1]);
408
			$result['wind_speed'] = round($matches[2]*1.60934,1);
409
			$result['wind_gust'] = round($matches[3]*1.60934,1);
410
			$result['temp'] = round(5/9*(($matches[4])-32),1);
411
		        $body_parse = substr($body_parse,strlen($matches[0])+1);
412
		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
413
			$result['wind_dir'] = intval($matches[1]);
414
			$result['wind_speed'] = round($matches[2]*1.60934,1);
415
			$result['wind_gust'] = round($matches[3]*1.60934,1);
416
		        $body_parse = substr($body_parse,strlen($matches[0])+1);
417
		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
418
			$result['wind_dir'] = intval($matches[1]);
419
			$result['wind_speed'] = round($matches[2]*1.60934,1);
420
			$result['wind_gust'] = round($matches[3]*1.60934,1);
421
		        $body_parse = substr($body_parse,strlen($matches[0])+1);
422
		    }
423
		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
424
			$result['temp'] = round(5/9*(($matches[1])-32),1);
425
		    }
426
		}
427
		} else $result['comment'] = trim($body_parse);
428
429
	    }
430
	//}
431
	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
432
	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
433
	if ($debug) print_r($result);
434
	return $result;
435
    }
436
    
437
    public function connect() {
438
	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
439
	$aprs_connect = 0;
0 ignored issues
show
Unused Code introduced by
$aprs_connect is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
440
	$aprs_keep = 120;
0 ignored issues
show
Unused Code introduced by
$aprs_keep is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
441
	$aprs_last_tx = time();
0 ignored issues
show
Unused Code introduced by
$aprs_last_tx is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
442
	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
443
	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
444
	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
445
	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
446
	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
447
	else $aprs_pass = '-1';
448
	
449
	$aprs_filter  = '';
0 ignored issues
show
Unused Code introduced by
$aprs_filter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
450
	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
451
	$Common = new Common();
452
	$s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr);
453
	if ($s !== false) {
454
		echo 'Connected to APRS server! '."\n";
455
		$authstart = time();
456
		$this->socket = $s;
457
		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
0 ignored issues
show
Unused Code introduced by
$send is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
458
		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
459
			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
460
			    echo 'APRS user verified !'."\n";
461
			    $this->connected = true;
462
			    return true;
463
			    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
464
			}
465
			if (time()-$authstart > 5) {
466
			    echo 'APRS timeout'."\n";
467
			    break;
468
			}
469
		}
470
		socket_set_option($this->socket,SOL_SOCKET,SO_KEEPALIVE);
471
	}
472
    }
473
474
    public function disconnect() {
475
	socket_close($this->socket);
476
    }
477
    
478
    public function send($data) {
479
	if ($this->connected === false) $this->connect();
480
	$send = socket_send( $this->socket  , $data , strlen($data),0);
481
	if ($send === FALSE) {
482
		socket_close($this->socket);
483
		$this->connect();
484
	}
485
    }
486
}
487
488
class APRSSpotter extends APRS {
489
	public function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$altitude_real,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) {
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $departure_airport is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $arrival_airport is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $waypoints is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $altitude is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $departure_airport_time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $arrival_airport_time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $route_stop is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $putinarchive is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $registration is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $pilot_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $pilot_name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $verticalrate is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $noarchive is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $ground is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $format_source is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $source_name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $over_country is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
490
		$Common = new Common();
491
		if ($latitude != '' && $longitude != '') {
492
			$latitude = $Common->convertDM($latitude,'latitude');
493
			$longitude = $Common->convertDM($longitude,'longitude');
494
			$coordinate = sprintf("%02d",$latitude['deg']).str_pad(number_format($latitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d",$longitude['deg']).str_pad(number_format($longitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$longitude['NSEW'];
495
			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
496
			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
497
			$w = $w1.$w2;
498
			//$w = '00';
499
			$custom = '';
500
			if ($ident != '') {
501
				if ($custom != '') $custom .= '/';
502
				$custom .= 'CS='.$ident;
503
			}
504
			if ($squawk != '') {
505
				if ($custom != '') $custom .= '/';
506
				$custom .= 'SQ='.$squawk;
507
			}
508
			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
509
				if ($custom != '') $custom .= '/';
510
				$custom .= 'AI='.$aircraft_icao;
511
			}
512
			if ($custom != '') $custom = ' '.$custom;
513
			$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");
514
		}
515
	}
516
}
517
class APRSMarine extends APRS {
518
	public function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source,$source_name,$over_country) {
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $putinarchive is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $callsign is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $status is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $noarchive is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $format_source is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $source_name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $over_country is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
519
		$Common = new Common();
520
		if ($latitude != '' && $longitude != '') {
521
			$latitude = $Common->convertDM($latitude,'latitude');
522
			$longitude = $Common->convertDM($longitude,'longitude');
523
			$coordinate = sprintf("%02d",$latitude['deg']).str_pad(number_format($latitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d",$longitude['deg']).str_pad(number_format($longitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$longitude['NSEW'];
524
			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
525
			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
526
			$w = $w1.$w2;
527
			//$w = '00';
528
			$custom = '';
529
			if ($ident != '') {
530
				if ($custom != '') $custom .= '/';
531
				$custom .= 'CS='.$ident;
532
			}
533
			if ($typeid != '') {
534
				if ($custom != '') $custom .= '/';
535
				$custom .= 'TI='.$typeid;
536
			}
537
			if ($imo != '') {
538
				if ($custom != '') $custom .= '/';
539
				$custom .= 'IMO='.$imo;
540
			}
541
			if ($arrival_date != '') {
542
				if ($custom != '') $custom .= '/';
543
				$custom .= 'AD='.strtotime($arrival_date);
544
			}
545
			if ($arrival_code != '') {
546
				if ($custom != '') $custom .= '/';
547
				$custom .= 'AC='.$arrival_code;
548
			}
549
			if ($custom != '') $custom = ' '.$custom;
550
			$altitude = 0;
551
			$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");
552
		}
553
	}
554
}
555
?>