diff --git a/device.go b/device.go index c4a1cf0d..18d4494e 100644 --- a/device.go +++ b/device.go @@ -13,6 +13,7 @@ type device struct { type Device interface { Start() bool + Halt() bool } func NewDevice(driver DriverInterface, r *Robot) *device { @@ -31,6 +32,11 @@ func (d *device) Start() bool { return d.Driver.Start() } +func (d *device) Halt() bool { + log.Println("Device " + d.Name + " halted") + return d.Driver.Halt() +} + func (d *device) Commands() interface{} { return FieldByNamePtr(d.Driver, "Commands").Interface() } diff --git a/driver.go b/driver.go index 0ce04d9f..d007312e 100644 --- a/driver.go +++ b/driver.go @@ -10,4 +10,5 @@ type Driver struct { type DriverInterface interface { Start() bool + Halt() bool } diff --git a/master.go b/master.go index 2d8eb5fe..d3f5fc9e 100644 --- a/master.go +++ b/master.go @@ -29,6 +29,7 @@ func (m *Master) Start() { for _ = range c { for r := range m.Robots { + m.Robots[r].haltDevices() m.Robots[r].finalizeConnections() } break diff --git a/robot.go b/robot.go index 9bd34b60..aec1da11 100644 --- a/robot.go +++ b/robot.go @@ -98,6 +98,12 @@ func (r *Robot) startDevices() bool { return success } +func (r *Robot) haltDevices() { + for _, device := range r.devices { + device.Halt() + } +} + func (r *Robot) finalizeConnections() { for _, connection := range r.connections { connection.Finalize() diff --git a/test_helper.go b/test_helper.go index fefc02f0..682dd1c3 100644 --- a/test_helper.go +++ b/test_helper.go @@ -5,6 +5,7 @@ type testDriver struct { } func (me *testDriver) Start() bool { return true } +func (me *testDriver) Halt() bool { return true } type testAdaptor struct { Adaptor