-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathload-message-labels.php
More file actions
65 lines (56 loc) · 2.18 KB
/
load-message-labels.php
File metadata and controls
65 lines (56 loc) · 2.18 KB
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
<?php
// Load message labels from CSV (label-list.csv)
$labelDescriptions = [];
$csvFile = __DIR__ . '/acars-decoding-library/label-list.csv';
if (file_exists($csvFile)) {
$file = fopen($csvFile, 'r');
$header = fgetcsv($file, 0, ',', '"', '\\'); // Skip header row
// First pass: collect all labels with their directions and decodability
$labelData = [];
while (($row = fgetcsv($file, 0, ',', '"', '\\')) !== false) {
if (count($row) >= 5) {
$direction = strtoupper(trim($row[0])); // up/dn
$code = trim($row[1]);
$decodability = trim($row[2]); // decodable/non-decodable/reserved/not-used
$name = trim($row[4]); // name column
if (!isset($labelData[$code])) {
$labelData[$code] = [
'directions' => [],
'decodable_directions' => []
];
}
$labelData[$code]['directions'][$direction] = $name;
// Track decodable directions
if ($decodability === 'decodable') {
$labelData[$code]['decodable_directions'][] = $direction;
}
}
}
fclose($file);
// Second pass: format the descriptions
foreach ($labelData as $code => $data) {
$directions = $data['directions'];
$hasUp = isset($directions['UP']);
$hasDn = isset($directions['DN']);
if ($hasUp && $hasDn) {
// Both directions exist
$explanation = $directions['UP'] . ' - UP / ' . $directions['DN'] . ' - DOWN';
$direction = '';
} elseif ($hasUp) {
// Only UP
$explanation = $directions['UP'] . ' - UP';
$direction = '';
} else {
// Only DN
$explanation = $directions['DN'] . ' - DOWN';
$direction = '';
}
$labelDescriptions[$code] = [
'explanation' => $explanation,
'direction' => $direction,
'decodable_directions' => $data['decodable_directions'] // e.g., ['UP'], ['DN'], or ['UP', 'DN']
];
}
}
// Make available as both variable names for compatibility
$MESSAGE_LABEL_DESCRIPTIONS = $labelDescriptions;