gatt/darwin: macOS implementation and ensure pointer usage

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2020-10-03 23:24:38 +02:00 committed by Ron Evans
parent 47770f6c59
commit 97f17e93f1
No known key found for this signature in database
GPG Key ID: BCEECD6D76F01FA1
4 changed files with 21 additions and 4 deletions

@ -162,5 +162,9 @@ func (pd *peripheralDelegate) DidUpdateValueForCharacteristic(prph cbgo.Peripher
if char != nil && char.callback != nil {
go char.callback(chr.Value())
}
if char.readChan != nil {
char.readChan <- nil
}
}
}

@ -114,6 +114,7 @@ type DeviceCharacteristic struct {
characteristic cbgo.Characteristic
callback func(buf []byte)
readChan chan error
}
// UUID returns the UUID for this DeviceCharacteristic.
@ -147,6 +148,18 @@ func (c *DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) er
}
// Read reads the current characteristic value.
func (c DeviceCharacteristic) Read() (data []byte, err error) {
return nil, nil
func (c *DeviceCharacteristic) Read() (data []byte, err error) {
c.readChan = make(chan error)
c.service.device.prph.ReadCharacteristic(c.characteristic)
// wait for result
select {
case <-c.readChan:
c.readChan = nil
case <-time.NewTimer(10 * time.Second).C:
c.readChan = nil
return nil, errors.New("timeout on Read()")
}
return c.characteristic.Value(), nil
}

@ -234,7 +234,7 @@ func (c *DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) er
}
// Read reads the current characteristic value.
func (c DeviceCharacteristic) Read() ([]byte, error) {
func (c *DeviceCharacteristic) Read() ([]byte, error) {
options := make(map[string]interface{})
return c.characteristic.ReadValue(options)
}

@ -348,7 +348,7 @@ var readingCharacteristic struct {
// Read reads the current characteristic value up to MTU length.
// A future enhancement would be to be able to retrieve a longer
// value by making multiple calls.
func (c DeviceCharacteristic) Read() ([]byte, error) {
func (c *DeviceCharacteristic) Read() ([]byte, error) {
errCode := C.sd_ble_gattc_read(c.connectionHandle, c.valueHandle, 0)
if errCode != 0 {
return nil, Error(errCode)