mirror of
https://github.com/okalachev/flix.git
synced 2025-07-29 12:28:59 +00:00
Add proxy for running alongside QGroundControl
This commit is contained in:
parent
03600dbaba
commit
ff39ffa46c
@ -53,9 +53,9 @@ class Flix:
|
|||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.EADDRINUSE:
|
if e.errno != errno.EADDRINUSE:
|
||||||
raise
|
raise
|
||||||
# Port busy with QGC - using forwarding
|
# Port busy - using proxy
|
||||||
logger.debug('Listening on port 14445 (QGC forwarding)')
|
logger.debug('Listening on port 14560 (proxy)')
|
||||||
self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14445', source_system=254) # type: ignore
|
self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14555', source_system=254) # type: ignore
|
||||||
self.connection.target_system = mav_id
|
self.connection.target_system = mav_id
|
||||||
self.mavlink: mavlink.MAVLink = self.connection.mav
|
self.mavlink: mavlink.MAVLink = self.connection.mav
|
||||||
self._event_listeners: dict[str, List[Callable[..., Any]]] = {}
|
self._event_listeners: dict[str, List[Callable[..., Any]]] = {}
|
||||||
|
37
tools/pyflix/proxy.py
Executable file
37
tools/pyflix/proxy.py
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""Proxy for running pyflix library alongside QGroundControl app."""
|
||||||
|
|
||||||
|
import socket
|
||||||
|
|
||||||
|
LOCAL = ('0.0.0.0', 14550) # from Flix
|
||||||
|
TARGETS = (
|
||||||
|
('127.0.0.1', 14560), # to QGroundControl
|
||||||
|
('127.0.0.1', 14555), # to pyflix
|
||||||
|
)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
sock.bind(LOCAL)
|
||||||
|
|
||||||
|
source_addr = None
|
||||||
|
packets = 0
|
||||||
|
|
||||||
|
print('Proxy started - run QGroundControl')
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data, addr = sock.recvfrom(1024) # read entire UDP packet
|
||||||
|
if addr in TARGETS: # packet from target
|
||||||
|
if source_addr is None:
|
||||||
|
continue
|
||||||
|
sock.sendto(data, source_addr)
|
||||||
|
else: # packet from source
|
||||||
|
source_addr = addr
|
||||||
|
for target in TARGETS:
|
||||||
|
sock.sendto(data, target)
|
||||||
|
|
||||||
|
packets += 1
|
||||||
|
print(f'\rPackets: {packets}', end='')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@ -10,6 +10,9 @@ dependencies = [
|
|||||||
"pymavlink",
|
"pymavlink",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
flixproxy = "pyflix.proxy:main"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["setuptools>=61.0"]
|
requires = ["setuptools>=61.0"]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "setuptools.build_meta"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user