change back to web.py since it is much more faster
And finally I found that web.py supports Python 3...
This commit is contained in:
parent
ff45f465e6
commit
4ce4d0a753
138
.gitignore
vendored
138
.gitignore
vendored
@ -39,3 +39,141 @@ gps-sdr-sim-lut
|
||||
# Temporary files
|
||||
*.swp
|
||||
*~
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
@ -1,62 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
from tornado.web import RequestHandler, StaticFileHandler
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
import socket
|
||||
import struct
|
||||
import time
|
||||
import os
|
||||
|
||||
import web
|
||||
HOST = 'localhost'
|
||||
PORT = 5678
|
||||
BUFFSIZE = 1024
|
||||
ADDR = (HOST, PORT)
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
|
||||
class IndexHandler(RequestHandler):
|
||||
def get(self):
|
||||
self.redirect('/static/baidumap.html')
|
||||
urls = (
|
||||
'/', 'index',
|
||||
'/post', 'post',
|
||||
'/static/*', 'static',
|
||||
)
|
||||
app = web.application(urls, globals())
|
||||
|
||||
|
||||
class PostHandler(RequestHandler):
|
||||
def post(self):
|
||||
self.set_header('Content-Type', 'text/plain')
|
||||
pos = [
|
||||
float(self.get_body_argument(k)) for k in ['lat', 'lon', 'hgt']
|
||||
]
|
||||
data = struct.pack('ddd', *pos)
|
||||
sock.sendto(data, (HOST, PORT))
|
||||
print(*pos)
|
||||
self.write('OK')
|
||||
class index:
|
||||
def GET(self):
|
||||
raise web.seeother('/static/baidumap.html')
|
||||
|
||||
|
||||
def make_app():
|
||||
return tornado.web.Application([
|
||||
(r'/', IndexHandler),
|
||||
(r'/post', PostHandler),
|
||||
(r'/static/(.*)', StaticFileHandler, {
|
||||
'path': os.path.dirname(__file__)
|
||||
})
|
||||
])
|
||||
class post:
|
||||
def POST(self):
|
||||
inn = web.input()
|
||||
lon = float(inn.get('lon'))
|
||||
lat = float(inn.get('lat'))
|
||||
h = float(inn.get('hgt'))
|
||||
data = struct.pack('ddd', lat, lon, h)
|
||||
sock.sendto(data, ADDR)
|
||||
print(lon, lat, h)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from argparse import ArgumentParser
|
||||
argp = ArgumentParser(description='GPS-SDR-SIM realtime map server.')
|
||||
argp.add_argument('port',
|
||||
type=int,
|
||||
default=8080,
|
||||
nargs='?',
|
||||
help='specify port for map server [default: 8080]')
|
||||
argp.add_argument(
|
||||
'--host',
|
||||
type=str,
|
||||
default='0.0.0.0',
|
||||
help='specify host map server to bind [default: 0.0.0.0]')
|
||||
args = argp.parse_args()
|
||||
class static:
|
||||
def GET(self, media, file):
|
||||
try:
|
||||
f = open(media + '/' + file, 'r')
|
||||
return f.read()
|
||||
except:
|
||||
return '404'
|
||||
|
||||
app = make_app()
|
||||
print('Serving at http://{}:{}'.format(args.host, args.port))
|
||||
app.listen(args.port, args.host)
|
||||
tornado.ioloop.IOLoop.current().start()
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
|
Loading…
Reference in New Issue
Block a user