feat: add osc scaffolding
This commit is contained in:
@@ -31,7 +31,7 @@ RUN cp /psn-py/psn$(python3-config --extension-suffix) /output
|
|||||||
|
|
||||||
FROM alpine:3.20 AS final
|
FROM alpine:3.20 AS final
|
||||||
|
|
||||||
RUN apk add --no-cache python3 py3-aiohttp
|
RUN apk add --no-cache python3 py3-aiohttp py3-python-osc
|
||||||
|
|
||||||
|
|
||||||
COPY --from=backend /output /backend/psn.so
|
COPY --from=backend /output /backend/psn.so
|
||||||
|
|||||||
@@ -7,12 +7,15 @@ import weakref
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
import psn
|
import psn
|
||||||
|
from pythonosc.osc_server import AsyncIOOSCUDPServer
|
||||||
|
from pythonosc.dispatcher import Dispatcher
|
||||||
from aiohttp import web, WSCloseCode
|
from aiohttp import web, WSCloseCode
|
||||||
|
|
||||||
PSN_DEFAULT_UDP_PORT = 56565
|
PSN_DEFAULT_UDP_PORT = 56565
|
||||||
PSN_DEFAULT_UDP_MCAST_ADDRESS = "236.10.10.10"
|
PSN_DEFAULT_UDP_MCAST_ADDRESS = "236.10.10.10"
|
||||||
PORT = 8000
|
WEB_SERVER_PORT = 8000
|
||||||
IP = "0.0.0.0"
|
IP = "0.0.0.0"
|
||||||
|
OSC_SERVER_PORT = 6969
|
||||||
NUM_TRACKERS = 3
|
NUM_TRACKERS = 3
|
||||||
|
|
||||||
|
|
||||||
@@ -129,6 +132,19 @@ async def background_tasks(app: web.Application):
|
|||||||
await app["broadcast_psn_data"]
|
await app["broadcast_psn_data"]
|
||||||
|
|
||||||
|
|
||||||
|
def filter_handler(address, *args) -> None:
|
||||||
|
logging.debug(f"{address}: {args}")
|
||||||
|
|
||||||
|
async def receive_osc_data(app):
|
||||||
|
dispatcher = Dispatcher()
|
||||||
|
dispatcher.map("/Tracker*", filter_handler)
|
||||||
|
server = AsyncIOOSCUDPServer((IP, OSC_SERVER_PORT), dispatcher, asyncio.get_event_loop())
|
||||||
|
transport, protocol = await server.create_serve_endpoint()
|
||||||
|
app["osc_transport"] = transport
|
||||||
|
yield
|
||||||
|
await transport.close()
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
app.router.add_get("/", handle_root)
|
app.router.add_get("/", handle_root)
|
||||||
@@ -145,6 +161,7 @@ def create_app():
|
|||||||
|
|
||||||
app.on_shutdown.append(on_shutdown)
|
app.on_shutdown.append(on_shutdown)
|
||||||
app.cleanup_ctx.append(background_tasks)
|
app.cleanup_ctx.append(background_tasks)
|
||||||
|
app.cleanup_ctx.append(receive_osc_data)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
@@ -152,4 +169,4 @@ def create_app():
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
app = create_app()
|
app = create_app()
|
||||||
web.run_app(app, host=IP, port=PORT)
|
web.run_app(app, host=IP, port=WEB_SERVER_PORT)
|
||||||
|
|||||||
Reference in New Issue
Block a user