update the current provider to take advantage of these last commits
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// Package conversions will host all of our unit conversion functions
|
// Package conversions will host all of our unit conversion functions
|
||||||
package conversions
|
package conversions
|
||||||
|
|
||||||
func MsToKph(v float32) int {
|
func MsToKph(v float32) uint16 {
|
||||||
return int((3600 * v) / 1000)
|
return uint16((3600 * v) / 1000)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,12 @@ package iracing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
conv "esdi/conversions"
|
conv "esdi/conversions"
|
||||||
helper "esdi/helpers"
|
|
||||||
telem "esdi/telemetry"
|
telem "esdi/telemetry"
|
||||||
|
|
||||||
"github.com/ESilva15/goirsdk"
|
"github.com/ESilva15/goirsdk"
|
||||||
@@ -24,9 +22,7 @@ type IRacing struct {
|
|||||||
data *telem.TelemetryData
|
data *telem.TelemetryData
|
||||||
|
|
||||||
// Timing information
|
// Timing information
|
||||||
initialTime time.Time
|
ticker *time.Ticker // ticker will keep polling intervals constant
|
||||||
lastMessageTime time.Time
|
|
||||||
ticker *time.Ticker // ticker will keep polling intervals constant
|
|
||||||
|
|
||||||
// Stream
|
// Stream
|
||||||
streamCh chan telem.TelemetryData
|
streamCh chan telem.TelemetryData
|
||||||
@@ -34,7 +30,11 @@ type IRacing struct {
|
|||||||
// isRunning bool
|
// 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
|
var err error
|
||||||
|
|
||||||
// Open the input file if provided
|
// 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) {
|
func (i *IRacing) stream(ctx context.Context) {
|
||||||
i.initialTime = time.Now()
|
i.data.InitialTime = time.Now()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@@ -71,7 +71,11 @@ func (i *IRacing) stream(ctx context.Context) {
|
|||||||
i.ReadData()
|
i.ReadData()
|
||||||
|
|
||||||
// Publish data
|
// 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.readVehicleData()
|
||||||
|
|
||||||
i.lastMessageTime = time.Now()
|
i.data.PenultimateDataPoll = i.data.LastDataPoll
|
||||||
|
i.data.LastDataPoll = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IRacing) readVehicleData() {
|
func (i *IRacing) readVehicleData() {
|
||||||
@@ -98,21 +103,24 @@ func (i *IRacing) readVehicleData() {
|
|||||||
curRPM := i.SDK.Vars.Vars["RPM"].Value
|
curRPM := i.SDK.Vars.Vars["RPM"].Value
|
||||||
curSpeed := i.SDK.Vars.Vars["Speed"].Value
|
curSpeed := i.SDK.Vars.Vars["Speed"].Value
|
||||||
|
|
||||||
speed := fmt.Sprintf("%3d", int32(conv.MsToKph(curSpeed.(float32))))
|
speed := conv.MsToKph(curSpeed.(float32))
|
||||||
gear := fmt.Sprintf("%2d", int32(curGear.(int)))
|
gear := uint8(curGear.(int))
|
||||||
rpm := fmt.Sprintf("%3d", int32(curRPM.(float32)))
|
rpm := uint16(curRPM.(float32))
|
||||||
|
|
||||||
speedArray := i.data.Values["Speed"]
|
i.data.Values[telem.Speed] = telem.TelemetryField{
|
||||||
helper.CopyBytes(speedArray[:], speed)
|
Type: telem.DataTypeUINT16,
|
||||||
i.data.Values["Speed"] = speedArray
|
Raw: uint64(speed),
|
||||||
|
}
|
||||||
|
|
||||||
gearArray := i.data.Values["Gear"]
|
i.data.Values[telem.Gear] = telem.TelemetryField{
|
||||||
helper.CopyBytes(gearArray[:], gear)
|
Type: telem.DataTypeUINT8,
|
||||||
i.data.Values["Gear"] = gearArray
|
Raw: uint64(gear),
|
||||||
|
}
|
||||||
|
|
||||||
rpmArray := i.data.Values["RPM"]
|
i.data.Values[telem.RPM] = telem.TelemetryField{
|
||||||
helper.CopyBytes(rpmArray[:], rpm)
|
Type: telem.DataTypeUINT16,
|
||||||
i.data.Values["RPM"] = rpmArray
|
Raw: uint64(rpm),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IRacing) Stream() (<-chan telem.TelemetryData, error) {
|
func (i *IRacing) Stream() (<-chan telem.TelemetryData, error) {
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package views
|
package views
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"esdi/telemetry"
|
telem "esdi/telemetry"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"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))
|
sv.TextView.SetText(stringify(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringify(data telemetry.TelemetryData) string {
|
func stringify(data *telem.TelemetryData) string {
|
||||||
var buffer strings.Builder
|
var buffer strings.Builder
|
||||||
|
|
||||||
buffer.WriteString(fmt.Sprintf("Gear: %d, RPM: %d, Speed: %d\n\n",
|
delta := data.LastDataPoll.Sub(data.PenultimateDataPoll)
|
||||||
data.Values["Gear"], data.Values["RPM"], data.Values["Speed"]))
|
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()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user