devices and providers can now drop mid stream and then reconnect without impact

This commit is contained in:
2026-09-25 14:48:29 +01:00
parent 584d13e1fd
commit 48b10afbba
6 changed files with 24 additions and 3 deletions
+7
View File
@@ -405,6 +405,11 @@ func (d *CDashDisplay) UnloadLayout() error {
return nil
}
func (cds *CDashDisplay) resetState() {
cds.fieldToWindows = make(map[telemetry.FieldID][]int16)
cds.State.Layout = NewLayoutTree()
}
func (cds *CDashDisplay) reset() error {
err := cds.WT.SendCommand(resetCMDID, []byte{0x01, 0x02, 0x03, 0x04}, nil)
if err != nil {
@@ -413,6 +418,8 @@ func (cds *CDashDisplay) reset() error {
time.Sleep(3000 * time.Millisecond)
cds.resetState()
return nil
}
+5
View File
@@ -1 +1,6 @@
package services
func (ds *DeviceService) OnStoppedMidStream() {
// Need to make every device be unconfigured
ds.StopStream()
}
+2 -2
View File
@@ -228,8 +228,8 @@ func (pss *PeripheralStateStore) OnStopStream() {
pss.mu.Unlock()
for _, state := range pss.GetStates() {
if state.State == DeviceIsStreaming {
pss.setDeviceConfigured(state.device.Name)
if state.State > DeviceIsConfigured {
pss.setDeviceUnconfigured(state.device.Name)
}
}
}
+1
View File
@@ -30,6 +30,7 @@ func NewOrchestrator(logger *slog.Logger) (*Orchestrator, error) {
// Setup telemetry service callbacks
telemService.startedStreaming = devService.StartStream
telemService.providerStoppedMidStream = devService.OnStoppedMidStream
return &Orchestrator{
DeviceService: devService,
+3 -1
View File
@@ -35,7 +35,8 @@ type TelemetryService struct {
CtxHealthcheck context.Context
healthCheckCancel context.CancelFunc
// Callbacks
startedStreaming func(ch <-chan telemetry.TelemetryData)
startedStreaming func(ch <-chan telemetry.TelemetryData)
providerStoppedMidStream func()
// Devices data request
// peripheralProvider func() []peripheral.Peripheral
// getRequiredFields func() []telemetry.FieldID
@@ -139,6 +140,7 @@ func (t *TelemetryService) dropActiveProvider() {
t.cancelForward()
}
// NOTE: can we move the stop stream into the provider Close() method?
t.activeProvider.StopStream()
t.activeProvider.Close()
t.activeProvider = nil
+6
View File
@@ -30,6 +30,8 @@ func (t *TelemetryService) onFindProvider(prov telem.TelemetryProvider) {
ch := t.StartStream()
t.startedStreaming(ch)
t.Messages <- "provider switch completed"
}
func (t *TelemetryService) onProviderStopsMidStream() {
@@ -38,6 +40,10 @@ func (t *TelemetryService) onProviderStopsMidStream() {
// if the stream stopped we have to restart the devices and everything
t.Messages <- "Telemetry provider stopped mid stream\n"
t.logger.Info("cleaning dropped provider and restarting lookup service")
t.dropActiveProvider()
go t.FindProvider(t.CtxMonitor)
// Tell the devices service that we lost the thing
t.providerStoppedMidStream()
}