@@ -19,47 +19,47 @@ discard block |
||
19 | 19 | // Check if schema is at latest version |
20 | 20 | $Connection = new Connection(); |
21 | 21 | if ($Connection->latest() === false) { |
22 | - echo "You MUST update to latest schema. Run install/index.php"; |
|
23 | - exit(); |
|
22 | + echo "You MUST update to latest schema. Run install/index.php"; |
|
23 | + exit(); |
|
24 | 24 | } |
25 | 25 | if (PHP_SAPI != 'cli') { |
26 | - echo "This script MUST be called from console, not a web browser."; |
|
26 | + echo "This script MUST be called from console, not a web browser."; |
|
27 | 27 | // exit(); |
28 | 28 | } |
29 | 29 | |
30 | 30 | // This is to be compatible with old version of settings.php |
31 | 31 | if (!isset($globalSources)) { |
32 | - if (isset($globalSBS1Hosts)) { |
|
33 | - //$hosts = $globalSBS1Hosts; |
|
34 | - foreach ($globalSBS1Hosts as $host) { |
|
35 | - $globalSources[] = array('host' => $host); |
|
36 | - } |
|
37 | - } else { |
|
38 | - if (!isset($globalSBS1Host)) { |
|
39 | - echo '$globalSources MUST be defined !'; |
|
40 | - die; |
|
32 | + if (isset($globalSBS1Hosts)) { |
|
33 | + //$hosts = $globalSBS1Hosts; |
|
34 | + foreach ($globalSBS1Hosts as $host) { |
|
35 | + $globalSources[] = array('host' => $host); |
|
36 | + } |
|
37 | + } else { |
|
38 | + if (!isset($globalSBS1Host)) { |
|
39 | + echo '$globalSources MUST be defined !'; |
|
40 | + die; |
|
41 | 41 | } |
42 | 42 | //$hosts = array($globalSBS1Host.':'.$globalSBS1Port); |
43 | 43 | $globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port); |
44 | - } |
|
44 | + } |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $options = getopt('s::',array('source::','server','idsource::')); |
48 | 48 | //if (isset($options['s'])) $hosts = array($options['s']); |
49 | 49 | //elseif (isset($options['source'])) $hosts = array($options['source']); |
50 | 50 | if (isset($options['s'])) { |
51 | - $globalSources = array(); |
|
52 | - $globalSources[] = array('host' => $options['s']); |
|
51 | + $globalSources = array(); |
|
52 | + $globalSources[] = array('host' => $options['s']); |
|
53 | 53 | } elseif (isset($options['source'])) { |
54 | - $globalSources = array(); |
|
55 | - $globalSources[] = array('host' => $options['source']); |
|
54 | + $globalSources = array(); |
|
55 | + $globalSources[] = array('host' => $options['source']); |
|
56 | 56 | } |
57 | 57 | if (isset($options['server'])) $globalServer = TRUE; |
58 | 58 | if (isset($options['idsource'])) $id_source = $options['idsource']; |
59 | 59 | else $id_source = 1; |
60 | 60 | if (isset($globalServer) && $globalServer) { |
61 | - if ($globalDebug) echo "Using Server Mode\n"; |
|
62 | - $SI=new SpotterServer(); |
|
61 | + if ($globalDebug) echo "Using Server Mode\n"; |
|
62 | + $SI=new SpotterServer(); |
|
63 | 63 | } else $SI=new SpotterImport($Connection->db); |
64 | 64 | //$APRS=new APRS($Connection->db); |
65 | 65 | $SBS=new SBS(); |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | //$servertz = system('date +%Z'); |
70 | 70 | // signal handler - playing nice with sockets and dump1090 |
71 | 71 | if (function_exists('pcntl_fork')) { |
72 | - pcntl_signal(SIGINT, function() { |
|
73 | - global $sockets; |
|
74 | - echo "\n\nctrl-c or kill signal received. Tidying up ... "; |
|
75 | - die("Bye!\n"); |
|
76 | - }); |
|
77 | - pcntl_signal_dispatch(); |
|
72 | + pcntl_signal(SIGINT, function() { |
|
73 | + global $sockets; |
|
74 | + echo "\n\nctrl-c or kill signal received. Tidying up ... "; |
|
75 | + die("Bye!\n"); |
|
76 | + }); |
|
77 | + pcntl_signal_dispatch(); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | // let's try and connect |
@@ -84,162 +84,162 @@ discard block |
||
84 | 84 | $reset = 0; |
85 | 85 | |
86 | 86 | function create_socket($host, $port, &$errno, &$errstr) { |
87 | - $ip = gethostbyname($host); |
|
88 | - $s = socket_create(AF_INET, SOCK_STREAM, 0); |
|
89 | - $r = @socket_connect($s, $ip, $port); |
|
90 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
91 | - if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
|
92 | - return $s; |
|
93 | - } |
|
94 | - $errno = socket_last_error($s); |
|
95 | - $errstr = socket_strerror($errno); |
|
96 | - socket_close($s); |
|
97 | - return false; |
|
87 | + $ip = gethostbyname($host); |
|
88 | + $s = socket_create(AF_INET, SOCK_STREAM, 0); |
|
89 | + $r = @socket_connect($s, $ip, $port); |
|
90 | + if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
91 | + if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
|
92 | + return $s; |
|
93 | + } |
|
94 | + $errno = socket_last_error($s); |
|
95 | + $errstr = socket_strerror($errno); |
|
96 | + socket_close($s); |
|
97 | + return false; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | function create_socket_udp($host, $port, &$errno, &$errstr) { |
101 | - echo "Create an UDP socket...\n"; |
|
102 | - $ip = gethostbyname($host); |
|
103 | - $s = socket_create(AF_INET, SOCK_DGRAM, 0); |
|
104 | - $r = @socket_bind($s, $ip, $port); |
|
105 | - if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
|
106 | - return $s; |
|
107 | - } |
|
108 | - $errno = socket_last_error($s); |
|
109 | - $errstr = socket_strerror($errno); |
|
110 | - socket_close($s); |
|
111 | - return false; |
|
101 | + echo "Create an UDP socket...\n"; |
|
102 | + $ip = gethostbyname($host); |
|
103 | + $s = socket_create(AF_INET, SOCK_DGRAM, 0); |
|
104 | + $r = @socket_bind($s, $ip, $port); |
|
105 | + if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
|
106 | + return $s; |
|
107 | + } |
|
108 | + $errno = socket_last_error($s); |
|
109 | + $errstr = socket_strerror($errno); |
|
110 | + socket_close($s); |
|
111 | + return false; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | function connect_all($hosts) { |
115 | - //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
|
116 | - global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset; |
|
117 | - $reset++; |
|
118 | - if ($globalDebug) echo 'Connect to all...'."\n"; |
|
119 | - foreach ($hosts as $id => $value) { |
|
115 | + //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
|
116 | + global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset; |
|
117 | + $reset++; |
|
118 | + if ($globalDebug) echo 'Connect to all...'."\n"; |
|
119 | + foreach ($hosts as $id => $value) { |
|
120 | 120 | $host = $value['host']; |
121 | 121 | $globalSources[$id]['last_exec'] = 0; |
122 | 122 | // Here we check type of source(s) |
123 | 123 | if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
124 | - if (preg_match('/deltadb.txt$/i',$host)) { |
|
125 | - //$formats[$id] = 'deltadbtxt'; |
|
126 | - $globalSources[$id]['format'] = 'deltadbtxt'; |
|
127 | - //$last_exec['deltadbtxt'] = 0; |
|
128 | - if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
|
129 | - } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
|
130 | - //$formats[$id] = 'vatsimtxt'; |
|
131 | - $globalSources[$id]['format'] = 'vatsimtxt'; |
|
132 | - //$last_exec['vatsimtxt'] = 0; |
|
133 | - if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
|
134 | - } else if (preg_match('/aircraftlist.json$/i',$host)) { |
|
135 | - //$formats[$id] = 'aircraftlistjson'; |
|
136 | - $globalSources[$id]['format'] = 'aircraftlistjson'; |
|
137 | - //$last_exec['aircraftlistjson'] = 0; |
|
138 | - if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
139 | - } else if (preg_match('/opensky/i',$host)) { |
|
140 | - //$formats[$id] = 'aircraftlistjson'; |
|
141 | - $globalSources[$id]['format'] = 'opensky'; |
|
142 | - //$last_exec['aircraftlistjson'] = 0; |
|
143 | - if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
|
144 | - } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
|
145 | - //$formats[$id] = 'radarvirtueljson'; |
|
146 | - $globalSources[$id]['format'] = 'radarvirtueljson'; |
|
147 | - //$last_exec['radarvirtueljson'] = 0; |
|
148 | - if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
149 | - if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
150 | - echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
151 | - exit(0); |
|
152 | - } |
|
153 | - } else if (preg_match('/planeUpdateFAA.php$/i',$host)) { |
|
154 | - //$formats[$id] = 'planeupdatefaa'; |
|
155 | - $globalSources[$id]['format'] = 'planeupdatefaa'; |
|
156 | - //$last_exec['planeupdatefaa'] = 0; |
|
157 | - if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
158 | - if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
159 | - echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
160 | - exit(0); |
|
161 | - } |
|
162 | - } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { |
|
163 | - //$formats[$id] = 'phpvmacars'; |
|
164 | - $globalSources[$id]['format'] = 'phpvmacars'; |
|
165 | - //$last_exec['phpvmacars'] = 0; |
|
166 | - if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
|
167 | - } else if (preg_match('/VAM-json.php$/i',$host)) { |
|
168 | - //$formats[$id] = 'phpvmacars'; |
|
169 | - $globalSources[$id]['format'] = 'vam'; |
|
170 | - if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
|
171 | - } else if (preg_match('/whazzup/i',$host)) { |
|
172 | - //$formats[$id] = 'whazzup'; |
|
173 | - $globalSources[$id]['format'] = 'whazzup'; |
|
174 | - //$last_exec['whazzup'] = 0; |
|
175 | - if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
|
176 | - } else if (preg_match('/recentpireps/i',$host)) { |
|
177 | - //$formats[$id] = 'pirepsjson'; |
|
178 | - $globalSources[$id]['format'] = 'pirepsjson'; |
|
179 | - //$last_exec['pirepsjson'] = 0; |
|
180 | - if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
|
181 | - } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
|
182 | - //$formats[$id] = 'fr24json'; |
|
183 | - $globalSources[$id]['format'] = 'fr24json'; |
|
184 | - //$last_exec['fr24json'] = 0; |
|
185 | - if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; |
|
186 | - if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
187 | - echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
188 | - exit(0); |
|
189 | - } |
|
190 | - //} else if (preg_match('/10001/',$host)) { |
|
191 | - } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
192 | - //$formats[$id] = 'tsv'; |
|
193 | - $globalSources[$id]['format'] = 'tsv'; |
|
194 | - if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
|
195 | - } |
|
196 | - } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
|
197 | - if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
198 | - } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
|
199 | - $hostport = explode(':',$host); |
|
200 | - if (isset($hostport[1])) { |
|
124 | + if (preg_match('/deltadb.txt$/i',$host)) { |
|
125 | + //$formats[$id] = 'deltadbtxt'; |
|
126 | + $globalSources[$id]['format'] = 'deltadbtxt'; |
|
127 | + //$last_exec['deltadbtxt'] = 0; |
|
128 | + if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
|
129 | + } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
|
130 | + //$formats[$id] = 'vatsimtxt'; |
|
131 | + $globalSources[$id]['format'] = 'vatsimtxt'; |
|
132 | + //$last_exec['vatsimtxt'] = 0; |
|
133 | + if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
|
134 | + } else if (preg_match('/aircraftlist.json$/i',$host)) { |
|
135 | + //$formats[$id] = 'aircraftlistjson'; |
|
136 | + $globalSources[$id]['format'] = 'aircraftlistjson'; |
|
137 | + //$last_exec['aircraftlistjson'] = 0; |
|
138 | + if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
139 | + } else if (preg_match('/opensky/i',$host)) { |
|
140 | + //$formats[$id] = 'aircraftlistjson'; |
|
141 | + $globalSources[$id]['format'] = 'opensky'; |
|
142 | + //$last_exec['aircraftlistjson'] = 0; |
|
143 | + if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
|
144 | + } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
|
145 | + //$formats[$id] = 'radarvirtueljson'; |
|
146 | + $globalSources[$id]['format'] = 'radarvirtueljson'; |
|
147 | + //$last_exec['radarvirtueljson'] = 0; |
|
148 | + if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
149 | + if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
150 | + echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
151 | + exit(0); |
|
152 | + } |
|
153 | + } else if (preg_match('/planeUpdateFAA.php$/i',$host)) { |
|
154 | + //$formats[$id] = 'planeupdatefaa'; |
|
155 | + $globalSources[$id]['format'] = 'planeupdatefaa'; |
|
156 | + //$last_exec['planeupdatefaa'] = 0; |
|
157 | + if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
158 | + if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
159 | + echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
160 | + exit(0); |
|
161 | + } |
|
162 | + } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { |
|
163 | + //$formats[$id] = 'phpvmacars'; |
|
164 | + $globalSources[$id]['format'] = 'phpvmacars'; |
|
165 | + //$last_exec['phpvmacars'] = 0; |
|
166 | + if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
|
167 | + } else if (preg_match('/VAM-json.php$/i',$host)) { |
|
168 | + //$formats[$id] = 'phpvmacars'; |
|
169 | + $globalSources[$id]['format'] = 'vam'; |
|
170 | + if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
|
171 | + } else if (preg_match('/whazzup/i',$host)) { |
|
172 | + //$formats[$id] = 'whazzup'; |
|
173 | + $globalSources[$id]['format'] = 'whazzup'; |
|
174 | + //$last_exec['whazzup'] = 0; |
|
175 | + if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
|
176 | + } else if (preg_match('/recentpireps/i',$host)) { |
|
177 | + //$formats[$id] = 'pirepsjson'; |
|
178 | + $globalSources[$id]['format'] = 'pirepsjson'; |
|
179 | + //$last_exec['pirepsjson'] = 0; |
|
180 | + if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
|
181 | + } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
|
182 | + //$formats[$id] = 'fr24json'; |
|
183 | + $globalSources[$id]['format'] = 'fr24json'; |
|
184 | + //$last_exec['fr24json'] = 0; |
|
185 | + if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; |
|
186 | + if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
187 | + echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
188 | + exit(0); |
|
189 | + } |
|
190 | + //} else if (preg_match('/10001/',$host)) { |
|
191 | + } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
192 | + //$formats[$id] = 'tsv'; |
|
193 | + $globalSources[$id]['format'] = 'tsv'; |
|
194 | + if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
|
195 | + } |
|
196 | + } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
|
197 | + if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
198 | + } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
|
199 | + $hostport = explode(':',$host); |
|
200 | + if (isset($hostport[1])) { |
|
201 | 201 | $port = $hostport[1]; |
202 | 202 | $hostn = $hostport[0]; |
203 | - } else { |
|
203 | + } else { |
|
204 | 204 | $port = $globalSources[$id]['port']; |
205 | 205 | $hostn = $globalSources[$id]['host']; |
206 | - } |
|
207 | - if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { |
|
208 | - $s = create_socket($hostn,$port, $errno, $errstr); |
|
209 | - } else { |
|
210 | - $s = create_socket_udp($hostn,$port, $errno, $errstr); |
|
211 | - } |
|
212 | - if ($s) { |
|
213 | - $sockets[$id] = $s; |
|
214 | - if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { |
|
215 | - if (preg_match('/aprs/',$hostn)) { |
|
206 | + } |
|
207 | + if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { |
|
208 | + $s = create_socket($hostn,$port, $errno, $errstr); |
|
209 | + } else { |
|
210 | + $s = create_socket_udp($hostn,$port, $errno, $errstr); |
|
211 | + } |
|
212 | + if ($s) { |
|
213 | + $sockets[$id] = $s; |
|
214 | + if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { |
|
215 | + if (preg_match('/aprs/',$hostn)) { |
|
216 | 216 | //$formats[$id] = 'aprs'; |
217 | 217 | $globalSources[$id]['format'] = 'aprs'; |
218 | 218 | //$aprs_connect = 0; |
219 | 219 | //$use_aprs = true; |
220 | - } elseif ($port == '10001') { |
|
221 | - //$formats[$id] = 'tsv'; |
|
222 | - $globalSources[$id]['format'] = 'tsv'; |
|
223 | - } elseif ($port == '30002') { |
|
224 | - //$formats[$id] = 'raw'; |
|
225 | - $globalSources[$id]['format'] = 'raw'; |
|
226 | - } elseif ($port == '5001') { |
|
227 | - //$formats[$id] = 'raw'; |
|
228 | - $globalSources[$id]['format'] = 'flightgearmp'; |
|
229 | - } elseif ($port == '30005') { |
|
220 | + } elseif ($port == '10001') { |
|
221 | + //$formats[$id] = 'tsv'; |
|
222 | + $globalSources[$id]['format'] = 'tsv'; |
|
223 | + } elseif ($port == '30002') { |
|
224 | + //$formats[$id] = 'raw'; |
|
225 | + $globalSources[$id]['format'] = 'raw'; |
|
226 | + } elseif ($port == '5001') { |
|
227 | + //$formats[$id] = 'raw'; |
|
228 | + $globalSources[$id]['format'] = 'flightgearmp'; |
|
229 | + } elseif ($port == '30005') { |
|
230 | 230 | // Not yet supported |
231 | - //$formats[$id] = 'beast'; |
|
232 | - $globalSources[$id]['format'] = 'beast'; |
|
233 | - //} else $formats[$id] = 'sbs'; |
|
234 | - } else $globalSources[$id]['format'] = 'sbs'; |
|
235 | - //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; |
|
231 | + //$formats[$id] = 'beast'; |
|
232 | + $globalSources[$id]['format'] = 'beast'; |
|
233 | + //} else $formats[$id] = 'sbs'; |
|
234 | + } else $globalSources[$id]['format'] = 'sbs'; |
|
235 | + //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; |
|
236 | 236 | } |
237 | 237 | if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
238 | - } else { |
|
238 | + } else { |
|
239 | 239 | if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
240 | - } |
|
241 | - } |
|
242 | - } |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | 243 | } |
244 | 244 | if (!isset($globalMinFetch)) $globalMinFetch = 15; |
245 | 245 | |
@@ -266,18 +266,18 @@ discard block |
||
266 | 266 | die; |
267 | 267 | } |
268 | 268 | foreach ($globalSources as $key => $source) { |
269 | - if (!isset($source['format'])) { |
|
270 | - $globalSources[$key]['format'] = 'auto'; |
|
271 | - } |
|
269 | + if (!isset($source['format'])) { |
|
270 | + $globalSources[$key]['format'] = 'auto'; |
|
271 | + } |
|
272 | 272 | } |
273 | 273 | connect_all($globalSources); |
274 | 274 | foreach ($globalSources as $key => $source) { |
275 | - if (isset($source['format']) && $source['format'] == 'aprs') { |
|
275 | + if (isset($source['format']) && $source['format'] == 'aprs') { |
|
276 | 276 | $aprs_connect = 0; |
277 | 277 | $use_aprs = true; |
278 | 278 | if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true; |
279 | 279 | break; |
280 | - } |
|
280 | + } |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | if ($use_aprs) { |
@@ -316,70 +316,70 @@ discard block |
||
316 | 316 | |
317 | 317 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
318 | 318 | while ($i > 0) { |
319 | - if (!$globalDaemon) $i = $endtime-time(); |
|
320 | - // Delete old ATC |
|
321 | - if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
|
319 | + if (!$globalDaemon) $i = $endtime-time(); |
|
320 | + // Delete old ATC |
|
321 | + if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
|
322 | 322 | if ($globalDebug) echo 'Delete old ATC...'."\n"; |
323 | - $ATC->deleteOldATC(); |
|
324 | - } |
|
323 | + $ATC->deleteOldATC(); |
|
324 | + } |
|
325 | 325 | |
326 | - if (count($last_exec) > 0) { |
|
326 | + if (count($last_exec) > 0) { |
|
327 | 327 | $max = $globalMinFetch; |
328 | 328 | foreach ($last_exec as $last) { |
329 | - if ((time() - $last['last']) < $max) $max = time() - $last['last']; |
|
329 | + if ((time() - $last['last']) < $max) $max = time() - $last['last']; |
|
330 | 330 | } |
331 | 331 | if ($max != $globalMinFetch) { |
332 | - if ($globalDebug) echo 'Sleeping...'."\n"; |
|
333 | - sleep($globalMinFetch-$max+2); |
|
332 | + if ($globalDebug) echo 'Sleeping...'."\n"; |
|
333 | + sleep($globalMinFetch-$max+2); |
|
334 | + } |
|
334 | 335 | } |
335 | - } |
|
336 | 336 | |
337 | 337 | |
338 | - //foreach ($formats as $id => $value) { |
|
339 | - foreach ($globalSources as $id => $value) { |
|
338 | + //foreach ($formats as $id => $value) { |
|
339 | + foreach ($globalSources as $id => $value) { |
|
340 | 340 | date_default_timezone_set('UTC'); |
341 | 341 | if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0; |
342 | 342 | if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
343 | - //$buffer = $Common->getData($hosts[$id]); |
|
344 | - $buffer = $Common->getData($value['host']); |
|
345 | - if ($buffer != '') $reset = 0; |
|
346 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
347 | - $buffer = explode('\n',$buffer); |
|
348 | - foreach ($buffer as $line) { |
|
349 | - if ($line != '' && count($line) > 7) { |
|
350 | - $line = explode(',', $line); |
|
351 | - $data = array(); |
|
352 | - $data['hex'] = $line[1]; // hex |
|
353 | - $data['ident'] = $line[2]; // ident |
|
354 | - if (isset($line[3])) $data['altitude'] = $line[3]; // altitude |
|
355 | - if (isset($line[4])) $data['speed'] = $line[4]; // speed |
|
356 | - if (isset($line[5])) $data['heading'] = $line[5]; // heading |
|
357 | - if (isset($line[6])) $data['latitude'] = $line[6]; // lat |
|
358 | - if (isset($line[7])) $data['longitude'] = $line[7]; // long |
|
359 | - $data['verticalrate'] = ''; // vertical rate |
|
360 | - //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk |
|
361 | - $data['emergency'] = ''; // emergency |
|
362 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
363 | - $data['format_source'] = 'deltadbtxt'; |
|
364 | - $data['id_source'] = $id_source; |
|
365 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
366 | - if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats']; |
|
367 | - $SI->add($data); |
|
368 | - unset($data); |
|
369 | - } |
|
370 | - } |
|
371 | - $last_exec[$id]['last'] = time(); |
|
343 | + //$buffer = $Common->getData($hosts[$id]); |
|
344 | + $buffer = $Common->getData($value['host']); |
|
345 | + if ($buffer != '') $reset = 0; |
|
346 | + $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
347 | + $buffer = explode('\n',$buffer); |
|
348 | + foreach ($buffer as $line) { |
|
349 | + if ($line != '' && count($line) > 7) { |
|
350 | + $line = explode(',', $line); |
|
351 | + $data = array(); |
|
352 | + $data['hex'] = $line[1]; // hex |
|
353 | + $data['ident'] = $line[2]; // ident |
|
354 | + if (isset($line[3])) $data['altitude'] = $line[3]; // altitude |
|
355 | + if (isset($line[4])) $data['speed'] = $line[4]; // speed |
|
356 | + if (isset($line[5])) $data['heading'] = $line[5]; // heading |
|
357 | + if (isset($line[6])) $data['latitude'] = $line[6]; // lat |
|
358 | + if (isset($line[7])) $data['longitude'] = $line[7]; // long |
|
359 | + $data['verticalrate'] = ''; // vertical rate |
|
360 | + //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk |
|
361 | + $data['emergency'] = ''; // emergency |
|
362 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
363 | + $data['format_source'] = 'deltadbtxt'; |
|
364 | + $data['id_source'] = $id_source; |
|
365 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
366 | + if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats']; |
|
367 | + $SI->add($data); |
|
368 | + unset($data); |
|
369 | + } |
|
370 | + } |
|
371 | + $last_exec[$id]['last'] = time(); |
|
372 | 372 | //} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) { |
373 | 373 | } elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) { |
374 | - //$buffer = $Common->getData($hosts[$id]); |
|
375 | - $buffer = $Common->getData($value['host']); |
|
376 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
377 | - $buffer = explode('\n',$buffer); |
|
378 | - $reset = 0; |
|
379 | - foreach ($buffer as $line) { |
|
380 | - if ($line != '') { |
|
381 | - $line = explode(':', $line); |
|
382 | - if (count($line) > 30 && $line[0] != 'callsign') { |
|
374 | + //$buffer = $Common->getData($hosts[$id]); |
|
375 | + $buffer = $Common->getData($value['host']); |
|
376 | + $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
377 | + $buffer = explode('\n',$buffer); |
|
378 | + $reset = 0; |
|
379 | + foreach ($buffer as $line) { |
|
380 | + if ($line != '') { |
|
381 | + $line = explode(':', $line); |
|
382 | + if (count($line) > 30 && $line[0] != 'callsign') { |
|
383 | 383 | $data = array(); |
384 | 384 | if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
385 | 385 | else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
@@ -392,36 +392,36 @@ discard block |
||
392 | 392 | if (isset($line[45])) $data['heading'] = $line[45]; // heading |
393 | 393 | elseif (isset($line[38])) $data['heading'] = $line[38]; // heading |
394 | 394 | $data['latitude'] = $line[5]; // lat |
395 | - $data['longitude'] = $line[6]; // long |
|
396 | - $data['verticalrate'] = ''; // vertical rate |
|
397 | - $data['squawk'] = ''; // squawk |
|
398 | - $data['emergency'] = ''; // emergency |
|
399 | - $data['waypoints'] = $line[30]; |
|
395 | + $data['longitude'] = $line[6]; // long |
|
396 | + $data['verticalrate'] = ''; // vertical rate |
|
397 | + $data['squawk'] = ''; // squawk |
|
398 | + $data['emergency'] = ''; // emergency |
|
399 | + $data['waypoints'] = $line[30]; |
|
400 | 400 | $data['datetime'] = date('Y-m-d H:i:s'); |
401 | 401 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37])); |
402 | 402 | //if (isset($line[37])) $data['last_update'] = $line[37]; |
403 | - $data['departure_airport_icao'] = $line[11]; |
|
404 | - $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':'); |
|
405 | - $data['arrival_airport_icao'] = $line[13]; |
|
403 | + $data['departure_airport_icao'] = $line[11]; |
|
404 | + $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':'); |
|
405 | + $data['arrival_airport_icao'] = $line[13]; |
|
406 | 406 | $data['frequency'] = $line[4]; |
407 | 407 | $data['type'] = $line[18]; |
408 | 408 | $data['range'] = $line[19]; |
409 | 409 | if (isset($line[35])) $data['info'] = $line[35]; |
410 | - $data['id_source'] = $id_source; |
|
411 | - //$data['arrival_airport_time'] = ; |
|
412 | - if ($line[9] != '') { |
|
413 | - $aircraft_data = explode('/',$line[9]); |
|
414 | - if (isset($aircraft_data[1])) { |
|
415 | - $data['aircraft_icao'] = $aircraft_data[1]; |
|
416 | - } |
|
417 | - } |
|
418 | - /* |
|
410 | + $data['id_source'] = $id_source; |
|
411 | + //$data['arrival_airport_time'] = ; |
|
412 | + if ($line[9] != '') { |
|
413 | + $aircraft_data = explode('/',$line[9]); |
|
414 | + if (isset($aircraft_data[1])) { |
|
415 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
416 | + } |
|
417 | + } |
|
418 | + /* |
|
419 | 419 | if ($value == 'whazzup') $data['format_source'] = 'whazzup'; |
420 | 420 | elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt'; |
421 | 421 | */ |
422 | - $data['format_source'] = $value['format']; |
|
422 | + $data['format_source'] = $value['format']; |
|
423 | 423 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
424 | - if ($line[3] == 'PILOT') $SI->add($data); |
|
424 | + if ($line[3] == 'PILOT') $SI->add($data); |
|
425 | 425 | elseif ($line[3] == 'ATC') { |
426 | 426 | //print_r($data); |
427 | 427 | $data['info'] = str_replace('^§','<br />',$data['info']); |
@@ -439,247 +439,247 @@ discard block |
||
439 | 439 | if (!isset($data['source_name'])) $data['source_name'] = ''; |
440 | 440 | echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
441 | 441 | } |
442 | - unset($data); |
|
443 | - } |
|
444 | - } |
|
445 | - } |
|
446 | - //if ($value == 'whazzup') $last_exec['whazzup'] = time(); |
|
447 | - //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time(); |
|
448 | - $last_exec[$id]['last'] = time(); |
|
449 | - //} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) { |
|
450 | - } elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
451 | - $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
452 | - if ($buffer != '') { |
|
453 | - $all_data = json_decode($buffer,true); |
|
454 | - if (isset($all_data['acList'])) { |
|
442 | + unset($data); |
|
443 | + } |
|
444 | + } |
|
445 | + } |
|
446 | + //if ($value == 'whazzup') $last_exec['whazzup'] = time(); |
|
447 | + //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time(); |
|
448 | + $last_exec[$id]['last'] = time(); |
|
449 | + //} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) { |
|
450 | + } elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
451 | + $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
452 | + if ($buffer != '') { |
|
453 | + $all_data = json_decode($buffer,true); |
|
454 | + if (isset($all_data['acList'])) { |
|
455 | 455 | $reset = 0; |
456 | 456 | foreach ($all_data['acList'] as $line) { |
457 | - $data = array(); |
|
458 | - $data['hex'] = $line['Icao']; // hex |
|
459 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
|
460 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude |
|
461 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed |
|
462 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading |
|
463 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat |
|
464 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long |
|
465 | - //$data['verticalrate'] = $line['']; // verticale rate |
|
466 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
|
467 | - $data['emergency'] = ''; // emergency |
|
468 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
|
469 | - /* |
|
457 | + $data = array(); |
|
458 | + $data['hex'] = $line['Icao']; // hex |
|
459 | + if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
|
460 | + if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude |
|
461 | + if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed |
|
462 | + if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading |
|
463 | + if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat |
|
464 | + if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long |
|
465 | + //$data['verticalrate'] = $line['']; // verticale rate |
|
466 | + if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
|
467 | + $data['emergency'] = ''; // emergency |
|
468 | + if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
|
469 | + /* |
|
470 | 470 | if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000); |
471 | 471 | else $data['datetime'] = date('Y-m-d H:i:s'); |
472 | 472 | */ |
473 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
474 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
|
475 | - $data['format_source'] = 'aircraftlistjson'; |
|
476 | - $data['id_source'] = $id_source; |
|
477 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
478 | - if (isset($data['datetime'])) $SI->add($data); |
|
479 | - unset($data); |
|
473 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
474 | + if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
|
475 | + $data['format_source'] = 'aircraftlistjson'; |
|
476 | + $data['id_source'] = $id_source; |
|
477 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
478 | + if (isset($data['datetime'])) $SI->add($data); |
|
479 | + unset($data); |
|
480 | 480 | } |
481 | - } else { |
|
481 | + } else { |
|
482 | 482 | $reset = 0; |
483 | 483 | foreach ($all_data as $line) { |
484 | - $data = array(); |
|
485 | - $data['hex'] = $line['hex']; // hex |
|
486 | - $data['ident'] = $line['flight']; // ident |
|
487 | - $data['altitude'] = $line['altitude']; // altitude |
|
488 | - $data['speed'] = $line['speed']; // speed |
|
489 | - $data['heading'] = $line['track']; // heading |
|
490 | - $data['latitude'] = $line['lat']; // lat |
|
491 | - $data['longitude'] = $line['lon']; // long |
|
492 | - $data['verticalrate'] = $line['vrt']; // verticale rate |
|
493 | - $data['squawk'] = $line['squawk']; // squawk |
|
494 | - $data['emergency'] = ''; // emergency |
|
495 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
496 | - $data['format_source'] = 'aircraftlistjson'; |
|
497 | - $data['id_source'] = $id_source; |
|
498 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
499 | - $SI->add($data); |
|
500 | - unset($data); |
|
484 | + $data = array(); |
|
485 | + $data['hex'] = $line['hex']; // hex |
|
486 | + $data['ident'] = $line['flight']; // ident |
|
487 | + $data['altitude'] = $line['altitude']; // altitude |
|
488 | + $data['speed'] = $line['speed']; // speed |
|
489 | + $data['heading'] = $line['track']; // heading |
|
490 | + $data['latitude'] = $line['lat']; // lat |
|
491 | + $data['longitude'] = $line['lon']; // long |
|
492 | + $data['verticalrate'] = $line['vrt']; // verticale rate |
|
493 | + $data['squawk'] = $line['squawk']; // squawk |
|
494 | + $data['emergency'] = ''; // emergency |
|
495 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
496 | + $data['format_source'] = 'aircraftlistjson'; |
|
497 | + $data['id_source'] = $id_source; |
|
498 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
499 | + $SI->add($data); |
|
500 | + unset($data); |
|
501 | + } |
|
501 | 502 | } |
502 | - } |
|
503 | - } |
|
504 | - //$last_exec['aircraftlistjson'] = time(); |
|
505 | - $last_exec[$id]['last'] = time(); |
|
506 | - //} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { |
|
507 | - } elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
508 | - $buffer = $Common->getData($value['host']); |
|
509 | - $all_data = json_decode($buffer,true); |
|
510 | - if (isset($all_data['planes'])) { |
|
503 | + } |
|
504 | + //$last_exec['aircraftlistjson'] = time(); |
|
505 | + $last_exec[$id]['last'] = time(); |
|
506 | + //} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { |
|
507 | + } elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
508 | + $buffer = $Common->getData($value['host']); |
|
509 | + $all_data = json_decode($buffer,true); |
|
510 | + if (isset($all_data['planes'])) { |
|
511 | 511 | $reset = 0; |
512 | 512 | foreach ($all_data['planes'] as $key => $line) { |
513 | - $data = array(); |
|
514 | - $data['hex'] = $key; // hex |
|
515 | - $data['ident'] = $line[3]; // ident |
|
516 | - $data['altitude'] = $line[6]; // altitude |
|
517 | - $data['speed'] = $line[8]; // speed |
|
518 | - $data['heading'] = $line[7]; // heading |
|
519 | - $data['latitude'] = $line[4]; // lat |
|
520 | - $data['longitude'] = $line[5]; // long |
|
521 | - //$data['verticalrate'] = $line[]; // verticale rate |
|
522 | - $data['squawk'] = $line[10]; // squawk |
|
523 | - $data['emergency'] = ''; // emergency |
|
524 | - $data['registration'] = $line[2]; |
|
525 | - $data['aircraft_icao'] = $line[0]; |
|
526 | - $deparr = explode('-',$line[1]); |
|
527 | - if (count($deparr) == 2) { |
|
513 | + $data = array(); |
|
514 | + $data['hex'] = $key; // hex |
|
515 | + $data['ident'] = $line[3]; // ident |
|
516 | + $data['altitude'] = $line[6]; // altitude |
|
517 | + $data['speed'] = $line[8]; // speed |
|
518 | + $data['heading'] = $line[7]; // heading |
|
519 | + $data['latitude'] = $line[4]; // lat |
|
520 | + $data['longitude'] = $line[5]; // long |
|
521 | + //$data['verticalrate'] = $line[]; // verticale rate |
|
522 | + $data['squawk'] = $line[10]; // squawk |
|
523 | + $data['emergency'] = ''; // emergency |
|
524 | + $data['registration'] = $line[2]; |
|
525 | + $data['aircraft_icao'] = $line[0]; |
|
526 | + $deparr = explode('-',$line[1]); |
|
527 | + if (count($deparr) == 2) { |
|
528 | 528 | $data['departure_airport_icao'] = $deparr[0]; |
529 | 529 | $data['arrival_airport_icao'] = $deparr[1]; |
530 | - } |
|
531 | - $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
|
532 | - $data['format_source'] = 'planeupdatefaa'; |
|
533 | - $data['id_source'] = $id_source; |
|
534 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
535 | - $SI->add($data); |
|
536 | - unset($data); |
|
530 | + } |
|
531 | + $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
|
532 | + $data['format_source'] = 'planeupdatefaa'; |
|
533 | + $data['id_source'] = $id_source; |
|
534 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
535 | + $SI->add($data); |
|
536 | + unset($data); |
|
537 | + } |
|
537 | 538 | } |
538 | - } |
|
539 | - //$last_exec['planeupdatefaa'] = time(); |
|
540 | - $last_exec[$id]['last'] = time(); |
|
541 | - } elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
542 | - $buffer = $Common->getData($value['host']); |
|
543 | - $all_data = json_decode($buffer,true); |
|
544 | - if (isset($all_data['states'])) { |
|
539 | + //$last_exec['planeupdatefaa'] = time(); |
|
540 | + $last_exec[$id]['last'] = time(); |
|
541 | + } elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
542 | + $buffer = $Common->getData($value['host']); |
|
543 | + $all_data = json_decode($buffer,true); |
|
544 | + if (isset($all_data['states'])) { |
|
545 | 545 | $reset = 0; |
546 | 546 | foreach ($all_data['states'] as $key => $line) { |
547 | - $data = array(); |
|
548 | - $data['hex'] = $line[0]; // hex |
|
549 | - $data['ident'] = trim($line[1]); // ident |
|
550 | - $data['altitude'] = round($line[7]*3.28084); // altitude |
|
551 | - $data['speed'] = round($line[9]*1.94384); // speed |
|
552 | - $data['heading'] = round($line[10]); // heading |
|
553 | - $data['latitude'] = $line[5]; // lat |
|
554 | - $data['longitude'] = $line[6]; // long |
|
555 | - $data['verticalrate'] = $line[11]; // verticale rate |
|
556 | - //$data['squawk'] = $line[10]; // squawk |
|
557 | - //$data['emergency'] = ''; // emergency |
|
558 | - //$data['registration'] = $line[2]; |
|
559 | - //$data['aircraft_icao'] = $line[0]; |
|
560 | - $data['datetime'] = date('Y-m-d H:i:s',$line[3]); |
|
561 | - $data['format_source'] = 'opensky'; |
|
562 | - $data['id_source'] = $id_source; |
|
563 | - $SI->add($data); |
|
564 | - unset($data); |
|
547 | + $data = array(); |
|
548 | + $data['hex'] = $line[0]; // hex |
|
549 | + $data['ident'] = trim($line[1]); // ident |
|
550 | + $data['altitude'] = round($line[7]*3.28084); // altitude |
|
551 | + $data['speed'] = round($line[9]*1.94384); // speed |
|
552 | + $data['heading'] = round($line[10]); // heading |
|
553 | + $data['latitude'] = $line[5]; // lat |
|
554 | + $data['longitude'] = $line[6]; // long |
|
555 | + $data['verticalrate'] = $line[11]; // verticale rate |
|
556 | + //$data['squawk'] = $line[10]; // squawk |
|
557 | + //$data['emergency'] = ''; // emergency |
|
558 | + //$data['registration'] = $line[2]; |
|
559 | + //$data['aircraft_icao'] = $line[0]; |
|
560 | + $data['datetime'] = date('Y-m-d H:i:s',$line[3]); |
|
561 | + $data['format_source'] = 'opensky'; |
|
562 | + $data['id_source'] = $id_source; |
|
563 | + $SI->add($data); |
|
564 | + unset($data); |
|
565 | + } |
|
565 | 566 | } |
566 | - } |
|
567 | - //$last_exec['planeupdatefaa'] = time(); |
|
568 | - $last_exec[$id]['last'] = time(); |
|
569 | - //} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) { |
|
570 | - } elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
571 | - //$buffer = $Common->getData($hosts[$id]); |
|
572 | - $buffer = $Common->getData($value['host']); |
|
573 | - $all_data = json_decode($buffer,true); |
|
574 | - if (!empty($all_data)) $reset = 0; |
|
575 | - foreach ($all_data as $key => $line) { |
|
567 | + //$last_exec['planeupdatefaa'] = time(); |
|
568 | + $last_exec[$id]['last'] = time(); |
|
569 | + //} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) { |
|
570 | + } elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
571 | + //$buffer = $Common->getData($hosts[$id]); |
|
572 | + $buffer = $Common->getData($value['host']); |
|
573 | + $all_data = json_decode($buffer,true); |
|
574 | + if (!empty($all_data)) $reset = 0; |
|
575 | + foreach ($all_data as $key => $line) { |
|
576 | 576 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
577 | - $data = array(); |
|
578 | - $data['hex'] = $line[0]; |
|
579 | - $data['ident'] = $line[16]; //$line[13] |
|
580 | - $data['altitude'] = $line[4]; // altitude |
|
581 | - $data['speed'] = $line[5]; // speed |
|
582 | - $data['heading'] = $line[3]; // heading |
|
583 | - $data['latitude'] = $line[1]; // lat |
|
584 | - $data['longitude'] = $line[2]; // long |
|
585 | - $data['verticalrate'] = $line[15]; // verticale rate |
|
586 | - $data['squawk'] = $line[6]; // squawk |
|
587 | - $data['aircraft_icao'] = $line[8]; |
|
588 | - $data['registration'] = $line[9]; |
|
589 | - $data['departure_airport_iata'] = $line[11]; |
|
590 | - $data['arrival_airport_iata'] = $line[12]; |
|
591 | - $data['emergency'] = ''; // emergency |
|
592 | - $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] |
|
593 | - $data['format_source'] = 'fr24json'; |
|
594 | - $data['id_source'] = $id_source; |
|
595 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
596 | - $SI->add($data); |
|
597 | - unset($data); |
|
577 | + $data = array(); |
|
578 | + $data['hex'] = $line[0]; |
|
579 | + $data['ident'] = $line[16]; //$line[13] |
|
580 | + $data['altitude'] = $line[4]; // altitude |
|
581 | + $data['speed'] = $line[5]; // speed |
|
582 | + $data['heading'] = $line[3]; // heading |
|
583 | + $data['latitude'] = $line[1]; // lat |
|
584 | + $data['longitude'] = $line[2]; // long |
|
585 | + $data['verticalrate'] = $line[15]; // verticale rate |
|
586 | + $data['squawk'] = $line[6]; // squawk |
|
587 | + $data['aircraft_icao'] = $line[8]; |
|
588 | + $data['registration'] = $line[9]; |
|
589 | + $data['departure_airport_iata'] = $line[11]; |
|
590 | + $data['arrival_airport_iata'] = $line[12]; |
|
591 | + $data['emergency'] = ''; // emergency |
|
592 | + $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] |
|
593 | + $data['format_source'] = 'fr24json'; |
|
594 | + $data['id_source'] = $id_source; |
|
595 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
596 | + $SI->add($data); |
|
597 | + unset($data); |
|
598 | + } |
|
598 | 599 | } |
599 | - } |
|
600 | - //$last_exec['fr24json'] = time(); |
|
601 | - $last_exec[$id]['last'] = time(); |
|
602 | - //} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) { |
|
603 | - } elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
604 | - //$buffer = $Common->getData($hosts[$id],'get','','','','','150'); |
|
605 | - $buffer = $Common->getData($value['host'],'get','','','','','150'); |
|
606 | - //echo $buffer; |
|
607 | - $buffer = str_replace(array("\n","\r"),"",$buffer); |
|
608 | - $buffer = preg_replace('/,"num":(.+)/','}',$buffer); |
|
609 | - $all_data = json_decode($buffer,true); |
|
610 | - if (json_last_error() != JSON_ERROR_NONE) { |
|
600 | + //$last_exec['fr24json'] = time(); |
|
601 | + $last_exec[$id]['last'] = time(); |
|
602 | + //} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) { |
|
603 | + } elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
604 | + //$buffer = $Common->getData($hosts[$id],'get','','','','','150'); |
|
605 | + $buffer = $Common->getData($value['host'],'get','','','','','150'); |
|
606 | + //echo $buffer; |
|
607 | + $buffer = str_replace(array("\n","\r"),"",$buffer); |
|
608 | + $buffer = preg_replace('/,"num":(.+)/','}',$buffer); |
|
609 | + $all_data = json_decode($buffer,true); |
|
610 | + if (json_last_error() != JSON_ERROR_NONE) { |
|
611 | 611 | die(json_last_error_msg()); |
612 | - } |
|
613 | - if (isset($all_data['mrkrs'])) { |
|
612 | + } |
|
613 | + if (isset($all_data['mrkrs'])) { |
|
614 | 614 | $reset = 0; |
615 | 615 | foreach ($all_data['mrkrs'] as $key => $line) { |
616 | - if (isset($line['inf'])) { |
|
616 | + if (isset($line['inf'])) { |
|
617 | 617 | $data = array(); |
618 | 618 | $data['hex'] = $line['inf']['ia']; |
619 | 619 | if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13] |
620 | - $data['altitude'] = round($line['inf']['al']*3.28084); // altitude |
|
621 | - if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed |
|
622 | - if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading |
|
623 | - $data['latitude'] = $line['pt'][0]; // lat |
|
624 | - $data['longitude'] = $line['pt'][1]; // long |
|
625 | - //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate |
|
626 | - if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk |
|
627 | - //$data['aircraft_icao'] = $line[8]; |
|
628 | - if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc']; |
|
620 | + $data['altitude'] = round($line['inf']['al']*3.28084); // altitude |
|
621 | + if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed |
|
622 | + if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading |
|
623 | + $data['latitude'] = $line['pt'][0]; // lat |
|
624 | + $data['longitude'] = $line['pt'][1]; // long |
|
625 | + //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate |
|
626 | + if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk |
|
627 | + //$data['aircraft_icao'] = $line[8]; |
|
628 | + if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc']; |
|
629 | 629 | //$data['departure_airport_iata'] = $line[11]; |
630 | 630 | //$data['arrival_airport_iata'] = $line[12]; |
631 | - //$data['emergency'] = ''; // emergency |
|
631 | + //$data['emergency'] = ''; // emergency |
|
632 | 632 | $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
633 | - $data['format_source'] = 'radarvirtueljson'; |
|
634 | - $data['id_source'] = $id_source; |
|
633 | + $data['format_source'] = 'radarvirtueljson'; |
|
634 | + $data['id_source'] = $id_source; |
|
635 | 635 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
636 | 636 | $SI->add($data); |
637 | 637 | unset($data); |
638 | - } |
|
638 | + } |
|
639 | + } |
|
639 | 640 | } |
640 | - } |
|
641 | - //$last_exec['radarvirtueljson'] = time(); |
|
642 | - $last_exec[$id]['last'] = time(); |
|
643 | - //} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) { |
|
644 | - } elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
645 | - //$buffer = $Common->getData($hosts[$id]); |
|
646 | - $buffer = $Common->getData($value['host'].'?'.time()); |
|
647 | - $all_data = json_decode(utf8_encode($buffer),true); |
|
641 | + //$last_exec['radarvirtueljson'] = time(); |
|
642 | + $last_exec[$id]['last'] = time(); |
|
643 | + //} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) { |
|
644 | + } elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
645 | + //$buffer = $Common->getData($hosts[$id]); |
|
646 | + $buffer = $Common->getData($value['host'].'?'.time()); |
|
647 | + $all_data = json_decode(utf8_encode($buffer),true); |
|
648 | 648 | |
649 | - if (isset($all_data['pireps'])) { |
|
649 | + if (isset($all_data['pireps'])) { |
|
650 | 650 | $reset = 0; |
651 | - foreach ($all_data['pireps'] as $line) { |
|
652 | - $data = array(); |
|
653 | - $data['id'] = $line['id']; |
|
654 | - $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
|
655 | - $data['ident'] = $line['callsign']; // ident |
|
656 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
|
657 | - if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
|
658 | - if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude |
|
659 | - if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed |
|
660 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading |
|
661 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
662 | - $data['latitude'] = $line['lat']; // lat |
|
663 | - $data['longitude'] = $line['lon']; // long |
|
664 | - //$data['verticalrate'] = $line['vrt']; // verticale rate |
|
665 | - //$data['squawk'] = $line['squawk']; // squawk |
|
666 | - //$data['emergency'] = ''; // emergency |
|
667 | - if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao']; |
|
668 | - if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime']; |
|
669 | - if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao']; |
|
670 | - //$data['arrival_airport_time'] = $line['arrtime']; |
|
671 | - if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft']; |
|
672 | - if (isset($line['transponder'])) $data['squawk'] = $line['transponder']; |
|
673 | - if (isset($line['atis'])) $data['info'] = $line['atis']; |
|
674 | - else $data['info'] = ''; |
|
675 | - $data['format_source'] = 'pireps'; |
|
676 | - $data['id_source'] = $id_source; |
|
677 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
678 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
679 | - if ($line['icon'] == 'plane') { |
|
651 | + foreach ($all_data['pireps'] as $line) { |
|
652 | + $data = array(); |
|
653 | + $data['id'] = $line['id']; |
|
654 | + $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
|
655 | + $data['ident'] = $line['callsign']; // ident |
|
656 | + if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
|
657 | + if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
|
658 | + if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude |
|
659 | + if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed |
|
660 | + if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading |
|
661 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
662 | + $data['latitude'] = $line['lat']; // lat |
|
663 | + $data['longitude'] = $line['lon']; // long |
|
664 | + //$data['verticalrate'] = $line['vrt']; // verticale rate |
|
665 | + //$data['squawk'] = $line['squawk']; // squawk |
|
666 | + //$data['emergency'] = ''; // emergency |
|
667 | + if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao']; |
|
668 | + if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime']; |
|
669 | + if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao']; |
|
670 | + //$data['arrival_airport_time'] = $line['arrtime']; |
|
671 | + if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft']; |
|
672 | + if (isset($line['transponder'])) $data['squawk'] = $line['transponder']; |
|
673 | + if (isset($line['atis'])) $data['info'] = $line['atis']; |
|
674 | + else $data['info'] = ''; |
|
675 | + $data['format_source'] = 'pireps'; |
|
676 | + $data['id_source'] = $id_source; |
|
677 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
678 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
679 | + if ($line['icon'] == 'plane') { |
|
680 | 680 | $SI->add($data); |
681 | - // print_r($data); |
|
682 | - } elseif ($line['icon'] == 'ct') { |
|
681 | + // print_r($data); |
|
682 | + } elseif ($line['icon'] == 'ct') { |
|
683 | 683 | $data['info'] = str_replace('^§','<br />',$data['info']); |
684 | 684 | $data['info'] = str_replace('&sect;','',$data['info']); |
685 | 685 | $typec = substr($data['ident'],-3); |
@@ -694,163 +694,163 @@ discard block |
||
694 | 694 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
695 | 695 | else $data['type'] = 'Observer'; |
696 | 696 | echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']); |
697 | - } |
|
698 | - unset($data); |
|
697 | + } |
|
698 | + unset($data); |
|
699 | + } |
|
699 | 700 | } |
700 | - } |
|
701 | - //$last_exec['pirepsjson'] = time(); |
|
702 | - $last_exec[$id]['last'] = time(); |
|
703 | - //} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { |
|
704 | - } elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
705 | - //$buffer = $Common->getData($hosts[$id]); |
|
706 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
707 | - $buffer = $Common->getData($value['host']); |
|
708 | - $all_data = json_decode($buffer,true); |
|
709 | - if ($buffer != '' && is_array($all_data)) { |
|
701 | + //$last_exec['pirepsjson'] = time(); |
|
702 | + $last_exec[$id]['last'] = time(); |
|
703 | + //} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { |
|
704 | + } elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
705 | + //$buffer = $Common->getData($hosts[$id]); |
|
706 | + if ($globalDebug) echo 'Get Data...'."\n"; |
|
707 | + $buffer = $Common->getData($value['host']); |
|
708 | + $all_data = json_decode($buffer,true); |
|
709 | + if ($buffer != '' && is_array($all_data)) { |
|
710 | 710 | $reset = 0; |
711 | 711 | foreach ($all_data as $line) { |
712 | - $data = array(); |
|
713 | - //$data['id'] = $line['id']; // id not usable |
|
714 | - if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
|
715 | - $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
716 | - if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
|
717 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
|
718 | - $data['ident'] = $line['flightnum']; // ident |
|
719 | - $data['altitude'] = $line['alt']; // altitude |
|
720 | - $data['speed'] = $line['gs']; // speed |
|
721 | - $data['heading'] = $line['heading']; // heading |
|
722 | - $data['latitude'] = $line['lat']; // lat |
|
723 | - $data['longitude'] = $line['lng']; // long |
|
724 | - $data['verticalrate'] = ''; // verticale rate |
|
725 | - $data['squawk'] = ''; // squawk |
|
726 | - $data['emergency'] = ''; // emergency |
|
727 | - //$data['datetime'] = $line['lastupdate']; |
|
728 | - $data['last_update'] = $line['lastupdate']; |
|
729 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
730 | - $data['departure_airport_icao'] = $line['depicao']; |
|
731 | - $data['departure_airport_time'] = $line['deptime']; |
|
732 | - $data['arrival_airport_icao'] = $line['arricao']; |
|
733 | - $data['arrival_airport_time'] = $line['arrtime']; |
|
734 | - $data['registration'] = $line['aircraft']; |
|
735 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
736 | - if (isset($line['aircraftname'])) { |
|
712 | + $data = array(); |
|
713 | + //$data['id'] = $line['id']; // id not usable |
|
714 | + if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
|
715 | + $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
716 | + if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
|
717 | + if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
|
718 | + $data['ident'] = $line['flightnum']; // ident |
|
719 | + $data['altitude'] = $line['alt']; // altitude |
|
720 | + $data['speed'] = $line['gs']; // speed |
|
721 | + $data['heading'] = $line['heading']; // heading |
|
722 | + $data['latitude'] = $line['lat']; // lat |
|
723 | + $data['longitude'] = $line['lng']; // long |
|
724 | + $data['verticalrate'] = ''; // verticale rate |
|
725 | + $data['squawk'] = ''; // squawk |
|
726 | + $data['emergency'] = ''; // emergency |
|
727 | + //$data['datetime'] = $line['lastupdate']; |
|
728 | + $data['last_update'] = $line['lastupdate']; |
|
729 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
730 | + $data['departure_airport_icao'] = $line['depicao']; |
|
731 | + $data['departure_airport_time'] = $line['deptime']; |
|
732 | + $data['arrival_airport_icao'] = $line['arricao']; |
|
733 | + $data['arrival_airport_time'] = $line['arrtime']; |
|
734 | + $data['registration'] = $line['aircraft']; |
|
735 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
736 | + if (isset($line['aircraftname'])) { |
|
737 | 737 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
738 | 738 | $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
739 | - $aircraft_data = explode('-',$line['aircraftname']); |
|
740 | - if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
|
741 | - elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
|
742 | - else { |
|
743 | - $aircraft_data = explode(' ',$line['aircraftname']); |
|
744 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
|
745 | - else $data['aircraft_icao'] = $line['aircraftname']; |
|
746 | - } |
|
747 | - } |
|
748 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; |
|
749 | - $data['id_source'] = $id_source; |
|
750 | - $data['format_source'] = 'phpvmacars'; |
|
751 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
752 | - $SI->add($data); |
|
753 | - unset($data); |
|
739 | + $aircraft_data = explode('-',$line['aircraftname']); |
|
740 | + if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
|
741 | + elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
|
742 | + else { |
|
743 | + $aircraft_data = explode(' ',$line['aircraftname']); |
|
744 | + if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
|
745 | + else $data['aircraft_icao'] = $line['aircraftname']; |
|
746 | + } |
|
747 | + } |
|
748 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; |
|
749 | + $data['id_source'] = $id_source; |
|
750 | + $data['format_source'] = 'phpvmacars'; |
|
751 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
752 | + $SI->add($data); |
|
753 | + unset($data); |
|
754 | 754 | } |
755 | 755 | if ($globalDebug) echo 'No more data...'."\n"; |
756 | 756 | unset($buffer); |
757 | 757 | unset($all_data); |
758 | - } |
|
759 | - //$last_exec['phpvmacars'] = time(); |
|
760 | - $last_exec[$id]['last'] = time(); |
|
761 | - } elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
762 | - //$buffer = $Common->getData($hosts[$id]); |
|
763 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
764 | - $buffer = $Common->getData($value['host']); |
|
765 | - $all_data = json_decode($buffer,true); |
|
766 | - if ($buffer != '' && is_array($all_data)) { |
|
758 | + } |
|
759 | + //$last_exec['phpvmacars'] = time(); |
|
760 | + $last_exec[$id]['last'] = time(); |
|
761 | + } elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
|
762 | + //$buffer = $Common->getData($hosts[$id]); |
|
763 | + if ($globalDebug) echo 'Get Data...'."\n"; |
|
764 | + $buffer = $Common->getData($value['host']); |
|
765 | + $all_data = json_decode($buffer,true); |
|
766 | + if ($buffer != '' && is_array($all_data)) { |
|
767 | 767 | $reset = 0; |
768 | 768 | foreach ($all_data as $line) { |
769 | - $data = array(); |
|
770 | - //$data['id'] = $line['id']; // id not usable |
|
771 | - $data['id'] = trim($line['flight_id']); |
|
772 | - $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
773 | - $data['pilot_name'] = $line['pilot_name']; |
|
774 | - $data['pilot_id'] = $line['pilot_id']; |
|
775 | - $data['ident'] = trim($line['callsign']); // ident |
|
776 | - $data['altitude'] = $line['altitude']; // altitude |
|
777 | - $data['speed'] = $line['gs']; // speed |
|
778 | - $data['heading'] = $line['heading']; // heading |
|
779 | - $data['latitude'] = $line['latitude']; // lat |
|
780 | - $data['longitude'] = $line['longitude']; // long |
|
781 | - $data['verticalrate'] = ''; // verticale rate |
|
782 | - $data['squawk'] = ''; // squawk |
|
783 | - $data['emergency'] = ''; // emergency |
|
784 | - //$data['datetime'] = $line['lastupdate']; |
|
785 | - $data['last_update'] = $line['last_update']; |
|
786 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
787 | - $data['departure_airport_icao'] = $line['departure']; |
|
788 | - //$data['departure_airport_time'] = $line['departure_time']; |
|
789 | - $data['arrival_airport_icao'] = $line['arrival']; |
|
790 | - //$data['arrival_airport_time'] = $line['arrival_time']; |
|
791 | - //$data['registration'] = $line['aircraft']; |
|
792 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
793 | - $data['aircraft_icao'] = $line['plane_type']; |
|
794 | - $data['id_source'] = $id_source; |
|
795 | - $data['format_source'] = 'vam'; |
|
796 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
797 | - $SI->add($data); |
|
798 | - unset($data); |
|
769 | + $data = array(); |
|
770 | + //$data['id'] = $line['id']; // id not usable |
|
771 | + $data['id'] = trim($line['flight_id']); |
|
772 | + $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
773 | + $data['pilot_name'] = $line['pilot_name']; |
|
774 | + $data['pilot_id'] = $line['pilot_id']; |
|
775 | + $data['ident'] = trim($line['callsign']); // ident |
|
776 | + $data['altitude'] = $line['altitude']; // altitude |
|
777 | + $data['speed'] = $line['gs']; // speed |
|
778 | + $data['heading'] = $line['heading']; // heading |
|
779 | + $data['latitude'] = $line['latitude']; // lat |
|
780 | + $data['longitude'] = $line['longitude']; // long |
|
781 | + $data['verticalrate'] = ''; // verticale rate |
|
782 | + $data['squawk'] = ''; // squawk |
|
783 | + $data['emergency'] = ''; // emergency |
|
784 | + //$data['datetime'] = $line['lastupdate']; |
|
785 | + $data['last_update'] = $line['last_update']; |
|
786 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
787 | + $data['departure_airport_icao'] = $line['departure']; |
|
788 | + //$data['departure_airport_time'] = $line['departure_time']; |
|
789 | + $data['arrival_airport_icao'] = $line['arrival']; |
|
790 | + //$data['arrival_airport_time'] = $line['arrival_time']; |
|
791 | + //$data['registration'] = $line['aircraft']; |
|
792 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
793 | + $data['aircraft_icao'] = $line['plane_type']; |
|
794 | + $data['id_source'] = $id_source; |
|
795 | + $data['format_source'] = 'vam'; |
|
796 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
797 | + $SI->add($data); |
|
798 | + unset($data); |
|
799 | 799 | } |
800 | 800 | if ($globalDebug) echo 'No more data...'."\n"; |
801 | 801 | unset($buffer); |
802 | 802 | unset($all_data); |
803 | - } |
|
804 | - //$last_exec['phpvmacars'] = time(); |
|
805 | - $last_exec[$id]['last'] = time(); |
|
803 | + } |
|
804 | + //$last_exec['phpvmacars'] = time(); |
|
805 | + $last_exec[$id]['last'] = time(); |
|
806 | 806 | //} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') { |
807 | 807 | } elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3') { |
808 | - if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
809 | - //$last_exec[$id]['last'] = time(); |
|
808 | + if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
809 | + //$last_exec[$id]['last'] = time(); |
|
810 | 810 | |
811 | - //$read = array( $sockets[$id] ); |
|
812 | - $read = $sockets; |
|
813 | - $write = NULL; |
|
814 | - $e = NULL; |
|
815 | - $n = socket_select($read, $write, $e, $timeout); |
|
816 | - if ($e != NULL) var_dump($e); |
|
817 | - if ($n > 0) { |
|
811 | + //$read = array( $sockets[$id] ); |
|
812 | + $read = $sockets; |
|
813 | + $write = NULL; |
|
814 | + $e = NULL; |
|
815 | + $n = socket_select($read, $write, $e, $timeout); |
|
816 | + if ($e != NULL) var_dump($e); |
|
817 | + if ($n > 0) { |
|
818 | 818 | $reset = 0; |
819 | 819 | foreach ($read as $nb => $r) { |
820 | - //$value = $formats[$nb]; |
|
821 | - $format = $globalSources[$nb]['format']; |
|
822 | - if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { |
|
823 | - $buffer = socket_read($r, 6000,PHP_NORMAL_READ); |
|
824 | - } else { |
|
825 | - $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port); |
|
826 | - } |
|
827 | - //$buffer = socket_read($r, 60000,PHP_NORMAL_READ); |
|
828 | - //echo $buffer."\n"; |
|
829 | - // lets play nice and handle signals such as ctrl-c/kill properly |
|
830 | - //if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
831 | - $error = false; |
|
832 | - //$SI::del(); |
|
833 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
834 | - // SBS format is CSV format |
|
835 | - if ($buffer != '') { |
|
820 | + //$value = $formats[$nb]; |
|
821 | + $format = $globalSources[$nb]['format']; |
|
822 | + if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { |
|
823 | + $buffer = socket_read($r, 6000,PHP_NORMAL_READ); |
|
824 | + } else { |
|
825 | + $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port); |
|
826 | + } |
|
827 | + //$buffer = socket_read($r, 60000,PHP_NORMAL_READ); |
|
828 | + //echo $buffer."\n"; |
|
829 | + // lets play nice and handle signals such as ctrl-c/kill properly |
|
830 | + //if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
831 | + $error = false; |
|
832 | + //$SI::del(); |
|
833 | + $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
834 | + // SBS format is CSV format |
|
835 | + if ($buffer != '') { |
|
836 | 836 | $tt[$format] = 0; |
837 | 837 | if ($format == 'acarssbs3') { |
838 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
839 | - $ACARS->add(trim($buffer)); |
|
840 | - $ACARS->deleteLiveAcarsData(); |
|
838 | + if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
839 | + $ACARS->add(trim($buffer)); |
|
840 | + $ACARS->deleteLiveAcarsData(); |
|
841 | 841 | } elseif ($format == 'raw') { |
842 | - // AVR format |
|
843 | - $data = $SBS->parse($buffer); |
|
844 | - if (is_array($data)) { |
|
842 | + // AVR format |
|
843 | + $data = $SBS->parse($buffer); |
|
844 | + if (is_array($data)) { |
|
845 | 845 | $data['datetime'] = date('Y-m-d H:i:s'); |
846 | 846 | $data['format_source'] = 'raw'; |
847 | 847 | if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
848 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
849 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
850 | - } |
|
851 | - } elseif ($format == 'flightgearsp') { |
|
852 | - //echo $buffer."\n"; |
|
853 | - if (strlen($buffer) > 5) { |
|
848 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
849 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
850 | + } |
|
851 | + } elseif ($format == 'flightgearsp') { |
|
852 | + //echo $buffer."\n"; |
|
853 | + if (strlen($buffer) > 5) { |
|
854 | 854 | $line = explode(',',$buffer); |
855 | 855 | $data = array(); |
856 | 856 | //XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p |
@@ -866,123 +866,123 @@ discard block |
||
866 | 866 | $data['format_source'] = 'flightgearsp'; |
867 | 867 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
868 | 868 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
869 | - } |
|
870 | - } elseif ($format == 'acars') { |
|
871 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
872 | - $ACARS->add(trim($buffer)); |
|
873 | - socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
|
874 | - $ACARS->deleteLiveAcarsData(); |
|
869 | + } |
|
870 | + } elseif ($format == 'acars') { |
|
871 | + if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
872 | + $ACARS->add(trim($buffer)); |
|
873 | + socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
|
874 | + $ACARS->deleteLiveAcarsData(); |
|
875 | 875 | } elseif ($format == 'flightgearmp') { |
876 | - if (substr($buffer,0,1) != '#') { |
|
876 | + if (substr($buffer,0,1) != '#') { |
|
877 | 877 | $data = array(); |
878 | 878 | //echo $buffer."\n"; |
879 | 879 | $line = explode(' ',$buffer); |
880 | 880 | if (count($line) == 11) { |
881 | - $userserver = explode('@',$line[0]); |
|
882 | - $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex |
|
883 | - $data['ident'] = $userserver[0]; |
|
884 | - $data['registration'] = $userserver[0]; |
|
885 | - $data['latitude'] = $line[4]; |
|
886 | - $data['longitude'] = $line[5]; |
|
887 | - $data['altitude'] = $line[6]; |
|
888 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
889 | - $aircraft_type = $line[10]; |
|
890 | - $aircraft_type = preg_split(':/:',$aircraft_type); |
|
891 | - $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
|
892 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
881 | + $userserver = explode('@',$line[0]); |
|
882 | + $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex |
|
883 | + $data['ident'] = $userserver[0]; |
|
884 | + $data['registration'] = $userserver[0]; |
|
885 | + $data['latitude'] = $line[4]; |
|
886 | + $data['longitude'] = $line[5]; |
|
887 | + $data['altitude'] = $line[6]; |
|
888 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
889 | + $aircraft_type = $line[10]; |
|
890 | + $aircraft_type = preg_split(':/:',$aircraft_type); |
|
891 | + $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
|
892 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
893 | + } |
|
893 | 894 | } |
894 | - } |
|
895 | 895 | } elseif ($format == 'beast') { |
896 | - echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n"; |
|
897 | - die; |
|
896 | + echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n"; |
|
897 | + die; |
|
898 | 898 | } elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') { |
899 | - $line = explode("\t", $buffer); |
|
900 | - for($k = 0; $k < count($line); $k=$k+2) { |
|
899 | + $line = explode("\t", $buffer); |
|
900 | + for($k = 0; $k < count($line); $k=$k+2) { |
|
901 | 901 | $key = $line[$k]; |
902 | - $lined[$key] = $line[$k+1]; |
|
903 | - } |
|
904 | - if (count($lined) > 3) { |
|
905 | - $data['hex'] = $lined['hexid']; |
|
906 | - //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
|
907 | - $data['datetime'] = date('Y-m-d H:i:s');; |
|
908 | - if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
|
909 | - if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
|
910 | - if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
|
911 | - if (isset($lined['speed'])) $data['speed'] = $lined['speed']; |
|
912 | - if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk']; |
|
913 | - if (isset($lined['alt'])) $data['altitude'] = $lined['alt']; |
|
914 | - if (isset($lined['heading'])) $data['heading'] = $lined['heading']; |
|
915 | - $data['id_source'] = $id_source; |
|
916 | - $data['format_source'] = 'tsv'; |
|
917 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
918 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
919 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
920 | - unset($lined); |
|
921 | - unset($data); |
|
922 | - } else $error = true; |
|
902 | + $lined[$key] = $line[$k+1]; |
|
903 | + } |
|
904 | + if (count($lined) > 3) { |
|
905 | + $data['hex'] = $lined['hexid']; |
|
906 | + //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
|
907 | + $data['datetime'] = date('Y-m-d H:i:s');; |
|
908 | + if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
|
909 | + if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
|
910 | + if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
|
911 | + if (isset($lined['speed'])) $data['speed'] = $lined['speed']; |
|
912 | + if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk']; |
|
913 | + if (isset($lined['alt'])) $data['altitude'] = $lined['alt']; |
|
914 | + if (isset($lined['heading'])) $data['heading'] = $lined['heading']; |
|
915 | + $data['id_source'] = $id_source; |
|
916 | + $data['format_source'] = 'tsv'; |
|
917 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
918 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
919 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
920 | + unset($lined); |
|
921 | + unset($data); |
|
922 | + } else $error = true; |
|
923 | 923 | } elseif ($format == 'aprs' && $use_aprs) { |
924 | - if ($aprs_connect == 0) { |
|
924 | + if ($aprs_connect == 0) { |
|
925 | 925 | $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
926 | 926 | $aprs_connect = 1; |
927 | - } |
|
927 | + } |
|
928 | 928 | |
929 | - if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { |
|
929 | + if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { |
|
930 | 930 | $aprs_last_tx = time(); |
931 | 931 | $data_aprs = "# Keep alive"; |
932 | 932 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
933 | - } |
|
933 | + } |
|
934 | 934 | |
935 | - //echo 'Connect : '.$aprs_connect.' '.$buffer."\n"; |
|
936 | - $buffer = str_replace('APRS <- ','',$buffer); |
|
937 | - $buffer = str_replace('APRS -> ','',$buffer); |
|
938 | - //echo $buffer."\n"; |
|
939 | - if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') { |
|
935 | + //echo 'Connect : '.$aprs_connect.' '.$buffer."\n"; |
|
936 | + $buffer = str_replace('APRS <- ','',$buffer); |
|
937 | + $buffer = str_replace('APRS -> ','',$buffer); |
|
938 | + //echo $buffer."\n"; |
|
939 | + if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') { |
|
940 | 940 | $line = $APRS->parse($buffer); |
941 | 941 | //print_r($line); |
942 | 942 | if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) { |
943 | - $aprs_last_tx = time(); |
|
944 | - $data = array(); |
|
945 | - //print_r($line); |
|
946 | - $data['hex'] = $line['address']; |
|
947 | - $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
948 | - //$data['datetime'] = date('Y-m-d H:i:s'); |
|
949 | - $data['ident'] = $line['ident']; |
|
950 | - $data['latitude'] = $line['latitude']; |
|
951 | - $data['longitude'] = $line['longitude']; |
|
952 | - //$data['verticalrate'] = $line[16]; |
|
953 | - if (isset($line['speed'])) $data['speed'] = $line['speed']; |
|
954 | - else $data['speed'] = 0; |
|
955 | - $data['altitude'] = $line['altitude']; |
|
956 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; |
|
957 | - //else $data['heading'] = 0; |
|
958 | - $data['aircraft_type'] = $line['stealth']; |
|
959 | - if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true; |
|
960 | - $data['id_source'] = $id_source; |
|
961 | - $data['format_source'] = 'aprs'; |
|
962 | - $data['source_name'] = $line['source']; |
|
963 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
964 | - $currentdate = date('Y-m-d H:i:s'); |
|
965 | - $aprsdate = strtotime($data['datetime']); |
|
966 | - // Accept data if time <= system time + 20s |
|
967 | - if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
943 | + $aprs_last_tx = time(); |
|
944 | + $data = array(); |
|
945 | + //print_r($line); |
|
946 | + $data['hex'] = $line['address']; |
|
947 | + $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
948 | + //$data['datetime'] = date('Y-m-d H:i:s'); |
|
949 | + $data['ident'] = $line['ident']; |
|
950 | + $data['latitude'] = $line['latitude']; |
|
951 | + $data['longitude'] = $line['longitude']; |
|
952 | + //$data['verticalrate'] = $line[16]; |
|
953 | + if (isset($line['speed'])) $data['speed'] = $line['speed']; |
|
954 | + else $data['speed'] = 0; |
|
955 | + $data['altitude'] = $line['altitude']; |
|
956 | + if (isset($line['heading'])) $data['heading'] = $line['heading']; |
|
957 | + //else $data['heading'] = 0; |
|
958 | + $data['aircraft_type'] = $line['stealth']; |
|
959 | + if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true; |
|
960 | + $data['id_source'] = $id_source; |
|
961 | + $data['format_source'] = 'aprs'; |
|
962 | + $data['source_name'] = $line['source']; |
|
963 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
964 | + $currentdate = date('Y-m-d H:i:s'); |
|
965 | + $aprsdate = strtotime($data['datetime']); |
|
966 | + // Accept data if time <= system time + 20s |
|
967 | + if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
968 | 968 | $send = $SI->add($data); |
969 | - } else { |
|
969 | + } else { |
|
970 | 970 | if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
971 | 971 | else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
972 | - } |
|
973 | - unset($data); |
|
972 | + } |
|
973 | + unset($data); |
|
974 | 974 | } |
975 | 975 | elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
976 | 976 | echo '!! Weather Station not yet supported'."\n"; |
977 | 977 | } |
978 | 978 | //elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n"; |
979 | 979 | //elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n"; |
980 | - } |
|
980 | + } |
|
981 | 981 | } else { |
982 | - $line = explode(',', $buffer); |
|
983 | - if (count($line) > 20) { |
|
984 | - $data['hex'] = $line[4]; |
|
985 | - /* |
|
982 | + $line = explode(',', $buffer); |
|
983 | + if (count($line) > 20) { |
|
984 | + $data['hex'] = $line[4]; |
|
985 | + /* |
|
986 | 986 | $data['datetime'] = $line[6].' '.$line[7]; |
987 | 987 | date_default_timezone_set($globalTimezone); |
988 | 988 | $datetime = new DateTime($data['datetime']); |
@@ -990,29 +990,29 @@ discard block |
||
990 | 990 | $data['datetime'] = $datetime->format('Y-m-d H:i:s'); |
991 | 991 | date_default_timezone_set('UTC'); |
992 | 992 | */ |
993 | - // Force datetime to current UTC datetime |
|
994 | - date_default_timezone_set('UTC'); |
|
995 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
996 | - $data['ident'] = trim($line[10]); |
|
997 | - $data['latitude'] = $line[14]; |
|
998 | - $data['longitude'] = $line[15]; |
|
999 | - $data['verticalrate'] = $line[16]; |
|
1000 | - $data['emergency'] = $line[20]; |
|
1001 | - $data['speed'] = $line[12]; |
|
1002 | - $data['squawk'] = $line[17]; |
|
1003 | - $data['altitude'] = $line[11]; |
|
1004 | - $data['heading'] = $line[13]; |
|
1005 | - $data['ground'] = $line[21]; |
|
1006 | - $data['emergency'] = $line[19]; |
|
1007 | - $data['format_source'] = 'sbs'; |
|
993 | + // Force datetime to current UTC datetime |
|
994 | + date_default_timezone_set('UTC'); |
|
995 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
996 | + $data['ident'] = trim($line[10]); |
|
997 | + $data['latitude'] = $line[14]; |
|
998 | + $data['longitude'] = $line[15]; |
|
999 | + $data['verticalrate'] = $line[16]; |
|
1000 | + $data['emergency'] = $line[20]; |
|
1001 | + $data['speed'] = $line[12]; |
|
1002 | + $data['squawk'] = $line[17]; |
|
1003 | + $data['altitude'] = $line[11]; |
|
1004 | + $data['heading'] = $line[13]; |
|
1005 | + $data['ground'] = $line[21]; |
|
1006 | + $data['emergency'] = $line[19]; |
|
1007 | + $data['format_source'] = 'sbs'; |
|
1008 | 1008 | if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
1009 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1010 | - $data['id_source'] = $id_source; |
|
1011 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data); |
|
1012 | - else $error = true; |
|
1013 | - unset($data); |
|
1014 | - } else $error = true; |
|
1015 | - if ($error) { |
|
1009 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1010 | + $data['id_source'] = $id_source; |
|
1011 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data); |
|
1012 | + else $error = true; |
|
1013 | + unset($data); |
|
1014 | + } else $error = true; |
|
1015 | + if ($error) { |
|
1016 | 1016 | if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { |
1017 | 1017 | if ($globalDebug) echo "Not a message. Ignoring... \n"; |
1018 | 1018 | } else { |
@@ -1028,13 +1028,13 @@ discard block |
||
1028 | 1028 | connect_all($sourceer); |
1029 | 1029 | $sourceer = array(); |
1030 | 1030 | } |
1031 | - } |
|
1031 | + } |
|
1032 | 1032 | } |
1033 | 1033 | // Sleep for xxx microseconds |
1034 | 1034 | if (isset($globalSBSSleep)) usleep($globalSBSSleep); |
1035 | - } else { |
|
1035 | + } else { |
|
1036 | 1036 | if ($format == 'flightgearmp') { |
1037 | - if ($globalDebug) echo "Reconnect FlightGear MP..."; |
|
1037 | + if ($globalDebug) echo "Reconnect FlightGear MP..."; |
|
1038 | 1038 | //@socket_close($r); |
1039 | 1039 | sleep($globalMinFetch); |
1040 | 1040 | $sourcefg[$nb] = $globalSources[$nb]; |
@@ -1043,9 +1043,9 @@ discard block |
||
1043 | 1043 | break; |
1044 | 1044 | |
1045 | 1045 | } elseif ($format != 'acars' && $format != 'flightgearsp') { |
1046 | - if (isset($tt[$format])) $tt[$format]++; |
|
1047 | - else $tt[$format] = 0; |
|
1048 | - if ($tt[$format] > 30) { |
|
1046 | + if (isset($tt[$format])) $tt[$format]++; |
|
1047 | + else $tt[$format] = 0; |
|
1048 | + if ($tt[$format] > 30) { |
|
1049 | 1049 | if ($globalDebug) echo "ERROR : Reconnect ".$format."..."; |
1050 | 1050 | //@socket_close($r); |
1051 | 1051 | sleep(2); |
@@ -1056,23 +1056,23 @@ discard block |
||
1056 | 1056 | //connect_all($globalSources); |
1057 | 1057 | $tt[$format]=0; |
1058 | 1058 | break; |
1059 | - } |
|
1059 | + } |
|
1060 | + } |
|
1060 | 1061 | } |
1061 | - } |
|
1062 | 1062 | } |
1063 | - } else { |
|
1063 | + } else { |
|
1064 | 1064 | $error = socket_strerror(socket_last_error()); |
1065 | 1065 | if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
1066 | 1066 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) { |
1067 | 1067 | if (isset($globalDebug)) echo "Restarting...\n"; |
1068 | 1068 | // Restart the script if possible |
1069 | 1069 | if (is_array($sockets)) { |
1070 | - if ($globalDebug) echo "Shutdown all sockets..."; |
|
1070 | + if ($globalDebug) echo "Shutdown all sockets..."; |
|
1071 | 1071 | |
1072 | - foreach ($sockets as $sock) { |
|
1072 | + foreach ($sockets as $sock) { |
|
1073 | 1073 | @socket_shutdown($sock,2); |
1074 | 1074 | @socket_close($sock); |
1075 | - } |
|
1075 | + } |
|
1076 | 1076 | |
1077 | 1077 | } |
1078 | 1078 | if ($globalDebug) echo "Restart all connections..."; |
@@ -1083,13 +1083,13 @@ discard block |
||
1083 | 1083 | if ($reset > 40) exit('Too many attempts...'); |
1084 | 1084 | connect_all($globalSources); |
1085 | 1085 | } |
1086 | - } |
|
1086 | + } |
|
1087 | 1087 | } |
1088 | 1088 | if ($globalDaemon === false) { |
1089 | - if ($globalDebug) echo 'Check all...'."\n"; |
|
1090 | - $SI->checkAll(); |
|
1089 | + if ($globalDebug) echo 'Check all...'."\n"; |
|
1090 | + $SI->checkAll(); |
|
1091 | + } |
|
1091 | 1092 | } |
1092 | - } |
|
1093 | 1093 | } |
1094 | 1094 | |
1095 | 1095 | ?> |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | die; |
41 | 41 | } |
42 | 42 | //$hosts = array($globalSBS1Host.':'.$globalSBS1Port); |
43 | - $globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port); |
|
43 | + $globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | -$options = getopt('s::',array('source::','server','idsource::')); |
|
47 | +$options = getopt('s::', array('source::', 'server', 'idsource::')); |
|
48 | 48 | //if (isset($options['s'])) $hosts = array($options['s']); |
49 | 49 | //elseif (isset($options['source'])) $hosts = array($options['source']); |
50 | 50 | if (isset($options['s'])) { |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | else $id_source = 1; |
60 | 60 | if (isset($globalServer) && $globalServer) { |
61 | 61 | if ($globalDebug) echo "Using Server Mode\n"; |
62 | - $SI=new SpotterServer(); |
|
63 | -} else $SI=new SpotterImport($Connection->db); |
|
62 | + $SI = new SpotterServer(); |
|
63 | +} else $SI = new SpotterImport($Connection->db); |
|
64 | 64 | //$APRS=new APRS($Connection->db); |
65 | -$SBS=new SBS(); |
|
66 | -$ACARS=new ACARS($Connection->db); |
|
67 | -$Common=new Common(); |
|
65 | +$SBS = new SBS(); |
|
66 | +$ACARS = new ACARS($Connection->db); |
|
67 | +$Common = new Common(); |
|
68 | 68 | date_default_timezone_set('UTC'); |
69 | 69 | //$servertz = system('date +%Z'); |
70 | 70 | // signal handler - playing nice with sockets and dump1090 |
71 | 71 | if (function_exists('pcntl_fork')) { |
72 | - pcntl_signal(SIGINT, function() { |
|
72 | + pcntl_signal(SIGINT, function() { |
|
73 | 73 | global $sockets; |
74 | 74 | echo "\n\nctrl-c or kill signal received. Tidying up ... "; |
75 | 75 | die("Bye!\n"); |
@@ -113,35 +113,35 @@ discard block |
||
113 | 113 | |
114 | 114 | function connect_all($hosts) { |
115 | 115 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
116 | - global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset; |
|
116 | + global $sockets, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset; |
|
117 | 117 | $reset++; |
118 | 118 | if ($globalDebug) echo 'Connect to all...'."\n"; |
119 | 119 | foreach ($hosts as $id => $value) { |
120 | 120 | $host = $value['host']; |
121 | 121 | $globalSources[$id]['last_exec'] = 0; |
122 | 122 | // Here we check type of source(s) |
123 | - if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
|
124 | - if (preg_match('/deltadb.txt$/i',$host)) { |
|
123 | + if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
|
124 | + if (preg_match('/deltadb.txt$/i', $host)) { |
|
125 | 125 | //$formats[$id] = 'deltadbtxt'; |
126 | 126 | $globalSources[$id]['format'] = 'deltadbtxt'; |
127 | 127 | //$last_exec['deltadbtxt'] = 0; |
128 | 128 | if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
129 | - } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
|
129 | + } else if (preg_match('/vatsim-data.txt$/i', $host)) { |
|
130 | 130 | //$formats[$id] = 'vatsimtxt'; |
131 | 131 | $globalSources[$id]['format'] = 'vatsimtxt'; |
132 | 132 | //$last_exec['vatsimtxt'] = 0; |
133 | 133 | if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
134 | - } else if (preg_match('/aircraftlist.json$/i',$host)) { |
|
134 | + } else if (preg_match('/aircraftlist.json$/i', $host)) { |
|
135 | 135 | //$formats[$id] = 'aircraftlistjson'; |
136 | 136 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
137 | 137 | //$last_exec['aircraftlistjson'] = 0; |
138 | 138 | if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
139 | - } else if (preg_match('/opensky/i',$host)) { |
|
139 | + } else if (preg_match('/opensky/i', $host)) { |
|
140 | 140 | //$formats[$id] = 'aircraftlistjson'; |
141 | 141 | $globalSources[$id]['format'] = 'opensky'; |
142 | 142 | //$last_exec['aircraftlistjson'] = 0; |
143 | 143 | if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
144 | - } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
|
144 | + } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) { |
|
145 | 145 | //$formats[$id] = 'radarvirtueljson'; |
146 | 146 | $globalSources[$id]['format'] = 'radarvirtueljson'; |
147 | 147 | //$last_exec['radarvirtueljson'] = 0; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
151 | 151 | exit(0); |
152 | 152 | } |
153 | - } else if (preg_match('/planeUpdateFAA.php$/i',$host)) { |
|
153 | + } else if (preg_match('/planeUpdateFAA.php$/i', $host)) { |
|
154 | 154 | //$formats[$id] = 'planeupdatefaa'; |
155 | 155 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
156 | 156 | //$last_exec['planeupdatefaa'] = 0; |
@@ -159,26 +159,26 @@ discard block |
||
159 | 159 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
160 | 160 | exit(0); |
161 | 161 | } |
162 | - } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { |
|
162 | + } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) { |
|
163 | 163 | //$formats[$id] = 'phpvmacars'; |
164 | 164 | $globalSources[$id]['format'] = 'phpvmacars'; |
165 | 165 | //$last_exec['phpvmacars'] = 0; |
166 | 166 | if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
167 | - } else if (preg_match('/VAM-json.php$/i',$host)) { |
|
167 | + } else if (preg_match('/VAM-json.php$/i', $host)) { |
|
168 | 168 | //$formats[$id] = 'phpvmacars'; |
169 | 169 | $globalSources[$id]['format'] = 'vam'; |
170 | 170 | if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
171 | - } else if (preg_match('/whazzup/i',$host)) { |
|
171 | + } else if (preg_match('/whazzup/i', $host)) { |
|
172 | 172 | //$formats[$id] = 'whazzup'; |
173 | 173 | $globalSources[$id]['format'] = 'whazzup'; |
174 | 174 | //$last_exec['whazzup'] = 0; |
175 | 175 | if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
176 | - } else if (preg_match('/recentpireps/i',$host)) { |
|
176 | + } else if (preg_match('/recentpireps/i', $host)) { |
|
177 | 177 | //$formats[$id] = 'pirepsjson'; |
178 | 178 | $globalSources[$id]['format'] = 'pirepsjson'; |
179 | 179 | //$last_exec['pirepsjson'] = 0; |
180 | 180 | if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
181 | - } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
|
181 | + } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) { |
|
182 | 182 | //$formats[$id] = 'fr24json'; |
183 | 183 | $globalSources[$id]['format'] = 'fr24json'; |
184 | 184 | //$last_exec['fr24json'] = 0; |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | exit(0); |
189 | 189 | } |
190 | 190 | //} else if (preg_match('/10001/',$host)) { |
191 | - } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
191 | + } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
192 | 192 | //$formats[$id] = 'tsv'; |
193 | 193 | $globalSources[$id]['format'] = 'tsv'; |
194 | 194 | if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
195 | 195 | } |
196 | - } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
|
196 | + } elseif (filter_var($host, FILTER_VALIDATE_URL)) { |
|
197 | 197 | if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
198 | - } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
|
199 | - $hostport = explode(':',$host); |
|
198 | + } elseif (!filter_var($host, FILTER_VALIDATE_URL)) { |
|
199 | + $hostport = explode(':', $host); |
|
200 | 200 | if (isset($hostport[1])) { |
201 | 201 | $port = $hostport[1]; |
202 | 202 | $hostn = $hostport[0]; |
@@ -205,14 +205,14 @@ discard block |
||
205 | 205 | $hostn = $globalSources[$id]['host']; |
206 | 206 | } |
207 | 207 | if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { |
208 | - $s = create_socket($hostn,$port, $errno, $errstr); |
|
208 | + $s = create_socket($hostn, $port, $errno, $errstr); |
|
209 | 209 | } else { |
210 | - $s = create_socket_udp($hostn,$port, $errno, $errstr); |
|
210 | + $s = create_socket_udp($hostn, $port, $errno, $errstr); |
|
211 | 211 | } |
212 | 212 | if ($s) { |
213 | 213 | $sockets[$id] = $s; |
214 | 214 | if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { |
215 | - if (preg_match('/aprs/',$hostn)) { |
|
215 | + if (preg_match('/aprs/', $hostn)) { |
|
216 | 216 | //$formats[$id] = 'aprs'; |
217 | 217 | $globalSources[$id]['format'] = 'aprs'; |
218 | 218 | //$aprs_connect = 0; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
254 | 254 | else $timeout = 20; |
255 | 255 | $errno = ''; |
256 | -$errstr=''; |
|
256 | +$errstr = ''; |
|
257 | 257 | |
258 | 258 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
259 | 259 | /* Initiate connections to all the hosts simultaneously */ |
@@ -282,16 +282,16 @@ discard block |
||
282 | 282 | |
283 | 283 | if ($use_aprs) { |
284 | 284 | require_once(dirname(__FILE__).'/../require/class.APRS.php'); |
285 | - $APRS=new APRS(); |
|
285 | + $APRS = new APRS(); |
|
286 | 286 | $aprs_connect = 0; |
287 | 287 | $aprs_keep = 120; |
288 | 288 | $aprs_last_tx = time(); |
289 | 289 | if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
290 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
290 | + else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName); |
|
291 | 291 | if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid; |
292 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
292 | + else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8); |
|
293 | 293 | if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
294 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
294 | + else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
295 | 295 | if ($aprs_full) $aprs_filter = ''; |
296 | 296 | |
297 | 297 | if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n"; |
@@ -303,12 +303,12 @@ discard block |
||
303 | 303 | sleep(1); |
304 | 304 | if ($globalDebug) echo "SCAN MODE \n\n"; |
305 | 305 | if (!isset($globalCronEnd)) $globalCronEnd = 60; |
306 | -$endtime = time()+$globalCronEnd; |
|
306 | +$endtime = time() + $globalCronEnd; |
|
307 | 307 | $i = 1; |
308 | 308 | $tt = array(); |
309 | 309 | // Delete all ATC |
310 | 310 | if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) { |
311 | - $ATC=new ATC($Connection->db); |
|
311 | + $ATC = new ATC($Connection->db); |
|
312 | 312 | } |
313 | 313 | if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
314 | 314 | $ATC->deleteAll(); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | |
317 | 317 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
318 | 318 | while ($i > 0) { |
319 | - if (!$globalDaemon) $i = $endtime-time(); |
|
319 | + if (!$globalDaemon) $i = $endtime - time(); |
|
320 | 320 | // Delete old ATC |
321 | 321 | if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
322 | 322 | if ($globalDebug) echo 'Delete old ATC...'."\n"; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | } |
331 | 331 | if ($max != $globalMinFetch) { |
332 | 332 | if ($globalDebug) echo 'Sleeping...'."\n"; |
333 | - sleep($globalMinFetch-$max+2); |
|
333 | + sleep($globalMinFetch - $max + 2); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | //$buffer = $Common->getData($hosts[$id]); |
344 | 344 | $buffer = $Common->getData($value['host']); |
345 | 345 | if ($buffer != '') $reset = 0; |
346 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
347 | - $buffer = explode('\n',$buffer); |
|
346 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
347 | + $buffer = explode('\n', $buffer); |
|
348 | 348 | foreach ($buffer as $line) { |
349 | 349 | if ($line != '' && count($line) > 7) { |
350 | 350 | $line = explode(',', $line); |
@@ -373,8 +373,8 @@ discard block |
||
373 | 373 | } elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) { |
374 | 374 | //$buffer = $Common->getData($hosts[$id]); |
375 | 375 | $buffer = $Common->getData($value['host']); |
376 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
377 | - $buffer = explode('\n',$buffer); |
|
376 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
377 | + $buffer = explode('\n', $buffer); |
|
378 | 378 | $reset = 0; |
379 | 379 | foreach ($buffer as $line) { |
380 | 380 | if ($line != '') { |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
386 | 386 | $data['pilot_id'] = $line[1]; |
387 | 387 | $data['pilot_name'] = $line[2]; |
388 | - $data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT); |
|
388 | + $data['hex'] = str_pad(dechex($line[1]), 6, '000000', STR_PAD_LEFT); |
|
389 | 389 | $data['ident'] = $line[0]; // ident |
390 | 390 | if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
391 | 391 | $data['speed'] = $line[8]; // speed |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37])); |
402 | 402 | //if (isset($line[37])) $data['last_update'] = $line[37]; |
403 | 403 | $data['departure_airport_icao'] = $line[11]; |
404 | - $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':'); |
|
404 | + $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':'); |
|
405 | 405 | $data['arrival_airport_icao'] = $line[13]; |
406 | 406 | $data['frequency'] = $line[4]; |
407 | 407 | $data['type'] = $line[18]; |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | $data['id_source'] = $id_source; |
411 | 411 | //$data['arrival_airport_time'] = ; |
412 | 412 | if ($line[9] != '') { |
413 | - $aircraft_data = explode('/',$line[9]); |
|
413 | + $aircraft_data = explode('/', $line[9]); |
|
414 | 414 | if (isset($aircraft_data[1])) { |
415 | 415 | $data['aircraft_icao'] = $aircraft_data[1]; |
416 | 416 | } |
@@ -424,9 +424,9 @@ discard block |
||
424 | 424 | if ($line[3] == 'PILOT') $SI->add($data); |
425 | 425 | elseif ($line[3] == 'ATC') { |
426 | 426 | //print_r($data); |
427 | - $data['info'] = str_replace('^§','<br />',$data['info']); |
|
428 | - $data['info'] = str_replace('&sect;','',$data['info']); |
|
429 | - $typec = substr($data['ident'],-3); |
|
427 | + $data['info'] = str_replace('^§', '<br />', $data['info']); |
|
428 | + $data['info'] = str_replace('&sect;', '', $data['info']); |
|
429 | + $typec = substr($data['ident'], -3); |
|
430 | 430 | if ($typec == 'APP') $data['type'] = 'Approach'; |
431 | 431 | elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
432 | 432 | elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
438 | 438 | elseif ($data['type'] == '') $data['type'] = 'Observer'; |
439 | 439 | if (!isset($data['source_name'])) $data['source_name'] = ''; |
440 | - echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
|
440 | + echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']); |
|
441 | 441 | } |
442 | 442 | unset($data); |
443 | 443 | } |
@@ -448,9 +448,9 @@ discard block |
||
448 | 448 | $last_exec[$id]['last'] = time(); |
449 | 449 | //} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) { |
450 | 450 | } elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
451 | - $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
451 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20'); |
|
452 | 452 | if ($buffer != '') { |
453 | - $all_data = json_decode($buffer,true); |
|
453 | + $all_data = json_decode($buffer, true); |
|
454 | 454 | if (isset($all_data['acList'])) { |
455 | 455 | $reset = 0; |
456 | 456 | foreach ($all_data['acList'] as $line) { |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | //} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { |
507 | 507 | } elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
508 | 508 | $buffer = $Common->getData($value['host']); |
509 | - $all_data = json_decode($buffer,true); |
|
509 | + $all_data = json_decode($buffer, true); |
|
510 | 510 | if (isset($all_data['planes'])) { |
511 | 511 | $reset = 0; |
512 | 512 | foreach ($all_data['planes'] as $key => $line) { |
@@ -523,12 +523,12 @@ discard block |
||
523 | 523 | $data['emergency'] = ''; // emergency |
524 | 524 | $data['registration'] = $line[2]; |
525 | 525 | $data['aircraft_icao'] = $line[0]; |
526 | - $deparr = explode('-',$line[1]); |
|
526 | + $deparr = explode('-', $line[1]); |
|
527 | 527 | if (count($deparr) == 2) { |
528 | 528 | $data['departure_airport_icao'] = $deparr[0]; |
529 | 529 | $data['arrival_airport_icao'] = $deparr[1]; |
530 | 530 | } |
531 | - $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
|
531 | + $data['datetime'] = date('Y-m-d H:i:s', $line[9]); |
|
532 | 532 | $data['format_source'] = 'planeupdatefaa'; |
533 | 533 | $data['id_source'] = $id_source; |
534 | 534 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | $last_exec[$id]['last'] = time(); |
541 | 541 | } elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
542 | 542 | $buffer = $Common->getData($value['host']); |
543 | - $all_data = json_decode($buffer,true); |
|
543 | + $all_data = json_decode($buffer, true); |
|
544 | 544 | if (isset($all_data['states'])) { |
545 | 545 | $reset = 0; |
546 | 546 | foreach ($all_data['states'] as $key => $line) { |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | //$data['emergency'] = ''; // emergency |
558 | 558 | //$data['registration'] = $line[2]; |
559 | 559 | //$data['aircraft_icao'] = $line[0]; |
560 | - $data['datetime'] = date('Y-m-d H:i:s',$line[3]); |
|
560 | + $data['datetime'] = date('Y-m-d H:i:s', $line[3]); |
|
561 | 561 | $data['format_source'] = 'opensky'; |
562 | 562 | $data['id_source'] = $id_source; |
563 | 563 | $SI->add($data); |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | } elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
571 | 571 | //$buffer = $Common->getData($hosts[$id]); |
572 | 572 | $buffer = $Common->getData($value['host']); |
573 | - $all_data = json_decode($buffer,true); |
|
573 | + $all_data = json_decode($buffer, true); |
|
574 | 574 | if (!empty($all_data)) $reset = 0; |
575 | 575 | foreach ($all_data as $key => $line) { |
576 | 576 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
@@ -602,11 +602,11 @@ discard block |
||
602 | 602 | //} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) { |
603 | 603 | } elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
604 | 604 | //$buffer = $Common->getData($hosts[$id],'get','','','','','150'); |
605 | - $buffer = $Common->getData($value['host'],'get','','','','','150'); |
|
605 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150'); |
|
606 | 606 | //echo $buffer; |
607 | - $buffer = str_replace(array("\n","\r"),"",$buffer); |
|
608 | - $buffer = preg_replace('/,"num":(.+)/','}',$buffer); |
|
609 | - $all_data = json_decode($buffer,true); |
|
607 | + $buffer = str_replace(array("\n", "\r"), "", $buffer); |
|
608 | + $buffer = preg_replace('/,"num":(.+)/', '}', $buffer); |
|
609 | + $all_data = json_decode($buffer, true); |
|
610 | 610 | if (json_last_error() != JSON_ERROR_NONE) { |
611 | 611 | die(json_last_error_msg()); |
612 | 612 | } |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | //$data['departure_airport_iata'] = $line[11]; |
630 | 630 | //$data['arrival_airport_iata'] = $line[12]; |
631 | 631 | //$data['emergency'] = ''; // emergency |
632 | - $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
|
632 | + $data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10] |
|
633 | 633 | $data['format_source'] = 'radarvirtueljson'; |
634 | 634 | $data['id_source'] = $id_source; |
635 | 635 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
@@ -644,14 +644,14 @@ discard block |
||
644 | 644 | } elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
645 | 645 | //$buffer = $Common->getData($hosts[$id]); |
646 | 646 | $buffer = $Common->getData($value['host'].'?'.time()); |
647 | - $all_data = json_decode(utf8_encode($buffer),true); |
|
647 | + $all_data = json_decode(utf8_encode($buffer), true); |
|
648 | 648 | |
649 | 649 | if (isset($all_data['pireps'])) { |
650 | 650 | $reset = 0; |
651 | 651 | foreach ($all_data['pireps'] as $line) { |
652 | 652 | $data = array(); |
653 | 653 | $data['id'] = $line['id']; |
654 | - $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
|
654 | + $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6); |
|
655 | 655 | $data['ident'] = $line['callsign']; // ident |
656 | 656 | if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
657 | 657 | if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
@@ -680,9 +680,9 @@ discard block |
||
680 | 680 | $SI->add($data); |
681 | 681 | // print_r($data); |
682 | 682 | } elseif ($line['icon'] == 'ct') { |
683 | - $data['info'] = str_replace('^§','<br />',$data['info']); |
|
684 | - $data['info'] = str_replace('&sect;','',$data['info']); |
|
685 | - $typec = substr($data['ident'],-3); |
|
683 | + $data['info'] = str_replace('^§', '<br />', $data['info']); |
|
684 | + $data['info'] = str_replace('&sect;', '', $data['info']); |
|
685 | + $typec = substr($data['ident'], -3); |
|
686 | 686 | $data['type'] = ''; |
687 | 687 | if ($typec == 'APP') $data['type'] = 'Approach'; |
688 | 688 | elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
694 | 694 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
695 | 695 | else $data['type'] = 'Observer'; |
696 | - echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']); |
|
696 | + echo $ATC->add($data['ident'], '', $data['latitude'], $data['longitude'], '0', $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source']); |
|
697 | 697 | } |
698 | 698 | unset($data); |
699 | 699 | } |
@@ -705,14 +705,14 @@ discard block |
||
705 | 705 | //$buffer = $Common->getData($hosts[$id]); |
706 | 706 | if ($globalDebug) echo 'Get Data...'."\n"; |
707 | 707 | $buffer = $Common->getData($value['host']); |
708 | - $all_data = json_decode($buffer,true); |
|
708 | + $all_data = json_decode($buffer, true); |
|
709 | 709 | if ($buffer != '' && is_array($all_data)) { |
710 | 710 | $reset = 0; |
711 | 711 | foreach ($all_data as $line) { |
712 | 712 | $data = array(); |
713 | 713 | //$data['id'] = $line['id']; // id not usable |
714 | 714 | if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
715 | - $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
715 | + $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex |
|
716 | 716 | if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
717 | 717 | if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
718 | 718 | $data['ident'] = $line['flightnum']; // ident |
@@ -735,12 +735,12 @@ discard block |
||
735 | 735 | if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
736 | 736 | if (isset($line['aircraftname'])) { |
737 | 737 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
738 | - $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
|
739 | - $aircraft_data = explode('-',$line['aircraftname']); |
|
738 | + $line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']); |
|
739 | + $aircraft_data = explode('-', $line['aircraftname']); |
|
740 | 740 | if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
741 | 741 | elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
742 | 742 | else { |
743 | - $aircraft_data = explode(' ',$line['aircraftname']); |
|
743 | + $aircraft_data = explode(' ', $line['aircraftname']); |
|
744 | 744 | if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
745 | 745 | else $data['aircraft_icao'] = $line['aircraftname']; |
746 | 746 | } |
@@ -762,14 +762,14 @@ discard block |
||
762 | 762 | //$buffer = $Common->getData($hosts[$id]); |
763 | 763 | if ($globalDebug) echo 'Get Data...'."\n"; |
764 | 764 | $buffer = $Common->getData($value['host']); |
765 | - $all_data = json_decode($buffer,true); |
|
765 | + $all_data = json_decode($buffer, true); |
|
766 | 766 | if ($buffer != '' && is_array($all_data)) { |
767 | 767 | $reset = 0; |
768 | 768 | foreach ($all_data as $line) { |
769 | 769 | $data = array(); |
770 | 770 | //$data['id'] = $line['id']; // id not usable |
771 | 771 | $data['id'] = trim($line['flight_id']); |
772 | - $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
772 | + $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex |
|
773 | 773 | $data['pilot_name'] = $line['pilot_name']; |
774 | 774 | $data['pilot_id'] = $line['pilot_id']; |
775 | 775 | $data['ident'] = trim($line['callsign']); // ident |
@@ -820,9 +820,9 @@ discard block |
||
820 | 820 | //$value = $formats[$nb]; |
821 | 821 | $format = $globalSources[$nb]['format']; |
822 | 822 | if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { |
823 | - $buffer = socket_read($r, 6000,PHP_NORMAL_READ); |
|
823 | + $buffer = socket_read($r, 6000, PHP_NORMAL_READ); |
|
824 | 824 | } else { |
825 | - $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port); |
|
825 | + $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port); |
|
826 | 826 | } |
827 | 827 | //$buffer = socket_read($r, 60000,PHP_NORMAL_READ); |
828 | 828 | //echo $buffer."\n"; |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | //if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
831 | 831 | $error = false; |
832 | 832 | //$SI::del(); |
833 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
833 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer)); |
|
834 | 834 | // SBS format is CSV format |
835 | 835 | if ($buffer != '') { |
836 | 836 | $tt[$format] = 0; |
@@ -851,10 +851,10 @@ discard block |
||
851 | 851 | } elseif ($format == 'flightgearsp') { |
852 | 852 | //echo $buffer."\n"; |
853 | 853 | if (strlen($buffer) > 5) { |
854 | - $line = explode(',',$buffer); |
|
854 | + $line = explode(',', $buffer); |
|
855 | 855 | $data = array(); |
856 | 856 | //XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p |
857 | - $data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6); |
|
857 | + $data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6); |
|
858 | 858 | $data['ident'] = $line[6]; |
859 | 859 | $data['aircraft_name'] = $line[7]; |
860 | 860 | $data['longitude'] = $line[1]; |
@@ -865,21 +865,21 @@ discard block |
||
865 | 865 | $data['datetime'] = date('Y-m-d H:i:s'); |
866 | 866 | $data['format_source'] = 'flightgearsp'; |
867 | 867 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
868 | - $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
|
868 | + $send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0); |
|
869 | 869 | } |
870 | 870 | } elseif ($format == 'acars') { |
871 | 871 | if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
872 | 872 | $ACARS->add(trim($buffer)); |
873 | - socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
|
873 | + socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port); |
|
874 | 874 | $ACARS->deleteLiveAcarsData(); |
875 | 875 | } elseif ($format == 'flightgearmp') { |
876 | - if (substr($buffer,0,1) != '#') { |
|
876 | + if (substr($buffer, 0, 1) != '#') { |
|
877 | 877 | $data = array(); |
878 | 878 | //echo $buffer."\n"; |
879 | - $line = explode(' ',$buffer); |
|
879 | + $line = explode(' ', $buffer); |
|
880 | 880 | if (count($line) == 11) { |
881 | - $userserver = explode('@',$line[0]); |
|
882 | - $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex |
|
881 | + $userserver = explode('@', $line[0]); |
|
882 | + $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex |
|
883 | 883 | $data['ident'] = $userserver[0]; |
884 | 884 | $data['registration'] = $userserver[0]; |
885 | 885 | $data['latitude'] = $line[4]; |
@@ -887,24 +887,24 @@ discard block |
||
887 | 887 | $data['altitude'] = $line[6]; |
888 | 888 | $data['datetime'] = date('Y-m-d H:i:s'); |
889 | 889 | $aircraft_type = $line[10]; |
890 | - $aircraft_type = preg_split(':/:',$aircraft_type); |
|
891 | - $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
|
890 | + $aircraft_type = preg_split(':/:', $aircraft_type); |
|
891 | + $data['aircraft_name'] = substr(end($aircraft_type), 0, -4); |
|
892 | 892 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
893 | 893 | } |
894 | 894 | } |
895 | 895 | } elseif ($format == 'beast') { |
896 | 896 | echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n"; |
897 | 897 | die; |
898 | - } elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') { |
|
898 | + } elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') { |
|
899 | 899 | $line = explode("\t", $buffer); |
900 | - for($k = 0; $k < count($line); $k=$k+2) { |
|
900 | + for ($k = 0; $k < count($line); $k = $k + 2) { |
|
901 | 901 | $key = $line[$k]; |
902 | - $lined[$key] = $line[$k+1]; |
|
902 | + $lined[$key] = $line[$k + 1]; |
|
903 | 903 | } |
904 | 904 | if (count($lined) > 3) { |
905 | 905 | $data['hex'] = $lined['hexid']; |
906 | 906 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
907 | - $data['datetime'] = date('Y-m-d H:i:s');; |
|
907 | + $data['datetime'] = date('Y-m-d H:i:s'); ; |
|
908 | 908 | if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
909 | 909 | if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
910 | 910 | if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
@@ -922,21 +922,21 @@ discard block |
||
922 | 922 | } else $error = true; |
923 | 923 | } elseif ($format == 'aprs' && $use_aprs) { |
924 | 924 | if ($aprs_connect == 0) { |
925 | - $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
|
925 | + $send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0); |
|
926 | 926 | $aprs_connect = 1; |
927 | 927 | } |
928 | 928 | |
929 | - if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { |
|
929 | + if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) { |
|
930 | 930 | $aprs_last_tx = time(); |
931 | 931 | $data_aprs = "# Keep alive"; |
932 | - $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
|
932 | + $send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0); |
|
933 | 933 | } |
934 | 934 | |
935 | 935 | //echo 'Connect : '.$aprs_connect.' '.$buffer."\n"; |
936 | - $buffer = str_replace('APRS <- ','',$buffer); |
|
937 | - $buffer = str_replace('APRS -> ','',$buffer); |
|
936 | + $buffer = str_replace('APRS <- ', '', $buffer); |
|
937 | + $buffer = str_replace('APRS -> ', '', $buffer); |
|
938 | 938 | //echo $buffer."\n"; |
939 | - if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') { |
|
939 | + if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') { |
|
940 | 940 | $line = $APRS->parse($buffer); |
941 | 941 | //print_r($line); |
942 | 942 | if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) { |
@@ -944,7 +944,7 @@ discard block |
||
944 | 944 | $data = array(); |
945 | 945 | //print_r($line); |
946 | 946 | $data['hex'] = $line['address']; |
947 | - $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
947 | + $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']); |
|
948 | 948 | //$data['datetime'] = date('Y-m-d H:i:s'); |
949 | 949 | $data['ident'] = $line['ident']; |
950 | 950 | $data['latitude'] = $line['latitude']; |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | $currentdate = date('Y-m-d H:i:s'); |
965 | 965 | $aprsdate = strtotime($data['datetime']); |
966 | 966 | // Accept data if time <= system time + 20s |
967 | - if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
967 | + if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate) + 20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
968 | 968 | $send = $SI->add($data); |
969 | 969 | } else { |
970 | 970 | if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | connect_all($sourceee); |
1055 | 1055 | $sourceee = array(); |
1056 | 1056 | //connect_all($globalSources); |
1057 | - $tt[$format]=0; |
|
1057 | + $tt[$format] = 0; |
|
1058 | 1058 | break; |
1059 | 1059 | } |
1060 | 1060 | } |
@@ -1062,7 +1062,7 @@ discard block |
||
1062 | 1062 | } |
1063 | 1063 | } else { |
1064 | 1064 | $error = socket_strerror(socket_last_error()); |
1065 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1065 | + if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n"; |
|
1066 | 1066 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) { |
1067 | 1067 | if (isset($globalDebug)) echo "Restarting...\n"; |
1068 | 1068 | // Restart the script if possible |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | if ($globalDebug) echo "Shutdown all sockets..."; |
1071 | 1071 | |
1072 | 1072 | foreach ($sockets as $sock) { |
1073 | - @socket_shutdown($sock,2); |
|
1073 | + @socket_shutdown($sock, 2); |
|
1074 | 1074 | @socket_close($sock); |
1075 | 1075 | } |
1076 | 1076 |
@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | require_once(dirname(__FILE__).'/../require/class.Connection.php'); |
15 | 15 | require_once(dirname(__FILE__).'/../require/class.Common.php'); |
16 | 16 | |
17 | -if (!isset($globalDebug)) $globalDebug = FALSE; |
|
17 | +if (!isset($globalDebug)) { |
|
18 | + $globalDebug = FALSE; |
|
19 | +} |
|
18 | 20 | |
19 | 21 | // Check if schema is at latest version |
20 | 22 | $Connection = new Connection(); |
@@ -54,13 +56,22 @@ discard block |
||
54 | 56 | $globalSources = array(); |
55 | 57 | $globalSources[] = array('host' => $options['source']); |
56 | 58 | } |
57 | -if (isset($options['server'])) $globalServer = TRUE; |
|
58 | -if (isset($options['idsource'])) $id_source = $options['idsource']; |
|
59 | -else $id_source = 1; |
|
59 | +if (isset($options['server'])) { |
|
60 | + $globalServer = TRUE; |
|
61 | +} |
|
62 | +if (isset($options['idsource'])) { |
|
63 | + $id_source = $options['idsource']; |
|
64 | +} else { |
|
65 | + $id_source = 1; |
|
66 | +} |
|
60 | 67 | if (isset($globalServer) && $globalServer) { |
61 | - if ($globalDebug) echo "Using Server Mode\n"; |
|
68 | + if ($globalDebug) { |
|
69 | + echo "Using Server Mode\n"; |
|
70 | + } |
|
62 | 71 | $SI=new SpotterServer(); |
63 | -} else $SI=new SpotterImport($Connection->db); |
|
72 | +} else { |
|
73 | + $SI=new SpotterImport($Connection->db); |
|
74 | +} |
|
64 | 75 | //$APRS=new APRS($Connection->db); |
65 | 76 | $SBS=new SBS(); |
66 | 77 | $ACARS=new ACARS($Connection->db); |
@@ -78,7 +89,9 @@ discard block |
||
78 | 89 | } |
79 | 90 | |
80 | 91 | // let's try and connect |
81 | -if ($globalDebug) echo "Connecting...\n"; |
|
92 | +if ($globalDebug) { |
|
93 | + echo "Connecting...\n"; |
|
94 | +} |
|
82 | 95 | $use_aprs = false; |
83 | 96 | $aprs_full = false; |
84 | 97 | $reset = 0; |
@@ -87,7 +100,9 @@ discard block |
||
87 | 100 | $ip = gethostbyname($host); |
88 | 101 | $s = socket_create(AF_INET, SOCK_STREAM, 0); |
89 | 102 | $r = @socket_connect($s, $ip, $port); |
90 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
103 | + if (!socket_set_nonblock($s)) { |
|
104 | + echo "Unable to set nonblock on socket\n"; |
|
105 | + } |
|
91 | 106 | if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
92 | 107 | return $s; |
93 | 108 | } |
@@ -115,7 +130,9 @@ discard block |
||
115 | 130 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
116 | 131 | global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset; |
117 | 132 | $reset++; |
118 | - if ($globalDebug) echo 'Connect to all...'."\n"; |
|
133 | + if ($globalDebug) { |
|
134 | + echo 'Connect to all...'."\n"; |
|
135 | + } |
|
119 | 136 | foreach ($hosts as $id => $value) { |
120 | 137 | $host = $value['host']; |
121 | 138 | $globalSources[$id]['last_exec'] = 0; |
@@ -125,27 +142,37 @@ discard block |
||
125 | 142 | //$formats[$id] = 'deltadbtxt'; |
126 | 143 | $globalSources[$id]['format'] = 'deltadbtxt'; |
127 | 144 | //$last_exec['deltadbtxt'] = 0; |
128 | - if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
|
145 | + if ($globalDebug) { |
|
146 | + echo "Connect to deltadb source (".$host.")...\n"; |
|
147 | + } |
|
129 | 148 | } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
130 | 149 | //$formats[$id] = 'vatsimtxt'; |
131 | 150 | $globalSources[$id]['format'] = 'vatsimtxt'; |
132 | 151 | //$last_exec['vatsimtxt'] = 0; |
133 | - if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
|
152 | + if ($globalDebug) { |
|
153 | + echo "Connect to vatsim source (".$host.")...\n"; |
|
154 | + } |
|
134 | 155 | } else if (preg_match('/aircraftlist.json$/i',$host)) { |
135 | 156 | //$formats[$id] = 'aircraftlistjson'; |
136 | 157 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
137 | 158 | //$last_exec['aircraftlistjson'] = 0; |
138 | - if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
159 | + if ($globalDebug) { |
|
160 | + echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
161 | + } |
|
139 | 162 | } else if (preg_match('/opensky/i',$host)) { |
140 | 163 | //$formats[$id] = 'aircraftlistjson'; |
141 | 164 | $globalSources[$id]['format'] = 'opensky'; |
142 | 165 | //$last_exec['aircraftlistjson'] = 0; |
143 | - if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
|
166 | + if ($globalDebug) { |
|
167 | + echo "Connect to opensky source (".$host.")...\n"; |
|
168 | + } |
|
144 | 169 | } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
145 | 170 | //$formats[$id] = 'radarvirtueljson'; |
146 | 171 | $globalSources[$id]['format'] = 'radarvirtueljson'; |
147 | 172 | //$last_exec['radarvirtueljson'] = 0; |
148 | - if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
173 | + if ($globalDebug) { |
|
174 | + echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
175 | + } |
|
149 | 176 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
150 | 177 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
151 | 178 | exit(0); |
@@ -154,7 +181,9 @@ discard block |
||
154 | 181 | //$formats[$id] = 'planeupdatefaa'; |
155 | 182 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
156 | 183 | //$last_exec['planeupdatefaa'] = 0; |
157 | - if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
184 | + if ($globalDebug) { |
|
185 | + echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
186 | + } |
|
158 | 187 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
159 | 188 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
160 | 189 | exit(0); |
@@ -163,26 +192,36 @@ discard block |
||
163 | 192 | //$formats[$id] = 'phpvmacars'; |
164 | 193 | $globalSources[$id]['format'] = 'phpvmacars'; |
165 | 194 | //$last_exec['phpvmacars'] = 0; |
166 | - if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
|
195 | + if ($globalDebug) { |
|
196 | + echo "Connect to phpvmacars source (".$host.")...\n"; |
|
197 | + } |
|
167 | 198 | } else if (preg_match('/VAM-json.php$/i',$host)) { |
168 | 199 | //$formats[$id] = 'phpvmacars'; |
169 | 200 | $globalSources[$id]['format'] = 'vam'; |
170 | - if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
|
201 | + if ($globalDebug) { |
|
202 | + echo "Connect to Vam source (".$host.")...\n"; |
|
203 | + } |
|
171 | 204 | } else if (preg_match('/whazzup/i',$host)) { |
172 | 205 | //$formats[$id] = 'whazzup'; |
173 | 206 | $globalSources[$id]['format'] = 'whazzup'; |
174 | 207 | //$last_exec['whazzup'] = 0; |
175 | - if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
|
208 | + if ($globalDebug) { |
|
209 | + echo "Connect to whazzup source (".$host.")...\n"; |
|
210 | + } |
|
176 | 211 | } else if (preg_match('/recentpireps/i',$host)) { |
177 | 212 | //$formats[$id] = 'pirepsjson'; |
178 | 213 | $globalSources[$id]['format'] = 'pirepsjson'; |
179 | 214 | //$last_exec['pirepsjson'] = 0; |
180 | - if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
|
215 | + if ($globalDebug) { |
|
216 | + echo "Connect to pirepsjson source (".$host.")...\n"; |
|
217 | + } |
|
181 | 218 | } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
182 | 219 | //$formats[$id] = 'fr24json'; |
183 | 220 | $globalSources[$id]['format'] = 'fr24json'; |
184 | 221 | //$last_exec['fr24json'] = 0; |
185 | - if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; |
|
222 | + if ($globalDebug) { |
|
223 | + echo "Connect to fr24 source (".$host.")...\n"; |
|
224 | + } |
|
186 | 225 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
187 | 226 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
188 | 227 | exit(0); |
@@ -191,10 +230,14 @@ discard block |
||
191 | 230 | } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
192 | 231 | //$formats[$id] = 'tsv'; |
193 | 232 | $globalSources[$id]['format'] = 'tsv'; |
194 | - if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
|
233 | + if ($globalDebug) { |
|
234 | + echo "Connect to tsv source (".$host.")...\n"; |
|
235 | + } |
|
195 | 236 | } |
196 | 237 | } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
197 | - if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
238 | + if ($globalDebug) { |
|
239 | + echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
240 | + } |
|
198 | 241 | } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
199 | 242 | $hostport = explode(':',$host); |
200 | 243 | if (isset($hostport[1])) { |
@@ -231,17 +274,25 @@ discard block |
||
231 | 274 | //$formats[$id] = 'beast'; |
232 | 275 | $globalSources[$id]['format'] = 'beast'; |
233 | 276 | //} else $formats[$id] = 'sbs'; |
234 | - } else $globalSources[$id]['format'] = 'sbs'; |
|
277 | + } else { |
|
278 | + $globalSources[$id]['format'] = 'sbs'; |
|
279 | + } |
|
235 | 280 | //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; |
236 | 281 | } |
237 | - if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
282 | + if ($globalDebug) { |
|
283 | + echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
284 | + } |
|
238 | 285 | } else { |
239 | - if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
286 | + if ($globalDebug) { |
|
287 | + echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
288 | + } |
|
240 | 289 | } |
241 | 290 | } |
242 | 291 | } |
243 | 292 | } |
244 | -if (!isset($globalMinFetch)) $globalMinFetch = 15; |
|
293 | +if (!isset($globalMinFetch)) { |
|
294 | + $globalMinFetch = 15; |
|
295 | +} |
|
245 | 296 | |
246 | 297 | // Initialize all |
247 | 298 | $status = array(); |
@@ -249,13 +300,19 @@ discard block |
||
249 | 300 | $formats = array(); |
250 | 301 | $last_exec = array(); |
251 | 302 | $time = time(); |
252 | -if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut; |
|
253 | -else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
|
254 | -else $timeout = 20; |
|
303 | +if (isset($globalSourcesTimeout)) { |
|
304 | + $timeout = $globalSourcesTimeOut; |
|
305 | +} else if (isset($globalSBS1TimeOut)) { |
|
306 | + $timeout = $globalSBS1TimeOut; |
|
307 | +} else { |
|
308 | + $timeout = 20; |
|
309 | +} |
|
255 | 310 | $errno = ''; |
256 | 311 | $errstr=''; |
257 | 312 | |
258 | -if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
313 | +if (!isset($globalDaemon)) { |
|
314 | + $globalDaemon = TRUE; |
|
315 | +} |
|
259 | 316 | /* Initiate connections to all the hosts simultaneously */ |
260 | 317 | //connect_all($hosts); |
261 | 318 | //connect_all($globalSources); |
@@ -275,7 +332,9 @@ discard block |
||
275 | 332 | if (isset($source['format']) && $source['format'] == 'aprs') { |
276 | 333 | $aprs_connect = 0; |
277 | 334 | $use_aprs = true; |
278 | - if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true; |
|
335 | + if (isset($source['port']) && $source['port'] == '10152') { |
|
336 | + $aprs_full = true; |
|
337 | + } |
|
279 | 338 | break; |
280 | 339 | } |
281 | 340 | } |
@@ -286,23 +345,43 @@ discard block |
||
286 | 345 | $aprs_connect = 0; |
287 | 346 | $aprs_keep = 120; |
288 | 347 | $aprs_last_tx = time(); |
289 | - if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
|
290 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
291 | - if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid; |
|
292 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
293 | - if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
|
294 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
295 | - if ($aprs_full) $aprs_filter = ''; |
|
348 | + if (isset($globalAPRSversion)) { |
|
349 | + $aprs_version = $globalAPRSversion; |
|
350 | + } else { |
|
351 | + $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
352 | + } |
|
353 | + if (isset($globalAPRSssid)) { |
|
354 | + $aprs_ssid = $globalAPRSssid; |
|
355 | + } else { |
|
356 | + $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
357 | + } |
|
358 | + if (isset($globalAPRSfilter)) { |
|
359 | + $aprs_filter = $globalAPRSfilter; |
|
360 | + } else { |
|
361 | + $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
362 | + } |
|
363 | + if ($aprs_full) { |
|
364 | + $aprs_filter = ''; |
|
365 | + } |
|
296 | 366 | |
297 | - if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n"; |
|
298 | - else $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n"; |
|
299 | -} |
|
367 | + if ($aprs_filter != '') { |
|
368 | + $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n"; |
|
369 | + } else { |
|
370 | + $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n"; |
|
371 | + } |
|
372 | + } |
|
300 | 373 | |
301 | 374 | // connected - lets do some work |
302 | -if ($globalDebug) echo "Connected!\n"; |
|
375 | +if ($globalDebug) { |
|
376 | + echo "Connected!\n"; |
|
377 | +} |
|
303 | 378 | sleep(1); |
304 | -if ($globalDebug) echo "SCAN MODE \n\n"; |
|
305 | -if (!isset($globalCronEnd)) $globalCronEnd = 60; |
|
379 | +if ($globalDebug) { |
|
380 | + echo "SCAN MODE \n\n"; |
|
381 | +} |
|
382 | +if (!isset($globalCronEnd)) { |
|
383 | + $globalCronEnd = 60; |
|
384 | +} |
|
306 | 385 | $endtime = time()+$globalCronEnd; |
307 | 386 | $i = 1; |
308 | 387 | $tt = array(); |
@@ -316,20 +395,28 @@ discard block |
||
316 | 395 | |
317 | 396 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
318 | 397 | while ($i > 0) { |
319 | - if (!$globalDaemon) $i = $endtime-time(); |
|
398 | + if (!$globalDaemon) { |
|
399 | + $i = $endtime-time(); |
|
400 | + } |
|
320 | 401 | // Delete old ATC |
321 | 402 | if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
322 | - if ($globalDebug) echo 'Delete old ATC...'."\n"; |
|
403 | + if ($globalDebug) { |
|
404 | + echo 'Delete old ATC...'."\n"; |
|
405 | + } |
|
323 | 406 | $ATC->deleteOldATC(); |
324 | 407 | } |
325 | 408 | |
326 | 409 | if (count($last_exec) > 0) { |
327 | 410 | $max = $globalMinFetch; |
328 | 411 | foreach ($last_exec as $last) { |
329 | - if ((time() - $last['last']) < $max) $max = time() - $last['last']; |
|
412 | + if ((time() - $last['last']) < $max) { |
|
413 | + $max = time() - $last['last']; |
|
414 | + } |
|
330 | 415 | } |
331 | 416 | if ($max != $globalMinFetch) { |
332 | - if ($globalDebug) echo 'Sleeping...'."\n"; |
|
417 | + if ($globalDebug) { |
|
418 | + echo 'Sleeping...'."\n"; |
|
419 | + } |
|
333 | 420 | sleep($globalMinFetch-$max+2); |
334 | 421 | } |
335 | 422 | } |
@@ -338,11 +425,15 @@ discard block |
||
338 | 425 | //foreach ($formats as $id => $value) { |
339 | 426 | foreach ($globalSources as $id => $value) { |
340 | 427 | date_default_timezone_set('UTC'); |
341 | - if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0; |
|
428 | + if (!isset($last_exec[$id]['last'])) { |
|
429 | + $last_exec[$id]['last'] = 0; |
|
430 | + } |
|
342 | 431 | if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
343 | 432 | //$buffer = $Common->getData($hosts[$id]); |
344 | 433 | $buffer = $Common->getData($value['host']); |
345 | - if ($buffer != '') $reset = 0; |
|
434 | + if ($buffer != '') { |
|
435 | + $reset = 0; |
|
436 | + } |
|
346 | 437 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
347 | 438 | $buffer = explode('\n',$buffer); |
348 | 439 | foreach ($buffer as $line) { |
@@ -351,19 +442,38 @@ discard block |
||
351 | 442 | $data = array(); |
352 | 443 | $data['hex'] = $line[1]; // hex |
353 | 444 | $data['ident'] = $line[2]; // ident |
354 | - if (isset($line[3])) $data['altitude'] = $line[3]; // altitude |
|
355 | - if (isset($line[4])) $data['speed'] = $line[4]; // speed |
|
356 | - if (isset($line[5])) $data['heading'] = $line[5]; // heading |
|
357 | - if (isset($line[6])) $data['latitude'] = $line[6]; // lat |
|
358 | - if (isset($line[7])) $data['longitude'] = $line[7]; // long |
|
445 | + if (isset($line[3])) { |
|
446 | + $data['altitude'] = $line[3]; |
|
447 | + } |
|
448 | + // altitude |
|
449 | + if (isset($line[4])) { |
|
450 | + $data['speed'] = $line[4]; |
|
451 | + } |
|
452 | + // speed |
|
453 | + if (isset($line[5])) { |
|
454 | + $data['heading'] = $line[5]; |
|
455 | + } |
|
456 | + // heading |
|
457 | + if (isset($line[6])) { |
|
458 | + $data['latitude'] = $line[6]; |
|
459 | + } |
|
460 | + // lat |
|
461 | + if (isset($line[7])) { |
|
462 | + $data['longitude'] = $line[7]; |
|
463 | + } |
|
464 | + // long |
|
359 | 465 | $data['verticalrate'] = ''; // vertical rate |
360 | 466 | //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk |
361 | 467 | $data['emergency'] = ''; // emergency |
362 | 468 | $data['datetime'] = date('Y-m-d H:i:s'); |
363 | 469 | $data['format_source'] = 'deltadbtxt'; |
364 | 470 | $data['id_source'] = $id_source; |
365 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
366 | - if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats']; |
|
471 | + if (isset($value['name']) && $value['name'] != '') { |
|
472 | + $data['source_name'] = $value['name']; |
|
473 | + } |
|
474 | + if (isset($value['sourcestats'])) { |
|
475 | + $data['sourcestats'] = $value['sourcestats']; |
|
476 | + } |
|
367 | 477 | $SI->add($data); |
368 | 478 | unset($data); |
369 | 479 | } |
@@ -381,16 +491,28 @@ discard block |
||
381 | 491 | $line = explode(':', $line); |
382 | 492 | if (count($line) > 30 && $line[0] != 'callsign') { |
383 | 493 | $data = array(); |
384 | - if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
|
385 | - else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
|
494 | + if (isset($line[37]) && $line[37] != '') { |
|
495 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
|
496 | + } else { |
|
497 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
|
498 | + } |
|
386 | 499 | $data['pilot_id'] = $line[1]; |
387 | 500 | $data['pilot_name'] = $line[2]; |
388 | 501 | $data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT); |
389 | 502 | $data['ident'] = $line[0]; // ident |
390 | - if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
|
503 | + if ($line[7] != '' && $line[7] != 0) { |
|
504 | + $data['altitude'] = $line[7]; |
|
505 | + } |
|
506 | + // altitude |
|
391 | 507 | $data['speed'] = $line[8]; // speed |
392 | - if (isset($line[45])) $data['heading'] = $line[45]; // heading |
|
393 | - elseif (isset($line[38])) $data['heading'] = $line[38]; // heading |
|
508 | + if (isset($line[45])) { |
|
509 | + $data['heading'] = $line[45]; |
|
510 | + } |
|
511 | + // heading |
|
512 | + elseif (isset($line[38])) { |
|
513 | + $data['heading'] = $line[38]; |
|
514 | + } |
|
515 | + // heading |
|
394 | 516 | $data['latitude'] = $line[5]; // lat |
395 | 517 | $data['longitude'] = $line[6]; // long |
396 | 518 | $data['verticalrate'] = ''; // vertical rate |
@@ -406,7 +528,9 @@ discard block |
||
406 | 528 | $data['frequency'] = $line[4]; |
407 | 529 | $data['type'] = $line[18]; |
408 | 530 | $data['range'] = $line[19]; |
409 | - if (isset($line[35])) $data['info'] = $line[35]; |
|
531 | + if (isset($line[35])) { |
|
532 | + $data['info'] = $line[35]; |
|
533 | + } |
|
410 | 534 | $data['id_source'] = $id_source; |
411 | 535 | //$data['arrival_airport_time'] = ; |
412 | 536 | if ($line[9] != '') { |
@@ -420,23 +544,38 @@ discard block |
||
420 | 544 | elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt'; |
421 | 545 | */ |
422 | 546 | $data['format_source'] = $value['format']; |
423 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
424 | - if ($line[3] == 'PILOT') $SI->add($data); |
|
425 | - elseif ($line[3] == 'ATC') { |
|
547 | + if (isset($value['name']) && $value['name'] != '') { |
|
548 | + $data['source_name'] = $value['name']; |
|
549 | + } |
|
550 | + if ($line[3] == 'PILOT') { |
|
551 | + $SI->add($data); |
|
552 | + } elseif ($line[3] == 'ATC') { |
|
426 | 553 | //print_r($data); |
427 | 554 | $data['info'] = str_replace('^§','<br />',$data['info']); |
428 | 555 | $data['info'] = str_replace('&sect;','',$data['info']); |
429 | 556 | $typec = substr($data['ident'],-3); |
430 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
431 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
432 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
433 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
434 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
435 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
436 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
437 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
438 | - elseif ($data['type'] == '') $data['type'] = 'Observer'; |
|
439 | - if (!isset($data['source_name'])) $data['source_name'] = ''; |
|
557 | + if ($typec == 'APP') { |
|
558 | + $data['type'] = 'Approach'; |
|
559 | + } elseif ($typec == 'TWR') { |
|
560 | + $data['type'] = 'Tower'; |
|
561 | + } elseif ($typec == 'OBS') { |
|
562 | + $data['type'] = 'Observer'; |
|
563 | + } elseif ($typec == 'GND') { |
|
564 | + $data['type'] = 'Ground'; |
|
565 | + } elseif ($typec == 'DEL') { |
|
566 | + $data['type'] = 'Delivery'; |
|
567 | + } elseif ($typec == 'DEP') { |
|
568 | + $data['type'] = 'Departure'; |
|
569 | + } elseif ($typec == 'FSS') { |
|
570 | + $data['type'] = 'Flight Service Station'; |
|
571 | + } elseif ($typec == 'CTR') { |
|
572 | + $data['type'] = 'Control Radar or Centre'; |
|
573 | + } elseif ($data['type'] == '') { |
|
574 | + $data['type'] = 'Observer'; |
|
575 | + } |
|
576 | + if (!isset($data['source_name'])) { |
|
577 | + $data['source_name'] = ''; |
|
578 | + } |
|
440 | 579 | echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
441 | 580 | } |
442 | 581 | unset($data); |
@@ -456,26 +595,55 @@ discard block |
||
456 | 595 | foreach ($all_data['acList'] as $line) { |
457 | 596 | $data = array(); |
458 | 597 | $data['hex'] = $line['Icao']; // hex |
459 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
|
460 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude |
|
461 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed |
|
462 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading |
|
463 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat |
|
464 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long |
|
598 | + if (isset($line['Call'])) { |
|
599 | + $data['ident'] = $line['Call']; |
|
600 | + } |
|
601 | + // ident |
|
602 | + if (isset($line['Alt'])) { |
|
603 | + $data['altitude'] = $line['Alt']; |
|
604 | + } |
|
605 | + // altitude |
|
606 | + if (isset($line['Spd'])) { |
|
607 | + $data['speed'] = $line['Spd']; |
|
608 | + } |
|
609 | + // speed |
|
610 | + if (isset($line['Trak'])) { |
|
611 | + $data['heading'] = $line['Trak']; |
|
612 | + } |
|
613 | + // heading |
|
614 | + if (isset($line['Lat'])) { |
|
615 | + $data['latitude'] = $line['Lat']; |
|
616 | + } |
|
617 | + // lat |
|
618 | + if (isset($line['Long'])) { |
|
619 | + $data['longitude'] = $line['Long']; |
|
620 | + } |
|
621 | + // long |
|
465 | 622 | //$data['verticalrate'] = $line['']; // verticale rate |
466 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
|
623 | + if (isset($line['Sqk'])) { |
|
624 | + $data['squawk'] = $line['Sqk']; |
|
625 | + } |
|
626 | + // squawk |
|
467 | 627 | $data['emergency'] = ''; // emergency |
468 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
|
628 | + if (isset($line['Reg'])) { |
|
629 | + $data['registration'] = $line['Reg']; |
|
630 | + } |
|
469 | 631 | /* |
470 | 632 | if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000); |
471 | 633 | else $data['datetime'] = date('Y-m-d H:i:s'); |
472 | 634 | */ |
473 | 635 | $data['datetime'] = date('Y-m-d H:i:s'); |
474 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
|
636 | + if (isset($line['Type'])) { |
|
637 | + $data['aircraft_icao'] = $line['Type']; |
|
638 | + } |
|
475 | 639 | $data['format_source'] = 'aircraftlistjson'; |
476 | 640 | $data['id_source'] = $id_source; |
477 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
478 | - if (isset($data['datetime'])) $SI->add($data); |
|
641 | + if (isset($value['name']) && $value['name'] != '') { |
|
642 | + $data['source_name'] = $value['name']; |
|
643 | + } |
|
644 | + if (isset($data['datetime'])) { |
|
645 | + $SI->add($data); |
|
646 | + } |
|
479 | 647 | unset($data); |
480 | 648 | } |
481 | 649 | } else { |
@@ -495,7 +663,9 @@ discard block |
||
495 | 663 | $data['datetime'] = date('Y-m-d H:i:s'); |
496 | 664 | $data['format_source'] = 'aircraftlistjson'; |
497 | 665 | $data['id_source'] = $id_source; |
498 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
666 | + if (isset($value['name']) && $value['name'] != '') { |
|
667 | + $data['source_name'] = $value['name']; |
|
668 | + } |
|
499 | 669 | $SI->add($data); |
500 | 670 | unset($data); |
501 | 671 | } |
@@ -531,7 +701,9 @@ discard block |
||
531 | 701 | $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
532 | 702 | $data['format_source'] = 'planeupdatefaa'; |
533 | 703 | $data['id_source'] = $id_source; |
534 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
704 | + if (isset($value['name']) && $value['name'] != '') { |
|
705 | + $data['source_name'] = $value['name']; |
|
706 | + } |
|
535 | 707 | $SI->add($data); |
536 | 708 | unset($data); |
537 | 709 | } |
@@ -571,7 +743,9 @@ discard block |
||
571 | 743 | //$buffer = $Common->getData($hosts[$id]); |
572 | 744 | $buffer = $Common->getData($value['host']); |
573 | 745 | $all_data = json_decode($buffer,true); |
574 | - if (!empty($all_data)) $reset = 0; |
|
746 | + if (!empty($all_data)) { |
|
747 | + $reset = 0; |
|
748 | + } |
|
575 | 749 | foreach ($all_data as $key => $line) { |
576 | 750 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
577 | 751 | $data = array(); |
@@ -592,7 +766,9 @@ discard block |
||
592 | 766 | $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] |
593 | 767 | $data['format_source'] = 'fr24json'; |
594 | 768 | $data['id_source'] = $id_source; |
595 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
769 | + if (isset($value['name']) && $value['name'] != '') { |
|
770 | + $data['source_name'] = $value['name']; |
|
771 | + } |
|
596 | 772 | $SI->add($data); |
597 | 773 | unset($data); |
598 | 774 | } |
@@ -616,23 +792,39 @@ discard block |
||
616 | 792 | if (isset($line['inf'])) { |
617 | 793 | $data = array(); |
618 | 794 | $data['hex'] = $line['inf']['ia']; |
619 | - if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13] |
|
795 | + if (isset($line['inf']['cs'])) { |
|
796 | + $data['ident'] = $line['inf']['cs']; |
|
797 | + } |
|
798 | + //$line[13] |
|
620 | 799 | $data['altitude'] = round($line['inf']['al']*3.28084); // altitude |
621 | - if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed |
|
622 | - if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading |
|
800 | + if (isset($line['inf']['gs'])) { |
|
801 | + $data['speed'] = round($line['inf']['gs']*0.539957); |
|
802 | + } |
|
803 | + // speed |
|
804 | + if (isset($line['inf']['tr'])) { |
|
805 | + $data['heading'] = $line['inf']['tr']; |
|
806 | + } |
|
807 | + // heading |
|
623 | 808 | $data['latitude'] = $line['pt'][0]; // lat |
624 | 809 | $data['longitude'] = $line['pt'][1]; // long |
625 | 810 | //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate |
626 | - if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk |
|
811 | + if (isset($line['inf']['sq'])) { |
|
812 | + $data['squawk'] = $line['inf']['sq']; |
|
813 | + } |
|
814 | + // squawk |
|
627 | 815 | //$data['aircraft_icao'] = $line[8]; |
628 | - if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc']; |
|
816 | + if (isset($line['inf']['rc'])) { |
|
817 | + $data['registration'] = $line['inf']['rc']; |
|
818 | + } |
|
629 | 819 | //$data['departure_airport_iata'] = $line[11]; |
630 | 820 | //$data['arrival_airport_iata'] = $line[12]; |
631 | 821 | //$data['emergency'] = ''; // emergency |
632 | 822 | $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
633 | 823 | $data['format_source'] = 'radarvirtueljson'; |
634 | 824 | $data['id_source'] = $id_source; |
635 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
825 | + if (isset($value['name']) && $value['name'] != '') { |
|
826 | + $data['source_name'] = $value['name']; |
|
827 | + } |
|
636 | 828 | $SI->add($data); |
637 | 829 | unset($data); |
638 | 830 | } |
@@ -653,29 +845,62 @@ discard block |
||
653 | 845 | $data['id'] = $line['id']; |
654 | 846 | $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
655 | 847 | $data['ident'] = $line['callsign']; // ident |
656 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
|
657 | - if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
|
658 | - if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude |
|
659 | - if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed |
|
660 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading |
|
661 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
848 | + if (isset($line['pilotid'])) { |
|
849 | + $data['pilot_id'] = $line['pilotid']; |
|
850 | + } |
|
851 | + // pilot id |
|
852 | + if (isset($line['name'])) { |
|
853 | + $data['pilot_name'] = $line['name']; |
|
854 | + } |
|
855 | + // pilot name |
|
856 | + if (isset($line['alt'])) { |
|
857 | + $data['altitude'] = $line['alt']; |
|
858 | + } |
|
859 | + // altitude |
|
860 | + if (isset($line['gs'])) { |
|
861 | + $data['speed'] = $line['gs']; |
|
862 | + } |
|
863 | + // speed |
|
864 | + if (isset($line['heading'])) { |
|
865 | + $data['heading'] = $line['heading']; |
|
866 | + } |
|
867 | + // heading |
|
868 | + if (isset($line['route'])) { |
|
869 | + $data['waypoints'] = $line['route']; |
|
870 | + } |
|
871 | + // route |
|
662 | 872 | $data['latitude'] = $line['lat']; // lat |
663 | 873 | $data['longitude'] = $line['lon']; // long |
664 | 874 | //$data['verticalrate'] = $line['vrt']; // verticale rate |
665 | 875 | //$data['squawk'] = $line['squawk']; // squawk |
666 | 876 | //$data['emergency'] = ''; // emergency |
667 | - if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao']; |
|
668 | - if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime']; |
|
669 | - if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao']; |
|
877 | + if (isset($line['depicao'])) { |
|
878 | + $data['departure_airport_icao'] = $line['depicao']; |
|
879 | + } |
|
880 | + if (isset($line['deptime'])) { |
|
881 | + $data['departure_airport_time'] = $line['deptime']; |
|
882 | + } |
|
883 | + if (isset($line['arricao'])) { |
|
884 | + $data['arrival_airport_icao'] = $line['arricao']; |
|
885 | + } |
|
670 | 886 | //$data['arrival_airport_time'] = $line['arrtime']; |
671 | - if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft']; |
|
672 | - if (isset($line['transponder'])) $data['squawk'] = $line['transponder']; |
|
673 | - if (isset($line['atis'])) $data['info'] = $line['atis']; |
|
674 | - else $data['info'] = ''; |
|
887 | + if (isset($line['aircraft'])) { |
|
888 | + $data['aircraft_icao'] = $line['aircraft']; |
|
889 | + } |
|
890 | + if (isset($line['transponder'])) { |
|
891 | + $data['squawk'] = $line['transponder']; |
|
892 | + } |
|
893 | + if (isset($line['atis'])) { |
|
894 | + $data['info'] = $line['atis']; |
|
895 | + } else { |
|
896 | + $data['info'] = ''; |
|
897 | + } |
|
675 | 898 | $data['format_source'] = 'pireps'; |
676 | 899 | $data['id_source'] = $id_source; |
677 | 900 | $data['datetime'] = date('Y-m-d H:i:s'); |
678 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
901 | + if (isset($value['name']) && $value['name'] != '') { |
|
902 | + $data['source_name'] = $value['name']; |
|
903 | + } |
|
679 | 904 | if ($line['icon'] == 'plane') { |
680 | 905 | $SI->add($data); |
681 | 906 | // print_r($data); |
@@ -684,15 +909,25 @@ discard block |
||
684 | 909 | $data['info'] = str_replace('&sect;','',$data['info']); |
685 | 910 | $typec = substr($data['ident'],-3); |
686 | 911 | $data['type'] = ''; |
687 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
688 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
689 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
690 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
691 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
692 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
693 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
694 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
695 | - else $data['type'] = 'Observer'; |
|
912 | + if ($typec == 'APP') { |
|
913 | + $data['type'] = 'Approach'; |
|
914 | + } elseif ($typec == 'TWR') { |
|
915 | + $data['type'] = 'Tower'; |
|
916 | + } elseif ($typec == 'OBS') { |
|
917 | + $data['type'] = 'Observer'; |
|
918 | + } elseif ($typec == 'GND') { |
|
919 | + $data['type'] = 'Ground'; |
|
920 | + } elseif ($typec == 'DEL') { |
|
921 | + $data['type'] = 'Delivery'; |
|
922 | + } elseif ($typec == 'DEP') { |
|
923 | + $data['type'] = 'Departure'; |
|
924 | + } elseif ($typec == 'FSS') { |
|
925 | + $data['type'] = 'Flight Service Station'; |
|
926 | + } elseif ($typec == 'CTR') { |
|
927 | + $data['type'] = 'Control Radar or Centre'; |
|
928 | + } else { |
|
929 | + $data['type'] = 'Observer'; |
|
930 | + } |
|
696 | 931 | echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']); |
697 | 932 | } |
698 | 933 | unset($data); |
@@ -703,7 +938,9 @@ discard block |
||
703 | 938 | //} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { |
704 | 939 | } elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
705 | 940 | //$buffer = $Common->getData($hosts[$id]); |
706 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
941 | + if ($globalDebug) { |
|
942 | + echo 'Get Data...'."\n"; |
|
943 | + } |
|
707 | 944 | $buffer = $Common->getData($value['host']); |
708 | 945 | $all_data = json_decode($buffer,true); |
709 | 946 | if ($buffer != '' && is_array($all_data)) { |
@@ -711,10 +948,16 @@ discard block |
||
711 | 948 | foreach ($all_data as $line) { |
712 | 949 | $data = array(); |
713 | 950 | //$data['id'] = $line['id']; // id not usable |
714 | - if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
|
951 | + if (isset($line['pilotid'])) { |
|
952 | + $data['id'] = $line['pilotid'].$line['flightnum']; |
|
953 | + } |
|
715 | 954 | $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
716 | - if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
|
717 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
|
955 | + if (isset($line['pilotname'])) { |
|
956 | + $data['pilot_name'] = $line['pilotname']; |
|
957 | + } |
|
958 | + if (isset($line['pilotid'])) { |
|
959 | + $data['pilot_id'] = $line['pilotid']; |
|
960 | + } |
|
718 | 961 | $data['ident'] = $line['flightnum']; // ident |
719 | 962 | $data['altitude'] = $line['alt']; // altitude |
720 | 963 | $data['speed'] = $line['gs']; // speed |
@@ -732,27 +975,41 @@ discard block |
||
732 | 975 | $data['arrival_airport_icao'] = $line['arricao']; |
733 | 976 | $data['arrival_airport_time'] = $line['arrtime']; |
734 | 977 | $data['registration'] = $line['aircraft']; |
735 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
978 | + if (isset($line['route'])) { |
|
979 | + $data['waypoints'] = $line['route']; |
|
980 | + } |
|
981 | + // route |
|
736 | 982 | if (isset($line['aircraftname'])) { |
737 | 983 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
738 | 984 | $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
739 | 985 | $aircraft_data = explode('-',$line['aircraftname']); |
740 | - if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
|
741 | - elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
|
742 | - else { |
|
986 | + if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) { |
|
987 | + $data['aircraft_icao'] = $aircraft_data[0]; |
|
988 | + } elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) { |
|
989 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
990 | + } else { |
|
743 | 991 | $aircraft_data = explode(' ',$line['aircraftname']); |
744 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
|
745 | - else $data['aircraft_icao'] = $line['aircraftname']; |
|
992 | + if (isset($aircraft_data[1])) { |
|
993 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
994 | + } else { |
|
995 | + $data['aircraft_icao'] = $line['aircraftname']; |
|
996 | + } |
|
746 | 997 | } |
747 | 998 | } |
748 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; |
|
999 | + if (isset($line['route'])) { |
|
1000 | + $data['waypoints'] = $line['route']; |
|
1001 | + } |
|
749 | 1002 | $data['id_source'] = $id_source; |
750 | 1003 | $data['format_source'] = 'phpvmacars'; |
751 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1004 | + if (isset($value['name']) && $value['name'] != '') { |
|
1005 | + $data['source_name'] = $value['name']; |
|
1006 | + } |
|
752 | 1007 | $SI->add($data); |
753 | 1008 | unset($data); |
754 | 1009 | } |
755 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
1010 | + if ($globalDebug) { |
|
1011 | + echo 'No more data...'."\n"; |
|
1012 | + } |
|
756 | 1013 | unset($buffer); |
757 | 1014 | unset($all_data); |
758 | 1015 | } |
@@ -760,7 +1017,9 @@ discard block |
||
760 | 1017 | $last_exec[$id]['last'] = time(); |
761 | 1018 | } elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
762 | 1019 | //$buffer = $Common->getData($hosts[$id]); |
763 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1020 | + if ($globalDebug) { |
|
1021 | + echo 'Get Data...'."\n"; |
|
1022 | + } |
|
764 | 1023 | $buffer = $Common->getData($value['host']); |
765 | 1024 | $all_data = json_decode($buffer,true); |
766 | 1025 | if ($buffer != '' && is_array($all_data)) { |
@@ -789,15 +1048,22 @@ discard block |
||
789 | 1048 | $data['arrival_airport_icao'] = $line['arrival']; |
790 | 1049 | //$data['arrival_airport_time'] = $line['arrival_time']; |
791 | 1050 | //$data['registration'] = $line['aircraft']; |
792 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1051 | + if (isset($line['route'])) { |
|
1052 | + $data['waypoints'] = $line['route']; |
|
1053 | + } |
|
1054 | + // route |
|
793 | 1055 | $data['aircraft_icao'] = $line['plane_type']; |
794 | 1056 | $data['id_source'] = $id_source; |
795 | 1057 | $data['format_source'] = 'vam'; |
796 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1058 | + if (isset($value['name']) && $value['name'] != '') { |
|
1059 | + $data['source_name'] = $value['name']; |
|
1060 | + } |
|
797 | 1061 | $SI->add($data); |
798 | 1062 | unset($data); |
799 | 1063 | } |
800 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
1064 | + if ($globalDebug) { |
|
1065 | + echo 'No more data...'."\n"; |
|
1066 | + } |
|
801 | 1067 | unset($buffer); |
802 | 1068 | unset($all_data); |
803 | 1069 | } |
@@ -805,7 +1071,9 @@ discard block |
||
805 | 1071 | $last_exec[$id]['last'] = time(); |
806 | 1072 | //} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') { |
807 | 1073 | } elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3') { |
808 | - if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
1074 | + if (function_exists('pcntl_fork')) { |
|
1075 | + pcntl_signal_dispatch(); |
|
1076 | + } |
|
809 | 1077 | //$last_exec[$id]['last'] = time(); |
810 | 1078 | |
811 | 1079 | //$read = array( $sockets[$id] ); |
@@ -813,7 +1081,9 @@ discard block |
||
813 | 1081 | $write = NULL; |
814 | 1082 | $e = NULL; |
815 | 1083 | $n = socket_select($read, $write, $e, $timeout); |
816 | - if ($e != NULL) var_dump($e); |
|
1084 | + if ($e != NULL) { |
|
1085 | + var_dump($e); |
|
1086 | + } |
|
817 | 1087 | if ($n > 0) { |
818 | 1088 | $reset = 0; |
819 | 1089 | foreach ($read as $nb => $r) { |
@@ -835,7 +1105,9 @@ discard block |
||
835 | 1105 | if ($buffer != '') { |
836 | 1106 | $tt[$format] = 0; |
837 | 1107 | if ($format == 'acarssbs3') { |
838 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1108 | + if ($globalDebug) { |
|
1109 | + echo 'ACARS : '.$buffer."\n"; |
|
1110 | + } |
|
839 | 1111 | $ACARS->add(trim($buffer)); |
840 | 1112 | $ACARS->deleteLiveAcarsData(); |
841 | 1113 | } elseif ($format == 'raw') { |
@@ -844,9 +1116,15 @@ discard block |
||
844 | 1116 | if (is_array($data)) { |
845 | 1117 | $data['datetime'] = date('Y-m-d H:i:s'); |
846 | 1118 | $data['format_source'] = 'raw'; |
847 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
848 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
849 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1119 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1120 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1121 | + } |
|
1122 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1123 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1124 | + } |
|
1125 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1126 | + $SI->add($data); |
|
1127 | + } |
|
850 | 1128 | } |
851 | 1129 | } elseif ($format == 'flightgearsp') { |
852 | 1130 | //echo $buffer."\n"; |
@@ -864,11 +1142,15 @@ discard block |
||
864 | 1142 | $data['speed'] = round($line[5]*1.94384); |
865 | 1143 | $data['datetime'] = date('Y-m-d H:i:s'); |
866 | 1144 | $data['format_source'] = 'flightgearsp'; |
867 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1145 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1146 | + $SI->add($data); |
|
1147 | + } |
|
868 | 1148 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
869 | 1149 | } |
870 | 1150 | } elseif ($format == 'acars') { |
871 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1151 | + if ($globalDebug) { |
|
1152 | + echo 'ACARS : '.$buffer."\n"; |
|
1153 | + } |
|
872 | 1154 | $ACARS->add(trim($buffer)); |
873 | 1155 | socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
874 | 1156 | $ACARS->deleteLiveAcarsData(); |
@@ -889,7 +1171,9 @@ discard block |
||
889 | 1171 | $aircraft_type = $line[10]; |
890 | 1172 | $aircraft_type = preg_split(':/:',$aircraft_type); |
891 | 1173 | $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
892 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1174 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1175 | + $SI->add($data); |
|
1176 | + } |
|
893 | 1177 | } |
894 | 1178 | } |
895 | 1179 | } elseif ($format == 'beast') { |
@@ -905,21 +1189,43 @@ discard block |
||
905 | 1189 | $data['hex'] = $lined['hexid']; |
906 | 1190 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
907 | 1191 | $data['datetime'] = date('Y-m-d H:i:s');; |
908 | - if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
|
909 | - if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
|
910 | - if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
|
911 | - if (isset($lined['speed'])) $data['speed'] = $lined['speed']; |
|
912 | - if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk']; |
|
913 | - if (isset($lined['alt'])) $data['altitude'] = $lined['alt']; |
|
914 | - if (isset($lined['heading'])) $data['heading'] = $lined['heading']; |
|
1192 | + if (isset($lined['ident'])) { |
|
1193 | + $data['ident'] = $lined['ident']; |
|
1194 | + } |
|
1195 | + if (isset($lined['lat'])) { |
|
1196 | + $data['latitude'] = $lined['lat']; |
|
1197 | + } |
|
1198 | + if (isset($lined['lon'])) { |
|
1199 | + $data['longitude'] = $lined['lon']; |
|
1200 | + } |
|
1201 | + if (isset($lined['speed'])) { |
|
1202 | + $data['speed'] = $lined['speed']; |
|
1203 | + } |
|
1204 | + if (isset($lined['squawk'])) { |
|
1205 | + $data['squawk'] = $lined['squawk']; |
|
1206 | + } |
|
1207 | + if (isset($lined['alt'])) { |
|
1208 | + $data['altitude'] = $lined['alt']; |
|
1209 | + } |
|
1210 | + if (isset($lined['heading'])) { |
|
1211 | + $data['heading'] = $lined['heading']; |
|
1212 | + } |
|
915 | 1213 | $data['id_source'] = $id_source; |
916 | 1214 | $data['format_source'] = 'tsv'; |
917 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
918 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
919 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1215 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1216 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1217 | + } |
|
1218 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1219 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1220 | + } |
|
1221 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1222 | + $SI->add($data); |
|
1223 | + } |
|
920 | 1224 | unset($lined); |
921 | 1225 | unset($data); |
922 | - } else $error = true; |
|
1226 | + } else { |
|
1227 | + $error = true; |
|
1228 | + } |
|
923 | 1229 | } elseif ($format == 'aprs' && $use_aprs) { |
924 | 1230 | if ($aprs_connect == 0) { |
925 | 1231 | $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
@@ -950,29 +1256,40 @@ discard block |
||
950 | 1256 | $data['latitude'] = $line['latitude']; |
951 | 1257 | $data['longitude'] = $line['longitude']; |
952 | 1258 | //$data['verticalrate'] = $line[16]; |
953 | - if (isset($line['speed'])) $data['speed'] = $line['speed']; |
|
954 | - else $data['speed'] = 0; |
|
1259 | + if (isset($line['speed'])) { |
|
1260 | + $data['speed'] = $line['speed']; |
|
1261 | + } else { |
|
1262 | + $data['speed'] = 0; |
|
1263 | + } |
|
955 | 1264 | $data['altitude'] = $line['altitude']; |
956 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; |
|
1265 | + if (isset($line['heading'])) { |
|
1266 | + $data['heading'] = $line['heading']; |
|
1267 | + } |
|
957 | 1268 | //else $data['heading'] = 0; |
958 | 1269 | $data['aircraft_type'] = $line['stealth']; |
959 | - if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true; |
|
1270 | + if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) { |
|
1271 | + $data['noarchive'] = true; |
|
1272 | + } |
|
960 | 1273 | $data['id_source'] = $id_source; |
961 | 1274 | $data['format_source'] = 'aprs'; |
962 | 1275 | $data['source_name'] = $line['source']; |
963 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1276 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1277 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1278 | + } |
|
964 | 1279 | $currentdate = date('Y-m-d H:i:s'); |
965 | 1280 | $aprsdate = strtotime($data['datetime']); |
966 | 1281 | // Accept data if time <= system time + 20s |
967 | 1282 | if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
968 | 1283 | $send = $SI->add($data); |
969 | 1284 | } else { |
970 | - if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
971 | - else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
1285 | + if ($line['stealth'] != 0) { |
|
1286 | + echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
1287 | + } else { |
|
1288 | + echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
1289 | + } |
|
972 | 1290 | } |
973 | 1291 | unset($data); |
974 | - } |
|
975 | - elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
|
1292 | + } elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
|
976 | 1293 | echo '!! Weather Station not yet supported'."\n"; |
977 | 1294 | } |
978 | 1295 | //elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n"; |
@@ -1005,25 +1322,42 @@ discard block |
||
1005 | 1322 | $data['ground'] = $line[21]; |
1006 | 1323 | $data['emergency'] = $line[19]; |
1007 | 1324 | $data['format_source'] = 'sbs'; |
1008 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1009 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1325 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1326 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1327 | + } |
|
1328 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1329 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1330 | + } |
|
1010 | 1331 | $data['id_source'] = $id_source; |
1011 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data); |
|
1012 | - else $error = true; |
|
1332 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1333 | + $send = $SI->add($data); |
|
1334 | + } else { |
|
1335 | + $error = true; |
|
1336 | + } |
|
1013 | 1337 | unset($data); |
1014 | - } else $error = true; |
|
1338 | + } else { |
|
1339 | + $error = true; |
|
1340 | + } |
|
1015 | 1341 | if ($error) { |
1016 | 1342 | if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { |
1017 | - if ($globalDebug) echo "Not a message. Ignoring... \n"; |
|
1343 | + if ($globalDebug) { |
|
1344 | + echo "Not a message. Ignoring... \n"; |
|
1345 | + } |
|
1018 | 1346 | } else { |
1019 | - if ($globalDebug) echo "Wrong line format. Ignoring... \n"; |
|
1347 | + if ($globalDebug) { |
|
1348 | + echo "Wrong line format. Ignoring... \n"; |
|
1349 | + } |
|
1020 | 1350 | if ($globalDebug) { |
1021 | 1351 | echo $buffer; |
1022 | 1352 | print_r($line); |
1023 | 1353 | } |
1024 | 1354 | //socket_close($r); |
1025 | - if ($globalDebug) echo "Reconnect after an error...\n"; |
|
1026 | - if ($format == 'aprs') $aprs_connect = 0; |
|
1355 | + if ($globalDebug) { |
|
1356 | + echo "Reconnect after an error...\n"; |
|
1357 | + } |
|
1358 | + if ($format == 'aprs') { |
|
1359 | + $aprs_connect = 0; |
|
1360 | + } |
|
1027 | 1361 | $sourceer[$nb] = $globalSources[$nb]; |
1028 | 1362 | connect_all($sourceer); |
1029 | 1363 | $sourceer = array(); |
@@ -1031,10 +1365,14 @@ discard block |
||
1031 | 1365 | } |
1032 | 1366 | } |
1033 | 1367 | // Sleep for xxx microseconds |
1034 | - if (isset($globalSBSSleep)) usleep($globalSBSSleep); |
|
1368 | + if (isset($globalSBSSleep)) { |
|
1369 | + usleep($globalSBSSleep); |
|
1370 | + } |
|
1035 | 1371 | } else { |
1036 | 1372 | if ($format == 'flightgearmp') { |
1037 | - if ($globalDebug) echo "Reconnect FlightGear MP..."; |
|
1373 | + if ($globalDebug) { |
|
1374 | + echo "Reconnect FlightGear MP..."; |
|
1375 | + } |
|
1038 | 1376 | //@socket_close($r); |
1039 | 1377 | sleep($globalMinFetch); |
1040 | 1378 | $sourcefg[$nb] = $globalSources[$nb]; |
@@ -1043,10 +1381,15 @@ discard block |
||
1043 | 1381 | break; |
1044 | 1382 | |
1045 | 1383 | } elseif ($format != 'acars' && $format != 'flightgearsp') { |
1046 | - if (isset($tt[$format])) $tt[$format]++; |
|
1047 | - else $tt[$format] = 0; |
|
1384 | + if (isset($tt[$format])) { |
|
1385 | + $tt[$format]++; |
|
1386 | + } else { |
|
1387 | + $tt[$format] = 0; |
|
1388 | + } |
|
1048 | 1389 | if ($tt[$format] > 30) { |
1049 | - if ($globalDebug) echo "ERROR : Reconnect ".$format."..."; |
|
1390 | + if ($globalDebug) { |
|
1391 | + echo "ERROR : Reconnect ".$format."..."; |
|
1392 | + } |
|
1050 | 1393 | //@socket_close($r); |
1051 | 1394 | sleep(2); |
1052 | 1395 | $aprs_connect = 0; |
@@ -1062,12 +1405,18 @@ discard block |
||
1062 | 1405 | } |
1063 | 1406 | } else { |
1064 | 1407 | $error = socket_strerror(socket_last_error()); |
1065 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1408 | + if ($globalDebug) { |
|
1409 | + echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1410 | + } |
|
1066 | 1411 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) { |
1067 | - if (isset($globalDebug)) echo "Restarting...\n"; |
|
1412 | + if (isset($globalDebug)) { |
|
1413 | + echo "Restarting...\n"; |
|
1414 | + } |
|
1068 | 1415 | // Restart the script if possible |
1069 | 1416 | if (is_array($sockets)) { |
1070 | - if ($globalDebug) echo "Shutdown all sockets..."; |
|
1417 | + if ($globalDebug) { |
|
1418 | + echo "Shutdown all sockets..."; |
|
1419 | + } |
|
1071 | 1420 | |
1072 | 1421 | foreach ($sockets as $sock) { |
1073 | 1422 | @socket_shutdown($sock,2); |
@@ -1075,18 +1424,24 @@ discard block |
||
1075 | 1424 | } |
1076 | 1425 | |
1077 | 1426 | } |
1078 | - if ($globalDebug) echo "Restart all connections..."; |
|
1427 | + if ($globalDebug) { |
|
1428 | + echo "Restart all connections..."; |
|
1429 | + } |
|
1079 | 1430 | sleep(2); |
1080 | 1431 | $time = time(); |
1081 | 1432 | //connect_all($hosts); |
1082 | 1433 | $aprs_connect = 0; |
1083 | - if ($reset > 40) exit('Too many attempts...'); |
|
1434 | + if ($reset > 40) { |
|
1435 | + exit('Too many attempts...'); |
|
1436 | + } |
|
1084 | 1437 | connect_all($globalSources); |
1085 | 1438 | } |
1086 | 1439 | } |
1087 | 1440 | } |
1088 | 1441 | if ($globalDaemon === false) { |
1089 | - if ($globalDebug) echo 'Check all...'."\n"; |
|
1442 | + if ($globalDebug) { |
|
1443 | + echo 'Check all...'."\n"; |
|
1444 | + } |
|
1090 | 1445 | $SI->checkAll(); |
1091 | 1446 | } |
1092 | 1447 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class aprs { |
3 | - protected $symbols = array('!' => 'Police', |
|
3 | + protected $symbols = array('!' => 'Police', |
|
4 | 4 | '#' => 'DIGI', |
5 | 5 | '$' => 'Phone', |
6 | 6 | '%' => 'DX Cluster', |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | 'y' => 'Yagi At QTH'); |
85 | 85 | |
86 | 86 | |
87 | - private function urshift($n, $s) { |
|
87 | + private function urshift($n, $s) { |
|
88 | 88 | return ($n >= 0) ? ($n >> $s) : |
89 | - (($n & 0x7fffffff) >> $s) | |
|
90 | - (0x40000000 >> ($s - 1)); |
|
91 | - } |
|
89 | + (($n & 0x7fffffff) >> $s) | |
|
90 | + (0x40000000 >> ($s - 1)); |
|
91 | + } |
|
92 | 92 | |
93 | - public function parse($input) { |
|
93 | + public function parse($input) { |
|
94 | 94 | global $globalDebug; |
95 | 95 | $debug = false; |
96 | 96 | $result = array(); |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | |
103 | 103 | /* Check that end was found and body has at least one byte. */ |
104 | 104 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
105 | - if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
106 | - return false; |
|
105 | + if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
106 | + return false; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /* Save header and body. */ |
@@ -116,23 +116,23 @@ discard block |
||
116 | 116 | /* Parse source, target and path. */ |
117 | 117 | //FLRDF0A52>APRS,qAS,LSTB |
118 | 118 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
119 | - $ident = $matches[1]; |
|
120 | - $all_elements = $matches[2]; |
|
121 | - if ($debug) echo 'ident : '.$ident."\n"; |
|
122 | - $result['ident'] = $ident; |
|
119 | + $ident = $matches[1]; |
|
120 | + $all_elements = $matches[2]; |
|
121 | + if ($debug) echo 'ident : '.$ident."\n"; |
|
122 | + $result['ident'] = $ident; |
|
123 | 123 | } else return false; |
124 | 124 | $elements = explode(',',$all_elements); |
125 | 125 | $source = end($elements); |
126 | 126 | $result['source'] = $source; |
127 | 127 | foreach ($elements as $element) { |
128 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
129 | - //echo "ok"; |
|
130 | - //if ($element == 'TCPIP*') return false; |
|
131 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
128 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
129 | + //echo "ok"; |
|
130 | + //if ($element == 'TCPIP*') return false; |
|
131 | + } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
132 | 132 | echo 'element : '.$element."\n"; |
133 | 133 | return false; |
134 | - } |
|
135 | - /* |
|
134 | + } |
|
135 | + /* |
|
136 | 136 | } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) { |
137 | 137 | //echo "ok"; |
138 | 138 | } else { |
@@ -145,49 +145,49 @@ discard block |
||
145 | 145 | $body_parse = substr($body,1); |
146 | 146 | //echo 'Body : '.$body."\n"; |
147 | 147 | if (preg_match('/^;(.){9}\*/',$body,$matches)) { |
148 | - $body_parse = substr($body_parse,10); |
|
149 | - $find = true; |
|
150 | - //echo $body_parse."\n"; |
|
148 | + $body_parse = substr($body_parse,10); |
|
149 | + $find = true; |
|
150 | + //echo $body_parse."\n"; |
|
151 | 151 | } |
152 | 152 | if (preg_match('/^`(.*)\//',$body,$matches)) { |
153 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
154 | - $find = true; |
|
155 | - //echo $body_parse."\n"; |
|
153 | + $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
154 | + $find = true; |
|
155 | + //echo $body_parse."\n"; |
|
156 | 156 | } |
157 | 157 | if (preg_match("/^'(.*)\//",$body,$matches)) { |
158 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
159 | - $find = true; |
|
160 | - //echo $body_parse."\n"; |
|
158 | + $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
159 | + $find = true; |
|
160 | + //echo $body_parse."\n"; |
|
161 | 161 | } |
162 | 162 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
163 | - $find = true; |
|
164 | - //print_r($matches); |
|
165 | - $timestamp = $matches[0]; |
|
166 | - if ($matches[4] == 'h') { |
|
163 | + $find = true; |
|
164 | + //print_r($matches); |
|
165 | + $timestamp = $matches[0]; |
|
166 | + if ($matches[4] == 'h') { |
|
167 | 167 | $timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]); |
168 | 168 | //echo 'timestamp : '.$timestamp.' - now : '.time()."\n"; |
169 | 169 | /* |
170 | 170 | if (time() + 3900 < $timestamp) $timestamp -= 86400; |
171 | 171 | elseif (time() - 82500 > $timestamp) $timestamp += 86400; |
172 | 172 | */ |
173 | - } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
173 | + } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
174 | 174 | // This work or not ? |
175 | 175 | $timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]); |
176 | - } |
|
177 | - $body_parse = substr($body_parse,7); |
|
178 | - $result['timestamp'] = $timestamp; |
|
179 | - //echo date('Ymd H:i:s',$timestamp); |
|
176 | + } |
|
177 | + $body_parse = substr($body_parse,7); |
|
178 | + $result['timestamp'] = $timestamp; |
|
179 | + //echo date('Ymd H:i:s',$timestamp); |
|
180 | 180 | } |
181 | 181 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) { |
182 | - $find = true; |
|
183 | - $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
|
184 | - $body_parse = substr($body_parse,8); |
|
185 | - $result['timestamp'] = $timestamp; |
|
186 | - //echo date('Ymd H:i:s',$timestamp); |
|
182 | + $find = true; |
|
183 | + $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
|
184 | + $body_parse = substr($body_parse,8); |
|
185 | + $result['timestamp'] = $timestamp; |
|
186 | + //echo date('Ymd H:i:s',$timestamp); |
|
187 | 187 | } |
188 | 188 | //if (strlen($body_parse) > 19) { |
189 | - 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)) { |
|
190 | - $find = true; |
|
189 | + 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)) { |
|
190 | + $find = true; |
|
191 | 191 | // 4658.70N/00707.78Ez |
192 | 192 | //print_r(str_split($body_parse)); |
193 | 193 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $lon = intval($lon_deg); |
205 | 205 | if ($lat > 89 || $lon > 179) return false; |
206 | 206 | |
207 | - /* |
|
207 | + /* |
|
208 | 208 | $tmp_5b = str_replace('.','',$lat_min); |
209 | 209 | if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) { |
210 | 210 | print_r($matches); |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | $result['longitude'] = $longitude; |
219 | 219 | $body_parse = substr($body_parse,18); |
220 | 220 | $body_parse_len = strlen($body_parse); |
221 | - } |
|
222 | - $body_parse_len = strlen($body_parse); |
|
223 | - if ($body_parse_len > 0) { |
|
221 | + } |
|
222 | + $body_parse_len = strlen($body_parse); |
|
223 | + if ($body_parse_len > 0) { |
|
224 | 224 | /* |
225 | 225 | if (!isset($result['timestamp']) && !isset($result['latitude'])) { |
226 | 226 | $body_split = str_split($body); |
@@ -247,61 +247,61 @@ discard block |
||
247 | 247 | $result['symbol_code'] = $symbol_code; |
248 | 248 | if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
249 | 249 | if ($symbol_code != '_') { |
250 | - //$body_parse = substr($body_parse,1); |
|
251 | - //$body_parse = trim($body_parse); |
|
252 | - //$body_parse_len = strlen($body_parse); |
|
253 | - if ($body_parse_len >= 7) { |
|
250 | + //$body_parse = substr($body_parse,1); |
|
251 | + //$body_parse = trim($body_parse); |
|
252 | + //$body_parse_len = strlen($body_parse); |
|
253 | + if ($body_parse_len >= 7) { |
|
254 | 254 | |
255 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
256 | - $course = substr($body_parse,0,3); |
|
257 | - $tmp_s = intval($course); |
|
258 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
259 | - $speed = substr($body_parse,4,3); |
|
260 | - $result['speed'] = round($speed*1.852); |
|
261 | - $body_parse = substr($body_parse,7); |
|
262 | - } |
|
263 | - // Check PHGR, PHG, RNG |
|
264 | - } |
|
265 | - /* |
|
255 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
256 | + $course = substr($body_parse,0,3); |
|
257 | + $tmp_s = intval($course); |
|
258 | + if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
259 | + $speed = substr($body_parse,4,3); |
|
260 | + $result['speed'] = round($speed*1.852); |
|
261 | + $body_parse = substr($body_parse,7); |
|
262 | + } |
|
263 | + // Check PHGR, PHG, RNG |
|
264 | + } |
|
265 | + /* |
|
266 | 266 | else if ($body_parse_len > 0) { |
267 | 267 | $rest = $body_parse; |
268 | 268 | } |
269 | 269 | */ |
270 | - if (strlen($body_parse) > 0) { |
|
271 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
272 | - $altitude = intval($matches[1]); |
|
273 | - //$result['altitude'] = round($altitude*0.3048); |
|
274 | - $result['altitude'] = $altitude; |
|
275 | - $body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
276 | - } |
|
277 | - } |
|
270 | + if (strlen($body_parse) > 0) { |
|
271 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
272 | + $altitude = intval($matches[1]); |
|
273 | + //$result['altitude'] = round($altitude*0.3048); |
|
274 | + $result['altitude'] = $altitude; |
|
275 | + $body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
276 | + } |
|
277 | + } |
|
278 | 278 | |
279 | - // Telemetry |
|
280 | - /* |
|
279 | + // Telemetry |
|
280 | + /* |
|
281 | 281 | 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)) { |
282 | 282 | // Nothing yet... |
283 | 283 | } |
284 | 284 | */ |
285 | - // DAO |
|
286 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
287 | - $dao = $matches[1]; |
|
288 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
285 | + // DAO |
|
286 | + if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
287 | + $dao = $matches[1]; |
|
288 | + if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
289 | 289 | $dao_split = str_split($dao); |
290 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
291 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
290 | + $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
291 | + $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
292 | 292 | |
293 | 293 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
294 | 294 | else $result['latitude'] += $lat_off; |
295 | 295 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
296 | 296 | else $result['longitude'] += $lon_off; |
297 | - } |
|
298 | - $body_parse = substr($body_parse,6); |
|
299 | - } |
|
297 | + } |
|
298 | + $body_parse = substr($body_parse,6); |
|
299 | + } |
|
300 | 300 | |
301 | - // OGN comment |
|
301 | + // OGN comment |
|
302 | 302 | // echo "Before OGN : ".$body_parse."\n"; |
303 | - //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
304 | - if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
303 | + //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
304 | + if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
305 | 305 | $id = $matches[1]; |
306 | 306 | //$mode = substr($id,0,2); |
307 | 307 | $address = substr($id,2); |
@@ -331,51 +331,51 @@ discard block |
||
331 | 331 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
332 | 332 | $result['stealth'] = $stealth; |
333 | 333 | $result['address'] = $address; |
334 | - } |
|
334 | + } |
|
335 | 335 | |
336 | - //Comment |
|
337 | - $result['comment'] = trim($body_parse); |
|
336 | + //Comment |
|
337 | + $result['comment'] = trim($body_parse); |
|
338 | 338 | } else { |
339 | - // parse weather |
|
340 | - //$body_parse = substr($body_parse,1); |
|
341 | - //$body_parse_len = strlen($body_parse); |
|
339 | + // parse weather |
|
340 | + //$body_parse = substr($body_parse,1); |
|
341 | + //$body_parse_len = strlen($body_parse); |
|
342 | 342 | |
343 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
344 | - $result['wind_dir'] = intval($matches[1]); |
|
345 | - $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
346 | - $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
347 | - $result['temp'] = round(5/9*(($matches[4])-32),1); |
|
348 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
349 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
343 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
344 | + $result['wind_dir'] = intval($matches[1]); |
|
345 | + $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
346 | + $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
347 | + $result['temp'] = round(5/9*(($matches[4])-32),1); |
|
348 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
349 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
350 | 350 | $result['wind_dir'] = intval($matches[1]); |
351 | 351 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
352 | 352 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
353 | 353 | $result['temp'] = round(5/9*(($matches[4])-32),1); |
354 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
355 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
354 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
355 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
356 | 356 | $result['wind_dir'] = intval($matches[1]); |
357 | 357 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
358 | 358 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
359 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
360 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
359 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
360 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
361 | 361 | $result['wind_dir'] = intval($matches[1]); |
362 | 362 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
363 | 363 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
364 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
365 | - } |
|
366 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
364 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
365 | + } |
|
366 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
367 | 367 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
368 | - } |
|
368 | + } |
|
369 | 369 | } |
370 | 370 | } else $result['comment'] = trim($body_parse); |
371 | 371 | |
372 | - } |
|
372 | + } |
|
373 | 373 | //} |
374 | 374 | if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
375 | 375 | if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
376 | 376 | //print_r($result); |
377 | 377 | return $result; |
378 | - } |
|
378 | + } |
|
379 | 379 | } |
380 | 380 | /* |
381 | 381 | $aprs = new aprs(); |
@@ -85,8 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | |
87 | 87 | private function urshift($n, $s) { |
88 | - return ($n >= 0) ? ($n >> $s) : |
|
89 | - (($n & 0x7fffffff) >> $s) | |
|
88 | + return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| |
|
90 | 89 | (0x40000000 >> ($s - 1)); |
91 | 90 | } |
92 | 91 | |
@@ -98,7 +97,7 @@ discard block |
||
98 | 97 | //$split_input = str_split($input); |
99 | 98 | |
100 | 99 | /* Find the end of header checking for NULL bytes while doing it. */ |
101 | - $splitpos = strpos($input,':'); |
|
100 | + $splitpos = strpos($input, ':'); |
|
102 | 101 | |
103 | 102 | /* Check that end was found and body has at least one byte. */ |
104 | 103 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
@@ -107,28 +106,28 @@ discard block |
||
107 | 106 | } |
108 | 107 | |
109 | 108 | /* Save header and body. */ |
110 | - $body = substr($input,$splitpos+1,$input_len); |
|
109 | + $body = substr($input, $splitpos + 1, $input_len); |
|
111 | 110 | $body_len = strlen($body); |
112 | - $header = substr($input,0,$splitpos); |
|
111 | + $header = substr($input, 0, $splitpos); |
|
113 | 112 | //$header_len = strlen($header); |
114 | 113 | if ($debug) echo 'header : '.$header."\n"; |
115 | 114 | |
116 | 115 | /* Parse source, target and path. */ |
117 | 116 | //FLRDF0A52>APRS,qAS,LSTB |
118 | - if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
|
117 | + if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) { |
|
119 | 118 | $ident = $matches[1]; |
120 | 119 | $all_elements = $matches[2]; |
121 | 120 | if ($debug) echo 'ident : '.$ident."\n"; |
122 | 121 | $result['ident'] = $ident; |
123 | 122 | } else return false; |
124 | - $elements = explode(',',$all_elements); |
|
123 | + $elements = explode(',', $all_elements); |
|
125 | 124 | $source = end($elements); |
126 | 125 | $result['source'] = $source; |
127 | 126 | foreach ($elements as $element) { |
128 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
127 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) { |
|
129 | 128 | //echo "ok"; |
130 | 129 | //if ($element == 'TCPIP*') return false; |
131 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
130 | + } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) { |
|
132 | 131 | echo 'element : '.$element."\n"; |
133 | 132 | return false; |
134 | 133 | } |
@@ -142,24 +141,24 @@ discard block |
||
142 | 141 | } |
143 | 142 | // Check for Timestamp |
144 | 143 | $find = false; |
145 | - $body_parse = substr($body,1); |
|
144 | + $body_parse = substr($body, 1); |
|
146 | 145 | //echo 'Body : '.$body."\n"; |
147 | - if (preg_match('/^;(.){9}\*/',$body,$matches)) { |
|
148 | - $body_parse = substr($body_parse,10); |
|
146 | + if (preg_match('/^;(.){9}\*/', $body, $matches)) { |
|
147 | + $body_parse = substr($body_parse, 10); |
|
149 | 148 | $find = true; |
150 | 149 | //echo $body_parse."\n"; |
151 | 150 | } |
152 | - if (preg_match('/^`(.*)\//',$body,$matches)) { |
|
153 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
151 | + if (preg_match('/^`(.*)\//', $body, $matches)) { |
|
152 | + $body_parse = substr($body_parse, strlen($matches[1]) - 1); |
|
154 | 153 | $find = true; |
155 | 154 | //echo $body_parse."\n"; |
156 | 155 | } |
157 | - if (preg_match("/^'(.*)\//",$body,$matches)) { |
|
158 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
156 | + if (preg_match("/^'(.*)\//", $body, $matches)) { |
|
157 | + $body_parse = substr($body_parse, strlen($matches[1]) - 1); |
|
159 | 158 | $find = true; |
160 | 159 | //echo $body_parse."\n"; |
161 | 160 | } |
162 | - if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
|
161 | + if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) { |
|
163 | 162 | $find = true; |
164 | 163 | //print_r($matches); |
165 | 164 | $timestamp = $matches[0]; |
@@ -174,19 +173,19 @@ discard block |
||
174 | 173 | // This work or not ? |
175 | 174 | $timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]); |
176 | 175 | } |
177 | - $body_parse = substr($body_parse,7); |
|
176 | + $body_parse = substr($body_parse, 7); |
|
178 | 177 | $result['timestamp'] = $timestamp; |
179 | 178 | //echo date('Ymd H:i:s',$timestamp); |
180 | 179 | } |
181 | - if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) { |
|
180 | + if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $body_parse, $matches)) { |
|
182 | 181 | $find = true; |
183 | 182 | $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
184 | - $body_parse = substr($body_parse,8); |
|
183 | + $body_parse = substr($body_parse, 8); |
|
185 | 184 | $result['timestamp'] = $timestamp; |
186 | 185 | //echo date('Ymd H:i:s',$timestamp); |
187 | 186 | } |
188 | 187 | //if (strlen($body_parse) > 19) { |
189 | - 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)) { |
|
188 | + 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)) { |
|
190 | 189 | $find = true; |
191 | 190 | // 4658.70N/00707.78Ez |
192 | 191 | //print_r(str_split($body_parse)); |
@@ -212,11 +211,11 @@ discard block |
||
212 | 211 | */ |
213 | 212 | $latitude = $lat + floatval($lat_min)/60; |
214 | 213 | $longitude = $lon + floatval($lon_min)/60; |
215 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
216 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
214 | + if ($sind == 'S') $latitude = 0 - $latitude; |
|
215 | + if ($wind == 'W') $longitude = 0 - $longitude; |
|
217 | 216 | $result['latitude'] = $latitude; |
218 | 217 | $result['longitude'] = $longitude; |
219 | - $body_parse = substr($body_parse,18); |
|
218 | + $body_parse = substr($body_parse, 18); |
|
220 | 219 | $body_parse_len = strlen($body_parse); |
221 | 220 | } |
222 | 221 | $body_parse_len = strlen($body_parse); |
@@ -240,7 +239,7 @@ discard block |
||
240 | 239 | if ($find) { |
241 | 240 | $body_split = str_split($body_parse); |
242 | 241 | $symbol_code = $body_split[0]; |
243 | - $body_parse = substr($body_parse,1); |
|
242 | + $body_parse = substr($body_parse, 1); |
|
244 | 243 | $body_parse_len = strlen($body_parse); |
245 | 244 | //} |
246 | 245 | //echo $body_parse; |
@@ -252,13 +251,13 @@ discard block |
||
252 | 251 | //$body_parse_len = strlen($body_parse); |
253 | 252 | if ($body_parse_len >= 7) { |
254 | 253 | |
255 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
256 | - $course = substr($body_parse,0,3); |
|
254 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) { |
|
255 | + $course = substr($body_parse, 0, 3); |
|
257 | 256 | $tmp_s = intval($course); |
258 | 257 | if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
259 | - $speed = substr($body_parse,4,3); |
|
258 | + $speed = substr($body_parse, 4, 3); |
|
260 | 259 | $result['speed'] = round($speed*1.852); |
261 | - $body_parse = substr($body_parse,7); |
|
260 | + $body_parse = substr($body_parse, 7); |
|
262 | 261 | } |
263 | 262 | // Check PHGR, PHG, RNG |
264 | 263 | } |
@@ -268,11 +267,11 @@ discard block |
||
268 | 267 | } |
269 | 268 | */ |
270 | 269 | if (strlen($body_parse) > 0) { |
271 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
270 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) { |
|
272 | 271 | $altitude = intval($matches[1]); |
273 | 272 | //$result['altitude'] = round($altitude*0.3048); |
274 | 273 | $result['altitude'] = $altitude; |
275 | - $body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
274 | + $body_parse = trim(substr($body_parse, strlen($matches[0]))); |
|
276 | 275 | } |
277 | 276 | } |
278 | 277 | |
@@ -283,35 +282,35 @@ discard block |
||
283 | 282 | } |
284 | 283 | */ |
285 | 284 | // DAO |
286 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
285 | + if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) { |
|
287 | 286 | $dao = $matches[1]; |
288 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
287 | + if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) { |
|
289 | 288 | $dao_split = str_split($dao); |
290 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
291 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
289 | + $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0; |
|
290 | + $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0; |
|
292 | 291 | |
293 | 292 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
294 | 293 | else $result['latitude'] += $lat_off; |
295 | 294 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
296 | 295 | else $result['longitude'] += $lon_off; |
297 | 296 | } |
298 | - $body_parse = substr($body_parse,6); |
|
297 | + $body_parse = substr($body_parse, 6); |
|
299 | 298 | } |
300 | 299 | |
301 | 300 | // OGN comment |
302 | 301 | // echo "Before OGN : ".$body_parse."\n"; |
303 | 302 | //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
304 | - if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
303 | + if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) { |
|
305 | 304 | $id = $matches[1]; |
306 | 305 | //$mode = substr($id,0,2); |
307 | - $address = substr($id,2); |
|
306 | + $address = substr($id, 2); |
|
308 | 307 | //print_r($matches); |
309 | - $addressType = (intval(substr($id,0,2),16))&3; |
|
308 | + $addressType = (intval(substr($id, 0, 2), 16))&3; |
|
310 | 309 | if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
311 | 310 | elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
312 | 311 | elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
313 | 312 | elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
314 | - $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
|
313 | + $aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2); |
|
315 | 314 | $result['aircrafttype_code'] = $aircraftType; |
316 | 315 | if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
317 | 316 | elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
@@ -328,7 +327,7 @@ discard block |
||
328 | 327 | elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
329 | 328 | elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
330 | 329 | elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
331 | - $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
|
330 | + $stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0; |
|
332 | 331 | $result['stealth'] = $stealth; |
333 | 332 | $result['address'] = $address; |
334 | 333 | } |
@@ -340,39 +339,39 @@ discard block |
||
340 | 339 | //$body_parse = substr($body_parse,1); |
341 | 340 | //$body_parse_len = strlen($body_parse); |
342 | 341 | |
343 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
342 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
344 | 343 | $result['wind_dir'] = intval($matches[1]); |
345 | - $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
346 | - $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
347 | - $result['temp'] = round(5/9*(($matches[4])-32),1); |
|
348 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
349 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
344 | + $result['wind_speed'] = round(intval($matches[2])*1.60934, 1); |
|
345 | + $result['wind_gust'] = round(intval($matches[3])*1.60934, 1); |
|
346 | + $result['temp'] = round(5/9*(($matches[4]) - 32), 1); |
|
347 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
348 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
350 | 349 | $result['wind_dir'] = intval($matches[1]); |
351 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
352 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
353 | - $result['temp'] = round(5/9*(($matches[4])-32),1); |
|
354 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
355 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
350 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
351 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
352 | + $result['temp'] = round(5/9*(($matches[4]) - 32), 1); |
|
353 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
354 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
356 | 355 | $result['wind_dir'] = intval($matches[1]); |
357 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
358 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
359 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
360 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
356 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
357 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
358 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
359 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) { |
|
361 | 360 | $result['wind_dir'] = intval($matches[1]); |
362 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
363 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
364 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
361 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
362 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
363 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
365 | 364 | } |
366 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
367 | - $result['temp'] = round(5/9*(($matches[1])-32),1); |
|
365 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) { |
|
366 | + $result['temp'] = round(5/9*(($matches[1]) - 32), 1); |
|
368 | 367 | } |
369 | 368 | } |
370 | 369 | } else $result['comment'] = trim($body_parse); |
371 | 370 | |
372 | 371 | } |
373 | 372 | //} |
374 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
375 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
373 | + if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4); |
|
374 | + if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4); |
|
376 | 375 | //print_r($result); |
377 | 376 | return $result; |
378 | 377 | } |
@@ -102,7 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | /* Check that end was found and body has at least one byte. */ |
104 | 104 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
105 | - if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
105 | + if ($globalDebug) { |
|
106 | + echo '!!! APRS invalid : '.$input."\n"; |
|
107 | + } |
|
106 | 108 | return false; |
107 | 109 | } |
108 | 110 | |
@@ -111,16 +113,22 @@ discard block |
||
111 | 113 | $body_len = strlen($body); |
112 | 114 | $header = substr($input,0,$splitpos); |
113 | 115 | //$header_len = strlen($header); |
114 | - if ($debug) echo 'header : '.$header."\n"; |
|
116 | + if ($debug) { |
|
117 | + echo 'header : '.$header."\n"; |
|
118 | + } |
|
115 | 119 | |
116 | 120 | /* Parse source, target and path. */ |
117 | 121 | //FLRDF0A52>APRS,qAS,LSTB |
118 | 122 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
119 | 123 | $ident = $matches[1]; |
120 | 124 | $all_elements = $matches[2]; |
121 | - if ($debug) echo 'ident : '.$ident."\n"; |
|
125 | + if ($debug) { |
|
126 | + echo 'ident : '.$ident."\n"; |
|
127 | + } |
|
122 | 128 | $result['ident'] = $ident; |
123 | - } else return false; |
|
129 | + } else { |
|
130 | + return false; |
|
131 | + } |
|
124 | 132 | $elements = explode(',',$all_elements); |
125 | 133 | $source = end($elements); |
126 | 134 | $result['source'] = $source; |
@@ -202,7 +210,9 @@ discard block |
||
202 | 210 | //$symbol_table = $matches[4]; |
203 | 211 | $lat = intval($lat_deg); |
204 | 212 | $lon = intval($lon_deg); |
205 | - if ($lat > 89 || $lon > 179) return false; |
|
213 | + if ($lat > 89 || $lon > 179) { |
|
214 | + return false; |
|
215 | + } |
|
206 | 216 | |
207 | 217 | /* |
208 | 218 | $tmp_5b = str_replace('.','',$lat_min); |
@@ -212,8 +222,12 @@ discard block |
||
212 | 222 | */ |
213 | 223 | $latitude = $lat + floatval($lat_min)/60; |
214 | 224 | $longitude = $lon + floatval($lon_min)/60; |
215 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
216 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
225 | + if ($sind == 'S') { |
|
226 | + $latitude = 0-$latitude; |
|
227 | + } |
|
228 | + if ($wind == 'W') { |
|
229 | + $longitude = 0-$longitude; |
|
230 | + } |
|
217 | 231 | $result['latitude'] = $latitude; |
218 | 232 | $result['longitude'] = $longitude; |
219 | 233 | $body_parse = substr($body_parse,18); |
@@ -245,7 +259,9 @@ discard block |
||
245 | 259 | //} |
246 | 260 | //echo $body_parse; |
247 | 261 | $result['symbol_code'] = $symbol_code; |
248 | - if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
|
262 | + if (isset($this->symbols[$symbol_code])) { |
|
263 | + $result['symbol'] = $this->symbols[$symbol_code]; |
|
264 | + } |
|
249 | 265 | if ($symbol_code != '_') { |
250 | 266 | //$body_parse = substr($body_parse,1); |
251 | 267 | //$body_parse = trim($body_parse); |
@@ -255,7 +271,9 @@ discard block |
||
255 | 271 | if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
256 | 272 | $course = substr($body_parse,0,3); |
257 | 273 | $tmp_s = intval($course); |
258 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
274 | + if ($tmp_s >= 1 && $tmp_s <= 360) { |
|
275 | + $result['heading'] = intval($course); |
|
276 | + } |
|
259 | 277 | $speed = substr($body_parse,4,3); |
260 | 278 | $result['speed'] = round($speed*1.852); |
261 | 279 | $body_parse = substr($body_parse,7); |
@@ -290,10 +308,16 @@ discard block |
||
290 | 308 | $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
291 | 309 | $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
292 | 310 | |
293 | - if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
|
294 | - else $result['latitude'] += $lat_off; |
|
295 | - if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
|
296 | - else $result['longitude'] += $lon_off; |
|
311 | + if ($result['latitude'] < 0) { |
|
312 | + $result['latitude'] -= $lat_off; |
|
313 | + } else { |
|
314 | + $result['latitude'] += $lat_off; |
|
315 | + } |
|
316 | + if ($result['longitude'] < 0) { |
|
317 | + $result['longitude'] -= $lon_off; |
|
318 | + } else { |
|
319 | + $result['longitude'] += $lon_off; |
|
320 | + } |
|
297 | 321 | } |
298 | 322 | $body_parse = substr($body_parse,6); |
299 | 323 | } |
@@ -307,27 +331,48 @@ discard block |
||
307 | 331 | $address = substr($id,2); |
308 | 332 | //print_r($matches); |
309 | 333 | $addressType = (intval(substr($id,0,2),16))&3; |
310 | - if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
|
311 | - elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
|
312 | - elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
|
313 | - elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
|
334 | + if ($addressType == 0) { |
|
335 | + $result['addresstype'] = "RANDOM"; |
|
336 | + } elseif ($addressType == 1) { |
|
337 | + $result['addresstype'] = "ICAO"; |
|
338 | + } elseif ($addressType == 2) { |
|
339 | + $result['addresstype'] = "FLARM"; |
|
340 | + } elseif ($addressType == 3) { |
|
341 | + $result['addresstype'] = "OGN"; |
|
342 | + } |
|
314 | 343 | $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
315 | 344 | $result['aircrafttype_code'] = $aircraftType; |
316 | - if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
|
317 | - elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
|
318 | - elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE"; |
|
319 | - elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
320 | - elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE"; |
|
321 | - elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE"; |
|
322 | - elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER"; |
|
323 | - elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER"; |
|
324 | - elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
325 | - elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
326 | - elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO"; |
|
327 | - elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON"; |
|
328 | - elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
|
329 | - elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
|
330 | - elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
|
345 | + if ($aircraftType == 0) { |
|
346 | + $result['aircrafttype'] = "UNKNOWN"; |
|
347 | + } elseif ($aircraftType == 1) { |
|
348 | + $result['aircrafttype'] = "GLIDER"; |
|
349 | + } elseif ($aircraftType == 2) { |
|
350 | + $result['aircrafttype'] = "TOW_PLANE"; |
|
351 | + } elseif ($aircraftType == 3) { |
|
352 | + $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
353 | + } elseif ($aircraftType == 4) { |
|
354 | + $result['aircrafttype'] = "PARACHUTE"; |
|
355 | + } elseif ($aircraftType == 5) { |
|
356 | + $result['aircrafttype'] = "DROP_PLANE"; |
|
357 | + } elseif ($aircraftType == 6) { |
|
358 | + $result['aircrafttype'] = "HANG_GLIDER"; |
|
359 | + } elseif ($aircraftType == 7) { |
|
360 | + $result['aircrafttype'] = "PARA_GLIDER"; |
|
361 | + } elseif ($aircraftType == 8) { |
|
362 | + $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
363 | + } elseif ($aircraftType == 9) { |
|
364 | + $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
365 | + } elseif ($aircraftType == 10) { |
|
366 | + $result['aircrafttype'] = "UFO"; |
|
367 | + } elseif ($aircraftType == 11) { |
|
368 | + $result['aircrafttype'] = "BALLOON"; |
|
369 | + } elseif ($aircraftType == 12) { |
|
370 | + $result['aircrafttype'] = "AIRSHIP"; |
|
371 | + } elseif ($aircraftType == 13) { |
|
372 | + $result['aircrafttype'] = "UAV"; |
|
373 | + } elseif ($aircraftType == 15) { |
|
374 | + $result['aircrafttype'] = "STATIC_OBJECT"; |
|
375 | + } |
|
331 | 376 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
332 | 377 | $result['stealth'] = $stealth; |
333 | 378 | $result['address'] = $address; |
@@ -367,12 +412,18 @@ discard block |
||
367 | 412 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
368 | 413 | } |
369 | 414 | } |
370 | - } else $result['comment'] = trim($body_parse); |
|
415 | + } else { |
|
416 | + $result['comment'] = trim($body_parse); |
|
417 | + } |
|
371 | 418 | |
372 | 419 | } |
373 | 420 | //} |
374 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
375 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
421 | + if (isset($result['latitude'])) { |
|
422 | + $result['latitude'] = round($result['latitude'],4); |
|
423 | + } |
|
424 | + if (isset($result['longitude'])) { |
|
425 | + $result['longitude'] = round($result['longitude'],4); |
|
426 | + } |
|
376 | 427 | //print_r($result); |
377 | 428 | return $result; |
378 | 429 | } |