-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python | ||
|
||
''' | ||
MAVProxy Cockpit module that serves files from its directory | ||
''' | ||
|
||
from MAVProxy.modules.lib import mp_module | ||
import os | ||
from http.server import HTTPServer, SimpleHTTPRequestHandler | ||
import threading | ||
|
||
class CustomHTTPRequestHandler(SimpleHTTPRequestHandler): | ||
"""Custom handler that serves from absolute directory path""" | ||
def __init__(self, *args, directory=None, **kwargs): | ||
# SimpleHTTPRequestHandler supports absolute paths directly | ||
super().__init__(*args, directory=directory, **kwargs) | ||
|
||
class Cockpit(mp_module.MPModule): | ||
def __init__(self, mpstate): | ||
super(Cockpit, self).__init__(mpstate, "cockpit", "Cockpit GCS module") | ||
|
||
# Default port | ||
self.port = 8080 | ||
self.link = "wsserver:0.0.0.0:5010" | ||
|
||
# Get the directory where this module file is located | ||
self.module_dir = os.path.dirname(os.path.abspath(__file__)) | ||
self.html_dir = os.path.join(self.module_dir, 'static', 'dist') | ||
|
||
# Start server automatically | ||
self.start_server() | ||
self.setup_new_link() | ||
|
||
def start_server(self): | ||
'''Start the web server serving from module directory''' | ||
try: | ||
# Create handler class with bound directory | ||
handler = lambda *args, **kwargs: CustomHTTPRequestHandler(*args, | ||
directory=self.html_dir, | ||
**kwargs) | ||
|
||
# Create and start server | ||
self.web_server = HTTPServer(('', self.port), handler) | ||
self.server_thread = threading.Thread(target=self.web_server.serve_forever) | ||
self.server_thread.daemon = True | ||
self.server_thread.start() | ||
print(f"Web server running at http://localhost:{self.port}/?mainConnectionURI=ws://localhost:5010#/") | ||
#print(f"Serving files from: {self.html_dir}") | ||
|
||
except Exception as e: | ||
print(f"Failed to start server: {e}") | ||
|
||
def setup_new_link(self): | ||
'''Setup a new MAVLink connection''' | ||
self.module('link').cmd_link(['add', self.link]) | ||
print(f"Added new MAVLink connection: {self.link}") | ||
|
||
def unload(self): | ||
'''Unload module''' | ||
# Stop the web server | ||
if hasattr(self, 'web_server'): | ||
self.web_server.shutdown() | ||
self.web_server.server_close() | ||
|
||
# Remove the WebSocket link | ||
self.module('link').cmd_link(['remove', self.link]) | ||
print(f"Removed MAVLink connection: {self.link}") | ||
|
||
def init(mpstate): | ||
'''Initialize module''' | ||
return Cockpit(mpstate) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.expanded-alerts-bar[invisible][data-v-d73840a1]{display:none} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.main[data-v-64737875]{width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;position:relative} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.battery-icon{font-size:2.25rem;line-height:2.25rem} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.