Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
422e8fcdc2 |
+79
-5
@@ -3,10 +3,13 @@
|
||||
package mockserver
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
@@ -64,18 +67,89 @@ func (r *Replayer) renderToTerminal(ctx context.Context) {
|
||||
}
|
||||
|
||||
// NOTE: temporary until I make a better view
|
||||
lastPercent := -1
|
||||
var s strings.Builder
|
||||
var bytesReader bytes.Reader
|
||||
og := bngsdk.Outgauge{}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case data := <-r.dataViewCh:
|
||||
percent := int(float64(data.SizeRead) / float64(fileInfo.Size()) * 100)
|
||||
if percent != lastPercent {
|
||||
fmt.Printf("\rReplayed: %d%%", percent)
|
||||
lastPercent = percent
|
||||
// Reset to the start of the terminal
|
||||
s.Reset()
|
||||
fmt.Fprintf(os.Stdout, "\x1b[2J\x1b[H")
|
||||
|
||||
bytesReader.Reset(data.Data)
|
||||
err := binary.Read(&bytesReader, binary.LittleEndian, &og)
|
||||
if err != nil {
|
||||
fmt.Fprintf(&s, "FAILED TO PARSE DATA\nError: %+v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
percent := int(float64(data.SizeRead) / float64(fileInfo.Size()) * 100)
|
||||
fmt.Fprintf(&s, "Replayed: %d%%\n", percent)
|
||||
// NOTE: write a string serialization function on the SDK itself
|
||||
fmt.Fprint(&s, "Outgauge {\n")
|
||||
fmt.Fprintf(&s, " Time: %d ms\n", og.Time)
|
||||
fmt.Fprintf(&s, " Car: %s\n", og.Car)
|
||||
fmt.Fprintf(&s, " Flags: %b\n", og.Flags)
|
||||
fmt.Fprintf(&s, " Gear: %d\n", og.Gear)
|
||||
fmt.Fprintf(&s, " Plid: %d\n", og.Plid)
|
||||
fmt.Fprintf(&s, " Speed: %f m/s\n", og.Speed)
|
||||
fmt.Fprintf(&s, " RPM: %f RPM\n", og.RPM)
|
||||
fmt.Fprintf(&s, " Turbo: %f Bar\n", og.Turbo)
|
||||
fmt.Fprintf(&s, " EngTemp: %f °C\n", og.EngTemp)
|
||||
fmt.Fprintf(&s, " Fuel: %f\n", og.Fuel)
|
||||
fmt.Fprintf(&s, " OilPressure: %f Bar\n", og.OilPressure)
|
||||
fmt.Fprintf(&s, " OilTemp: %f °C\n", og.OilTemp)
|
||||
fmt.Fprintf(&s, " DashLights: %b\n", og.DashLights)
|
||||
fmt.Fprintf(&s, " ShowLights: %b\n", og.ShowLights)
|
||||
fmt.Fprintf(&s, " Throttle: %f\n", og.Throttle)
|
||||
fmt.Fprintf(&s, " Brakes: %f\n", og.Brake)
|
||||
fmt.Fprintf(&s, " Clutch: %f\n", og.Clutch)
|
||||
fmt.Fprintf(&s, " Display1: %s\n", og.Display1)
|
||||
fmt.Fprintf(&s, " Display2: %s\n", og.Display2)
|
||||
fmt.Fprintf(&s, " ID: %d\n", og.Display2)
|
||||
fmt.Fprint(&s, "}\n\n")
|
||||
|
||||
fmt.Fprint(&s, "DashLights {\n")
|
||||
fmt.Fprintf(&s, " DL_SHIFT: %t\n", og.DashLights&bngsdk.DL_SHIFT != 0)
|
||||
fmt.Fprintf(&s, " DL_FULLBEAM: %t\n", og.DashLights&bngsdk.DL_FULLBEAM != 0)
|
||||
fmt.Fprintf(&s, " DL_HANDBRAKE: %t\n", og.DashLights&bngsdk.DL_HANDBRAKE != 0)
|
||||
fmt.Fprintf(&s, " DL_PITSPEED: %t\n", og.DashLights&bngsdk.DL_PITSPEED != 0)
|
||||
fmt.Fprintf(&s, " DL_TC: %t\n", og.DashLights&bngsdk.DL_TC != 0)
|
||||
fmt.Fprintf(&s, " DL_SIGNAL_L: %t\n", og.DashLights&bngsdk.DL_SIGNAL_L != 0)
|
||||
fmt.Fprintf(&s, " DL_SIGNAL_R: %t\n", og.DashLights&bngsdk.DL_SIGNAL_R != 0)
|
||||
fmt.Fprintf(&s, " DL_SIGNAL_ANY: %t\n", og.DashLights&bngsdk.DL_SIGNAL_ANY != 0)
|
||||
fmt.Fprintf(&s, " DL_OILWARN: %t\n", og.DashLights&bngsdk.DL_OILWARN != 0)
|
||||
fmt.Fprintf(&s, " DL_BATTERY: %t\n", og.DashLights&bngsdk.DL_BATTERY != 0)
|
||||
fmt.Fprintf(&s, " DL_ABS: %t\n", og.DashLights&bngsdk.DL_ABS != 0)
|
||||
fmt.Fprintf(&s, " DL_SPARE: %t\n", og.DashLights&bngsdk.DL_SPARE != 0)
|
||||
fmt.Fprint(&s, "}\n\n")
|
||||
|
||||
fmt.Fprint(&s, "ShowLights {\n") // Fixed typo "ShowLigths"
|
||||
fmt.Fprintf(&s, " DL_SHIFT: %t\n", og.ShowLights&bngsdk.DL_SHIFT != 0)
|
||||
fmt.Fprintf(&s, " DL_FULLBEAM: %t\n", og.ShowLights&bngsdk.DL_FULLBEAM != 0)
|
||||
fmt.Fprintf(&s, " DL_HANDBRAKE: %t\n", og.ShowLights&bngsdk.DL_HANDBRAKE != 0)
|
||||
fmt.Fprintf(&s, " DL_PITSPEED: %t\n", og.ShowLights&bngsdk.DL_PITSPEED != 0)
|
||||
fmt.Fprintf(&s, " DL_TC: %t\n", og.ShowLights&bngsdk.DL_TC != 0)
|
||||
fmt.Fprintf(&s, " DL_SIGNAL_L: %t\n", og.ShowLights&bngsdk.DL_SIGNAL_L != 0)
|
||||
fmt.Fprintf(&s, " DL_SIGNAL_R: %t\n", og.ShowLights&bngsdk.DL_SIGNAL_R != 0)
|
||||
fmt.Fprintf(&s, " DL_SIGNAL_ANY: %t\n", og.ShowLights&bngsdk.DL_SIGNAL_ANY != 0)
|
||||
fmt.Fprintf(&s, " DL_OILWARN: %t\n", og.ShowLights&bngsdk.DL_OILWARN != 0)
|
||||
fmt.Fprintf(&s, " DL_BATTERY: %t\n", og.ShowLights&bngsdk.DL_BATTERY != 0)
|
||||
fmt.Fprintf(&s, " DL_ABS: %t\n", og.ShowLights&bngsdk.DL_ABS != 0)
|
||||
fmt.Fprintf(&s, " DL_SPARE: %t\n", og.ShowLights&bngsdk.DL_SPARE != 0)
|
||||
fmt.Fprint(&s, "}\n\n")
|
||||
|
||||
fmt.Fprint(&s, "Flags {\n")
|
||||
fmt.Fprintf(&s, " OG_TURBO (Has Turbo): %t\n", og.Flags&bngsdk.OG_TURBO != 0)
|
||||
fmt.Fprintf(&s, " OG_KM (Is Metric): %t\n", og.Flags&bngsdk.OG_KM != 0)
|
||||
fmt.Fprintf(&s, " OG_BAR (Pressure): %t\n", og.Flags&bngsdk.OG_BAR != 0)
|
||||
fmt.Fprint(&s, "}")
|
||||
|
||||
fmt.Fprint(os.Stdout, s.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user