feat: TurboSu initial release - racing telemetry dashboard
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"id": "f1_24",
|
||||
"name": "F1 24",
|
||||
"parser_type": "f1",
|
||||
"telemetry_format": "f124",
|
||||
"description": "F1 24 UDP 遥测数据输出",
|
||||
"author": "Yei.J. (AskaEth)",
|
||||
"version": "1.0.0",
|
||||
"default_port": 20777
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import struct
|
||||
import time
|
||||
from server.telemetry.data import TelemetryData
|
||||
|
||||
|
||||
def get_parser():
|
||||
return F124Parser()
|
||||
|
||||
|
||||
class F124Parser:
|
||||
def game_id(self) -> str:
|
||||
return "f1_24"
|
||||
|
||||
def parse(self, data: bytes, addr: tuple) -> TelemetryData:
|
||||
td = TelemetryData(game_id="f1_24", timestamp=time.time())
|
||||
td.raw = {"raw_hex": data.hex(), "length": len(data), "addr": f"{addr[0]}:{addr[1]}"}
|
||||
|
||||
if len(data) < 1289:
|
||||
return td
|
||||
|
||||
try:
|
||||
td.speed_kmh = struct.unpack_from("<f", data, 37)[0]
|
||||
td.speed_mph = td.speed_kmh * 0.621371
|
||||
td.rpm = struct.unpack_from("<H", data, 41)[0]
|
||||
td.max_rpm = struct.unpack_from("<H", data, 43)[0]
|
||||
td.gear = struct.unpack_from("<B", data, 46)[0] & 0x0F
|
||||
td.throttle = struct.unpack_from("<f", data, 47)[0]
|
||||
td.brake = struct.unpack_from("<f", data, 55)[0]
|
||||
td.steering = struct.unpack_from("<B", data, 45)[0] / 127.0
|
||||
td.lap_number = struct.unpack_from("<B", data, 262)[0]
|
||||
td.lap_time = struct.unpack_from("<f", data, 63)[0]
|
||||
td.best_lap = struct.unpack_from("<f", data, 268)[0]
|
||||
td.fuel = struct.unpack_from("<f", data, 51)[0]
|
||||
except struct.error:
|
||||
pass
|
||||
|
||||
return td
|
||||
Reference in New Issue
Block a user