feat: TurboSu initial release - racing telemetry dashboard
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import struct
|
||||
import time
|
||||
from server.telemetry.data import TelemetryData
|
||||
|
||||
|
||||
def get_parser():
|
||||
return ACCParser()
|
||||
|
||||
|
||||
class ACCParser:
|
||||
def game_id(self) -> str:
|
||||
return "assetto_corsa_competizione"
|
||||
|
||||
def parse(self, data: bytes, addr: tuple) -> TelemetryData:
|
||||
td = TelemetryData(game_id="assetto_corsa_competizione", timestamp=time.time())
|
||||
td.raw = {"raw_hex": data.hex(), "length": len(data), "addr": f"{addr[0]}:{addr[1]}"}
|
||||
|
||||
if len(data) < 200:
|
||||
return td
|
||||
|
||||
try:
|
||||
td.speed_kmh = struct.unpack_from("<f", data, 0)[0]
|
||||
td.speed_mph = td.speed_kmh * 0.621371
|
||||
td.rpm = struct.unpack_from("<f", data, 4)[0]
|
||||
td.max_rpm = struct.unpack_from("<f", data, 8)[0]
|
||||
td.gear = struct.unpack_from("<B", data, 12)[0]
|
||||
td.throttle = struct.unpack_from("<f", data, 16)[0]
|
||||
td.brake = struct.unpack_from("<f", data, 20)[0]
|
||||
td.steering = struct.unpack_from("<f", data, 24)[0]
|
||||
td.fuel = struct.unpack_from("<f", data, 28)[0]
|
||||
except struct.error:
|
||||
pass
|
||||
|
||||
return td
|
||||
Reference in New Issue
Block a user