-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnode_receive_message.go
69 lines (59 loc) · 1.92 KB
/
node_receive_message.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
package zstack
import (
"context"
"github.com/shimmeringbee/logwrap"
"github.com/shimmeringbee/zigbee"
)
func (z *ZStack) startMessageReceiver() {
_, z.messageReceiverStop = z.subscriber.Subscribe(&AfIncomingMsg{}, func(v interface{}) {
msg := v.(*AfIncomingMsg)
ctx, cancel := context.WithTimeout(context.Background(), DefaultResolveIEEETimeout)
defer cancel()
ieee, err := z.ResolveNodeIEEEAddress(ctx, msg.SourceAddress)
if err != nil {
z.logger.LogError(ctx, "Received AfIncomingMsg (application message), however unable to resolve IEEE address to issue event.", logwrap.Err(err), logwrap.Datum("NetworkAddress", msg.SourceAddress))
return
}
node, _ := z.nodeTable.getByIEEE(ieee)
z.sendEvent(zigbee.NodeIncomingMessageEvent{
Node: node,
IncomingMessage: zigbee.IncomingMessage{
GroupID: msg.GroupID,
SourceAddress: zigbee.SourceAddress{
IEEEAddress: ieee,
NetworkAddress: msg.SourceAddress,
},
Broadcast: msg.WasBroadcast,
Secure: msg.SecurityUse,
LinkQuality: msg.LinkQuality,
Sequence: msg.Sequence,
ApplicationMessage: zigbee.ApplicationMessage{
ClusterID: msg.ClusterID,
SourceEndpoint: msg.SourceEndpoint,
DestinationEndpoint: msg.DestinationEndpoint,
Data: msg.Data,
},
},
})
z.nodeTable.update(ieee, updateReceived(), lqi(msg.LinkQuality))
})
}
func (z *ZStack) stopMessageReceiver() {
if z.messageReceiverStop != nil {
z.messageReceiverStop()
}
}
type AfIncomingMsg struct {
GroupID zigbee.GroupID
ClusterID zigbee.ClusterID
SourceAddress zigbee.NetworkAddress
SourceEndpoint zigbee.Endpoint
DestinationEndpoint zigbee.Endpoint
WasBroadcast bool
LinkQuality uint8
SecurityUse bool
TimeStamp uint32
Sequence uint8
Data []byte `bcsliceprefix:"8"`
}
const AfIncomingMsgID uint8 = 0x81