Completed
Push — master ( 56221e...3c95ac )
by Yannick
07:57
created

aprs::connect()   C

Complexity

Conditions 8
Paths 40

Size

Total Lines 35
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 29
nc 40
nop 0
dl 0
loc 35
rs 5.3846
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
7
    protected $symbols = array('!' => 'Police',
8
	'#' => 'DIGI',
9
	'$' => 'Phone',
10
	'%' => 'DX Cluster',
11
	'&' => 'HF Gateway',
12
	"'" => 'Aircraft (small)',
13
	'(' => 'Cloudy',
14
	'*' => 'Snowmobile',
15
	'+' => 'Red Cross',
16
	',' => 'Reverse L Shape',
17
	'-' => 'House QTH (VHF)',
18
	'.' => 'X',
19
	'/' => 'Dot',
20
	'0' => '0',
21
	'1' => '1',
22
	'2' => '2',
23
	'3' => '3',
24
	'4' => '4',
25
	'5' => '5',
26
	'6' => '6',
27
	'7' => '7',
28
	'8' => '8',
29
	'9' => '9',
30
	':' => 'Fire',
31
	';' => 'Campground',
32
	'<' => 'Motorcycle',
33
	'=' => 'Railroad Engine',
34
	'>' => 'Car',
35
	'?' => 'Server for Files',
36
	'@' => 'HC Future Predict',
37
	'A' => 'Aid Station',
38
	'B' => 'BBS',
39
	'C' => 'Canoe',
40
	'E' => 'Eyeball',
41
	'G' => 'Grid Square',
42
	'H' => 'Hotel',
43
	'I' => 'TCP-IP',
44
	'K' => 'School',
45
	'M' => 'MacAPRS',
46
	'N' => 'NTS Station',
47
	'O' => 'Balloon',
48
	'P' => 'Police',
49
	'Q' => 'T.B.D.',
50
	'R' => 'Recreational Vehicle',
51
	'S' => 'Shuttle',
52
	'T' => 'SSTV',
53
	'U' => 'Bus',
54
	'V' => 'ATV',
55
	'W' => 'National Weather Service Site',
56
	'X' => 'Helicopter',
57
	'Y' => 'Yacht (Sail)',
58
	'Z' => 'WinAPRS',
59
	'[' => 'Jogger',
60
	']' => 'PBBS',
61
	'^' => 'Large Aircraft',
62
	'_' => 'Weather Station',
63
	'`' => 'Dish Antenna',
64
	'a' => 'Ambulance',
65
	'b' => 'Bike',
66
	'c' => 'T.B.D.',
67
	'd' => 'Dial Garage (Fire Department)',
68
	'e' => 'Horse (Equestrian)',
69
	'f' => 'Firetruck',
70
	'g' => 'Glider',
71
	'h' => 'Hospital',
72
	'i' => 'IOTA (Islands On The Air)',
73
	'j' => 'Jeep',
74
	'k' => 'Truck',
75
	'l' => 'Laptop',
76
	'm' => 'Mic-Repeater',
77
	'n' => 'Node',
78
	'o' => 'EOC',
79
	'p' => 'Rover (Puppy)',
80
	'q' => 'Grid SQ Shown Above 128 Miles',
81
	'r' => 'Antenna',
82
	's' => 'Ship (Power Boat)',
83
	't' => 'Truck Stop',
84
	'u' => 'Truck (18 Wheeler)',
85
	'v' => 'Van',
86
	'w' => 'Water Station',
87
	'x' => 'xAPRS (UNIX)',
88
	'y' => 'Yagi At QTH');
89
	
90
91
    private function urshift($n, $s) {
92
	return ($n >= 0) ? ($n >> $s) :
93
	    (($n & 0x7fffffff) >> $s) | 
94
		(0x40000000 >> ($s - 1));
95
    }
96
97
    public function parse($input) {
98
	global $globalDebug;
99
	$debug = false;
100
	$result = array();
101
	$input_len = strlen($input);
102
	//$split_input = str_split($input);
103
104
	/* Find the end of header checking for NULL bytes while doing it. */
105
	$splitpos = strpos($input,':');
106
	
107
	/* Check that end was found and body has at least one byte. */
108
	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
109
	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
	    return false;
111
	}
112
	
113
	if ($debug) echo 'input : '.$input."\n";
114
	/* Save header and body. */
115
	$body = substr($input,$splitpos+1,$input_len);
116
	$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...
117
	$header = substr($input,0,$splitpos);
118
	//$header_len = strlen($header);
119
	if ($debug) echo 'header : '.$header."\n";
120
	
121
	/* Parse source, target and path. */
122
	//FLRDF0A52>APRS,qAS,LSTB
123
	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
124
	    $ident = $matches[1];
125
	    $all_elements = $matches[2];
126
	    if ($debug) echo 'ident : '.$ident."\n";
127
	    $result['ident'] = $ident;
128
	} else return false;
129
	$elements = explode(',',$all_elements);
130
	$source = end($elements);
131
	$result['source'] = $source;
132
	foreach ($elements as $element) {
133
	    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...
134
	        //echo "ok";
135
	        //if ($element == 'TCPIP*') return false;
136
	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
137
		if ($debug) echo 'element : '.$element."\n";
138
		return false;
139
	    }
140
	    /*
141
	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
142
		//echo "ok";
143
	    } else {
144
	        return false;
145
	    }
146
	    */
147
	}
148
	
149
	$type = substr($body,0,1);
150
	if ($debug) echo 'type : '.$type."\n";
151
	if ($type == ';') {
152
		$result['ident'] = trim(substr($body,1,9));
153
	} elseif ($type == ',') {
154
		// Invalid data or test data
155
		return false;
156
	}
157
	
158
	// Check for Timestamp
159
	$find = false;
160
	$body_parse = substr($body,1);
161
	//echo 'Body : '.$body."\n";
162
	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
163
	    $body_parse = substr($body_parse,10);
164
	    $find = true;
165
	    //echo $body_parse."\n";
166
	}
167
	if (preg_match('/^`(.*)\//',$body,$matches)) {
168
	    $body_parse = substr($body_parse,strlen($matches[1])-1);
169
	    $find = true;
170
	    //echo $body_parse."\n";
171
	}
172
	if (preg_match("/^'(.*)\//",$body,$matches)) {
173
	    $body_parse = substr($body_parse,strlen($matches[1])-1);
174
	    $find = true;
175
	    //echo $body_parse."\n";
176
	}
177
	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
178
	    $find = true;
179
	    //print_r($matches);
180
	    $timestamp = $matches[0];
181
	    if ($matches[4] == 'h') {
182
		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
183
		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
184
		/*
185
		if (time() + 3900 < $timestamp) $timestamp -= 86400;
186
		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
187
		*/
188
	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
189
		// This work or not ?
190
		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
191
	    }
192
	    $body_parse = substr($body_parse,7);
193
	    $result['timestamp'] = $timestamp;
194
	    //echo date('Ymd H:i:s',$timestamp);
195
	}
196
	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
197
	    $find = true;
198
	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
199
	    $body_parse = substr($body_parse,8);
200
	    $result['timestamp'] = $timestamp;
201
	    //echo date('Ymd H:i:s',$timestamp);
202
	}
203
	//if (strlen($body_parse) > 19) {
204
	    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)) {
205
	    $find = true;
206
		// 4658.70N/00707.78Ez
207
		//print_r(str_split($body_parse));
208
		
209
		//$latlon = $matches[0];
210
		$sind = strtoupper($matches[3]);
211
		$wind = strtoupper($matches[7]);
212
		$lat_deg = $matches[1];
213
		$lat_min = $matches[2];
214
		$lon_deg = $matches[5];
215
		$lon_min = $matches[6];
216
	    
217
		//$symbol_table = $matches[4];
218
		$lat = intval($lat_deg);
219
		$lon = intval($lon_deg);
220
		if ($lat > 89 || $lon > 179) return false;
221
	    
222
	    /*
223
	    $tmp_5b = str_replace('.','',$lat_min);
224
	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
225
	        print_r($matches);
226
	    }
227
	    */
228
		$latitude = $lat + floatval($lat_min)/60;
229
		$longitude = $lon + floatval($lon_min)/60;
230
		if ($sind == 'S') $latitude = 0-$latitude;
231
		if ($wind == 'W') $longitude = 0-$longitude;
232
		$result['latitude'] = $latitude;
233
		$result['longitude'] = $longitude;
234
		$body_parse = substr($body_parse,18);
235
		$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...
236
	    }
237
	    $body_parse_len = strlen($body_parse);
