From 8e24a9553738a2724180f06c881febf7c0fc16fd Mon Sep 17 00:00:00 2001 From: Tim Kluge Date: Fri, 10 Oct 2025 22:29:49 +0200 Subject: [PATCH 1/3] linux: Add Write method to write characteristic value with response --- gattc_linux.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gattc_linux.go b/gattc_linux.go index 0202e985..03f8fe04 100644 --- a/gattc_linux.go +++ b/gattc_linux.go @@ -222,7 +222,21 @@ func (s DeviceService) DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacteri // writes can be in flight at any given time. This call is also known as a // "write command" (as opposed to a write request). func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (n int, err error) { - err = c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, map[string]dbus.Variant(nil)).Err + args := make(map[string]any) + err = c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, args).Err + args["type"] = "command" + if err != nil { + return 0, err + } + return len(p), nil +} + +// Write replaces the characteristic value with a new value. The +// call will return after all data has been written. +func (c DeviceCharacteristic) Write(p []byte) (n int, err error) { + args := make(map[string]any) + args["type"] = "request" + err = c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, args).Err if err != nil { return 0, err } From 8a0bf633dc165630c6d0719537d19b15e646fff3 Mon Sep 17 00:00:00 2001 From: Tim Kluge Date: Sun, 19 Oct 2025 16:15:40 +0200 Subject: [PATCH 2/3] Use short hand error check --- gattc_linux.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gattc_linux.go b/gattc_linux.go index 03f8fe04..7fa46ecb 100644 --- a/gattc_linux.go +++ b/gattc_linux.go @@ -222,10 +222,8 @@ func (s DeviceService) DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacteri // writes can be in flight at any given time. This call is also known as a // "write command" (as opposed to a write request). func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (n int, err error) { - args := make(map[string]any) - err = c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, args).Err - args["type"] = "command" - if err != nil { + args := map[string]any{"type": "command"} + if err := c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, args).Err; err != nil { return 0, err } return len(p), nil @@ -234,10 +232,8 @@ func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (n int, err error) // Write replaces the characteristic value with a new value. The // call will return after all data has been written. func (c DeviceCharacteristic) Write(p []byte) (n int, err error) { - args := make(map[string]any) - args["type"] = "request" - err = c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, args).Err - if err != nil { + args := map[string]any{"type": "request"} + if err := c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, args).Err; err != nil { return 0, err } return len(p), nil From b78d0062617828de441afd3c8508da1502b923c8 Mon Sep 17 00:00:00 2001 From: Tim Kluge Date: Sun, 19 Oct 2025 22:26:55 +0200 Subject: [PATCH 3/3] Remove named returns --- gattc_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gattc_linux.go b/gattc_linux.go index 7fa46ecb..66ed5303 100644 --- a/gattc_linux.go +++ b/gattc_linux.go @@ -221,7 +221,7 @@ func (s DeviceService) DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacteri // call will return before all data has been written. A limited number of such // writes can be in flight at any given time. This call is also known as a // "write command" (as opposed to a write request). -func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (n int, err error) { +func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (int, error) { args := map[string]any{"type": "command"} if err := c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, args).Err; err != nil { return 0, err @@ -231,7 +231,7 @@ func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (n int, err error) // Write replaces the characteristic value with a new value. The // call will return after all data has been written. -func (c DeviceCharacteristic) Write(p []byte) (n int, err error) { +func (c DeviceCharacteristic) Write(p []byte) (int, error) { args := map[string]any{"type": "request"} if err := c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, args).Err; err != nil { return 0, err