Completed
Push — master ( 416413...2c5ccc )
by Yannick
16:48 queued 08:22
created

aprs   D

Complexity

Total Complexity 100

Size/Duplication

Total Lines 470
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 470
rs 4.8717
c 0
b 0
f 0
wmc 100
lcom 2
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A urshift() 0 5 2
F parse() 0 333 87
C connect() 0 35 8
A send() 0 5 3

How to fix   Complexity   

Complex Class

Complex classes like aprs often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use aprs, and based on these observations, apply Extract Interface, too.

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'] = 'sbs';
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'] == 'sbs') {
162
			$result['hex'] = 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
			$body_parse = substr($body_parse,1);
273
			$body_parse_len = strlen($body_parse);
274
			$result['symbol_code'] = $symbol_code;
275
			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
276
			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...
277
			}
278
		    //$body_parse = substr($body_parse,1);
279
		    //$body_parse = trim($body_parse);
280
		    //$body_parse_len = strlen($body_parse);
281
		    if ($body_parse_len >= 7) {
282
			
283
		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
284
		    	    $course = substr($body_parse,0,3);
285
		    	    $tmp_s = intval($course);
286
		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
287
		    	    $speed = substr($body_parse,4,3);
288
		    	    if ($speed != '...') {
289
		    		    $result['speed'] = round($speed*1.852);
290
		    	    }
291
		    	    $body_parse = substr($body_parse,7);
292
		        }
293
		        // Check PHGR, PHG, RNG
294
		    } 
295
		    /*
296
		    else if ($body_parse_len > 0) {
297
			$rest = $body_parse;
298
		    }
299
		    */
300
		    if (strlen($body_parse) > 0) {
301
		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
302
		            $altitude = intval($matches[1]);
303
		            //$result['altitude'] = round($altitude*0.3048);
304
		            $result['altitude'] = $altitude;
305
		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
306
		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
307
		        }
308
		    }
309
		    
310
		    // Telemetry
311
		    /*
312
		    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)) {
313
		        // Nothing yet...
314
		    }
315
		    */
316
		    // DAO
317
		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
318
			    $dao = $matches[1];
319
			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
320
				$dao_split = str_split($dao);
321
			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
322
			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
323
			    
324
				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
325
				else $result['latitude'] += $lat_off;
326
				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
327
				else $result['longitude'] += $lon_off;
328
			    }
329
		            $body_parse = substr($body_parse,6);
330
		    }
331
		    
332
		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
333
			$result['ident'] = $matches[1];
334
		    }
335
		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
336
			$result['squawk'] = $matches[1];
337
		    }
338
		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
339
			$result['aircraft_icao'] = $matches[1];
340
		    }
341
		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
342
			$result['typeid'] = $matches[1];
343
		    }
344
		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
345
			$result['imo'] = $matches[1];
346
		    }
347
		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
348
			$result['arrival_date'] = $matches[1];
349
		    }
350
		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
351
			$result['arrival_code'] = $matches[1];
352
		    }
353
		    // OGN comment
354
		   // echo "Before OGN : ".$body_parse."\n";
355
		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
356
		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
357
			$id = $matches[1];
358
			//$mode = substr($id,0,2);
359
			$address = substr($id,2);
360
			//print_r($matches);
361
			$addressType = (intval(substr($id,0,2),16))&3;
362
			if ($addressType == 0) $result['addresstype'] = "RANDOM";
363
			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
364
			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
365
			elseif ($addressType == 3) $result['addresstype'] = "OGN";
366
			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
367
			$result['aircrafttype_code'] = $aircraftType;
368
			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
369
			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
370
			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
371
			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
372
			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
373
			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
374
			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
375
			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
376
			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
377
			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
378
			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
379
			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
380
			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
381
			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
382
			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
383
			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
384
			$result['stealth'] = $stealth;
385
			$result['address'] = $address;
386
		    }
387
		    
388
		    //Comment
389
		    $result['comment'] = trim($body_parse);
