Skip to content
Open
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
19 changes: 19 additions & 0 deletions gatts_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ func (om *objectManager) GetManagedObjects() (map[dbus.ObjectPath]map[string]map
type bluezChar struct {
props *prop.Properties
writeEvent func(client Connection, offset int, value []byte)

mtu int
}

func (c *bluezChar) ReadValue(options map[string]dbus.Variant) ([]byte, *dbus.Error) {
if mtu, ok := options["mtu"]; ok {
// Store the MTU, so it can be retrieved later.
mtuValue := mtu.Value().(uint16)
c.mtu = int(mtuValue)
}

// TODO: should we use the offset value? The BlueZ documentation doesn't
// clearly specify this. The go-bluetooth library doesn't, but I believe it
// should be respected.
Expand All @@ -61,6 +69,12 @@ func (c *bluezChar) ReadValue(options map[string]dbus.Variant) ([]byte, *dbus.Er
}

func (c *bluezChar) WriteValue(value []byte, options map[string]dbus.Variant) *dbus.Error {
if mtu, ok := options["mtu"]; ok {
// Store the MTU, so it can be retrieved later.
mtuValue := mtu.Value().(uint16)
c.mtu = int(mtuValue)
}

if c.writeEvent != nil {
// BlueZ doesn't seem to tell who did the write, so pass 0 always as the
// connection ID.
Expand Down Expand Up @@ -168,3 +182,8 @@ func (c *Characteristic) Write(p []byte) (n int, err error) {
}
return len(p), nil
}

// MTU returns the exchanged MTU value, or zero if not available.
func (c *Characteristic) MTU() int {
return c.char.mtu
}
Loading