浏览代码

update ota

liuxiulin 7 月之前
父节点
当前提交
afd5dba37a
共有 2 个文件被更改,包括 12 次插入3 次删除
  1. 2 2
      pkg/deviceStatus/deviceStatus.go
  2. 10 1
      services/emqx-agent/agent.go

+ 2 - 2
pkg/deviceStatus/deviceStatus.go

@@ -5,8 +5,8 @@ import (
 )
 
 const (
-	StatusKeyPrefix = "status:device:"
-	InfoKeyPrefix   = "info:device:"
+	StatusKeyPrefix = "device:status"
+	InfoKeyPrefix   = "device:info"
 	dataExpires     = 7200
 )
 

+ 10 - 1
services/emqx-agent/agent.go

@@ -321,7 +321,16 @@ 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*int(params.Size) : (params.Offset+1)+int(params.Size)])
+	start := params.Offset * int(params.Size)
+	stop := (params.Offset + 1) + int(params.Size)
+	if stop >= len(fileArgs.FileData) {
+		stop = len(fileArgs.FileData)
+	}
+	data := fileReply.File[start:stop]
+	buf.Write(gbinary.BeEncodeUint16(gconv.Uint16(len(data))))
+	buf.Write(data)
+	// 生成随机的4位数字
+	//randomNumber := rand.Intn(9000) + 1000
 	server.Log.Infof("1----------填充文件:%2X", buf.Bytes())
 	var mCrc crc
 	checkSum := mCrc.reset().pushBytes(buf.Bytes()).value()