package bhomedbapi import ( "basic.com/valib/bhshmq.git/proto/source/bhome_msg" "encoding/json" ) type DeviceCtlApi struct { } func (api DeviceCtlApi) DevAuthApply(paramBody map[string]interface{}) (bool,interface{}) { url := DATA_URL_PREFIX + "/devAuth/apply" netNode := getNetNode(url2Topic(Topic_System_Service,url)) client := NewClient(WithNodes(netNode)) body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil) if err != nil { return false,nil } var res Result if err = json.Unmarshal(body, &res); err != nil { return false,nil } return res.Success,res.Data } func (api DeviceCtlApi) DevDetail(paramBody map[string]interface{}) (bool, interface{}) { url := DATA_URL_PREFIX + "/device/detail" netNode := getNetNode(url2Topic(Topic_System_Service,url)) client := NewClient(WithNodes(netNode)) body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil) if err != nil { return false,nil } var res Result 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" netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{ Ip: []byte(ip), }) client := NewClient(WithNodes(netNode)) body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil) if err != nil { return false,nil } var res Result 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" netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{ Ip: []byte(ip), }) client := NewClient(WithNodes(netNode)) body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil) if err != nil { return false,nil } var res Result 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" netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{ Ip: []byte(ip), }) client := NewClient(WithNodes(netNode)) body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil) if err != nil { return false,nil } var res Result 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" netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{ Ip: []byte(ip), }) client := NewClient(WithNodes(netNode)) body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil) if err != nil { return false,nil } var res Result 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" netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{ Ip: []byte(ip), }) 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 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" netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{ Ip: []byte(ip), }) 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 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" netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{ Ip: []byte(ip), }) client := NewClient(WithNodes(netNode)) body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, nil,nil) if err != nil { return false,nil } var res Result if err = json.Unmarshal(body, &res); err != nil { return false,nil } return res.Success,res.Data }