238
	    if ($body_parse_len > 0) {
239
		/*
240
		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
241
			$body_split = str_split($body);
242
			$symbol_code = $body_split[0];
243
			$body_parse = substr($body,1);
244
			$body_parse_len = strlen($body_parse);
245
		} else { 
246
		*/
247
		/*
248
		if ($find === false) {
249
			$body_split = str_split($body);
250
			$symbol_code = $body_split[0];
251
			$body_parse = substr($body,1);
252
			$body_parse_len = strlen($body_parse);
253
		} else { 
254
		*/
255
		if ($find) {
256
			$body_split = str_split($body_parse);
257
			$symbol_code = $body_split[0];
258
		//}
259
		//echo $body_parse;
260
			if ($type != ';' && $type != '>') {
261
			$body_parse = substr($body_parse,1);
262
			$body_parse_len = strlen($body_parse);
263
			$result['symbol_code'] = $symbol_code;
264
			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
265
			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...
266
			}
267
		    //$body_parse = substr($body_parse,1);
268
		    //$body_parse = trim($body_parse);
269
		    //$body_parse_len = strlen($body_parse);
270
		    if ($body_parse_len >= 7) {
271
			
272
		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
273
		    	    $course = substr($body_parse,0,3);
274
		    	    $tmp_s = intval($course);
275
		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
276
		    	    $speed = substr($body_parse,4,3);
277
		    	    if ($speed != '...') {
278
		    		    $result['speed'] = round($speed*1.852);
279
		    	    }
280
		    	    $body_parse = substr($body_parse,7);
281
		        }
282
		        // Check PHGR, PHG, RNG
283
		    } 
284
		    /*
285
		    else if ($body_parse_len > 0) {
286
			$rest = $body_parse;
287
		    }
288
		    */
289
		    if (strlen($body_parse) > 0) {
290
		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
291
		            $altitude = intval($matches[1]);
292
		            //$result['altitude'] = round($altitude*0.3048);
293
		            $result['altitude'] = $altitude;
294
		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
295
		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
296
		        }
297
		    }
298
		    
299
		    // Telemetry
300
		    /*
301
		    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)) {
302
		        // Nothing yet...
303
		    }
304
		    */
305
		    // DAO
306
		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
307
			    $dao = $matches[1];
308
			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
309
				$dao_split = str_split($dao);
310
			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
311
			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
312
			    
313
				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
314
				else $result['latitude'] += $lat_off;
315
				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
316
				else $result['longitude'] += $lon_off;
317
			    }
318
		            $body_parse = substr($body_parse,6);
319
		    }
320
		    
321
		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
322
			$result['callsign'] = $matches[1];
323
		    }
324
		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
325
			$result['squawk'] = $matches[1];
326
		    }
327
		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
328
			$result['aircraft_icao'] = $matches[1];
329
		    }
330
		    // OGN comment
331
		   // echo "Before OGN : ".$body_parse."\n";
332
		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
333
		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
334
			$id = $matches[1];
335
			//$mode = substr($id,0,2);
336
			$address = substr($id,2);
337
			//print_r($matches);
338
			$addressType = (intval(substr($id,0,2),16))&3;
339
			if ($addressType == 0) $result['addresstype'] = "RANDOM";
340
			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
341
			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
342
			elseif ($addressType == 3) $result['addresstype'] = "OGN";
343
			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
344
			$result['aircrafttype_code'] = $aircraftType;
345
			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
346
			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
347
			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
348
			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
349
			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
350
			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
351
			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
352
			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
353
			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
354
			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
355
			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
356
			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
357
			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
358
			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
359
			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
360
			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
361
			$result['stealth'] = $stealth;
362
			$result['address'] = $address;
363
		    }
364
		    
365
		    //Comment
366
		    $result['comment'] = trim($body_parse);
