forked from muka/go-bluetooth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_Element1.go
367 lines (308 loc) · 9.88 KB
/
gen_Element1.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// Code generated by go-bluetooth generator DO NOT EDIT.
package mesh
import (
"sync"
"github.com/godbus/dbus/v5"
"github.com/muka/go-bluetooth/bluez"
"github.com/muka/go-bluetooth/props"
"github.com/muka/go-bluetooth/util"
)
var Element1Interface = "org.bluez.mesh.Element1"
// NewElement1 create a new instance of Element1
//
// Args:
// - servicePath: unique name
// - objectPath: <app_defined_element_path>
func NewElement1(servicePath string, objectPath dbus.ObjectPath) (*Element1, error) {
a := new(Element1)
a.client = bluez.NewClient(
&bluez.Config{
Name: servicePath,
Iface: Element1Interface,
Path: dbus.ObjectPath(objectPath),
Bus: bluez.SystemBus,
},
)
a.Properties = new(Element1Properties)
_, err := a.GetProperties()
if err != nil {
return nil, err
}
return a, nil
}
/*
Element1 Mesh Element Hierarchy
*/
type Element1 struct {
client *bluez.Client
propertiesSignal chan *dbus.Signal
objectManagerSignal chan *dbus.Signal
objectManager *bluez.ObjectManager
Properties *Element1Properties
watchPropertiesChannel chan *dbus.Signal
}
// Element1Properties contains the exposed properties of an interface
type Element1Properties struct {
lock sync.RWMutex `dbus:"ignore"`
/*
Location Location descriptor as defined in the GATT Bluetooth Namespace
Descriptors section of the Bluetooth SIG Assigned Numbers
*/
Location uint16
/*
Models An array of SIG Models:
id - SIG Model Identifier
options - a dictionary that may contain additional model
info. The following keys are defined:
*/
Models []ConfigurationItem
/*
Publish supports publication mechanism
*/
Publish bool
/*
Subscribe supports subscription mechanism
The array may be empty.
*/
Subscribe bool
/*
VendorModels An array of Vendor Models:
vendor - a 16-bit Bluetooth-assigned Company ID as
defined by Bluetooth SIG.
id - a 16-bit vendor-assigned Model Identifier
options - a dictionary that may contain additional model
info. The following keys are defined:
*/
VendorModels []VendorOptionsItem
}
//Lock access to properties
func (p *Element1Properties) Lock() {
p.lock.Lock()
}
//Unlock access to properties
func (p *Element1Properties) Unlock() {
p.lock.Unlock()
}
// GetLocation get Location value
func (a *Element1) GetLocation() (uint16, error) {
v, err := a.GetProperty("Location")
if err != nil {
return uint16(0), err
}
return v.Value().(uint16), nil
}
// GetModels get Models value
func (a *Element1) GetModels() ([]ConfigurationItem, error) {
v, err := a.GetProperty("Models")
if err != nil {
return []ConfigurationItem{}, err
}
return v.Value().([]ConfigurationItem), nil
}
// SetPublish set Publish value
func (a *Element1) SetPublish(v bool) error {
return a.SetProperty("Publish", v)
}
// GetPublish get Publish value
func (a *Element1) GetPublish() (bool, error) {
v, err := a.GetProperty("Publish")
if err != nil {
return false, err
}
return v.Value().(bool), nil
}
// SetSubscribe set Subscribe value
func (a *Element1) SetSubscribe(v bool) error {
return a.SetProperty("Subscribe", v)
}
// GetSubscribe get Subscribe value
func (a *Element1) GetSubscribe() (bool, error) {
v, err := a.GetProperty("Subscribe")
if err != nil {
return false, err
}
return v.Value().(bool), nil
}
// GetVendorModels get VendorModels value
func (a *Element1) GetVendorModels() ([]VendorOptionsItem, error) {
v, err := a.GetProperty("VendorModels")
if err != nil {
return []VendorOptionsItem{}, err
}
return v.Value().([]VendorOptionsItem), nil
}
// Close the connection
func (a *Element1) Close() {
a.unregisterPropertiesSignal()
a.client.Disconnect()
}
// Path return Element1 object path
func (a *Element1) Path() dbus.ObjectPath {
return a.client.Config.Path
}
// Client return Element1 dbus client
func (a *Element1) Client() *bluez.Client {
return a.client
}
// Interface return Element1 interface
func (a *Element1) Interface() string {
return a.client.Config.Iface
}
// GetObjectManagerSignal return a channel for receiving updates from the ObjectManager
func (a *Element1) GetObjectManagerSignal() (chan *dbus.Signal, func(), error) {
if a.objectManagerSignal == nil {
if a.objectManager == nil {
om, err := bluez.GetObjectManager()
if err != nil {
return nil, nil, err
}
a.objectManager = om
}
s, err := a.objectManager.Register()
if err != nil {
return nil, nil, err
}
a.objectManagerSignal = s
}
cancel := func() {
if a.objectManagerSignal == nil {
return
}
a.objectManagerSignal <- nil
a.objectManager.Unregister(a.objectManagerSignal)
a.objectManagerSignal = nil
}
return a.objectManagerSignal, cancel, nil
}
// ToMap convert a Element1Properties to map
func (a *Element1Properties) ToMap() (map[string]interface{}, error) {
return props.ToMap(a), nil
}
// FromMap convert a map to an Element1Properties
func (a *Element1Properties) FromMap(props map[string]interface{}) (*Element1Properties, error) {
props1 := map[string]dbus.Variant{}
for k, val := range props {
props1[k] = dbus.MakeVariant(val)
}
return a.FromDBusMap(props1)
}
// FromDBusMap convert a map to an Element1Properties
func (a *Element1Properties) FromDBusMap(props map[string]dbus.Variant) (*Element1Properties, error) {
s := new(Element1Properties)
err := util.MapToStruct(s, props)
return s, err
}
// ToProps return the properties interface
func (a *Element1) ToProps() bluez.Properties {
return a.Properties
}
// GetWatchPropertiesChannel return the dbus channel to receive properties interface
func (a *Element1) GetWatchPropertiesChannel() chan *dbus.Signal {
return a.watchPropertiesChannel
}
// SetWatchPropertiesChannel set the dbus channel to receive properties interface
func (a *Element1) SetWatchPropertiesChannel(c chan *dbus.Signal) {
a.watchPropertiesChannel = c
}
// GetProperties load all available properties
func (a *Element1) GetProperties() (*Element1Properties, error) {
a.Properties.Lock()
err := a.client.GetProperties(a.Properties)
a.Properties.Unlock()
return a.Properties, err
}
// SetProperty set a property
func (a *Element1) SetProperty(name string, value interface{}) error {
return a.client.SetProperty(name, value)
}
// GetProperty get a property
func (a *Element1) GetProperty(name string) (dbus.Variant, error) {
return a.client.GetProperty(name)
}
// GetPropertiesSignal return a channel for receiving udpdates on property changes
func (a *Element1) GetPropertiesSignal() (chan *dbus.Signal, error) {
if a.propertiesSignal == nil {
s, err := a.client.Register(a.client.Config.Path, bluez.PropertiesInterface)
if err != nil {
return nil, err
}
a.propertiesSignal = s
}
return a.propertiesSignal, nil
}
// Unregister for changes signalling
func (a *Element1) unregisterPropertiesSignal() {
if a.propertiesSignal != nil {
a.propertiesSignal <- nil
a.propertiesSignal = nil
}
}
// WatchProperties updates on property changes
func (a *Element1) WatchProperties() (chan *bluez.PropertyChanged, error) {
return bluez.WatchProperties(a)
}
func (a *Element1) UnwatchProperties(ch chan *bluez.PropertyChanged) error {
return bluez.UnwatchProperties(a, ch)
}
/*
MessageReceived This method is called by bluetooth-meshd daemon when a message
arrives addressed to the application.
The source parameter is unicast address of the remote
node-element that sent the message.
The key_index parameter indicates which application key has been
used to decode the incoming message. The same key_index should
be used by the application when sending a response to this
message (in case a response is expected).
The destination parameter contains the destination address of
received message. Underlying variant types are:
uint16
Destination is an unicast address, or a well known
group address
array{byte}
Destination is a virtual address label
The data parameter is the incoming message.
*/
func (a *Element1) MessageReceived(source uint16, key_index uint16, destination dbus.Variant, data []byte) error {
return a.client.Call("MessageReceived", 0, source, key_index, destination, data).Store()
}
/*
DevKeyMessageReceived This method is called by meshd daemon when a message arrives
addressed to the application, which was sent with the remote
node's device key.
The source parameter is unicast address of the remote
node-element that sent the message.
The remote parameter if true indicates that the device key
used to decrypt the message was from the sender. False
indicates that the local nodes device key was used, and the
message has permissions to modify local states.
The net_index parameter indicates what subnet the message was
received on, and if a response is required, the same subnet
must be used to send the response.
The data parameter is the incoming message.
*/
func (a *Element1) DevKeyMessageReceived(source uint16, remote bool, net_index uint16, data []byte) error {
return a.client.Call("DevKeyMessageReceived", 0, source, remote, net_index, data).Store()
}
/*
UpdateModelConfiguration This method is called by bluetooth-meshd daemon when a model's
configuration is updated.
The model_id parameter contains BT SIG Model Identifier or, if
Vendor key is present in config dictionary, a 16-bit
vendor-assigned Model Identifier.
The config parameter is a dictionary with the following keys
defined:
array{uint16} Bindings
Indices of application keys bound to the model
uint32 PublicationPeriod
Model publication period in milliseconds
uint16 Vendor
A 16-bit Bluetooth-assigned Company Identifier of the
vendor as defined by Bluetooth SIG
array{variant} Subscriptions
Addresses the model is subscribed to.
Each address is provided either as uint16 for group
addresses, or as array{byte} for virtual labels.
*/
func (a *Element1) UpdateModelConfiguration(model_id uint16, config map[string]interface{}) error {
return a.client.Call("UpdateModelConfiguration", 0, model_id, config).Store()
}