SVappsLAB.iRacingTelemetrySDK 0.7.0

Prefix Reserved
dotnet add package SVappsLAB.iRacingTelemetrySDK --version 0.7.0                
NuGet\Install-Package SVappsLAB.iRacingTelemetrySDK -Version 0.7.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SVappsLAB.iRacingTelemetrySDK" Version="0.7.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SVappsLAB.iRacingTelemetrySDK --version 0.7.0                
#r "nuget: SVappsLAB.iRacingTelemetrySDK, 0.7.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SVappsLAB.iRacingTelemetrySDK as a Cake Addin
#addin nuget:?package=SVappsLAB.iRacingTelemetrySDK&version=0.7.0

// Install SVappsLAB.iRacingTelemetrySDK as a Cake Tool
#tool nuget:?package=SVappsLAB.iRacingTelemetrySDK&version=0.7.0                

iRacingTelemetrySDK

iRacingTelemetrySDK is a .Net SDK tailored for C# developers aiming to incorporate telemetry data from the iRacing simulator into their software projects.

Features

  • Live Telemetry Data: facilitates easy retrieval of telemetry information generated during iRacing sessions, including vehicle speed, engine RPM, tire temperatures, and more.

  • Playback of saved IBT Telemetry Data: In addition to live data access, the SDK can read previously saved iRacing IBT files and play them back as if it were live data, using the same API. This allows you to analyze and process historical telemetry data, the same way you would with live data.

  • Strongly Typed Telemetry Data: Source Generation is used to create strongly typed iRacing variables, such as Floats (speed, rpm) and Enums (track surface, pit service state).

  • Optimized Performance: The SDK uses techniques such as asynchronous Task's, ref struct's and ReadOnlySpan's to minimize memory allocations and maximize performance. When processing IBT files for example, the SDK is able to process 1 hour of saved telemetry data in under 1/2 second. A rate of over 300,000 telemetry records/sec.

Telemetry Variables

The iRacing simulator generates extensive telemetry data. This SDK lets you select which telemetry data you want to track and generates a strongly-typed struct with named variables you can access directly in your project.

Availability

iRacing outputs different variables depending on the context. Some variables available in live sessions might not be available in offline IBT files, and vice versa.

To check variable availability, use the ./Samples/DumpVariables_DumpSessionInfo utility. This will generate a CSV file listing available variables and a YAML file with complete session info.

Once you know what variables are available and you have the list of which ones you want to use, you're ready to start using the SDK.

Getting Started

To incorporate iRacingTelemetrySDK into your projects, follow these steps:

  1. Install the Package: Add the iRacingTelemetrySDK NuGet package to your project using your preferred package manager.

    dotnet add package SVappsLAB.iRacingTelemetrySDK
    
  2. Add the RequiredTelemetryVars attribute to the main class of your project

    The attribute takes an array of strings. The string values, are the name of the iRacing telemetry variables you want to use in your program.

    // these are the telemetry variables we want to track
    [RequiredTelemetryVars(["isOnTrackCar", "rpm", "speed", "PlayerTrackSurface"])]
    
    internal class Program
    {
      ...
    }
    

    A source generator will be leveraged to create a new .Net TelemetryData type you can use in your code. For the attribute above, the created type will look like

    public record struct TelemetryData(Boolean IsOnTrackCar,Single RPM,Single Speed, irsdk_TrkLoc PlayerTrackSurface);
    
  3. Create an instance of the TelemetryClient

    The TelemetryClient runs in one of two modes: Live or IBT file playback.

    For live telemetry, you only need to provide a logger.

     // live telemetry
     using var tc = TelemetryClient<TelemetryData>.Create(logger);
    

    For IBT playback, provide the path to the IBT file and an optional playback speed multiplier. The speed multiplier will speed up or slow down the playback of the IBT file.<br/> A speed of 1 will play the IBT file at the normal speed iRacing output the file (60 records/sec). A speed of 20 will playback the file at 20x speed (20*60=1200 records/rec).<br/> To play the file at maximum speed, use int.MaxValue as the multiplier value.

     // process the IBT file at 10x speed
    var ibtOptions = new IBTOptions(@"C:\path\to\file.ibt", 10);
     using var tc = TelemetryClient<TelemetryData>.Create(logger, ibtOptions);
    
  4. Add an event handler

    The event handler will be called with the latest telemetry data.

    // event handler
    void OnTelemetryUpdate(object? _sender, TelemetryData e)
    {
        // do something with the telemetry data
        logger.LogInformation("rpm: {rpm}, speed: {speed}, track surface: {trksuf}", e.RPM, e.Speed, e.PlayerTrackSurface);
    }
    
  5. Monitor for telemetry data changes

    Once monitoring is initiated, the events will fire and your event handlers will be called.<br> Monitoring is stopped, when the CancellationToken is cancelled, or the when the end-of-file is reached when processing a IBT file.

    CancellationTokenSource cts = new new CancellationTokenSource();
    
    // start monitoring the telemetry
    await tc.Monitor(cts.Token);
    

Samples

See ./Samples/README.md for a list of example projects using the SDK

Event Sequence Diagram

The following shows how the events are

sequenceDiagram
    participant C as Client
    create participant S as SDK

    C--)S: created
    C->>S: startup()
 
    create participant R as monitoring telemetry
    S--)R: 
    note over R: events start to fire
    activate R
    R-->>C: EVENT: "connected"
 
    loop sessionInfo
        note right of S: when sessionInfo changes
        R-->>C: EVENT: "sessionInfo"
    end
 
    loop telemetry
        note right of S: when telemetry updates
        R-->>C: EVENT: "telemetry"
    end
 
    R-->C: EVENT: "disconnected"
    C->>S: shutdown()
    deactivate R
    note over R: events stop
    destroy R
 
    R--)S: 
    destroy S
    C--)S: destroyed

License

This project is licensed under the Apache License. Refer to the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.7.0 86 12/8/2024
0.6.7 90 10/13/2024
0.6.5 88 9/28/2024
0.6.3 107 9/17/2024
0.6.2 114 9/14/2024
0.6.1 112 9/9/2024
0.6.0 119 8/27/2024
0.5.0 138 8/17/2024
0.4.8 108 7/20/2024
0.1.7-beta 110 7/20/2024 0.1.7-beta is deprecated because it is no longer maintained.
0.1.6-beta 104 7/20/2024 0.1.6-beta is deprecated because it is no longer maintained.