some fixes regarding iracing provider transforms and working the auto detection
This commit is contained in:
@@ -49,7 +49,7 @@ func (t *TelemetryService) OnFindProvider(prov providers.Provider) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add some way of retriggering this. Currently it should:
|
// TODO: add some way of retriggering this. Currently it should:
|
||||||
// start monitoring on startup -> find provider -> stop monitoring
|
// start monitoring on startup -> find provider -> stop monitoring (when game closes for example)
|
||||||
func (t *TelemetryService) FindProvider(ctx context.Context, callback func(providers.Provider),
|
func (t *TelemetryService) FindProvider(ctx context.Context, callback func(providers.Provider),
|
||||||
) {
|
) {
|
||||||
ticker := time.NewTicker(2 * time.Second)
|
ticker := time.NewTicker(2 * time.Second)
|
||||||
@@ -157,9 +157,8 @@ func (t *TelemetryService) StartStream() {
|
|||||||
|
|
||||||
// Start the new stream
|
// Start the new stream
|
||||||
simInCh, _ := t.ativeProvider.Stream()
|
simInCh, _ := t.ativeProvider.Stream()
|
||||||
// if err != nil {
|
// TODO: the provider needs to be able to tell the data has stopped
|
||||||
// // NOTE
|
// so we can restart the provider lookup routine
|
||||||
// }
|
|
||||||
|
|
||||||
// Create the context so we can control the lifecycle
|
// Create the context so we can control the lifecycle
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|||||||
@@ -7,40 +7,35 @@ func EmptyTransform(v any, out *TelemetryField) {
|
|||||||
out.Raw = uint64('-')
|
out.Raw = uint64('-')
|
||||||
}
|
}
|
||||||
|
|
||||||
func UInt8Transform(v any, out *TelemetryField) {
|
func UInt8Transform(v int, out *TelemetryField) {
|
||||||
out.Type = DataTypeUINT8
|
out.Type = DataTypeUINT8
|
||||||
|
|
||||||
if v == nil {
|
if v < 0 {
|
||||||
out.Raw = 0
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
out.Raw = uint64(v.(int))
|
|
||||||
}
|
|
||||||
|
|
||||||
func FloatToStringTransform(v float32, out *TelemetryField) {
|
|
||||||
out.Type = DataTypeSTRING
|
|
||||||
out.Str = strconv.FormatFloat(float64(v), 'f', 1, 32)
|
|
||||||
}
|
|
||||||
|
|
||||||
func FloatToStringTransformDEPRECATE(v any, out *TelemetryField) {
|
|
||||||
out.Type = DataTypeSTRING
|
|
||||||
|
|
||||||
if v == nil {
|
|
||||||
out.Str = "inv"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
out.Str = strconv.FormatFloat(float64(v.(float32)), 'f', 1, 32)
|
|
||||||
}
|
|
||||||
|
|
||||||
func FloatToUInt8TransformDEPRECATE(v any, out *TelemetryField) {
|
|
||||||
out.Type = DataTypeUINT8
|
|
||||||
|
|
||||||
if v == nil {
|
|
||||||
out.Raw = uint64(0)
|
out.Raw = uint64(0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
out.Raw = uint64(v.(float32))
|
out.Raw = uint64(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func FloatToStringTransform(v float32, out *TelemetryField) {
|
||||||
|
out.Type = DataTypeSTRING
|
||||||
|
|
||||||
|
if v < 0.0 {
|
||||||
|
out.Str = "inv"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
out.Str = strconv.FormatFloat(float64(v), 'f', 1, 32)
|
||||||
|
}
|
||||||
|
|
||||||
|
func FloatToUInt8Transform(v float32, out *TelemetryField) {
|
||||||
|
out.Type = DataTypeUINT8
|
||||||
|
|
||||||
|
if v < 0.0 {
|
||||||
|
out.Raw = uint64(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
out.Raw = uint64(v)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-6
@@ -30,11 +30,8 @@ type VirtualField interface {
|
|||||||
// BoundField is the data structure we use to bind the telemetry provider's data
|
// BoundField is the data structure we use to bind the telemetry provider's data
|
||||||
// to our internal telemetry fields
|
// to our internal telemetry fields
|
||||||
type BoundField struct {
|
type BoundField struct {
|
||||||
Key string // NOTE: to be deprecated
|
ID FieldID
|
||||||
ID FieldID
|
Update func(out *TelemetryField)
|
||||||
Fetch func() any // NOTE: to be deprecated
|
|
||||||
Transform func(any, *TelemetryField) // NOTE: to be deprecated
|
|
||||||
Update func(out *TelemetryField)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var bufferPool = sync.Pool{
|
var bufferPool = sync.Pool{
|
||||||
@@ -105,7 +102,8 @@ func (tf *TelemetryField) Pack(dest []byte) []byte {
|
|||||||
case DataTypeINT32, DataTypeUINT32:
|
case DataTypeINT32, DataTypeUINT32:
|
||||||
dest = append(dest, uint8(tf.Raw), uint8(tf.Raw>>8), uint8(tf.Raw>>16), uint8(tf.Raw>>24))
|
dest = append(dest, uint8(tf.Raw), uint8(tf.Raw>>8), uint8(tf.Raw>>16), uint8(tf.Raw>>24))
|
||||||
case DataTypeINT64, DataTypeUINT64:
|
case DataTypeINT64, DataTypeUINT64:
|
||||||
dest = append(dest, uint8(tf.Raw), uint8(tf.Raw>>8), uint8(tf.Raw>>16),
|
dest = append(
|
||||||
|
dest, uint8(tf.Raw), uint8(tf.Raw>>8), uint8(tf.Raw>>16),
|
||||||
uint8(tf.Raw>>24), uint8(tf.Raw>>32), uint8(tf.Raw>>40), uint8(tf.Raw>>48),
|
uint8(tf.Raw>>24), uint8(tf.Raw>>32), uint8(tf.Raw>>40), uint8(tf.Raw>>48),
|
||||||
uint8(tf.Raw>>56),
|
uint8(tf.Raw>>56),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ type TelemetryProvider interface {
|
|||||||
StopStream()
|
StopStream()
|
||||||
Stream() (<-chan TelemetryData, error)
|
Stream() (<-chan TelemetryData, error)
|
||||||
Subscribe(map[int16]FieldID)
|
Subscribe(map[int16]FieldID)
|
||||||
|
Stalled() bool // Return true if no fresh data is coming
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user