Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4762d854cd | ||
|
|
a82caa05a2 | ||
|
|
eed8c562b2 | ||
|
|
052f4582c9 | ||
|
|
7584b0ffcf | ||
|
|
7a210af58d | ||
|
|
78ec6a1e86 | ||
|
|
6070620713 |
+76
-295
@@ -2,7 +2,6 @@ package goirsdk
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Msg struct {
|
type Msg struct {
|
||||||
@@ -13,13 +12,15 @@ type Msg struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
DATAVALIDEVENTNAME string = "IRSDKDataValidEvent"
|
||||||
MEMMAPFILENAME = "IRSDKMemMapFileName"
|
MEMMAPFILENAME = "IRSDKMemMapFileName"
|
||||||
SimStatusUrl string = "http://127.0.0.1:32034/get_sim_status?object=simStatus"
|
SimStatusUrl string = "http://127.0.0.1:32034/get_sim_status?object=simStatus"
|
||||||
IRSDK_DATAVALIDEVENTNAME string = "Local\\IRSDKDataValidEvent"
|
IRSDK_DATAVALIDEVENTNAME string = "Local\\" + DATAVALIDEVENTNAME
|
||||||
IRSDK_MEMMAPFILENAME string = "Local\\" + MEMMAPFILENAME
|
// IRSDK_DATAVALIDEVENTNAME string = DATAVALIDEVENTNAME
|
||||||
IRSDK_BROADCASTMSGNAME string = "IRSDK_BROADCASTMSG"
|
IRSDK_MEMMAPFILENAME string = "Local\\" + MEMMAPFILENAME
|
||||||
fileMapSize uint32 = 1164 * 1024
|
IRSDK_BROADCASTMSGNAME string = "IRSDK_BROADCASTMSG"
|
||||||
connTimeout int64 = 30
|
fileMapSize uint32 = 1164 * 1024
|
||||||
|
connTimeout int64 = 30
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -141,124 +142,55 @@ type bitfieldValue struct {
|
|||||||
// EngineWarnings - Start
|
// EngineWarnings - Start
|
||||||
// TODO: wtf
|
// TODO: wtf
|
||||||
var (
|
var (
|
||||||
irsdk_WaterTempWarning int64 = 0x00000001
|
irsdk_WaterTempWarning = 0x00000001
|
||||||
irsdk_FuelPressureWarning int64 = 0x00000002
|
irsdk_FuelPressureWarning = 0x00000002
|
||||||
irsdk_OilPressureWarning int64 = 0x00000004
|
irsdk_OilPressureWarning = 0x00000004
|
||||||
irsdk_EngineStalled int64 = 0x00000008
|
irsdk_EngineStalled = 0x00000008
|
||||||
irsdk_PitSpeedLimiter int64 = 0x00000010
|
irsdk_PitSpeedLimiter = 0x00000010
|
||||||
irsdk_RevLimiterActive int64 = 0x00000020
|
irsdk_RevLimiterActive = 0x00000020
|
||||||
irsdk_AbsActive int64 = 0x00000100
|
irsdk_AbsActive = 0x00000100
|
||||||
// DEPRECATE THESE ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
|
|
||||||
irsdkWaterTempWarning = bitfieldValue{0x01, "irsdk_waterTempWarning"}
|
|
||||||
irsdkFuelPressureWarning = bitfieldValue{0x02, "irsdk_fueldPressureWarning"}
|
|
||||||
irsdkOilPressureWarning = bitfieldValue{0x04, "irsdk_oilPressureWarning"}
|
|
||||||
irsdkEngineStalled = bitfieldValue{0x08, "irsdk_engineStalled"}
|
|
||||||
irsdkPitSpeedLimiter = bitfieldValue{0x10, "irsdk_pitSpeedLimiter"}
|
|
||||||
irsdkRevLimiterActive = bitfieldValue{0x20, "irsdk_revLimiterActive"}
|
|
||||||
irsdkAbsActive = bitfieldValue{0x100, "irsdk_absActive"}
|
|
||||||
irsdkEngineWarnings = []bitfieldValue{
|
|
||||||
irsdkWaterTempWarning, irsdkFuelPressureWarning,
|
|
||||||
irsdkOilPressureWarning, irsdkEngineStalled, irsdkPitSpeedLimiter, irsdkRevLimiterActive,
|
|
||||||
irsdkAbsActive,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (i *IBT) WaterTempWarning() bool {
|
func (i *IBT) checkEngineWarningsBitfield(field int) bool {
|
||||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
val, ok := i.Vars.Vars["EngineWarnings"]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatal("no EngineWarnings")
|
log.Fatal("no EngineWarnings")
|
||||||
}
|
}
|
||||||
|
|
||||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
bitfield, ok := val.Value.(uint32)
|
||||||
if err != nil {
|
if !ok {
|
||||||
log.Fatal("unable to get EngineWarnings: " + err.Error())
|
log.Fatalf("unable to typecast EngineWarnings: %+v", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitfield&irsdk_WaterTempWarning != 0
|
return bitfield&uint32(field) != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) WaterTempWarning() bool {
|
||||||
|
return i.checkEngineWarningsBitfield(irsdk_WaterTempWarning)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IBT) FuelPressureWarning() bool {
|
func (i *IBT) FuelPressureWarning() bool {
|
||||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
return i.checkEngineWarningsBitfield(irsdk_FuelPressureWarning)
|
||||||
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 {
|
func (i *IBT) OilPressureWarning() bool {
|
||||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
return i.checkEngineWarningsBitfield(irsdk_OilPressureWarning)
|
||||||
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 {
|
func (i *IBT) EngineStalled() bool {
|
||||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
return i.checkEngineWarningsBitfield(irsdk_EngineStalled)
|
||||||
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 {
|
func (i *IBT) PitSpeedLimiter() bool {
|
||||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
return i.checkEngineWarningsBitfield(irsdk_PitSpeedLimiter)
|
||||||
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 {
|
func (i *IBT) RevLimiterActive() bool {
|
||||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
return i.checkEngineWarningsBitfield(irsdk_RevLimiterActive)
|
||||||
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 {
|
func (i *IBT) AbsActive() bool {
|
||||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
return i.checkEngineWarningsBitfield(irsdk_AbsActive)
|
||||||
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
|
// EngineWarnings - END
|
||||||
@@ -274,102 +206,47 @@ const (
|
|||||||
irsdk_StateCoolDown = 0x06
|
irsdk_StateCoolDown = 0x06
|
||||||
)
|
)
|
||||||
|
|
||||||
func (i *IBT) SessionStateInvalid() bool {
|
func (i *IBT) checkSessionStateField(field int) bool {
|
||||||
val, ok := i.Vars.Vars["SessionState"]
|
val, ok := i.Vars.Vars["SessionState"]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatal("no SessionState")
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
value, ok := val.Value.(int)
|
||||||
if err != nil {
|
if !ok {
|
||||||
log.Fatal("unable to get SessionState: " + err.Error())
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitfield == irsdk_StateInvalid
|
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 {
|
func (i *IBT) SessionStateGetInCar() bool {
|
||||||
val, ok := i.Vars.Vars["SessionState"]
|
return i.checkSessionStateField(irsdk_StateGetInCar)
|
||||||
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 {
|
func (i *IBT) SessionStateWarmup() bool {
|
||||||
val, ok := i.Vars.Vars["SessionState"]
|
return i.checkSessionStateField(irsdk_StateWarmup)
|
||||||
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 {
|
func (i *IBT) SessionStateParadeLaps() bool {
|
||||||
val, ok := i.Vars.Vars["SessionState"]
|
return i.checkSessionStateField(irsdk_StateParadeLaps)
|
||||||
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 {
|
func (i *IBT) SessionStateRacing() bool {
|
||||||
val, ok := i.Vars.Vars["SessionState"]
|
return i.checkSessionStateField(irsdk_StateRacing)
|
||||||
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 {
|
func (i *IBT) SessionStateCheckered() bool {
|
||||||
val, ok := i.Vars.Vars["SessionState"]
|
return i.checkSessionStateField(irsdk_StateCheckered)
|
||||||
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 {
|
func (i *IBT) SessionStateCoolDown() bool {
|
||||||
val, ok := i.Vars.Vars["SessionState"]
|
return i.checkSessionStateField(irsdk_StateCoolDown)
|
||||||
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 {
|
func SessionStateToString(state int) string {
|
||||||
@@ -651,175 +528,79 @@ func CameraStateToString(state int) string {
|
|||||||
// PitSvFlags -- Start
|
// PitSvFlags -- Start
|
||||||
const (
|
const (
|
||||||
// Tires
|
// Tires
|
||||||
irsdk_LFTireChange = 0x00000001
|
irsdk_LFTireChange uint32 = 0x00000001
|
||||||
irsdk_RFTireChange = 0x00000002
|
irsdk_RFTireChange uint32 = 0x00000002
|
||||||
irsdk_LRTireChange = 0x00000004
|
irsdk_LRTireChange uint32 = 0x00000004
|
||||||
irsdk_RRTireChange = 0x00000008
|
irsdk_RRTireChange uint32 = 0x00000008
|
||||||
// Fuel
|
// Fuel
|
||||||
irsdk_FuelFill = 0x00000010
|
irsdk_FuelFill uint32 = 0x00000010
|
||||||
|
|
||||||
irsdk_WindshieldTearoff = 0x00000020
|
irsdk_WindshieldTearoff uint32 = 0x00000020
|
||||||
irsdk_FastRepair = 0x00000040
|
irsdk_FastRepair uint32 = 0x00000040
|
||||||
|
|
||||||
// Other pit service request flags
|
// Other pit service request flags
|
||||||
irsdk_ClearTires = 0x00000080 // Uncheck tire change
|
irsdk_ClearTires uint32 = 0x00000080 // Uncheck tire change
|
||||||
irsdk_ClearWS = 0x00000100 // Uncheck windshield tearoff
|
irsdk_ClearWS uint32 = 0x00000100 // Uncheck windshield tearoff
|
||||||
irsdk_ClearFR = 0x00000200 // Uncheck FastRepair
|
irsdk_ClearFR uint32 = 0x00000200 // Uncheck FastRepair
|
||||||
irsdk_ClearFuel = 0x00000400 // Uncheck refuelling
|
irsdk_ClearFuel uint32 = 0x00000400 // Uncheck refuelling
|
||||||
)
|
)
|
||||||
|
|
||||||
func (i *IBT) LFTireChange() bool {
|
func (i *IBT) checkPitSvFlags(field uint32) bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
val, ok := i.Vars.Vars["PitSvFlags"]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatal("no PitSvFlags")
|
log.Fatal("no PitSvFlags")
|
||||||
}
|
}
|
||||||
|
|
||||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
bitfield, ok := val.Value.(uint32)
|
||||||
if err != nil {
|
if !ok {
|
||||||
log.Fatal("unable to get PitSvFlags: " + err.Error())
|
log.Fatal("unable to get PitSvFlags: %+v", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitfield&irsdk_LFTireChange != 0
|
return bitfield&field != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IBT) LFTireChange() bool {
|
||||||
|
return i.checkPitSvFlags(irsdk_LFTireChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IBT) RFTireChange() bool {
|
func (i *IBT) RFTireChange() bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
return i.checkPitSvFlags(irsdk_RFTireChange)
|
||||||
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 {
|
func (i *IBT) LRTireChange() bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
return i.checkPitSvFlags(irsdk_LRTireChange)
|
||||||
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 {
|
func (i *IBT) RRTireChange() bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
return i.checkPitSvFlags(irsdk_RRTireChange)
|
||||||
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 {
|
func (i *IBT) FuelFill() bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
return i.checkPitSvFlags(irsdk_FuelFill)
|
||||||
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 {
|
func (i *IBT) WindshieldTearoff() bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
return i.checkPitSvFlags(irsdk_WindshieldTearoff)
|
||||||
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 {
|
func (i *IBT) FastRepair() bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
return i.checkPitSvFlags(irsdk_FastRepair)
|
||||||
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 {
|
func (i *IBT) ClearTires() bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
return i.checkPitSvFlags(irsdk_ClearTires)
|
||||||
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 {
|
func (i *IBT) ClearWS() bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
return i.checkPitSvFlags(irsdk_ClearWS)
|
||||||
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 {
|
func (i *IBT) ClearFR() bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
return i.checkPitSvFlags(irsdk_ClearFR)
|
||||||
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 {
|
func (i *IBT) ClearFuel() bool {
|
||||||
val, ok := i.Vars.Vars["PitSvFlags"]
|
return i.checkPitSvFlags(irsdk_ClearFuel)
|
||||||
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
|
// PitSvFlags -- End
|
||||||
|
|||||||
+1
-7
@@ -4,8 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ESilva15/goirsdk/logger"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -23,8 +21,6 @@ type DiskSubHeader struct {
|
|||||||
|
|
||||||
// readSubheader will read the subheader contents out of the telemetry data
|
// readSubheader will read the subheader contents out of the telemetry data
|
||||||
func (i *IBT) readSubheader() error {
|
func (i *IBT) readSubheader() error {
|
||||||
log := logger.GetInstance()
|
|
||||||
|
|
||||||
var subheaderRaw [SubHeaderSize]byte
|
var subheaderRaw [SubHeaderSize]byte
|
||||||
_, err := i.File.ReadAt(subheaderRaw[:], HeaderSize)
|
_, err := i.File.ReadAt(subheaderRaw[:], HeaderSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -39,7 +35,7 @@ func (i *IBT) readSubheader() error {
|
|||||||
if i.Opts.IBTExport {
|
if i.Opts.IBTExport {
|
||||||
err = i.exportIBT(subheaderRaw[:], HeaderSize)
|
err = i.exportIBT(subheaderRaw[:], HeaderSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to export subheaders: %v\n", err)
|
i.Opts.Logger.Debug("failed to export disksubheader", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +46,6 @@ func (i *IBT) readSubheader() error {
|
|||||||
// or nil if an error occurs. In which case the error return value is more
|
// or nil if an error occurs. In which case the error return value is more
|
||||||
// valuable
|
// valuable
|
||||||
func parseTelemetrySubHeader(buf [SubHeaderSize]byte) (*DiskSubHeader, error) {
|
func parseTelemetrySubHeader(buf [SubHeaderSize]byte) (*DiskSubHeader, error) {
|
||||||
// utils.HexDump(buf[:])
|
|
||||||
|
|
||||||
dst := DiskSubHeader{}
|
dst := DiskSubHeader{}
|
||||||
err := binary.Read(bytes.NewBuffer(buf[:]), binary.LittleEndian, &dst)
|
err := binary.Read(bytes.NewBuffer(buf[:]), binary.LittleEndian, &dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
// go:build windows
|
//go:build windows
|
||||||
|
|
||||||
package mmaputils
|
package mmaputils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@@ -55,9 +57,14 @@ func (u *utils) OpenEvent(eventName string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
event, err := windows.OpenEvent(windows.SYNCHRONIZE, false, name)
|
// 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 err != nil {
|
||||||
return err
|
// If event does not exist yet, create it
|
||||||
|
event, err = windows.CreateEvent(nil, 0, 0, name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
u.wEvent = event
|
u.wEvent = event
|
||||||
|
|
||||||
@@ -87,6 +94,33 @@ func (u *utils) OpenBroadcastChannel(name string) error {
|
|||||||
return nil
|
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
|
// INITIALIZATION
|
||||||
|
|
||||||
// closeEvent closes a given windows.Handle
|
// closeEvent closes a given windows.Handle
|
||||||
@@ -3,6 +3,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ESilva15/goirsdk"
|
"github.com/ESilva15/goirsdk"
|
||||||
@@ -13,8 +15,20 @@ func msToKph(v float32) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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
|
// Instantiate our iRacing SDK instance
|
||||||
irsdk, err := goirsdk.Init(goirsdk.Options{
|
irsdk, err := goirsdk.Init(goirsdk.Options{
|
||||||
|
Logger: logger,
|
||||||
SourceType: goirsdk.IBTFile,
|
SourceType: goirsdk.IBTFile,
|
||||||
SourcePath: "../../../../testTelemetry/mx5_2016Okayama_full_2024_10_19_22_02_12.ibt",
|
SourcePath: "../../../../testTelemetry/mx5_2016Okayama_full_2024_10_19_22_02_12.ibt",
|
||||||
IBTExportType: goirsdk.SharedMemoryFile,
|
IBTExportType: goirsdk.SharedMemoryFile,
|
||||||
@@ -60,14 +74,14 @@ func main() {
|
|||||||
sessionState := irsdk.Vars.Vars["SessionState"].Value.(int)
|
sessionState := irsdk.Vars.Vars["SessionState"].Value.(int)
|
||||||
trkloc := irsdk.Vars.Vars["PlayerTrackSurface"].Value.(int)
|
trkloc := irsdk.Vars.Vars["PlayerTrackSurface"].Value.(int)
|
||||||
trksurf := irsdk.Vars.Vars["PlayerTrackSurfaceMaterial"].Value.(int)
|
trksurf := irsdk.Vars.Vars["PlayerTrackSurfaceMaterial"].Value.(int)
|
||||||
pitsvflags := irsdk.Vars.Vars["PitSvFlags"].Value.(string)
|
pitsvflags := irsdk.Vars.Vars["PitSvFlags"].Value.(uint32)
|
||||||
|
|
||||||
fmt.Printf("\033[?25l\033[2J\033[H")
|
fmt.Printf("\033[?25l\033[2J\033[H")
|
||||||
fmt.Printf("Gear: %d, RPM: %d, Speed: %d\n", gear, rpm, speed)
|
fmt.Printf("Gear: %d, RPM: %d, Speed: %d\n", gear, rpm, speed)
|
||||||
fmt.Printf("SessionState: %s\n", goirsdk.SessionStateToString(sessionState))
|
fmt.Printf("SessionState: %s\n", goirsdk.SessionStateToString(sessionState))
|
||||||
fmt.Printf("TrkLoc: %s\n", goirsdk.TrkLocToString(trkloc))
|
fmt.Printf("TrkLoc: %s\n", goirsdk.TrkLocToString(trkloc))
|
||||||
fmt.Printf("TrkSurf: %s\n", goirsdk.TrkSurfToString(trksurf))
|
fmt.Printf("TrkSurf: %s\n", goirsdk.TrkSurfToString(trksurf))
|
||||||
fmt.Printf("PitSvFlags: %s\n", pitsvflags)
|
fmt.Printf("PitSvFlags: %d\n", pitsvflags)
|
||||||
fmt.Printf(" FL FR\n")
|
fmt.Printf(" FL FR\n")
|
||||||
fmt.Printf(" %t %t\n", irsdk.LFTireChange(), irsdk.RFTireChange())
|
fmt.Printf(" %t %t\n", irsdk.LFTireChange(), irsdk.RFTireChange())
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ESilva15/goirsdk"
|
"github.com/ESilva15/goirsdk"
|
||||||
@@ -13,8 +15,22 @@ func msToKph(v float32) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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
|
// Instantiate our iRacing SDK instance
|
||||||
irsdk, err := goirsdk.Init(goirsdk.Options{
|
irsdk, err := goirsdk.Init(goirsdk.Options{
|
||||||
|
Logger: logger,
|
||||||
SourceType: goirsdk.SharedMemoryFile,
|
SourceType: goirsdk.SharedMemoryFile,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -53,9 +69,29 @@ func main() {
|
|||||||
gear := int32(irsdk.Vars.Vars["Gear"].Value.(int))
|
gear := int32(irsdk.Vars.Vars["Gear"].Value.(int))
|
||||||
rpm := int32(irsdk.Vars.Vars["RPM"].Value.(float32))
|
rpm := int32(irsdk.Vars.Vars["RPM"].Value.(float32))
|
||||||
speed := int32(msToKph(irsdk.Vars.Vars["Speed"].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("\033[?25l\033[2J\033[H")
|
||||||
fmt.Printf("Gear: %d, RPM: %d, Speed: %d", gear, rpm, speed)
|
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
|
<-mainLoopTicker.C
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -4,8 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ESilva15/goirsdk/logger"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -32,8 +30,6 @@ type TelemetryHeaders struct {
|
|||||||
|
|
||||||
// readHeader will read the header out of the telemetry data
|
// readHeader will read the header out of the telemetry data
|
||||||
func (i *IBT) readHeader() error {
|
func (i *IBT) readHeader() error {
|
||||||
log := logger.GetInstance()
|
|
||||||
|
|
||||||
var headerRaw [FileHeaderSize]byte
|
var headerRaw [FileHeaderSize]byte
|
||||||
_, err := i.File.ReadAt(headerRaw[:], 0)
|
_, err := i.File.ReadAt(headerRaw[:], 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -48,7 +44,7 @@ func (i *IBT) readHeader() error {
|
|||||||
if i.Opts.IBTExport {
|
if i.Opts.IBTExport {
|
||||||
err = i.exportIBT(headerRaw[:], 0)
|
err = i.exportIBT(headerRaw[:], 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to export headers: %v\n", err)
|
i.Opts.Logger.Debug("Failed to export headers", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ package goirsdk
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ESilva15/goirsdk/logger"
|
eventutils "github.com/ESilva15/goirsdk/eventutils"
|
||||||
"github.com/ESilva15/goirsdk/mmaputils"
|
|
||||||
"github.com/ESilva15/goirsdk/sharedMem"
|
"github.com/ESilva15/goirsdk/sharedMem"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@@ -33,6 +34,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
Logger *slog.Logger
|
||||||
SourceType TelemetryContainer // type of source data
|
SourceType TelemetryContainer // type of source data
|
||||||
SourcePath string // Path to source
|
SourcePath string // Path to source
|
||||||
IBTExportType TelemetryContainer // export type of telemetry: store .ibt or replay in shm
|
IBTExportType TelemetryContainer // export type of telemetry: store .ibt or replay in shm
|
||||||
@@ -47,7 +49,7 @@ type IBT struct {
|
|||||||
File Reader // Source of the data
|
File Reader // Source of the data
|
||||||
Opts Options
|
Opts Options
|
||||||
IBTExporter Writer
|
IBTExporter Writer
|
||||||
winUtils *mmaputils.IRacingWinUtils // WinUtils gives access to the system utilities
|
winUtils *eventutils.EventUtils // WinUtils gives access to the system utilities
|
||||||
|
|
||||||
// TODO: fragment this struct a little bit, for now I want to actually get
|
// TODO: fragment this struct a little bit, for now I want to actually get
|
||||||
// stuff done so its enough to work as is
|
// stuff done so its enough to work as is
|
||||||
@@ -75,11 +77,9 @@ func (i *IBT) IsConnected() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *IBT) exportYAML() error {
|
func (i *IBT) exportYAML() error {
|
||||||
log := logger.GetInstance()
|
|
||||||
|
|
||||||
file, err := os.OpenFile(i.Opts.SessionInfoExportPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
|
file, err := os.OpenFile(i.Opts.SessionInfoExportPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to open file for YAML export: %v\n", err)
|
i.Opts.Logger.Debug(fmt.Sprintf("Failed to open file for YAML export: %v\n", err))
|
||||||
return fmt.Errorf("failed to open output file for YAML: %v", err)
|
return fmt.Errorf("failed to open output file for YAML: %v", err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
@@ -88,7 +88,7 @@ func (i *IBT) exportYAML() error {
|
|||||||
|
|
||||||
err = enc.Encode(i.SessionInfo)
|
err = enc.Encode(i.SessionInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to write into file for YAML export: %v\n", 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)
|
return fmt.Errorf("failed to write YAML contents to file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,16 +96,24 @@ func (i *IBT) exportYAML() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *IBT) exportIBT(data []byte, offset int64) error {
|
func (i *IBT) exportIBT(data []byte, offset int64) error {
|
||||||
log := logger.GetInstance()
|
nBytes, err := i.IBTExporter.WriteAt(data, offset)
|
||||||
|
|
||||||
_, err := i.IBTExporter.WriteAt(data, offset)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
i.IBTExporter.Close()
|
i.IBTExporter.Close()
|
||||||
i.IBTExporter = nil
|
i.IBTExporter = nil
|
||||||
log.Println("Won't attempt to export anymore")
|
i.Opts.Logger.Debug(fmt.Sprintf("won't attempt to export anymore: %+v", err))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nBytes > 0 {
|
||||||
|
// Send the event stating the data has been created
|
||||||
|
err = i.winUtils.Utils.SignalEvent()
|
||||||
|
if err != nil {
|
||||||
|
i.Opts.Logger.Debug("failed to signal event", "err", err)
|
||||||
|
} else {
|
||||||
|
i.Opts.Logger.Debug("no error signaling", "nBytes", nBytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +123,7 @@ func (i *IBT) openSource() error {
|
|||||||
switch i.Opts.SourceType {
|
switch i.Opts.SourceType {
|
||||||
case SharedMemoryFile:
|
case SharedMemoryFile:
|
||||||
// User is requesting us to read live data - present in the mem map file
|
// User is requesting us to read live data - present in the mem map file
|
||||||
i.File, err = mmaputils.OpenMemMap(MEMMAPFILENAME, fileMapSize)
|
i.File, err = eventutils.OpenMemMap(MEMMAPFILENAME, fileMapSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open memory mapped file: %+v", err)
|
return fmt.Errorf("failed to open memory mapped file: %+v", err)
|
||||||
}
|
}
|
||||||
@@ -123,10 +131,10 @@ func (i *IBT) openSource() error {
|
|||||||
// To use our windows interface we need to initialize it first
|
// To use our windows interface we need to initialize it first
|
||||||
// it will return a struct with a pointer to the windows handles
|
// 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
|
// if, for some reason, we need to stub out this to run in on Linux its easier
|
||||||
i.winUtils, err = mmaputils.Init()
|
// i.winUtils, err = eventutils.Init()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
// I don't believe we need this on windows either, but I'll have to check
|
// I don't believe we need this on windows either, but I'll have to check
|
||||||
// We need to open the windows event thing
|
// We need to open the windows event thing
|
||||||
@@ -177,16 +185,24 @@ func (i *IBT) openExporter() error {
|
|||||||
// Init serves to initialize and get a hold of a IBT struct
|
// Init serves to initialize and get a hold of a IBT struct
|
||||||
// Receives an Options struct with the required configurations
|
// Receives an Options struct with the required configurations
|
||||||
func Init(opts Options) (*IBT, error) {
|
func Init(opts Options) (*IBT, error) {
|
||||||
// log := logger.GetInstance()
|
|
||||||
|
|
||||||
// Create our irsdk instance
|
// Create our irsdk instance
|
||||||
var err error
|
var err error
|
||||||
ibt := IBT{
|
ibt := IBT{
|
||||||
Opts: opts,
|
Opts: opts,
|
||||||
Vars: &TelemetryVars{},
|
Vars: &TelemetryVars{},
|
||||||
winUtils: nil,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// Setup the source
|
||||||
err = ibt.openSource()
|
err = ibt.openSource()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -224,7 +240,7 @@ func Init(opts Options) (*IBT, error) {
|
|||||||
// Read the telemetry vars info
|
// Read the telemetry vars info
|
||||||
err = ibt.readVariablerHeaders()
|
err = ibt.readVariablerHeaders()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Unable to parser variable headers from file: %v", err)
|
return nil, fmt.Errorf("unable to parser variable headers from file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ibt, nil
|
return &ibt, nil
|
||||||
@@ -234,8 +250,22 @@ func (i *IBT) ListVariables() map[string]Var {
|
|||||||
return i.Vars.Vars
|
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
|
// Close cleans up our irsdk instance
|
||||||
func (i *IBT) Close() {
|
func (i *IBT) Close() {
|
||||||
|
if i == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if i.winUtils != nil {
|
if i.winUtils != nil {
|
||||||
// If its not live data, the user is the one with ownership of the handle
|
// If its not live data, the user is the one with ownership of the handle
|
||||||
i.File.Close()
|
i.File.Close()
|
||||||
|
|||||||
+99
-99
@@ -1,101 +1,101 @@
|
|||||||
package goirsdk
|
package goirsdk
|
||||||
|
|
||||||
import (
|
// import (
|
||||||
"fmt"
|
// "fmt"
|
||||||
"log"
|
// "log"
|
||||||
"os"
|
// "os"
|
||||||
"sort"
|
// "sort"
|
||||||
"testing"
|
// "testing"
|
||||||
"time"
|
// "time"
|
||||||
)
|
// )
|
||||||
|
//
|
||||||
type StandingsLine struct {
|
// type StandingsLine struct {
|
||||||
CarIdx int
|
// CarIdx int
|
||||||
LapPct float32
|
// LapPct float32
|
||||||
Lap int32
|
// Lap int32
|
||||||
DriverName string
|
// DriverName string
|
||||||
EstTime float32
|
// EstTime float32
|
||||||
TimeBehind float32
|
// TimeBehind float32
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
func lapTimeRepresentation(t float32) string {
|
// func lapTimeRepresentation(t float32) string {
|
||||||
if t < 0 {
|
// if t < 0 {
|
||||||
t = 0
|
// t = 0
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
wholeSeconds := int64(t)
|
// wholeSeconds := int64(t)
|
||||||
lapTime := time.Unix(wholeSeconds, int64((t-float32(wholeSeconds))*1e9))
|
// lapTime := time.Unix(wholeSeconds, int64((t-float32(wholeSeconds))*1e9))
|
||||||
|
//
|
||||||
return lapTime.Format("04:05.000")
|
// return lapTime.Format("04:05.000")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
func TestFunctionality(t *testing.T) {
|
// 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 {
|
// if err != nil {
|
||||||
t.Fatal("Was unable to prepare telemetry file for testing.")
|
// t.Fatal("Was unable to prepare telemetry file for testing.")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
i, _ := Init(input, "", "")
|
// i, _ := Init(input, "", "")
|
||||||
defer i.Close()
|
// defer i.Close()
|
||||||
|
//
|
||||||
// Set up a loop to iterate our data
|
// // Set up a loop to iterate our data
|
||||||
mainLoopTicker := time.NewTicker(time.Second / 60)
|
// mainLoopTicker := time.NewTicker(time.Second / 60)
|
||||||
defer mainLoopTicker.Stop()
|
// defer mainLoopTicker.Stop()
|
||||||
|
//
|
||||||
for {
|
// for {
|
||||||
// Update the data that the SDK is holding with the next tick
|
// // Update the data that the SDK is holding with the next tick
|
||||||
_, err := i.Update(100 * time.Millisecond)
|
// _, err := i.Update(100 * time.Millisecond)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Printf("could not update data: %v", err)
|
// log.Printf("could not update data: %v", err)
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// Vehicle Movement data gathered from the names we can find on the
|
// // Vehicle Movement data gathered from the names we can find on the
|
||||||
// telemetry_docs.pdf file
|
// // telemetry_docs.pdf file
|
||||||
// - I wish to make this less verbose if possible
|
// // - I wish to make this less verbose if possible
|
||||||
if _, ok := i.Vars.Vars["CarIdxPosition"]; !ok {
|
// if _, ok := i.Vars.Vars["CarIdxPosition"]; !ok {
|
||||||
log.Fatal("Field `CarIdxPosition` doesn't exist")
|
// log.Fatal("Field `CarIdxPosition` doesn't exist")
|
||||||
}
|
// }
|
||||||
driversLapDistPct := i.Vars.Vars["CarIdxLapDistPct"].Value.([]float32)
|
// driversLapDistPct := i.Vars.Vars["CarIdxLapDistPct"].Value.([]float32)
|
||||||
driversEstTime := i.Vars.Vars["CarIdxEstTime"].Value.([]float32)
|
// driversEstTime := i.Vars.Vars["CarIdxEstTime"].Value.([]float32)
|
||||||
driversLap := i.Vars.Vars["CarIdxLap"].Value.([]int32)
|
// driversLap := i.Vars.Vars["CarIdxLap"].Value.([]int32)
|
||||||
// driversBehind := i.Vars.Vars["CarIdxF2Time"].Value.([]float32)
|
// // driversBehind := i.Vars.Vars["CarIdxF2Time"].Value.([]float32)
|
||||||
|
//
|
||||||
drivers := i.SessionInfo.DriverInfo.Drivers
|
// drivers := i.SessionInfo.DriverInfo.Drivers
|
||||||
myIdx := i.SessionInfo.DriverInfo.DriverCarIdx
|
// myIdx := i.SessionInfo.DriverInfo.DriverCarIdx
|
||||||
|
//
|
||||||
standings := make([]StandingsLine, len(drivers))
|
// standings := make([]StandingsLine, len(drivers))
|
||||||
|
//
|
||||||
fmt.Printf("\033[?25l\033[2J\033[H")
|
// fmt.Printf("\033[?25l\033[2J\033[H")
|
||||||
for k := range len(drivers) {
|
// for k := range len(drivers) {
|
||||||
if drivers[k].CarIsPaceCar == 1 || drivers[k].IsSpectator == 1 {
|
// if drivers[k].CarIsPaceCar == 1 || drivers[k].IsSpectator == 1 {
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
standings[k] = StandingsLine{
|
// standings[k] = StandingsLine{
|
||||||
CarIdx: k,
|
// CarIdx: k,
|
||||||
LapPct: driversLapDistPct[k],
|
// LapPct: driversLapDistPct[k],
|
||||||
DriverName: drivers[k].UserName,
|
// DriverName: drivers[k].UserName,
|
||||||
EstTime: driversEstTime[k],
|
// EstTime: driversEstTime[k],
|
||||||
Lap: driversLap[k],
|
// Lap: driversLap[k],
|
||||||
TimeBehind: driversEstTime[myIdx],
|
// TimeBehind: driversEstTime[myIdx],
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
sort.Slice(standings, func(i int, j int) bool {
|
// sort.Slice(standings, func(i int, j int) bool {
|
||||||
if standings[i].Lap > int32(standings[j].Lap) {
|
// if standings[i].Lap > int32(standings[j].Lap) {
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return standings[i].LapPct >= standings[j].LapPct
|
// return standings[i].LapPct >= standings[j].LapPct
|
||||||
})
|
// })
|
||||||
|
//
|
||||||
fmt.Printf("%v\n", driversEstTime)
|
// fmt.Printf("%v\n", driversEstTime)
|
||||||
// for p, v := range standings {
|
// // for p, v := range standings {
|
||||||
// fmt.Printf("[%2d] %-30s %13f %13f\n",
|
// // fmt.Printf("[%2d] %-30s %13f %13f\n",
|
||||||
// p+1, v.DriverName, v.LapPct, driversEstTime[p] - driversEstTime[myIdx])
|
// // p+1, v.DriverName, v.LapPct, driversEstTime[p] - driversEstTime[myIdx])
|
||||||
// }
|
// // }
|
||||||
|
//
|
||||||
<-mainLoopTicker.C
|
// <-mainLoopTicker.C
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package logger
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
var l *log.Logger
|
|
||||||
var once sync.Once
|
|
||||||
|
|
||||||
func createLogger() {
|
|
||||||
l = log.New(os.Stdout, "[ibtReader] ", log.LstdFlags | log.Lshortfile)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetInstance() *log.Logger {
|
|
||||||
once.Do(func() {
|
|
||||||
createLogger()
|
|
||||||
})
|
|
||||||
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
// 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 IRacingWinUtils struct {
|
|
||||||
Utils *utils
|
|
||||||
}
|
|
||||||
|
|
||||||
func Init() (*IRacingWinUtils, error) {
|
|
||||||
u, err := newUtils()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &IRacingWinUtils{u}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *IRacingWinUtils) Close() {
|
|
||||||
u.Utils.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenWinEvent will open the named windows event
|
|
||||||
func (u *IRacingWinUtils) OpenWinEvent(name string) error {
|
|
||||||
return u.Utils.OpenEvent(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenBroadcastChannel will open the broadcast channel
|
|
||||||
func (u *IRacingWinUtils) 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 *IRacingWinUtils) CheckValidDataEvent(timeout time.Duration) bool {
|
|
||||||
return u.Utils.CheckValidDataEvent(timeout)
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
//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
-5
@@ -6,8 +6,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ESilva15/goirsdk/logger"
|
|
||||||
|
|
||||||
"golang.org/x/text/encoding/charmap"
|
"golang.org/x/text/encoding/charmap"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@@ -312,8 +310,6 @@ type Driver struct {
|
|||||||
|
|
||||||
// readSessionInfo will read the session info yaml out of the telemetry data
|
// readSessionInfo will read the session info yaml out of the telemetry data
|
||||||
func (i *IBT) readSessionInfo() error {
|
func (i *IBT) readSessionInfo() error {
|
||||||
log := logger.GetInstance()
|
|
||||||
|
|
||||||
sessionInfoStringRaw := make([]byte, i.Headers.SessionInfoLength)
|
sessionInfoStringRaw := make([]byte, i.Headers.SessionInfoLength)
|
||||||
_, err := i.File.ReadAt(sessionInfoStringRaw, int64(i.Headers.SessionInfoOffset))
|
_, err := i.File.ReadAt(sessionInfoStringRaw, int64(i.Headers.SessionInfoOffset))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -337,7 +333,7 @@ func (i *IBT) readSessionInfo() error {
|
|||||||
if i.Opts.SessionInfoExport {
|
if i.Opts.SessionInfoExport {
|
||||||
err := i.exportYAML()
|
err := i.exportYAML()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to export YAML string: %v\n", err)
|
i.Opts.Logger.Debug("Failed to export YAML string", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+40
-73
@@ -7,7 +7,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -157,38 +156,6 @@ func (i *IBT) readVariablerHeaders() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IBT) parseEngineWarnings() {
|
|
||||||
val, ok := i.Vars.Vars["EngineWarnings"]
|
|
||||||
if !ok {
|
|
||||||
log.Fatal("no engine warnings")
|
|
||||||
}
|
|
||||||
|
|
||||||
bitfield, err := strconv.ParseInt(val.Value.(string), 0, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Unable to get engine warnings: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, ew := range irsdkEngineWarnings {
|
|
||||||
result := (int(bitfield) & ew.Value) != 0
|
|
||||||
i.Vars.Vars[ew.Name] = Var{Value: result}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseBitfieldVariables will parse the variables:
|
|
||||||
// - irsdk_CameraState "CamCameraState"
|
|
||||||
// - irsdk_EngineWarnings "EngineWarnings"
|
|
||||||
// - irsdk_PitSvFlags "PitSvFlags"
|
|
||||||
// - irsdk_Flags "SessionFlags"
|
|
||||||
// - irsdk_SessionState "SessionState"
|
|
||||||
// - irsdk_TrkLoc "CarIdxTrackSurface"
|
|
||||||
//
|
|
||||||
// The approach for now will be to create unique entries in the data map for
|
|
||||||
// the fields in these variables
|
|
||||||
func (i *IBT) parseBitfieldVariables() {
|
|
||||||
// Parse the EngineWarnings variables - its the only one for now
|
|
||||||
i.parseEngineWarnings()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *IBT) readData(buf []byte) error {
|
func (i *IBT) readData(buf []byte) error {
|
||||||
for k, v := range i.Vars.Vars {
|
for k, v := range i.Vars.Vars {
|
||||||
// Slice of the variable value in the buffer
|
// Slice of the variable value in the buffer
|
||||||
@@ -249,18 +216,17 @@ func (i *IBT) readData(buf []byte) error {
|
|||||||
case IRSDK_bitField:
|
case IRSDK_bitField:
|
||||||
if v.Count > 1 {
|
if v.Count > 1 {
|
||||||
// Array of data
|
// Array of data
|
||||||
data := make([]string, v.Count)
|
data := make([]uint32, v.Count)
|
||||||
for entry := 0; entry < int(v.Count); entry++ {
|
for entry := 0; entry < int(v.Count); entry++ {
|
||||||
entryOffset := v.Offset + int32(entry)*int32(VarTypes[int(v.Type)].Size)
|
entryOffset := v.Offset + int32(entry)*int32(VarTypes[int(v.Type)].Size)
|
||||||
rbuf := buf[entryOffset : entryOffset+int32(VarTypes[int(v.Type)].Size)]
|
rbuf := buf[entryOffset : entryOffset+int32(VarTypes[int(v.Type)].Size)]
|
||||||
newValue := fmt.Sprintf("0x%x", int(binary.LittleEndian.Uint32(rbuf)))
|
data[entry] = binary.LittleEndian.Uint32(rbuf)
|
||||||
data[entry] = newValue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v.Value = data
|
v.Value = data
|
||||||
} else {
|
} else {
|
||||||
// Single value
|
// Single value
|
||||||
v.Value = fmt.Sprintf("0x%x", int(binary.LittleEndian.Uint32(rbuf)))
|
v.Value = binary.LittleEndian.Uint32(rbuf)
|
||||||
}
|
}
|
||||||
case IRSDK_float:
|
case IRSDK_float:
|
||||||
if v.Count > 1 {
|
if v.Count > 1 {
|
||||||
@@ -295,14 +261,10 @@ func (i *IBT) readData(buf []byte) error {
|
|||||||
v.Value = math.Float64frombits(uint64(binary.LittleEndian.Uint64(rbuf)))
|
v.Value = math.Float64frombits(uint64(binary.LittleEndian.Uint64(rbuf)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// --------------
|
|
||||||
|
|
||||||
i.Vars.Vars[k] = v
|
i.Vars.Vars[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the bitfield variables here
|
|
||||||
i.parseBitfieldVariables()
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +272,8 @@ func (i *IBT) readData(buf []byte) error {
|
|||||||
// live and offline data
|
// live and offline data
|
||||||
func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
||||||
// This is what happens if we are reading live data
|
// This is what happens if we are reading live data
|
||||||
if i.winUtils != nil {
|
switch i.Opts.SourceType {
|
||||||
|
case SharedMemoryFile:
|
||||||
// Put a way to check if the sim is active here
|
// Put a way to check if the sim is active here
|
||||||
// fmt.Println("NOT CHECKING IF SIM IS ACTIVE - ADD ME")
|
// fmt.Println("NOT CHECKING IF SIM IS ACTIVE - ADD ME")
|
||||||
|
|
||||||
@@ -344,23 +307,29 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
|||||||
buf := make([]byte, i.Headers.BufLen)
|
buf := make([]byte, i.Headers.BufLen)
|
||||||
|
|
||||||
_, err := i.File.ReadAt(buf, int64(start))
|
_, err := i.File.ReadAt(buf, int64(start))
|
||||||
|
if err == io.EOF {
|
||||||
|
return Ended, nil
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed, err
|
return Failed, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if i.Opts.IBTExport {
|
if i.Opts.IBTExport {
|
||||||
// Dirty attempt at getting this to work to write to a memory mapped file
|
// Dirty attempt at getting this to work to write to a memory mapped file
|
||||||
|
var offset int64 = 0
|
||||||
switch i.Opts.IBTExportType {
|
switch i.Opts.IBTExportType {
|
||||||
case IBTFile:
|
case IBTFile:
|
||||||
err = i.exportIBT(buf, int64(i.Headers.BufOffset+i.Vars.RecorderTick*i.Headers.BufLen))
|
// i.Opts.Logger.Debug("Reading live data and exporting to IBT file")
|
||||||
if err != nil {
|
offset = int64(i.Headers.BufOffset + i.Vars.RecorderTick*i.Headers.BufLen)
|
||||||
log.Printf("Failed to export live telemetry data: %v", err)
|
|
||||||
}
|
|
||||||
case SharedMemoryFile:
|
case SharedMemoryFile:
|
||||||
err = i.exportIBT(buf, int64(i.Headers.BufOffset))
|
// i.Opts.Logger.Debug("Reading live data and exporting to SHM file")
|
||||||
if err != nil {
|
offset = int64(i.Headers.BufOffset)
|
||||||
log.Printf("Failed to export live telemetry data: %v", err)
|
}
|
||||||
}
|
|
||||||
|
err = i.exportIBT(buf, offset)
|
||||||
|
if err != nil {
|
||||||
|
i.Opts.Logger.Debug(fmt.Sprintf("Failed to export offline telemetry data: %+v", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,37 +338,15 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
|||||||
return Unknown, err
|
return Unknown, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == io.EOF {
|
|
||||||
return Ended, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Document why this is here, I don't remember the exact words right now
|
// Document why this is here, I don't remember the exact words right now
|
||||||
i.Vars.RecorderTick++
|
i.Vars.RecorderTick++
|
||||||
} else {
|
case IBTFile:
|
||||||
// This is what happens if we are reading from an .ibt file
|
// This is what happens if we are reading from an .ibt file
|
||||||
// This will get the dataframe corresponding to a given tick
|
// This will get the dataframe corresponding to a given tick
|
||||||
start := i.Headers.BufOffset + i.Vars.Tick*i.Headers.BufLen
|
start := i.Headers.BufOffset + i.Vars.Tick*i.Headers.BufLen
|
||||||
buf := make([]byte, i.Headers.BufLen)
|
buf := make([]byte, i.Headers.BufLen)
|
||||||
_, err := i.File.ReadAt(buf, int64(start))
|
_, err := i.File.ReadAt(buf, int64(start))
|
||||||
|
|
||||||
// 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
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
return Ended, nil
|
return Ended, nil
|
||||||
}
|
}
|
||||||
@@ -407,6 +354,26 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
|||||||
return Unknown, err
|
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)
|
err = i.readData(buf)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
log.Fatalf("What happened?\n%v\n", err)
|
log.Fatalf("What happened?\n%v\n", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user