From f925cede6d60b16291dd5d46ce49fe8cc13b1a1c Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Fri, 3 Jan 2025 14:31:25 +0000 Subject: [PATCH] Add the ability to export to an IBT file --- irsdk.go | 33 +++++++++++++++++++++++++-------- variables.go | 6 ++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/irsdk.go b/irsdk.go index dfb10aa..cddbbb0 100644 --- a/irsdk.go +++ b/irsdk.go @@ -3,12 +3,14 @@ package goirsdk import ( "fmt" - // "os" + "log" + "os" + // "os" "io" // "log" // "time" - // conv "ibtReader/conversions" + // conv "ibtReader/conversions" "github.com/ESilva15/goirsdk/winutils" ) @@ -26,12 +28,13 @@ type Reader interface { // IBT struct will hold the relevant data for a given IBT file type IBT struct { - File Reader // Source of the data - Headers *TelemetryHeaders // IBT file Headers - SubHeaders *DiskSubHeader // IBT file Sub Headers - SessionInfo *SessionInfoYAML // IBT file Session Info - Vars *TelemetryVars // Vars will hold the telemetry data - winUtils *winutils.IRacingWinUtils // WinUtils gives access to the system utilities + File Reader // Source of the data + FileToExport string // If set, it will export the IBT data to the file + Headers *TelemetryHeaders // IBT file Headers + SubHeaders *DiskSubHeader // IBT file Sub Headers + SessionInfo *SessionInfoYAML // IBT file Session Info + Vars *TelemetryVars // Vars will hold the telemetry data + winUtils *winutils.IRacingWinUtils // WinUtils gives access to the system utilities } func (i *IBT) IsConnected() bool { @@ -47,6 +50,20 @@ func (i *IBT) IsConnected() bool { return false } +func (i *IBT) ExportToIBT(filepath string) { + rbuf := make([]byte, fileMapSize) + + _, err := i.File.ReadAt(rbuf, 0) + if err != nil { + log.Fatal(err) + } + + err = os.WriteFile(filepath, rbuf, 0644) + if err != nil { + log.Fatal(err) + } +} + // Init serves to initialize and get a hold of a IBT struct func Init(f Reader) (*IBT, error) { // Read the header of the file diff --git a/variables.go b/variables.go index 3847f86..8119329 100644 --- a/variables.go +++ b/variables.go @@ -226,5 +226,11 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) { i.Vars.Tick++ } + // Make this happen in a different thread, or have this send to a queue that has a thread + // writing to a file + if i.FileToExport != "" { + i.ExportToIBT(i.FileToExport) + } + return Running, nil }