Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4762d854cd | ||
|
|
a82caa05a2 | ||
|
|
eed8c562b2 | ||
|
|
052f4582c9 | ||
|
|
7584b0ffcf | ||
|
|
7a210af58d | ||
|
|
78ec6a1e86 | ||
|
|
6070620713 | ||
|
|
1ad9dd4ab7 | ||
|
|
56c7081e8f | ||
|
|
ddfcd31b27 | ||
|
|
18233a87b1 | ||
|
|
b9c013ae2f | ||
|
|
5f18023f13 | ||
|
|
6b0283b206 | ||
|
|
a449ced75f | ||
|
|
9adc0a9456 | ||
|
|
76a091b076 | ||
|
|
b703933f08 | ||
|
|
6bcc0a1613 | ||
|
|
fa7f0b73ee | ||
|
|
c5ff9f95c9 | ||
|
|
4713fc80eb | ||
|
|
f102d74311 | ||
|
|
172fa4ff52 | ||
|
|
90a0321e9f | ||
|
|
6b595fabb1 | ||
|
|
4a56d253e5 | ||
|
|
a3418e0c95 | ||
|
|
45a0aa43aa | ||
|
|
38e7ea32cc | ||
|
|
bcbffdc7a2 | ||
|
|
2dc1771bb6 | ||
|
|
f925cede6d | ||
|
|
300c86190b | ||
|
|
5fa39f2935 | ||
|
|
423b8dcc22 | ||
|
|
b6aaaab8b2 | ||
|
|
0f33e19558 | ||
|
|
57d006c0e7 | ||
|
|
23a7efc37d | ||
|
|
7a1b128d6b | ||
|
|
2e1b811a80 | ||
|
|
6d03e46b44 | ||
|
|
f8149d687d | ||
|
|
dcfaec6d63 | ||
|
|
b66606fc6c | ||
|
|
e153a2efb1 | ||
|
|
b2a3e2f97c | ||
|
|
4c795c49c4 | ||
|
|
7ce4d0ed4b | ||
|
|
422d90e98a | ||
|
|
dbf30c1d4e | ||
|
|
78a2512410 | ||
|
|
d48a6fa24a | ||
|
|
2bc756a2f0 |
@@ -0,0 +1,2 @@
|
|||||||
|
coverage*
|
||||||
|
*.txt
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
test:
|
||||||
|
go test -coverprofile=coverage.out ./... -cover -bench=
|
||||||
|
go tool cover -html=coverage.out -o coverage.html
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
# TODO
|
||||||
|
- [x] Read live telemetry (from a live session or replay)
|
||||||
|
- [x] Read data from a stored `.ibt` file
|
||||||
|
- [x] Allow to export the data to an `.ibt` file
|
||||||
|
- [x] Allow to export the session info data to a `.yaml` file
|
||||||
|
- [ ] Make sure variables with multiple counts are correctly parsed and stored
|
||||||
|
- [ ] Correctly support and implement the bitFields data
|
||||||
|
- [ ] Add the message broadcasting system
|
||||||
|
- [ ] Explore a more convenient API for fetching the data for the SDK user. Also do some renamings
|
||||||
|
- [ ] Change the pattern in which the data is fetched from the telemetry and
|
||||||
|
how it is exported into `.ibt` files
|
||||||
|
|
||||||
|
|
||||||
|
# About
|
||||||
|
This project is a simple Go SDK for the popular iRacing racing simulator.
|
||||||
|
It has the capabilites to:
|
||||||
|
- Read live data (live session or replay)
|
||||||
|
- Read data from a `.ibt` telemetry file
|
||||||
|
|
||||||
|
It should run on Linux, MacOS and Windows. With the caveat that live sessions
|
||||||
|
only happen on Windows (that I know about), therefore Linux and MacOS can only
|
||||||
|
read data from telemetry files.
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
The SDK instance is created by calling `goirsdk.Init(Reader, exportTelem, exportYAML)`
|
||||||
|
- `Reader` is a variable that implements the interface:
|
||||||
|
```go
|
||||||
|
type Reader interface {
|
||||||
|
io.Reader
|
||||||
|
io.ReaderAt
|
||||||
|
io.ReadCloser
|
||||||
|
}
|
||||||
|
```
|
||||||
|
To read data from a `.ibt` file, the user should pass the `*os.File` of it, and
|
||||||
|
to read live telemetry the user should pass nil
|
||||||
|
|
||||||
|
- `exportTelem` should be an empty string if the user doesn't want to export
|
||||||
|
the data, otherwise pass a string with the path for the destination telemetry
|
||||||
|
file
|
||||||
|
|
||||||
|
- `exportYAML` is just like the exportTelem but for the session info `yaml` data
|
||||||
|
|
||||||
|
### Example
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/ESilva15/goirsdk"
|
||||||
|
)
|
||||||
|
|
||||||
|
func msToKph(v float32) int {
|
||||||
|
return int((3600 * v) / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Open the data source file
|
||||||
|
file, err := os.Open("/path/to/ibtFile")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to open IBT file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Instantiate our iRacing SDK instance
|
||||||
|
irsdk, err := goirsdk.Init(file, "", "")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create iRacing interface: %v", err)
|
||||||
|
}
|
||||||
|
defer irsdk.Close()
|
||||||
|
|
||||||
|
// Set up a loop to iterate our data
|
||||||
|
mainLoopTicker := time.NewTicker(time.Second / 60)
|
||||||
|
defer mainLoopTicker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
// Update the data that the SDK is holding with the next tick
|
||||||
|
_, err := irsdk.Update(100 * time.Millisecond)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("could not update data: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 := irsdk.Vars.Vars["Gear"]; !ok {
|
||||||
|
log.Fatal("Field `Gear` doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := irsdk.Vars.Vars["RPM"]; !ok {
|
||||||
|
log.Fatal("Field `RPM` doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := irsdk.Vars.Vars["Speed"]; !ok {
|
||||||
|
log.Fatal("Field `Speed` doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
gear := int32(irsdk.Vars.Vars["Gear"].Value.(int))
|
||||||
|
rpm := int32(irsdk.Vars.Vars["RPM"].Value.(float32))
|
||||||
|
speed := int32(msToKph(irsdk.Vars.Vars["Speed"].Value.(float32)))
|
||||||
|
|
||||||
|
fmt.Printf("\033[?25l\033[2J\033[H")
|
||||||
|
fmt.Printf("Gear: %d, RPM: %d, Speed: %d", gear, rpm, speed)
|
||||||
|
|
||||||
|
<-mainLoopTicker.C
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## 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.
|
||||||
+606
@@ -0,0 +1,606 @@
|
|||||||
|
package goirsdk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Msg struct {
|
||||||
|
Cmd int
|
||||||
|
P1 int32
|
||||||
|
P2 int32
|
||||||
|
P3 int32
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
DATAVALIDEVENTNAME string = "IRSDKDataValidEvent"
|
||||||
|
MEMMAPFILENAME = "IRSDKMemMapFileName"
|
||||||
|
SimStatusUrl string = "http://127.0.0.1:32034/get_sim_status?object=simStatus"
|
||||||
|
IRSDK_DATAVALIDEVENTNAME string = "Local\\" + DATAVALIDEVENTNAME
|
||||||
|
// IRSDK_DATAVALIDEVENTNAME string = DATAVALIDEVENTNAME
|
||||||
|
IRSDK_MEMMAPFILENAME string = "Local\\" + MEMMAPFILENAME
|
||||||
|
IRSDK_BROADCASTMSGNAME string = "IRSDK_BROADCASTMSG"
|
||||||
|
fileMapSize uint32 = 1164 * 1024
|
||||||
|
connTimeout int64 = 30
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
BroadcastCamSwitchPos int = 0 // car position, group, camera
|
||||||
|
BroadcastCamSwitchNum int = 1 // driver #, group, camera
|
||||||
|
BroadcastCamSetState int = 2 // irsdk_CameraState, unused, unused
|
||||||
|
BroadcastReplaySetPlaySpeed int = 3 // speed, slowMotion, unused
|
||||||
|
BroadcastReplaySetPlayPosition int = 4 // irsdk_RpyPosMode, Frame Number (high, low)
|
||||||
|
BroadcastReplaySearch int = 5 // irsdk_RpySrchMode, unused, unused
|
||||||
|
BroadcastReplaySetState int = 6 // irsdk_RpyStateMode, unused, unused
|
||||||
|
BroadcastReloadTextures int = 7 // irsdk_ReloadTexturesMode, carIdx, unused
|
||||||
|
BroadcastChatComand int = 8 // irsdk_ChatCommandMode, subCommand, unused
|
||||||
|
BroadcastPitCommand int = 9 // irsdk_PitCommandMode, parameter
|
||||||
|
BroadcastTelemCommand int = 10 // irsdk_TelemCommandMode, unused, unused
|
||||||
|
BroadcastFFBCommand int = 11 // irsdk_FFBCommandMode, value (float, high, low)
|
||||||
|
BroadcastReplaySearchSessionTime int = 12 // sessionNum, sessionTimeMS (high, low)
|
||||||
|
BroadcastLast int = 13 // unused placeholder
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ChatCommandMacro int = 0 // pass in a number from 1-15 representing the chat macro to launch
|
||||||
|
ChatCommandBeginChat int = 1 // Open up a new chat window
|
||||||
|
ChatCommandReply int = 2 // Reply to last private chat
|
||||||
|
ChatCommandCancel int = 3 // Close chat window
|
||||||
|
)
|
||||||
|
|
||||||
|
// this only works when the driver is in the car
|
||||||
|
const (
|
||||||
|
PitCommandClear int = 0 // Clear all pit checkboxes
|
||||||
|
PitCommandWS int = 1 // Clean the winshield, using one tear off
|
||||||
|
PitCommandFuel int = 2 // Add fuel, optionally specify the amount to add in liters or pass '0' to use existing amount
|
||||||
|
PitCommandLF int = 3 // Change the left front tire, optionally specifying the pressure in KPa or pass '0' to use existing pressure
|
||||||
|
PitCommandRF int = 4 // right front
|
||||||
|
PitCommandLR int = 5 // left rear
|
||||||
|
PitCommandRR int = 6 // right rear
|
||||||
|
PitCommandClearTires int = 7 // Clear tire pit checkboxes
|
||||||
|
PitCommandFR int = 8 // Request a fast repair
|
||||||
|
PitCommandClearWS int = 9 // Uncheck Clean the winshield checkbox
|
||||||
|
PitCommandClearFR int = 10 // Uncheck request a fast repair
|
||||||
|
PitCommandClearFuel int = 11 // Uncheck add fuel
|
||||||
|
)
|
||||||
|
|
||||||
|
// You can call this any time, but telemtry only records when driver is in there car
|
||||||
|
const (
|
||||||
|
TelemCommandStop int = 0 // Turn telemetry recording off
|
||||||
|
TelemCommandStart int = 1 // Turn telemetry recording on
|
||||||
|
TelemCommandRestart int = 2 // Write current file to disk and start a new one
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
RpyStateEraseTape int = 0 // clear any data in the replay tape
|
||||||
|
RpyStateLast int = 1 // unused place holder
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ReloadTexturesAll int = 0 // reload all textuers
|
||||||
|
ReloadTexturesCarIdx int = 1 // reload only textures for the specific carIdx
|
||||||
|
)
|
||||||
|
|
||||||
|
// Search replay tape for events
|
||||||
|
const (
|
||||||
|
RpySrchToStart int = 0
|
||||||
|
RpySrchToEnd int = 1
|
||||||
|
RpySrchPrevSession int = 2
|
||||||
|
RpySrchNextSession int = 3
|
||||||
|
RpySrchPrevLap int = 4
|
||||||
|
RpySrchNextLap int = 5
|
||||||
|
RpySrchPrevFrame int = 6
|
||||||
|
RpySrchNextFrame int = 7
|
||||||
|
RpySrchPrevIncident int = 8
|
||||||
|
RpySrchNextIncident int = 9
|
||||||
|
RpySrchLast int = 10 // unused placeholder
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
RpyPosBegin int = 0
|
||||||
|
RpyPosCurrent int = 1
|
||||||
|
RpyPosEnd int = 2
|
||||||
|
RpyPosLast int = 3 // unused placeholder
|
||||||
|
)
|
||||||
|
|
||||||
|
// You can call this any time
|
||||||
|
const (
|
||||||
|
FFBCommandMaxForce int = 0 // Set the maximum force when mapping steering torque force to direct input units (float in Nm)
|
||||||
|
FFBCommandLast int = 1 // unused placeholder
|
||||||
|
)
|
||||||
|
|
||||||
|
// irsdk_BroadcastCamSwitchPos or irsdk_BroadcastCamSwitchNum camera focus defines
|
||||||
|
// pass these in for the first parameter to select the 'focus at' types in the camera system.
|
||||||
|
const (
|
||||||
|
csFocusAtIncident int = -3
|
||||||
|
csFocusAtLeader int = -2
|
||||||
|
csFocusAtExiting int = -1
|
||||||
|
csFocusAtDriver int = 0 // ctFocusAtDriver + car number...
|
||||||
|
)
|
||||||
|
|
||||||
|
// StatusField - START
|
||||||
|
const (
|
||||||
|
irsdk_stConnected = 0x01
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i *IBT) SessionStatusConnected() bool {
|
||||||
|
return i.Headers.Status == irsdk_stConnected
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: move this away from here
|
||||||
|
// func (i *IBT) SessionTimedOut() bool {
|
||||||
|
// return sdk.lastValidData+connTimeout > time.Now().Unix()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// StatusField - END
|
||||||
|
|
||||||
|
// Camera positions
|
||||||
|
type bitfieldValue struct {
|
||||||
|
Value int
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// EngineWarnings - Start
|
||||||
|
// TODO: wtf
|
||||||
|
var (
|
||||||
|
irsdk_WaterTempWarning = 0x00000001
|
||||||
|
irsdk_FuelPressureWarning = 0x00000002
|
||||||
|
irsdk_OilPressureWarning = 0x00000004
|
||||||
|
irsdk_EngineStalled = 0x00000008
|
||||||
|
irsdk_PitSpeedLimiter = 0x00000010
|
||||||
|
irsdk_RevLimiterActive = 0x00000020
|
||||||
|
irsdk_AbsActive = 0x00000100
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i *IBT) checkEngineWarningsBitfield(field int) bool {
|
||||||
|
val, ok := i.Vars.Vars["EngineWarnings"]
|
||||||
|
if !ok {
|
||||||
|
log.Fatal("no EngineWarnings")
|
||||||
|
}
|
||||||
|
|
||||||
|
bitfield, ok := val.Value.(uint32)
|
||||||
|
if !ok {
|
||||||
|
log.Fatalf("unable to typecast EngineWarnings: %+v", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitfield&uint32(field) != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) WaterTempWarning() bool {
|
||||||
|
return i.checkEngineWarningsBitfield(irsdk_WaterTempWarning)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) FuelPressureWarning() bool {
|
||||||
|
return i.checkEngineWarningsBitfield(irsdk_FuelPressureWarning)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) OilPressureWarning() bool {
|
||||||
|
return i.checkEngineWarningsBitfield(irsdk_OilPressureWarning)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) EngineStalled() bool {
|
||||||
|
return i.checkEngineWarningsBitfield(irsdk_EngineStalled)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) PitSpeedLimiter() bool {
|
||||||
|
return i.checkEngineWarningsBitfield(irsdk_PitSpeedLimiter)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) RevLimiterActive() bool {
|
||||||
|
return i.checkEngineWarningsBitfield(irsdk_RevLimiterActive)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) AbsActive() bool {
|
||||||
|
return i.checkEngineWarningsBitfield(irsdk_AbsActive)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EngineWarnings - END
|
||||||
|
|
||||||
|
// SessionState - START
|
||||||
|
const (
|
||||||
|
irsdk_StateInvalid = 0x00
|
||||||
|
irsdk_StateGetInCar = 0x01
|
||||||
|
irsdk_StateWarmup = 0x02
|
||||||
|
irsdk_StateParadeLaps = 0x03
|
||||||
|
irsdk_StateRacing = 0x04
|
||||||
|
irsdk_StateCheckered = 0x05
|
||||||
|
irsdk_StateCoolDown = 0x06
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i *IBT) checkSessionStateField(field int) bool {
|
||||||
|
val, ok := i.Vars.Vars["SessionState"]
|
||||||
|
if !ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
value, ok := val.Value.(int)
|
||||||
|
if !ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return value == field
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) SessionStateInvalid() bool {
|
||||||
|
return i.checkSessionStateField(irsdk_StateInvalid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BUG: Need to fix all of these functions, they are all wrong
|
||||||
|
func (i *IBT) SessionStateGetInCar() bool {
|
||||||
|
return i.checkSessionStateField(irsdk_StateGetInCar)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) SessionStateWarmup() bool {
|
||||||
|
return i.checkSessionStateField(irsdk_StateWarmup)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) SessionStateParadeLaps() bool {
|
||||||
|
return i.checkSessionStateField(irsdk_StateParadeLaps)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) SessionStateRacing() bool {
|
||||||
|
return i.checkSessionStateField(irsdk_StateRacing)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) SessionStateCheckered() bool {
|
||||||
|
return i.checkSessionStateField(irsdk_StateCheckered)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) SessionStateCoolDown() bool {
|
||||||
|
return i.checkSessionStateField(irsdk_StateCoolDown)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SessionStateToString(state int) string {
|
||||||
|
switch state {
|
||||||
|
case irsdk_StateInvalid:
|
||||||
|
return "StateInvalid"
|
||||||
|
case irsdk_StateGetInCar:
|
||||||
|
return "StateGetInCar"
|
||||||
|
case irsdk_StateWarmup:
|
||||||
|
return "StateWarmup"
|
||||||
|
case irsdk_StateParadeLaps:
|
||||||
|
return "StateParadeLaps"
|
||||||
|
case irsdk_StateRacing:
|
||||||
|
return "StateRacing"
|
||||||
|
case irsdk_StateCheckered:
|
||||||
|
return "StateCheckered"
|
||||||
|
case irsdk_StateCoolDown:
|
||||||
|
return "StateCoolDown"
|
||||||
|
default:
|
||||||
|
return "UknownSessionState"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SessionState - END
|
||||||
|
|
||||||
|
// TrkLoc const
|
||||||
|
const (
|
||||||
|
irsdk_NotInWorld = -1
|
||||||
|
irsdk_OffTrack = 0
|
||||||
|
irsdk_InPitStall = 1
|
||||||
|
irsdk_AproachingPits = 2
|
||||||
|
irsdk_OnTrack = 3
|
||||||
|
)
|
||||||
|
|
||||||
|
func TrkLocToString(trkloc int) string {
|
||||||
|
switch trkloc {
|
||||||
|
case irsdk_NotInWorld:
|
||||||
|
return "NotInWorld"
|
||||||
|
case irsdk_OffTrack:
|
||||||
|
return "OffTrack"
|
||||||
|
case irsdk_InPitStall:
|
||||||
|
return "InPitStall"
|
||||||
|
case irsdk_AproachingPits:
|
||||||
|
return "AproachingPits"
|
||||||
|
case irsdk_OnTrack:
|
||||||
|
return "OnTrack"
|
||||||
|
default:
|
||||||
|
return "UknownTrackLocation"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flags
|
||||||
|
const (
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
func FlagToString(flag int) string {
|
||||||
|
switch flag {
|
||||||
|
case irsdk_checkered:
|
||||||
|
return "irsdk_checkered"
|
||||||
|
case irsdk_white:
|
||||||
|
return "irsdk_white"
|
||||||
|
case irsdk_green:
|
||||||
|
return "irsdk_green"
|
||||||
|
case irsdk_yellow:
|
||||||
|
return "irsdk_yellow"
|
||||||
|
case irsdk_red:
|
||||||
|
return "irsdk_red"
|
||||||
|
case irsdk_blue:
|
||||||
|
return "irsdk_blue"
|
||||||
|
case irsdk_debris:
|
||||||
|
return "irsdk_debris"
|
||||||
|
case irsdk_crossed:
|
||||||
|
return "irsdk_crossed"
|
||||||
|
case irsdk_yellowWaving:
|
||||||
|
return "irsdk_yellowWaving"
|
||||||
|
case irsdk_oneLapToGreen:
|
||||||
|
return "irsdk_oneLapToGreen"
|
||||||
|
case irsdk_greenHeld:
|
||||||
|
return "irsdk_greenHeld"
|
||||||
|
case irsdk_tenToGo:
|
||||||
|
return "irsdk_tenToGo"
|
||||||
|
case irsdk_fiveToGo:
|
||||||
|
return "irsdk_fiveToGo"
|
||||||
|
case irsdk_randomWaving:
|
||||||
|
return "irsdk_randomWaving"
|
||||||
|
case irsdk_caution:
|
||||||
|
return "irsdk_caution"
|
||||||
|
case irsdk_cautionWaving:
|
||||||
|
return "irsdk_cautionWaving"
|
||||||
|
case irsdk_black:
|
||||||
|
return "irsdk_black"
|
||||||
|
case irsdk_disqualify:
|
||||||
|
return "irsdk_disqualify"
|
||||||
|
case irsdk_servicible:
|
||||||
|
return "irsdk_servicible"
|
||||||
|
case irsdk_furled:
|
||||||
|
return "irsdk_furled"
|
||||||
|
case irsdk_repair:
|
||||||
|
return "irsdk_repair"
|
||||||
|
case irsdk_startHidden:
|
||||||
|
return "irsdk_startHidden"
|
||||||
|
case irsdk_startReady:
|
||||||
|
return "irsdk_startReady"
|
||||||
|
case irsdk_startSet:
|
||||||
|
return "irsdk_startSet"
|
||||||
|
case irsdk_startGo:
|
||||||
|
return "irsdk_startGo"
|
||||||
|
default:
|
||||||
|
return "UknownFlag"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// enum irsdk_TrkSurf
|
||||||
|
const (
|
||||||
|
irsdk_SurfaceNotInWorld = iota - 1
|
||||||
|
irsdk_UndefinedMaterial
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
func TrkSurfToString(surface int) string {
|
||||||
|
switch surface {
|
||||||
|
case irsdk_SurfaceNotInWorld:
|
||||||
|
return "SurfaceNotInWorld"
|
||||||
|
case irsdk_UndefinedMaterial:
|
||||||
|
return "UndefinedMaterial"
|
||||||
|
case irsdk_Asphalt1Material:
|
||||||
|
return "Asphalt1Material"
|
||||||
|
case irsdk_Asphalt2Material:
|
||||||
|
return "Asphalt2Material"
|
||||||
|
case irsdk_Asphalt3Material:
|
||||||
|
return "Asphalt3Material"
|
||||||
|
case irsdk_Asphalt4Material:
|
||||||
|
return "Asphalt4Material"
|
||||||
|
case irsdk_Concrete1Material:
|
||||||
|
return "Concrete1Material"
|
||||||
|
case irsdk_Concrete2Material:
|
||||||
|
return "Concrete2Material"
|
||||||
|
case irsdk_RacingDirt1Material:
|
||||||
|
return "RacingDirt1Material"
|
||||||
|
case irsdk_RacingDirt2Material:
|
||||||
|
return "RacingDirt2Material"
|
||||||
|
case irsdk_Paint1Material:
|
||||||
|
return "Paint1Material"
|
||||||
|
case irsdk_Paint2Material:
|
||||||
|
return "Paint2Material"
|
||||||
|
case irsdk_Rumble1Material:
|
||||||
|
return "Rumble1Material"
|
||||||
|
case irsdk_Rumble2Material:
|
||||||
|
return "Rumble2Material"
|
||||||
|
case irsdk_Rumble3Material:
|
||||||
|
return "Rumble3Material"
|
||||||
|
case irsdk_Rumble4Material:
|
||||||
|
return "Rumble4Material"
|
||||||
|
case irsdk_Grass1Material:
|
||||||
|
return "Grass1Material"
|
||||||
|
case irsdk_Grass2Material:
|
||||||
|
return "Grass2Material"
|
||||||
|
case irsdk_Grass3Material:
|
||||||
|
return "Grass3Material"
|
||||||
|
case irsdk_Grass4Material:
|
||||||
|
return "Grass4Material"
|
||||||
|
case irsdk_Dirt1Material:
|
||||||
|
return "Dirt1Material"
|
||||||
|
case irsdk_Dirt2Material:
|
||||||
|
return "Dirt2Material"
|
||||||
|
case irsdk_Dirt3Material:
|
||||||
|
return "Dirt3Material"
|
||||||
|
case irsdk_Dirt4Material:
|
||||||
|
return "Dirt4Material"
|
||||||
|
case irsdk_SandMaterial:
|
||||||
|
return "SandMaterial"
|
||||||
|
case irsdk_Gravel1Material:
|
||||||
|
return "Gravel1Material"
|
||||||
|
case irsdk_Gravel2Material:
|
||||||
|
return "Gravel2Material"
|
||||||
|
case irsdk_GrasscreteMaterial:
|
||||||
|
return "GrasscreteMaterial"
|
||||||
|
case irsdk_AstroturfMaterial:
|
||||||
|
return "AstroturfMaterial"
|
||||||
|
default:
|
||||||
|
return "UknownTrackSurface"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CameraState
|
||||||
|
const (
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
func CameraStateToString(state int) string {
|
||||||
|
switch state {
|
||||||
|
case irsdk_IsSessionScreen:
|
||||||
|
return "IsSessionScreen"
|
||||||
|
case irsdk_IsScenicActive:
|
||||||
|
return "IsScenicActive"
|
||||||
|
case irsdk_CamToolActive:
|
||||||
|
return "CamToolActive"
|
||||||
|
case irsdk_UIHidden:
|
||||||
|
return "UIHidden"
|
||||||
|
case irsdk_UseAutoShotSelection:
|
||||||
|
return "UseAutoShotSelection"
|
||||||
|
case irsdk_UseTemporaryEdits:
|
||||||
|
return "UseTemporaryEdits"
|
||||||
|
case irsdk_UseKeyAcceleration:
|
||||||
|
return "UseKeyAcceleration"
|
||||||
|
case irsdk_UseKey10xAcceleration:
|
||||||
|
return "UseKey10xAcceleration"
|
||||||
|
case irsdk_UseMouseAimMode:
|
||||||
|
return "UseMouseAimMode"
|
||||||
|
default:
|
||||||
|
return "UknownCameraState"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PitSvFlags -- Start
|
||||||
|
const (
|
||||||
|
// Tires
|
||||||
|
irsdk_LFTireChange uint32 = 0x00000001
|
||||||
|
irsdk_RFTireChange uint32 = 0x00000002
|
||||||
|
irsdk_LRTireChange uint32 = 0x00000004
|
||||||
|
irsdk_RRTireChange uint32 = 0x00000008
|
||||||
|
// Fuel
|
||||||
|
irsdk_FuelFill uint32 = 0x00000010
|
||||||
|
|
||||||
|
irsdk_WindshieldTearoff uint32 = 0x00000020
|
||||||
|
irsdk_FastRepair uint32 = 0x00000040
|
||||||
|
|
||||||
|
// Other pit service request flags
|
||||||
|
irsdk_ClearTires uint32 = 0x00000080 // Uncheck tire change
|
||||||
|
irsdk_ClearWS uint32 = 0x00000100 // Uncheck windshield tearoff
|
||||||
|
irsdk_ClearFR uint32 = 0x00000200 // Uncheck FastRepair
|
||||||
|
irsdk_ClearFuel uint32 = 0x00000400 // Uncheck refuelling
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i *IBT) checkPitSvFlags(field uint32) bool {
|
||||||
|
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||||
|
if !ok {
|
||||||
|
log.Fatal("no PitSvFlags")
|
||||||
|
}
|
||||||
|
|
||||||
|
bitfield, ok := val.Value.(uint32)
|
||||||
|
if !ok {
|
||||||
|
log.Fatal("unable to get PitSvFlags: %+v", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitfield&field != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) LFTireChange() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_LFTireChange)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) RFTireChange() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_RFTireChange)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) LRTireChange() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_LRTireChange)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) RRTireChange() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_RRTireChange)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) FuelFill() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_FuelFill)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) WindshieldTearoff() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_WindshieldTearoff)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) FastRepair() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_FastRepair)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) ClearTires() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_ClearTires)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) ClearWS() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_ClearWS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) ClearFR() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_ClearFR)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) ClearFuel() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_ClearFuel)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PitSvFlags -- End
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package conversions
|
||||||
|
|
||||||
|
func MsToKph(v float32) int {
|
||||||
|
return int((3600 * v) / 1000)
|
||||||
|
}
|
||||||
+70
-47
@@ -1,47 +1,70 @@
|
|||||||
package ibtReader
|
package goirsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SubHeaderSize = 32 // SubHeaderSize is the size of the subheader
|
SubHeaderSize = 32 // SubHeaderSize is the size of the subheader
|
||||||
)
|
)
|
||||||
|
|
||||||
// DiskSubHeader represents the IBT sub headers
|
// DiskSubHeader represents the IBT sub headers
|
||||||
type DiskSubHeader struct {
|
type DiskSubHeader struct {
|
||||||
StartDate int64 // StartDate represents the start date of the telemetry
|
StartDate int64 // StartDate represents the start date of the telemetry
|
||||||
StartTime float64 // StartTime of file relative to start of session
|
StartTime float64 // StartTime of file relative to start of session
|
||||||
EndTime float64 // EndTime of file relative to start of session
|
EndTime float64 // EndTime of file relative to start of session
|
||||||
LapCount int32 // LapCount represents the total number laps
|
LapCount int32 // LapCount represents the total number laps
|
||||||
RecordCount int32 // RecordCount holds the number of data frames
|
RecordCount int32 // RecordCount holds the number of data frames
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseTelemetrySubHeader will return a pointer to a DiskSubHeader variable
|
// readSubheader will read the subheader contents out of the telemetry data
|
||||||
// or nil if an error occurs. In which case the error return value is more
|
func (i *IBT) readSubheader() error {
|
||||||
// valuable
|
var subheaderRaw [SubHeaderSize]byte
|
||||||
func parseTelemetrySubHeader(buf [SubHeaderSize]byte) (*DiskSubHeader, error) {
|
_, err := i.File.ReadAt(subheaderRaw[:], HeaderSize)
|
||||||
dst := DiskSubHeader{}
|
if err != nil {
|
||||||
err := binary.Read(bytes.NewBuffer(buf[:]), binary.LittleEndian, &dst)
|
return fmt.Errorf("failed to read disk subheaders from file: %v", err)
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
i.SubHeaders, err = parseTelemetrySubHeader(subheaderRaw)
|
||||||
}
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to parse disk subheaders from file: %v", err)
|
||||||
return &dst, nil
|
}
|
||||||
}
|
|
||||||
|
// Write to the output file - TODO add the check
|
||||||
// ToString renders a string showing the values of the struct
|
if i.Opts.IBTExport {
|
||||||
func (d *DiskSubHeader) ToString() string {
|
err = i.exportIBT(subheaderRaw[:], HeaderSize)
|
||||||
return fmt.Sprintf(
|
if err != nil {
|
||||||
"StartDate: %13d (0x%04x)\n"+
|
i.Opts.Logger.Debug("failed to export disksubheader", "err", err)
|
||||||
"StartTime: %13f (0x%08x)\n"+
|
}
|
||||||
"EndTime: %13f (0x%08x)\n"+
|
}
|
||||||
"LapCount: %13d (0x%04x)\n"+
|
|
||||||
"RecordCount: %13d (0x%04x)\n",
|
return nil
|
||||||
d.StartDate, d.StartDate, d.StartTime, d.StartTime,
|
}
|
||||||
d.EndTime, d.EndTime, d.LapCount, d.LapCount,
|
|
||||||
d.RecordCount, d.RecordCount,
|
// parseTelemetrySubHeader will return a pointer to a DiskSubHeader variable
|
||||||
)
|
// or nil if an error occurs. In which case the error return value is more
|
||||||
}
|
// valuable
|
||||||
|
func parseTelemetrySubHeader(buf [SubHeaderSize]byte) (*DiskSubHeader, error) {
|
||||||
|
dst := DiskSubHeader{}
|
||||||
|
err := binary.Read(bytes.NewBuffer(buf[:]), binary.LittleEndian, &dst)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &dst, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToString renders a string showing the values of the struct
|
||||||
|
func (d *DiskSubHeader) ToString() string {
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"StartDate: %13d (0x%04x)\n"+
|
||||||
|
"StartTime: %13f (0x%08x)\n"+
|
||||||
|
"EndTime: %13f (0x%08x)\n"+
|
||||||
|
"LapCount: %13d (0x%04x)\n"+
|
||||||
|
"RecordCount: %13d (0x%04x)\n",
|
||||||
|
d.StartDate, d.StartDate, d.StartTime, d.StartTime,
|
||||||
|
d.EndTime, d.EndTime, d.LapCount, d.LapCount,
|
||||||
|
d.RecordCount, d.RecordCount,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package goirsdk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestParseTelemetrySubHeader_WithGoodBuffer
|
||||||
|
// Given a well structured buffer it will output the expected
|
||||||
|
// DiskSubHeader struct
|
||||||
|
func TestParseTelemetrySubHeader_WithGoodBuffer(t *testing.T) {
|
||||||
|
// Arrange
|
||||||
|
header := [32]byte{
|
||||||
|
0x54, 0x1e, 0x14, 0x67, 0x00, 0x00, 0x00, 0x00, 0x54, 0x09, 0x00, 0xf0,
|
||||||
|
0xee, 0x7e, 0x6b, 0x40, 0x53, 0x74, 0x88, 0x44, 0x44, 0x86, 0x8f, 0x40,
|
||||||
|
0x08, 0x00, 0x00, 0x00, 0xe1, 0xb8, 0x00, 0x00,
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedHeader := DiskSubHeader{
|
||||||
|
StartDate: 1729371732,
|
||||||
|
StartTime: 219.96666717536084,
|
||||||
|
EndTime: 1008.7833338413715,
|
||||||
|
LapCount: 8,
|
||||||
|
RecordCount: 47329,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Act
|
||||||
|
headers, err := parseTelemetrySubHeader(header)
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error parsing buffer: %v", err)
|
||||||
|
}
|
||||||
|
if !cmp.Equal(&expectedHeader, headers) {
|
||||||
|
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
// I should rename winutils to something else but what this package does
|
||||||
|
// is interface some windows stuff that we need for the:
|
||||||
|
// - Broadcast Channel
|
||||||
|
// - Valid Data Event windows thing
|
||||||
|
package mmaputils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Reader interface {
|
||||||
|
io.Reader
|
||||||
|
io.ReaderAt
|
||||||
|
io.ReadCloser
|
||||||
|
}
|
||||||
|
|
||||||
|
type EventUtils struct {
|
||||||
|
Utils *utils
|
||||||
|
}
|
||||||
|
|
||||||
|
func Init() (*EventUtils, error) {
|
||||||
|
u, err := newUtils()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &EventUtils{u}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *EventUtils) Close() {
|
||||||
|
if u.Utils == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
u.Utils.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenEvent will open the named windows event
|
||||||
|
func (u *EventUtils) OpenEvent(name string) error {
|
||||||
|
return u.Utils.OpenEvent(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenBroadcastChannel will open the broadcast channel
|
||||||
|
func (u *EventUtils) OpenBroadcastChannel(name string) error {
|
||||||
|
return u.Utils.OpenBroadcastChannel(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckValidDataEvent checks if our windows even is telling us we are good to go
|
||||||
|
func (u *EventUtils) CheckValidDataEvent(timeout time.Duration) bool {
|
||||||
|
return u.Utils.CheckValidDataEvent(timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignalEvent triggers a frame pulse (used by mock servers and tests)
|
||||||
|
func (u *EventUtils) SignalEvent() error {
|
||||||
|
return u.Utils.SignalEvent()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignalEvent triggers a frame pulse (used by mock servers and tests)
|
||||||
|
func SignalEvent(name string) {
|
||||||
|
signalEvent(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CleanupEvent cleans up event resources (used by mock servers and tests)
|
||||||
|
func CleanupEvent(name string) {
|
||||||
|
cleanupEvent(name)
|
||||||
|
}
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
//go:build linux && cgo
|
||||||
|
|
||||||
|
package mmaputils
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <semaphore.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static inline void* open_posix_semaphore(const char* name) {
|
||||||
|
sem_t* sem = sem_open(name, O_CREAT, 0666, 0);
|
||||||
|
if (sem == SEM_FAILED) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return (void*)sem;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void close_posix_semaphore(void* sem_ptr) {
|
||||||
|
if (sem_ptr != NULL) {
|
||||||
|
sem_close((sem_t*)sem_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int timed_wait_posix_semaphore(void* sem_ptr, long timeout_ms) {
|
||||||
|
if (sem_ptr == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
sem_t* sem = (sem_t*)sem_ptr;
|
||||||
|
|
||||||
|
// Drain the semaphore
|
||||||
|
while (sem_trywait(sem) == 0) {}
|
||||||
|
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
|
||||||
|
ts.tv_sec += timeout_ms / 1000;
|
||||||
|
ts.tv_nsec += (timeout_ms % 1000) * 1000000;
|
||||||
|
|
||||||
|
if (ts.tv_nsec >= 1000000000) {
|
||||||
|
ts.tv_sec += ts.tv_nsec / 1000000000;
|
||||||
|
ts.tv_nsec %= 1000000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
int res;
|
||||||
|
do {
|
||||||
|
res = sem_timedwait(sem, &ts);
|
||||||
|
} while (res == -1 && errno == EINTR); // Retry if interrupted by Go GC/scheduler
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int signal_posix_semaphore(const char* name) {
|
||||||
|
if (name == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
sem_t* sem = sem_open(name, 0);
|
||||||
|
if (sem == SEM_FAILED) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int res = sem_post(sem);
|
||||||
|
sem_close(sem);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int post_posix_semaphore(void* sem_ptr) {
|
||||||
|
if (sem_ptr != NULL) {
|
||||||
|
return sem_post((sem_t*)sem_ptr);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int unlink_posix_semaphore(const char* name) {
|
||||||
|
if (name == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return sem_unlink(name);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/ESilva15/goirsdk/sharedMem"
|
||||||
|
)
|
||||||
|
|
||||||
|
type utils struct {
|
||||||
|
semName string
|
||||||
|
sem unsafe.Pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
func newUtils() (*utils, error) {
|
||||||
|
return &utils{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *utils) Close() {
|
||||||
|
if u.sem != nil {
|
||||||
|
C.close_posix_semaphore(u.sem)
|
||||||
|
u.sem = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenMemMap returns a Reader interface that can be used to read the data
|
||||||
|
// No need to encapsulate it
|
||||||
|
func OpenMemMap(name string, size uint32) (Reader, error) {
|
||||||
|
file, err := sharedMem.Open(name, size)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to open `%s` with err: %+v", name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenEvent creates or connects to a Unix socket for event signaling on Linux
|
||||||
|
func (u *utils) OpenEvent(eventName string) error {
|
||||||
|
u.semName = "/" + strings.TrimPrefix(eventName, "/")
|
||||||
|
|
||||||
|
cName := C.CString(u.semName)
|
||||||
|
defer C.free(unsafe.Pointer(cName))
|
||||||
|
|
||||||
|
sem := C.open_posix_semaphore(cName)
|
||||||
|
if sem == nil {
|
||||||
|
return fmt.Errorf("failed to open POSIX semaphore: %s", u.semName)
|
||||||
|
}
|
||||||
|
|
||||||
|
u.sem = sem
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *utils) OpenBroadcastChannel(name string) error {
|
||||||
|
// No-op or log stub on Linux
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckValidDataEvent waits for a pulse byte sent over the socket
|
||||||
|
func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
|
||||||
|
if u.sem == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
ms := C.long(timeout.Milliseconds())
|
||||||
|
res := C.timed_wait_posix_semaphore(u.sem, ms)
|
||||||
|
|
||||||
|
return res == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *utils) SignalEvent() error {
|
||||||
|
if u.sem == nil {
|
||||||
|
return fmt.Errorf("u.sem is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
C.post_posix_semaphore(u.sem)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func signalEvent(name string) {
|
||||||
|
semName := "/" + strings.TrimPrefix(name, "/")
|
||||||
|
cName := C.CString(semName)
|
||||||
|
defer C.free(unsafe.Pointer(cName))
|
||||||
|
C.signal_posix_semaphore(cName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanupEvent(name string) {
|
||||||
|
semName := "/" + strings.TrimPrefix(name, "/")
|
||||||
|
cName := C.CString(semName)
|
||||||
|
defer C.free(unsafe.Pointer(cName))
|
||||||
|
C.unlink_posix_semaphore(cName)
|
||||||
|
}
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
package mmaputils_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
eventutils "github.com/ESilva15/goirsdk/eventutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
const testEventName = "test_iRSDKDataValidEvent"
|
||||||
|
|
||||||
|
// Tests initialization and resource cleanup
|
||||||
|
func TestInitAndClose(t *testing.T) {
|
||||||
|
sdkUtils, err := eventutils.Init()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Init() failed: %v", err)
|
||||||
|
}
|
||||||
|
if sdkUtils == nil {
|
||||||
|
t.Fatalf("Init() returned nil struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
sdkUtils.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests timeout behavior when telemetry stalls or stops
|
||||||
|
func TestCheckValidDataEvent_Timeout(t *testing.T) {
|
||||||
|
defer eventutils.CleanupEvent(testEventName)
|
||||||
|
|
||||||
|
sdkUtils, err := eventutils.Init()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Init() failed: %v", err)
|
||||||
|
}
|
||||||
|
defer sdkUtils.Close()
|
||||||
|
|
||||||
|
if err := sdkUtils.OpenEvent(testEventName); err != nil {
|
||||||
|
t.Fatalf("OpenEvent() failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout := 40 * time.Millisecond
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
|
// Should return false because no producer signaled the event
|
||||||
|
got := sdkUtils.CheckValidDataEvent(timeout)
|
||||||
|
elapsed := time.Since(start)
|
||||||
|
|
||||||
|
if got != false {
|
||||||
|
t.Errorf("expected CheckValidDataEvent to return false on timeout, got true")
|
||||||
|
}
|
||||||
|
|
||||||
|
if elapsed < timeout {
|
||||||
|
t.Errorf("expected timeout to wait at least %v, returned early after %v", timeout, elapsed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests successful unblocking when a frame signal arrives
|
||||||
|
func TestCheckValidDataEvent_Signaled(t *testing.T) {
|
||||||
|
defer eventutils.CleanupEvent(testEventName)
|
||||||
|
|
||||||
|
sdkUtils, err := eventutils.Init()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Init() failed: %v", err)
|
||||||
|
}
|
||||||
|
defer sdkUtils.Close()
|
||||||
|
|
||||||
|
if err := sdkUtils.OpenEvent(testEventName); err != nil {
|
||||||
|
t.Fatalf("OpenEvent() failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simulate mock producer sending a frame signal after 10ms
|
||||||
|
go func() {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
eventutils.SignalEvent(testEventName)
|
||||||
|
}()
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
got := sdkUtils.CheckValidDataEvent(200 * time.Millisecond)
|
||||||
|
elapsed := time.Since(start)
|
||||||
|
|
||||||
|
if got != true {
|
||||||
|
t.Errorf("expected CheckValidDataEvent to return true on signal, got false")
|
||||||
|
}
|
||||||
|
|
||||||
|
if elapsed >= 150*time.Millisecond {
|
||||||
|
t.Errorf("CheckValidDataEvent took too long (%v), failed to wake up immediately", elapsed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests multi-frame streaming loop (simulating steady 60Hz feed)
|
||||||
|
func TestCheckValidDataEvent_MultipleTicks(t *testing.T) {
|
||||||
|
defer eventutils.CleanupEvent(testEventName)
|
||||||
|
|
||||||
|
sdkUtils, err := eventutils.Init()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Init() failed: %v", err)
|
||||||
|
}
|
||||||
|
defer sdkUtils.Close()
|
||||||
|
|
||||||
|
if err := sdkUtils.OpenEvent(testEventName); err != nil {
|
||||||
|
t.Fatalf("OpenEvent() failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
frameCount := 5
|
||||||
|
go func() {
|
||||||
|
for i := 0; i < frameCount; i++ {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
eventutils.SignalEvent(testEventName)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for i := 0; i < frameCount; i++ {
|
||||||
|
ok := sdkUtils.CheckValidDataEvent(100 * time.Millisecond)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("failed to receive pulse for tick %d", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test60FPS60SecondsSemaphores(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("Skipping 60-second endurance test in short mode")
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventName = "test_60fps_event"
|
||||||
|
const targetFPS = 60
|
||||||
|
const durationSeconds = 60
|
||||||
|
const totalFrames = targetFPS * durationSeconds // 3,600 frames
|
||||||
|
const frameInterval = time.Second / targetFPS // ~16.666ms
|
||||||
|
|
||||||
|
// Timeout per frame set to 100ms to absorb normal OS thread scheduling jitter
|
||||||
|
const frameWaitTimeout = 250 * time.Millisecond
|
||||||
|
|
||||||
|
// Cleanup prior event state
|
||||||
|
eventutils.CleanupEvent(eventName)
|
||||||
|
defer eventutils.CleanupEvent(eventName)
|
||||||
|
|
||||||
|
// Initialize Reader
|
||||||
|
uReader, err := eventutils.Init()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to initialize reader: %v", err)
|
||||||
|
}
|
||||||
|
defer uReader.Close()
|
||||||
|
|
||||||
|
if err := uReader.OpenEvent(eventName); err != nil {
|
||||||
|
t.Fatalf("Failed to open event on reader: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize Writer
|
||||||
|
uWriter, err := eventutils.Init()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to initialize writer: %v", err)
|
||||||
|
}
|
||||||
|
defer uWriter.Close()
|
||||||
|
|
||||||
|
if err := uWriter.OpenEvent(eventName); err != nil {
|
||||||
|
t.Fatalf("Failed to open event on writer: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
stopWriter := make(chan struct{})
|
||||||
|
writerDone := make(chan struct{})
|
||||||
|
|
||||||
|
// Producer Goroutine: Emits pulse at 60 FPS
|
||||||
|
go func() {
|
||||||
|
defer close(writerDone)
|
||||||
|
ticker := time.NewTicker(frameInterval)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-stopWriter:
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
if err := uWriter.SignalEvent(); err != nil {
|
||||||
|
t.Errorf("SignalEvent failed on writer: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
startTime := time.Now()
|
||||||
|
receivedFrames := 0
|
||||||
|
|
||||||
|
// Consumer Loop: Consumes 3,600 frames continuously
|
||||||
|
for i := 1; i <= totalFrames; i++ {
|
||||||
|
ok := uReader.CheckValidDataEvent(frameWaitTimeout)
|
||||||
|
if !ok {
|
||||||
|
close(stopWriter)
|
||||||
|
<-writerDone
|
||||||
|
t.Fatalf("FAILED at frame %d/%d (elapsed: %v). Semaphore timed out after %v.",
|
||||||
|
i, totalFrames, time.Since(startTime), frameWaitTimeout)
|
||||||
|
}
|
||||||
|
receivedFrames++
|
||||||
|
}
|
||||||
|
|
||||||
|
elapsed := time.Since(startTime)
|
||||||
|
close(stopWriter)
|
||||||
|
<-writerDone
|
||||||
|
|
||||||
|
actualFPS := float64(receivedFrames) / elapsed.Seconds()
|
||||||
|
t.Logf("Passed: Processed %d/%d frames continuously in %v (Average FPS: %.2f)",
|
||||||
|
receivedFrames, totalFrames, elapsed, actualFPS)
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package mmaputils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/ESilva15/goirsdk/sharedMem"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
WAIT_OBJECT_0 = 0
|
||||||
|
WAIT_TIMEOUT = 258
|
||||||
|
)
|
||||||
|
|
||||||
|
var once sync.Once
|
||||||
|
|
||||||
|
type utils struct {
|
||||||
|
user32DLL *windows.LazyDLL
|
||||||
|
wEvent windows.Handle
|
||||||
|
wBroadcastChn uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
// INITIALIZATION
|
||||||
|
func newUtils() (*utils, error) {
|
||||||
|
return &utils{
|
||||||
|
user32DLL: openUser32DLL(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *utils) Close() {
|
||||||
|
closeEvent(&u.wEvent)
|
||||||
|
// Do we need to unload the user32DLL ???
|
||||||
|
// Do we need to close the broadcast channel ???
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenMemMap returns a Reader interface that can be used to read the data
|
||||||
|
// No need to encapsulate it
|
||||||
|
func OpenMemMap(name string, size uint32) (Reader, error) {
|
||||||
|
file, err := sharedMem.Open("Local\\"+name, size)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// openEvent opens a windows.Handle for a given event
|
||||||
|
func (u *utils) OpenEvent(eventName string) error {
|
||||||
|
name, err := windows.UTF16PtrFromString(eventName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request EVENT_MODIFY_STATE so SetEvent can be called on this handle
|
||||||
|
event, err := windows.OpenEvent(windows.SYNCHRONIZE|windows.EVENT_MODIFY_STATE, false, name)
|
||||||
|
if err != nil {
|
||||||
|
// If event does not exist yet, create it
|
||||||
|
event, err = windows.CreateEvent(nil, 0, 0, name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
u.wEvent = event
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// loadUser32DLL loads the user32.dll which is used to create some processes
|
||||||
|
func openUser32DLL() *windows.LazyDLL {
|
||||||
|
return windows.NewLazyDLL("user32.dll")
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenBroadcastChannel opens up a broadcast channel to send commands to iracing
|
||||||
|
func (u *utils) OpenBroadcastChannel(name string) error {
|
||||||
|
registerWindowsMessageW := u.user32DLL.NewProc("RegisterWindowMessageW")
|
||||||
|
|
||||||
|
msgPtr, err := windows.UTF16PtrFromString(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ret, _, err := registerWindowsMessageW.Call(uintptr(unsafe.Pointer(msgPtr)))
|
||||||
|
if ret == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
u.wBroadcastChn = ret
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *utils) SignalEvent() error {
|
||||||
|
if u.wEvent != 0 {
|
||||||
|
err := windows.SetEvent(u.wEvent)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to signal Win32 event: %+v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func signalEvent(name string) {
|
||||||
|
cName, err := syscall.UTF16PtrFromString(name)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h, err := windows.OpenEvent(windows.EVENT_MODIFY_STATE, false, cName)
|
||||||
|
if err == nil {
|
||||||
|
windows.SetEvent(h)
|
||||||
|
windows.CloseHandle(h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanupEvent(name string) {
|
||||||
|
// Win32 events clean up automatically when handles close
|
||||||
|
}
|
||||||
|
|
||||||
|
// INITIALIZATION
|
||||||
|
|
||||||
|
// closeEvent closes a given windows.Handle
|
||||||
|
func closeEvent(h *windows.Handle) {
|
||||||
|
windows.CloseHandle(*h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// openEvent waits for a good response for some given time
|
||||||
|
func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
|
||||||
|
t0 := time.Now().UnixNano()
|
||||||
|
timeoutInt := uint32(timeout / time.Millisecond)
|
||||||
|
|
||||||
|
result, err := windows.WaitForSingleObject(u.wEvent, timeoutInt)
|
||||||
|
if err != nil {
|
||||||
|
remaining := timeoutInt - uint32((time.Now().UnixNano()-t0)/1000000)
|
||||||
|
if remaining > 0 {
|
||||||
|
time.Sleep(time.Duration(remaining) * time.Millisecond)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the result of the wait
|
||||||
|
if result == WAIT_OBJECT_0 {
|
||||||
|
return true
|
||||||
|
} else if result == WAIT_TIMEOUT {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendBroadcastMessage sends a message trough the broadcast channel
|
||||||
|
func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
|
||||||
|
sendMsg := u.user32DLL.NewProc("SendNotifyMessageW")
|
||||||
|
ret, _, err := sendMsg.Call(0xffff, id, p1, p2)
|
||||||
|
|
||||||
|
if ret == 1 {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/ESilva15/goirsdk"
|
||||||
|
)
|
||||||
|
|
||||||
|
func msToKph(v float32) int {
|
||||||
|
return int((3600 * v) / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
output, err := os.OpenFile("./output.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o755)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to open log file: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger := slog.New(
|
||||||
|
slog.NewTextHandler(output, &slog.HandlerOptions{
|
||||||
|
Level: slog.LevelDebug,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Instantiate our iRacing SDK instance
|
||||||
|
irsdk, err := goirsdk.Init(goirsdk.Options{
|
||||||
|
Logger: logger,
|
||||||
|
SourceType: goirsdk.IBTFile,
|
||||||
|
SourcePath: "../../../../testTelemetry/mx5_2016Okayama_full_2024_10_19_22_02_12.ibt",
|
||||||
|
IBTExportType: goirsdk.SharedMemoryFile,
|
||||||
|
IBTExportPath: "./exported.ibt",
|
||||||
|
IBTExport: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create iRacing interface: %v", err)
|
||||||
|
}
|
||||||
|
defer irsdk.Close()
|
||||||
|
|
||||||
|
// Set up a loop to iterate our data
|
||||||
|
// TODO: revert this 240 back to 60 because i recorded the thing wrong or whatever
|
||||||
|
mainLoopTicker := time.NewTicker(time.Second / 240)
|
||||||
|
defer mainLoopTicker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
// Update the data that the SDK is holding with the next tick
|
||||||
|
_, err := irsdk.Update(100 * time.Millisecond)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("could not update data: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 := irsdk.Vars.Vars["Gear"]; !ok {
|
||||||
|
log.Fatal("Field `Gear` doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := irsdk.Vars.Vars["RPM"]; !ok {
|
||||||
|
log.Fatal("Field `RPM` doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := irsdk.Vars.Vars["Speed"]; !ok {
|
||||||
|
log.Fatal("Field `Speed` doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
gear := int32(irsdk.Vars.Vars["Gear"].Value.(int))
|
||||||
|
rpm := int32(irsdk.Vars.Vars["RPM"].Value.(float32))
|
||||||
|
speed := int32(msToKph(irsdk.Vars.Vars["Speed"].Value.(float32)))
|
||||||
|
sessionState := irsdk.Vars.Vars["SessionState"].Value.(int)
|
||||||
|
trkloc := irsdk.Vars.Vars["PlayerTrackSurface"].Value.(int)
|
||||||
|
trksurf := irsdk.Vars.Vars["PlayerTrackSurfaceMaterial"].Value.(int)
|
||||||
|
pitsvflags := irsdk.Vars.Vars["PitSvFlags"].Value.(uint32)
|
||||||
|
|
||||||
|
fmt.Printf("\033[?25l\033[2J\033[H")
|
||||||
|
fmt.Printf("Gear: %d, RPM: %d, Speed: %d\n", gear, rpm, speed)
|
||||||
|
fmt.Printf("SessionState: %s\n", goirsdk.SessionStateToString(sessionState))
|
||||||
|
fmt.Printf("TrkLoc: %s\n", goirsdk.TrkLocToString(trkloc))
|
||||||
|
fmt.Printf("TrkSurf: %s\n", goirsdk.TrkSurfToString(trksurf))
|
||||||
|
fmt.Printf("PitSvFlags: %d\n", pitsvflags)
|
||||||
|
fmt.Printf(" FL FR\n")
|
||||||
|
fmt.Printf(" %t %t\n", irsdk.LFTireChange(), irsdk.RFTireChange())
|
||||||
|
fmt.Printf("\n")
|
||||||
|
fmt.Printf(" RL RR\n")
|
||||||
|
fmt.Printf(" %t %t\n", irsdk.LRTireChange(), irsdk.RRTireChange())
|
||||||
|
fmt.Printf(" FuelFill: %t\n", irsdk.FuelFill())
|
||||||
|
fmt.Printf(" WindshieldTearoff: %t\n", irsdk.WindshieldTearoff())
|
||||||
|
fmt.Printf(" FastRepair: %t\n", irsdk.FastRepair())
|
||||||
|
fmt.Printf(" ClearTires: %t\n", irsdk.ClearTires())
|
||||||
|
fmt.Printf(" ClearWS: %t\n", irsdk.ClearWS())
|
||||||
|
fmt.Printf(" ClearFR: %t\n", irsdk.ClearFR())
|
||||||
|
fmt.Printf(" ClearFuel: %t\n", irsdk.ClearFuel())
|
||||||
|
|
||||||
|
// fmt.Printf("Vars:\n")
|
||||||
|
// for _, v := range irsdk.ListVariables() {
|
||||||
|
// fmt.Printf("%+v\n", v.Name)
|
||||||
|
// }
|
||||||
|
// os.Exit(0)
|
||||||
|
|
||||||
|
<-mainLoopTicker.C
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/ESilva15/goirsdk"
|
||||||
|
)
|
||||||
|
|
||||||
|
func msToKph(v float32) int {
|
||||||
|
return int((3600 * v) / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
output, err := os.OpenFile("./output.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o755)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to open log file: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger := slog.New(
|
||||||
|
slog.NewTextHandler(output, &slog.HandlerOptions{
|
||||||
|
Level: slog.LevelDebug,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.Debug("Starting test")
|
||||||
|
|
||||||
|
// Instantiate our iRacing SDK instance
|
||||||
|
irsdk, err := goirsdk.Init(goirsdk.Options{
|
||||||
|
Logger: logger,
|
||||||
|
SourceType: goirsdk.SharedMemoryFile,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create iRacing interface: %v", err)
|
||||||
|
}
|
||||||
|
defer irsdk.Close()
|
||||||
|
|
||||||
|
// Set up a loop to iterate our data
|
||||||
|
// TODO: revert this 240 back to 60 because i recorded the thing wrong or whatever
|
||||||
|
mainLoopTicker := time.NewTicker(time.Second / 240)
|
||||||
|
defer mainLoopTicker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
// Update the data that the SDK is holding with the next tick
|
||||||
|
_, err := irsdk.Update(100 * time.Millisecond)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("could not update data: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 := irsdk.Vars.Vars["Gear"]; !ok {
|
||||||
|
log.Fatal("Field `Gear` doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := irsdk.Vars.Vars["RPM"]; !ok {
|
||||||
|
log.Fatal("Field `RPM` doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := irsdk.Vars.Vars["Speed"]; !ok {
|
||||||
|
log.Fatal("Field `Speed` doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
gear := int32(irsdk.Vars.Vars["Gear"].Value.(int))
|
||||||
|
rpm := int32(irsdk.Vars.Vars["RPM"].Value.(float32))
|
||||||
|
speed := int32(msToKph(irsdk.Vars.Vars["Speed"].Value.(float32)))
|
||||||
|
sessionState := irsdk.Vars.Vars["SessionState"].Value.(int)
|
||||||
|
trkloc := irsdk.Vars.Vars["PlayerTrackSurface"].Value.(int)
|
||||||
|
trksurf := irsdk.Vars.Vars["PlayerTrackSurfaceMaterial"].Value.(int)
|
||||||
|
pitsvflags := irsdk.Vars.Vars["PitSvFlags"].Value.(uint32)
|
||||||
|
|
||||||
|
fmt.Printf("\033[?25l\033[2J\033[H")
|
||||||
|
fmt.Printf("Gear: %d, RPM: %d, Speed: %d\n", gear, rpm, speed)
|
||||||
|
fmt.Printf("SessionState: %s\n", goirsdk.SessionStateToString(sessionState))
|
||||||
|
fmt.Printf("TrkLoc: %s\n", goirsdk.TrkLocToString(trkloc))
|
||||||
|
fmt.Printf("TrkSurf: %s\n", goirsdk.TrkSurfToString(trksurf))
|
||||||
|
fmt.Printf("PitSvFlags: %d\n", pitsvflags)
|
||||||
|
fmt.Printf(" FL FR\n")
|
||||||
|
fmt.Printf(" %t %t\n", irsdk.LFTireChange(), irsdk.RFTireChange())
|
||||||
|
fmt.Printf("\n")
|
||||||
|
fmt.Printf(" RL RR\n")
|
||||||
|
fmt.Printf(" %t %t\n", irsdk.LRTireChange(), irsdk.RRTireChange())
|
||||||
|
fmt.Printf(" FuelFill: %t\n", irsdk.FuelFill())
|
||||||
|
fmt.Printf(" WindshieldTearoff: %t\n", irsdk.WindshieldTearoff())
|
||||||
|
fmt.Printf(" FastRepair: %t\n", irsdk.FastRepair())
|
||||||
|
fmt.Printf(" ClearTires: %t\n", irsdk.ClearTires())
|
||||||
|
fmt.Printf(" ClearWS: %t\n", irsdk.ClearWS())
|
||||||
|
fmt.Printf(" ClearFR: %t\n", irsdk.ClearFR())
|
||||||
|
fmt.Printf(" ClearFuel: %t\n", irsdk.ClearFuel())
|
||||||
|
|
||||||
|
<-mainLoopTicker.C
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
module esilvalabs.org/ibtReader.git
|
module github.com/ESilva15/goirsdk
|
||||||
|
|
||||||
go 1.23.2
|
go 1.23.2
|
||||||
|
|
||||||
require gopkg.in/yaml.v3 v3.0.1
|
require (
|
||||||
|
github.com/google/go-cmp v0.6.0
|
||||||
|
golang.org/x/sys v0.29.0
|
||||||
|
golang.org/x/text v0.19.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||||
|
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||||
|
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
|||||||
+91
-80
@@ -1,80 +1,91 @@
|
|||||||
package ibtReader
|
package goirsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FileHeaderSize = 112 // FileHeaderSize is the size of the headers
|
FileHeaderSize = 112 // FileHeaderSize is the size of the headers
|
||||||
HeaderSize = 4 // HeaderSize is the size of a single header
|
HeaderSize = 4 // HeaderSize is the size of a single header
|
||||||
)
|
)
|
||||||
|
|
||||||
// TelemetryHeaders struct to hold an IBT file's headers
|
// TelemetryHeaders struct to hold an IBT file's headers
|
||||||
type TelemetryHeaders struct {
|
type TelemetryHeaders struct {
|
||||||
Version int32
|
Version int32
|
||||||
// Status of 1 indicates a completed session and status of 0 a live session
|
Status int32 // Status of 1 indicates a completed session and status of 0 a live session
|
||||||
Status int32
|
TickRate int32 // TickRate indicates the frequency of writes (usually 60)
|
||||||
// TickRate indicates the frequency of writes (usually 60)
|
SessionInfoUpdate int32 // SessionInfoUpdate indicates the number of times the SessionInfo was
|
||||||
TickRate int32
|
// updated. 0 for finished sessions and >1 for active sessions
|
||||||
// SessionInfoUpdate indicates the number of times the SessionInfo was
|
SessionInfoLength int32 // SessionInfoLength is the length of the session info buffer
|
||||||
// updated. 0 for finished sessions and >1 for active sessions
|
SessionInfoOffset int32 // SessionInfoOffset is the offset of the session info in the buffer
|
||||||
SessionInfoUpdate int32
|
NumVars int32 // NumVars is the number of variables in each input
|
||||||
// SessionInfoLength is the length of the session info buffer
|
VarHeaderOffset int32 // VarHeaderOffset is the offset of the VarHeader
|
||||||
SessionInfoLength int32
|
NumBuf int32 // NumBuf will be 1 for static files and 3 for live telemetry files
|
||||||
// SessionInfoOffset is the offset of the session info in the buffer
|
BufLen int32 // BufLen is the length for parsing VarHeader values
|
||||||
SessionInfoOffset int32
|
Padding [12]byte // Padding
|
||||||
// NumVars is the number of variables in each input
|
BufOffset int32 // I still don't know what this is:
|
||||||
NumVars int32
|
}
|
||||||
// VarHeaderOffset is the offset of the VarHeader
|
|
||||||
VarHeaderOffset int32
|
// readHeader will read the header out of the telemetry data
|
||||||
// NumBuf will be 1 for static files and 3 for live telemetry files
|
func (i *IBT) readHeader() error {
|
||||||
NumBuf int32
|
var headerRaw [FileHeaderSize]byte
|
||||||
// BufLen is the length for parsing VarHeader values
|
_, err := i.File.ReadAt(headerRaw[:], 0)
|
||||||
BufLen int32
|
if err != nil {
|
||||||
// Padding
|
return fmt.Errorf("failed to read headers from file: %v", err)
|
||||||
Padding [12]byte
|
}
|
||||||
// I still don't know what this is:
|
i.Headers, err = parseTelemetryHeader(headerRaw)
|
||||||
BufOffset int32
|
if err != nil {
|
||||||
}
|
return fmt.Errorf("unable to read headers from file: %v", err)
|
||||||
|
}
|
||||||
// ToString renders a string showing the values of the struct
|
|
||||||
func (th *TelemetryHeaders) ToString() string {
|
// Write to the output file - TODO: this should only write if necessary
|
||||||
return fmt.Sprintf(
|
if i.Opts.IBTExport {
|
||||||
"Version: %5d (0x%04x)\n"+
|
err = i.exportIBT(headerRaw[:], 0)
|
||||||
"Status: %5d (0x%04x)\n"+
|
if err != nil {
|
||||||
"TickRate: %5d (0x%04x)\n"+
|
i.Opts.Logger.Debug("Failed to export headers", "err", err)
|
||||||
"SIUpdate: %5d (0x%04x)\n"+
|
}
|
||||||
"SILength: %5d (0x%04x)\n"+
|
}
|
||||||
"SIOffset: %5d (0x%04x)\n"+
|
|
||||||
"NumVars: %5d (0x%04x)\n"+
|
return nil
|
||||||
"VarHeaderOffset: %5d (0x%04x)\n"+
|
}
|
||||||
"NumBuf: %5d (0x%04x)\n"+
|
|
||||||
"BufLen: %5d (0x%04x)\n"+
|
// parseTelemetryHeader will read the IBT file headers from a correctly sized
|
||||||
"BufOffset: %5d (0x%04x)\n",
|
// buffer.
|
||||||
th.Version, th.Version, th.Status, th.Status, th.TickRate, th.TickRate,
|
// You need to pass a the first FILE_HEADER_SIZE bytes of the buffer
|
||||||
th.SessionInfoUpdate, th.SessionInfoUpdate,
|
func parseTelemetryHeader(buf [FileHeaderSize]byte) (*TelemetryHeaders, error) {
|
||||||
th.SessionInfoLength, th.SessionInfoLength,
|
// utils.HexDump(buf[:])
|
||||||
th.SessionInfoOffset, th.SessionInfoOffset,
|
// fmt.Printf("Len: %d\n", len(buf))
|
||||||
th.NumVars, th.NumVars, th.VarHeaderOffset, th.VarHeaderOffset,
|
|
||||||
th.NumBuf, th.NumBuf, th.BufLen, th.BufLen, th.BufOffset, th.BufOffset,
|
dst := TelemetryHeaders{}
|
||||||
)
|
err := binary.Read(bytes.NewBuffer(buf[:]), binary.LittleEndian, &dst)
|
||||||
}
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to unpack data: %v", err)
|
||||||
// parseTelemetryHeader will read the IBT file headers from a correctly sized
|
}
|
||||||
// buffer.
|
|
||||||
// You need to pass a the first FILE_HEADER_SIZE bytes of the buffer
|
return &dst, nil
|
||||||
func parseTelemetryHeader(buf [FileHeaderSize]byte) (*TelemetryHeaders, error) {
|
}
|
||||||
if len(buf)%HeaderSize != 0 {
|
|
||||||
return nil, fmt.Errorf("buffer must be multiple of size: %d", HeaderSize)
|
// ToString renders a string showing the values of the struct
|
||||||
}
|
func (th *TelemetryHeaders) ToString() string {
|
||||||
|
return fmt.Sprintf(
|
||||||
dst := TelemetryHeaders{}
|
"Version: %5d (0x%04x)\n"+
|
||||||
err := binary.Read(bytes.NewBuffer(buf[:]), binary.LittleEndian, &dst)
|
"Status: %5d (0x%04x)\n"+
|
||||||
if err != nil {
|
"TickRate: %5d (0x%04x)\n"+
|
||||||
return nil, fmt.Errorf("unable to unpack data: %v", err)
|
"SIUpdate: %5d (0x%04x)\n"+
|
||||||
}
|
"SILength: %5d (0x%04x)\n"+
|
||||||
|
"SIOffset: %5d (0x%04x)\n"+
|
||||||
return &dst, nil
|
"NumVars: %5d (0x%04x)\n"+
|
||||||
}
|
"VarHeaderOffset: %5d (0x%04x)\n"+
|
||||||
|
"NumBuf: %5d (0x%04x)\n"+
|
||||||
|
"BufLen: %5d (0x%04x)\n"+
|
||||||
|
"BufOffset: %5d (0x%04x)\n",
|
||||||
|
th.Version, th.Version, th.Status, th.Status, th.TickRate, th.TickRate,
|
||||||
|
th.SessionInfoUpdate, th.SessionInfoUpdate,
|
||||||
|
th.SessionInfoLength, th.SessionInfoLength,
|
||||||
|
th.SessionInfoOffset, th.SessionInfoOffset,
|
||||||
|
th.NumVars, th.NumVars, th.VarHeaderOffset, th.VarHeaderOffset,
|
||||||
|
th.NumBuf, th.NumBuf, th.BufLen, th.BufLen, th.BufOffset, th.BufOffset,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package goirsdk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestParseTelemetryHeader_WithGoodBuffer
|
||||||
|
// Given a well structured buffer it will output the expected
|
||||||
|
// TelemetryHeaders struct
|
||||||
|
func TestParseTelemetryHeader_WithGoodBuffer(t *testing.T) {
|
||||||
|
// Arrange
|
||||||
|
header := [112]byte{
|
||||||
|
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x05, 0x3f, 0x00, 0x00, 0x90, 0x99, 0x00, 0x00,
|
||||||
|
0x10, 0x01, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||||
|
0x1d, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x60, 0x2b, 0x00, 0x00, 0x95, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedHeader := TelemetryHeaders{
|
||||||
|
Version: 2,
|
||||||
|
Status: 1,
|
||||||
|
TickRate: 60,
|
||||||
|
SessionInfoUpdate: 0,
|
||||||
|
SessionInfoLength: 16133,
|
||||||
|
SessionInfoOffset: 39312,
|
||||||
|
NumVars: 272,
|
||||||
|
VarHeaderOffset: 144,
|
||||||
|
NumBuf: 1,
|
||||||
|
BufLen: 1053,
|
||||||
|
Padding: [12]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0x2b, 0x0, 0x0},
|
||||||
|
BufOffset: 55445,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Act
|
||||||
|
headers, err := parseTelemetryHeader(header)
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error parsing buffer: %v", err)
|
||||||
|
}
|
||||||
|
if !cmp.Equal(&expectedHeader, headers) {
|
||||||
|
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,136 +1,274 @@
|
|||||||
// Package IbtReader is all you need for you iRacing telemetry parsing
|
// Package goirsdk is all you need for you iRacing telemetry parsing
|
||||||
package ibtReader
|
package goirsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
)
|
"log/slog"
|
||||||
|
"os"
|
||||||
const (
|
"time"
|
||||||
ibtFile = "./telemetryFiles/mx5_2016Okayama_full_2024_10_19_22_02_12.ibt"
|
|
||||||
)
|
eventutils "github.com/ESilva15/goirsdk/eventutils"
|
||||||
|
"github.com/ESilva15/goirsdk/sharedMem"
|
||||||
// Reader is an interface to represent the readable data that can be either
|
"gopkg.in/yaml.v3"
|
||||||
// a .ibt file (or live data, hopefully)
|
)
|
||||||
type Reader interface {
|
|
||||||
io.Reader
|
// Reader is an interface to represent the readable data that can be either
|
||||||
io.ReaderAt
|
// a .ibt file (or live data, hopefully)
|
||||||
io.ReadCloser
|
type Reader interface {
|
||||||
}
|
io.Reader
|
||||||
|
io.ReaderAt
|
||||||
// IBT struct will hold the relevant data for a given IBT file
|
io.ReadCloser
|
||||||
type IBT struct {
|
}
|
||||||
File Reader // Source of the data
|
|
||||||
Headers *TelemetryHeaders // IBT file Headers
|
type Writer interface {
|
||||||
SubHeaders *DiskSubHeader // IBT file Sub Headers
|
io.WriterAt
|
||||||
SessionInfo *SessionInfoYAML // IBT file Session Info
|
io.Closer
|
||||||
Vars *TelemetryVars // Vars will hold the telemetry data
|
}
|
||||||
Tick int32 // Tick holds the cound of the reads
|
|
||||||
}
|
type TelemetryContainer int
|
||||||
|
|
||||||
// Init serves to initialize and get a hold of a IBT struct
|
const (
|
||||||
func Init(f Reader) (*IBT, error) {
|
IBTFile TelemetryContainer = iota
|
||||||
// Read the header of the file
|
SharedMemoryFile TelemetryContainer = iota
|
||||||
var err error
|
)
|
||||||
ibt := IBT{
|
|
||||||
File: f,
|
type Options struct {
|
||||||
Vars: &TelemetryVars{},
|
Logger *slog.Logger
|
||||||
}
|
SourceType TelemetryContainer // type of source data
|
||||||
|
SourcePath string // Path to source
|
||||||
// Read the file headers
|
IBTExportType TelemetryContainer // export type of telemetry: store .ibt or replay in shm
|
||||||
var headerRaw [FileHeaderSize]byte
|
IBTExportPath string // path where to export the data
|
||||||
_, err = ibt.File.ReadAt(headerRaw[:], 0)
|
IBTExport bool // whether to export the telemetry data
|
||||||
if err != nil {
|
SessionInfoExport bool // whether to export the session info data
|
||||||
return nil, fmt.Errorf("Failed to read headers from file: %v", err)
|
SessionInfoExportPath string // path where to export the session info
|
||||||
}
|
}
|
||||||
ibt.Headers, err = parseTelemetryHeader(headerRaw)
|
|
||||||
if err != nil {
|
// IBT struct will hold the relevant data for a given IBT file
|
||||||
return nil, fmt.Errorf("Unable to read headers from file: %v", err)
|
type IBT struct {
|
||||||
}
|
File Reader // Source of the data
|
||||||
|
Opts Options
|
||||||
// Read the disk sub headers
|
IBTExporter Writer
|
||||||
var subheaderRaw [SubHeaderSize]byte
|
winUtils *eventutils.EventUtils // WinUtils gives access to the system utilities
|
||||||
_, err = ibt.File.ReadAt(subheaderRaw[:], 112)
|
|
||||||
if err != nil {
|
// TODO: fragment this struct a little bit, for now I want to actually get
|
||||||
return nil, fmt.Errorf("Failed to read disk subheaders from file: %v", err)
|
// stuff done so its enough to work as is
|
||||||
}
|
// Actual FILE
|
||||||
ibt.SubHeaders, err = parseTelemetrySubHeader(subheaderRaw)
|
Headers *TelemetryHeaders // IBT file Headers
|
||||||
if err != nil {
|
SubHeaders *DiskSubHeader // IBT file Sub Headers
|
||||||
return nil, fmt.Errorf("Unable to parse disk subheaders from file: %v", err)
|
SessionInfo *SessionInfoYAML // IBT file Session Info
|
||||||
}
|
Vars *TelemetryVars // Vars will hold the telemetry data
|
||||||
|
}
|
||||||
// Read session info string
|
|
||||||
sessionInfoStringRaw := make([]byte, ibt.Headers.SessionInfoLength)
|
func (i *IBT) IsConnected() bool {
|
||||||
_, err = ibt.File.ReadAt(sessionInfoStringRaw, int64(ibt.Headers.SessionInfoOffset))
|
if i.Headers == nil {
|
||||||
if err != nil {
|
return false
|
||||||
return nil, fmt.Errorf("Failed to read sessionInfoString from file: %v", err)
|
}
|
||||||
}
|
|
||||||
ibt.SessionInfo, err = parseSessionInfo(sessionInfoStringRaw)
|
if !i.SessionStatusConnected() {
|
||||||
if err != nil {
|
return false
|
||||||
return nil, fmt.Errorf("Unable to parse SessionInfoString from file: %v", err)
|
}
|
||||||
}
|
|
||||||
|
if i.SessionStateInvalid() {
|
||||||
// Read the telemetry vars info
|
return false
|
||||||
err = ibt.readVariablerHeaders()
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Unable to parser variable headers from file: %v", err)
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ibt, nil
|
func (i *IBT) exportYAML() error {
|
||||||
}
|
file, err := os.OpenFile(i.Opts.SessionInfoExportPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||||
|
if err != nil {
|
||||||
func msToKph(v float32) int {
|
i.Opts.Logger.Debug(fmt.Sprintf("Failed to open file for YAML export: %v\n", err))
|
||||||
return int((3600 * v) / 1000)
|
return fmt.Errorf("failed to open output file for YAML: %v", err)
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
// func main() {
|
|
||||||
// fmt.Println("================== IBT FILE PARSER ==================")
|
enc := yaml.NewEncoder(file)
|
||||||
//
|
|
||||||
// file, err := os.Open(ibtFile)
|
err = enc.Encode(i.SessionInfo)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// log.Fatalf("Failed to open IBT file: %v", err)
|
i.Opts.Logger.Debug(fmt.Sprintf("Failed to write into file for YAML export: %v\n", err))
|
||||||
// }
|
return fmt.Errorf("failed to write YAML contents to file: %v", err)
|
||||||
//
|
}
|
||||||
// ibt, err := Init(file)
|
|
||||||
// fmt.Printf("%s\n", ibt.Headers.ToString())
|
return nil
|
||||||
// fmt.Printf("%s\n", ibt.SubHeaders.ToString())
|
}
|
||||||
//
|
|
||||||
// // Display the human readable start date
|
func (i *IBT) exportIBT(data []byte, offset int64) error {
|
||||||
// unixStartDate := time.Unix(ibt.SubHeaders.StartDate, 0)
|
nBytes, err := i.IBTExporter.WriteAt(data, offset)
|
||||||
// startDate := unixStartDate.Format("2006/01/02 15:04:05 -0700 MST")
|
if err != nil {
|
||||||
// fmt.Println("StartDate:", startDate)
|
i.IBTExporter.Close()
|
||||||
//
|
i.IBTExporter = nil
|
||||||
// // Display the human readable version of start time
|
i.Opts.Logger.Debug(fmt.Sprintf("won't attempt to export anymore: %+v", err))
|
||||||
// unixStartTime := time.Unix(ibt.SubHeaders.StartDate+int64(ibt.SubHeaders.StartTime), 0)
|
return err
|
||||||
// startTime := unixStartTime.Format("2006/01/02 15:04:05 -0700 MST")
|
}
|
||||||
// fmt.Println("StartTime:", startTime)
|
|
||||||
//
|
if nBytes > 0 {
|
||||||
// // Display the human readable version of end time
|
// Send the event stating the data has been created
|
||||||
// unixEndTime := time.Unix(ibt.SubHeaders.StartDate+int64(ibt.SubHeaders.EndTime), 0)
|
err = i.winUtils.Utils.SignalEvent()
|
||||||
// endTime := unixEndTime.Format("2006/01/02 15:04:05 -0700 MST")
|
if err != nil {
|
||||||
// fmt.Println("EndTime: ", endTime)
|
i.Opts.Logger.Debug("failed to signal event", "err", err)
|
||||||
//
|
} else {
|
||||||
// last := time.Now().UnixMilli()
|
i.Opts.Logger.Debug("no error signaling", "nBytes", nBytes)
|
||||||
// for {
|
}
|
||||||
// time.Sleep(time.Second / 60)
|
}
|
||||||
// res := ibt.Update()
|
|
||||||
//
|
return nil
|
||||||
// curTime := time.Now().UnixMilli()
|
}
|
||||||
//
|
|
||||||
// if curTime-last > 250 {
|
func (i *IBT) openSource() error {
|
||||||
// fmt.Printf(" \r")
|
var err error
|
||||||
// if val, ok := ibt.Vars.Vars["Speed"]; ok {
|
|
||||||
// fmt.Printf("\r%d %d", ibt.Tick/60, msToKph(val.Value.(float32)))
|
switch i.Opts.SourceType {
|
||||||
// } else {
|
case SharedMemoryFile:
|
||||||
// fmt.Printf("\r%d %s", ibt.Tick/60, "KEY DOESN'T EXIST")
|
// User is requesting us to read live data - present in the mem map file
|
||||||
// }
|
i.File, err = eventutils.OpenMemMap(MEMMAPFILENAME, fileMapSize)
|
||||||
// }
|
if err != nil {
|
||||||
//
|
return fmt.Errorf("failed to open memory mapped file: %+v", err)
|
||||||
// if !res {
|
}
|
||||||
// fmt.Println("\nEnd of file found...")
|
|
||||||
// break
|
// To use our windows interface we need to initialize it first
|
||||||
// }
|
// it will return a struct with a pointer to the windows handles
|
||||||
// }
|
// if, for some reason, we need to stub out this to run in on Linux its easier
|
||||||
//
|
// i.winUtils, err = eventutils.Init()
|
||||||
// fmt.Printf("%d\n", ibt.Tick)
|
// if err != nil {
|
||||||
// }
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// I don't believe we need this on windows either, but I'll have to check
|
||||||
|
// We need to open the windows event thing
|
||||||
|
// err = i.winUtils.OpenWinEvent(IRSDK_DATAVALIDEVENTNAME)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// We need to open the broadcast channel
|
||||||
|
// err = i.winUtils.OpenBroadcastChannel(IRSDK_BROADCASTMSGNAME)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
case IBTFile:
|
||||||
|
i.File, err = os.Open(i.Opts.SourcePath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to open file `%s`: %+v", i.Opts.SourcePath, err)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("a source type must be specified")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) openExporter() error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
switch i.Opts.IBTExportType {
|
||||||
|
case SharedMemoryFile:
|
||||||
|
// Lets create a shared memory file!
|
||||||
|
shm, err := sharedMem.Create(MEMMAPFILENAME, fileMapSize)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to create memory map file: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
i.IBTExporter = shm
|
||||||
|
case IBTFile:
|
||||||
|
i.IBTExporter, err = os.OpenFile(i.Opts.IBTExportPath, os.O_CREATE|os.O_RDWR, 0o644)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to open ibt export file: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init serves to initialize and get a hold of a IBT struct
|
||||||
|
// Receives an Options struct with the required configurations
|
||||||
|
func Init(opts Options) (*IBT, error) {
|
||||||
|
// Create our irsdk instance
|
||||||
|
var err error
|
||||||
|
ibt := IBT{
|
||||||
|
Opts: opts,
|
||||||
|
Vars: &TelemetryVars{},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the event utils
|
||||||
|
evutils, err := eventutils.Init()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = evutils.OpenEvent(IRSDK_DATAVALIDEVENTNAME)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ibt.winUtils = evutils
|
||||||
|
|
||||||
|
// Setup the source
|
||||||
|
err = ibt.openSource()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup the IBT data export - can be either shared memory or data file
|
||||||
|
if opts.IBTExport {
|
||||||
|
err = ibt.openExporter()
|
||||||
|
if err != nil {
|
||||||
|
// We log this only, or return some type of message
|
||||||
|
// Set the option to false so we won't export
|
||||||
|
ibt.Opts.IBTExport = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the file headers
|
||||||
|
err = ibt.readHeader()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the disk sub headers
|
||||||
|
err = ibt.readSubheader()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read session info string
|
||||||
|
err = ibt.readSessionInfo()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the telemetry vars info
|
||||||
|
err = ibt.readVariablerHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to parser variable headers from file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ibt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) ListVariables() map[string]Var {
|
||||||
|
return i.Vars.Vars
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckForDataEvent
|
||||||
|
// timeout is in ms
|
||||||
|
func (i *IBT) CheckForDataEvent(timeout time.Duration) bool {
|
||||||
|
if i.winUtils.CheckValidDataEvent(timeout) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close cleans up our irsdk instance
|
||||||
|
func (i *IBT) Close() {
|
||||||
|
if i == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if i.winUtils != nil {
|
||||||
|
// If its not live data, the user is the one with ownership of the handle
|
||||||
|
i.File.Close()
|
||||||
|
i.winUtils.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+101
@@ -0,0 +1,101 @@
|
|||||||
|
package goirsdk
|
||||||
|
|
||||||
|
// import (
|
||||||
|
// "fmt"
|
||||||
|
// "log"
|
||||||
|
// "os"
|
||||||
|
// "sort"
|
||||||
|
// "testing"
|
||||||
|
// "time"
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// type StandingsLine struct {
|
||||||
|
// CarIdx int
|
||||||
|
// LapPct float32
|
||||||
|
// Lap int32
|
||||||
|
// DriverName string
|
||||||
|
// EstTime float32
|
||||||
|
// TimeBehind float32
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// func lapTimeRepresentation(t float32) string {
|
||||||
|
// if t < 0 {
|
||||||
|
// t = 0
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// wholeSeconds := int64(t)
|
||||||
|
// lapTime := time.Unix(wholeSeconds, int64((t-float32(wholeSeconds))*1e9))
|
||||||
|
//
|
||||||
|
// return lapTime.Format("04:05.000")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// func TestFunctionality(t *testing.T) {
|
||||||
|
// input, err := os.Open("../../testTelemetry/supercars_race_watkins_glenn.ibt")
|
||||||
|
// if err != nil {
|
||||||
|
// t.Fatal("Was unable to prepare telemetry file for testing.")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// i, _ := Init(input, "", "")
|
||||||
|
// defer i.Close()
|
||||||
|
//
|
||||||
|
// // Set up a loop to iterate our data
|
||||||
|
// mainLoopTicker := time.NewTicker(time.Second / 60)
|
||||||
|
// defer mainLoopTicker.Stop()
|
||||||
|
//
|
||||||
|
// for {
|
||||||
|
// // Update the data that the SDK is holding with the next tick
|
||||||
|
// _, err := i.Update(100 * time.Millisecond)
|
||||||
|
// if err != nil {
|
||||||
|
// log.Printf("could not update data: %v", err)
|
||||||
|
// continue
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 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["CarIdxPosition"]; !ok {
|
||||||
|
// log.Fatal("Field `CarIdxPosition` doesn't exist")
|
||||||
|
// }
|
||||||
|
// driversLapDistPct := i.Vars.Vars["CarIdxLapDistPct"].Value.([]float32)
|
||||||
|
// driversEstTime := i.Vars.Vars["CarIdxEstTime"].Value.([]float32)
|
||||||
|
// driversLap := i.Vars.Vars["CarIdxLap"].Value.([]int32)
|
||||||
|
// // driversBehind := i.Vars.Vars["CarIdxF2Time"].Value.([]float32)
|
||||||
|
//
|
||||||
|
// drivers := i.SessionInfo.DriverInfo.Drivers
|
||||||
|
// myIdx := i.SessionInfo.DriverInfo.DriverCarIdx
|
||||||
|
//
|
||||||
|
// standings := make([]StandingsLine, len(drivers))
|
||||||
|
//
|
||||||
|
// fmt.Printf("\033[?25l\033[2J\033[H")
|
||||||
|
// for k := range len(drivers) {
|
||||||
|
// if drivers[k].CarIsPaceCar == 1 || drivers[k].IsSpectator == 1 {
|
||||||
|
// continue
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// standings[k] = StandingsLine{
|
||||||
|
// CarIdx: k,
|
||||||
|
// LapPct: driversLapDistPct[k],
|
||||||
|
// DriverName: drivers[k].UserName,
|
||||||
|
// EstTime: driversEstTime[k],
|
||||||
|
// Lap: driversLap[k],
|
||||||
|
// TimeBehind: driversEstTime[myIdx],
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// sort.Slice(standings, func(i int, j int) bool {
|
||||||
|
// if standings[i].Lap > int32(standings[j].Lap) {
|
||||||
|
// return true
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return standings[i].LapPct >= standings[j].LapPct
|
||||||
|
// })
|
||||||
|
//
|
||||||
|
// fmt.Printf("%v\n", driversEstTime)
|
||||||
|
// // for p, v := range standings {
|
||||||
|
// // fmt.Printf("[%2d] %-30s %13f %13f\n",
|
||||||
|
// // p+1, v.DriverName, v.LapPct, driversEstTime[p] - driversEstTime[myIdx])
|
||||||
|
// // }
|
||||||
|
//
|
||||||
|
// <-mainLoopTicker.C
|
||||||
|
// }
|
||||||
|
// }
|
||||||
+373
-323
@@ -1,323 +1,373 @@
|
|||||||
package ibtReader
|
package goirsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"gopkg.in/yaml.v3"
|
"log"
|
||||||
)
|
"strings"
|
||||||
|
|
||||||
// SessionInfoYAML is a string with session info in the IBT file
|
"golang.org/x/text/encoding/charmap"
|
||||||
type SessionInfoYAML struct {
|
"gopkg.in/yaml.v3"
|
||||||
WeekendInfo struct {
|
)
|
||||||
TrackName string `yaml:"TrackName"`
|
|
||||||
TrackID int `yaml:"TrackID"`
|
// SessionInfoYAML is a string with session info in the IBT file
|
||||||
TrackLength string `yaml:"TrackLength"`
|
type SessionInfoYAML struct {
|
||||||
TrackDisplayName string `yaml:"TrackDisplayName"`
|
WeekendInfo struct {
|
||||||
TrackDisplayShortName string `yaml:"TrackDisplayShortName"`
|
TrackName string `yaml:"TrackName"`
|
||||||
TrackConfigName string `yaml:"TrackConfigName"`
|
TrackID int `yaml:"TrackID"`
|
||||||
TrackCity string `yaml:"TrackCity"`
|
TrackLength string `yaml:"TrackLength"`
|
||||||
TrackCountry string `yaml:"TrackCountry"`
|
TrackDisplayName string `yaml:"TrackDisplayName"`
|
||||||
TrackAltitude string `yaml:"TrackAltitude"`
|
TrackDisplayShortName string `yaml:"TrackDisplayShortName"`
|
||||||
TrackLatitude string `yaml:"TrackLatitude"`
|
TrackConfigName string `yaml:"TrackConfigName"`
|
||||||
TrackLongitude string `yaml:"TrackLongitude"`
|
TrackCity string `yaml:"TrackCity"`
|
||||||
TrackNorthOffset string `yaml:"TrackNorthOffset"`
|
TrackCountry string `yaml:"TrackCountry"`
|
||||||
TrackNumTurns int `yaml:"TrackNumTurns"`
|
TrackAltitude string `yaml:"TrackAltitude"`
|
||||||
TrackPitSpeedLimit string `yaml:"TrackPitSpeedLimit"`
|
TrackLatitude string `yaml:"TrackLatitude"`
|
||||||
TrackType string `yaml:"TrackType"`
|
TrackLongitude string `yaml:"TrackLongitude"`
|
||||||
TrackDirection string `yaml:"TrackDirection"`
|
TrackNorthOffset string `yaml:"TrackNorthOffset"`
|
||||||
TrackWeatherType string `yaml:"TrackWeatherType"`
|
TrackNumTurns int `yaml:"TrackNumTurns"`
|
||||||
TrackSkies string `yaml:"TrackSkies"`
|
TrackPitSpeedLimit string `yaml:"TrackPitSpeedLimit"`
|
||||||
TrackSurfaceTemp string `yaml:"TrackSurfaceTemp"`
|
TrackType string `yaml:"TrackType"`
|
||||||
TrackAirTemp string `yaml:"TrackAirTemp"`
|
TrackDirection string `yaml:"TrackDirection"`
|
||||||
TrackAirPressure string `yaml:"TrackAirPressure"`
|
TrackWeatherType string `yaml:"TrackWeatherType"`
|
||||||
TrackWindVel string `yaml:"TrackWindVel"`
|
TrackSkies string `yaml:"TrackSkies"`
|
||||||
TrackWindDir string `yaml:"TrackWindDir"`
|
TrackSurfaceTemp string `yaml:"TrackSurfaceTemp"`
|
||||||
TrackRelativeHumidity string `yaml:"TrackRelativeHumidity"`
|
TrackAirTemp string `yaml:"TrackAirTemp"`
|
||||||
TrackFogLevel string `yaml:"TrackFogLevel"`
|
TrackAirPressure string `yaml:"TrackAirPressure"`
|
||||||
TrackCleanup int `yaml:"TrackCleanup"`
|
TrackWindVel string `yaml:"TrackWindVel"`
|
||||||
TrackDynamicTrack int `yaml:"TrackDynamicTrack"`
|
TrackWindDir string `yaml:"TrackWindDir"`
|
||||||
TrackVersion string `yaml:"TrackVersion"`
|
TrackRelativeHumidity string `yaml:"TrackRelativeHumidity"`
|
||||||
SeriesID int `yaml:"SeriesID"`
|
TrackFogLevel string `yaml:"TrackFogLevel"`
|
||||||
SeasonID int `yaml:"SeasonID"`
|
TrackCleanup int `yaml:"TrackCleanup"`
|
||||||
SessionID int `yaml:"SessionID"`
|
TrackDynamicTrack int `yaml:"TrackDynamicTrack"`
|
||||||
SubSessionID int `yaml:"SubSessionID"`
|
TrackVersion string `yaml:"TrackVersion"`
|
||||||
LeagueID int `yaml:"LeagueID"`
|
SeriesID int `yaml:"SeriesID"`
|
||||||
Official int `yaml:"Official"`
|
SeasonID int `yaml:"SeasonID"`
|
||||||
RaceWeek int `yaml:"RaceWeek"`
|
SessionID int `yaml:"SessionID"`
|
||||||
EventType string `yaml:"EventType"`
|
SubSessionID int `yaml:"SubSessionID"`
|
||||||
Category string `yaml:"Category"`
|
LeagueID int `yaml:"LeagueID"`
|
||||||
SimMode string `yaml:"SimMode"`
|
Official int `yaml:"Official"`
|
||||||
TeamRacing int `yaml:"TeamRacing"`
|
RaceWeek int `yaml:"RaceWeek"`
|
||||||
MinDrivers int `yaml:"MinDrivers"`
|
EventType string `yaml:"EventType"`
|
||||||
MaxDrivers int `yaml:"MaxDrivers"`
|
Category string `yaml:"Category"`
|
||||||
DCRuleSet string `yaml:"DCRuleSet"`
|
SimMode string `yaml:"SimMode"`
|
||||||
QualifierMustStartRace int `yaml:"QualifierMustStartRace"`
|
TeamRacing int `yaml:"TeamRacing"`
|
||||||
NumCarClasses int `yaml:"NumCarClasses"`
|
MinDrivers int `yaml:"MinDrivers"`
|
||||||
NumCarTypes int `yaml:"NumCarTypes"`
|
MaxDrivers int `yaml:"MaxDrivers"`
|
||||||
HeatRacing int `yaml:"HeatRacing"`
|
DCRuleSet string `yaml:"DCRuleSet"`
|
||||||
BuildType string `yaml:"BuildType"`
|
QualifierMustStartRace int `yaml:"QualifierMustStartRace"`
|
||||||
BuildTarget string `yaml:"BuildTarget"`
|
NumCarClasses int `yaml:"NumCarClasses"`
|
||||||
BuildVersion string `yaml:"BuildVersion"`
|
NumCarTypes int `yaml:"NumCarTypes"`
|
||||||
WeekendOptions struct {
|
HeatRacing int `yaml:"HeatRacing"`
|
||||||
NumStarters int `yaml:"NumStarters"`
|
BuildType string `yaml:"BuildType"`
|
||||||
StartingGrid string `yaml:"StartingGrid"`
|
BuildTarget string `yaml:"BuildTarget"`
|
||||||
QualifyScoring string `yaml:"QualifyScoring"`
|
BuildVersion string `yaml:"BuildVersion"`
|
||||||
CourseCautions string `yaml:"CourseCautions"`
|
WeekendOptions struct {
|
||||||
StandingStart int `yaml:"StandingStart"`
|
NumStarters int `yaml:"NumStarters"`
|
||||||
ShortParadeLap int `yaml:"ShortParadeLap"`
|
StartingGrid string `yaml:"StartingGrid"`
|
||||||
Restarts string `yaml:"Restarts"`
|
QualifyScoring string `yaml:"QualifyScoring"`
|
||||||
WeatherType string `yaml:"WeatherType"`
|
CourseCautions string `yaml:"CourseCautions"`
|
||||||
Skies string `yaml:"Skies"`
|
StandingStart int `yaml:"StandingStart"`
|
||||||
WindDirection string `yaml:"WindDirection"`
|
ShortParadeLap int `yaml:"ShortParadeLap"`
|
||||||
WindSpeed string `yaml:"WindSpeed"`
|
Restarts string `yaml:"Restarts"`
|
||||||
WeatherTemp string `yaml:"WeatherTemp"`
|
WeatherType string `yaml:"WeatherType"`
|
||||||
RelativeHumidity string `yaml:"RelativeHumidity"`
|
Skies string `yaml:"Skies"`
|
||||||
FogLevel string `yaml:"FogLevel"`
|
WindDirection string `yaml:"WindDirection"`
|
||||||
TimeOfDay string `yaml:"TimeOfDay"`
|
WindSpeed string `yaml:"WindSpeed"`
|
||||||
Date string `yaml:"Date"`
|
WeatherTemp string `yaml:"WeatherTemp"`
|
||||||
EarthRotationSpeedupFactor int `yaml:"EarthRotationSpeedupFactor"`
|
RelativeHumidity string `yaml:"RelativeHumidity"`
|
||||||
Unofficial int `yaml:"Unofficial"`
|
FogLevel string `yaml:"FogLevel"`
|
||||||
CommercialMode string `yaml:"CommercialMode"`
|
TimeOfDay string `yaml:"TimeOfDay"`
|
||||||
NightMode string `yaml:"NightMode"`
|
Date string `yaml:"Date"`
|
||||||
IsFixedSetup int `yaml:"IsFixedSetup"`
|
EarthRotationSpeedupFactor int `yaml:"EarthRotationSpeedupFactor"`
|
||||||
StrictLapsChecking string `yaml:"StrictLapsChecking"`
|
Unofficial int `yaml:"Unofficial"`
|
||||||
HasOpenRegistration int `yaml:"HasOpenRegistration"`
|
CommercialMode string `yaml:"CommercialMode"`
|
||||||
HardcoreLevel int `yaml:"HardcoreLevel"`
|
NightMode string `yaml:"NightMode"`
|
||||||
NumJokerLaps int `yaml:"NumJokerLaps"`
|
IsFixedSetup int `yaml:"IsFixedSetup"`
|
||||||
IncidentLimit string `yaml:"IncidentLimit"`
|
StrictLapsChecking string `yaml:"StrictLapsChecking"`
|
||||||
FastRepairsLimit string `yaml:"FastRepairsLimit"`
|
HasOpenRegistration int `yaml:"HasOpenRegistration"`
|
||||||
GreenWhiteCheckeredLimit int `yaml:"GreenWhiteCheckeredLimit"`
|
HardcoreLevel int `yaml:"HardcoreLevel"`
|
||||||
} `yaml:"WeekendOptions"`
|
NumJokerLaps int `yaml:"NumJokerLaps"`
|
||||||
TelemetryOptions struct {
|
IncidentLimit string `yaml:"IncidentLimit"`
|
||||||
TelemetryDiskFile string `yaml:"TelemetryDiskFile"`
|
FastRepairsLimit string `yaml:"FastRepairsLimit"`
|
||||||
} `yaml:"TelemetryOptions"`
|
GreenWhiteCheckeredLimit int `yaml:"GreenWhiteCheckeredLimit"`
|
||||||
} `yaml:"WeekendInfo"`
|
} `yaml:"WeekendOptions"`
|
||||||
SessionInfo struct {
|
TelemetryOptions struct {
|
||||||
Sessions []struct {
|
TelemetryDiskFile string `yaml:"TelemetryDiskFile"`
|
||||||
SessionNum int `yaml:"SessionNum"`
|
} `yaml:"TelemetryOptions"`
|
||||||
SessionLaps string `yaml:"SessionLaps"`
|
} `yaml:"WeekendInfo"`
|
||||||
SessionTime string `yaml:"SessionTime"`
|
SessionInfo struct {
|
||||||
SessionNumLapsToAvg int `yaml:"SessionNumLapsToAvg"`
|
Sessions []struct {
|
||||||
SessionType string `yaml:"SessionType"`
|
SessionNum int `yaml:"SessionNum"`
|
||||||
SessionTrackRubberState string `yaml:"SessionTrackRubberState"`
|
SessionLaps string `yaml:"SessionLaps"`
|
||||||
SessionName string `yaml:"SessionName"`
|
SessionTime string `yaml:"SessionTime"`
|
||||||
SessionSubType interface{} `yaml:"SessionSubType"`
|
SessionNumLapsToAvg int `yaml:"SessionNumLapsToAvg"`
|
||||||
SessionSkipped int `yaml:"SessionSkipped"`
|
SessionType string `yaml:"SessionType"`
|
||||||
SessionRunGroupsUsed int `yaml:"SessionRunGroupsUsed"`
|
SessionTrackRubberState string `yaml:"SessionTrackRubberState"`
|
||||||
ResultsPositions interface{} `yaml:"ResultsPositions"`
|
SessionName string `yaml:"SessionName"`
|
||||||
ResultsFastestLap []struct {
|
SessionSubType interface{} `yaml:"SessionSubType"`
|
||||||
CarIdx int `yaml:"CarIdx"`
|
SessionSkipped int `yaml:"SessionSkipped"`
|
||||||
FastestLap int `yaml:"FastestLap"`
|
SessionRunGroupsUsed int `yaml:"SessionRunGroupsUsed"`
|
||||||
FastestTime int `yaml:"FastestTime"`
|
ResultsPositions interface{} `yaml:"ResultsPositions"`
|
||||||
} `yaml:"ResultsFastestLap"`
|
ResultsFastestLap []struct {
|
||||||
ResultsAverageLapTime int `yaml:"ResultsAverageLapTime"`
|
CarIdx int `yaml:"CarIdx"`
|
||||||
ResultsNumCautionFlags int `yaml:"ResultsNumCautionFlags"`
|
FastestLap int `yaml:"FastestLap"`
|
||||||
ResultsNumCautionLaps int `yaml:"ResultsNumCautionLaps"`
|
FastestTime int `yaml:"FastestTime"`
|
||||||
ResultsNumLeadChanges int `yaml:"ResultsNumLeadChanges"`
|
} `yaml:"ResultsFastestLap"`
|
||||||
ResultsLapsComplete int `yaml:"ResultsLapsComplete"`
|
ResultsAverageLapTime int `yaml:"ResultsAverageLapTime"`
|
||||||
ResultsOfficial int `yaml:"ResultsOfficial"`
|
ResultsNumCautionFlags int `yaml:"ResultsNumCautionFlags"`
|
||||||
} `yaml:"Sessions"`
|
ResultsNumCautionLaps int `yaml:"ResultsNumCautionLaps"`
|
||||||
} `yaml:"SessionInfo"`
|
ResultsNumLeadChanges int `yaml:"ResultsNumLeadChanges"`
|
||||||
CameraInfo struct {
|
ResultsLapsComplete int `yaml:"ResultsLapsComplete"`
|
||||||
Groups []struct {
|
ResultsOfficial int `yaml:"ResultsOfficial"`
|
||||||
GroupNum int `yaml:"GroupNum"`
|
} `yaml:"Sessions"`
|
||||||
GroupName string `yaml:"GroupName"`
|
} `yaml:"SessionInfo"`
|
||||||
Cameras []struct {
|
CameraInfo struct {
|
||||||
CameraNum int `yaml:"CameraNum"`
|
Groups []struct {
|
||||||
CameraName string `yaml:"CameraName"`
|
GroupNum int `yaml:"GroupNum"`
|
||||||
} `yaml:"Cameras"`
|
GroupName string `yaml:"GroupName"`
|
||||||
IsScenic bool `yaml:"IsScenic,omitempty"`
|
Cameras []struct {
|
||||||
} `yaml:"Groups"`
|
CameraNum int `yaml:"CameraNum"`
|
||||||
} `yaml:"CameraInfo"`
|
CameraName string `yaml:"CameraName"`
|
||||||
RadioInfo struct {
|
} `yaml:"Cameras"`
|
||||||
SelectedRadioNum int `yaml:"SelectedRadioNum"`
|
IsScenic bool `yaml:"IsScenic,omitempty"`
|
||||||
Radios []struct {
|
} `yaml:"Groups"`
|
||||||
RadioNum int `yaml:"RadioNum"`
|
} `yaml:"CameraInfo"`
|
||||||
HopCount int `yaml:"HopCount"`
|
RadioInfo struct {
|
||||||
NumFrequencies int `yaml:"NumFrequencies"`
|
SelectedRadioNum int `yaml:"SelectedRadioNum"`
|
||||||
TunedToFrequencyNum int `yaml:"TunedToFrequencyNum"`
|
Radios []struct {
|
||||||
ScanningIsOn int `yaml:"ScanningIsOn"`
|
RadioNum int `yaml:"RadioNum"`
|
||||||
Frequencies []struct {
|
HopCount int `yaml:"HopCount"`
|
||||||
FrequencyNum int `yaml:"FrequencyNum"`
|
NumFrequencies int `yaml:"NumFrequencies"`
|
||||||
FrequencyName string `yaml:"FrequencyName"`
|
TunedToFrequencyNum int `yaml:"TunedToFrequencyNum"`
|
||||||
Priority int `yaml:"Priority"`
|
ScanningIsOn int `yaml:"ScanningIsOn"`
|
||||||
CarIdx int `yaml:"CarIdx"`
|
Frequencies []struct {
|
||||||
EntryIdx int `yaml:"EntryIdx"`
|
FrequencyNum int `yaml:"FrequencyNum"`
|
||||||
ClubID int `yaml:"ClubID"`
|
FrequencyName string `yaml:"FrequencyName"`
|
||||||
CanScan int `yaml:"CanScan"`
|
Priority int `yaml:"Priority"`
|
||||||
CanSquawk int `yaml:"CanSquawk"`
|
CarIdx int `yaml:"CarIdx"`
|
||||||
Muted int `yaml:"Muted"`
|
EntryIdx int `yaml:"EntryIdx"`
|
||||||
IsMutable int `yaml:"IsMutable"`
|
ClubID int `yaml:"ClubID"`
|
||||||
IsDeletable int `yaml:"IsDeletable"`
|
CanScan int `yaml:"CanScan"`
|
||||||
} `yaml:"Frequencies"`
|
CanSquawk int `yaml:"CanSquawk"`
|
||||||
} `yaml:"Radios"`
|
Muted int `yaml:"Muted"`
|
||||||
} `yaml:"RadioInfo"`
|
IsMutable int `yaml:"IsMutable"`
|
||||||
DriverInfo struct {
|
IsDeletable int `yaml:"IsDeletable"`
|
||||||
DriverCarIdx int `yaml:"DriverCarIdx"`
|
} `yaml:"Frequencies"`
|
||||||
DriverUserID int `yaml:"DriverUserID"`
|
} `yaml:"Radios"`
|
||||||
PaceCarIdx int `yaml:"PaceCarIdx"`
|
} `yaml:"RadioInfo"`
|
||||||
DriverHeadPosX float64 `yaml:"DriverHeadPosX"`
|
DriverInfo struct {
|
||||||
DriverHeadPosY float64 `yaml:"DriverHeadPosY"`
|
DriverCarIdx int `yaml:"DriverCarIdx"`
|
||||||
DriverHeadPosZ float64 `yaml:"DriverHeadPosZ"`
|
DriverUserID int `yaml:"DriverUserID"`
|
||||||
DriverCarIdleRPM float64 `yaml:"DriverCarIdleRPM"`
|
PaceCarIdx int `yaml:"PaceCarIdx"`
|
||||||
DriverCarRedLine float64 `yaml:"DriverCarRedLine"`
|
DriverHeadPosX float64 `yaml:"DriverHeadPosX"`
|
||||||
DriverCarEngCylinderCount int `yaml:"DriverCarEngCylinderCount"`
|
DriverHeadPosY float64 `yaml:"DriverHeadPosY"`
|
||||||
DriverCarFuelKgPerLtr float64 `yaml:"DriverCarFuelKgPerLtr"`
|
DriverHeadPosZ float64 `yaml:"DriverHeadPosZ"`
|
||||||
DriverCarFuelMaxLtr float64 `yaml:"DriverCarFuelMaxLtr"`
|
DriverCarIdleRPM float64 `yaml:"DriverCarIdleRPM"`
|
||||||
DriverCarMaxFuelPct float64 `yaml:"DriverCarMaxFuelPct"`
|
DriverCarRedLine float64 `yaml:"DriverCarRedLine"`
|
||||||
DriverCarGearNumForward int `yaml:"DriverCarGearNumForward"`
|
DriverCarEngCylinderCount int `yaml:"DriverCarEngCylinderCount"`
|
||||||
DriverCarGearNeutral int `yaml:"DriverCarGearNeutral"`
|
DriverCarFuelKgPerLtr float64 `yaml:"DriverCarFuelKgPerLtr"`
|
||||||
DriverCarGearReverse int `yaml:"DriverCarGearReverse"`
|
DriverCarFuelMaxLtr float64 `yaml:"DriverCarFuelMaxLtr"`
|
||||||
DriverCarSLFirstRPM float64 `yaml:"DriverCarSLFirstRPM"`
|
DriverCarMaxFuelPct float64 `yaml:"DriverCarMaxFuelPct"`
|
||||||
DriverCarSLShiftRPM float64 `yaml:"DriverCarSLShiftRPM"`
|
DriverCarGearNumForward int `yaml:"DriverCarGearNumForward"`
|
||||||
DriverCarSLLastRPM float64 `yaml:"DriverCarSLLastRPM"`
|
DriverCarGearNeutral int `yaml:"DriverCarGearNeutral"`
|
||||||
DriverCarSLBlinkRPM float64 `yaml:"DriverCarSLBlinkRPM"`
|
DriverCarGearReverse int `yaml:"DriverCarGearReverse"`
|
||||||
DriverCarVersion string `yaml:"DriverCarVersion"`
|
DriverCarSLFirstRPM float64 `yaml:"DriverCarSLFirstRPM"`
|
||||||
DriverPitTrkPct float64 `yaml:"DriverPitTrkPct"`
|
DriverCarSLShiftRPM float64 `yaml:"DriverCarSLShiftRPM"`
|
||||||
DriverCarEstLapTime float64 `yaml:"DriverCarEstLapTime"`
|
DriverCarSLLastRPM float64 `yaml:"DriverCarSLLastRPM"`
|
||||||
DriverSetupName string `yaml:"DriverSetupName"`
|
DriverCarSLBlinkRPM float64 `yaml:"DriverCarSLBlinkRPM"`
|
||||||
DriverSetupIsModified int `yaml:"DriverSetupIsModified"`
|
DriverCarVersion string `yaml:"DriverCarVersion"`
|
||||||
DriverSetupLoadTypeName string `yaml:"DriverSetupLoadTypeName"`
|
DriverPitTrkPct float64 `yaml:"DriverPitTrkPct"`
|
||||||
DriverSetupPassedTech int `yaml:"DriverSetupPassedTech"`
|
DriverCarEstLapTime float64 `yaml:"DriverCarEstLapTime"`
|
||||||
DriverIncidentCount int `yaml:"DriverIncidentCount"`
|
DriverSetupName string `yaml:"DriverSetupName"`
|
||||||
Drivers []Driver `yaml:"Drivers"`
|
DriverSetupIsModified int `yaml:"DriverSetupIsModified"`
|
||||||
} `yaml:"DriverInfo"`
|
DriverSetupLoadTypeName string `yaml:"DriverSetupLoadTypeName"`
|
||||||
SplitTimeInfo struct {
|
DriverSetupPassedTech int `yaml:"DriverSetupPassedTech"`
|
||||||
Sectors []struct {
|
DriverIncidentCount int `yaml:"DriverIncidentCount"`
|
||||||
SectorNum int `yaml:"SectorNum"`
|
Drivers []Driver `yaml:"Drivers"`
|
||||||
SectorStartPct float64 `yaml:"SectorStartPct"`
|
} `yaml:"DriverInfo"`
|
||||||
} `yaml:"Sectors"`
|
SplitTimeInfo struct {
|
||||||
} `yaml:"SplitTimeInfo"`
|
Sectors []struct {
|
||||||
CarSetup struct {
|
SectorNum int `yaml:"SectorNum"`
|
||||||
UpdateCount int `yaml:"UpdateCount"`
|
SectorStartPct float64 `yaml:"SectorStartPct"`
|
||||||
TiresAero struct {
|
} `yaml:"Sectors"`
|
||||||
LeftFront struct {
|
} `yaml:"SplitTimeInfo"`
|
||||||
StartingPressure string `yaml:"StartingPressure"`
|
CarSetup struct {
|
||||||
LastHotPressure string `yaml:"LastHotPressure"`
|
UpdateCount int `yaml:"UpdateCount"`
|
||||||
LastTempsOMI string `yaml:"LastTempsOMI"`
|
TiresAero struct {
|
||||||
TreadRemaining string `yaml:"TreadRemaining"`
|
LeftFront struct {
|
||||||
} `yaml:"LeftFront"`
|
StartingPressure string `yaml:"StartingPressure"`
|
||||||
LeftRear struct {
|
LastHotPressure string `yaml:"LastHotPressure"`
|
||||||
StartingPressure string `yaml:"StartingPressure"`
|
LastTempsOMI string `yaml:"LastTempsOMI"`
|
||||||
LastHotPressure string `yaml:"LastHotPressure"`
|
TreadRemaining string `yaml:"TreadRemaining"`
|
||||||
LastTempsOMI string `yaml:"LastTempsOMI"`
|
} `yaml:"LeftFront"`
|
||||||
TreadRemaining string `yaml:"TreadRemaining"`
|
LeftRear struct {
|
||||||
} `yaml:"LeftRear"`
|
StartingPressure string `yaml:"StartingPressure"`
|
||||||
RightFront struct {
|
LastHotPressure string `yaml:"LastHotPressure"`
|
||||||
StartingPressure string `yaml:"StartingPressure"`
|
LastTempsOMI string `yaml:"LastTempsOMI"`
|
||||||
LastHotPressure string `yaml:"LastHotPressure"`
|
TreadRemaining string `yaml:"TreadRemaining"`
|
||||||
LastTempsIMO string `yaml:"LastTempsIMO"`
|
} `yaml:"LeftRear"`
|
||||||
TreadRemaining string `yaml:"TreadRemaining"`
|
RightFront struct {
|
||||||
} `yaml:"RightFront"`
|
StartingPressure string `yaml:"StartingPressure"`
|
||||||
RightRear struct {
|
LastHotPressure string `yaml:"LastHotPressure"`
|
||||||
StartingPressure string `yaml:"StartingPressure"`
|
LastTempsIMO string `yaml:"LastTempsIMO"`
|
||||||
LastHotPressure string `yaml:"LastHotPressure"`
|
TreadRemaining string `yaml:"TreadRemaining"`
|
||||||
LastTempsIMO string `yaml:"LastTempsIMO"`
|
} `yaml:"RightFront"`
|
||||||
TreadRemaining string `yaml:"TreadRemaining"`
|
RightRear struct {
|
||||||
} `yaml:"RightRear"`
|
StartingPressure string `yaml:"StartingPressure"`
|
||||||
} `yaml:"TiresAero"`
|
LastHotPressure string `yaml:"LastHotPressure"`
|
||||||
Chassis struct {
|
LastTempsIMO string `yaml:"LastTempsIMO"`
|
||||||
Front struct {
|
TreadRemaining string `yaml:"TreadRemaining"`
|
||||||
ArbSetting int `yaml:"ArbSetting"`
|
} `yaml:"RightRear"`
|
||||||
ToeIn string `yaml:"ToeIn"`
|
} `yaml:"TiresAero"`
|
||||||
FuelLevel string `yaml:"FuelLevel"`
|
Chassis struct {
|
||||||
CrossWeight string `yaml:"CrossWeight"`
|
Front struct {
|
||||||
} `yaml:"Front"`
|
ArbSetting int `yaml:"ArbSetting"`
|
||||||
LeftFront struct {
|
ToeIn string `yaml:"ToeIn"`
|
||||||
CornerWeight string `yaml:"CornerWeight"`
|
FuelLevel string `yaml:"FuelLevel"`
|
||||||
RideHeight string `yaml:"RideHeight"`
|
CrossWeight string `yaml:"CrossWeight"`
|
||||||
SpringPerchOffset string `yaml:"SpringPerchOffset"`
|
} `yaml:"Front"`
|
||||||
Camber string `yaml:"Camber"`
|
LeftFront struct {
|
||||||
} `yaml:"LeftFront"`
|
CornerWeight string `yaml:"CornerWeight"`
|
||||||
LeftRear struct {
|
RideHeight string `yaml:"RideHeight"`
|
||||||
CornerWeight string `yaml:"CornerWeight"`
|
SpringPerchOffset string `yaml:"SpringPerchOffset"`
|
||||||
RideHeight string `yaml:"RideHeight"`
|
Camber string `yaml:"Camber"`
|
||||||
SpringPerchOffset string `yaml:"SpringPerchOffset"`
|
} `yaml:"LeftFront"`
|
||||||
Camber string `yaml:"Camber"`
|
LeftRear struct {
|
||||||
ToeIn string `yaml:"ToeIn"`
|
CornerWeight string `yaml:"CornerWeight"`
|
||||||
} `yaml:"LeftRear"`
|
RideHeight string `yaml:"RideHeight"`
|
||||||
InCarDials struct {
|
SpringPerchOffset string `yaml:"SpringPerchOffset"`
|
||||||
DisplayPage string `yaml:"DisplayPage"`
|
Camber string `yaml:"Camber"`
|
||||||
BrakePressureBias string `yaml:"BrakePressureBias"`
|
ToeIn string `yaml:"ToeIn"`
|
||||||
} `yaml:"InCarDials"`
|
} `yaml:"LeftRear"`
|
||||||
RightFront struct {
|
InCarDials struct {
|
||||||
CornerWeight string `yaml:"CornerWeight"`
|
DisplayPage string `yaml:"DisplayPage"`
|
||||||
RideHeight string `yaml:"RideHeight"`
|
BrakePressureBias string `yaml:"BrakePressureBias"`
|
||||||
SpringPerchOffset string `yaml:"SpringPerchOffset"`
|
} `yaml:"InCarDials"`
|
||||||
Camber string `yaml:"Camber"`
|
RightFront struct {
|
||||||
} `yaml:"RightFront"`
|
CornerWeight string `yaml:"CornerWeight"`
|
||||||
RightRear struct {
|
RideHeight string `yaml:"RideHeight"`
|
||||||
CornerWeight string `yaml:"CornerWeight"`
|
SpringPerchOffset string `yaml:"SpringPerchOffset"`
|
||||||
RideHeight string `yaml:"RideHeight"`
|
Camber string `yaml:"Camber"`
|
||||||
SpringPerchOffset string `yaml:"SpringPerchOffset"`
|
} `yaml:"RightFront"`
|
||||||
Camber string `yaml:"Camber"`
|
RightRear struct {
|
||||||
ToeIn string `yaml:"ToeIn"`
|
CornerWeight string `yaml:"CornerWeight"`
|
||||||
} `yaml:"RightRear"`
|
RideHeight string `yaml:"RideHeight"`
|
||||||
Rear struct {
|
SpringPerchOffset string `yaml:"SpringPerchOffset"`
|
||||||
ArbSetting int `yaml:"ArbSetting"`
|
Camber string `yaml:"Camber"`
|
||||||
WingSetting int `yaml:"WingSetting"`
|
ToeIn string `yaml:"ToeIn"`
|
||||||
} `yaml:"Rear"`
|
} `yaml:"RightRear"`
|
||||||
} `yaml:"Chassis"`
|
Rear struct {
|
||||||
} `yaml:"CarSetup"`
|
ArbSetting int `yaml:"ArbSetting"`
|
||||||
}
|
WingSetting int `yaml:"WingSetting"`
|
||||||
|
} `yaml:"Rear"`
|
||||||
// Driver ...
|
} `yaml:"Chassis"`
|
||||||
type Driver struct {
|
} `yaml:"CarSetup"`
|
||||||
CarIdx int `yaml:"CarIdx"`
|
}
|
||||||
UserName string `yaml:"UserName"`
|
|
||||||
AbbrevName string `yaml:"AbbrevName"`
|
// Driver ...
|
||||||
Initials string `yaml:"Initials"`
|
type Driver struct {
|
||||||
UserID int `yaml:"UserID"`
|
CarIdx int `yaml:"CarIdx"`
|
||||||
TeamID int `yaml:"TeamID"`
|
UserName string `yaml:"UserName"`
|
||||||
TeamName string `yaml:"TeamName"`
|
AbbrevName string `yaml:"AbbrevName"`
|
||||||
CarNumber string `yaml:"CarNumber"`
|
Initials string `yaml:"Initials"`
|
||||||
CarNumberRaw int `yaml:"CarNumberRaw"`
|
UserID int `yaml:"UserID"`
|
||||||
CarPath string `yaml:"CarPath"`
|
TeamID int `yaml:"TeamID"`
|
||||||
CarClassID int `yaml:"CarClassID"`
|
TeamName string `yaml:"TeamName"`
|
||||||
CarID int `yaml:"CarID"`
|
CarNumber string `yaml:"CarNumber"`
|
||||||
CarIsPaceCar int `yaml:"CarIsPaceCar"`
|
CarNumberRaw int `yaml:"CarNumberRaw"`
|
||||||
CarIsAI int `yaml:"CarIsAI"`
|
CarPath string `yaml:"CarPath"`
|
||||||
CarScreenName string `yaml:"CarScreenName"`
|
CarClassID int `yaml:"CarClassID"`
|
||||||
CarScreenNameShort string `yaml:"CarScreenNameShort"`
|
CarID int `yaml:"CarID"`
|
||||||
CarClassShortName string `yaml:"CarClassShortName"`
|
CarIsPaceCar int `yaml:"CarIsPaceCar"`
|
||||||
CarClassRelSpeed int `yaml:"CarClassRelSpeed"`
|
CarIsAI int `yaml:"CarIsAI"`
|
||||||
CarClassLicenseLevel int `yaml:"CarClassLicenseLevel"`
|
CarScreenName string `yaml:"CarScreenName"`
|
||||||
CarClassMaxFuelPct string `yaml:"CarClassMaxFuelPct"`
|
CarScreenNameShort string `yaml:"CarScreenNameShort"`
|
||||||
CarClassWeightPenalty string `yaml:"CarClassWeightPenalty"`
|
CarClassShortName string `yaml:"CarClassShortName"`
|
||||||
CarClassPowerAdjust string `yaml:"CarClassPowerAdjust"`
|
CarClassRelSpeed int `yaml:"CarClassRelSpeed"`
|
||||||
CarClassDryTireSetLimit string `yaml:"CarClassDryTireSetLimit"`
|
CarClassLicenseLevel int `yaml:"CarClassLicenseLevel"`
|
||||||
CarClassColor int `yaml:"CarClassColor"`
|
CarClassMaxFuelPct string `yaml:"CarClassMaxFuelPct"`
|
||||||
CarClassEstLapTime float64 `yaml:"CarClassEstLapTime"`
|
CarClassWeightPenalty string `yaml:"CarClassWeightPenalty"`
|
||||||
IRating int `yaml:"IRating"`
|
CarClassPowerAdjust string `yaml:"CarClassPowerAdjust"`
|
||||||
LicLevel int `yaml:"LicLevel"`
|
CarClassDryTireSetLimit string `yaml:"CarClassDryTireSetLimit"`
|
||||||
LicSubLevel int `yaml:"LicSubLevel"`
|
CarClassColor int `yaml:"CarClassColor"`
|
||||||
LicString string `yaml:"LicString"`
|
CarClassEstLapTime float64 `yaml:"CarClassEstLapTime"`
|
||||||
LicColor string `yaml:"LicColor"`
|
IRating int `yaml:"IRating"`
|
||||||
IsSpectator int `yaml:"IsSpectator"`
|
LicLevel int `yaml:"LicLevel"`
|
||||||
CarDesignStr string `yaml:"CarDesignStr"`
|
LicSubLevel int `yaml:"LicSubLevel"`
|
||||||
HelmetDesignStr string `yaml:"HelmetDesignStr"`
|
LicString string `yaml:"LicString"`
|
||||||
SuitDesignStr string `yaml:"SuitDesignStr"`
|
LicColor string `yaml:"LicColor"`
|
||||||
CarNumberDesignStr string `yaml:"CarNumberDesignStr"`
|
IsSpectator int `yaml:"IsSpectator"`
|
||||||
CarSponsor1 int `yaml:"CarSponsor_1"`
|
CarDesignStr string `yaml:"CarDesignStr"`
|
||||||
CarSponsor2 int `yaml:"CarSponsor_2"`
|
HelmetDesignStr string `yaml:"HelmetDesignStr"`
|
||||||
CurDriverIncidentCount int `yaml:"CurDriverIncidentCount"`
|
SuitDesignStr string `yaml:"SuitDesignStr"`
|
||||||
TeamIncidentCount int `yaml:"TeamIncidentCount"`
|
CarNumberDesignStr string `yaml:"CarNumberDesignStr"`
|
||||||
}
|
CarSponsor1 int `yaml:"CarSponsor_1"`
|
||||||
|
CarSponsor2 int `yaml:"CarSponsor_2"`
|
||||||
// parseSessionInfo will parse the sessionInfo buffer into the SessionInfoYAML
|
CurDriverIncidentCount int `yaml:"CurDriverIncidentCount"`
|
||||||
// struct
|
TeamIncidentCount int `yaml:"TeamIncidentCount"`
|
||||||
func parseSessionInfo(data []byte) (*SessionInfoYAML, error) {
|
}
|
||||||
var sessionInfo SessionInfoYAML
|
|
||||||
err := yaml.Unmarshal(data, &sessionInfo)
|
// readSessionInfo will read the session info yaml out of the telemetry data
|
||||||
if err != nil {
|
func (i *IBT) readSessionInfo() error {
|
||||||
return nil, err
|
sessionInfoStringRaw := make([]byte, i.Headers.SessionInfoLength)
|
||||||
}
|
_, err := i.File.ReadAt(sessionInfoStringRaw, int64(i.Headers.SessionInfoOffset))
|
||||||
|
if err != nil {
|
||||||
return &sessionInfo, nil
|
return fmt.Errorf("Failed to read sessionInfoString from file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToString will return a readable string of the struct
|
// Write to the output file
|
||||||
func (s *SessionInfoYAML) ToString() string {
|
if i.Opts.IBTExport {
|
||||||
stringified, _ := json.MarshalIndent(s, "", " ")
|
err := i.exportIBT(sessionInfoStringRaw[:], int64(i.Headers.SessionInfoOffset))
|
||||||
return string(stringified)
|
if err != nil {
|
||||||
}
|
log.Printf("Failed to export offline telemetry data: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i.SessionInfo, err = parseSessionInfo(sessionInfoStringRaw, i.Headers.SessionInfoLength)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Unable to parse SessionInfoString from file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to YAML output file
|
||||||
|
if i.Opts.SessionInfoExport {
|
||||||
|
err := i.exportYAML()
|
||||||
|
if err != nil {
|
||||||
|
i.Opts.Logger.Debug("Failed to export YAML string", "err", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseSessionInfo will parse the sessionInfo buffer into the SessionInfoYAML
|
||||||
|
// struct
|
||||||
|
func parseSessionInfo(buf []byte, len int32) (*SessionInfoYAML, error) {
|
||||||
|
// this seems not to work on windows
|
||||||
|
// windows := true
|
||||||
|
var sessionInfo SessionInfoYAML
|
||||||
|
dataBuffer := buf
|
||||||
|
|
||||||
|
// FOR WINDOWS
|
||||||
|
// if windows {
|
||||||
|
decoder := charmap.Windows1252.NewDecoder()
|
||||||
|
buf, err := decoder.Bytes(buf)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
dataBuffer = []byte(strings.TrimRight(string(buf[:len]), "\x00"))
|
||||||
|
// }
|
||||||
|
|
||||||
|
err = yaml.Unmarshal(dataBuffer, &sessionInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &sessionInfo, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToString will return a readable string of the struct
|
||||||
|
func (s *SessionInfoYAML) ToString() string {
|
||||||
|
stringified, _ := json.MarshalIndent(s, "", " ")
|
||||||
|
return string(stringified)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package sharedMem
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Memory is shared memory struct
|
||||||
|
type Memory struct {
|
||||||
|
m *shmi
|
||||||
|
pos int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create is create shared memory
|
||||||
|
func Create(name string, size uint32) (*Memory, error) {
|
||||||
|
m, err := create(name, size)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &Memory{m, 0}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open is open exist shared memory
|
||||||
|
func Open(name string, size uint32) (*Memory, error) {
|
||||||
|
m, err := open(name, size)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &Memory{m, 0}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close is close & discard shared memory
|
||||||
|
func (o *Memory) Close() (err error) {
|
||||||
|
if o.m != nil {
|
||||||
|
err = o.m.close()
|
||||||
|
if err == nil {
|
||||||
|
o.m = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read is read shared memory (current position)
|
||||||
|
func (o *Memory) Read(p []byte) (n int, err error) {
|
||||||
|
n, err = o.ReadAt(p, o.pos)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
o.pos += int64(n)
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadAt is read shared memory (offset)
|
||||||
|
func (o *Memory) ReadAt(p []byte, off int64) (n int, err error) {
|
||||||
|
return o.m.readAt(p, off)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seek is move read/write position at shared memory
|
||||||
|
func (o *Memory) Seek(offset int64, whence int) (int64, error) {
|
||||||
|
switch whence {
|
||||||
|
case io.SeekStart:
|
||||||
|
offset += int64(0)
|
||||||
|
case io.SeekCurrent:
|
||||||
|
offset += o.pos
|
||||||
|
case io.SeekEnd:
|
||||||
|
offset += int64(o.m.size)
|
||||||
|
}
|
||||||
|
if offset < 0 || offset >= int64(o.m.size) {
|
||||||
|
return 0, fmt.Errorf("invalid offset")
|
||||||
|
}
|
||||||
|
o.pos = offset
|
||||||
|
return offset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write is write shared memory (current position)
|
||||||
|
func (o *Memory) Write(p []byte) (n int, err error) {
|
||||||
|
n, err = o.WriteAt(p, o.pos)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
o.pos += int64(n)
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteAt is write shared memory (offset)
|
||||||
|
func (o *Memory) WriteAt(p []byte, off int64) (n int, err error) {
|
||||||
|
return o.m.writeAt(p, off)
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
//go:build darwin && cgo
|
||||||
|
// +build darwin,cgo
|
||||||
|
|
||||||
|
package sharedMem
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/errno.h>
|
||||||
|
|
||||||
|
int _create(const char* name, int size, int flag) {
|
||||||
|
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
|
||||||
|
|
||||||
|
int fd = shm_open(name, flag, mode);
|
||||||
|
if (fd < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct stat mapstat;
|
||||||
|
int ret = fstat(fd, &mapstat);
|
||||||
|
if (ret != -1 && mapstat.st_size == 0) {
|
||||||
|
if (ftruncate(fd, size) != 0) {
|
||||||
|
close(fd);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
} else if (ret == -1) {
|
||||||
|
close(fd);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Create(const char* name, int size) {
|
||||||
|
int flag = O_RDWR | O_CREAT;
|
||||||
|
return _create(name, size, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Open(const char* name, int size) {
|
||||||
|
int flag = O_RDWR;
|
||||||
|
return _create(name, size, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* Map(int fd, int size) {
|
||||||
|
void* p = mmap(
|
||||||
|
NULL, size,
|
||||||
|
PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED, fd, 0);
|
||||||
|
if (p == MAP_FAILED) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Close(int fd, void* p, int size) {
|
||||||
|
if (p != NULL) {
|
||||||
|
munmap(p, size);
|
||||||
|
}
|
||||||
|
if (fd != 0) {
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Delete(const char* name) {
|
||||||
|
shm_unlink(name);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
type shmi struct {
|
||||||
|
name string
|
||||||
|
fd C.int
|
||||||
|
v unsafe.Pointer
|
||||||
|
size uint32
|
||||||
|
parent bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// create shared memory. return shmi object.
|
||||||
|
// name should not be more than 31 bytes.
|
||||||
|
func create(name string, size uint32) (*shmi, error) {
|
||||||
|
name = "/" + name
|
||||||
|
|
||||||
|
fd := C.Create(C.CString(name), C.int(size))
|
||||||
|
if fd < 0 {
|
||||||
|
return nil, fmt.Errorf("create")
|
||||||
|
}
|
||||||
|
|
||||||
|
v := C.Map(fd, C.int(size))
|
||||||
|
if v == nil {
|
||||||
|
C.Close(fd, nil, C.int(size))
|
||||||
|
C.Delete(C.CString(name))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &shmi{name, fd, v, size, true}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// open shared memory. return shmi object.
|
||||||
|
// name should not be more than 31 bytes.
|
||||||
|
func open(name string, size uint32) (*shmi, error) {
|
||||||
|
name = "/" + name
|
||||||
|
|
||||||
|
fd := C.Open(C.CString(name), C.int(size))
|
||||||
|
if fd < 0 {
|
||||||
|
return nil, fmt.Errorf("open")
|
||||||
|
}
|
||||||
|
|
||||||
|
v := C.Map(fd, C.int(size))
|
||||||
|
if v == nil {
|
||||||
|
C.Close(fd, nil, C.int(size))
|
||||||
|
C.Delete(C.CString(name))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &shmi{name, fd, v, size, false}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *shmi) close() error {
|
||||||
|
if o.v != nil {
|
||||||
|
C.Close(o.fd, o.v, C.int(o.size))
|
||||||
|
o.v = nil
|
||||||
|
}
|
||||||
|
if o.parent {
|
||||||
|
C.Delete(C.CString(o.name))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// read shared memory. return read size.
|
||||||
|
func (o *shmi) readAt(p []byte, off int64) (n int, err error) {
|
||||||
|
if off >= int64(o.size) {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
if max := int64(o.size) - off; int64(len(p)) > max {
|
||||||
|
p = p[:max]
|
||||||
|
}
|
||||||
|
return copyPtr2Slice(uintptr(o.v), p, off, o.size), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// write shared memory. return write size.
|
||||||
|
func (o *shmi) writeAt(p []byte, off int64) (n int, err error) {
|
||||||
|
if off >= int64(o.size) {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
if max := int64(o.size) - off; int64(len(p)) > max {
|
||||||
|
p = p[:max]
|
||||||
|
}
|
||||||
|
return copySlice2Ptr(p, uintptr(o.v), off, o.size), nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
//go:build linux && cgo
|
||||||
|
// +build linux,cgo
|
||||||
|
|
||||||
|
package sharedMem
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -lrt
|
||||||
|
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int _create(const char* name, int size, int flag) {
|
||||||
|
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
|
||||||
|
|
||||||
|
int fd = shm_open(name, flag, mode);
|
||||||
|
if (fd < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ftruncate(fd, size) != 0) {
|
||||||
|
close(fd);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Create(const char* name, int size) {
|
||||||
|
int flag = O_RDWR | O_CREAT;
|
||||||
|
return _create(name, size, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Open(const char* name, int size) {
|
||||||
|
int flag = O_RDWR;
|
||||||
|
return _create(name, size, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* Map(int fd, int size) {
|
||||||
|
void* p = mmap(
|
||||||
|
NULL, size,
|
||||||
|
PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED, fd, 0);
|
||||||
|
if (p == MAP_FAILED) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Close(int fd, void* p, int size) {
|
||||||
|
if (p != NULL) {
|
||||||
|
munmap(p, size);
|
||||||
|
}
|
||||||
|
if (fd != 0) {
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Delete(const char* name) {
|
||||||
|
shm_unlink(name);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
type shmi struct {
|
||||||
|
name string
|
||||||
|
fd C.int
|
||||||
|
v unsafe.Pointer
|
||||||
|
size uint32
|
||||||
|
parent bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// create shared memory. return shmi object.
|
||||||
|
func create(name string, size uint32) (*shmi, error) {
|
||||||
|
name = "/" + name
|
||||||
|
|
||||||
|
fd := C.Create(C.CString(name), C.int(size))
|
||||||
|
if fd < 0 {
|
||||||
|
return nil, fmt.Errorf("create")
|
||||||
|
}
|
||||||
|
|
||||||
|
v := C.Map(fd, C.int(size))
|
||||||
|
if v == nil {
|
||||||
|
C.Close(fd, nil, C.int(size))
|
||||||
|
C.Delete(C.CString(name))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &shmi{name, fd, v, size, true}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// open shared memory. return shmi object.
|
||||||
|
func open(name string, size uint32) (*shmi, error) {
|
||||||
|
name = "/" + name
|
||||||
|
|
||||||
|
fd := C.Open(C.CString(name), C.int(size))
|
||||||
|
if fd < 0 {
|
||||||
|
return nil, fmt.Errorf("open")
|
||||||
|
}
|
||||||
|
|
||||||
|
v := C.Map(fd, C.int(size))
|
||||||
|
if v == nil {
|
||||||
|
C.Close(fd, nil, C.int(size))
|
||||||
|
C.Delete(C.CString(name))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &shmi{name, fd, v, size, false}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *shmi) close() error {
|
||||||
|
if o.v != nil {
|
||||||
|
C.Close(o.fd, o.v, C.int(o.size))
|
||||||
|
o.v = nil
|
||||||
|
}
|
||||||
|
if o.parent {
|
||||||
|
C.Delete(C.CString(o.name))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// read shared memory. return read size.
|
||||||
|
func (o *shmi) readAt(p []byte, off int64) (n int, err error) {
|
||||||
|
if off >= int64(o.size) {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
if max := int64(o.size) - off; int64(len(p)) > max {
|
||||||
|
p = p[:max]
|
||||||
|
}
|
||||||
|
return copyPtr2Slice(uintptr(o.v), p, off, o.size), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// write shared memory. return write size.
|
||||||
|
func (o *shmi) writeAt(p []byte, off int64) (n int, err error) {
|
||||||
|
if off >= int64(o.size) {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
if max := int64(o.size) - off; int64(len(p)) > max {
|
||||||
|
p = p[:max]
|
||||||
|
}
|
||||||
|
return copySlice2Ptr(p, uintptr(o.v), off, o.size), nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
//go:build windows && cgo
|
||||||
|
// +build windows,cgo
|
||||||
|
|
||||||
|
package sharedMem
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
type shmi struct {
|
||||||
|
h windows.Handle
|
||||||
|
v uintptr
|
||||||
|
size uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// create shared memory. return shmi object.
|
||||||
|
func create(name string, size uint32) (*shmi, error) {
|
||||||
|
fnPtr, _ := windows.UTF16PtrFromString(name)
|
||||||
|
|
||||||
|
flProtect := uint32(windows.PAGE_READONLY)
|
||||||
|
|
||||||
|
h, errno := windows.CreateFileMapping(
|
||||||
|
windows.InvalidHandle,
|
||||||
|
nil,
|
||||||
|
flProtect,
|
||||||
|
0,
|
||||||
|
size,
|
||||||
|
fnPtr)
|
||||||
|
if h == 0 {
|
||||||
|
log.Fatal("could not open memmap file: ", errno)
|
||||||
|
}
|
||||||
|
|
||||||
|
addr, errno := windows.MapViewOfFile(h,
|
||||||
|
windows.FILE_MAP_READ,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
uintptr(size))
|
||||||
|
if addr == 0 {
|
||||||
|
log.Printf("error in MapViewOfFile: %v", errno)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &shmi{h, addr, size}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// open shared memory. return shmi object.
|
||||||
|
func open(name string, size uint32) (*shmi, error) {
|
||||||
|
return create(name, size)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *shmi) close() error {
|
||||||
|
if o.v != uintptr(0) {
|
||||||
|
windows.UnmapViewOfFile(o.v)
|
||||||
|
o.v = uintptr(0)
|
||||||
|
}
|
||||||
|
if o.h != windows.InvalidHandle {
|
||||||
|
windows.CloseHandle(o.h)
|
||||||
|
o.h = windows.InvalidHandle
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// read shared memory. return read size.
|
||||||
|
func (o *shmi) readAt(p []byte, off int64) (n int, err error) {
|
||||||
|
if off >= int64(o.size) {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
if max := int64(o.size) - off; int64(len(p)) > max {
|
||||||
|
p = p[:max]
|
||||||
|
}
|
||||||
|
return copyPtr2Slice(o.v, p, off, o.size), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// write shared memory. return write size.
|
||||||
|
func (o *shmi) writeAt(p []byte, off int64) (n int, err error) {
|
||||||
|
if off >= int64(o.size) {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
if max := int64(o.size) - off; int64(len(p)) > max {
|
||||||
|
p = p[:max]
|
||||||
|
}
|
||||||
|
return copySlice2Ptr(p, o.v, off, o.size), nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package sharedMem
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func copySlice2Ptr(b []byte, p uintptr, off int64, size uint32) int {
|
||||||
|
bb := unsafe.Slice((*byte)(*(*unsafe.Pointer)(unsafe.Pointer(&p))), int(size))
|
||||||
|
return copy(bb[off:], b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyPtr2Slice(p uintptr, b []byte, off int64, size uint32) int {
|
||||||
|
bb := unsafe.Slice((*byte)(*(*unsafe.Pointer)(unsafe.Pointer(&p))), int(size))
|
||||||
|
return copy(b, bb[off:size])
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,19 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func HexDump(buf []byte) {
|
||||||
|
fmt.Printf("\n============ HEX DUMP =============\n")
|
||||||
|
for k := 0; k < len(buf); k++ {
|
||||||
|
if k%4 == 0 && k > 0 {
|
||||||
|
fmt.Printf(" ")
|
||||||
|
}
|
||||||
|
|
||||||
|
if k%16 == 0 && k > 0 {
|
||||||
|
fmt.Printf("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("%02X", buf[k])
|
||||||
|
}
|
||||||
|
fmt.Printf("\n============ HEX DUMP =============\n")
|
||||||
|
}
|
||||||
+387
-177
@@ -1,177 +1,387 @@
|
|||||||
package ibtReader
|
package goirsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
"time"
|
||||||
|
)
|
||||||
const (
|
|
||||||
VarHeaderSize = 144
|
const (
|
||||||
IRSDK_char = 0
|
VarHeaderSize = 144
|
||||||
IRSDK_bool = 1
|
IRSDK_char = 0
|
||||||
IRSDK_int = 2
|
IRSDK_bool = 1
|
||||||
IRSDK_bitField = 3
|
IRSDK_int = 2
|
||||||
IRSDK_float = 4
|
IRSDK_bitField = 3
|
||||||
IRSDK_double = 5
|
IRSDK_float = 4
|
||||||
)
|
IRSDK_double = 5
|
||||||
|
Running IRacingState = iota
|
||||||
// I think I can make an interface if IRSDK types with available types and
|
Paused
|
||||||
// that they need a parser (reads and type coerces I guess)
|
Ended
|
||||||
var (
|
Failed
|
||||||
VarTypes = map[int]VarType{
|
Unknown
|
||||||
IRSDK_char: {1, "irsdk_char"},
|
)
|
||||||
IRSDK_bool: {1, "irsdk_bool"},
|
|
||||||
IRSDK_int: {4, "irsdk_int"},
|
// I think I can make an interface if IRSDK types with available types and
|
||||||
IRSDK_bitField: {4, "irsdk_bitField"},
|
// that they need a parser (reads and type coerces I guess)
|
||||||
IRSDK_float: {4, "irsdk_float"},
|
var (
|
||||||
IRSDK_double: {8, "irsdk_double"},
|
VarTypes = map[int]VarType{
|
||||||
}
|
IRSDK_char: {1, "irsdk_char"},
|
||||||
)
|
IRSDK_bool: {1, "irsdk_bool"},
|
||||||
|
IRSDK_int: {4, "irsdk_int"},
|
||||||
type VarType struct {
|
IRSDK_bitField: {4, "irsdk_bitField"},
|
||||||
Size int // Size is the var type size in bytes
|
IRSDK_float: {4, "irsdk_float"},
|
||||||
Name string // Name is the irsdk var name
|
IRSDK_double: {8, "irsdk_double"},
|
||||||
}
|
}
|
||||||
|
)
|
||||||
type IBTVar struct {
|
|
||||||
Type int32
|
type (
|
||||||
Offset int32
|
IRacingState int
|
||||||
Count int32
|
VarType struct {
|
||||||
CountAsTime bool
|
Size int // Size is the var type size in bytes
|
||||||
Padding [3]byte
|
Name string // Name is the irsdk var name
|
||||||
Name [32]byte
|
}
|
||||||
Description [64]byte
|
)
|
||||||
Unit [32]byte
|
|
||||||
}
|
type IBTVar struct {
|
||||||
|
Type int32
|
||||||
type Var struct {
|
Offset int32
|
||||||
Type int32
|
Count int32
|
||||||
Offset int32
|
CountAsTime bool
|
||||||
Count int32
|
Padding [3]byte
|
||||||
CountAsTime bool
|
Name [32]byte
|
||||||
Name string
|
Description [64]byte
|
||||||
Description string
|
Unit [32]byte
|
||||||
Unit string
|
}
|
||||||
// TODO
|
|
||||||
// Create an interface for this value
|
type Var struct {
|
||||||
// Represent the IRSDK var types with a struct each that implements the Parse
|
Type int32
|
||||||
// method or something like that I guess
|
Offset int32
|
||||||
Value interface{}
|
Count int32
|
||||||
}
|
CountAsTime bool
|
||||||
|
Name string
|
||||||
func (v *IBTVar) ToString() string {
|
Description string
|
||||||
return fmt.Sprintf(
|
Unit string
|
||||||
"Type: %5d (0x%08x)\n"+
|
// TODO
|
||||||
"Offset: %5d (0x%08x)\n"+
|
// Create an interface for this value
|
||||||
"Count: %5d (0x%08x)\n"+
|
// Represent the IRSDK var types with a struct each that implements the Parse
|
||||||
"CountAsTime: %5t\n"+
|
// method or something like that I guess
|
||||||
"Name: %s\n"+
|
Value interface{}
|
||||||
"Description: %s\n"+
|
}
|
||||||
"Unit: %s",
|
|
||||||
v.Type, v.Type, v.Offset, v.Offset, v.Count, v.Count,
|
func (v *Var) ToString() string {
|
||||||
v.CountAsTime, v.Name, v.Description, v.Unit,
|
return fmt.Sprintf(
|
||||||
)
|
"Type: %5d (0x%08x)\n"+
|
||||||
}
|
"Offset: %5d (0x%08x)\n"+
|
||||||
|
"Count: %5d (0x%08x)\n"+
|
||||||
type varBuffer struct {
|
"CountAsTime: %5t\n"+
|
||||||
tickCount int
|
"Name: %s\n"+
|
||||||
bufOffset int
|
"Description: %s\n"+
|
||||||
}
|
"Unit: %s",
|
||||||
|
v.Type, v.Type, v.Offset, v.Offset, v.Count, v.Count,
|
||||||
type TelemetryVars struct {
|
v.CountAsTime, v.Name, v.Description, v.Unit,
|
||||||
LastVersion int
|
)
|
||||||
Vars map[string]Var
|
}
|
||||||
}
|
|
||||||
|
func (v *IBTVar) ToString() string {
|
||||||
func (i *IBT) readVariablerHeaders() error {
|
return fmt.Sprintf(
|
||||||
i.Vars = &TelemetryVars{Vars: make(map[string]Var, i.Headers.NumVars)}
|
"Type: %5d (0x%08x)\n"+
|
||||||
|
"Offset: %5d (0x%08x)\n"+
|
||||||
var k int32
|
"Count: %5d (0x%08x)\n"+
|
||||||
for k = 0; k < i.Headers.NumVars; k++ {
|
"CountAsTime: %5t\n"+
|
||||||
rbuf := make([]byte, VarHeaderSize)
|
"Name: %s\n"+
|
||||||
|
"Description: %s\n"+
|
||||||
_, err := i.File.ReadAt(rbuf, int64(i.Headers.VarHeaderOffset+k*VarHeaderSize))
|
"Unit: %s",
|
||||||
if err != nil {
|
v.Type, v.Type, v.Offset, v.Offset, v.Count, v.Count,
|
||||||
return err
|
v.CountAsTime, v.Name, v.Description, v.Unit,
|
||||||
}
|
)
|
||||||
|
}
|
||||||
var dst IBTVar
|
|
||||||
err = binary.Read(bytes.NewBuffer(rbuf[:]), binary.LittleEndian, &dst)
|
type varBuffer struct {
|
||||||
if err != nil {
|
TickCount int32
|
||||||
return err
|
BufOffset int32
|
||||||
}
|
}
|
||||||
|
|
||||||
v := Var{
|
type TelemetryVars struct {
|
||||||
Type: dst.Type,
|
Tick int32 // Keeps track of the current data buffer tick
|
||||||
Offset: dst.Offset,
|
RecorderTick int32 // Counts from 0 when creating a telemetry file from a
|
||||||
Count: dst.Count,
|
// replay or live data
|
||||||
CountAsTime: dst.CountAsTime,
|
Vars map[string]Var // Variables content
|
||||||
Name: strings.TrimRight(string(dst.Name[:]), "\x00"),
|
}
|
||||||
Description: strings.TrimRight(string(dst.Description[:]), "\x00"),
|
|
||||||
Unit: strings.TrimRight(string(dst.Unit[:]), "\x00"),
|
func (i *IBT) readVariablerHeaders() error {
|
||||||
Value: nil,
|
i.Vars = &TelemetryVars{Vars: make(map[string]Var, i.Headers.NumVars)}
|
||||||
}
|
|
||||||
|
var k int32
|
||||||
i.Vars.Vars[v.Name] = v
|
for k = 0; k < i.Headers.NumVars; k++ {
|
||||||
}
|
rbuf := make([]byte, VarHeaderSize)
|
||||||
|
|
||||||
return nil
|
_, err := i.File.ReadAt(rbuf, int64(i.Headers.VarHeaderOffset+k*VarHeaderSize))
|
||||||
}
|
if err != nil {
|
||||||
|
return err
|
||||||
func (i *IBT) readData() error {
|
}
|
||||||
// I think that we can add one extra check or verification here
|
|
||||||
// The file headers tells us how many data frames there are, we can probably
|
if i.Opts.IBTExport {
|
||||||
// cap it at that instead of waiting for the read to fail
|
err = i.exportIBT(rbuf, int64(i.Headers.VarHeaderOffset+k*VarHeaderSize))
|
||||||
// Probably wouldn't work on live data tho
|
if err != nil {
|
||||||
start := i.Headers.BufOffset + i.Tick*i.Headers.BufLen
|
// Don't outright kill it here - maybe nowhere else
|
||||||
buf := make([]byte, i.Headers.BufLen)
|
log.Printf("Failed to export variable contents: %v\n", err)
|
||||||
_, err := i.File.ReadAt(buf, int64(start))
|
}
|
||||||
if err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
var dst IBTVar
|
||||||
|
err = binary.Read(bytes.NewBuffer(rbuf[:]), binary.LittleEndian, &dst)
|
||||||
for k, v := range i.Vars.Vars {
|
if err != nil {
|
||||||
rbuf := buf[v.Offset : v.Offset+int32(VarTypes[int(v.Type)].Size)]
|
return err
|
||||||
|
}
|
||||||
// Read the value
|
|
||||||
switch v.Type {
|
v := Var{
|
||||||
case IRSDK_char:
|
Type: dst.Type,
|
||||||
v.Value = string(rbuf[0])
|
Offset: dst.Offset,
|
||||||
case IRSDK_bool:
|
Count: dst.Count,
|
||||||
v.Value = int(rbuf[0]) > 0
|
CountAsTime: dst.CountAsTime,
|
||||||
case IRSDK_int:
|
Name: strings.TrimRight(string(dst.Name[:]), "\x00"),
|
||||||
v.Value = int(binary.LittleEndian.Uint32(rbuf))
|
Description: strings.TrimRight(string(dst.Description[:]), "\x00"),
|
||||||
case IRSDK_bitField:
|
Unit: strings.TrimRight(string(dst.Unit[:]), "\x00"),
|
||||||
v.Value = fmt.Sprintf("0x%x", int(binary.LittleEndian.Uint32(rbuf)))
|
Value: nil,
|
||||||
case IRSDK_float:
|
}
|
||||||
v.Value = math.Float32frombits(uint32(binary.LittleEndian.Uint32(rbuf)))
|
|
||||||
case IRSDK_double:
|
i.Vars.Vars[v.Name] = v
|
||||||
v.Value = math.Float64frombits(uint64(binary.LittleEndian.Uint64(rbuf)))
|
}
|
||||||
}
|
|
||||||
// --------------
|
return nil
|
||||||
|
}
|
||||||
i.Vars.Vars[k] = v
|
|
||||||
}
|
func (i *IBT) readData(buf []byte) error {
|
||||||
|
for k, v := range i.Vars.Vars {
|
||||||
i.Tick++
|
// Slice of the variable value in the buffer
|
||||||
|
rbuf := buf[v.Offset : v.Offset+int32(VarTypes[int(v.Type)].Size)]
|
||||||
return nil
|
|
||||||
}
|
// Read the value
|
||||||
|
switch v.Type {
|
||||||
func (i *IBT) Update() bool {
|
case IRSDK_char:
|
||||||
err := i.readData()
|
if v.Count > 1 {
|
||||||
if err != nil && err != io.EOF {
|
// Array of data
|
||||||
log.Fatalf("What happened?\n%v\n", err)
|
data := make([]string, v.Count)
|
||||||
}
|
for entry := 0; entry < int(v.Count); entry++ {
|
||||||
|
entryOffset := v.Offset + int32(entry)*int32(VarTypes[int(v.Type)].Size)
|
||||||
if err == io.EOF {
|
rbuf := buf[entryOffset : entryOffset+int32(VarTypes[int(v.Type)].Size)]
|
||||||
return false
|
|
||||||
}
|
newValue := string(rbuf[0])
|
||||||
|
data[entry] = newValue
|
||||||
return true
|
}
|
||||||
}
|
|
||||||
|
v.Value = data
|
||||||
|
} else {
|
||||||
|
// Single value
|
||||||
|
v.Value = string(rbuf[0])
|
||||||
|
}
|
||||||
|
case IRSDK_bool:
|
||||||
|
if v.Count > 1 {
|
||||||
|
// Array of data
|
||||||
|
data := make([]bool, 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)]
|
||||||
|
|
||||||
|
newValue := int(rbuf[0]) > 0
|
||||||
|
data[entry] = newValue
|
||||||
|
}
|
||||||
|
|
||||||
|
v.Value = data
|
||||||
|
} else {
|
||||||
|
// Single value
|
||||||
|
v.Value = int(rbuf[0]) > 0
|
||||||
|
}
|
||||||
|
case IRSDK_int:
|
||||||
|
if v.Count > 1 {
|
||||||
|
// Array of data
|
||||||
|
data := make([]int32, 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)]
|
||||||
|
newValue := int32(binary.LittleEndian.Uint32(rbuf))
|
||||||
|
data[entry] = newValue
|
||||||
|
}
|
||||||
|
|
||||||
|
v.Value = data
|
||||||
|
} else {
|
||||||
|
// Single value
|
||||||
|
v.Value = int(binary.LittleEndian.Uint32(rbuf))
|
||||||
|
}
|
||||||
|
case IRSDK_bitField:
|
||||||
|
if v.Count > 1 {
|
||||||
|
// Array of data
|
||||||
|
data := make([]uint32, 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)]
|
||||||
|
data[entry] = binary.LittleEndian.Uint32(rbuf)
|
||||||
|
}
|
||||||
|
|
||||||
|
v.Value = data
|
||||||
|
} else {
|
||||||
|
// Single value
|
||||||
|
v.Value = binary.LittleEndian.Uint32(rbuf)
|
||||||
|
}
|
||||||
|
case IRSDK_float:
|
||||||
|
if v.Count > 1 {
|
||||||
|
// Array of data
|
||||||
|
data := make([]float32, 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)]
|
||||||
|
newValue := math.Float32frombits(uint32(binary.LittleEndian.Uint32(rbuf)))
|
||||||
|
data[entry] = newValue
|
||||||
|
}
|
||||||
|
|
||||||
|
v.Value = data
|
||||||
|
} else {
|
||||||
|
// Single value
|
||||||
|
v.Value = math.Float32frombits(uint32(binary.LittleEndian.Uint32(rbuf)))
|
||||||
|
}
|
||||||
|
case IRSDK_double:
|
||||||
|
if v.Count > 1 {
|
||||||
|
// Array of data
|
||||||
|
data := make([]float64, 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)]
|
||||||
|
newValue := math.Float64frombits(uint64(binary.LittleEndian.Uint64(rbuf)))
|
||||||
|
data[entry] = newValue
|
||||||
|
}
|
||||||
|
|
||||||
|
v.Value = data
|
||||||
|
} else {
|
||||||
|
// Single value
|
||||||
|
v.Value = math.Float64frombits(uint64(binary.LittleEndian.Uint64(rbuf)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i.Vars.Vars[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update will read the next data chunk from the telemetry data, works for both the
|
||||||
|
// live and offline data
|
||||||
|
func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
||||||
|
// This is what happens if we are reading live data
|
||||||
|
switch i.Opts.SourceType {
|
||||||
|
case SharedMemoryFile:
|
||||||
|
// Put a way to check if the sim is active here
|
||||||
|
// fmt.Println("NOT CHECKING IF SIM IS ACTIVE - ADD ME")
|
||||||
|
|
||||||
|
// WORKING HERE
|
||||||
|
// Need to figure out how to grab the latest buffer with data
|
||||||
|
var vb varBuffer
|
||||||
|
foundTickCount := 0
|
||||||
|
for k := 0; k < int(i.Headers.NumBuf); k++ {
|
||||||
|
rbuf := make([]byte, 16)
|
||||||
|
// Read 16 bytes, I don't know why, but do need to understand this
|
||||||
|
_, err := i.File.ReadAt(rbuf, int64(48+k*16))
|
||||||
|
if err != nil {
|
||||||
|
return Failed, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var curVb varBuffer
|
||||||
|
err = binary.Read(bytes.NewBuffer(rbuf[:]), binary.LittleEndian, &curVb)
|
||||||
|
if err != nil {
|
||||||
|
return Failed, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if foundTickCount < int(curVb.TickCount) {
|
||||||
|
foundTickCount = int(curVb.TickCount)
|
||||||
|
vb = curVb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i.Vars.Tick = vb.TickCount
|
||||||
|
|
||||||
|
start := vb.BufOffset
|
||||||
|
buf := make([]byte, i.Headers.BufLen)
|
||||||
|
|
||||||
|
_, err := i.File.ReadAt(buf, int64(start))
|
||||||
|
if err == io.EOF {
|
||||||
|
return Ended, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return Failed, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if i.Opts.IBTExport {
|
||||||
|
// Dirty attempt at getting this to work to write to a memory mapped file
|
||||||
|
var offset int64 = 0
|
||||||
|
switch i.Opts.IBTExportType {
|
||||||
|
case IBTFile:
|
||||||
|
// i.Opts.Logger.Debug("Reading live data and exporting to IBT file")
|
||||||
|
offset = int64(i.Headers.BufOffset + i.Vars.RecorderTick*i.Headers.BufLen)
|
||||||
|
case SharedMemoryFile:
|
||||||
|
// i.Opts.Logger.Debug("Reading live data and exporting to SHM file")
|
||||||
|
offset = int64(i.Headers.BufOffset)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = i.exportIBT(buf, offset)
|
||||||
|
if err != nil {
|
||||||
|
i.Opts.Logger.Debug(fmt.Sprintf("Failed to export offline telemetry data: %+v", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = i.readData(buf)
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
return Unknown, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Document why this is here, I don't remember the exact words right now
|
||||||
|
i.Vars.RecorderTick++
|
||||||
|
case IBTFile:
|
||||||
|
// This is what happens if we are reading from an .ibt file
|
||||||
|
// This will get the dataframe corresponding to a given tick
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make this happen in a different thread, or have this send to a queue that has a thread
|
||||||
|
// writing to a file
|
||||||
|
if i.Opts.IBTExport {
|
||||||
|
// Dirty attempt at getting this to work to write to a memory mapped file
|
||||||
|
var offset int64 = 0
|
||||||
|
switch i.Opts.IBTExportType {
|
||||||
|
case IBTFile:
|
||||||
|
// i.Opts.Logger.Debug("Reading IBT file and exporting to IBT file")
|
||||||
|
offset = int64(start)
|
||||||
|
case SharedMemoryFile:
|
||||||
|
// i.Opts.Logger.Debug("Reading IBT file and exporting to SHM file")
|
||||||
|
offset = int64(i.Headers.BufOffset)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = i.exportIBT(buf, offset)
|
||||||
|
if err != nil {
|
||||||
|
i.Opts.Logger.Debug(fmt.Sprintf("Failed to export offline telemetry data: %+v", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = i.readData(buf)
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
log.Fatalf("What happened?\n%v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This was previously in the read data method, but it probably fits here better
|
||||||
|
i.Vars.Tick++
|
||||||
|
}
|
||||||
|
|
||||||
|
return Running, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user