liuxiulin 8 tháng trước cách đây
mục cha
commit
2e98891965

+ 1 - 0
pkg/models/device.go

@@ -77,6 +77,7 @@ const (
 	SetFjsqStatus   Command = "setFjsqStatus"   // 智能分集水器控制
 	SetOutdoorPower Command = "setOutdoorPower" // 设置水系统外机电源状态
 	SetOutdoorTemp  Command = "setOutdoorTemp"  // 设置水系统外机出水温度
+	OtaUpgrade      Command = "devUpgrade"      // ota升级
 )
 
 type SendCommandParams struct {

+ 0 - 16
services/emqx-agent/agent.go

@@ -305,22 +305,6 @@ func (a *Access) GetStatus(args rpcs.ArgsGetStatus, reply *rpcs.ReplyGetStatus)
 	return a.SendCommand(cmdArgs, &cmdReply)
 }
 
-func (a *Access) Upgrade(args rpcs.ArgsUpgrade4G, reply *rpcs.ReplyEmptyResult) error {
-	server.Log.Infof("4G模组OTA升级:%s", args.DeviceId)
-	cmdReply := rpcs.ReplySendCommand{}
-	cmdArgs := rpcs.ArgsSendCommand{
-		DeviceId: args.DeviceId,
-		WaitTime: 0,
-		Cmd:      "devUpgrade",
-		Params: map[string]interface{}{
-			"fileId":   args.FileId,
-			"fileSize": args.FileSize,
-		},
-	}
-
-	return a.SendCommand(cmdArgs, &cmdReply)
-}
-
 func chunkUpgrade(params rpcs.ChunkUpgrade) error {
 	server.Log.Infof("4G模组OTA升级:%s", params.DeviceId)
 	reply := new(rpcs.ReplyEmptyResult)

+ 0 - 17
services/knowoapi/model/device.go

@@ -1,7 +1,6 @@
 package model
 
 import (
-	"fmt"
 	"sparrow/pkg/models"
 	"time"
 
@@ -145,22 +144,6 @@ func (a *Device) GetDevices(vendorid, proid string, pi, ps int, deviceid string)
 	return
 }
 
-// GetDevice 获取设备
-func (a *Device) GetDevice(vendorid string, alertid string) (data models.Device, err error) {
-	cache := getCache()
-	key := fmt.Sprintf("Alert:%d", alertid)
-	if v, ok := cache.Get(key); ok {
-		_d := v.(*models.Device)
-		data = *_d
-	} else {
-		err = a.db.Where("vendor_id = ? and record_id = ?", vendorid, alertid).First(&data).Error
-		if err == nil {
-			cache.Set(key, &data)
-		}
-	}
-	return
-}
-
 // GetDevicesByVenderId 获取用户设备
 func (a *Device) GetDevicesByVenderId(vendorid string) (datas []models.Device, err error) {
 	a.db.Where("vendor_id = ?", vendorid).Find(&datas)

+ 11 - 10
services/knowoapi/services/device.go

@@ -156,9 +156,9 @@ func (a deviceservice) GetDevicesCountByVenderId(vendorid string) (map[string]in
 	return deviceCount, nil
 }
 
-func (a deviceservice) Upgrade(param *models.UpgradeParams) error {
+func (a deviceservice) Upgrade(params *models.UpgradeParams) error {
 	var fileArgs rpcs.ArgsOtaFile
-	fileArgs.FileData = param.File
+	fileArgs.FileData = params.File
 	fileArgs.FileId = guid.S()
 	var reply rpcs.ReplyEmptyResult
 
@@ -167,17 +167,18 @@ func (a deviceservice) Upgrade(param *models.UpgradeParams) error {
 		server.Log.Errorf("OTA升级文件保存失败:%v", err)
 		return err
 	}
-
-	var args rpcs.ArgsUpgrade4G
-	args.DeviceId = param.DeviceID
-	args.FileId = fileArgs.FileId
-	args.FileSize = param.FileSize
-
-	err = server.RPCCallByName(nil, rpcs.EmqxAgentServiceName, "Access.Upgrade", args, &reply)
+	var args rpcs.ArgsSendCommand
+	args.Cmd = string(models.OtaUpgrade)
+	args.DeviceId = params.DeviceID
+	args.Params = map[string]interface{}{
+		"fileId":   fileArgs.FileId,
+		"fileSize": params.FileSize,
+	}
+	err = a.sendCommand(args)
 	if err != nil {
-		server.Log.Errorf("4G模组OTA升级失败:%v", err)
 		return err
 	}
+
 	server.Log.Debugf("ota升级请求成功")
 	return nil
 }