-
Notifications
You must be signed in to change notification settings - Fork 1
/
rdsparse.php
111 lines (101 loc) · 3.4 KB
/
rdsparse.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
<?php
include_once('rdsdecode.php');
include_once('tmcdecode.php');
include_once('tmclocation.php');
function show_group($group)
{
global $cid, $tabcd, $time;
//echo sprintf("<li><pre>%04x %04x %04x %04x</pre></li>\n", $group[0], $group[1], $group[2], $group[3]);
switch($group[1] >> 11)
{
case 0x08: // 4A = Clock-time and date
$offset = ($group[3] & 0x1f) * ($group[3] & 0x20 ? -1 : 1);
$minute = ($group[3] >> 6) & 0x3f;
$hour = ($group[3] >> 12) + (($group[2] & 0x01) << 4);
$date = ($group[2] >> 1) + (($group[1] & 0x03) << 15);
$time = ($date - 40587) * 86400 + $hour * 3600 + $minute * 60;
$loctime = $time + $offset * 1800;
echo "<tr><td class=\"timestamp\" colspan=\"4\">Timestamp: " . gmdate("d. m. Y H:i T", $time) . " / " . ($group[3] & 0x20 ? "-" : "+") . sprintf("%02d:%02d", ($group[3] >> 1) & 0x0f, ($group[3] & 0x01) * 30) . "</td></tr>\n";
break;
case 0x10: // 8A = TMC data
if($message = decode_tmc($group))
{
$event = find_event($message['ecd']);
$location = find_place($cid, $tabcd, $message['lcd']);
echo "<tr><td class=\"ecd\"><a href=\"tmcmsgmap.php?cid=$cid&tabcd=$tabcd&ecd={$message['ecd']}&lcd={$message['lcd']}&ext={$message['ext']}&dir={$message['dir']}";
if(array_key_exists('div', $message))
echo "&div={$message['div']}";
if(array_key_exists('dur', $message))
echo "&dur={$message['dur']}";
if(array_key_exists('bits', $message))
echo "&bits={$message['bits']}";
echo "&time=$time\">{$message['ecd']}</a></td><td class=\"event\">{$event['text']}</td>";
echo "<td class=\"lcd\"><a href=\"/tmc/tmcview.php?cid=$cid&tabcd=$tabcd&lcd={$message['lcd']}\">$cid:$tabcd:{$message['lcd']}</a></td><td class=\"location\">";
switch($location['class'])
{
case 'P':
echo trim($location['junctionnumber'] . " " . $location['n1id']);
break;
case 'L':
echo trim($location['roadnumber'] . " " . $location['rnid']);
break;
case 'A':
echo $location['nid'];
break;
}
echo "</td></tr>\n";
}
break;
default:
//echo sprintf("<!-- %d%s -->\n", $group[1] >> 12, ($group[1] & (1 << 11) ? 'B' : 'A'));
break;
}
flush();
}
$cid = (array_key_exists('cid', $_REQUEST) ? (int)$_REQUEST['cid'] : 58);
$tabcd = (array_key_exists('tabcd', $_REQUEST) ? (int)$_REQUEST['tabcd'] : 1);
$time = (array_key_exists('time', $_REQUEST) ? (int)$_REQUEST['time'] : time());
header("Content-type: text/html");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="rds.css"/>
<title>RDS decoder</title>
</head>
<body>
<h1>RDS decoder</h1>
<table>
<?php
echo "<!--"; print_r($_REQUEST); echo "-->\n";
$function = "decode_{$_REQUEST['format']}_{$_REQUEST['input']}";
switch($function)
{
case "decode_hex_text":
case "decode_bit_text":
case "decode_byte_text":
case "decode_hex_url":
case "decode_bit_url":
case "decode_byte_url":
if(array_key_exists($_REQUEST['input'], $_REQUEST))
call_user_func($function, $_REQUEST[$_REQUEST['input']], "show_group");
else
echo "<p>No input given.</p>\n";
break;
case "decode_hex_file":
case "decode_bit_file":
case "decode_byte_file":
if(array_key_exists('file', $_FILES))
call_user_func($function, $_FILES['file']['tmp_name'], "show_group");
else
echo "<p>No input given.</p>\n";
break;
default:
echo "<p>Invalid input type or format.</p>\n";
break;
}
?>
</table>
</body>
</html>