Package: gt-telem
Gran Turismo TelemetryPython library for interfacing with Polyphony Digital's telemetry service for motion rigs in GT6/GTS/GT7 (maybe older?)FeaturesPlaystation IP Address discoveryAsynchronous callbacksGame event observerTelemetry as an object or a dictionaryInstallationInstall with pip:pip install gt-telemUsageGetting telemetry is fairly straightforward. Here's a simple example that runs the client on a separate thread:fromgt_telemimportTurismoClientfromtimeimportsleeptc=TurismoClient()tc.start()foriinrange(10):sleep(1)print(tc.telemetry.position)tc.stop()If you're working inside of an asynchronous framework, use run_async()fromgt_telemimportTurismoClientclassMyAsyncClass:def__init__(self,tc:TurismoClient):self.tc=tcself.cancel_tkn:asyncio.Event=Noneasyncdefstart_telem(self):awaitself.tc.run_async(self.cancel_tkn)Otherwise run like this if you only care for callbacks:importjsonfromgt_telemimportTurismoClientfromgt_telem.modelsimportTelemetryasyncdefprint_telem(t:Telemetry):print(json.dumps(t.as_dict,indent=4))tc=TurismoClient()tc.register_callback(print_telem)tc.run()#blocking callThe full list of telemetry is availablehere.EventsThe following events are currently supported:gt_telem.events.GameEventson_running - The game has started/is runningon_in_game_menu - Outside of a race or track screenon_at_track - Player has entered a track screenon_in_race - Fired when the simulation starts, before player controlon_paused - When the player pauses the raceon_race_end - Fires when a player leaves the simulationgt_telem.events.RaceEventson_race_start - Fired at the beginning of Lap 1on_race_finish - Fired when the last lap is completed (checkered flag)on_lap_change - Fires when the lap counter changes (including 0->1)on_best_lap_time - A new best lap is seton_last_lap_time - A new last lap time is availablegt_telem.events.DriverEventson_gear_change - A gear has changedon_flash_lights - High Beams have been activatedon_handbrake - Player has utilized handbrakeon_suggested_gear - Fires when the game suggests a gear changeon_tcs - Traction Control System activatedon_asm - Active Stability Management activatedon_rev_limit - Engine revs exceed thresholdon_brake - Player depresses brakeon_throttle - Player depresses throttleon_shift_light_low - Engine revs entered lower bound for shift lighton_shift_light_high - Engine revs exceed upper bound for shift lightExample using EventsHere's a more complex example of a telemetry recorder that hooks into race start, pause, and race end:fromgt_telemimportTurismoClientfromgt_telem.eventsimportGameEventsfromgt_telem.errors.playstation_errorsimport*classMySimpleTelemetryRecorder():def__init__(self,tc:TurismoClient):self.tc=tcself.storage=[]defstart(self):self.tc.register_callback(MySimpleTelemetryRecorder.receive_telem,[self])defstop(self):self.tc.deregister_callback(MySimpleTelemetryRecorder.receive_telem)# save self.storage somewhere@staticmethodasyncdefreceive_telem(t,context):context.storage.append(t)print(f"{t.engine_rpm}RPM -{t.boost_pressure}kPa")print(f"Best:{t.best_lap_time}\tLast:{t.last_lap_time}")if__name__=="__main__":try:tc=TurismoClient()exceptPlayStatonOnStandbyErrorase:print("Turn the playstation on")print(e)exit()exceptPlayStationNotFoundErrorase:print("Maybe I'm on the wrong network")print(e)exit()ge=GameEvents(tc)mstr=MySimpleTelemetryRecorder(tc)ge.on_in_race.append(mstr.start)ge.on_race_end.append(mstr.stop)ge.on_paused.append(mstr.stop)print("Listening for telemetry. CTRL+C to stop")tc.run()TurismoClient.run()is a blocking call, but does shut down gracefully when a keyboard interrupt is issued. It also accepts a cancellation token.Advanced ExampleSeethis jupyter notebookthat displays a live race view and how to properly pass a token to shut down gracefully.