|
@@ -1,6 +1,7 @@
|
|
package services
|
|
package services
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "encoding/json"
|
|
"github.com/gogf/gf/encoding/gjson"
|
|
"github.com/gogf/gf/encoding/gjson"
|
|
"sparrow/pkg/models"
|
|
"sparrow/pkg/models"
|
|
"sparrow/pkg/rpcs"
|
|
"sparrow/pkg/rpcs"
|
|
@@ -28,10 +29,28 @@ type DeviceService interface {
|
|
Upgrade(params *models.UpgradeParams) error
|
|
Upgrade(params *models.UpgradeParams) error
|
|
// GetUpgradeProgress 获取ota升级进度
|
|
// GetUpgradeProgress 获取ota升级进度
|
|
GetUpgradeProgress(deviceId string) (rpcs.ReplyOtaProgress, error)
|
|
GetUpgradeProgress(deviceId string) (rpcs.ReplyOtaProgress, error)
|
|
- // 获取设备状态数据
|
|
|
|
- GetDeviceStatus(deviceId string) (*gjson.Json, error)
|
|
|
|
- // 获取分体式五恒获取网关信息
|
|
|
|
- GetSplitInfo(deviceId string) error
|
|
|
|
|
|
+ // GetDeviceStatus 获取设备状态数据
|
|
|
|
+ GetDeviceStatus(deviceId string, deviceType int) (*gjson.Json, error)
|
|
|
|
+ // SetReport 获取设备状态
|
|
|
|
+ SetReport(params models.SendCommandParams) error
|
|
|
|
+ // Restart 重启设备
|
|
|
|
+ Restart(params models.SendCommandParams) error
|
|
|
|
+ // ClearData 清除设备配置数据
|
|
|
|
+ ClearData(params models.SendCommandParams) error
|
|
|
|
+ // SetDataTrans 设备端自动上报配置
|
|
|
|
+ SetDataTrans(params models.SendCommandParams) error
|
|
|
|
+ // GetInfo 获取网关信息
|
|
|
|
+ GetInfo(params models.SendCommandParams) error
|
|
|
|
+ // ForceRun 远程控制某个模块强制运行
|
|
|
|
+ ForceRun(params models.SendCommandParams) error
|
|
|
|
+ // SetDeviceId 写入设备id
|
|
|
|
+ SetDeviceId(params models.SendCommandParams) error
|
|
|
|
+ // SetFjsqStatus 智能分集水器控制
|
|
|
|
+ SetFjsqStatus(params models.SendCommandParams) error
|
|
|
|
+ // SetOutdoorPower 设置水系统外机电源状态
|
|
|
|
+ SetOutdoorPower(params models.SendCommandParams) error
|
|
|
|
+ // SetOutdoorTemp 设置水系统外机出水温度
|
|
|
|
+ SetOutdoorTemp(params models.SendCommandParams) error
|
|
}
|
|
}
|
|
|
|
|
|
type deviceservice struct {
|
|
type deviceservice struct {
|
|
@@ -175,7 +194,7 @@ func (a deviceservice) GetUpgradeProgress(deviceId string) (rpcs.ReplyOtaProgres
|
|
return reply, nil
|
|
return reply, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (a deviceservice) GetDeviceStatus(deviceId string) (*gjson.Json, error) {
|
|
|
|
|
|
+func (a deviceservice) GetDeviceStatus(deviceId string, deviceType int) (*gjson.Json, error) {
|
|
var args rpcs.ArgsGetStatus
|
|
var args rpcs.ArgsGetStatus
|
|
args.Id = deviceId
|
|
args.Id = deviceId
|
|
|
|
|
|
@@ -185,14 +204,140 @@ func (a deviceservice) GetDeviceStatus(deviceId string) (*gjson.Json, error) {
|
|
server.Log.Errorf("设备状态数据获取失败:%v", err)
|
|
server.Log.Errorf("设备状态数据获取失败:%v", err)
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
+ result := new(gjson.Json)
|
|
|
|
+ switch deviceType {
|
|
|
|
+ case 1:
|
|
|
|
+ status := new(models.SplitDeviceStatus)
|
|
|
|
+ err = json.Unmarshal([]byte(reply.Status), &status)
|
|
|
|
+ status.StatusCodeMap["nj1"] = 1
|
|
|
|
+ status.StatusCodeMap["nj2"] = 1
|
|
|
|
+ status.StatusCodeMap["nj3"] = 1
|
|
|
|
+ status.StatusCodeMap["nj4"] = 1
|
|
|
|
+ status.StatusCodeMap["nj5"] = 1
|
|
|
|
+ status.StatusCodeMap["air_quality_sensor"] = 1
|
|
|
|
|
|
- return gjson.New(reply.Status), nil
|
|
|
|
|
|
+ if status.StatusCode&0x01 == 0 {
|
|
|
|
+ status.StatusCodeMap["nj1"] = 0
|
|
|
|
+ }
|
|
|
|
+ if status.StatusCode&0x02 == 0 {
|
|
|
|
+ status.StatusCodeMap["nj2"] = 0
|
|
|
|
+ }
|
|
|
|
+ if status.StatusCode&0x04 == 0 {
|
|
|
|
+ status.StatusCodeMap["nj1"] = 0
|
|
|
|
+ }
|
|
|
|
+ if status.StatusCode&0x08 == 0 {
|
|
|
|
+ status.StatusCodeMap["nj1"] = 0
|
|
|
|
+ }
|
|
|
|
+ if status.StatusCode&0x10 == 0 {
|
|
|
|
+ status.StatusCodeMap["nj1"] = 0
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ result = gjson.New(status)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result, nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SetReport 获取设备状态
|
|
|
|
+func (a deviceservice) SetReport(params models.SendCommandParams) error {
|
|
|
|
+ var args rpcs.ArgsSendCommand
|
|
|
|
+ args.DeviceId = params.DeviceId
|
|
|
|
+ args.Cmd = string(models.Report)
|
|
|
|
+ return a.sendCommand(args)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Restart 重启设备
|
|
|
|
+func (a deviceservice) Restart(params models.SendCommandParams) error {
|
|
|
|
+ var args rpcs.ArgsSendCommand
|
|
|
|
+ args.DeviceId = params.DeviceId
|
|
|
|
+ args.Cmd = string(models.Restart)
|
|
|
|
+ return a.sendCommand(args)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// ClearData 清除设备配置数据
|
|
|
|
+func (a deviceservice) ClearData(params models.SendCommandParams) error {
|
|
|
|
+ var args rpcs.ArgsSendCommand
|
|
|
|
+ args.DeviceId = params.DeviceId
|
|
|
|
+ args.Cmd = string(models.ClearData)
|
|
|
|
+ return a.sendCommand(args)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SetDataTrans 设备端自动上报配置
|
|
|
|
+func (a deviceservice) SetDataTrans(params models.SendCommandParams) error {
|
|
|
|
+ var args rpcs.ArgsSendCommand
|
|
|
|
+ args.DeviceId = params.DeviceId
|
|
|
|
+ args.Params = map[string]interface{}{
|
|
|
|
+ "enable": params.Enable,
|
|
|
|
+ "internal": params.Internal,
|
|
|
|
+ }
|
|
|
|
+ args.Cmd = string(models.SetDataTrans)
|
|
|
|
+ return a.sendCommand(args)
|
|
}
|
|
}
|
|
|
|
|
|
-func (a deviceservice) GetSplitInfo(deviceId string) error {
|
|
|
|
|
|
+// GetInfo 获取网关信息
|
|
|
|
+func (a deviceservice) GetInfo(params models.SendCommandParams) error {
|
|
var args rpcs.ArgsSendCommand
|
|
var args rpcs.ArgsSendCommand
|
|
- args.DeviceId = deviceId
|
|
|
|
- args.Cmd = "getInfo"
|
|
|
|
|
|
+ args.DeviceId = params.DeviceId
|
|
|
|
+ args.Cmd = string(models.GetInfo)
|
|
|
|
+ return a.sendCommand(args)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// ForceRun 远程控制某个模块强制运行
|
|
|
|
+func (a deviceservice) ForceRun(params models.SendCommandParams) error {
|
|
|
|
+ var args rpcs.ArgsSendCommand
|
|
|
|
+ args.DeviceId = params.DeviceId
|
|
|
|
+ args.Cmd = string(models.ForceRun)
|
|
|
|
+ args.Params = map[string]interface{}{
|
|
|
|
+ "module": params.Module,
|
|
|
|
+ "power": params.ModulePower,
|
|
|
|
+ }
|
|
|
|
+ return a.sendCommand(args)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SetDeviceId 写入设备id
|
|
|
|
+func (a deviceservice) SetDeviceId(params models.SendCommandParams) error {
|
|
|
|
+ var args rpcs.ArgsSendCommand
|
|
|
|
+ args.DeviceId = params.DeviceId
|
|
|
|
+ args.Cmd = string(models.SetDeviceId)
|
|
|
|
+ args.Params = map[string]interface{}{
|
|
|
|
+ "id": params.Id,
|
|
|
|
+ }
|
|
|
|
+ return a.sendCommand(args)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SetFjsqStatus 智能分集水器控制
|
|
|
|
+func (a deviceservice) SetFjsqStatus(params models.SendCommandParams) error {
|
|
|
|
+ var args rpcs.ArgsSendCommand
|
|
|
|
+ args.DeviceId = params.DeviceId
|
|
|
|
+ args.Cmd = string(models.SetFjsqStatus)
|
|
|
|
+ return a.sendCommand(args)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SetOutdoorPower 设置水系统外机电源状态
|
|
|
|
+func (a deviceservice) SetOutdoorPower(params models.SendCommandParams) error {
|
|
|
|
+ var args rpcs.ArgsSendCommand
|
|
|
|
+ args.DeviceId = params.DeviceId
|
|
|
|
+ args.Cmd = string(models.SetOutdoorPower)
|
|
|
|
+ args.Params = map[string]interface{}{
|
|
|
|
+ "power": params.OutdoorPower,
|
|
|
|
+ }
|
|
|
|
+ return a.sendCommand(args)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SetOutdoorTemp 设置水系统外机出水温度
|
|
|
|
+func (a deviceservice) SetOutdoorTemp(params models.SendCommandParams) error {
|
|
|
|
+ var args rpcs.ArgsSendCommand
|
|
|
|
+ args.DeviceId = params.DeviceId
|
|
|
|
+ args.Cmd = string(models.SetOutdoorTemp)
|
|
|
|
+ args.Params = map[string]interface{}{
|
|
|
|
+ "cool_mode_temp": params.CoolModeTemp,
|
|
|
|
+ "heat_mode_temp": params.HeatModeTemp,
|
|
|
|
+ }
|
|
|
|
+ return a.sendCommand(args)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SendCommand 下发指令
|
|
|
|
+func (a deviceservice) sendCommand(args rpcs.ArgsSendCommand) error {
|
|
var reply rpcs.ReplySendCommand
|
|
var reply rpcs.ReplySendCommand
|
|
err := server.RPCCallByName(nil, rpcs.ControllerName, "Controller.SendCommand", args, &reply)
|
|
err := server.RPCCallByName(nil, rpcs.ControllerName, "Controller.SendCommand", args, &reply)
|
|
if err != nil {
|
|
if err != nil {
|