Merge branch 'master' into unittesting
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# About
|
||||
This project will be able to parse `.ibt` files, read live data from races and
|
||||
broadcast messages to the service. Its still not very mature at all, but after
|
||||
this commit I will turn it into a package instead and give it a stable API.
|
||||
Will also put some examples then.
|
||||
|
||||
|
||||
## The SDK
|
||||
I used various sources to develop and understand how `iRacing` works, and learn
|
||||
a lot with it. Once I have matured this project a bit I will document its
|
||||
inner workings too.
|
||||
|
||||
|
||||
## SharedMem
|
||||
I vendored in the code from [hidez8891/shm](https://github.com/hidez8891/shm)
|
||||
since the repo has been archived. I took the opportunity to update some of its
|
||||
code.
|
||||
+136
-1
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package goirsdk
|
||||
|
||||
type Msg struct {
|
||||
Cmd int
|
||||
@@ -115,3 +115,138 @@ const (
|
||||
const (
|
||||
// CamNose
|
||||
)
|
||||
|
||||
|
||||
// Some other constants that I need to get trough
|
||||
// // bit fields
|
||||
// enum irsdk_EngineWarnings
|
||||
// {
|
||||
// irsdk_waterTempWarning = 0x01,
|
||||
// irsdk_fuelPressureWarning = 0x02,
|
||||
// irsdk_oilPressureWarning = 0x04,
|
||||
// irsdk_engineStalled = 0x08,
|
||||
// irsdk_pitSpeedLimiter = 0x10,
|
||||
// irsdk_revLimiterActive = 0x20,
|
||||
// };
|
||||
//
|
||||
// // global flags
|
||||
// enum irsdk_Flags
|
||||
// {
|
||||
// // global flags
|
||||
// irsdk_checkered = 0x00000001,
|
||||
// irsdk_white = 0x00000002,
|
||||
// irsdk_green = 0x00000004,
|
||||
// irsdk_yellow = 0x00000008,
|
||||
// irsdk_red = 0x00000010,
|
||||
// irsdk_blue = 0x00000020,
|
||||
// irsdk_debris = 0x00000040,
|
||||
// irsdk_crossed = 0x00000080,
|
||||
// irsdk_yellowWaving = 0x00000100,
|
||||
// irsdk_oneLapToGreen = 0x00000200,
|
||||
// irsdk_greenHeld = 0x00000400,
|
||||
// irsdk_tenToGo = 0x00000800,
|
||||
// irsdk_fiveToGo = 0x00001000,
|
||||
// irsdk_randomWaving = 0x00002000,
|
||||
// irsdk_caution = 0x00004000,
|
||||
// irsdk_cautionWaving = 0x00008000,
|
||||
//
|
||||
// // drivers black flags
|
||||
// irsdk_black = 0x00010000,
|
||||
// irsdk_disqualify = 0x00020000,
|
||||
// irsdk_servicible = 0x00040000, // car is allowed service (not a flag)
|
||||
// irsdk_furled = 0x00080000,
|
||||
// irsdk_repair = 0x00100000,
|
||||
//
|
||||
// // start lights
|
||||
// irsdk_startHidden = 0x10000000,
|
||||
// irsdk_startReady = 0x20000000,
|
||||
// irsdk_startSet = 0x40000000,
|
||||
// irsdk_startGo = 0x80000000,
|
||||
// };
|
||||
//
|
||||
//
|
||||
// // status
|
||||
// enum irsdk_TrkLoc
|
||||
// {
|
||||
// irsdk_NotInWorld = -1,
|
||||
// irsdk_OffTrack,
|
||||
// irsdk_InPitStall,
|
||||
// irsdk_AproachingPits,
|
||||
// irsdk_OnTrack
|
||||
// };
|
||||
//
|
||||
// enum irsdk_TrkSurf
|
||||
// {
|
||||
// irsdk_SurfaceNotInWorld = -1,
|
||||
// irsdk_UndefinedMaterial = 0,
|
||||
//
|
||||
// irsdk_Asphalt1Material,
|
||||
// irsdk_Asphalt2Material,
|
||||
// irsdk_Asphalt3Material,
|
||||
// irsdk_Asphalt4Material,
|
||||
// irsdk_Concrete1Material,
|
||||
// irsdk_Concrete2Material,
|
||||
// irsdk_RacingDirt1Material,
|
||||
// irsdk_RacingDirt2Material,
|
||||
// irsdk_Paint1Material,
|
||||
// irsdk_Paint2Material,
|
||||
// irsdk_Rumble1Material,
|
||||
// irsdk_Rumble2Material,
|
||||
// irsdk_Rumble3Material,
|
||||
// irsdk_Rumble4Material,
|
||||
//
|
||||
// irsdk_Grass1Material,
|
||||
// irsdk_Grass2Material,
|
||||
// irsdk_Grass3Material,
|
||||
// irsdk_Grass4Material,
|
||||
// irsdk_Dirt1Material,
|
||||
// irsdk_Dirt2Material,
|
||||
// irsdk_Dirt3Material,
|
||||
// irsdk_Dirt4Material,
|
||||
// irsdk_SandMaterial,
|
||||
// irsdk_Gravel1Material,
|
||||
// irsdk_Gravel2Material,
|
||||
// irsdk_GrasscreteMaterial,
|
||||
// irsdk_AstroturfMaterial,
|
||||
// };
|
||||
//
|
||||
// enum irsdk_SessionState
|
||||
// {
|
||||
// irsdk_StateInvalid,
|
||||
// irsdk_StateGetInCar,
|
||||
// irsdk_StateWarmup,
|
||||
// irsdk_StateParadeLaps,
|
||||
// irsdk_StateRacing,
|
||||
// irsdk_StateCheckered,
|
||||
// irsdk_StateCoolDown
|
||||
// };
|
||||
//
|
||||
// enum irsdk_CameraState
|
||||
// {
|
||||
// irsdk_IsSessionScreen = 0x0001, // the camera tool can only be activated if viewing the session screen (out of car)
|
||||
// irsdk_IsScenicActive = 0x0002, // the scenic camera is active (no focus car)
|
||||
//
|
||||
// //these can be changed with a broadcast message
|
||||
// irsdk_CamToolActive = 0x0004,
|
||||
// irsdk_UIHidden = 0x0008,
|
||||
// irsdk_UseAutoShotSelection = 0x0010,
|
||||
// irsdk_UseTemporaryEdits = 0x0020,
|
||||
// irsdk_UseKeyAcceleration = 0x0040,
|
||||
// irsdk_UseKey10xAcceleration = 0x0080,
|
||||
// irsdk_UseMouseAimMode = 0x0100
|
||||
// };
|
||||
//
|
||||
// enum irsdk_PitSvFlags
|
||||
// {
|
||||
// irsdk_LFTireChange = 0x0001,
|
||||
// irsdk_RFTireChange = 0x0002,
|
||||
// irsdk_LRTireChange = 0x0004,
|
||||
// irsdk_RRTireChange = 0x0008,
|
||||
//
|
||||
// irsdk_FuelFill = 0x0010,
|
||||
// irsdk_WindshieldTearoff = 0x0020,
|
||||
// irsdk_FastRepair = 0x0040
|
||||
// };
|
||||
|
||||
//----
|
||||
//
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package goirsdk
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module ibtReader
|
||||
module github.com/ESilva15/goirsdk
|
||||
|
||||
go 1.23.2
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package goirsdk
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// Package IbtReader is all you need for you iRacing telemetry parsing
|
||||
package main
|
||||
// Package goirsdk is all you need for you iRacing telemetry parsing
|
||||
package goirsdk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
// "os"
|
||||
"io"
|
||||
"log"
|
||||
"time"
|
||||
// "log"
|
||||
// "time"
|
||||
|
||||
conv "ibtReader/conversions"
|
||||
"ibtReader/winutils"
|
||||
// conv "ibtReader/conversions"
|
||||
"github.com/ESilva15/goirsdk/winutils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -135,68 +135,68 @@ func (i *IBT) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("================== IBT FILE PARSER ==================")
|
||||
|
||||
file, err := os.Open(ibtFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open IBT file: %v", err)
|
||||
}
|
||||
|
||||
ibt, err := Init(file)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create irsdk instance: %v", err)
|
||||
}
|
||||
// fmt.Printf("%s\n", ibt.Headers.ToString())
|
||||
// fmt.Printf("%s\n", ibt.SubHeaders.ToString())
|
||||
// fmt.Printf("%s\n", ibt.SessionInfo.ToString())
|
||||
|
||||
// Display the human readable start date
|
||||
// unixStartDate := time.Unix(ibt.SubHeaders.StartDate, 0)
|
||||
// startDate := unixStartDate.Format("2006/01/02 15:04:05 -0700 MST")
|
||||
// fmt.Println("StartDate:", startDate)
|
||||
|
||||
// Display the human readable version of start time
|
||||
// unixStartTime := time.Unix(ibt.SubHeaders.StartDate+int64(ibt.SubHeaders.StartTime), 0)
|
||||
// startTime := unixStartTime.Format("2006/01/02 15:04:05 -0700 MST")
|
||||
// fmt.Println("StartTime:", startTime)
|
||||
|
||||
// Display the human readable version of end time
|
||||
// unixEndTime := time.Unix(ibt.SubHeaders.StartDate+int64(ibt.SubHeaders.EndTime), 0)
|
||||
// endTime := unixEndTime.Format("2006/01/02 15:04:05 -0700 MST")
|
||||
// fmt.Println("EndTime: ", endTime)
|
||||
|
||||
last := time.Now().UnixMilli()
|
||||
for {
|
||||
time.Sleep(time.Second / 60)
|
||||
res, err := ibt.Update(100 * time.Millisecond)
|
||||
if res == Unknown {
|
||||
log.Fatalf("Some unknown error occurred: %v\n", err)
|
||||
}
|
||||
|
||||
if res == Paused {
|
||||
fmt.Printf("\r \r")
|
||||
fmt.Println("GAME IS PAUSED")
|
||||
continue
|
||||
}
|
||||
|
||||
curTime := time.Now().UnixMilli()
|
||||
|
||||
if curTime-last > 250 {
|
||||
fmt.Printf(" \r")
|
||||
if val, ok := ibt.Vars.Vars["Speed"]; ok {
|
||||
fmt.Printf("\r%d %d", ibt.Vars.Tick/60, conv.MsToKph(val.Value.(float32)))
|
||||
} else {
|
||||
fmt.Printf("\r%d %s", ibt.Vars.Tick/60, "KEY DOESN'T EXIST")
|
||||
}
|
||||
}
|
||||
|
||||
if res == Ended {
|
||||
fmt.Println("\nEnd of file found...")
|
||||
break
|
||||
}
|
||||
}
|
||||
fmt.Printf("%d\n", ibt.Vars.Tick)
|
||||
|
||||
ibt.Close()
|
||||
}
|
||||
// func main() {
|
||||
// fmt.Println("================== IBT FILE PARSER ==================")
|
||||
//
|
||||
// file, err := os.Open(ibtFile)
|
||||
// if err != nil {
|
||||
// log.Fatalf("Failed to open IBT file: %v", err)
|
||||
// }
|
||||
//
|
||||
// ibt, err := Init(file)
|
||||
// if err != nil {
|
||||
// log.Fatalf("Failed to create irsdk instance: %v", err)
|
||||
// }
|
||||
// // fmt.Printf("%s\n", ibt.Headers.ToString())
|
||||
// // fmt.Printf("%s\n", ibt.SubHeaders.ToString())
|
||||
// // fmt.Printf("%s\n", ibt.SessionInfo.ToString())
|
||||
//
|
||||
// // Display the human readable start date
|
||||
// // unixStartDate := time.Unix(ibt.SubHeaders.StartDate, 0)
|
||||
// // startDate := unixStartDate.Format("2006/01/02 15:04:05 -0700 MST")
|
||||
// // fmt.Println("StartDate:", startDate)
|
||||
//
|
||||
// // Display the human readable version of start time
|
||||
// // unixStartTime := time.Unix(ibt.SubHeaders.StartDate+int64(ibt.SubHeaders.StartTime), 0)
|
||||
// // startTime := unixStartTime.Format("2006/01/02 15:04:05 -0700 MST")
|
||||
// // fmt.Println("StartTime:", startTime)
|
||||
//
|
||||
// // Display the human readable version of end time
|
||||
// // unixEndTime := time.Unix(ibt.SubHeaders.StartDate+int64(ibt.SubHeaders.EndTime), 0)
|
||||
// // endTime := unixEndTime.Format("2006/01/02 15:04:05 -0700 MST")
|
||||
// // fmt.Println("EndTime: ", endTime)
|
||||
//
|
||||
// last := time.Now().UnixMilli()
|
||||
// for {
|
||||
// time.Sleep(time.Second / 60)
|
||||
// res, err := ibt.Update(100 * time.Millisecond)
|
||||
// if res == Unknown {
|
||||
// log.Fatalf("Some unknown error occurred: %v\n", err)
|
||||
// }
|
||||
//
|
||||
// if res == Paused {
|
||||
// fmt.Printf("\r \r")
|
||||
// fmt.Println("GAME IS PAUSED")
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// curTime := time.Now().UnixMilli()
|
||||
//
|
||||
// if curTime-last > 250 {
|
||||
// fmt.Printf(" \r")
|
||||
// if val, ok := ibt.Vars.Vars["Speed"]; ok {
|
||||
// fmt.Printf("\r%d %d", ibt.Vars.Tick/60, conv.MsToKph(val.Value.(float32)))
|
||||
// } else {
|
||||
// fmt.Printf("\r%d %s", ibt.Vars.Tick/60, "KEY DOESN'T EXIST")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if res == Ended {
|
||||
// fmt.Println("\nEnd of file found...")
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// fmt.Printf("%d\n", ibt.Vars.Tick)
|
||||
//
|
||||
// ibt.Close()
|
||||
// }
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package goirsdk
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
Binary file not shown.
+4
-5
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package goirsdk
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -210,6 +210,9 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
||||
start := i.Headers.BufOffset + i.Vars.Tick*i.Headers.BufLen
|
||||
buf := make([]byte, i.Headers.BufLen)
|
||||
_, err := i.File.ReadAt(buf, int64(start))
|
||||
if err == io.EOF {
|
||||
return Ended, nil
|
||||
}
|
||||
if err != nil {
|
||||
return Unknown, err
|
||||
}
|
||||
@@ -219,10 +222,6 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
||||
log.Fatalf("What happened?\n%v\n", err)
|
||||
}
|
||||
|
||||
if err == io.EOF {
|
||||
return Ended, nil
|
||||
}
|
||||
|
||||
// This was previously in the read data method, but it probably fits here better
|
||||
i.Vars.Tick++
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
package winutils
|
||||
|
||||
import (
|
||||
"ibtReader/sharedMem"
|
||||
"github.com/ESilva15/goirsdk/sharedMem"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user