saas-smartAi通信协议标准库
gongshangguo
2022-02-28 8c2d879c9d3e2208b2cd4d9401b3f6756857d0e9
设备注册信息
1个文件已修改
16 ■■■■■ 已修改文件
server/server.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/server.go
@@ -4,6 +4,7 @@
    "basic.com/valib/go-aiot.git/aiotProto/aiot"
    "basic.com/valib/go-aiot.git/client"
    "basic.com/valib/go-aiot.git/util"
    "encoding/json"
    uuid "github.com/satori/go.uuid"
    "go.uber.org/zap"
    "net"
@@ -160,8 +161,9 @@
}
// 注册设备信息
func (s *Server) SetDeviceList(masterId string, nodeIds []string) bool {
    if len(nodeIds) == 0 {
func (s *Server) SetDeviceList(masterId string, registerData *aiot.DeviceRegister) bool {
    if len(registerData.DeviceList) == 0 {
        return true
    }
    // 锁
@@ -174,9 +176,9 @@
    }
    // 添加设备ID
    for _, nodeId := range nodeIds{
        s.ClusterDevice[masterId][nodeId] = struct{}{}
        s.Devices[nodeId] = struct{}{}
    for _, node := range registerData.DeviceList{
        s.ClusterDevice[masterId][node.DeviceId] = struct{}{}
        s.Devices[node.DeviceId] = struct{}{}
    }
    return true
}
@@ -265,5 +267,7 @@
    // 添加集群ID
    s.SetCluster(msg.SenderId, cli)
    // 设置集群
    s.SetDeviceList(msg.SenderId, msg.DeviceProto.DeviceIds)
    registerData := &aiot.DeviceRegister{}
    json.Unmarshal(msg.Data, registerData)
    s.SetDeviceList(msg.SenderId, registerData)
}