Sfoglia il codice sorgente

Configure for Ardupilot server

Stephen Dade 5 anni fa
parent
commit
bf27ab4257
6 ha cambiato i file con 29 aggiunte e 21 eliminazioni
  1. 1 1
      README.md
  2. 12 11
      app.py
  3. 1 1
      templates/index.html
  4. 11 0
      terraingen.ini
  5. 0 8
      terraingen.wsgi
  6. 4 0
      wsgi.py

+ 1 - 1
README.md

@@ -21,7 +21,7 @@ This website uses the flask library.
 
 To install dependencies:
 
-``pip install flask wheel numpy mavproxy crc16 pytest``
+``pip install flask wheel uwsgi numpy mavproxy crc16 pytest``
 
 To run:
 

+ 12 - 11
app.py

@@ -16,7 +16,10 @@ from terrain_gen import add_offset
 this_path = os.path.dirname(os.path.realpath(__file__))
 
 # Where the user requested tile are stored
-output_path = os.path.join(this_path, 'outputTer')
+output_path = os.path.join(this_path, '..', 'userRequestTerrain')
+
+# Where the data database is
+tile_path = os.path.join(this_path, '..', 'data', 'tiles')
 
 # The output folder for all gzipped terrain requests
 app = Flask(__name__, static_url_path='/terrain', static_folder=output_path,)
@@ -36,17 +39,17 @@ def getDatFile(lat, lon):
         EW = 'E'
     return "%c%02u%c%03u.DAT.gz" % (NS, min(abs(int(lat)), 99), EW, min(abs(int(lon)), 999))
 
-def compressFiles(fileList, uuidkey, outfolder):
+def compressFiles(fileList, uuidkey):
     # create a zip file comprised of dat.gz tiles
-    zipthis = os.path.join(outfolder, uuidkey + '.zip')
+    zipthis = os.path.join(output_path, uuidkey + '.zip')
 
     # create output dirs if needed
     try:
-        os.makedirs(outfolder)
+        os.makedirs(output_path)
     except OSError:
         pass
     try:
-        os.makedirs(os.path.join(this_path, "processedTerrain"))
+        os.makedirs(tile_path)
     except OSError:
         pass
 
@@ -56,7 +59,7 @@ def compressFiles(fileList, uuidkey, outfolder):
                 if not os.path.exists(fn):
                     #download if required
                     print("Downloading " + os.path.basename(fn))
-                    g = urllib.request.urlopen('https://firmware.ardupilot.org/terrain/tiles/' +
+                    g = urllib.request.urlopen('https://terrain.ardupilot.org/data/tiles/' +
                                                os.path.basename(fn))
                     print("Downloaded " + os.path.basename(fn))
                     with open(fn, 'b+w') as f:
@@ -119,15 +122,13 @@ def generate():
                 done.add(tag)
                 # make sure tile is inside the 60deg latitude limit
                 if abs(lat_int) <= 60:
-                    filelist.append(os.path.join(this_path, "processedTerrain",
-                                                 getDatFile(lat_int, lon_int)))
+                    filelist.append(tile_path, getDatFile(lat_int, lon_int)))
                 else:
                     outsideLat = True
 
         # make sure tile is inside the 60deg latitude limit
         if abs(lat_int) <= 60:
-            filelist.append(os.path.join(this_path, "processedTerrain",
-                                         getDatFile(lat_int, lon_int)))
+            filelist.append(os.path.join(tile_path, getDatFile(lat_int, lon_int)))
         else:
             outsideLat = True
 
@@ -136,7 +137,7 @@ def generate():
         print(filelist)
 
         #compress
-        success = compressFiles(filelist, uuidkey, output_path)
+        success = compressFiles(filelist, uuidkey)
 
         # as a cleanup, remove any generated terrain older than 24H
         for f in os.listdir(output_path):

+ 1 - 1
templates/index.html

@@ -2,7 +2,7 @@
 <title>ArduPilot Terrain Generator</title>
 <h1>ArduPilot Terrain Generator</h1>
 
-<p>Use this to generate terrain to put on your SD card.</p>
+<p>Use this to generate terrain to put on your SD card. The generated terrain is based on the SRTM data and has 100m horizontal resolution.</p>
 
 <p>Multiple generated files can be combined on the SD card.</p>
 

+ 11 - 0
terraingen.ini

@@ -0,0 +1,11 @@
+[uwsgi]
+module = wsgi:app
+
+master = true
+processes = 5
+
+socket = terraingen.sock
+chmod-socket = 660
+vacuum = true
+
+die-on-term = true

+ 0 - 8
terraingen.wsgi

@@ -1,8 +0,0 @@
-#!/usr/bin/python3
-import sys
-import logging
-logging.basicConfig(stream=sys.stderr)
-sys.path.insert(0,"/var/www/terraingen/")
-
-from app import app as application
-application.secret_key = 'Add your secret key'

+ 4 - 0
wsgi.py

@@ -0,0 +1,4 @@
+from terraingen import app
+
+if __name__ == "__main__":
+    app.run()