|
@@ -3,7 +3,6 @@ package main
|
|
import (
|
|
import (
|
|
"bytes"
|
|
"bytes"
|
|
"context"
|
|
"context"
|
|
- "encoding/json"
|
|
|
|
"errors"
|
|
"errors"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/gogf/gf/encoding/gjson"
|
|
"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 {
|
|
func (a *Access) chunkUpgrade(params rpcs.ChunkUpgrade) error {
|
|
server.Log.Infof("4G模组OTA升级:%s", params.DeviceId)
|
|
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
|
|
var fileArgs rpcs.ArgsOtaFile
|
|
fileArgs.FileId = params.FileId
|
|
fileArgs.FileId = params.FileId
|
|
|
|
|
|
var fileReply rpcs.ReplyOtaFile
|
|
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 {
|
|
if err != nil {
|
|
server.Log.Errorf("OTA升级文件保存失败:%v", err)
|
|
server.Log.Errorf("OTA升级文件保存失败:%v", err)
|
|
return err
|
|
return err
|
|
@@ -346,12 +321,12 @@ func (a *Access) chunkUpgrade(params rpcs.ChunkUpgrade) error {
|
|
if fileReply.File == nil {
|
|
if fileReply.File == nil {
|
|
return errors.New(fmt.Sprintf("文件:%s 获取失败", params.FileId))
|
|
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
|
|
var mCrc crc
|
|
checkSum := mCrc.reset().pushBytes(buf.Bytes()).value()
|
|
checkSum := mCrc.reset().pushBytes(buf.Bytes()).value()
|
|
buf.Write([]byte{byte(checkSum), byte(checkSum >> 8)})
|
|
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
|
|
var SendByteArgs rpcs.ArgsSendByteData
|
|
SendByteArgs.DeviceId = params.DeviceId
|
|
SendByteArgs.DeviceId = params.DeviceId
|
|
SendByteArgs.Data = buf.Bytes()
|
|
SendByteArgs.Data = buf.Bytes()
|