forked from muka/go-bluetooth
/
GattDescriptor1.go
122 lines (100 loc) · 2.83 KB
/
GattDescriptor1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package service
import (
"github.com/godbus/dbus"
"github.com/godbus/dbus/introspect"
"github.com/godbus/dbus/prop"
"github.com/muka/go-bluetooth/bluez"
"github.com/muka/go-bluetooth/bluez/profile"
)
// NewGattDescriptor1 create a new GattDescriptor1 client
func NewGattDescriptor1(config *GattDescriptor1Config, props *profile.GattDescriptor1Properties) (*GattDescriptor1, error) {
propInterface, err := NewProperties(config.conn)
if err != nil {
return nil, err
}
g := &GattDescriptor1{
config: config,
properties: props,
PropertiesInterface: propInterface,
}
err = propInterface.AddProperties(g.Interface(), props)
if err != nil {
return nil, err
}
return g, nil
}
//GattDescriptor1Config GattDescriptor1 configuration
type GattDescriptor1Config struct {
objectPath dbus.ObjectPath
characteristic *GattCharacteristic1
ID int
conn *dbus.Conn
}
// GattDescriptor1 client
type GattDescriptor1 struct {
config *GattDescriptor1Config
properties *profile.GattDescriptor1Properties
PropertiesInterface *Properties
}
//Path return the object path
func (s *GattDescriptor1) Path() dbus.ObjectPath {
return s.config.objectPath
}
//Interface return the Dbus interface
func (s *GattDescriptor1) Interface() string {
return bluez.GattDescriptor1Interface
}
//Properties return the properties of the service
func (s *GattDescriptor1) Properties() map[string]bluez.Properties {
p := make(map[string]bluez.Properties)
s.properties.Characteristic = s.config.characteristic.Path()
p[s.Interface()] = s.properties
return p
}
//ReadValue read a value
func (s *GattDescriptor1) ReadValue(options map[string]interface{}) []byte {
dbg("Descriptor.ReadValue")
b := make([]byte, 0)
return b
}
//WriteValue write a value
func (s *GattDescriptor1) WriteValue(value []byte, options map[string]interface{}) {
dbg("Descriptor.ReadValue")
}
//Expose the desc to dbus
func (s *GattDescriptor1) Expose() error {
dbg("GATT Descriptor path %s", s.Path())
conn := s.config.conn
err := conn.Export(s, s.Path(), s.Interface())
if err != nil {
return err
}
dbg("Exposing Properties interface")
for iface, props := range s.Properties() {
s.PropertiesInterface.AddProperties(iface, props)
}
s.PropertiesInterface.Expose(s.Path())
node := &introspect.Node{
Interfaces: []introspect.Interface{
//Introspect
introspect.IntrospectData,
//Properties
prop.IntrospectData,
//GattCharacteristic1
{
Name: s.Interface(),
Methods: introspect.Methods(s),
Properties: s.PropertiesInterface.Introspection(s.Interface()),
},
},
}
err = conn.Export(
introspect.NewIntrospectable(node),
s.Path(),
"org.freedesktop.DBus.Introspectable")
if err != nil {
return err
}
dbg("Exposed GATT descriptor %s (%s)", s.properties.UUID, s.Path())
return nil
}