package bhomedbapi import ( "basic.com/valib/c_bhomebus.git/proto/source/bhome_msg" jsoniter "github.com/json-iterator/go" ) type DeviceCtlApi struct { } func (api DeviceCtlApi) DevAuthApply(targetIp string, fromDevId string, fromIp string, key string) (bool, interface{}) { url := DATA_URL_PREFIX + "/devAuth/apply" dest := &bhome_msg.BHAddress{ Ip: []byte(targetIp), } netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{ Addr: dest, }) client := NewClient(WithNodes(netNode)) paramBody := map[string]interface{}{ "key": key, "fromDevId": fromDevId, "fromIp": fromIp, } body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil) if err != nil { return false, nil } var res Result var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(body, &res); err != nil { return false, nil } return res.Success, res.Data } func (api DeviceCtlApi) DevDetail(targetIp string, devId string) (bool, interface{}) { url := DATA_URL_PREFIX + "/device/detail" dest := &bhome_msg.BHAddress{ Ip: []byte(targetIp), } netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{ Addr: dest, }) paramQuery := map[string]string{ "devId": devId, } client := NewClient(WithNodes(netNode)) body, err := client.DoGetRequest(url, paramQuery, nil) if err != nil { return false, nil } var res Result var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(body, &res); err != nil { return false, nil } return res.Success, res.Data } //控制其他节点创建集群 func (api DeviceCtlApi) RemoteCreateCluster(devId string, ip string, paramBody map[string]interface{}) (bool, interface{}) { url := DATA_URL_PREFIX + "/cluster/createCluster" dest := &bhome_msg.BHAddress{ Ip: []byte(ip), } netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{ Addr: dest, }) client := NewClient(WithNodes(netNode)) body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil) if err != nil { return false, nil } var res Result var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(body, &res); err != nil { return false, nil } return res.Success, res.Data } //控制其他节点搜索集群 func (api DeviceCtlApi) RemoteSearchCluster(devId string, ip string, paramBody map[string]interface{}) (bool, interface{}) { url := DATA_URL_PREFIX + "/cluster/search" dest := &bhome_msg.BHAddress{ Ip: []byte(ip), } netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{ Addr: dest, }) client := NewClient(WithNodes(netNode)) body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil) if err != nil { return false, nil } var res Result var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(body, &res); err != nil { return false, nil } return res.Success, res.Data } //获取远程设备搜索到集群节点列表 func (api DeviceCtlApi) RemoteGetSearchNodes(devId string, ip string, paramBody map[string]interface{}) (bool, interface{}) { url := DATA_URL_PREFIX + "/cluster/getSearchNodes" dest := &bhome_msg.BHAddress{ Ip: []byte(ip), } netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{ Addr: dest, }) client := NewClient(WithNodes(netNode)) body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil) if err != nil { return false, nil } var res Result var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(body, &res); err != nil { return false, nil } return res.Success, res.Data } //控制其他节点设备加入集群 func (api DeviceCtlApi) RemoteJoinCluster(devId string, ip string, paramBody map[string]interface{}) (bool, interface{}) { url := DATA_URL_PREFIX + "/cluster/joinCluster" dest := &bhome_msg.BHAddress{ Ip: []byte(ip), } netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{ Addr: dest, }) client := NewClient(WithNodes(netNode)) body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil) if err != nil { return false, nil } var res Result var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(body, &res); err != nil { return false, nil } return res.Success, res.Data } //远程控制设备重启 func (api DeviceCtlApi) RemoteReboot(devId string, ip string) (bool, interface{}) { url := DATA_URL_PREFIX + "/sysset/reboot" dest := &bhome_msg.BHAddress{ Ip: []byte(ip), } netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{ Addr: dest, }) client := NewClient(WithNodes(netNode)) paramBody := map[string]interface{}{} body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil) if err != nil { return false, nil } var res Result var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(body, &res); err != nil { return false, nil } return res.Success, res.Data } //远程控制算法或应用卸载 func (api DeviceCtlApi) RemoteUninstall(devId string, ip string, id string) (bool, interface{}) { url := DATA_URL_PREFIX + "/sdk/remoteUninstall" dest := &bhome_msg.BHAddress{ Ip: []byte(ip), } netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{ Addr: dest, }) client := NewClient(WithNodes(netNode)) paramBody := map[string]interface{}{ "id": id, } body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, nil) if err != nil { return false, nil } var res Result var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(body, &res); err != nil { return false, nil } return res.Success, res.Data } //远程控制设备系统更新 func (api DeviceCtlApi) RemoteSysUpdate(devId string, ip string) (bool, interface{}) { url := DATA_URL_PREFIX + "/sysset/remoteSysUpdate" dest := &bhome_msg.BHAddress{ Ip: []byte(ip), } netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{ Addr: dest, }) client := NewClient(WithNodes(netNode)) body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, nil, nil) if err != nil { return false, nil } var res Result var json = jsoniter.ConfigCompatibleWithStandardLibrary if err = json.Unmarshal(body, &res); err != nil { return false, nil } return res.Success, res.Data }