Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5da82a6ec3 | ||
|
|
2fd6f6abb6 | ||
|
|
d102a45bee | ||
|
|
db30d9146d | ||
|
|
481b746aef | ||
|
|
48b10afbba | ||
|
|
584d13e1fd | ||
|
|
d677c66a22 | ||
|
|
d14649d80c |
@@ -8,47 +8,54 @@ available peripheral: [CDashDisplay](https://github.com/ESilva15/CDashDisplay).
|
|||||||
If anyone finds this project useful for anything at all it would be pretty cool.
|
If anyone finds this project useful for anything at all it would be pretty cool.
|
||||||
My main goal is to learn and have some fun.
|
My main goal is to learn and have some fun.
|
||||||
|
|
||||||
Currently it can read from a `.ibt` file or live telemetry from iRacing.
|
|
||||||
It can only be ran from the terminal:
|
## Usage
|
||||||
`go run . offline -p <port> -i <ibt-file>`
|
To launch the software, compile (TBD) or just run it with: `go run . tui`
|
||||||
|
|
||||||
|
You should see something like this:
|
||||||

|

|
||||||
|
|
||||||
|
The current behaviour is very opaque.
|
||||||
|
|
||||||
or to view the live data:
|
What is happening in the background is the software looks up for the configured
|
||||||
`go run . live -p <port>`
|
devices and for available telemetry providers.
|
||||||
|
|
||||||
|
Once it finds a device, in this case the CDashDisplay, it will try to configure
|
||||||
|
it against the available telemetry provider.
|
||||||
|
|
||||||
|
After configuring it it will automatically start streaming data from the
|
||||||
|
telemetry provider into the CDashDisplay.
|
||||||
|
|
||||||
|
Using the `arrows` you can navigate to the `stream` item on the list and then
|
||||||
|
go to the update button and press `s` to see the output on the terminal.
|
||||||
|
|
||||||
|
I upgraded the backend significantly and there's plenty of work to be done on
|
||||||
|
the frontend. I know its quite bad right now.
|
||||||
|
|
||||||
|
|
||||||
|
## Compatibility:
|
||||||
Games implemented so far:
|
Games implemented so far:
|
||||||
- [iRacing](https://www.iracing.com/) using the [goirsdk](https://github.com/ESilva15/goirsdk)
|
- [iRacing](https://www.iracing.com/) using the [goirsdk](https://github.com/ESilva15/goirsdk)
|
||||||
|
- [BeamNG.drive](https://www.beamng.com/game/) using the [gobngsdk](https://github.com/ESilva15/gobngsdk)
|
||||||
|
|
||||||
|
Peripherals:
|
||||||
|
- [CDashDisplay](https://github.com/ESilva15/CDashDisplay)
|
||||||
|
|
||||||
<!-- Games being implemented: -->
|
<!-- Games being implemented: -->
|
||||||
<!-- - [BeamNG.drive](https://www.beamng.com/game/) using the [gobngsdk](https://github.com/ESilva15/gobngsdk) -->
|
|
||||||
<!---->
|
<!---->
|
||||||
<!-- Games to be implemented: -->
|
<!-- Games to be implemented: -->
|
||||||
<!-- - [Assetto Corsa](https://assettocorsa.gg/) -->
|
<!-- - [Assetto Corsa](https://assettocorsa.gg/) -->
|
||||||
|
|
||||||
|
|
||||||
## Roadmap
|
|
||||||
- [X] Implement the interface for a data source
|
|
||||||
- [ ] Configuration of the peripherals via ESDI
|
|
||||||
- [ ] Detection of the display
|
|
||||||
- [ ] LapTime Calculator
|
|
||||||
- [ ] A very long list useful stuff like flags, position, more info about
|
|
||||||
other drivers, track conditions and so on so forth
|
|
||||||
- [ ] Telemetry analysis tool
|
|
||||||
- [ ] Better user interface
|
|
||||||
|
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
### Mockservers
|
### Mockservers
|
||||||
To mock [BeamNG.drive](https://www.beamng.com/game/), I built
|
I'm using a mockserver developed by myself that pretty much mimicks the telemetry
|
||||||
[BeaMNGMockOg](https://github.com/ESilva15/BeamNGMockOg) (should have though longer
|
output from the actual simulators. It uses the SDKs I developed to do so with the
|
||||||
about the name).
|
added bonus of being able to run the project on Linux and mainly develop it.
|
||||||
You create a recording by launching the BeamNG and then launching the mockserver with:
|
|
||||||
`BeamNGMockOg record -a 127.0.0.1 -p 4443 -o output.bin`.
|
Just go to [TelemetryMockserver on GitHub](https://github.com/ESilva15/TelemetryMockserver) and follow
|
||||||
|
the instructions there.
|
||||||
|
|
||||||
To replay the recording:
|
|
||||||
`BeamNGMockOg replay [--loop] -a 127.0.0.1 -p 4443 -i input.bin`
|
|
||||||
|
|
||||||
### Troubleshooting
|
### Troubleshooting
|
||||||
#### Can't see BeamNG data coming through
|
#### Can't see BeamNG data coming through
|
||||||
@@ -74,4 +81,3 @@ pprof:
|
|||||||
## Shameless begging
|
## Shameless begging
|
||||||
Hey, doesn't hurt to try, its free either way:
|
Hey, doesn't hurt to try, its free either way:
|
||||||
[Buy me a coffee!](buymeacoffee.com/ESilva_15)
|
[Buy me a coffee!](buymeacoffee.com/ESilva_15)
|
||||||
|
|
||||||
|
|||||||
@@ -405,6 +405,11 @@ func (d *CDashDisplay) UnloadLayout() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cds *CDashDisplay) resetState() {
|
||||||
|
cds.fieldToWindows = make(map[telemetry.FieldID][]int16)
|
||||||
|
cds.State.Layout = NewLayoutTree()
|
||||||
|
}
|
||||||
|
|
||||||
func (cds *CDashDisplay) reset() error {
|
func (cds *CDashDisplay) reset() error {
|
||||||
err := cds.WT.SendCommand(resetCMDID, []byte{0x01, 0x02, 0x03, 0x04}, nil)
|
err := cds.WT.SendCommand(resetCMDID, []byte{0x01, 0x02, 0x03, 0x04}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -413,6 +418,8 @@ func (cds *CDashDisplay) reset() error {
|
|||||||
|
|
||||||
time.Sleep(3000 * time.Millisecond)
|
time.Sleep(3000 * time.Millisecond)
|
||||||
|
|
||||||
|
cds.resetState()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
module esdi
|
module esdi
|
||||||
|
|
||||||
go 1.27.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ESilva15/ESgoRepl v0.1.0
|
github.com/ESilva15/gobngsdk v1.2.0
|
||||||
github.com/ESilva15/gobngsdk v1.1.3
|
github.com/ESilva15/goirsdk v0.3.9
|
||||||
github.com/ESilva15/goirsdk v0.3.0
|
|
||||||
github.com/arl/statsviz v0.8.0
|
github.com/arl/statsviz v0.8.0
|
||||||
github.com/gdamore/tcell/v2 v2.8.1
|
github.com/gdamore/tcell/v2 v2.8.1
|
||||||
github.com/rivo/tview v0.42.0
|
github.com/rivo/tview v0.42.0
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
github.com/ESilva15/ESgoRepl v0.1.0 h1:hOVcRBfdP8Yw1kLr2tFoM3SetV7vxFswKjzfAtq8UgM=
|
github.com/ESilva15/gobngsdk v1.2.0 h1:jX2ByFaIHnjCdPmrj1JiqCoNRLyu4vqIXC7++EUOCK4=
|
||||||
github.com/ESilva15/ESgoRepl v0.1.0/go.mod h1:O2JQMyEgHy0zf9UvzvLNvp2w95T2uazc3torrzRmG9Y=
|
github.com/ESilva15/gobngsdk v1.2.0/go.mod h1:cKLaZRgM0tGGXDvosaSjHnxeyC5Y6rg7zCLqEUJnOzw=
|
||||||
github.com/ESilva15/gobngsdk v1.1.3 h1:CFaz2KjHKnBLrQuEN1QHOd1761cWM/rmTwLpSLrgbe4=
|
github.com/ESilva15/goirsdk v0.3.9 h1:p+C7JtTTlo75Tq+CMH4bL70rItSLIotkXcHx+mCgSuc=
|
||||||
github.com/ESilva15/gobngsdk v1.1.3/go.mod h1:cKLaZRgM0tGGXDvosaSjHnxeyC5Y6rg7zCLqEUJnOzw=
|
github.com/ESilva15/goirsdk v0.3.9/go.mod h1:5borQbw+L4fe9b58JFHRHZwrzz0sMVAteuYbRnFOc0Q=
|
||||||
github.com/ESilva15/goirsdk v0.3.0 h1:6D95Avq7chikGHwEUKh7Y/HaLHOWQ75Qxaz8oMDSfrw=
|
|
||||||
github.com/ESilva15/goirsdk v0.3.0/go.mod h1:5borQbw+L4fe9b58JFHRHZwrzz0sMVAteuYbRnFOc0Q=
|
|
||||||
github.com/arl/statsviz v0.8.0 h1:O6GjjVxEDxcByAucOSl29HaGYLXsuwA3ujJw8H9E7/U=
|
github.com/arl/statsviz v0.8.0 h1:O6GjjVxEDxcByAucOSl29HaGYLXsuwA3ujJw8H9E7/U=
|
||||||
github.com/arl/statsviz v0.8.0/go.mod h1:XlrbiT7xYT03xaW9JMMfD8KFUhBOESJwfyNJu83PbB0=
|
github.com/arl/statsviz v0.8.0/go.mod h1:XlrbiT7xYT03xaW9JMMfD8KFUhBOESJwfyNJu83PbB0=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 113 KiB |
+11
-12
@@ -186,13 +186,11 @@ func (b *BeamNG) Subscribe(requestFields []telemetry.FieldID) []string {
|
|||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
|
|
||||||
func (b *BeamNG) readData() {
|
func (b *BeamNG) readData() error {
|
||||||
slog.Debug("READING THIS DATA")
|
|
||||||
ogSnapshot, err := b.SDK.Update()
|
ogSnapshot, err := b.SDK.Update()
|
||||||
slog.Debug("THE DATA WAS READ")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Error getting data", "error", err)
|
slog.Error("Error getting data", "error", err)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.mut.Lock()
|
b.mut.Lock()
|
||||||
@@ -200,22 +198,20 @@ func (b *BeamNG) readData() {
|
|||||||
defer b.mut.Unlock()
|
defer b.mut.Unlock()
|
||||||
|
|
||||||
// Read 1 to 1 data
|
// Read 1 to 1 data
|
||||||
slog.Debug("Reading normal data binds")
|
|
||||||
for _, bind := range b.data.ActiveBinds {
|
for _, bind := range b.data.ActiveBinds {
|
||||||
slog.Debug("Current bind: ", "id", bind.ID)
|
|
||||||
b.updaters[bind.ID](&b.data.Values[bind.ID])
|
b.updaters[bind.ID](&b.data.Values[bind.ID])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up virtual binds
|
// Set up virtual binds
|
||||||
slog.Debug("Entering virtual binds loop")
|
|
||||||
for _, vBind := range b.data.VirtualBinds {
|
for _, vBind := range b.data.VirtualBinds {
|
||||||
// NOTE: delete the logs here, they are really bad
|
// NOTE: delete the logs here, they are really bad
|
||||||
slog.Debug("Processing virtual binds")
|
|
||||||
vBind.Process(b.data)
|
vBind.Process(b.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.data.PenultimateDataPoll = b.data.LastDataPoll
|
b.data.PenultimateDataPoll = b.data.LastDataPoll
|
||||||
b.data.LastDataPoll = time.Now()
|
b.data.LastDataPoll = time.Now()
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BeamNG) stream(ctx context.Context) <-chan telemetry.TelemetryData {
|
func (b *BeamNG) stream(ctx context.Context) <-chan telemetry.TelemetryData {
|
||||||
@@ -239,14 +235,17 @@ func (b *BeamNG) stream(ctx context.Context) <-chan telemetry.TelemetryData {
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-b.ticker.C:
|
case <-b.ticker.C:
|
||||||
slog.Debug("READING DATA")
|
err := b.readData()
|
||||||
b.readData()
|
if err != nil {
|
||||||
slog.Debug("READ DATA")
|
if b.streamCancel != nil {
|
||||||
|
b.streamCancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Publish data
|
// Publish data
|
||||||
select {
|
select {
|
||||||
case outCh <- *b.data:
|
case outCh <- *b.data:
|
||||||
slog.Debug("PUBLISHED DATA")
|
// Successfuly read and sent data
|
||||||
default:
|
default:
|
||||||
// skip this data, don't allow publishers to lag behind
|
// skip this data, don't allow publishers to lag behind
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ func (i *IRacing) stream(ctx context.Context) <-chan telemetry.TelemetryData {
|
|||||||
|
|
||||||
// Put this into the configuration file
|
// Put this into the configuration file
|
||||||
consecutiveTimeouts := 0
|
consecutiveTimeouts := 0
|
||||||
maxTimeouts := 30
|
maxTimeouts := 10
|
||||||
dataEvTimeout := 100
|
dataEvTimeout := 30
|
||||||
for {
|
for {
|
||||||
// Explicitly intercept cancellation
|
// Explicitly intercept cancellation
|
||||||
select {
|
select {
|
||||||
|
|||||||
+6
-1
@@ -83,14 +83,17 @@ func (ds *DeviceService) PeripheralExists(pname string) bool {
|
|||||||
// Getters [END] ---------------------------------------------------------------
|
// Getters [END] ---------------------------------------------------------------
|
||||||
|
|
||||||
// Actions [START] -------------------------------------------------------------
|
// Actions [START] -------------------------------------------------------------
|
||||||
func (ds *DeviceService) StartStream() {
|
func (ds *DeviceService) StartStream(ch <-chan telemetry.TelemetryData) {
|
||||||
// NOTE: i'm using this pattern a whole lot. Maybe I can create a struct to handle this
|
// NOTE: i'm using this pattern a whole lot. Maybe I can create a struct to handle this
|
||||||
|
ds.SetTelemetryChannel(ch)
|
||||||
|
|
||||||
var ctx context.Context
|
var ctx context.Context
|
||||||
ctx, ds.streamCancel = context.WithCancel(context.Background())
|
ctx, ds.streamCancel = context.WithCancel(context.Background())
|
||||||
|
|
||||||
ds.PSS.OnStartStream()
|
ds.PSS.OnStartStream()
|
||||||
|
|
||||||
go ds.transmit(ctx)
|
go ds.transmit(ctx)
|
||||||
|
ds.Messages <- "Device service started stream\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DeviceService) StopStream() {
|
func (ds *DeviceService) StopStream() {
|
||||||
@@ -154,6 +157,8 @@ func (ds *DeviceService) peripheralConfigured(pname string, fields []telemetry.F
|
|||||||
// We need to retrigger field subscription here
|
// We need to retrigger field subscription here
|
||||||
subscribedTo := ds.triggerFieldSubscription(fields)
|
subscribedTo := ds.triggerFieldSubscription(fields)
|
||||||
ds.Messages <- fmt.Sprintf("subscribed to fields: %q\n", subscribedTo)
|
ds.Messages <- fmt.Sprintf("subscribed to fields: %q\n", subscribedTo)
|
||||||
|
|
||||||
|
ds.PSS.OnStartStreamPeripheral(pname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callbacks [END] -------------------------------------------------------------
|
// Callbacks [END] -------------------------------------------------------------
|
||||||
|
|||||||
@@ -1 +1,6 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
|
func (ds *DeviceService) OnStoppedMidStream() {
|
||||||
|
// Need to make every device be unconfigured
|
||||||
|
ds.StopStream()
|
||||||
|
}
|
||||||
|
|||||||
@@ -211,14 +211,25 @@ func (pss *PeripheralStateStore) OnStartStream() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pss *PeripheralStateStore) OnStartStreamPeripheral(pname string) {
|
||||||
|
state, err := pss.GetState(pname)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if state.State == DeviceIsConfigured {
|
||||||
|
pss.setDeviceIsStreaming(pname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (pss *PeripheralStateStore) OnStopStream() {
|
func (pss *PeripheralStateStore) OnStopStream() {
|
||||||
pss.mu.Lock()
|
pss.mu.Lock()
|
||||||
pss.isStreaming = false
|
pss.isStreaming = false
|
||||||
pss.mu.Unlock()
|
pss.mu.Unlock()
|
||||||
|
|
||||||
for _, state := range pss.GetStates() {
|
for _, state := range pss.GetStates() {
|
||||||
if state.State == DeviceIsStreaming {
|
if state.State > DeviceIsConfigured {
|
||||||
pss.setDeviceConfigured(state.device.Name)
|
pss.setDeviceUnconfigured(state.device.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -349,6 +360,7 @@ func (pss *PeripheralStateStore) configurePeripheral(
|
|||||||
onFailure(pname)
|
onFailure(pname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
pss.Messages <- fmt.Sprintf("Configuring peripheral for provider: %s\n", provider)
|
||||||
|
|
||||||
err = state.Peripheral.Setup(provider)
|
err = state.Peripheral.Setup(provider)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ func NewOrchestrator(logger *slog.Logger) (*Orchestrator, error) {
|
|||||||
devService.triggerFieldSubscription = telemService.SubscribeToFields
|
devService.triggerFieldSubscription = telemService.SubscribeToFields
|
||||||
|
|
||||||
// Setup telemetry service callbacks
|
// Setup telemetry service callbacks
|
||||||
// telemService.getRequiredFields = devService.GetRequiredFields
|
telemService.startedStreaming = devService.StartStream
|
||||||
|
telemService.providerStoppedMidStream = devService.OnStoppedMidStream
|
||||||
|
|
||||||
return &Orchestrator{
|
return &Orchestrator{
|
||||||
DeviceService: devService,
|
DeviceService: devService,
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ type TelemetryService struct {
|
|||||||
CtxHealthcheck context.Context
|
CtxHealthcheck context.Context
|
||||||
healthCheckCancel context.CancelFunc
|
healthCheckCancel context.CancelFunc
|
||||||
// Callbacks
|
// Callbacks
|
||||||
|
startedStreaming func(ch <-chan telemetry.TelemetryData)
|
||||||
|
providerStoppedMidStream func()
|
||||||
// Devices data request
|
// Devices data request
|
||||||
// peripheralProvider func() []peripheral.Peripheral
|
// peripheralProvider func() []peripheral.Peripheral
|
||||||
// getRequiredFields func() []telemetry.FieldID
|
// getRequiredFields func() []telemetry.FieldID
|
||||||
@@ -138,6 +140,7 @@ func (t *TelemetryService) dropActiveProvider() {
|
|||||||
t.cancelForward()
|
t.cancelForward()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: can we move the stop stream into the provider Close() method?
|
||||||
t.activeProvider.StopStream()
|
t.activeProvider.StopStream()
|
||||||
t.activeProvider.Close()
|
t.activeProvider.Close()
|
||||||
t.activeProvider = nil
|
t.activeProvider = nil
|
||||||
@@ -204,21 +207,17 @@ func (t *TelemetryService) StopStream() {
|
|||||||
t.isStreaming = false
|
t.isStreaming = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TelemetryService) StartStream() {
|
func (t *TelemetryService) StartStream() <-chan telemetry.TelemetryData {
|
||||||
slog.Debug("Stream started")
|
|
||||||
|
|
||||||
// Start the new stream
|
// Start the new stream
|
||||||
if t.activeProvider == nil {
|
if t.activeProvider == nil {
|
||||||
slog.Debug("there's no active provider. not starting the stream")
|
slog.Debug("there's no active provider. not starting the stream")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the provider healthcheck
|
// Stop the provider healthcheck
|
||||||
t.healthCheckCancel()
|
t.healthCheckCancel()
|
||||||
|
|
||||||
simInCh, _ := t.activeProvider.Stream()
|
simInCh, _ := t.activeProvider.Stream()
|
||||||
// TODO: the provider needs to be able to tell the data has stopped
|
|
||||||
// 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())
|
||||||
@@ -227,6 +226,10 @@ func (t *TelemetryService) StartStream() {
|
|||||||
// Multiplex this data
|
// Multiplex this data
|
||||||
go t.multiplexData(ctx, simInCh)
|
go t.multiplexData(ctx, simInCh)
|
||||||
t.isStreaming = true
|
t.isStreaming = true
|
||||||
|
|
||||||
|
t.Messages <- "Provider has started streaming data\n"
|
||||||
|
|
||||||
|
return simInCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TelemetryService) multiplexData(ctx context.Context, dataCh <-chan telem.TelemetryData) {
|
func (t *TelemetryService) multiplexData(ctx context.Context, dataCh <-chan telem.TelemetryData) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ func (t *TelemetryService) onFindProvider(prov telem.TelemetryProvider) {
|
|||||||
// Attach to the provider
|
// Attach to the provider
|
||||||
t.logger.Info("found provider for " + prov.Name())
|
t.logger.Info("found provider for " + prov.Name())
|
||||||
t.Messages <- fmt.Sprintf("Found provider \"%s\"\n", prov.Name())
|
t.Messages <- fmt.Sprintf("Found provider \"%s\"\n", prov.Name())
|
||||||
|
|
||||||
err := t.SwitchProvider(prov)
|
err := t.SwitchProvider(prov)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Messages <- fmt.Sprintf("Failed to switch to provider: %+v\n", err.Error())
|
t.Messages <- fmt.Sprintf("Failed to switch to provider: %+v\n", err.Error())
|
||||||
@@ -26,6 +27,11 @@ func (t *TelemetryService) onFindProvider(prov telem.TelemetryProvider) {
|
|||||||
// Start the healthcheck on our provider so we can drop it if it stops
|
// Start the healthcheck on our provider so we can drop it if it stops
|
||||||
t.CtxHealthcheck, t.healthCheckCancel = context.WithCancel(context.Background())
|
t.CtxHealthcheck, t.healthCheckCancel = context.WithCancel(context.Background())
|
||||||
go t.ProviderMonitor(t.CtxHealthcheck)
|
go t.ProviderMonitor(t.CtxHealthcheck)
|
||||||
|
|
||||||
|
ch := t.StartStream()
|
||||||
|
t.startedStreaming(ch)
|
||||||
|
|
||||||
|
t.Messages <- "provider switch completed"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TelemetryService) onProviderStopsMidStream() {
|
func (t *TelemetryService) onProviderStopsMidStream() {
|
||||||
@@ -34,6 +40,10 @@ func (t *TelemetryService) onProviderStopsMidStream() {
|
|||||||
// if the stream stopped we have to restart the devices and everything
|
// if the stream stopped we have to restart the devices and everything
|
||||||
t.Messages <- "Telemetry provider stopped mid stream\n"
|
t.Messages <- "Telemetry provider stopped mid stream\n"
|
||||||
t.logger.Info("cleaning dropped provider and restarting lookup service")
|
t.logger.Info("cleaning dropped provider and restarting lookup service")
|
||||||
|
|
||||||
t.dropActiveProvider()
|
t.dropActiveProvider()
|
||||||
go t.FindProvider(t.CtxMonitor)
|
go t.FindProvider(t.CtxMonitor)
|
||||||
|
|
||||||
|
// Tell the devices service that we lost the thing
|
||||||
|
t.providerStoppedMidStream()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,23 +88,9 @@ func (sc *StreamingCtrl) registerHooks() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this isn't the startstop method/action anymore. It should show up the stream
|
||||||
|
// visualizer - TODO: add metrics to the visualizer too, instead of just data
|
||||||
func (sc *StreamingCtrl) StartStop() {
|
func (sc *StreamingCtrl) StartStop() {
|
||||||
if sc.TelemServ.IsStreaming() {
|
|
||||||
slog.Info("stopping stream")
|
|
||||||
|
|
||||||
sc.TelemServ.StopStream()
|
|
||||||
sc.DevService.StopStream()
|
|
||||||
|
|
||||||
sc.isRunning = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// stream is not running, we have to start it now
|
|
||||||
// NOTE:
|
|
||||||
// Subscribe the only existing device - needs to be discovered by now
|
|
||||||
slog.Debug("setting the data stream for device servie")
|
|
||||||
sc.DevService.SetTelemetryChannel(sc.TelemServ.SubscribeListener("DeviceService", 1))
|
|
||||||
|
|
||||||
dev, err := sc.DevService.GetPeripheral(uidevice.NAME)
|
dev, err := sc.DevService.GetPeripheral(uidevice.NAME)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if uiDev, ok := dev.(*uidevice.UIDevice); ok {
|
if uiDev, ok := dev.(*uidevice.UIDevice); ok {
|
||||||
@@ -112,14 +98,6 @@ func (sc *StreamingCtrl) StartStop() {
|
|||||||
go sc.listenToUIStream()
|
go sc.listenToUIStream()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Debug("starting services")
|
|
||||||
sc.DevService.StartStream()
|
|
||||||
sc.TelemServ.StartStream()
|
|
||||||
|
|
||||||
sc.isRunning = true
|
|
||||||
|
|
||||||
slog.Debug("starting stream")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *StreamingCtrl) parseStreamUpdateForm(form *views.StreamOptionsView) (*models.StreamOptions, error) {
|
func (sc *StreamingCtrl) parseStreamUpdateForm(form *views.StreamOptionsView) (*models.StreamOptions, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user