-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluez_gatt_client.go
51 lines (41 loc) · 1.4 KB
/
bluez_gatt_client.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
package bluez
type GattApplication struct {
Path string
Services map[string]*GattService
}
type GattService struct {
UUID string
Characteristics map[string]*GattCharacteristic
}
type GattCharacteristic struct {
UUID string
Flags []string
OnReadFunc func() ([]byte, error)
OnWriteFunc func([]byte) error
}
func (self *GattApplication) AddService(gattService *GattService) {
self.Services[gattService.UUID] = gattService
}
func (self *GattApplication) RemoveService(gattService *GattService) {
delete(self.Services, gattService.UUID)
}
func (self *GattService) AddCharacteristic(gattCharacteristic *GattCharacteristic) {
self.Characteristics[gattCharacteristic.UUID] = gattCharacteristic
}
func (self *GattService) RemoveCharacteristic(gattCharacteristic *GattCharacteristic) {
delete(self.Characteristics, gattCharacteristic.UUID)
}
func NewGattApplication(path string) (gattApplication *GattApplication) {
gattApplication = &GattApplication{Path: path}
gattApplication.Services = make(map[string]*GattService, 0)
return
}
func NewGattService(uuid string) (gattService *GattService) {
gattService = &GattService{UUID: uuid}
gattService.Characteristics = make(map[string]*GattCharacteristic, 0)
return
}
func NewGattCharacteristic(uuid string, flags []string) (gattCharacteristic *GattCharacteristic) {
gattCharacteristic = &GattCharacteristic{UUID: uuid, Flags: flags}
return
}