mirror of
https://github.com/AbaTekNTNU/followspot-psn.git
synced 2025-12-06 13:54:58 +00:00
Noe
This commit is contained in:
@@ -1,18 +1,20 @@
|
|||||||
import psn
|
|
||||||
import time
|
|
||||||
import socket
|
|
||||||
import json
|
|
||||||
from aiohttp import web
|
|
||||||
import logging
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import socket
|
||||||
|
import time
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
import psn
|
||||||
|
from aiohttp import web
|
||||||
|
|
||||||
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
|
PORT = 8000
|
||||||
IP = "0.0.0.0"
|
IP = "0.0.0.0"
|
||||||
NUM_TRACKERS = 3
|
NUM_TRACKERS = 3
|
||||||
|
|
||||||
|
|
||||||
# Internal state is a list of TrackerData objects
|
# Internal state is a list of TrackerData objects
|
||||||
@dataclass
|
@dataclass
|
||||||
class TrackerData:
|
class TrackerData:
|
||||||
@@ -20,7 +22,6 @@ class TrackerData:
|
|||||||
x: float
|
x: float
|
||||||
y: float
|
y: float
|
||||||
|
|
||||||
|
|
||||||
def to_tracker(self):
|
def to_tracker(self):
|
||||||
tracker = psn.Tracker(self.id, f"Tracker {self.id}")
|
tracker = psn.Tracker(self.id, f"Tracker {self.id}")
|
||||||
x, y = pic_to_scene_coords(self.x, self.y)
|
x, y = pic_to_scene_coords(self.x, self.y)
|
||||||
@@ -52,9 +53,11 @@ def pic_to_scene_coords(x, y):
|
|||||||
return x / 200, -y / 200
|
return x / 200, -y / 200
|
||||||
|
|
||||||
|
|
||||||
async def update_all_clients(app: web.Application):
|
async def update_all_clients(app: web.Application, ws: web.WebSocketResponse = None):
|
||||||
for ws in app["ws_clients"]:
|
for ws_send in app["ws_clients"]:
|
||||||
await ws.send_str(trackers_to_json(app))
|
if ws_send == ws:
|
||||||
|
continue
|
||||||
|
await ws_send.send_str(trackers_to_json(app))
|
||||||
|
|
||||||
|
|
||||||
async def handle_websocket(request):
|
async def handle_websocket(request):
|
||||||
@@ -72,7 +75,7 @@ async def handle_websocket(request):
|
|||||||
if msg.type == web.WSMsgType.TEXT:
|
if msg.type == web.WSMsgType.TEXT:
|
||||||
# Each message is a single tracker object
|
# Each message is a single tracker object
|
||||||
update_tracker(msg.data, request.app)
|
update_tracker(msg.data, request.app)
|
||||||
await update_all_clients(request.app)
|
await update_all_clients(request.app, ws)
|
||||||
|
|
||||||
elif msg.type == web.WSMsgType.ERROR:
|
elif msg.type == web.WSMsgType.ERROR:
|
||||||
logging.error("ws connection closed with exception %s" % ws.exception())
|
logging.error("ws connection closed with exception %s" % ws.exception())
|
||||||
@@ -101,7 +104,9 @@ async def broadcast_psn_data(app):
|
|||||||
trackers[tracker_data.id] = tracker_data.to_tracker()
|
trackers[tracker_data.id] = tracker_data.to_tracker()
|
||||||
packets = encoder.encode_data(trackers, get_elapsed_time_ms())
|
packets = encoder.encode_data(trackers, get_elapsed_time_ms())
|
||||||
for packet in packets:
|
for packet in packets:
|
||||||
app["sock"].sendto(packet, (PSN_DEFAULT_UDP_MCAST_ADDRESS, PSN_DEFAULT_UDP_PORT))
|
app["sock"].sendto(
|
||||||
|
packet, (PSN_DEFAULT_UDP_MCAST_ADDRESS, PSN_DEFAULT_UDP_PORT)
|
||||||
|
)
|
||||||
await asyncio.sleep(0.033) # ~30fps
|
await asyncio.sleep(0.033) # ~30fps
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
<img src="/bg.png" alt="" bind:this={image} class="scale-50" />
|
<img src="/scene_drawing.png" alt="" bind:this={image} class="scale-50" />
|
||||||
<div
|
<div
|
||||||
bind:this={parent}
|
bind:this={parent}
|
||||||
class="absolute inset-0 border border-red-500"
|
class="absolute inset-0 border border-red-500"
|
||||||
|
|||||||
Reference in New Issue
Block a user