Browse Source

update ota

liuxiulin 8 tháng trước cách đây
mục cha
commit
4094873f68
1 tập tin đã thay đổi với 5 bổ sung30 xóa
  1. 5 30
      services/emqx-agent/agent.go

+ 5 - 30
services/emqx-agent/agent.go

@@ -3,7 +3,6 @@ package main
 import (
 	"bytes"
 	"context"
-	"encoding/json"
 	"errors"
 	"fmt"
 	"github.com/gogf/gf/encoding/gjson"
@@ -307,38 +306,14 @@ func (a *Access) GetStatus(args rpcs.ArgsGetStatus, reply *rpcs.ReplyGetStatus)
 
 func (a *Access) chunkUpgrade(params rpcs.ChunkUpgrade) error {
 	server.Log.Infof("4G模组OTA升级:%s", params.DeviceId)
-	cmd := &klink.CloudSend{
-		Action:     "cloudSend",
-		MsgId:      0,
-		DeviceCode: params.DeviceId,
-		Timestamp:  time.Now().Unix(),
-		Data: &klink.CloudSendData{
-			Cmd: "devUpgrade",
-			Params: map[string]interface{}{
-				"fileId":   params.FileId,
-				"fileSize": params.FileSize,
-				"size":     params.Size,
-				"offset":   params.Offset,
-			},
-		},
-	}
-
-	byteCmd, err := json.Marshal(cmd)
-	if err != nil {
-		return err
-	}
-
-	buf := bytes.NewBuffer(gbinary.BeEncodeUint16(gconv.Uint16(len(byteCmd))))
 
-	server.Log.Infof("1----------填充数据长度:%2X", buf.Bytes())
+	buf := bytes.NewBuffer(gbinary.BeEncodeUint16(gconv.Uint16(params.Offset)))
 
-	buf.Write(byteCmd)
-	server.Log.Infof("2----------填充响应数据:%2X", buf.Bytes())
 	var fileArgs rpcs.ArgsOtaFile
 	fileArgs.FileId = params.FileId
 
 	var fileReply rpcs.ReplyOtaFile
-	err = server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.GetFile", fileArgs, &fileReply)
+	err := server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.GetFile", fileArgs, &fileReply)
 	if err != nil {
 		server.Log.Errorf("OTA升级文件保存失败:%v", err)
 		return err
@@ -346,12 +321,12 @@ func (a *Access) chunkUpgrade(params rpcs.ChunkUpgrade) error {
 	if fileReply.File == nil {
 		return errors.New(fmt.Sprintf("文件:%s 获取失败", params.FileId))
 	}
-	buf.Write(fileReply.File[params.Offset : params.Offset+int(params.Size)])
-	server.Log.Infof("3----------填充文件:%2X", buf.Bytes())
+	buf.Write(fileReply.File[params.Offset*int(params.Size) : (params.Offset+1)+int(params.Size)])
+	server.Log.Infof("1----------填充文件:%2X", buf.Bytes())
 	var mCrc crc
 	checkSum := mCrc.reset().pushBytes(buf.Bytes()).value()
 	buf.Write([]byte{byte(checkSum), byte(checkSum >> 8)})
-	server.Log.Infof("4----------填充CRC:%2X", buf.Bytes())
+	server.Log.Infof("2----------填充CRC:%2X", buf.Bytes())
 	var SendByteArgs rpcs.ArgsSendByteData
 	SendByteArgs.DeviceId = params.DeviceId
 	SendByteArgs.Data = buf.Bytes()