Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions cmd/oceantv/broadcast_hardware_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *hardwareRestarting) handleHardwareShutdownFailedEvent(event hardwareShu
}

func (s *hardwareRestarting) cameraIsReporting() bool {
up, err := s.camera.isUp(s.broadcastContext, model.MacDecode(s.cfg.CameraMac))
up, err := s.hardware.isUp(s.broadcastContext, model.MacDecode(s.cfg.CameraMac))
if err != nil {
s.bus.publish(invalidConfigurationEvent{fmt.Errorf("could not get camera reporting status: %w", err)})
return false
Expand Down Expand Up @@ -230,12 +230,12 @@ func (s *hardwareStarting) enter() {
s.LastEntered = time.Now()
// A MAC of 0 indicates it is invalid or unset, proceed with starting the camera.
if s.cfg.ControllerMAC == 0 {
s.camera.start(s.broadcastContext)
s.hardware.start(s.broadcastContext)
return
}

// The first check for any known hardware error states.
hwErr, err := s.camera.error(s.broadcastContext)
hwErr, err := s.hardware.error(s.broadcastContext)
if err != nil {
errWrapped := fmt.Errorf("could not get hardware error state: %w", err)
s.log(errWrapped.Error())
Expand Down Expand Up @@ -263,23 +263,23 @@ func (s *hardwareStarting) enter() {
// we have a controller that doesn't have the latest firmware.
}

voltage, err := s.camera.voltage(s.broadcastContext)
voltage, err := s.hardware.voltage(s.broadcastContext)
if err != nil {
errWrapped := fmt.Errorf("could not get hardware voltage: %w", err)
s.log(errWrapped.Error())
s.bus.publish(invalidConfigurationEvent{errWrapped})
return
}

alarmVoltage, err := s.camera.alarmVoltage(s.broadcastContext)
alarmVoltage, err := s.hardware.alarmVoltage(s.broadcastContext)
if err != nil {
errWrapped := fmt.Errorf("could not get alarm voltage: %w", err)
s.log(errWrapped.Error())
s.bus.publish(invalidConfigurationEvent{errWrapped})
return
}

controllerIsOn, err := s.camera.isUp(s.broadcastContext, model.MacDecode(s.cfg.ControllerMAC))
controllerIsOn, err := s.hardware.isUp(s.broadcastContext, model.MacDecode(s.cfg.ControllerMAC))
if err != nil {
errWrapped := fmt.Errorf("could not get controller status: %w", err)
s.log(errWrapped.Error())
Expand Down Expand Up @@ -314,8 +314,8 @@ func (s *hardwareStarting) enter() {
}

// Controller is reporting and we're above streaming voltage, let's power
// on the camera.
s.camera.start(s.broadcastContext)
// on the hardware.
s.hardware.start(s.broadcastContext)
}

func (s *hardwareStarting) exit() {}
Expand Down Expand Up @@ -436,7 +436,7 @@ func newHardwareShuttingDown(ctx *broadcastContext) *hardwareShuttingDown {
}
func (s *hardwareShuttingDown) enter() {
s.LastEntered = time.Now()
s.camera.shutdown(s.broadcastContext)
s.hardware.shutdown(s.broadcastContext)
}
func (s *hardwareShuttingDown) exit() {}

Expand Down Expand Up @@ -500,7 +500,7 @@ func newHardwarePoweringOff(ctx *broadcastContext) *hardwarePoweringOff {
}
func (s *hardwarePoweringOff) enter() {
s.LastEntered = time.Now()
s.camera.stop(s.broadcastContext)
s.hardware.stop(s.broadcastContext)
}
func (s *hardwarePoweringOff) exit() {}

Expand Down Expand Up @@ -683,7 +683,7 @@ func (s *hardwareStopping) handleHardwarePowerOffFailedEvent(event hardwarePower
}

func (s *hardwareStopping) cameraIsReporting() bool {
up, err := s.camera.isUp(s.broadcastContext, model.MacDecode(s.cfg.CameraMac))
up, err := s.hardware.isUp(s.broadcastContext, model.MacDecode(s.cfg.CameraMac))
if err != nil {
s.bus.publish(invalidConfigurationEvent{fmt.Errorf("could not get camera reporting status: %w", err)})
return false
Expand Down Expand Up @@ -843,7 +843,7 @@ func (sm *hardwareStateMachine) handleEvent(event event) error {
func (sm *hardwareStateMachine) handleTimeEvent(t timeEvent) {
sm.log("handling time event")
eventIfStatus := func(e event, status bool) {
sm.ctx.camera.publishEventIfStatus(sm.ctx, e, status, sm.ctx.cfg.CameraMac, sm.ctx.store, sm.log, sm.ctx.bus.publish)
sm.ctx.hardware.publishEventIfStatus(sm.ctx, e, status, sm.ctx.cfg.CameraMac, sm.ctx.store, sm.log, sm.ctx.bus.publish)
}
switch sm.currentState.(type) {
case *hardwareStarting:
Expand All @@ -866,7 +866,7 @@ func (sm *hardwareStateMachine) handleTimeEvent(t timeEvent) {
return
}

voltage, err := sm.ctx.camera.voltage(sm.ctx)
voltage, err := sm.ctx.hardware.voltage(sm.ctx)
if err != nil {
errWrapped := fmt.Errorf("could not get hardware voltage: %v", err)
sm.log(errWrapped.Error())
Expand Down Expand Up @@ -963,7 +963,7 @@ func (sm *hardwareStateMachine) handleHardwareStartRequestEvent(event hardwareSt
case *hardwareOff, *hardwareRestarting:
sm.transition(newHardwareStarting(sm.ctx))
case *hardwareStarting:
sm.ctx.camera.publishEventIfStatus(sm.ctx, hardwareStartedEvent{}, true, sm.ctx.cfg.CameraMac, sm.ctx.store, sm.log, sm.ctx.bus.publish)
sm.ctx.hardware.publishEventIfStatus(sm.ctx, hardwareStartedEvent{}, true, sm.ctx.cfg.CameraMac, sm.ctx.store, sm.log, sm.ctx.bus.publish)
case *hardwareStopping:
// Ignore and log.
sm.log("ignoring hardware start request event since hardware is still stopping")
Expand Down
4 changes: 2 additions & 2 deletions cmd/oceantv/broadcast_hardware_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestGetHardwareStateStorage(t *testing.T) {
}{
{"test hardware off", newHardwareOff()},
{"test hardware on", newHardwareOn()},
{"test hardware starting", newHardwareStarting(&broadcastContext{camera: &dummyHardwareManager{}, logOutput: t.Log, notifier: newMockNotifier()})},
{"test hardware starting", newHardwareStarting(&broadcastContext{hardware: &dummyHardwareManager{}, logOutput: t.Log, notifier: newMockNotifier()})},
{"test hardware stopping", newHardwareStopping(minimalMockBroadcastContext(t))},
{"test hardware restarting", newHardwareRestarting(minimalMockBroadcastContext(t))},
}
Expand Down Expand Up @@ -361,7 +361,7 @@ func (h hardwareSystem) withForwardingService(fs ForwardingService) hardwareSyst

func (h hardwareSystem) withHardwareManager(hm hardwareManager) hardwareSystemOption {
return func(bs *hardwareSystem) error {
bs.ctx.camera = hm
bs.ctx.hardware = hm
return nil
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/oceantv/broadcast_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ func TestBroadcastStart(t *testing.T) {
)

bCtx.man = newDummyManager(t, tt.cfg)
bCtx.camera = tt.hardwareMan
bCtx.hardware = tt.hardwareMan
bCtx.fwd = newDummyForwardingService()
bCtx.cfg = tt.cfg
bCtx.bus = bus
Expand Down Expand Up @@ -1293,10 +1293,10 @@ func TestBroadcastStart(t *testing.T) {
}

// Check that the hardware manager start was called/not called as expected.
startCalled := bCtx.camera.(*dummyHardwareManager).startCalled
startCalled := bCtx.hardware.(*dummyHardwareManager).startCalled
if tt.expectHardwareStartCall != startCalled {
t.Errorf("hardware manager start was/was not called as expected, expected: %v, got: %v",
tt.expectHardwareStartCall, bCtx.camera.(*dummyHardwareManager).startCalled)
tt.expectHardwareStartCall, bCtx.hardware.(*dummyHardwareManager).startCalled)
}

// Check that the broadcast manager start was called/not called as expected.
Expand Down
14 changes: 7 additions & 7 deletions cmd/oceantv/broadcast_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
)

type broadcastContext struct {
cfg *BroadcastConfig
man BroadcastManager
store Store
svc BroadcastService
fwd ForwardingService
bus eventBus
camera hardwareManager
cfg *BroadcastConfig
man BroadcastManager
store Store
svc BroadcastService
fwd ForwardingService
bus eventBus
hardware hardwareManager

// When nil, defaults to log.Println. Useful to plug in test implementation.
logOutput func(v ...any)
Expand Down
2 changes: 1 addition & 1 deletion cmd/oceantv/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func standardMockBroadcastContext(t *testing.T, hardwareHealthy bool) *broadcast
return &broadcastContext{
store: &dummyStore{},
svc: &dummyService{},
camera: &dummyHardwareManager{hardwareHealthy: hardwareHealthy},
hardware: &dummyHardwareManager{hardwareHealthy: hardwareHealthy},
notifier: newMockNotifier(),
logOutput: t.Log,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/oceantv/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func withForwardingService(fs ForwardingService) broadcastSystemOption {

func withHardwareManager(hm hardwareManager) broadcastSystemOption {
return func(bs *broadcastSystem) error {
bs.ctx.camera = hm
bs.ctx.hardware = hm
return nil
}
}
Expand Down
Loading