| | |
| | | "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" |
| | |
| | | } |
| | | |
| | | // 注册设备信息 |
| | | 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 |
| | | } |
| | | // 锁 |
| | |
| | | } |
| | | |
| | | // 添加设备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 |
| | | } |
| | |
| | | // 添加集群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) |
| | | } |