From e3b405e5beeee747696fe59a6781f1b825d8ea63 Mon Sep 17 00:00:00 2001 From: Yurii Soldak Date: Mon, 1 Nov 2021 22:48:16 +0100 Subject: [PATCH] sd: get and set characteristic attributes --- gatts_sd.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gatts_sd.go b/gatts_sd.go index 796fb24d..a1fcbf48 100644 --- a/gatts_sd.go +++ b/gatts_sd.go @@ -146,3 +146,21 @@ func (c *Characteristic) Write(p []byte) (n int, err error) { return len(p), nil } + +// GetAttributes retrieves persistent system attribute information +// Use together with SetAttributes to save and restore characteristic state +func (c *Characteristic) GetAttributes(p []byte) (n int, err error) { + connHandle := currentConnection.Get() + p_len := uint16(len(p)) + errCode := C.sd_ble_gatts_sys_attr_get(connHandle, &p[0], &p_len, 0) + return int(p_len), makeError(errCode) +} + +// SetAttributes updates persistent system attribute information +// Use together with GetAttributes to save and restore characteristic state +func (c *Characteristic) SetAttributes(p []byte) (err error) { + connHandle := currentConnection.Get() + p_len := uint16(len(p)) + errCode := C.sd_ble_gatts_sys_attr_set(connHandle, &p[0], p_len, 0) + return makeError(errCode) +}