feat: TurboSu initial release - racing telemetry dashboard
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import struct
|
||||
import time
|
||||
from server.telemetry.data import TelemetryData
|
||||
|
||||
|
||||
def get_parser():
|
||||
return ForzaMotorsportParser()
|
||||
|
||||
|
||||
class ForzaMotorsportParser:
|
||||
def game_id(self) -> str:
|
||||
return "forza_motorsport"
|
||||
|
||||
def parse(self, data: bytes, addr: tuple) -> TelemetryData:
|
||||
td = TelemetryData(game_id="forza_motorsport", timestamp=time.time())
|
||||
td.raw = {"raw_hex": data.hex(), "length": len(data), "addr": f"{addr[0]}:{addr[1]}"}
|
||||
|
||||
if len(data) < 323:
|
||||
return td
|
||||
|
||||
try:
|
||||
td.rpm = struct.unpack_from("<f", data, 8)[0]
|
||||
td.max_rpm = struct.unpack_from("<f", data, 16)[0]
|
||||
td.horsepower = struct.unpack_from("<f", data, 12)[0]
|
||||
td.torque = struct.unpack_from("<f", data, 20)[0]
|
||||
td.boost = struct.unpack_from("<f", data, 308)[0]
|
||||
td.fuel = struct.unpack_from("<f", data, 312)[0]
|
||||
td.oil_temp = struct.unpack_from("<f", data, 316)[0]
|
||||
td.engine_temp = struct.unpack_from("<f", data, 320)[0]
|
||||
td.speed_mph = struct.unpack_from("<f", data, 244)[0]
|
||||
td.speed_kmh = td.speed_mph * 1.60934
|
||||
td.gear = struct.unpack_from("<B", data, 264)[0]
|
||||
td.best_lap = struct.unpack_from("<f", data, 268)[0]
|
||||
td.last_lap = struct.unpack_from("<f", data, 276)[0]
|
||||
td.lap_time = struct.unpack_from("<f", data, 284)[0]
|
||||
td.lap_number = struct.unpack_from("<H", data, 292)[0]
|
||||
td.position_x = struct.unpack_from("<f", data, 0)[0]
|
||||
td.position_y = struct.unpack_from("<f", data, 4)[0]
|
||||
td.position_z = struct.unpack_from("<f", data, 552)[0]
|
||||
td.throttle = struct.unpack_from("<f", data, 228)[0]
|
||||
td.brake = struct.unpack_from("<f", data, 232)[0]
|
||||
td.steering = struct.unpack_from("<f", data, 204)[0]
|
||||
td.clutch = struct.unpack_from("<f", data, 252)[0]
|
||||
td.handbrake = struct.unpack_from("<f", data, 256)[0]
|
||||
except struct.error:
|
||||
pass
|
||||
|
||||
return td
|
||||
Reference in New Issue
Block a user