summaryrefslogtreecommitdiff
path: root/tools/mmd/tracker.wsgi
blob: 8411ffbc45c881226c676000ab5397049b6487fe (plain) (blame)
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
#!/usr/bin/env python

from cgi import escape
from urlparse import parse_qs

def application (environ, response):
  """
  beginning of WSGI/python application for
  MURSAT1 Tracker
  """
  
  body = '''
<!doctype html>
<html class="tracker">
<head>
  <meta charset="utf-8" />
  <title>Tracking ARISSAT using OrbTrak</title>
  <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
  <script src="static/predictlib.js" type="text/javascript"></script>
  <script src="static/tle.js" type="text/javascript"></script>
  <script src="static/orbtrak.js" type="text/javascript"></script>
  <script type="text/javascript">
    function load()
    {{
      Orb.startOSMTracking({longitude}, {latitude}, {altitude}, '{name}');
    }}
    function printTLE ()
    {{
      tleWindow = window.open ("", "", "width=500, height=40");
      tleWindow.document.write ("<pre>" + Orb.printTLE () + "</pre>");
      tleWindow.focus ();
    }}
  </script>
  <link rel="stylesheet" type="text/css" href="static/mmd.css" />
</head>
<body class="tracker" onload="load()">
  <div id="osm">
    <div class="groundstation">
      Location
      <span id="gsName"></span>,
      Lon:
      <span id="gsLongitude"></span>,
      Lat:
      <span id="gsLatitude"></span>,
      Alt:
      <span id="gsAltitude"></span>
    </div>
  </div>
  <table class="current">
    <tr>
      <th class="telemetry">Satellite</th>
      <th class="telemetry">Longitude</th>
      <th class="telemetry">Latitude</th>
      <th class="telemetry">Azimuth</th>
      <th class="telemetry">Elevation</th>
      <th class="telemetry">Altitude</th>
    </tr>
    <tr>
      <td class="telemetry"  id="name">
      </td>
      <td class="telemetry"  title="degrees east (+)/west (-) of Greenwich" id="longitude">
      </td>
      <td class="telemetry"  title="degrees north (+)/south (-) of equator" id="latitude">
      </td>
      <td class="telemetry"  id="azimuth">
      </td>
      <td class="telemetry"  id="elevation">
      </td>
      <td class="telemetry"  title="km above surface of earth" id="altitude">
      </td>
    </tr>
  </table>
  <div class="options">Set refresh rate to <span>
    <select class="options" name="refresh" id="refresh" tabindex="1">
    <option value="100">0.1</option>
    <option value="500">0.5</option>
    <option value="1000">1.0</option>
    <option value="2000">2.0</option>
    <option value="5000" selected="selected">5.0</option>
    </select> seconds</span>
  </div>
  <div class="options">
    <input class="options" type="submit" value="update" id="setPreviewMinutes" onClick="Orb.createSatelliteTrack ()" tabindex="2" />
    preview for the next <input class="options" type="text" name="previewMinutes" id="previewMinutes" value="90" size="5" tabindex="3" />
    minutes
  </div>
  <div class="options">
    <input class="options" type="submit" value="show TLE" onClick="printTLE ()" />
  </div>
  <pre class="debug" id="debug"></pre>
</body>
</html>
'''

  qs = parse_qs (environ['QUERY_STRING'], True)
  if qs.has_key ('longitude') and qs.has_key ('latitude') and qs.has_key ('altitude'):
    query = {
      'longitude': escape (qs.get ('longitude')[0]),
      'latitude': escape (qs.get ('latitude')[0]),
      'altitude': escape (qs.get ('altitude')[0])
      }
    if qs.has_key ('name'):
      query ['name'] = escape (qs.get ('name')[0])
    else:
      query ['name'] = 'unknown set'
  else:
    query = {
      'longitude': 15.4422,
      'latitude': 47.0658,
      'altitude': 376,
      'name': 'Graz'
      }

  body = body.format (**query)
  headers = ([('Content-Type', 'text/html'), ('Content-Length', str (len (body)))])
  response ('200 OK', headers)

  return [body]

# vim: tw=0 ts=2 expandtab
# EOF