-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasedrv.go
61 lines (50 loc) · 1.22 KB
/
basedrv.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
package iotbase
import (
"encoding/json"
"github.com/akingbrDu/iotbase/core"
)
type BaseDriver struct {
device core.Device
model core.ModelAriot
deploy core.DeployAriot
handler core.IEventHandler
initParamHook core.IInitHook
}
func (drv *BaseDriver) Init(device core.Device, configJson string, modelJson string, handler core.IEventHandler) error {
drv.handler = handler
drv.device = device
err := json.Unmarshal([]byte(modelJson), &drv.model)
if err != nil {
return err
}
err = json.Unmarshal([]byte(configJson), &drv.deploy)
if err != nil {
return err
}
return nil
}
func (drv *BaseDriver) emitStatus(status core.Status) {
if drv.handler != nil {
drv.handler.OnStatus(status)
}
}
func (drv *BaseDriver) emitError(warn core.Warn) {
if drv.handler != nil {
drv.handler.OnError(warn)
}
}
func (drv *BaseDriver) emitProperty(property core.Property) {
if drv.handler != nil {
drv.handler.OnProperty(property)
}
}
func (drv *BaseDriver) emitProperties(properties []core.Property) {
if drv.handler != nil {
drv.handler.OnProperties(properties)
}
}
func (drv *BaseDriver) emitCommandReply(reply core.CommandReply) {
if drv.handler != nil {
drv.handler.OnCommandReply(reply)
}
}