Setting the environment to handle multiple data sinks

im scaffolding it but first I recon I will make this transfer data to
the lcd and then we will take a look at making it pretty
This commit is contained in:
2026-03-03 23:11:24 +00:00
parent da315b1c7b
commit c9086cae56
3 changed files with 26 additions and 16 deletions
+1 -1
View File
@@ -41,5 +41,5 @@ func (i *IRacing) UpdateData() error {
} }
func (i *IRacing) GetSessionInfo() (interface{}, error) { func (i *IRacing) GetSessionInfo() (interface{}, error) {
return i.SDK.SessionInfo, nil return i.SDK.SessionInfo, nil
} }
+19 -15
View File
@@ -34,16 +34,20 @@ const (
) )
type IRacingService struct { type IRacingService struct {
Message chan string Message chan string
// Timers
LastMessageTime time.Time LastMessageTime time.Time
Data *esdi.SimulationData
DataView *esdi.DataPacket
InitialTime time.Time InitialTime time.Time
LastTime time.Time LastTime time.Time
Mut sync.Mutex
ticker *time.Ticker ticker *time.Ticker
Irsdk *goirsdk.IBT // Data vessels
// data *esdi.SimulationData
dataView *esdi.DataPacket
// Data access control
Mut sync.Mutex
// Source
Irsdk *goirsdk.IBT
// Stream control
isRunning bool isRunning bool
Stream chan string Stream chan string
StreamCancel context.CancelFunc StreamCancel context.CancelFunc
@@ -66,8 +70,8 @@ func NewIRacingService(msg chan string) *IRacingService {
ticker: time.NewTicker(time.Second / 60), ticker: time.NewTicker(time.Second / 60),
Irsdk: irsdk, Irsdk: irsdk,
Stream: make(chan string, 10), Stream: make(chan string, 10),
Data: &esdi.SimulationData{}, data: &esdi.SimulationData{},
DataView: &esdi.DataPacket{}, dataView: &esdi.DataPacket{},
isRunning: false, isRunning: false,
} }
} }
@@ -127,9 +131,9 @@ func (irs *IRacingService) ReadData(ctx context.Context) {
irs.getVehicleData() irs.getVehicleData()
// Test the actual dataPacket we are sending over the wire // Test the actual dataPacket we are sending over the wire
copyBytes(irs.DataView.Speed[:], SpeedLen, fmt.Sprintf("%3d", irs.Data.Speed)) copyBytes(irs.dataView.Speed[:], SpeedLen, fmt.Sprintf("%3d", irs.data.Speed))
copyBytes(irs.DataView.Gear[:], GearLen, fmt.Sprintf("%2d", irs.Data.Gear)) copyBytes(irs.dataView.Gear[:], GearLen, fmt.Sprintf("%2d", irs.data.Gear))
copyBytes(irs.DataView.RPM[:], RpmLen, fmt.Sprintf("%3d", irs.Data.RPM)) copyBytes(irs.dataView.RPM[:], RpmLen, fmt.Sprintf("%3d", irs.data.RPM))
irs.LastMessageTime = time.Now() irs.LastMessageTime = time.Now()
} }
@@ -139,9 +143,9 @@ func (irs *IRacingService) getVehicleData() {
curRPM := irs.Irsdk.Vars.Vars["RPM"].Value curRPM := irs.Irsdk.Vars.Vars["RPM"].Value
curSpeed := irs.Irsdk.Vars.Vars["Speed"].Value curSpeed := irs.Irsdk.Vars.Vars["Speed"].Value
irs.Data.Gear = int32(curGear.(int)) irs.data.Gear = int32(curGear.(int))
irs.Data.RPM = int32(curRPM.(float32)) irs.data.RPM = int32(curRPM.(float32))
irs.Data.Speed = int32(msToKph(curSpeed.(float32))) irs.data.Speed = int32(msToKph(curSpeed.(float32)))
} }
func copyBytes(dest []byte, destSize int, src string) { func copyBytes(dest []byte, destSize int, src string) {
@@ -179,7 +183,7 @@ func (irs *IRacingService) Stringified() string {
// buffer.WriteString("Car data:\n") // buffer.WriteString("Car data:\n")
buffer.WriteString(fmt.Sprintf("Gear: %d, RPM: %d, Speed: %d\n\n", buffer.WriteString(fmt.Sprintf("Gear: %d, RPM: %d, Speed: %d\n\n",
irs.Data.Gear, irs.Data.RPM, irs.Data.Speed)) irs.data.Gear, irs.data.RPM, irs.data.Speed))
// buffer.WriteString("Fuel data:\n") // buffer.WriteString("Fuel data:\n")
// buffer.WriteString(fmt.Sprintf("Fuel Est: %s\n\n", e.dataPacket.FuelEst)) // buffer.WriteString(fmt.Sprintf("Fuel Est: %s\n\n", e.dataPacket.FuelEst))
+6
View File
@@ -0,0 +1,6 @@
package services
// Telemetry will be our base struct to handle telemetry data
// It should hook to a data sink and handle it like iRacing, BeamNG, AC and so on
type Telemetry struct {
}