|
@@ -94,7 +94,7 @@ func (a *Access) processStatus(topicInfo *protocol.TopicInfo, vendorId string, m
|
|
|
case klink.ReportFirmwareAction:
|
|
|
_ = processDeviceReportUpgrade(topicInfo.DeviceCode, message.GetString("version"))
|
|
|
case klink.DevUpgradeAction:
|
|
|
- _ = processDeviceUpgrade(topicInfo.DeviceCode, message)
|
|
|
+ _ = a.processDeviceUpgrade(topicInfo.DeviceCode, message)
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
@@ -171,7 +171,7 @@ func processReportStatus(topicInfo *protocol.TopicInfo, vendorId string, message
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func processDeviceUpgrade(deviceId string, message *gjson.Json) error {
|
|
|
+func (a *Access) processDeviceUpgrade(deviceId string, message *gjson.Json) error {
|
|
|
var reply rpcs.ReplyEmptyResult
|
|
|
data := gjson.New(message.GetJson("data").MustToJson())
|
|
|
switch data.GetString("cmd") {
|
|
@@ -185,7 +185,7 @@ func processDeviceUpgrade(deviceId string, message *gjson.Json) error {
|
|
|
Size: params.GetInt64("size"),
|
|
|
Offset: params.GetInt("offset"),
|
|
|
}
|
|
|
- err := chunkUpgrade(*args)
|
|
|
+ err := a.chunkUpgrade(*args)
|
|
|
if err != nil {
|
|
|
server.Log.Errorf("分片下载发送失败:%v", err)
|
|
|
}
|
|
@@ -305,9 +305,8 @@ func (a *Access) GetStatus(args rpcs.ArgsGetStatus, reply *rpcs.ReplyGetStatus)
|
|
|
return a.SendCommand(cmdArgs, &cmdReply)
|
|
|
}
|
|
|
|
|
|
-func chunkUpgrade(params rpcs.ChunkUpgrade) error {
|
|
|
+func (a *Access) chunkUpgrade(params rpcs.ChunkUpgrade) error {
|
|
|
server.Log.Infof("4G模组OTA升级:%s", params.DeviceId)
|
|
|
- reply := new(rpcs.ReplyEmptyResult)
|
|
|
cmd := &klink.CloudSend{
|
|
|
Action: "cloudSend",
|
|
|
MsgId: 0,
|
|
@@ -344,7 +343,6 @@ func chunkUpgrade(params rpcs.ChunkUpgrade) error {
|
|
|
server.Log.Errorf("OTA升级文件保存失败:%v", err)
|
|
|
return err
|
|
|
}
|
|
|
- server.Log.Infof("获取到OTA文件:%v", fileReply)
|
|
|
if fileReply.File == nil {
|
|
|
return errors.New(fmt.Sprintf("文件:%s 获取失败", params.FileId))
|
|
|
}
|
|
@@ -357,7 +355,8 @@ func chunkUpgrade(params rpcs.ChunkUpgrade) error {
|
|
|
var SendByteArgs rpcs.ArgsSendByteData
|
|
|
SendByteArgs.DeviceId = params.DeviceId
|
|
|
SendByteArgs.Data = buf.Bytes()
|
|
|
- err = server.RPCCallByName(nil, rpcs.EmqxAgentServiceName, "Access.SendByteData", SendByteArgs, &reply)
|
|
|
+ replay := new(rpcs.ReplySendCommand)
|
|
|
+ err = a.SendByteData(SendByteArgs, replay)
|
|
|
|
|
|
return nil
|
|
|
}
|
|
@@ -369,13 +368,13 @@ func (a *Access) SendByteData(args rpcs.ArgsSendByteData, reply *rpcs.ReplySendC
|
|
|
err := server.RPCCallByName(nil, rpcs.RegistryServerName, "Registry.FindDeviceByIdentifier", args.DeviceId, device)
|
|
|
if err != nil {
|
|
|
server.Log.Errorf("device not found %s", args.DeviceId)
|
|
|
- return nil
|
|
|
+ return err
|
|
|
}
|
|
|
product := &models.Product{}
|
|
|
err = server.RPCCallByName(nil, rpcs.RegistryServerName, "Registry.FindProduct", device.ProductID, product)
|
|
|
if err != nil {
|
|
|
server.Log.Errorf("device not found %s", args.DeviceId)
|
|
|
- return nil
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
return a.client.PublishToMsgToDev(protocol.GetCommandTopic(args.DeviceId, product.ProductKey), args.Data)
|