Updated the function that checks for the sim running and how we stream data
This commit is contained in:
@@ -126,6 +126,10 @@ func (i *IRacing) stream(ctx context.Context) {
|
|||||||
i.data.InitialTime = time.Now()
|
i.data.InitialTime = time.Now()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
// Put this into the configuration file
|
||||||
|
consecutiveTimeouts := 0
|
||||||
|
maxTimeouts := 30
|
||||||
|
dataEvTimeout := 100
|
||||||
for {
|
for {
|
||||||
// Explicitly intercept cancellation
|
// Explicitly intercept cancellation
|
||||||
select {
|
select {
|
||||||
@@ -134,17 +138,8 @@ func (i *IRacing) stream(ctx context.Context) {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix this logic
|
if i.SDK.CheckForDataEvent(time.Duration(dataEvTimeout) * time.Millisecond) {
|
||||||
// We start by checking if we do or do not have data available
|
consecutiveTimeouts = 0
|
||||||
// if !i.isDataAvailable() {
|
|
||||||
// i.logger.Info("isDataAvailable check failed. Cancelling stream...")
|
|
||||||
// i.streamCancel()
|
|
||||||
// }
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
case <-i.ticker.C:
|
|
||||||
i.readData()
|
i.readData()
|
||||||
|
|
||||||
// Publish data
|
// Publish data
|
||||||
@@ -153,6 +148,15 @@ func (i *IRacing) stream(ctx context.Context) {
|
|||||||
default:
|
default:
|
||||||
// skip this data, don't allow publishers to lag behind
|
// skip this data, don't allow publishers to lag behind
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
consecutiveTimeouts++
|
||||||
|
if consecutiveTimeouts >= maxTimeouts {
|
||||||
|
i.logger.Info("Telemetry stream stalled")
|
||||||
|
if i.streamCancel != nil {
|
||||||
|
i.streamCancel()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -175,7 +179,6 @@ func (i *IRacing) readData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set up virtual binds
|
// Set up virtual binds
|
||||||
i.logger.Debug("Entering virtual binds loop")
|
|
||||||
for _, vBind := range i.data.VirtualBinds {
|
for _, vBind := range i.data.VirtualBinds {
|
||||||
vBind.Process(i.data)
|
vBind.Process(i.data)
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-22
@@ -1,35 +1,33 @@
|
|||||||
package iracing
|
package iracing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
"log/slog"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ESilva15/goirsdk"
|
"github.com/ESilva15/goirsdk"
|
||||||
|
eventutils "github.com/ESilva15/goirsdk/eventutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IsRunning() bool {
|
func IsRunning() bool {
|
||||||
sdk, err := goirsdk.Init(goirsdk.Options{
|
irUtils, err := eventutils.Init()
|
||||||
SourceType: goirsdk.SharedMemoryFile,
|
|
||||||
})
|
|
||||||
defer sdk.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
log.Fatalf("Failed to initialize mmaputils: %v", err)
|
||||||
|
}
|
||||||
|
defer irUtils.Close()
|
||||||
|
|
||||||
|
// 2. Connect to the OS event (Win32 Event on Windows, POSIX Semaphore on Linux)
|
||||||
|
if err := irUtils.OpenEvent(goirsdk.IRSDK_DATAVALIDEVENTNAME); err != nil {
|
||||||
|
log.Fatalf("Failed to open event: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if sdk.SessionStateInvalid() {
|
// We now check for some consecutive data events
|
||||||
// slog.Debug("state is invalid")
|
for range 3 {
|
||||||
// sessionState, ok := sdk.Vars.Vars["SessionState"]
|
if !irUtils.CheckValidDataEvent(1 * time.Second) {
|
||||||
// if !ok {
|
slog.Debug("timed out waiting for DataValidEvent")
|
||||||
// slog.Debug("SessionState not ok")
|
return false
|
||||||
// return false
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// state, ok := sessionState.Value.(int)
|
|
||||||
// if !ok {
|
|
||||||
// slog.Debug(fmt.Sprintf("can't typecast: %+v", sessionState))
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// slog.Debug(fmt.Sprintf("%d", state))
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user