From 4713fc80eb4eed83cfafb1c77d3ad9f13a1f20ec Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Wed, 15 Jan 2025 14:28:03 +0000 Subject: [PATCH] Not much here --- irsdk_test.go | 17 ++++++++++++----- variables.go | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/irsdk_test.go b/irsdk_test.go index f8f4d3c..344e0c3 100644 --- a/irsdk_test.go +++ b/irsdk_test.go @@ -14,7 +14,7 @@ func TestFunctionality(t *testing.T) { t.Fatal("Was unable to prepare telemetry file for testing.") } - i, err := Init(input, "", "") + i, _ := Init(input, "", "") defer i.Close() // Set up a loop to iterate our data @@ -32,14 +32,21 @@ func TestFunctionality(t *testing.T) { // Vehicle Movement data gathered from the names we can find on the // telemetry_docs.pdf file // - I wish to make this less verbose if possible - if _, ok := i.Vars.Vars["Gear"]; !ok { - log.Fatal("Field `Gear` doesn't exist") + if _, ok := i.Vars.Vars["CarIdxPosition"]; !ok { + log.Fatal("Field `CarIdxPosition` doesn't exist") } + driversPositions := i.Vars.Vars["CarIdxPosition"].Value.([]int) - gear := int32(i.Vars.Vars["Gear"].Value.(int)) + drivers := i.SessionInfo.DriverInfo.Drivers fmt.Printf("\033[?25l\033[2J\033[H") - fmt.Printf("Gear: %d\n", gear) + for k := range len(drivers) { + if drivers[k].CarIsPaceCar == 1 || drivers[k].IsSpectator == 1 { + continue + } + + fmt.Printf("[%d] [%d] %s\n", k, driversPositions[drivers[k].CarIdx], drivers[k].UserName) + } <-mainLoopTicker.C } diff --git a/variables.go b/variables.go index 35b5cce..12ec584 100644 --- a/variables.go +++ b/variables.go @@ -151,19 +151,19 @@ func (i *IBT) readData(buf []byte) error { case IRSDK_bool: v.Value = int(rbuf[0]) > 0 case IRSDK_int: - v.Value = int(binary.LittleEndian.Uint32(rbuf)) - fmt.Printf("%s\n", v.Name) - if v.Name == "CarIdxPosition" { - fmt.Printf("CarIdXPosition: %d\n", v.Count) - for entry := range v.Count { + if v.Count > 1 { + data := make([]int, v.Count) + for entry := 0; entry < int(v.Count); entry++ { entryOffset := v.Offset + int32(entry)*int32(VarTypes[int(v.Type)].Size) rbuf := buf[entryOffset : entryOffset+int32(VarTypes[int(v.Type)].Size)] - v := int(binary.LittleEndian.Uint32(rbuf)) - if v != 0 { - fmt.Printf("[%d] %v %v\n", entry, v, i.SessionInfo.DriverInfo.Drivers[entry].AbbrevName) - } - } - } + newValue := int(binary.LittleEndian.Uint32(rbuf)) + data[entry] = newValue + } + + v.Value = data + } else { + v.Value = int(binary.LittleEndian.Uint32(rbuf)) + } case IRSDK_bitField: v.Value = fmt.Sprintf("0x%x", int(binary.LittleEndian.Uint32(rbuf))) case IRSDK_float: