-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfgcom.html
282 lines (270 loc) · 10.1 KB
/
fgcom.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="GENERATOR"
content="Manual">
<meta name="author"
content="Geoff R. McLane">
<title>
FGCOM Pilots
</title>
<meta http-equiv="Content-Type"
content="text/html; charset=us-ascii">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable"
content="yes">
<script type="text/javascript"
src="js/jquery-2.0.3.js">
</script>
<script type="text/javascript">
var fgcom_url = 'proxy/fgcom.php';
var fgcom_dir = 'http://fgcom.flightgear.org/feed.php?json';
var fgcom_to = 3000;
var cf_url = 'http://crossfeed.fgx.ch/flights.json';
var cf_to = 3000; // about each 3 seconds
function init(url) {
if (url.length == 0) url = fgcom_dir;
fgcom_url = url;
sendRequest3(url);
}
// ----------------------------------------------------------------------------------------------
// Loading the JSON data
// ----------------------------------------------------------------------------------------------
// XMLHttpRequest handling
function getXMLHttpRequest() {
var httpReq = null;
if (window.XMLHttpRequest) {
httpReq = new XMLHttpRequest();
}
else if (typeof ActiveXObject != "undefined") {
httpReq = new ActiveXObject("Microsoft.XMLHTTP")
}
return httpReq;
}
function sendRequestCB(url,callback) {
var req = getXMLHttpRequest();
if (req !== null) {
req.onreadystatechange = callback;
req.open("GET", url);
req.send(null);
} else {
alert("Your browser does not support an XMLHttpRequest object. No updates will happen!");
}
}
function sendRequest(url) {
sendRequestCB(url,crossfeed);
}
function sendRequest3(url) {
sendRequestCB( url, fgcomdata);
}
var flightdata = [];
function getCFData(icao) {
var cf = "";
var len = flightdata.length;
var i, j;
for (i = 0; i < len; i++) {
var fr = flightdata[i];
if (fr[0] == icao) {
for (j = 1; j < 8; j++) {
if (j > 1) cf += ",";
cf += fr[j];
}
break;
}
}
return cf;
}
function crossfeed() {
if (( this.readyState == 4 ) && (this.status == "200")) {
var text = this.responseText;
var data = JSON.parse(text);
flightdata = [];
$(data.flights).each(function (i) {
var cs = this.callsign;
var lat = this.lat;
var lon = this.lon;
var alt = this.alt_ft;
var hdg = this.hdg;
var spd = this.spd_kts;
var mod = get_model(this.model);
var dist = this.dist_nm;
var flightrow = [cs,lat,lon,alt,hdg,spd,dist,mod];
flightdata.push(flightrow);
});
setTimeout("sendRequest('"+cf_url+"')", cf_to);
}
}
// Some strings to construct the table...
var tableheader = "<table width='100%'>"+
"<tr>"+
"<th>Callsign<\/th>"+
"<th>ICAO<\/th>"+
"<th>Frequency<\/th>"+
"<th>Date<\/th>"+
"<th>Lat,Lon,Alt,Hdg,Spd,Dist,Mod<\/th>"+
"<\/tr>";
function fgcomdata() {
if ( this.readyState == 4 ) {
if (this.status == "200") {
var text = this.responseText;
// console.log("FGC:["+text+"]");
html = tableheader;
try {
var data = JSON.parse(text);
if (data.clients) {
var ca = data.clients;
var sz = ca.length;
// console.log("Gt array of " + sz + " clients");
var i;
for (i = 0; i < sz; i++) {
var fa = ca[i];
var cs = fa.callsign;
var app = fa.app;
var ver = fa.version;
var icao = fa.icao;
var freq = fa.frequency;
var dt = fa.datetime;
if (freq == '910.111') {
freq = 'Echo-test';
}
var cf = getCFData(cs);
html += "<tr>";
html += "<td><b>"+cs+"<\/b> ("+app+" "+ver+")<\/td>";
html += "<td><b>"+icao+"<\/b><\/td>";
html += "<td><b>"+freq+"<\/b> MHz<\/td>";
html += "<td>"+dt+"<\/td>";
html += '<td align="center">'+cf+"<\/td>";
html += "<\/tr>";
}
if (sz == 0) {
html += "<tr>";
html += "<td colspan='5' align='center'>No FGCom connections available from "+
'<a href="'+fgcom_url+'">'+fgcom_url+'<\/a><\/td>';
html += "<\/tr>";
} else {
var msg = " connection";
if (sz > 1) msg += 's';
html += "<tr>";
html += "<td colspan='5' align='center'>Total "+sz+msg+"<\/td>";
html += "<\/tr>";
}
} else {
//console.log("clients not present");
html += "<tr>";
html += "<td colspan='5' align='center'>No FGCom connections available from "+
'<a href="'+fgcom_url+'">'+fgcom_url+'<\/a><\/td>';
html += "<\/tr>";
}
} catch (e) {
html += "<tr>";
html += "<td colspan='5' align='center'>Parse error: "+e+" from "+
'<a href="'+fgcom_url+'">'+fgcom_url+'<\/a><\/td>';
html += "<\/tr>";
//console.log("Parse error: ", e);
}
html += "<\/table>";
$("#main").html(html);
setTimeout("sendRequest3('"+fgcom_url+"')", fgcom_to);
}
}
}
// ----------------------------------------------------------------------------------------------
// Utility functions
// ----------------------------------------------------------------------------------------------
// various guesses that it is ATC
function is_atc( callsign, model ) {
if (model == 'OpenRadar') return true;
var mod = model.toUpperCase();
var n = mod.indexOf('ATC');
if (n >= 0) return true;
n = callsign.indexOf('ATC');
if (n >= 0) return true;
return false;
}
// strip .xml extension, and strip '-model'
function strip_extent(txt) {
var n = txt.lastIndexOf('.');
if (n > 0) {
txt = txt.substr(0,n);
n = txt.indexOf('-model'); // like 'A-10-model'
if (n > 0) {
txt = txt.substr(0,n);
} else {
n = txt.indexOf('-jsbsim'); // like 'dr400-180-jsbsim'
if (n > 0) {
txt = txt.substr(0,n);
}
}
}
return txt;
}
// remove path from model name, strip .xml extension, and limit length to 10 letters
function get_model(txt) {
var n = txt.lastIndexOf('/');
if (n > 0) {
txt = strip_extent(txt.substr(n+1));
}
if (txt.length > 10) {
txt = txt.substr(0,10);
}
return txt;
}
function gup( name ) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
</script>
<link rel="stylesheet"
media="screen"
type="text/css"
title="Design"
href="css/fgcom.css">
</head>
<body>
<table summary="header table">
<tr>
<td>
<img src="images/fgcom.jpg"
alt="fgcom logo">
</td>
<td>
<h1>
Live FGCom
</h1>
</td>
</tr>
</table>
<hr style="width:100%; margin:0; padding:0;">
<br>
<div id="title">
Live FGCOM Server Connections, plus crossfeed data, where available.
</div>
<div id="main">
</div>
<div id="footer">
<hr>
<p>
Copyright - Clément de l'Hamaide 2013
</p>
<p>
<a href="http://fgcom.flightgear.org">fgcom.flightgear.org</a>
</p>
<br>
</div>
<!-- This gives IE compatibility with the OpenLayers map init function -->
<script type="text/javascript"
defer="defer">
sendRequest(cf_url); // start crossfeed feed
var url = gup('url');
init(url); // init the fgcom feed
</script>
</body>
</html>