-
Notifications
You must be signed in to change notification settings - Fork 0
/
radar_table.php
218 lines (190 loc) · 6.33 KB
/
radar_table.php
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
<!-- Copyright © 2024 Anthony Borriello - antonioborriello.wordpress.com -->
<!-- GitHub: https://github.com/anthonyborriello -->
<!DOCTYPE html>
<html>
<head>
<title>Radar Table</title>
<style>
body {
font-family: 'Verdana', sans-serif;
padding-top: 20px;
background-color: #000;
color: #fff;
}
h1 {
font-weight: 100;
text-align: center;
padding-bottom: 4px;
}
.container {
max-width: 1200px;
margin: 20px auto;
}
table {
width: 100%;
border-collapse: collapse;
table-layout: fixed; /* Sets the table width based on the specified width and ignores the content */
}
th, td {
padding: 0px;
border-bottom: 1px solid #fff;
text-align: center;
}
th {
background-color: #004165;
}
tr:nth-child(even) {
background-color: #00304e;
}
tr:nth-child(odd) {
background-color: #00243a;
}
a.icao-link {
color: #fff;
}
.flight-status {
display: inline-block;
padding: 5px 10px;
border-radius: 5px;
color: #fff;
}
.ads-b {
background-color: #1a8cff;
}
a {
color: #1a8cff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* Sets a fixed height for all table rows */
tr {
height: 50px;
}
/* Sets the text for cells of empty rows */
tr > td[colspan="9"]:empty::before {
content: "";
color: #fff;
}
/* Custom status background color */
.na-status {
background-color: #666;
}
</style>
<meta http-equiv="refresh" content="5">
</head>
<body>
<div class="container">
<div class="header">
<h1>Dump1090 Radar Table</h1>
</div>
<table>
<tr>
<th>ICAO</th>
<th>Flight</th>
<th>Squawk</th>
<th>Altitude</th>
<th>Ground Speed</th>
<th>Distance (NM)</th>
<th>Heading</th>
<th>Latitude</th>
<th>Longitude</th>
<th>Status</th>
</tr>
<?php
function calculate_distance($lat1, $lon1, $lat2, $lon2) {
if ($lat1 == 0 || $lon1 == 0 || $lat2 == 0 || $lon2 == 0) {
return "N/A"; // If any of the coordinates are missing, returns "N/A"
}
$R = 3440.065;
$lat1_rad = deg2rad($lat1);
$lon1_rad = deg2rad($lon1);
$lat2_rad = deg2rad($lat2);
$lon2_rad = deg2rad($lon2);
$dlon = $lon2_rad - $lon1_rad;
$dlat = $lat2_rad - $lat1_rad;
$a = sin($dlat / 2)**2 + cos($lat1_rad) * cos($lat2_rad) * sin($dlon / 2)**2;
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
$distance = $R * $c;
return $distance;
}
$response = file_get_contents('http://raspberrypi:8080/data/aircraft.json');
if ($response) {
$data = json_decode($response, true);
$aircrafts = $data['aircraft'] ?? [];
$reference_point = array(41.9028, 12.4964);
$aircraft_distances = [];
foreach ($aircrafts as $aircraft) {
$aircraft_lat = $aircraft['lat'] ?? 0;
$aircraft_lon = $aircraft['lon'] ?? 0;
$distance = calculate_distance($reference_point[0], $reference_point[1], $aircraft_lat, $aircraft_lon);
// Checks if the coordinates are present and sets the $status variable
if ($aircraft_lat != 0 && $aircraft_lon != 0) {
$status = "ADS-B";
} else {
// If coordinates are missing, checks if the 'category' field is present
$status = isset($aircraft['category']) && !empty($aircraft['category']) ? "ADS-B" : "N/A";
}
// Limit the number of decimal places to 2 if it's a number
if (is_numeric($distance)) {
$formatted_distance = number_format($distance, 2);
} else {
$formatted_distance = $distance;
}
$aircraft_distances[] = [
'icao' => $aircraft['hex'],
'flight' => $aircraft['flight'],
'squawk' => $aircraft['squawk'],
'altitude' => $aircraft['alt_baro'],
'ground_speed' => $aircraft['gs'],
'distance' => $formatted_distance,
'heading' => $aircraft['track'],
'latitude' => $aircraft['lat'],
'longitude' => $aircraft['lon'],
'status' => $status,
'distance_numeric' => $distance // Saves the numeric distance for sorting
];
}
// Sorts the aircraft by distance
usort($aircraft_distances, function($a, $b) {
return $a['distance_numeric'] <=> $b['distance_numeric'];
});
// Prints the data in the HTML table
foreach ($aircraft_distances as $aircraft_data) {
echo "<tr>";
echo "<td><a class='icao-link' href='https://globe.adsbexchange.com/?icao={$aircraft_data['icao']}' target='_blank'>{$aircraft_data['icao']}</a></td>";
echo "<td><a href='https://www.flightradar24.com/{$aircraft_data['flight']}' target='_blank'>{$aircraft_data['flight']}</a></td>";
echo "<td>{$aircraft_data['squawk']}</td>";
echo "<td>{$aircraft_data['altitude']}</td>";
echo "<td>{$aircraft_data['ground_speed']}</td>";
// Replace 'N/A' with an empty string if it's 'N/A'
$distance_display = $aircraft_data['distance'] == 'N/A' ? '' : $aircraft_data['distance'];
echo "<td>{$distance_display}</td>";
echo "<td>{$aircraft_data['heading']}</td>";
echo "<td>{$aircraft_data['latitude']}</td>";
echo "<td>{$aircraft_data['longitude']}</td>";
echo "<td><span class='flight-status " . strtolower($aircraft_data['status']);
// Add the 'na-status' class if status is 'N/A'
if ($aircraft_data['status'] == 'N/A') {
echo " na-status";
}
echo "'>";
// If status is 'N/A', print custom text instead of 'N/A'
if ($aircraft_data['status'] == 'N/A') {
echo "ADS-B";
} else {
echo $aircraft_data['status'];
}
echo "</span></td>";
echo "</tr>";
}
} else {
http_response_code(500);
echo "<tr><td colspan='10'>500 Internal Server Error</td></tr>";
}
?>
</table>
</div>
</body>
</html>