Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6070620713 | ||
|
|
1ad9dd4ab7 | ||
|
|
56c7081e8f | ||
|
|
ddfcd31b27 | ||
|
|
18233a87b1 | ||
|
|
b9c013ae2f | ||
|
|
5f18023f13 | ||
|
|
6b0283b206 | ||
|
|
a449ced75f | ||
|
|
9adc0a9456 | ||
|
|
76a091b076 |
@@ -6,7 +6,7 @@
|
||||
- [ ] 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
|
||||
- [ ] 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
|
||||
|
||||
|
||||
+693
-139
@@ -1,5 +1,10 @@
|
||||
package goirsdk
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Msg struct {
|
||||
Cmd int
|
||||
P1 int32
|
||||
@@ -8,13 +13,13 @@ type Msg struct {
|
||||
}
|
||||
|
||||
const (
|
||||
MEMMAPFILENAME = "IRSDKMemMapFileName"
|
||||
SimStatusUrl string = "http://127.0.0.1:32034/get_sim_status?object=simStatus"
|
||||
IRSDK_DATAVALIDEVENTNAME string = "Local\\IRSDKDataValidEvent"
|
||||
IRSDK_MEMMAPFILENAME string = "Local\\IRSDKMemMapFileName"
|
||||
IRSDK_MEMMAPFILENAME string = "Local\\" + MEMMAPFILENAME
|
||||
IRSDK_BROADCASTMSGNAME string = "IRSDK_BROADCASTMSG"
|
||||
fileMapSize uint32 = 1164 * 1024
|
||||
connTimeout int64 = 30
|
||||
stConnected int = 1
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -111,21 +116,39 @@ const (
|
||||
csFocusAtDriver int = 0 // ctFocusAtDriver + car number...
|
||||
)
|
||||
|
||||
// Camera positions
|
||||
// StatusField - START
|
||||
const (
|
||||
// CamNose
|
||||
irsdk_stConnected = 0x01
|
||||
)
|
||||
|
||||
// Some other constants that I need to get trough
|
||||
// // bit fields
|
||||
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 const
|
||||
// EngineWarnings - Start
|
||||
// TODO: wtf
|
||||
var (
|
||||
irsdk_WaterTempWarning int64 = 0x00000001
|
||||
irsdk_FuelPressureWarning int64 = 0x00000002
|
||||
irsdk_OilPressureWarning int64 = 0x00000004
|
||||
irsdk_EngineStalled int64 = 0x00000008
|
||||
irsdk_PitSpeedLimiter int64 = 0x00000010
|
||||
irsdk_RevLimiterActive int64 = 0x00000020
|
||||
irsdk_AbsActive int64 = 0x00000100
|
||||
// DEPRECATE THESE ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
|
||||
irsdkWaterTempWarning = bitfieldValue{0x01, "irsdk_waterTempWarning"}
|
||||
irsdkFuelPressureWarning = bitfieldValue{0x02, "irsdk_fueldPressureWarning"}
|
||||
irsdkOilPressureWarning = bitfieldValue{0x04, "irsdk_oilPressureWarning"}
|
||||
@@ -133,139 +156,670 @@ var (
|
||||
irsdkPitSpeedLimiter = bitfieldValue{0x10, "irsdk_pitSpeedLimiter"}
|
||||
irsdkRevLimiterActive = bitfieldValue{0x20, "irsdk_revLimiterActive"}
|
||||
irsdkAbsActive = bitfieldValue{0x100, "irsdk_absActive"}
|
||||
irsdkEngineWarnings = []bitfieldValue{irsdkWaterTempWarning, irsdkFuelPressureWarning,
|
||||
irsdkEngineWarnings = []bitfieldValue{
|
||||
irsdkWaterTempWarning, irsdkFuelPressureWarning,
|
||||
irsdkOilPressureWarning, irsdkEngineStalled, irsdkPitSpeedLimiter, irsdkRevLimiterActive,
|
||||
irsdkAbsActive}
|
||||
irsdkAbsActive,
|
||||
}
|
||||
)
|
||||
|
||||
// enum irsdk_EngineWarnings
|
||||
// {
|
||||
// irsdk_waterTempWarning = 0x01,
|
||||
// irsdk_fuelPressureWarning = 0x02,
|
||||
// irsdk_oilPressureWarning = 0x04,
|
||||
// irsdk_engineStalled = 0x08,
|
||||
// irsdk_pitSpeedLimiter = 0x10,
|
||||
// irsdk_revLimiterActive = 0x20,
|
||||
// };
|
||||
//
|
||||
// // global flags
|
||||
// enum irsdk_Flags
|
||||
// {
|
||||
// // global flags
|
||||
// irsdk_checkered = 0x00000001,
|
||||
// irsdk_white = 0x00000002,
|
||||
// irsdk_green = 0x00000004,
|
||||
// irsdk_yellow = 0x00000008,
|
||||
// irsdk_red = 0x00000010,
|
||||
// irsdk_blue = 0x00000020,
|
||||
// irsdk_debris = 0x00000040,
|
||||
// irsdk_crossed = 0x00000080,
|
||||
// irsdk_yellowWaving = 0x00000100,
|
||||
// irsdk_oneLapToGreen = 0x00000200,
|
||||
// irsdk_greenHeld = 0x00000400,
|
||||
// irsdk_tenToGo = 0x00000800,
|
||||
// irsdk_fiveToGo = 0x00001000,
|
||||
// irsdk_randomWaving = 0x00002000,
|
||||
// irsdk_caution = 0x00004000,
|
||||
// irsdk_cautionWaving = 0x00008000,
|
||||
//
|
||||
// // drivers black flags
|
||||
// irsdk_black = 0x00010000,
|
||||
// irsdk_disqualify = 0x00020000,
|
||||
// irsdk_servicible = 0x00040000, // car is allowed service (not a flag)
|
||||
// irsdk_furled = 0x00080000,
|
||||
// irsdk_repair = 0x00100000,
|
||||
//
|
||||
// // start lights
|
||||
// irsdk_startHidden = 0x10000000,
|
||||
// irsdk_startReady = 0x20000000,
|
||||
// irsdk_startSet = 0x40000000,
|
||||
// irsdk_startGo = 0x80000000,
|
||||
// };
|
||||
//
|
||||
//
|
||||
// // status
|
||||
// enum irsdk_TrkLoc
|
||||
// {
|
||||
// irsdk_NotInWorld = -1,
|
||||
// irsdk_OffTrack,
|
||||
// irsdk_InPitStall,
|
||||
// irsdk_AproachingPits,
|
||||
// irsdk_OnTrack
|
||||
// };
|
||||
//
|
||||
// enum irsdk_TrkSurf
|
||||
// {
|
||||
// irsdk_SurfaceNotInWorld = -1,
|
||||
// irsdk_UndefinedMaterial = 0,
|
||||
//
|
||||
// irsdk_Asphalt1Material,
|
||||
// irsdk_Asphalt2Material,
|
||||
// irsdk_Asphalt3Material,
|
||||
// irsdk_Asphalt4Material,
|
||||
// irsdk_Concrete1Material,
|
||||
// irsdk_Concrete2Material,
|
||||
// irsdk_RacingDirt1Material,
|
||||
// irsdk_RacingDirt2Material,
|
||||
// irsdk_Paint1Material,
|
||||
// irsdk_Paint2Material,
|
||||
// irsdk_Rumble1Material,
|
||||
// irsdk_Rumble2Material,
|
||||
// irsdk_Rumble3Material,
|
||||
// irsdk_Rumble4Material,
|
||||
//
|
||||
// irsdk_Grass1Material,
|
||||
// irsdk_Grass2Material,
|
||||
// irsdk_Grass3Material,
|
||||
// irsdk_Grass4Material,
|
||||
// irsdk_Dirt1Material,
|
||||
// irsdk_Dirt2Material,
|
||||
// irsdk_Dirt3Material,
|
||||
// irsdk_Dirt4Material,
|
||||
// irsdk_SandMaterial,
|
||||
// irsdk_Gravel1Material,
|
||||
// irsdk_Gravel2Material,
|
||||
// irsdk_GrasscreteMaterial,
|
||||
// irsdk_AstroturfMaterial,
|
||||
// };
|
||||
//
|
||||
// enum irsdk_SessionState
|
||||
// {
|
||||
// irsdk_StateInvalid,
|
||||
// irsdk_StateGetInCar,
|
||||
// irsdk_StateWarmup,
|
||||
// irsdk_StateParadeLaps,
|
||||
// irsdk_StateRacing,
|
||||
// irsdk_StateCheckered,
|
||||
// irsdk_StateCoolDown
|
||||
// };
|
||||
//
|
||||
// enum irsdk_CameraState
|
||||
// {
|
||||
// irsdk_IsSessionScreen = 0x0001, // the camera tool can only be activated if viewing the session screen (out of car)
|
||||
// irsdk_IsScenicActive = 0x0002, // the scenic camera is active (no focus car)
|
||||
//
|
||||
// //these can be changed with a broadcast message
|
||||
// irsdk_CamToolActive = 0x0004,
|
||||
// irsdk_UIHidden = 0x0008,
|
||||
// irsdk_UseAutoShotSelection = 0x0010,
|
||||
// irsdk_UseTemporaryEdits = 0x0020,
|
||||
// irsdk_UseKeyAcceleration = 0x0040,
|
||||
// irsdk_UseKey10xAcceleration = 0x0080,
|
||||
// irsdk_UseMouseAimMode = 0x0100
|
||||
// };
|
||||
//
|
||||
// enum irsdk_PitSvFlags
|
||||
// {
|
||||
// irsdk_LFTireChange = 0x0001,
|
||||
// irsdk_RFTireChange = 0x0002,
|
||||
// irsdk_LRTireChange = 0x0004,
|
||||
// irsdk_RRTireChange = 0x0008,
|
||||
//
|
||||
// irsdk_FuelFill = 0x0010,
|
||||
// irsdk_WindshieldTearoff = 0x0020,
|
||||
// irsdk_FastRepair = 0x0040
|
||||
// };
|
||||
func (i *IBT) WaterTempWarning() bool {
|
||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
||||
if !ok {
|
||||
log.Fatal("no EngineWarnings")
|
||||
}
|
||||
|
||||
//----
|
||||
//
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get EngineWarnings: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_WaterTempWarning != 0
|
||||
}
|
||||
|
||||
func (i *IBT) FuelPressureWarning() bool {
|
||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
||||
if !ok {
|
||||
log.Fatal("no EngineWarnings")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get EngineWarnings: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_FuelPressureWarning != 0
|
||||
}
|
||||
|
||||
func (i *IBT) OilPressureWarning() bool {
|
||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
||||
if !ok {
|
||||
log.Fatal("no EngineWarnings")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get EngineWarnings: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_OilPressureWarning != 0
|
||||
}
|
||||
|
||||
func (i *IBT) EngineStalled() bool {
|
||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
||||
if !ok {
|
||||
log.Fatal("no EngineWarnings")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get EngineWarnings: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_EngineStalled != 0
|
||||
}
|
||||
|
||||
func (i *IBT) PitSpeedLimiter() bool {
|
||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
||||
if !ok {
|
||||
log.Fatal("no EngineWarnings")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get EngineWarnings: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_PitSpeedLimiter != 0
|
||||
}
|
||||
|
||||
func (i *IBT) RevLimiterActive() bool {
|
||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
||||
if !ok {
|
||||
log.Fatal("no EngineWarnings")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get EngineWarnings: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_RevLimiterActive != 0
|
||||
}
|
||||
|
||||
func (i *IBT) AbsActive() bool {
|
||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
||||
if !ok {
|
||||
log.Fatal("no EngineWarnings")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get EngineWarnings: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_AbsActive != 0
|
||||
}
|
||||
|
||||
// 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) SessionStateInvalid() bool {
|
||||
val, ok := i.Vars.Vars["SessionState"]
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return bitfield == irsdk_StateInvalid
|
||||
}
|
||||
|
||||
func (i *IBT) SessionStateGetInCar() bool {
|
||||
val, ok := i.Vars.Vars["SessionState"]
|
||||
if !ok {
|
||||
log.Fatal("no SessionState")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get SessionState: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield == irsdk_StateGetInCar
|
||||
}
|
||||
|
||||
func (i *IBT) SessionStateWarmup() bool {
|
||||
val, ok := i.Vars.Vars["SessionState"]
|
||||
if !ok {
|
||||
log.Fatal("no SessionState")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get SessionState: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield == irsdk_StateWarmup
|
||||
}
|
||||
|
||||
func (i *IBT) SessionStateParadeLaps() bool {
|
||||
val, ok := i.Vars.Vars["SessionState"]
|
||||
if !ok {
|
||||
log.Fatal("no SessionState")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get SessionState: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield == irsdk_StateParadeLaps
|
||||
}
|
||||
|
||||
func (i *IBT) SessionStateRacing() bool {
|
||||
val, ok := i.Vars.Vars["SessionState"]
|
||||
if !ok {
|
||||
log.Fatal("no SessionState")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get SessionState: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield == irsdk_StateRacing
|
||||
}
|
||||
|
||||
func (i *IBT) SessionStateCheckered() bool {
|
||||
val, ok := i.Vars.Vars["SessionState"]
|
||||
if !ok {
|
||||
log.Fatal("no SessionState")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get SessionState: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield == irsdk_StateCheckered
|
||||
}
|
||||
|
||||
func (i *IBT) SessionStateCoolDown() bool {
|
||||
val, ok := i.Vars.Vars["SessionState"]
|
||||
if !ok {
|
||||
log.Fatal("no SessionState")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get SessionState: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield == 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 = 0x00000001
|
||||
irsdk_RFTireChange = 0x00000002
|
||||
irsdk_LRTireChange = 0x00000004
|
||||
irsdk_RRTireChange = 0x00000008
|
||||
// Fuel
|
||||
irsdk_FuelFill = 0x00000010
|
||||
|
||||
irsdk_WindshieldTearoff = 0x00000020
|
||||
irsdk_FastRepair = 0x00000040
|
||||
|
||||
// Other pit service request flags
|
||||
irsdk_ClearTires = 0x00000080 // Uncheck tire change
|
||||
irsdk_ClearWS = 0x00000100 // Uncheck windshield tearoff
|
||||
irsdk_ClearFR = 0x00000200 // Uncheck FastRepair
|
||||
irsdk_ClearFuel = 0x00000400 // Uncheck refuelling
|
||||
)
|
||||
|
||||
func (i *IBT) LFTireChange() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_LFTireChange != 0
|
||||
}
|
||||
|
||||
func (i *IBT) RFTireChange() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_RFTireChange != 0
|
||||
}
|
||||
|
||||
func (i *IBT) LRTireChange() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_LRTireChange != 0
|
||||
}
|
||||
|
||||
func (i *IBT) RRTireChange() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_RRTireChange != 0
|
||||
}
|
||||
|
||||
func (i *IBT) FuelFill() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_FuelFill != 0
|
||||
}
|
||||
|
||||
func (i *IBT) WindshieldTearoff() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_WindshieldTearoff != 0
|
||||
}
|
||||
|
||||
func (i *IBT) FastRepair() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_FastRepair != 0
|
||||
}
|
||||
|
||||
func (i *IBT) ClearTires() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_ClearTires != 0
|
||||
}
|
||||
|
||||
func (i *IBT) ClearWS() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_ClearWS != 0
|
||||
}
|
||||
|
||||
func (i *IBT) ClearFR() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_ClearFR != 0
|
||||
}
|
||||
|
||||
func (i *IBT) ClearFuel() bool {
|
||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||
if !ok {
|
||||
log.Fatal("no PitSvFlags")
|
||||
}
|
||||
|
||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
||||
if err != nil {
|
||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
||||
}
|
||||
|
||||
return bitfield&irsdk_ClearFuel != 0
|
||||
}
|
||||
|
||||
// PitSvFlags -- End
|
||||
|
||||
+7
-7
@@ -1,11 +1,11 @@
|
||||
package goirsdk
|
||||
|
||||
import (
|
||||
"github.com/ESilva15/goirsdk/logger"
|
||||
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/ESilva15/goirsdk/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -28,18 +28,18 @@ func (i *IBT) readSubheader() error {
|
||||
var subheaderRaw [SubHeaderSize]byte
|
||||
_, err := i.File.ReadAt(subheaderRaw[:], HeaderSize)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to read disk subheaders from file: %v", err)
|
||||
return fmt.Errorf("failed to read disk subheaders from file: %v", err)
|
||||
}
|
||||
i.SubHeaders, err = parseTelemetrySubHeader(subheaderRaw)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to parse disk subheaders from file: %v", err)
|
||||
return fmt.Errorf("unable to parse disk subheaders from file: %v", err)
|
||||
}
|
||||
|
||||
// Write to the output file - TODO add the check
|
||||
if i.IBTExport != nil {
|
||||
err = i.exportIBT(subheaderRaw[:], HeaderSize)
|
||||
if i.Opts.IBTExport {
|
||||
err = i.exportIBT(subheaderRaw[:], HeaderSize)
|
||||
if err != nil {
|
||||
log.Printf("Failed to export subheaders: %v\n", err)
|
||||
log.Printf("failed to export subheaders: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/ESilva15/goirsdk"
|
||||
)
|
||||
|
||||
func msToKph(v float32) int {
|
||||
return int((3600 * v) / 1000)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Instantiate our iRacing SDK instance
|
||||
irsdk, err := goirsdk.Init(goirsdk.Options{
|
||||
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.(string)
|
||||
|
||||
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: %s\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
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/ESilva15/goirsdk"
|
||||
@@ -14,21 +13,18 @@ func msToKph(v float32) int {
|
||||
}
|
||||
|
||||
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, "", "")
|
||||
irsdk, err := goirsdk.Init(goirsdk.Options{
|
||||
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
|
||||
mainLoopTicker := time.NewTicker(time.Second / 60)
|
||||
// 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 {
|
||||
+19
-30
@@ -1,11 +1,11 @@
|
||||
package goirsdk
|
||||
|
||||
import (
|
||||
"github.com/ESilva15/goirsdk/logger"
|
||||
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/ESilva15/goirsdk/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,30 +15,19 @@ const (
|
||||
|
||||
// TelemetryHeaders struct to hold an IBT file's headers
|
||||
type TelemetryHeaders struct {
|
||||
Version int32
|
||||
// Status of 1 indicates a completed session and status of 0 a live session
|
||||
Status int32
|
||||
// TickRate indicates the frequency of writes (usually 60)
|
||||
TickRate int32
|
||||
// SessionInfoUpdate indicates the number of times the SessionInfo was
|
||||
Version int32
|
||||
Status int32 // Status of 1 indicates a completed session and status of 0 a live session
|
||||
TickRate int32 // TickRate indicates the frequency of writes (usually 60)
|
||||
SessionInfoUpdate int32 // SessionInfoUpdate indicates the number of times the SessionInfo was
|
||||
// updated. 0 for finished sessions and >1 for active sessions
|
||||
SessionInfoUpdate int32
|
||||
// SessionInfoLength is the length of the session info buffer
|
||||
SessionInfoLength int32
|
||||
// SessionInfoOffset is the offset of the session info in the buffer
|
||||
SessionInfoOffset int32
|
||||
// NumVars is the number of variables in each input
|
||||
NumVars int32
|
||||
// VarHeaderOffset is the offset of the VarHeader
|
||||
VarHeaderOffset int32
|
||||
// NumBuf will be 1 for static files and 3 for live telemetry files
|
||||
NumBuf int32
|
||||
// BufLen is the length for parsing VarHeader values
|
||||
BufLen int32
|
||||
// Padding
|
||||
Padding [12]byte
|
||||
// I still don't know what this is:
|
||||
BufOffset int32
|
||||
SessionInfoLength int32 // SessionInfoLength is the length of the session info buffer
|
||||
SessionInfoOffset int32 // SessionInfoOffset is the offset of the session info in the buffer
|
||||
NumVars int32 // NumVars is the number of variables in each input
|
||||
VarHeaderOffset int32 // VarHeaderOffset is the offset of the VarHeader
|
||||
NumBuf int32 // NumBuf will be 1 for static files and 3 for live telemetry files
|
||||
BufLen int32 // BufLen is the length for parsing VarHeader values
|
||||
Padding [12]byte // Padding
|
||||
BufOffset int32 // I still don't know what this is:
|
||||
}
|
||||
|
||||
// readHeader will read the header out of the telemetry data
|
||||
@@ -48,18 +37,18 @@ func (i *IBT) readHeader() error {
|
||||
var headerRaw [FileHeaderSize]byte
|
||||
_, err := i.File.ReadAt(headerRaw[:], 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to read headers from file: %v", err)
|
||||
return fmt.Errorf("failed to read headers from file: %v", err)
|
||||
}
|
||||
i.Headers, err = parseTelemetryHeader(headerRaw)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to read headers from file: %v", err)
|
||||
return fmt.Errorf("unable to read headers from file: %v", err)
|
||||
}
|
||||
|
||||
// Write to the output file - TODO: this should only write if necessary
|
||||
if i.IBTExport != nil {
|
||||
err = i.exportIBT(headerRaw[:], 0)
|
||||
if i.Opts.IBTExport {
|
||||
err = i.exportIBT(headerRaw[:], 0)
|
||||
if err != nil {
|
||||
log.Printf("Failed to export headers: %v\n", err)
|
||||
log.Printf("Failed to export headers: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,23 +3,15 @@ package goirsdk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"io"
|
||||
|
||||
"github.com/ESilva15/goirsdk/logger"
|
||||
"github.com/ESilva15/goirsdk/winutils"
|
||||
"github.com/ESilva15/goirsdk/mmaputils"
|
||||
"github.com/ESilva15/goirsdk/sharedMem"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const (
|
||||
ibtFile = "./telemetryFiles/mx5_2016Okayama_full_2024_10_19_22_02_12.ibt"
|
||||
)
|
||||
|
||||
func msToKph(v float32) int {
|
||||
return int((3600 * v) / 1000)
|
||||
}
|
||||
|
||||
// Reader is an interface to represent the readable data that can be either
|
||||
// a .ibt file (or live data, hopefully)
|
||||
type Reader interface {
|
||||
@@ -28,37 +20,64 @@ type Reader interface {
|
||||
io.ReadCloser
|
||||
}
|
||||
|
||||
type Writer interface {
|
||||
io.WriterAt
|
||||
io.Closer
|
||||
}
|
||||
|
||||
type TelemetryContainer int
|
||||
|
||||
const (
|
||||
IBTFile TelemetryContainer = iota
|
||||
SharedMemoryFile TelemetryContainer = iota
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
SourceType TelemetryContainer // type of source data
|
||||
SourcePath string // Path to source
|
||||
IBTExportType TelemetryContainer // export type of telemetry: store .ibt or replay in shm
|
||||
IBTExportPath string // path where to export the data
|
||||
IBTExport bool // whether to export the telemetry data
|
||||
SessionInfoExport bool // whether to export the session info data
|
||||
SessionInfoExportPath string // path where to export the session info
|
||||
}
|
||||
|
||||
// IBT struct will hold the relevant data for a given IBT file
|
||||
type IBT struct {
|
||||
File Reader // Source of the data
|
||||
IBTExport *os.File // If set, it will export the IBT data to the file
|
||||
IBTExportPath string // Path for IBT export
|
||||
YAMLExport *os.File // If set, it will export the session YAML to the file
|
||||
YAMLExportPath string // Path for YAML export
|
||||
Headers *TelemetryHeaders // IBT file Headers
|
||||
SubHeaders *DiskSubHeader // IBT file Sub Headers
|
||||
SessionInfo *SessionInfoYAML // IBT file Session Info
|
||||
Vars *TelemetryVars // Vars will hold the telemetry data
|
||||
winUtils *winutils.IRacingWinUtils // WinUtils gives access to the system utilities
|
||||
File Reader // Source of the data
|
||||
Opts Options
|
||||
IBTExporter Writer
|
||||
winUtils *mmaputils.IRacingWinUtils // WinUtils gives access to the system utilities
|
||||
|
||||
// TODO: fragment this struct a little bit, for now I want to actually get
|
||||
// stuff done so its enough to work as is
|
||||
// Actual FILE
|
||||
Headers *TelemetryHeaders // IBT file Headers
|
||||
SubHeaders *DiskSubHeader // IBT file Sub Headers
|
||||
SessionInfo *SessionInfoYAML // IBT file Session Info
|
||||
Vars *TelemetryVars // Vars will hold the telemetry data
|
||||
}
|
||||
|
||||
func (i *IBT) IsConnected() bool {
|
||||
if i.Headers != nil {
|
||||
if sessionStatusOK(int(i.Headers.Status)) {
|
||||
return true
|
||||
}
|
||||
// if sessionStatusOK(int(i.Headers.Status)) && (sdk.lastValidData+connTimeout > time.Now().Unix()) {
|
||||
// return true
|
||||
// }
|
||||
if i.Headers == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
if !i.SessionStatusConnected() {
|
||||
return false
|
||||
}
|
||||
|
||||
if i.SessionStateInvalid() {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (i *IBT) exportYAML() error {
|
||||
log := logger.GetInstance()
|
||||
|
||||
file, err := os.OpenFile(i.YAMLExportPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
file, err := os.OpenFile(i.Opts.SessionInfoExportPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
log.Printf("Failed to open file for YAML export: %v\n", err)
|
||||
return fmt.Errorf("failed to open output file for YAML: %v", err)
|
||||
@@ -79,11 +98,10 @@ func (i *IBT) exportYAML() error {
|
||||
func (i *IBT) exportIBT(data []byte, offset int64) error {
|
||||
log := logger.GetInstance()
|
||||
|
||||
_, err := i.IBTExport.WriteAt(data, offset)
|
||||
|
||||
_, err := i.IBTExporter.WriteAt(data, offset)
|
||||
if err != nil {
|
||||
i.IBTExport.Close()
|
||||
i.IBTExport = nil
|
||||
i.IBTExporter.Close()
|
||||
i.IBTExporter = nil
|
||||
log.Println("Won't attempt to export anymore")
|
||||
return err
|
||||
}
|
||||
@@ -91,61 +109,97 @@ func (i *IBT) exportIBT(data []byte, offset int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Init serves to initialize and get a hold of a IBT struct
|
||||
// f -> is the source data, pass nil for the SDK to read live data or a
|
||||
// *os.File to read from a file
|
||||
// exportTelem -> is a string with the path to export the telemetry data, pass
|
||||
// an empty string to not export any data
|
||||
// exportTelem -> is a string with the path to export the session info data, pass
|
||||
// an empty string to not export any data
|
||||
func Init(f Reader, exportTelem string, exportYAML string) (*IBT, error) {
|
||||
// log := logger.GetInstance()
|
||||
|
||||
// Read the header of the file
|
||||
func (i *IBT) openSource() error {
|
||||
var err error
|
||||
ibt := IBT{
|
||||
File: f,
|
||||
IBTExport: nil,
|
||||
IBTExportPath: exportTelem,
|
||||
YAMLExport: nil,
|
||||
YAMLExportPath: exportYAML,
|
||||
Vars: &TelemetryVars{},
|
||||
winUtils: nil,
|
||||
}
|
||||
|
||||
// If requested to output to a telemetry file
|
||||
if exportTelem != "" {
|
||||
ibt.IBTExport, err = os.OpenFile(exportTelem, os.O_CREATE|os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open ibt export file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if ibt.File == nil {
|
||||
switch i.Opts.SourceType {
|
||||
case SharedMemoryFile:
|
||||
// User is requesting us to read live data - present in the mem map file
|
||||
ibt.File, err = winutils.OpenMemMap(IRSDK_MEMMAPFILENAME, fileMapSize)
|
||||
i.File, err = mmaputils.OpenMemMap(MEMMAPFILENAME, fileMapSize)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to open memory mapped file: %v", err)
|
||||
return fmt.Errorf("failed to open memory mapped file: %+v", err)
|
||||
}
|
||||
|
||||
// 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
|
||||
ibt.winUtils, err = winutils.Init()
|
||||
i.winUtils, err = mmaputils.Init()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
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 = ibt.winUtils.OpenWinEvent(IRSDK_DATAVALIDEVENTNAME)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// err = i.winUtils.OpenWinEvent(IRSDK_DATAVALIDEVENTNAME)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// We need to open the broadcast channel
|
||||
err = ibt.winUtils.OpenBroadcastChannel(IRSDK_BROADCASTMSGNAME)
|
||||
// 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 nil, err
|
||||
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) {
|
||||
// log := logger.GetInstance()
|
||||
|
||||
// Create our irsdk instance
|
||||
var err error
|
||||
ibt := IBT{
|
||||
Opts: opts,
|
||||
Vars: &TelemetryVars{},
|
||||
winUtils: nil,
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,6 +230,10 @@ func Init(f Reader, exportTelem string, exportYAML string) (*IBT, error) {
|
||||
return &ibt, nil
|
||||
}
|
||||
|
||||
func (i *IBT) ListVariables() map[string]Var {
|
||||
return i.Vars.Vars
|
||||
}
|
||||
|
||||
// Close cleans up our irsdk instance
|
||||
func (i *IBT) Close() {
|
||||
if i.winUtils != nil {
|
||||
|
||||
+3
-3
@@ -30,7 +30,7 @@ func lapTimeRepresentation(t float32) string {
|
||||
}
|
||||
|
||||
func TestFunctionality(t *testing.T) {
|
||||
input, err := os.Open("../testTelemetry/supercars_race_watkins_glenn.ibt")
|
||||
input, err := os.Open("../../testTelemetry/supercars_race_watkins_glenn.ibt")
|
||||
if err != nil {
|
||||
t.Fatal("Was unable to prepare telemetry file for testing.")
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func TestFunctionality(t *testing.T) {
|
||||
// driversBehind := i.Vars.Vars["CarIdxF2Time"].Value.([]float32)
|
||||
|
||||
drivers := i.SessionInfo.DriverInfo.Drivers
|
||||
myIdx := i.SessionInfo.DriverInfo.DriverCarIdx
|
||||
myIdx := i.SessionInfo.DriverInfo.DriverCarIdx
|
||||
|
||||
standings := make([]StandingsLine, len(drivers))
|
||||
|
||||
@@ -90,7 +90,7 @@ func TestFunctionality(t *testing.T) {
|
||||
return standings[i].LapPct >= standings[j].LapPct
|
||||
})
|
||||
|
||||
fmt.Printf("%v\n", driversEstTime)
|
||||
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])
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
// is interface some windows stuff that we need for the:
|
||||
// - Broadcast Channel
|
||||
// - Valid Data Event windows thing
|
||||
package winutils
|
||||
package mmaputils
|
||||
|
||||
import (
|
||||
"github.com/ESilva15/goirsdk/sharedMem"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
@@ -32,23 +31,12 @@ func (u *IRacingWinUtils) Close() {
|
||||
u.Utils.Close()
|
||||
}
|
||||
|
||||
// OpenMemMap returns a Reader interface that can be used to read the data
|
||||
// No need to encapsulate it
|
||||
func OpenMemMap(path string, size uint32) (Reader, error) {
|
||||
file, err := sharedMem.Open(path, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
// OpenWinEvent will open the named windows event
|
||||
func (u *IRacingWinUtils) OpenWinEvent(name string) error {
|
||||
return u.Utils.OpenEvent(name)
|
||||
}
|
||||
|
||||
// OpenWinEvent will open the broadcast channel
|
||||
// OpenBroadcastChannel will open the broadcast channel
|
||||
func (u *IRacingWinUtils) OpenBroadcastChannel(name string) error {
|
||||
return u.Utils.OpenBroadcastChannel(name)
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
//go:build (linux && cgo) || (darwin && cgo)
|
||||
|
||||
package mmaputils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/ESilva15/goirsdk/sharedMem"
|
||||
)
|
||||
|
||||
type utils struct {
|
||||
socketPath string
|
||||
listener *net.UnixConn
|
||||
}
|
||||
|
||||
func newUtils() (*utils, error) {
|
||||
return &utils{}, nil
|
||||
}
|
||||
|
||||
func (u *utils) Close() {
|
||||
if u.listener != nil {
|
||||
u.listener.Close()
|
||||
os.Remove(u.socketPath)
|
||||
}
|
||||
}
|
||||
|
||||
// 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.socketPath = fmt.Sprintf("/tmp/iracing_%s.sock", eventName)
|
||||
_ = os.Remove(u.socketPath)
|
||||
|
||||
addr, err := net.ResolveUnixAddr("unixgram", u.socketPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
l, err := net.ListenUnixgram("unixgram", addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.listener = l
|
||||
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.listener == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
_ = u.listener.SetReadDeadline(time.Now().Add(timeout))
|
||||
buf := make([]byte, 1)
|
||||
_, err := u.listener.Read(buf)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// package winutils
|
||||
//
|
||||
// import (
|
||||
// "errors"
|
||||
// "sync"
|
||||
// "time"
|
||||
// )
|
||||
//
|
||||
// const (
|
||||
// WAIT_OBJECT_0 = 0
|
||||
// WAIT_TIMEOUT = 258
|
||||
// )
|
||||
//
|
||||
// var (
|
||||
// once sync.Once
|
||||
// ErrUnsupportedOS = errors.New("not found")
|
||||
// )
|
||||
//
|
||||
// type utils struct {
|
||||
// }
|
||||
//
|
||||
// // INITIALIZATION
|
||||
// func newUtils() (*utils, error) {
|
||||
// return nil, ErrUnsupportedOS
|
||||
// }
|
||||
//
|
||||
// func (u *utils) Close() {
|
||||
// }
|
||||
//
|
||||
// // openEvent opens a windows.Handle for a given event
|
||||
// func (u *utils) OpenEvent(eventName string) error {
|
||||
// return ErrUnsupportedOS
|
||||
// }
|
||||
//
|
||||
// // OpenBroadcastChannel opens up a broadcast channel to send commands to iracing
|
||||
// func (u *utils) OpenBroadcastChannel(name string) error {
|
||||
// return ErrUnsupportedOS
|
||||
// }
|
||||
//
|
||||
// // INITIALIZATION
|
||||
//
|
||||
// // openEvent waits for a good response for some given time
|
||||
// func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
|
||||
// return false
|
||||
// }
|
||||
//
|
||||
// // SendBroadcastMessage sends a message trough the broadcast channel
|
||||
// func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
|
||||
// return ErrUnsupportedOS
|
||||
// }
|
||||
@@ -1,13 +1,13 @@
|
||||
//go:build windows && cgo
|
||||
// +build windows,cgo
|
||||
// go:build windows
|
||||
|
||||
package winutils
|
||||
package mmaputils
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/ESilva15/goirsdk/sharedMem"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -16,13 +16,11 @@ const (
|
||||
WAIT_TIMEOUT = 258
|
||||
)
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
)
|
||||
var once sync.Once
|
||||
|
||||
type utils struct {
|
||||
user32DLL *windows.LazyDLL
|
||||
wEvent *windows.Handle
|
||||
wEvent windows.Handle
|
||||
wBroadcastChn uintptr
|
||||
}
|
||||
|
||||
@@ -34,11 +32,22 @@ func newUtils() (*utils, error) {
|
||||
}
|
||||
|
||||
func (u *utils) Close() {
|
||||
closeEvent(u.wEvent)
|
||||
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)
|
||||
@@ -50,7 +59,7 @@ func (u *utils) OpenEvent(eventName string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.wEvent = &event
|
||||
u.wEvent = event
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -90,7 +99,7 @@ func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
|
||||
t0 := time.Now().UnixNano()
|
||||
timeoutInt := uint32(timeout / time.Millisecond)
|
||||
|
||||
result, err := windows.WaitForSingleObject(*u.wEvent, timeoutInt)
|
||||
result, err := windows.WaitForSingleObject(u.wEvent, timeoutInt)
|
||||
if err != nil {
|
||||
remaining := timeoutInt - uint32((time.Now().UnixNano()-t0)/1000000)
|
||||
if remaining > 0 {
|
||||
+4
-9
@@ -1,13 +1,13 @@
|
||||
package goirsdk
|
||||
|
||||
import (
|
||||
"github.com/ESilva15/goirsdk/logger"
|
||||
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/ESilva15/goirsdk/logger"
|
||||
|
||||
"golang.org/x/text/encoding/charmap"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -321,7 +321,7 @@ func (i *IBT) readSessionInfo() error {
|
||||
}
|
||||
|
||||
// Write to the output file
|
||||
if i.IBTExport != nil {
|
||||
if i.Opts.IBTExport {
|
||||
err := i.exportIBT(sessionInfoStringRaw[:], int64(i.Headers.SessionInfoOffset))
|
||||
if err != nil {
|
||||
log.Printf("Failed to export offline telemetry data: %v", err)
|
||||
@@ -334,7 +334,7 @@ func (i *IBT) readSessionInfo() error {
|
||||
}
|
||||
|
||||
// Write to YAML output file
|
||||
if i.YAMLExportPath != "" {
|
||||
if i.Opts.SessionInfoExport {
|
||||
err := i.exportYAML()
|
||||
if err != nil {
|
||||
log.Printf("Failed to export YAML string: %v\n", err)
|
||||
@@ -370,11 +370,6 @@ func parseSessionInfo(buf []byte, len int32) (*SessionInfoYAML, error) {
|
||||
return &sessionInfo, nil
|
||||
}
|
||||
|
||||
// sessionStatusOK will tell us if we are connected to the live data
|
||||
func sessionStatusOK(status int) bool {
|
||||
return (status & stConnected) > 0
|
||||
}
|
||||
|
||||
// ToString will return a readable string of the struct
|
||||
func (s *SessionInfoYAML) ToString() string {
|
||||
stringified, _ := json.MarshalIndent(s, "", " ")
|
||||
|
||||
+40
-17
@@ -40,11 +40,13 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
type IRacingState int
|
||||
type VarType struct {
|
||||
Size int // Size is the var type size in bytes
|
||||
Name string // Name is the irsdk var name
|
||||
}
|
||||
type (
|
||||
IRacingState int
|
||||
VarType struct {
|
||||
Size int // Size is the var type size in bytes
|
||||
Name string // Name is the irsdk var name
|
||||
}
|
||||
)
|
||||
|
||||
type IBTVar struct {
|
||||
Type int32
|
||||
@@ -106,9 +108,10 @@ type varBuffer struct {
|
||||
}
|
||||
|
||||
type TelemetryVars struct {
|
||||
Tick int32 // Keeps track of the current data buffer tick
|
||||
RecorderTick int32 // Counts from 0 when creating a telemetry file from a replay or live data
|
||||
Vars map[string]Var // Variables content
|
||||
Tick int32 // Keeps track of the current data buffer tick
|
||||
RecorderTick int32 // Counts from 0 when creating a telemetry file from a
|
||||
// replay or live data
|
||||
Vars map[string]Var // Variables content
|
||||
}
|
||||
|
||||
func (i *IBT) readVariablerHeaders() error {
|
||||
@@ -123,7 +126,7 @@ func (i *IBT) readVariablerHeaders() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if i.IBTExport != nil {
|
||||
if i.Opts.IBTExport {
|
||||
err = i.exportIBT(rbuf, int64(i.Headers.VarHeaderOffset+k*VarHeaderSize))
|
||||
if err != nil {
|
||||
// Don't outright kill it here - maybe nowhere else
|
||||
@@ -306,6 +309,7 @@ func (i *IBT) readData(buf []byte) error {
|
||||
// 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
|
||||
if i.winUtils != nil {
|
||||
// Put a way to check if the sim is active here
|
||||
// fmt.Println("NOT CHECKING IF SIM IS ACTIVE - ADD ME")
|
||||
@@ -344,10 +348,19 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
||||
return Failed, err
|
||||
}
|
||||
|
||||
if i.IBTExport != nil {
|
||||
err = i.exportIBT(buf, int64(i.Headers.BufOffset+i.Vars.RecorderTick*i.Headers.BufLen))
|
||||
if err != nil {
|
||||
log.Printf("Failed to export live telemetry data: %v", err)
|
||||
if i.Opts.IBTExport {
|
||||
// Dirty attempt at getting this to work to write to a memory mapped file
|
||||
switch i.Opts.IBTExportType {
|
||||
case IBTFile:
|
||||
err = i.exportIBT(buf, int64(i.Headers.BufOffset+i.Vars.RecorderTick*i.Headers.BufLen))
|
||||
if err != nil {
|
||||
log.Printf("Failed to export live telemetry data: %v", err)
|
||||
}
|
||||
case SharedMemoryFile:
|
||||
err = i.exportIBT(buf, int64(i.Headers.BufOffset))
|
||||
if err != nil {
|
||||
log.Printf("Failed to export live telemetry data: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,6 +376,7 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
||||
// Document why this is here, I don't remember the exact words right now
|
||||
i.Vars.RecorderTick++
|
||||
} else {
|
||||
// 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)
|
||||
@@ -370,10 +384,19 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
||||
|
||||
// Make this happen in a different thread, or have this send to a queue that has a thread
|
||||
// writing to a file
|
||||
if i.IBTExport != nil {
|
||||
err = i.exportIBT(buf, int64(start))
|
||||
if err != nil {
|
||||
log.Printf("Failed to export offline telemetry data: %v", err)
|
||||
if i.Opts.IBTExport {
|
||||
// Dirty attempt at getting this to work to write to a memory mapped file
|
||||
switch i.Opts.IBTExportType {
|
||||
case IBTFile:
|
||||
err = i.exportIBT(buf, int64(start))
|
||||
if err != nil {
|
||||
log.Printf("Failed to export offline telemetry data: %v", err)
|
||||
}
|
||||
case SharedMemoryFile:
|
||||
err = i.exportIBT(buf, int64(i.Headers.BufOffset))
|
||||
if err != nil {
|
||||
log.Printf("Failed to export live telemetry data: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
//go:build (linux && cgo) || (darwin && cgo)
|
||||
// +build linux,cgo darwin,cgo
|
||||
|
||||
package winutils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
WAIT_OBJECT_0 = 0
|
||||
WAIT_TIMEOUT = 258
|
||||
)
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
ErrUnsupportedOS = errors.New("not found")
|
||||
)
|
||||
|
||||
type utils struct {
|
||||
}
|
||||
|
||||
// INITIALIZATION
|
||||
func newUtils() (*utils, error) {
|
||||
return nil, ErrUnsupportedOS
|
||||
}
|
||||
|
||||
func (u *utils) Close() {
|
||||
}
|
||||
|
||||
// openEvent opens a windows.Handle for a given event
|
||||
func (u *utils) OpenEvent(eventName string) error {
|
||||
return ErrUnsupportedOS
|
||||
}
|
||||
|
||||
// OpenBroadcastChannel opens up a broadcast channel to send commands to iracing
|
||||
func (u *utils) OpenBroadcastChannel(name string) error {
|
||||
return ErrUnsupportedOS
|
||||
}
|
||||
|
||||
// INITIALIZATION
|
||||
|
||||
// openEvent waits for a good response for some given time
|
||||
func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// SendBroadcastMessage sends a message trough the broadcast channel
|
||||
func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
|
||||
return ErrUnsupportedOS
|
||||
}
|
||||
Reference in New Issue
Block a user