367
		} else {
368
		    // parse weather
369
		    //$body_parse = substr($body_parse,1);
370
		    //$body_parse_len = strlen($body_parse);
371
372
		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
373
			    $result['wind_dir'] = intval($matches[1]);
374
			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
375
			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
376
			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
377
		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
378
		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
379
			$result['wind_dir'] = intval($matches[1]);
380
			$result['wind_speed'] = round($matches[2]*1.60934,1);
381
			$result['wind_gust'] = round($matches[3]*1.60934,1);
382
			$result['temp'] = round(5/9*(($matches[4])-32),1);
383
		        $body_parse = substr($body_parse,strlen($matches[0])+1);
384
		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
385
			$result['wind_dir'] = intval($matches[1]);
386
			$result['wind_speed'] = round($matches[2]*1.60934,1);
387
			$result['wind_gust'] = round($matches[3]*1.60934,1);
388
		        $body_parse = substr($body_parse,strlen($matches[0])+1);
389
		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
390
			$result['wind_dir'] = intval($matches[1]);
391
			$result['wind_speed'] = round($matches[2]*1.60934,1);
392
			$result['wind_gust'] = round($matches[3]*1.60934,1);
393
		        $body_parse = substr($body_parse,strlen($matches[0])+1);
394
		    }
395
		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
396
			$result['temp'] = round(5/9*(($matches[1])-32),1);
397
		    }
398
		}
399
		} else $result['comment'] = trim($body_parse);
400
401
	    }
402
	//}
403
	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
404
	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
405
	if ($debug) print_r($result);
406
	return $result;
407
    }
408
    
409
    function connect() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
410
	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
411
	$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...
412
	$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...
413
	$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...
414
	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
415
	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
416
	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
417
	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
418
	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
419
	else $aprs_pass = '-1';
420
	
421
	$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...
422
	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
423
	$Common = new Common();
424
	$s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr);
425
	if ($s !== false) {
426
		echo 'Connected to APRS server! '."\n";
427
		$authstart = time();
428
		$this->socket = $s;
429
		$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...
430
		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
431
			echo $msgin."\n";
432
			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
433
			    echo 'Verified !';
434
			    return true;
435
			    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...
436
			}
437
			if (time()-$authstart > 5) {
438
			    echo 'Timeout';
439
			    break;
440
			}
441
		}
442
	}
443
    }
444
    
445
    function send($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
446
	$send = socket_send( $this->socket  , $data , strlen($data),0);
447
	if ($send === FALSE) $this->connect();
448
    }
449
}
450
451
class APRSSpotter extends APRS {
452
	function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$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 $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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
453
		$Common = new Common();
454
		if ($latitude != '' && $longitude != '') {
455
		$latitude = $Common->convertDM($latitude,'latitude');
456
		$longitude = $Common->convertDM($longitude,'longitude');
457
		$coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW'];
458
		$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
459
		$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
460
		$w = $w1.$w2;
461
		//$w = '00';
462
		$custom = '';
463
		if ($ident != '') {
464
			if ($custom != '') $custom .= '/';
465
			$custom .= 'CS='.$ident;
466
		}
467
		if ($squawk != '') {
468
			if ($custom != '') $custom .= '/';
469
			$custom .= 'SQ='.$squawk;
470
		}
471
		if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
472
			if ($custom != '') $custom .= '/';
473
			$custom .= 'AI='.$aircraft_icao;
474
		}
475
		if ($custom != '') $custom = ' '.$custom;
476
			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.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");
477
		}
478
	}
479
}
480
class APRSMarine extends APRS {
481
	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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
482
		$Common = new Common();
483
		if ($latitude != '' && $longitude != '') {
484
		$latitude = $Common->convertDM($latitude,'latitude');
485
		$longitude = $Common->convertDM($longitude,'longitude');
486
		$coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW'];
487
		$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
488
		$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
489
		$w = $w1.$w2;
490
		//$w = '00';
491
		$custom = '';
492
		if ($ident != '') {
493
			if ($custom != '') $custom .= '/';
494
			$custom .= 'CS='.$ident;
495
		}
496
		if ($typeid != '') {
497
			if ($custom != '') $custom .= '/';
498
			$custom .= 'TI='.$typeid;
499
		}
500
		if ($imo != '') {
501
			if ($custom != '') $custom .= '/';
502
			$custom .= 'IMO='.$imo;
503
		}
504
		if ($arrival_date != '') {
505
			if ($custom != '') $custom .= '/';
506
			$custom .= 'AD='.$arrival_date;
507
		}
508
		if ($arrival_code != '') {
509
			if ($custom != '') $custom .= '/';
510
			$custom .= 'AC='.$arrival_code;
511
		}
512
		if ($custom != '') $custom = ' '.$custom;
513
		$altitude = 0;
514
			$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");
515
		}
516
	}
517
}
518
?>