This repository has been archived by the owner on Sep 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmessage_pushing.go
78 lines (72 loc) · 3.22 KB
/
message_pushing.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
// Copyright 2017 The go-oceanconnect authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package oceanconnect
import (
"encoding/json"
"errors"
)
type Notification string
const (
// NotificationDeviceAdded is used to notify initial device logins.
// When a device registers with the OceanConnect (the device creates messages on
// the OceanConnect and obtains the password), the OceanConnect sends a
// notification to the application or a new device is added to the gateway, the
// OceanConnect invokes this interface to send a notification to the application.
NotificationDeviceAdded Notification = "deviceAdded"
// NotificationDeviceInfoChanged is used after receiving device information changes
// (changes of static information such as the device name and manufacturer ID).
NotificationDeviceInfoChanged Notification = "deviceInfoChanged"
// NotificationDeviceDataChanged is used after receiving device data changes
// (dynamic changes such as changes of service attribute values).
NotificationDeviceDataChanged Notification = "deviceDataChanged"
// NotificationDeviceDeleted is used when learning that a
// non-directly-connected device is deleted
NotificationDeviceDeleted Notification = "deviceDeleted"
// NotificationMessageConfirm is used after receiving an acknowledgment
// message from the gateway, for example, the OceanConnect sends a command
// to the gateway and the gateway acknowledges the message.
NotificationMessageConfirm Notification = "messageConfirm"
// NotificationCommandResponse is used after receiving a response command
// from a device (gateway or common device), for example, the OceanConnect sends a
// command to the device and the device returns a response command after running the
// command, such as video call, video recording, and screenshot
NotificationCommandResponse Notification = "commandRsp"
// NotificationDeviceEvent after receiving an event (for example, insufficient
// UDS storage space) from a device
NotificationDeviceEvent Notification = "deviceEvent"
// NotificationServiceInfoChanged is sent when learning device service information
// changes, the OceanConnect invokes this interface to send a notification to the
// application.
NotificationServiceInfoChanged Notification = "serviceInfoChanged"
// NotificationRuleEvent is used when generates the corresponding rule event
// notification to NA when the rule is triggered
NotificationRuleEvent Notification = "ruleEvent"
)
func notificationDeserializer(not Notification, in []byte) (interface{}, error) {
switch not {
case NotificationDeviceDataChanged:
s := &DeviceDataChanged{}
if err := json.Unmarshal(in, s); err != nil {
return nil, err
}
return s, nil
case NotificationDeviceAdded:
case NotificationDeviceInfoChanged:
case NotificationDeviceDeleted:
case NotificationMessageConfirm:
case NotificationCommandResponse:
case NotificationDeviceEvent:
case NotificationServiceInfoChanged:
case NotificationRuleEvent:
break
}
return nil, errors.New("not implemented")
}
//DeviceDataChanged struct with device data
type DeviceDataChanged struct {
DeviceID string
GatewayID string
RequestID string
Service Service `json:"service"`
}