From da9f786611fcd0f84b805378c4854346edb4350d Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Fri, 6 Mar 2026 19:31:53 +0000 Subject: [PATCH] update the current provider to take advantage of these last commits --- conversions/conversions.go | 4 +-- providers/iracing/iracing.go | 50 +++++++++++++++++++++--------------- tui/internal/views/stream.go | 18 +++++++++---- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/conversions/conversions.go b/conversions/conversions.go index 1a135d9..e8f8976 100644 --- a/conversions/conversions.go +++ b/conversions/conversions.go @@ -1,6 +1,6 @@ // Package conversions will host all of our unit conversion functions package conversions -func MsToKph(v float32) int { - return int((3600 * v) / 1000) +func MsToKph(v float32) uint16 { + return uint16((3600 * v) / 1000) } diff --git a/providers/iracing/iracing.go b/providers/iracing/iracing.go index 9a34a89..47798f8 100644 --- a/providers/iracing/iracing.go +++ b/providers/iracing/iracing.go @@ -2,14 +2,12 @@ package iracing import ( "context" - "fmt" "log" "os" "sync" "time" conv "esdi/conversions" - helper "esdi/helpers" telem "esdi/telemetry" "github.com/ESilva15/goirsdk" @@ -24,9 +22,7 @@ type IRacing struct { data *telem.TelemetryData // Timing information - initialTime time.Time - lastMessageTime time.Time - ticker *time.Ticker // ticker will keep polling intervals constant + ticker *time.Ticker // ticker will keep polling intervals constant // Stream streamCh chan telem.TelemetryData @@ -34,7 +30,11 @@ type IRacing struct { // isRunning bool } -func NewIRacingProvider(source string, telemOut string, yamlOut string) (*IRacing, error) { +func NewIRacingProvider( + source string, + telemOut string, + yamlOut string, +) (*IRacing, error) { var err error // Open the input file if provided @@ -60,7 +60,7 @@ func NewIRacingProvider(source string, telemOut string, yamlOut string) (*IRacin } func (i *IRacing) stream(ctx context.Context) { - i.initialTime = time.Now() + i.data.InitialTime = time.Now() go func() { for { @@ -71,7 +71,11 @@ func (i *IRacing) stream(ctx context.Context) { i.ReadData() // Publish data - i.streamCh <- *i.data + select { + case i.streamCh <- *i.data: + default: + // skip this data, don't allow publishers to lag behind + } } } }() @@ -90,7 +94,8 @@ func (i *IRacing) ReadData() { i.readVehicleData() - i.lastMessageTime = time.Now() + i.data.PenultimateDataPoll = i.data.LastDataPoll + i.data.LastDataPoll = time.Now() } func (i *IRacing) readVehicleData() { @@ -98,21 +103,24 @@ func (i *IRacing) readVehicleData() { curRPM := i.SDK.Vars.Vars["RPM"].Value curSpeed := i.SDK.Vars.Vars["Speed"].Value - speed := fmt.Sprintf("%3d", int32(conv.MsToKph(curSpeed.(float32)))) - gear := fmt.Sprintf("%2d", int32(curGear.(int))) - rpm := fmt.Sprintf("%3d", int32(curRPM.(float32))) + speed := conv.MsToKph(curSpeed.(float32)) + gear := uint8(curGear.(int)) + rpm := uint16(curRPM.(float32)) - speedArray := i.data.Values["Speed"] - helper.CopyBytes(speedArray[:], speed) - i.data.Values["Speed"] = speedArray + i.data.Values[telem.Speed] = telem.TelemetryField{ + Type: telem.DataTypeUINT16, + Raw: uint64(speed), + } - gearArray := i.data.Values["Gear"] - helper.CopyBytes(gearArray[:], gear) - i.data.Values["Gear"] = gearArray + i.data.Values[telem.Gear] = telem.TelemetryField{ + Type: telem.DataTypeUINT8, + Raw: uint64(gear), + } - rpmArray := i.data.Values["RPM"] - helper.CopyBytes(rpmArray[:], rpm) - i.data.Values["RPM"] = rpmArray + i.data.Values[telem.RPM] = telem.TelemetryField{ + Type: telem.DataTypeUINT16, + Raw: uint64(rpm), + } } func (i *IRacing) Stream() (<-chan telem.TelemetryData, error) { diff --git a/tui/internal/views/stream.go b/tui/internal/views/stream.go index 38d097e..ddc8ca6 100644 --- a/tui/internal/views/stream.go +++ b/tui/internal/views/stream.go @@ -1,9 +1,10 @@ package views import ( - "esdi/telemetry" + telem "esdi/telemetry" "fmt" "strings" + "time" "github.com/rivo/tview" ) @@ -29,15 +30,22 @@ func NewStreamView() *StreamView { } } -func (sv *StreamView) Update(data telemetry.TelemetryData) { +func (sv *StreamView) Update(data *telem.TelemetryData) { sv.TextView.SetText(stringify(data)) } -func stringify(data telemetry.TelemetryData) string { +func stringify(data *telem.TelemetryData) string { var buffer strings.Builder - buffer.WriteString(fmt.Sprintf("Gear: %d, RPM: %d, Speed: %d\n\n", - data.Values["Gear"], data.Values["RPM"], data.Values["Speed"])) + delta := data.LastDataPoll.Sub(data.PenultimateDataPoll) + buffer.WriteString(fmt.Sprintf("[%s]\n", time.Now().Format("2006/01/02 15:04:05.000"))) + buffer.WriteString(fmt.Sprintf("Delta: %d [%f]\n\n", delta.Milliseconds(), 1000.0/60.0)) + + buffer.WriteString(fmt.Sprintf("Gear: %s, RPM: %s, Speed: %s\n", + data.Values[telem.Gear].String(), + data.Values[telem.RPM].String(), + data.Values[telem.Speed].String(), + )) return buffer.String() }