From a6683df10b234a36dc98d3f55450301fde49c3f1 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Fri, 18 Sep 2026 15:38:17 +0100 Subject: [PATCH 1/4] fixed the start and stop behaviour. it was crashing --- Docs/Streaming_Flow.md | 1 + providers/iracing/iracing.go | 27 +-- services/devices.go | 8 - services/telemetry.go | 228 ++++++++++++++------------ tui/internal/controllers/streaming.go | 35 +--- 5 files changed, 152 insertions(+), 147 deletions(-) create mode 100644 Docs/Streaming_Flow.md diff --git a/Docs/Streaming_Flow.md b/Docs/Streaming_Flow.md new file mode 100644 index 0000000..3a88ed0 --- /dev/null +++ b/Docs/Streaming_Flow.md @@ -0,0 +1 @@ +# Streaming Flow diff --git a/providers/iracing/iracing.go b/providers/iracing/iracing.go index 8826c4a..c792f4f 100644 --- a/providers/iracing/iracing.go +++ b/providers/iracing/iracing.go @@ -33,7 +33,8 @@ type IRacing struct { ticker *time.Ticker // ticker will keep polling intervals constant // Stream - streamCh chan telemetry.TelemetryData + wg sync.WaitGroup + // streamCh chan telemetry.TelemetryData streamCancel context.CancelFunc } @@ -50,10 +51,10 @@ func NewIRacingProvider( } provider := &IRacing{ - logger: logger, - SDK: sdk, - data: telemetry.NewTelemetryData(), - streamCh: make(chan telemetry.TelemetryData, 1), + logger: logger, + SDK: sdk, + data: telemetry.NewTelemetryData(), + // streamCh: make(chan telemetry.TelemetryData, 1), // NOTE: This is because I stupidly recorded a test IBT file in 240 // TODO: make this configurable from the user side ticker: time.NewTicker(time.Second / 240), @@ -129,11 +130,14 @@ func (i *IRacing) isDataAvailable() bool { return true } -func (i *IRacing) stream(ctx context.Context) { +func (i *IRacing) stream(ctx context.Context) <-chan telemetry.TelemetryData { i.data.InitialTime = time.Now() + outCh := make(chan telemetry.TelemetryData) + i.wg.Add(1) go func() { - defer close(i.streamCh) + defer i.wg.Done() + defer close(outCh) // Put this into the configuration file consecutiveTimeouts := 0 @@ -153,7 +157,7 @@ func (i *IRacing) stream(ctx context.Context) { // Publish data select { - case i.streamCh <- *i.data: + case outCh <- *i.data: default: // skip this data, don't allow publishers to lag behind } @@ -169,6 +173,8 @@ func (i *IRacing) stream(ctx context.Context) { } } }() + + return outCh } func (i *IRacing) readData() { @@ -205,9 +211,9 @@ func (i *IRacing) Stream() (<-chan telemetry.TelemetryData, error) { ctx, i.streamCancel = context.WithCancel(context.Background()) // Start the stream - i.stream(ctx) + ch := i.stream(ctx) - return i.streamCh, nil + return ch, nil } func (i *IRacing) StopStream() { @@ -216,6 +222,7 @@ func (i *IRacing) StopStream() { } i.streamCancel() + i.wg.Wait() i.streamCancel = nil } diff --git a/services/devices.go b/services/devices.go index c1119ff..714025d 100644 --- a/services/devices.go +++ b/services/devices.go @@ -84,14 +84,6 @@ func (ds *DeviceService) FindDevices() { } } -// func (ds *DeviceService) SubscribeFields() error { -// for _, dev := range ds.Devices { -// fields := dev.RequiredFields() -// } -// -// return nil -// } - func (ds *DeviceService) RegisterDevice(dev peripheral.Peripheral) error { ds.mu.Lock() defer ds.mu.Unlock() diff --git a/services/telemetry.go b/services/telemetry.go index d4bb5db..7af4cb4 100644 --- a/services/telemetry.go +++ b/services/telemetry.go @@ -16,6 +16,8 @@ import ( type TelemetryService struct { logger *slog.Logger devService *DeviceService + // Streaming + isStreaming bool // Concurrency protection mut sync.RWMutex activeProvider telem.TelemetryProvider @@ -66,6 +68,92 @@ func (t *TelemetryService) ProviderMonitor(ctx context.Context) { } } +// Listener Control [START] ---------------------------------------------------- + +func (t *TelemetryService) SubscribeListener(id string, bufferSize int) <-chan telem.TelemetryData { + t.mut.Lock() + defer t.mut.Unlock() + + // NOTE: is this truly necessary? + // return the channel if it already exists + if ch, exists := t.listeners[id]; exists { + return ch + } + + ch := make(chan telem.TelemetryData, bufferSize) + t.listeners[id] = ch + + t.logger.Info("New stream subscriber registered", "id", id) + return ch +} + +func (t *TelemetryService) UnsubscribeListener(id string) { + t.mut.Lock() + defer t.mut.Unlock() + + if ch, exists := t.listeners[id]; exists { + close(ch) + delete(t.listeners, id) + t.logger.Info("Stream subscriber removed", "id", id) + } +} + +func (t *TelemetryService) SubscribeToFields() []telem.FieldID { + seen := make(map[telemetry.FieldID]struct{}) + var allFields []telemetry.FieldID + + for _, dev := range t.devService.Devices { + for _, field := range dev.RequiredFields() { + if _, exists := seen[field]; !exists { + seen[field] = struct{}{} + allFields = append(allFields, field) + } + } + } + + t.logger.Debug("requested fields", "fields", allFields) + t.activeProvider.Subscribe(allFields) + + return allFields +} + +// Listener Control [END] ------------------------------------------------------ + +// Provider Control [START] ---------------------------------------------------- + +func (t *TelemetryService) HasActiveProvider() bool { + if t.activeProvider == nil { + return false + } + + return true +} + +func (t *TelemetryService) dropActiveProvider() { + if t.cancelForward != nil { + t.cancelForward() + } + + t.activeProvider.StopStream() + t.activeProvider.Close() + t.activeProvider = nil +} + +func (t *TelemetryService) SwitchProvider(newProvider telem.TelemetryProvider) error { + t.mut.Lock() + defer t.mut.Unlock() + + // Clean up the current to be old provider + if t.activeProvider != nil { + t.dropActiveProvider() + } + + // Assign the new provider + t.activeProvider = newProvider + + return nil +} + func (t *TelemetryService) onProviderHealthCheckFailed() { // Just restart the whole lookup process go t.FindProvider(t.CtxMonitor) @@ -123,19 +211,46 @@ func (t *TelemetryService) FindProvider(ctx context.Context) { } } -func (t *TelemetryService) SwitchProvider(newProvider telem.TelemetryProvider) error { +// Provider Control [END] ------------------------------------------------------ + +// Streaming Control [START] --------------------------------------------------- + +func (t *TelemetryService) StopStream() { t.mut.Lock() defer t.mut.Unlock() - // Clean up the current to be old provider - if t.activeProvider != nil { - t.dropActiveProvider() + if t.cancelForward != nil { + t.cancelForward() + t.cancelForward = nil } - // Assign the new provider - t.activeProvider = newProvider + t.activeProvider.StopStream() + t.isStreaming = false +} - return nil +func (t *TelemetryService) StartStream() { + slog.Debug("Stream started") + + // Start the new stream + if t.activeProvider == nil { + slog.Debug("there's no active provider. not starting the stream") + return + } + + // Stop the provider healthcheck + t.healthCheckCancel() + + 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 + ctx, cancel := context.WithCancel(context.Background()) + t.cancelForward = cancel + + // Multiplex this data + go t.multiplexData(ctx, simInCh) + t.isStreaming = true } func (t *TelemetryService) multiplexData(ctx context.Context, dataCh <-chan telem.TelemetryData) { @@ -165,101 +280,8 @@ func (t *TelemetryService) multiplexData(ctx context.Context, dataCh <-chan tele } } -func (t *TelemetryService) dropActiveProvider() { - if t.cancelForward != nil { - t.cancelForward() - } - - t.activeProvider.StopStream() - t.activeProvider.Close() - t.activeProvider = nil +func (t *TelemetryService) IsStreaming() bool { + return t.isStreaming } -func (t *TelemetryService) SubscribeListener(id string, bufferSize int) <-chan telem.TelemetryData { - t.mut.Lock() - defer t.mut.Unlock() - - // NOTE: is this truly necessary? - // return the channel if it already exists - if ch, exists := t.listeners[id]; exists { - return ch - } - - ch := make(chan telem.TelemetryData, bufferSize) - t.listeners[id] = ch - - t.logger.Info("New stream subscriber registered", "id", id) - return ch -} - -func (t *TelemetryService) UnsubscribeListener(id string) { - t.mut.Lock() - defer t.mut.Unlock() - - if ch, exists := t.listeners[id]; exists { - close(ch) - delete(t.listeners, id) - t.logger.Info("Stream subscriber removed", "id", id) - } -} - -func (t *TelemetryService) SubscribeToFields() { - seen := make(map[telemetry.FieldID]struct{}) - var allFields []telemetry.FieldID - - for _, dev := range t.devService.Devices { - for _, field := range dev.RequiredFields() { - if _, exists := seen[field]; !exists { - seen[field] = struct{}{} - allFields = append(allFields, field) - } - } - } - - t.logger.Debug("requested fields", "fields", allFields) - t.activeProvider.Subscribe(allFields) -} - -func (t *TelemetryService) StartStream() { - slog.Debug("Stream started") - - // Start the new stream - if t.activeProvider == nil { - slog.Debug("there's no active provider. not starting the stream") - return - } - - // Stop the provider healthcheck - t.healthCheckCancel() - - 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 - ctx, cancel := context.WithCancel(context.Background()) - t.cancelForward = cancel - - // Multiplex this data - go t.multiplexData(ctx, simInCh) -} - -func (t *TelemetryService) StopStream() { - t.mut.Lock() - defer t.mut.Unlock() - - if t.cancelForward != nil { - t.cancelForward() - t.cancelForward = nil - } - - t.activeProvider.StopStream() -} - -func (t *TelemetryService) HasActiveProvider() bool { - if t.activeProvider == nil { - return false - } - - return true -} +// Streaming Control [END] ----------------------------------------------------- diff --git a/tui/internal/controllers/streaming.go b/tui/internal/controllers/streaming.go index cad0299..3a05dc5 100644 --- a/tui/internal/controllers/streaming.go +++ b/tui/internal/controllers/streaming.go @@ -18,7 +18,7 @@ import ( type StreamingCtrl struct { *Controller - Service *services.DeviceService + DevService *services.DeviceService StreamView *views.StreamToolView Messages chan string Internal chan string @@ -45,18 +45,16 @@ func NewStreamingCtrl( ctrl := &StreamingCtrl{ Controller: base, - Service: devService, + DevService: devService, TelemServ: serTelem, Messages: make(chan string, 10), Internal: make(chan string, 10), TelemetryCh: make(chan telemetry.TelemetryData, 1), Run: false, StreamView: streamView, - isRunning: false, } ctrl.registerHooks() - // ctrl.subscribeListeners() return ctrl } @@ -96,11 +94,11 @@ func (sc *StreamingCtrl) registerHooks() { } func (sc *StreamingCtrl) StartStop() { - if sc.isRunning { + if sc.TelemServ.IsStreaming() { slog.Info("stopping stream") sc.TelemServ.StopStream() - sc.Service.StopStream() + sc.DevService.StopStream() sc.isRunning = false return @@ -110,9 +108,9 @@ func (sc *StreamingCtrl) StartStop() { // NOTE: // Subscribe the only existing device - needs to be discovered by now slog.Debug("setting the data stream for device servie") - sc.Service.SetTelemetryChannel(sc.TelemServ.SubscribeListener("DeviceService", 1)) + sc.DevService.SetTelemetryChannel(sc.TelemServ.SubscribeListener("DeviceService", 1)) - dev, err := sc.Service.GetDevice(uidevice.NAME) + dev, err := sc.DevService.GetDevice(uidevice.NAME) if err == nil { if uiDev, ok := dev.(*uidevice.UIDevice); ok { sc.TelemetryCh = uiDev.DataChannel() @@ -121,7 +119,7 @@ func (sc *StreamingCtrl) StartStop() { } slog.Debug("starting services") - sc.Service.StartStream() + sc.DevService.StartStream() sc.TelemServ.StartStream() sc.isRunning = true @@ -161,24 +159,11 @@ func (sc *StreamingCtrl) updateStream() { // Performance reasoning: this is not used during the high frequency data transmission // so we can get away with using a map for convenience here func (sc *StreamingCtrl) SetInternalState() { - // Acquire the cdashdisplay - // displayIF, err := sc.Service.GetDevice(cdashdisplay.NAME) - // if err != nil { - // sc.Messages <- "failed to get " + cdashdisplay.NAME - // return - // } - // display, ok := displayIF.(*cdashdisplay.CDashDisplay) - // if !ok { - // sc.Messages <- "failed to acquire " + cdashdisplay.NAME - // return - // } - // --- - - sc.TelemServ.SubscribeToFields() + fields := sc.TelemServ.SubscribeToFields() // sc.Messages <- fmt.Sprintf("Subscribed Fields: %+v [%d]\n", fields, len(fields)) // Should I update this? - sc.Messages <- fmt.Sprintf("Subscribed to fields\n") + sc.Messages <- fmt.Sprintf("Subscribed to fields: %+v", fields) } func (sc *StreamingCtrl) listenToUIStream() { @@ -190,8 +175,6 @@ func (sc *StreamingCtrl) listenToUIStream() { } isDrawing.Store(true) - // sc.Logger.Debug("got data", "data", msg) - // Capture locally telemetryMsg := msg From a2e14ba6a90c1c114a9cec111db556544694d2aa Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Fri, 18 Sep 2026 15:42:34 +0100 Subject: [PATCH 2/4] applied the same start-stop scheme to the BeamNG provider --- providers/beamng/beamng.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/providers/beamng/beamng.go b/providers/beamng/beamng.go index 816635d..f07b933 100644 --- a/providers/beamng/beamng.go +++ b/providers/beamng/beamng.go @@ -28,7 +28,7 @@ type BeamNG struct { updaters [telemetry.MaxFields]func(*telemetry.TelemetryField) // stream control - streamCh chan telemetry.TelemetryData + wg sync.WaitGroup streamCancel context.CancelFunc // timing @@ -46,12 +46,11 @@ func NewBeamNGProvider(logger *slog.Logger, opts *bngsdk.Options) (*BeamNG, erro } provider := &BeamNG{ - logger: logger.With("TelemetryProvider", NAME), - streamCh: make(chan telemetry.TelemetryData, 1), - data: telemetry.NewTelemetryData(), - SDK: beam, - og: &bngsdk.Outgauge{}, - ticker: time.NewTicker(time.Second / 60), + logger: logger.With("TelemetryProvider", NAME), + data: telemetry.NewTelemetryData(), + SDK: beam, + og: &bngsdk.Outgauge{}, + ticker: time.NewTicker(time.Second / 60), } provider.updaters = [telemetry.MaxFields]func(*telemetry.TelemetryField){ @@ -110,9 +109,9 @@ func (b *BeamNG) Stream() (<-chan telemetry.TelemetryData, error) { ctx, b.streamCancel = context.WithCancel(context.Background()) // Start the stream - b.stream(ctx) + ch := b.stream(ctx) - return b.streamCh, nil + return ch, nil } func (b *BeamNG) Subscribe(requestFields []telemetry.FieldID) { @@ -162,7 +161,6 @@ func (b *BeamNG) Subscribe(requestFields []telemetry.FieldID) { func (b *BeamNG) readData() { slog.Debug("READING THIS DATA") - // BUG: getting stuck in here ogSnapshot, err := b.SDK.Update() slog.Debug("THE DATA WAS READ") if err != nil { @@ -193,10 +191,15 @@ func (b *BeamNG) readData() { b.data.LastDataPoll = time.Now() } -func (b *BeamNG) stream(ctx context.Context) { +func (b *BeamNG) stream(ctx context.Context) <-chan telemetry.TelemetryData { b.data.InitialTime = time.Now() + outCh := make(chan telemetry.TelemetryData) + b.wg.Add(1) go func() { + defer b.wg.Done() + defer close(outCh) + for { // Explicitly intercept cancellation select { @@ -205,8 +208,6 @@ func (b *BeamNG) stream(ctx context.Context) { default: } - // NOTE: add a method to check if there's data available, or make this happen - select { case <-ctx.Done(): return @@ -217,7 +218,7 @@ func (b *BeamNG) stream(ctx context.Context) { // Publish data select { - case b.streamCh <- *b.data: + case outCh <- *b.data: slog.Debug("PUBLISHED DATA") default: // skip this data, don't allow publishers to lag behind @@ -225,4 +226,6 @@ func (b *BeamNG) stream(ctx context.Context) { } } }() + + return outCh } From 174b27004f7a8f0ddfd3f833c2bdf0d96e7dd46f Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Fri, 18 Sep 2026 16:37:30 +0100 Subject: [PATCH 3/4] added error returns to the SendData method on the peripheral interface --- devices/cdashdisplay/display.go | 27 ++++++++++++++++++--------- devices/uidevice/device.go | 6 ++++-- peripheral/errors.go | 9 +++++++++ peripheral/peripheral.go | 2 +- services/devices.go | 6 +++++- 5 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 peripheral/errors.go diff --git a/devices/cdashdisplay/display.go b/devices/cdashdisplay/display.go index dcb6489..7175bc2 100644 --- a/devices/cdashdisplay/display.go +++ b/devices/cdashdisplay/display.go @@ -12,6 +12,7 @@ import ( "time" helper "esdi/helpers" + "esdi/peripheral" "esdi/peripheral/communication" "esdi/peripheral/communication/packets" "esdi/peripheral/types" @@ -107,10 +108,12 @@ func NewCDashState() *CDashState { } type CDashDisplay struct { - WT *communication.WalkieTalkie - State *CDashState - fieldToWindows map[telemetry.FieldID][]int16 - bufPool sync.Pool + WT *communication.WalkieTalkie + State *CDashState + fieldToWindows map[telemetry.FieldID][]int16 + bufPool sync.Pool + failedSends int + FailedSendsConsecutiveLimit int } // Connect will try to find and connect to the CDashDisplay @@ -118,7 +121,7 @@ func NewCDashDisplay() (*CDashDisplay, error) { // Look for the port p, err := findDisplayPort() if err != nil { - slog.Info("failed to find cdashdisplay port: %s", err.Error()) + slog.Info("failed to find cdashdisplay port", "reason", err.Error()) return nil, err } @@ -132,6 +135,8 @@ func NewCDashDisplay() (*CDashDisplay, error) { return &b }, }, + failedSends: 0, + FailedSendsConsecutiveLimit: 5, }, nil } @@ -393,12 +398,12 @@ func (d *CDashDisplay) UnloadLayout() error { return nil } -func (d *CDashDisplay) SendData(data *telemetry.TelemetryData) { +func (d *CDashDisplay) SendData(data *telemetry.TelemetryData) error { packet := d.encodePacket(data) bytes, err := helper.StructToBytes(packet) if err != nil { - return + return peripheral.ErrFailureToPackData } curStr := "" @@ -408,7 +413,6 @@ func (d *CDashDisplay) SendData(data *telemetry.TelemetryData) { curStr += fmt.Sprintf("%02x ", byte) if byteCount == 8 { - // slog.Debug(curStr) curStr = "" byteCount = 0 } @@ -417,6 +421,11 @@ func (d *CDashDisplay) SendData(data *telemetry.TelemetryData) { // var ack packets.AckPacket err = d.WT.SendCommand(sendDataCMDID, bytes, nil) if err != nil && err != io.EOF { - return + if d.failedSends == d.FailedSendsConsecutiveLimit { + return peripheral.ErrDeviceTimedOut + } + d.failedSends++ } + + return nil } diff --git a/devices/uidevice/device.go b/devices/uidevice/device.go index c08fd85..4f0ac2e 100644 --- a/devices/uidevice/device.go +++ b/devices/uidevice/device.go @@ -17,9 +17,9 @@ func NewUIDevice() (peripheral.Peripheral, error) { }, nil } -func (uid *UIDevice) SendData(data *telemetry.TelemetryData) { +func (uid *UIDevice) SendData(data *telemetry.TelemetryData) error { if data == nil { - return + return peripheral.ErrInvalidData } select { @@ -27,6 +27,8 @@ func (uid *UIDevice) SendData(data *telemetry.TelemetryData) { default: // Drop frame if buffer is full } + + return nil } func (uid *UIDevice) Name() string { diff --git a/peripheral/errors.go b/peripheral/errors.go new file mode 100644 index 0000000..c2674ba --- /dev/null +++ b/peripheral/errors.go @@ -0,0 +1,9 @@ +package peripheral + +import "errors" + +var ( + ErrInvalidData = errors.New("invalid data") + ErrDeviceTimedOut = errors.New("device timed out") + ErrFailureToPackData = errors.New("failed to pack received data") +) diff --git a/peripheral/peripheral.go b/peripheral/peripheral.go index f7b31e5..21379af 100644 --- a/peripheral/peripheral.go +++ b/peripheral/peripheral.go @@ -17,7 +17,7 @@ const ( type Peripheral interface { Name() string - SendData(*telemetry.TelemetryData) + SendData(*telemetry.TelemetryData) error RequiredFields() []telemetry.FieldID } diff --git a/services/devices.go b/services/devices.go index 714025d..8ea1a3c 100644 --- a/services/devices.go +++ b/services/devices.go @@ -159,7 +159,11 @@ func (ds *DeviceService) transmit(ctx context.Context) { // the data locked ds.mu.RLock() for _, dev := range ds.Devices { - dev.SendData(&data) + err := dev.SendData(&data) + if err == peripheral.ErrDeviceTimedOut { + // What do we do here? + // TODO: somehow we need to handle reconnection + } } ds.mu.RUnlock() From a5c465a2039d3d11601dfa21cf3f9889f13cb126 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Sun, 20 Sep 2026 15:06:48 +0100 Subject: [PATCH 4/4] has way too many things In short: added the ability to detect when a device has disconnected. From this we have to achieve a way of: - reconnecting the device - re-subscribing to the fields it needs (it should already be subscribed since the ESDI didn't stop tho - but for the sake of it, or in case a device joins later) - start sending data to it (which should be automatic given how we are handling the devices) --- cmd/repl.go | 180 +++++++------- devices/cdashdisplay/display.go | 8 + devices/device.go | 2 +- devices/uidevice/device.go | 8 + peripheral/communication/walkieTalkie.go | 33 +-- peripheral/peripheral.go | 1 + providers/iracing/iracing.go | 4 +- services/devices.go | 102 +++----- services/devices_lookup.go | 222 ++++++++++++++++++ services/telemetry.go | 2 +- .../controllers/cdashdisplay_layout.go | 14 +- .../cdashdisplay_layout_moveTool.go | 4 +- tui/internal/controllers/device.go | 2 +- tui/internal/controllers/streaming.go | 2 +- 14 files changed, 387 insertions(+), 197 deletions(-) create mode 100644 services/devices_lookup.go diff --git a/cmd/repl.go b/cmd/repl.go index 503783e..7467a0e 100644 --- a/cmd/repl.go +++ b/cmd/repl.go @@ -1,103 +1,97 @@ package cmd import ( - "esdi/peripheral" - "fmt" - "strconv" - - repl "github.com/ESilva15/ESgoRepl" - "github.com/spf13/cobra" ) func replCmdAction(cmd *cobra.Command, args []string) { - r := repl.NewREPL(repl.REPLCfg{ - PS1: "\rESDI > ", - }) - - perClerk := peripheral.NewPeripheralDeviceClerk() - - discoverDevicesREPLCmd := repl.Command{ - Name: "discover", - Usage: "discovers connected devices", - Action: func(r *repl.REPL, args []string) error { - err := perClerk.FindDevices() - if err != nil { - return err - } - - return nil - }, - } - - listDevicesREPLCmd := repl.Command{ - Name: "list", - Usage: "lists connected devices", - Action: func(r *repl.REPL, args []string) error { - _ = perClerk.ListDevices() - - return nil - }, - } - - listDeviceAPIREPLCmd := repl.Command{ - Name: "v-api", - Usage: "shows API of a device - pass its ID", - Action: func(r *repl.REPL, args []string) error { - // We should add this to the REPL instead - if len(args) < 1 { - return fmt.Errorf("requires at least on argument") - } - - // First and only argument should be the ID of the device we want to use - targetID, err := strconv.ParseInt(args[0], 10, 0) - if err != nil { - return err - } - - err = perClerk.ListDeviceAPI(uint8(targetID)) - if err != nil { - fmt.Println("failed to view device API: ", err.Error()) - } - - return nil - }, - } - - runDeviceAPIREPLCmd := repl.Command{ - Name: "v-run", - Usage: "runs a funcion of a device - pass its ID and function name", - Action: func(r *repl.REPL, args []string) error { - // We should add this to the REPL instead - if len(args) < 3 { - return fmt.Errorf("requires at least on argument") - } - - // First and only argument should be the ID of the device we want to use - targetID, err := strconv.ParseInt(args[0], 10, 0) - if err != nil { - return err - } - - fnName := args[1] - fnArgs := args[2:] - - err = perClerk.RunDeviceFunction(uint8(targetID), fnName, fnArgs) - if err != nil { - return err - } - - return nil - }, - } - - r.RegisterCMD(discoverDevicesREPLCmd) - r.RegisterCMD(listDevicesREPLCmd) - r.RegisterCMD(listDeviceAPIREPLCmd) - r.RegisterCMD(runDeviceAPIREPLCmd) - - r.Start() - r.Close() + // r := repl.NewREPL(repl.REPLCfg{ + // PS1: "\rESDI > ", + // }) + // + // perClerk := peripheral.NewPeripheralDeviceClerk() + // + // discoverDevicesREPLCmd := repl.Command{ + // Name: "discover", + // Usage: "discovers connected devices", + // Action: func(r *repl.REPL, args []string) error { + // err := perClerk.FindDevices() + // if err != nil { + // return err + // } + // + // return nil + // }, + // } + // + // listDevicesREPLCmd := repl.Command{ + // Name: "list", + // Usage: "lists connected devices", + // Action: func(r *repl.REPL, args []string) error { + // _ = perClerk.ListDevices() + // + // return nil + // }, + // } + // + // listDeviceAPIREPLCmd := repl.Command{ + // Name: "v-api", + // Usage: "shows API of a device - pass its ID", + // Action: func(r *repl.REPL, args []string) error { + // // We should add this to the REPL instead + // if len(args) < 1 { + // return fmt.Errorf("requires at least on argument") + // } + // + // // First and only argument should be the ID of the device we want to use + // targetID, err := strconv.ParseInt(args[0], 10, 0) + // if err != nil { + // return err + // } + // + // err = perClerk.ListDeviceAPI(uint8(targetID)) + // if err != nil { + // fmt.Println("failed to view device API: ", err.Error()) + // } + // + // return nil + // }, + // } + // + // runDeviceAPIREPLCmd := repl.Command{ + // Name: "v-run", + // Usage: "runs a funcion of a device - pass its ID and function name", + // Action: func(r *repl.REPL, args []string) error { + // // We should add this to the REPL instead + // if len(args) < 3 { + // return fmt.Errorf("requires at least on argument") + // } + // + // // First and only argument should be the ID of the device we want to use + // targetID, err := strconv.ParseInt(args[0], 10, 0) + // if err != nil { + // return err + // } + // + // fnName := args[1] + // fnArgs := args[2:] + // + // err = perClerk.RunDeviceFunction(uint8(targetID), fnName, fnArgs) + // if err != nil { + // return err + // } + // + // return nil + // }, + // } + // + // r.RegisterCMD(discoverDevicesREPLCmd) + // r.RegisterCMD(listDevicesREPLCmd) + // r.RegisterCMD(listDeviceAPIREPLCmd) + // r.RegisterCMD(runDeviceAPIREPLCmd) + // + // r.Start() + // r.Close() } // removeLabelCmd represents the removeLabel command diff --git a/devices/cdashdisplay/display.go b/devices/cdashdisplay/display.go index 7175bc2..267c86d 100644 --- a/devices/cdashdisplay/display.go +++ b/devices/cdashdisplay/display.go @@ -140,6 +140,14 @@ func NewCDashDisplay() (*CDashDisplay, error) { }, nil } +func (cds *CDashDisplay) Close() error { + // if cds.WT != nil { + // cds.Close() + // } + + return nil +} + func (d *CDashDisplay) SendCommand() { } diff --git a/devices/device.go b/devices/device.go index 9318cac..84ab486 100644 --- a/devices/device.go +++ b/devices/device.go @@ -12,7 +12,7 @@ type Device struct { Discover func() (peripheral.Peripheral, error) } -var List map[string]Device = map[string]Device{ +var List map[string]*Device = map[string]*Device{ uidevice.NAME: { Name: uidevice.NAME, Discover: DiscoverUIDevice, diff --git a/devices/uidevice/device.go b/devices/uidevice/device.go index 4f0ac2e..763f759 100644 --- a/devices/uidevice/device.go +++ b/devices/uidevice/device.go @@ -17,6 +17,14 @@ func NewUIDevice() (peripheral.Peripheral, error) { }, nil } +func (uid *UIDevice) Close() error { + if uid.dataChan != nil { + close(uid.dataChan) + } + + return nil +} + func (uid *UIDevice) SendData(data *telemetry.TelemetryData) error { if data == nil { return peripheral.ErrInvalidData diff --git a/peripheral/communication/walkieTalkie.go b/peripheral/communication/walkieTalkie.go index e5503b6..fde5936 100644 --- a/peripheral/communication/walkieTalkie.go +++ b/peripheral/communication/walkieTalkie.go @@ -108,6 +108,15 @@ func (wt *WalkieTalkie) sendPacket(cmd types.Command, data any) error { return err } + // slog.Debug("# START ########################################################") + // slog.Debug(fmt.Sprintf("StartMarker: %02x", constvar.StartOfText)) + // slog.Debug(fmt.Sprintf("CMD: %02x", cmd)) + // slog.Debug(fmt.Sprintf("Len: %d", len(payload))) + // slog.Debug(fmt.Sprintf("Payload: %v", payload)) + // slog.Debug(fmt.Sprintf("CRC: %v", CRC8(payload))) + // slog.Debug(fmt.Sprintf("EndMarker: %02x", constvar.EndOfText)) + // slog.Debug("-") + packet := CMDDataPacket{ StartMarker: constvar.StartOfText, CMD: cmd, @@ -119,7 +128,9 @@ func (wt *WalkieTalkie) sendPacket(cmd types.Command, data any) error { // Send the payload serializedPacket := packet.Serialize() - // fmt.Fprintf(os.Stderr, "%+v", serializedPacket) + + // slog.Debug("Serialized packet", "packet", packet) + // slog.Debug("# END ##########################################################") _, err = wt.Serial.Write(serializedPacket) if err != nil { @@ -176,21 +187,11 @@ func (wt *WalkieTalkie) readPacket(resp packets.Packet) error { // return nil // } -func (wt *WalkieTalkie) SendCommand(cmd types.Command, payload any, - responseBody packets.Packet) error { - // Prepare the header - // header := header{ - // StartByte: constvar.StartOfText, - // CMD: cmd, - // EndByte: constvar.EndOfText, - // } - - // Send the header - // err := wt.sendHeader(&header) - // if err != nil { - // return err - // } - +func (wt *WalkieTalkie) SendCommand( + cmd types.Command, + payload any, + responseBody packets.Packet, +) error { // Send the body err := wt.sendPacket(cmd, payload) if err != nil { diff --git a/peripheral/peripheral.go b/peripheral/peripheral.go index 21379af..ed667a7 100644 --- a/peripheral/peripheral.go +++ b/peripheral/peripheral.go @@ -19,6 +19,7 @@ type Peripheral interface { Name() string SendData(*telemetry.TelemetryData) error RequiredFields() []telemetry.FieldID + Close() error } type PeripheralDeviceClerk struct { diff --git a/providers/iracing/iracing.go b/providers/iracing/iracing.go index c792f4f..9701f6f 100644 --- a/providers/iracing/iracing.go +++ b/providers/iracing/iracing.go @@ -54,10 +54,8 @@ func NewIRacingProvider( logger: logger, SDK: sdk, data: telemetry.NewTelemetryData(), - // streamCh: make(chan telemetry.TelemetryData, 1), - // NOTE: This is because I stupidly recorded a test IBT file in 240 // TODO: make this configurable from the user side - ticker: time.NewTicker(time.Second / 240), + ticker: time.NewTicker(time.Second / 60), } provider.updaters = [telemetry.MaxFields]func(*telemetry.TelemetryField){ diff --git a/services/devices.go b/services/devices.go index 8ea1a3c..214208a 100644 --- a/services/devices.go +++ b/services/devices.go @@ -2,32 +2,21 @@ package services import ( "context" - "errors" - "fmt" "log/slog" - "sync" "sync/atomic" - "time" "esdi/devices" "esdi/peripheral" "esdi/telemetry" ) -var ErrPeripheralAlreadyRegistered = errors.New("peripheral is already registered") - -// DeviceService will handle sending the data from the telemetry service to the -// actual devices -// NOTE: create a virtual device and make it be the output window or something so -// we can just add it as a device or whatever instead of being a custom made thing -// that would be pretty cool I think +// DeviceService is the API for the peripherals type DeviceService struct { Logger *slog.Logger // Device discovery - mu sync.RWMutex + PSS *PeripheralStateStore // Store to track peripheral state ctxDiscovery context.Context ctxDiscoveryCancel context.CancelFunc - Devices map[string]peripheral.Peripheral // Strem handling streamCancel context.CancelFunc TelemCh <-chan telemetry.TelemetryData @@ -39,7 +28,7 @@ func NewDeviceService(logger *slog.Logger) *DeviceService { sharedChannel := make(chan string, 10) dev := &DeviceService{ - Devices: make(map[string]peripheral.Peripheral), + PSS: NewPeripheralStateStore(logger.With("Service", "PeripheralStateStore"), devices.List), Logger: logger, Messages: sharedChannel, } @@ -52,68 +41,33 @@ func NewDeviceService(logger *slog.Logger) *DeviceService { return dev } -func (ds *DeviceService) FindDevices() { - // Need to define a list of devices to search for - // For now lets just try to find our cdashdisplay - will think about the rest later - ticker := time.NewTicker(2 * time.Second) - defer ticker.Stop() +// Getters [START] ------------------------------------------------------------- +func (ds *DeviceService) GetDevices() []peripheral.Peripheral { + snapshot := ds.PSS.GetStates() + peripherals := make([]peripheral.Peripheral, 0, len(snapshot)) - for { - select { - case <-ds.ctxDiscovery.Done(): - // If requested to cancel we cancel background discovery - return - case <-ticker.C: - for pName, peripheral := range devices.List { - if ds.DeviceExists(pName) { - // We already discovered this device - continue - } - - ds.Logger.Debug("looking for device", "name", pName) - dev, err := peripheral.Discover() - if err != nil { - ds.Logger.Debug("didn't find device", "name", pName) - continue - } - - // Register the device we just found - ds.RegisterDevice(dev) - } + for _, state := range snapshot { + if state.State != DeviceIsConnected { + continue } - } -} - -func (ds *DeviceService) RegisterDevice(dev peripheral.Peripheral) error { - ds.mu.Lock() - defer ds.mu.Unlock() - - if ds.DeviceExists(dev.Name()) { - return ErrPeripheralAlreadyRegistered + peripherals = append(peripherals, state.Peripheral) } - ds.Devices[dev.Name()] = dev - - return nil + return peripherals } -func (ds *DeviceService) GetDevice(name string) (peripheral.Peripheral, error) { - val, ok := ds.Devices[name] - if !ok { - return nil, fmt.Errorf("device `%s` couldn't be found", name) - } - - return val, nil +func (ds *DeviceService) GetPeripheral(pname string) (peripheral.Peripheral, error) { + return ds.PSS.GetPeripheral(pname) } -func (ds *DeviceService) DeviceExists(name string) bool { - if _, ok := ds.Devices[name]; !ok { - return false - } - - return true +func (ds *DeviceService) PeripheralExists(pname string) bool { + _, err := ds.PSS.GetPeripheral(pname) + return err == nil } +// Getters [END] --------------------------------------------------------------- + +// Actions [START] ------------------------------------------------------------- func (ds *DeviceService) StartStream() { // NOTE: i'm using this pattern a whole lot. Maybe I can create a struct to handle this var ctx context.Context @@ -136,6 +90,8 @@ func (ds *DeviceService) SetTelemetryChannel(ch <-chan telemetry.TelemetryData) ds.TelemCh = ch } +// Actions [END] --------------------------------------------------------------- + // transmit will send the data to the devices themselves func (ds *DeviceService) transmit(ctx context.Context) { var isSending atomic.Bool @@ -157,15 +113,17 @@ func (ds *DeviceService) transmit(ctx context.Context) { // TODO: make a copy of the data and send that copy instead of keeping // the data locked - ds.mu.RLock() - for _, dev := range ds.Devices { - err := dev.SendData(&data) + for _, dev := range ds.PSS.GetStates() { + if dev.State != DeviceIsConnected { + continue + } + + err := dev.Peripheral.SendData(&data) + if err == peripheral.ErrDeviceTimedOut { - // What do we do here? - // TODO: somehow we need to handle reconnection + ds.onDeviceTimedOut(dev.device.Name) } } - ds.mu.RUnlock() isSending.Store(false) } diff --git a/services/devices_lookup.go b/services/devices_lookup.go new file mode 100644 index 0000000..98e7655 --- /dev/null +++ b/services/devices_lookup.go @@ -0,0 +1,222 @@ +package services + +import ( + "errors" + "log/slog" + "maps" + "sync" + "time" + + "esdi/devices" + "esdi/peripheral" +) + +var ( + ErrPeripheralAlreadyRegistered = errors.New("peripheral is already registered") + ErrNoSuchDevice = errors.New("device doesn't exist") + ErrDeviceIsNotConnected = errors.New("device isn't connected") +) + +type DeviceState = uint8 + +const ( + DeviceTimedOut uint8 = iota + DeviceIsConnected + DeviceIsDisconnected + DeviceReconnected +) + +type PeripheralState struct { + device *devices.Device + Peripheral peripheral.Peripheral + State DeviceState +} + +func NewPeripheralState( + dev *devices.Device, + peripheral peripheral.Peripheral, + state DeviceState, +) *PeripheralState { + perState := PeripheralState{ + device: dev, + Peripheral: peripheral, + State: state, + } + + return &perState +} + +type PeripheralStateStore struct { + Logger *slog.Logger + mu sync.RWMutex + store map[string]*PeripheralState +} + +func NewPeripheralStateStore( + nLogger *slog.Logger, + devList map[string]*devices.Device, +) *PeripheralStateStore { + store := PeripheralStateStore{ + Logger: nLogger, + store: make(map[string]*PeripheralState), + } + + for _, dev := range devList { + store.AddDevice(dev) + } + + return &store +} + +func (pss *PeripheralStateStore) GetStates() map[string]*PeripheralState { + pss.mu.RLock() + defer pss.mu.RUnlock() + + return maps.Clone(pss.store) +} + +func (pss *PeripheralStateStore) GetState(pname string) (*PeripheralState, error) { + if !pss.DeviceExists(pname) { + return nil, ErrNoSuchDevice + } + + pss.mu.RLock() + defer pss.mu.RUnlock() + return pss.store[pname], nil +} + +func (pss *PeripheralStateStore) GetPeripheral(pname string) (peripheral.Peripheral, error) { + state, err := pss.GetState(pname) + if err != nil { + return nil, err + } + + if state.State != DeviceIsConnected { + return nil, ErrDeviceIsNotConnected + } + + return state.Peripheral, nil +} + +// AddDevice adds a new device for tracking +func (pss *PeripheralStateStore) AddDevice(dev *devices.Device) error { + if pss.DeviceExists(dev.Name) { + return ErrPeripheralAlreadyRegistered + } + + pss.mu.Lock() + defer pss.mu.Unlock() + pss.store[dev.Name] = NewPeripheralState(dev, nil, DeviceIsDisconnected) + + return nil +} + +// DeviceExists returns whether the store is already tracking `pname` +func (pss *PeripheralStateStore) DeviceExists(pname string) bool { + pss.mu.RLock() + defer pss.mu.RUnlock() + + if _, ok := pss.store[pname]; ok { + return true + } + + return false +} + +// DeleteDevice deletes `pname` from tracking +func (pss *PeripheralStateStore) DeleteDevice(pname string) error { + if !pss.DeviceExists(pname) { + return ErrNoSuchDevice + } + + pss.mu.Lock() + defer pss.mu.Unlock() + + delete(pss.store, pname) + + return nil +} + +// "Events" [START] ------------------------------------------------------------ +func (ds *DeviceService) onDeviceTimedOut(pname string) { + // We need to deregister the device + ds.PSS.setDeviceTimedOut(pname) +} + +// "Events" [END] -------------------------------------------------------------- + +// Device State Handling [START] ----------------------------------------------- +func (pss *PeripheralStateStore) setDeviceConnected(pname string, per peripheral.Peripheral) { + pss.Logger.Info("found device", "device", pname) + + pss.mu.Lock() + defer pss.mu.Unlock() + pss.store[pname].Peripheral = per + pss.store[pname].State = DeviceIsConnected +} + +func (pss *PeripheralStateStore) setDeviceTimedOut(pname string) { + pss.Logger.Info("device timed out", "device", pname) + + pss.mu.Lock() + defer pss.mu.Unlock() + pss.store[pname].Peripheral = nil + pss.store[pname].State = DeviceTimedOut +} + +func (pss *PeripheralStateStore) setDeviceReconnected(pname string, per peripheral.Peripheral) { + pss.Logger.Info("device reconnecting", "device", pname) + + pss.mu.Lock() + defer pss.mu.Unlock() + pss.store[pname].Peripheral = per + pss.store[pname].State = DeviceReconnected +} + +// Device State Handling [END] ------------------------------------------------- + +// Device Handling [START] ----------------------------------------------------- +func (pss *PeripheralStateStore) HandleDeviceState() { + peripherals := pss.GetStates() + + for pName, pState := range peripherals { + switch pState.State { + case DeviceIsDisconnected: + pss.Logger.Debug("looking for device", "name", pName) + dev, err := pState.device.Discover() + if err != nil { + continue + } + + // Register the device we just found + pss.setDeviceConnected(pName, dev) + case DeviceIsConnected: + // Need to check if its streaming, if its not streaming than we have to do a healthcheck + pss.Logger.Debug("Device is connected. Normal", "device", pName) + case DeviceReconnected: + // If the device has reconnected we need to reset the device and then set it as connected + pss.Logger.Debug("Device has reconnected. Clearing up state", "device", pName) + case DeviceTimedOut: + // If the device has timed out we need to re-discover it or something + pss.Logger.Debug("Device is timed out. Attempting to recconect", "device", pName) + } + } +} + +// Device Handling [END] ------------------------------------------------------- + +// FindDevices is a routine that goes over the devices in the PeripheralStateStore +// and handles their state accordingly +func (ds *DeviceService) FindDevices() { + ticker := time.NewTicker(2 * time.Second) + defer ticker.Stop() + + for { + select { + case <-ds.ctxDiscovery.Done(): + return + case <-ticker.C: + ds.PSS.HandleDeviceState() + } + } +} diff --git a/services/telemetry.go b/services/telemetry.go index 7af4cb4..674be83 100644 --- a/services/telemetry.go +++ b/services/telemetry.go @@ -102,7 +102,7 @@ func (t *TelemetryService) SubscribeToFields() []telem.FieldID { seen := make(map[telemetry.FieldID]struct{}) var allFields []telemetry.FieldID - for _, dev := range t.devService.Devices { + for _, dev := range t.devService.GetDevices() { for _, field := range dev.RequiredFields() { if _, exists := seen[field]; !exists { seen[field] = struct{}{} diff --git a/tui/internal/controllers/cdashdisplay_layout.go b/tui/internal/controllers/cdashdisplay_layout.go index 6400b47..f90f6a7 100644 --- a/tui/internal/controllers/cdashdisplay_layout.go +++ b/tui/internal/controllers/cdashdisplay_layout.go @@ -211,7 +211,7 @@ func (lc *LayoutController) createWindow() { } // Acquire the cdashdisplay - displayIF, err := lc.DevService.GetDevice(cdashdisplay.NAME) + displayIF, err := lc.DevService.GetPeripheral(cdashdisplay.NAME) if err != nil { lc.Messages <- "failed to get " + cdashdisplay.NAME return @@ -321,7 +321,7 @@ func (lc *LayoutController) newWindowAction() { func (lc *LayoutController) updateWindowAction(win *cdashdisplay.DesktopUIWindow) { // Acquire the cdashdisplay - displayIF, err := lc.DevService.GetDevice(cdashdisplay.NAME) + displayIF, err := lc.DevService.GetPeripheral(cdashdisplay.NAME) if err != nil { lc.Messages <- "failed to get " + cdashdisplay.NAME return @@ -347,7 +347,7 @@ func (lc *LayoutController) displayLoadedLayouts() { lc.Logger.Debug("We want to view our layout!") // Acquire the cdashdisplay - displayIF, err := lc.DevService.GetDevice(cdashdisplay.NAME) + displayIF, err := lc.DevService.GetPeripheral(cdashdisplay.NAME) if err != nil { lc.Messages <- "failed to get " + cdashdisplay.NAME return @@ -392,7 +392,7 @@ func (lc *LayoutController) getCurrentTreeNodeModel() (*tview.TreeNode, int16, e func (lc *LayoutController) loadLayout() { // Acquire the cdashdisplay - displayIF, err := lc.DevService.GetDevice(cdashdisplay.NAME) + displayIF, err := lc.DevService.GetPeripheral(cdashdisplay.NAME) if err != nil { lc.Messages <- "failed to get " + cdashdisplay.NAME return @@ -416,7 +416,7 @@ func (lc *LayoutController) loadLayout() { func (lc *LayoutController) unloadLayout() { // Acquire the cdashdisplay - displayIF, err := lc.DevService.GetDevice(cdashdisplay.NAME) + displayIF, err := lc.DevService.GetPeripheral(cdashdisplay.NAME) if err != nil { lc.Messages <- "failed to get " + cdashdisplay.NAME return @@ -437,7 +437,7 @@ func (lc *LayoutController) unloadLayout() { func (lc *LayoutController) saveLayout() { // Acquire the cdashdisplay - displayIF, err := lc.DevService.GetDevice(cdashdisplay.NAME) + displayIF, err := lc.DevService.GetPeripheral(cdashdisplay.NAME) if err != nil { lc.Messages <- "failed to get " + cdashdisplay.NAME return @@ -470,7 +470,7 @@ func (lc *LayoutController) deleteWindow() { wID := curNode.GetReference().(int16) // Acquire the cdashdisplay - displayIF, err := lc.DevService.GetDevice(cdashdisplay.NAME) + displayIF, err := lc.DevService.GetPeripheral(cdashdisplay.NAME) if err != nil { lc.Messages <- "failed to get " + cdashdisplay.NAME return diff --git a/tui/internal/controllers/cdashdisplay_layout_moveTool.go b/tui/internal/controllers/cdashdisplay_layout_moveTool.go index ba31690..87487bf 100644 --- a/tui/internal/controllers/cdashdisplay_layout_moveTool.go +++ b/tui/internal/controllers/cdashdisplay_layout_moveTool.go @@ -52,7 +52,7 @@ func (lc *LayoutController) handleMovementCapture(idx int16, } // Acquire the cdashdisplay - displayIF, err := lc.DevService.GetDevice(cdashdisplay.NAME) + displayIF, err := lc.DevService.GetPeripheral(cdashdisplay.NAME) if err != nil { lc.Messages <- "failed to get " + cdashdisplay.NAME return nil @@ -86,7 +86,7 @@ func (lc *LayoutController) handleResizeCapture(idx int16, } // Acquire the cdashdisplay - displayIF, err := lc.DevService.GetDevice(cdashdisplay.NAME) + displayIF, err := lc.DevService.GetPeripheral(cdashdisplay.NAME) if err != nil { lc.Messages <- "failed to get " + cdashdisplay.NAME return nil diff --git a/tui/internal/controllers/device.go b/tui/internal/controllers/device.go index 22c3e73..f0f86a3 100644 --- a/tui/internal/controllers/device.go +++ b/tui/internal/controllers/device.go @@ -67,7 +67,7 @@ func (mc *DeviceController) AddDeviceAPIListItems() { mc.DeviceAPIView.DevAPIList. AddItem("layout", "build a layout for CDashDisplay", func() { // This CDashDisplay specific, only load if we have a CDashDisplay - if !mc.DevService.DeviceExists(cdashdisplay.NAME) { + if !mc.DevService.PeripheralExists(cdashdisplay.NAME) { mc.DevService.Messages <- "CDashDisplay it not loaded yet\n" return } diff --git a/tui/internal/controllers/streaming.go b/tui/internal/controllers/streaming.go index 3a05dc5..9778602 100644 --- a/tui/internal/controllers/streaming.go +++ b/tui/internal/controllers/streaming.go @@ -110,7 +110,7 @@ func (sc *StreamingCtrl) StartStop() { slog.Debug("setting the data stream for device servie") sc.DevService.SetTelemetryChannel(sc.TelemServ.SubscribeListener("DeviceService", 1)) - dev, err := sc.DevService.GetDevice(uidevice.NAME) + dev, err := sc.DevService.GetPeripheral(uidevice.NAME) if err == nil { if uiDev, ok := dev.(*uidevice.UIDevice); ok { sc.TelemetryCh = uiDev.DataChannel()