ninafw: should support muliple connections as a central
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
00a475adf1
commit
0a9bffe397
2 changed files with 20 additions and 4 deletions
|
@ -184,7 +184,7 @@ func (a *Adapter) startNotifications() {
|
||||||
println("notification received", not.connectionHandle, not.handle, not.data)
|
println("notification received", not.connectionHandle, not.handle, not.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
d := a.findDevice(not.connectionHandle)
|
d := a.findConnectedDevice(not.connectionHandle)
|
||||||
if d.deviceInternal == nil {
|
if d.deviceInternal == nil {
|
||||||
if debug {
|
if debug {
|
||||||
println("no device found for handle", not.connectionHandle)
|
println("no device found for handle", not.connectionHandle)
|
||||||
|
@ -212,7 +212,23 @@ func (a *Adapter) startNotifications() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adapter) findDevice(handle uint16) Device {
|
func (a *Adapter) addDevice(d Device) {
|
||||||
|
a.connectedDevices = append(a.connectedDevices, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Adapter) removeDevice(d Device) {
|
||||||
|
for i := range a.connectedDevices {
|
||||||
|
if d.handle == a.connectedDevices[i].handle {
|
||||||
|
copy(a.connectedDevices[i:], a.connectedDevices[i+1:])
|
||||||
|
a.connectedDevices[len(a.connectedDevices)-1] = Device{} // the zero value of T
|
||||||
|
a.connectedDevices = a.connectedDevices[:len(a.connectedDevices)-1]
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Adapter) findConnectedDevice(handle uint16) Device {
|
||||||
for _, d := range a.connectedDevices {
|
for _, d := range a.connectedDevices {
|
||||||
if d.handle == handle {
|
if d.handle == handle {
|
||||||
if debug {
|
if debug {
|
||||||
|
|
|
@ -178,7 +178,7 @@ func (a *Adapter) Connect(address Address, params ConnectionParams) (Device, err
|
||||||
notificationRegistrations: make([]notificationRegistration, 0),
|
notificationRegistrations: make([]notificationRegistration, 0),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
a.connectedDevices = append(a.connectedDevices, d)
|
a.addDevice(d)
|
||||||
|
|
||||||
return d, nil
|
return d, nil
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ func (d Device) Disconnect() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
d.adapter.connectedDevices = []Device{}
|
d.adapter.removeDevice(d)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue