Skip to content

Commit

Permalink
modules: create Cockpit module
Browse files Browse the repository at this point in the history
  • Loading branch information
Williangalvani committed Nov 25, 2024
1 parent 888e97f commit bf49cf0
Show file tree
Hide file tree
Showing 87 changed files with 2,986 additions and 0 deletions.
71 changes: 71 additions & 0 deletions MAVProxy/modules/mavproxy_cockpit/__init__.py
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)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

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.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

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.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bf49cf0

Please sign in to comment.