390
		} else {
391
		    // parse weather
392
		    //$body_parse = substr($body_parse,1);
393
		    //$body_parse_len = strlen($body_parse);
394
395
		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
396
			    $result['wind_dir'] = intval($matches[1]);
397
			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
398
			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
399
			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
400
		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
401
		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
402
			$result['wind_dir'] = intval($matches[1]);
403
			$result['wind_speed'] = round($matches[2]*1.60934,1);
404
			$result['wind_gust'] = round($matches[3]*1.60934,1);
405
			$result['temp'] = round(5/9*(($matches[4])-32),1);
406
		        $body_parse = substr($body_parse,strlen($matches[0])+1);
407
		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
408
			$result['wind_dir'] = intval($matches[1]);
409
			$result['wind_speed'] = round($matches[2]*1.60934,1);
410
			$result['wind_gust'] = round($matches[3]*1.60934,1);
411
		        $body_parse = substr($body_parse,strlen($matches[0])+1);
412
		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([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
		    }
418
		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
419
			$result['temp'] = round(5/9*(($matches[1])-32),1);
420
		    }
421
		}
422
		} else $result['comment'] = trim($body_parse);
423
424
	    }
425
	//}
426
	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
427
	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
428
	if ($debug) print_r($result);
429
	return $result;
430
    }
431
    
432
    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...
433
	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
434
	$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...
435
	$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...
436
	$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...
437
	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
438
	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
439
	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
440
	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
441
	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
442
	else $aprs_pass = '-1';
443
	
444
	$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...
445
	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
446
	$Common = new Common();
447
	$s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr);
448
	if ($s !== false) {
449
		echo 'Connected to APRS server! '."\n";
450
		$authstart = time();
451
		$this->socket = $s;
452
		$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...
453
		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
454
			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
455
			    echo 'APRS user verified !'."\n";
456
			    $this->connected = true;
457
			    return true;
458
			    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...
459
			}
460
			if (time()-$authstart > 5) {
461
			    echo 'APRS timeout'."\n";
462
			    break;
463
			}
464
		}
465
	}
466
    }
467
    
468
    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...
469
	if ($this->connected === false) $this->connect();
470
	$send = socket_send( $this->socket  , $data , strlen($data),0);
471
	if ($send === FALSE) $this->connect();
472
    }
473
}
474
475
class APRSSpotter extends APRS {
476
	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
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...
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...
477
		$Common = new Common();
478
		if ($latitude != '' && $longitude != '') {
479
			$latitude = $Common->convertDM($latitude,'latitude');
480
			$longitude = $Common->convertDM($longitude,'longitude');
481
			$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'];
482
			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
483
			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
484
			$w = $w1.$w2;
485
			//$w = '00';
486
			$custom = '';
487
			if ($ident != '') {
488
				if ($custom != '') $custom .= '/';
489
				$custom .= 'CS='.$ident;
490
			}
491
			if ($squawk != '') {
492
				if ($custom != '') $custom .= '/';
493
				$custom .= 'SQ='.$squawk;
494
			}
495
			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
496
				if ($custom != '') $custom .= '/';
497
				$custom .= 'AI='.$aircraft_icao;
498
			}
499
			if ($custom != '') $custom = ' '.$custom;
500
			$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_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
501
		}
502
	}
503
}
504
class APRSMarine extends APRS {
505
	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
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...
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...
506
		$Common = new Common();
507
		if ($latitude != '' && $longitude != '') {
508
			$latitude = $Common->convertDM($latitude,'latitude');
509
			$longitude = $Common->convertDM($longitude,'longitude');
510
			$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'];
511
			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
512
			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
513
			$w = $w1.$w2;
514
			//$w = '00';
515
			$custom = '';
516
			if ($ident != '') {
517
				if ($custom != '') $custom .= '/';
518
				$custom .= 'CS='.$ident;
519
			}
520
			if ($typeid != '') {
521
				if ($custom != '') $custom .= '/';
522
				$custom .= 'TI='.$typeid;
523
			}
524
			if ($imo != '') {
525
				if ($custom != '') $custom .= '/';
526
				$custom .= 'IMO='.$imo;
527
			}
528
			if ($arrival_date != '') {
529
				if ($custom != '') $custom .= '/';
530
				$custom .= 'AD='.strtotime($arrival_date);
531
			}
532
			if ($arrival_code != '') {
533
				if ($custom != '') $custom .= '/';
534
				$custom .= 'AC='.$arrival_code;
535
			}
536
			if ($custom != '') $custom = ' '.$custom;
537
			$altitude = 0;
538
			$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");
539
		}
540
	}
541
}
542
?>