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