支持ota升级结果相应处理
This commit is contained in:
@@ -57,9 +57,7 @@ func (l *loraListener) HandleInstruction(upstreamCtx context.Context, sourceAddr
|
||||
return l.handleCollectResult(ctx, sourceAddr, p.CollectResult)
|
||||
|
||||
case *proto.Instruction_OtaUpgradeStatus:
|
||||
logger.Infow("收到OTA升级状态,暂未实现处理逻辑", "来源地址", sourceAddr, "状态", p.OtaUpgradeStatus)
|
||||
// TODO: 在这里实现OTA升级状态的处理逻辑
|
||||
return nil
|
||||
return l.handleOtaStatus(ctx, sourceAddr, p.OtaUpgradeStatus)
|
||||
|
||||
case *proto.Instruction_LogUploadRequest:
|
||||
logger.Infow("收到设备日志上传请求,暂未实现处理逻辑", "来源地址", sourceAddr, "日志条数", len(p.LogUploadRequest.Entries))
|
||||
@@ -275,3 +273,35 @@ func (l *loraListener) recordSensorData(ctx context.Context, areaControllerID ui
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// handleOtaStatus 处理设备上报的OTA升级状态。
|
||||
func (l *loraListener) handleOtaStatus(ctx context.Context, sourceAddr string, status *proto.OtaUpgradeStatus) error {
|
||||
reqCtx, logger := logs.Trace(ctx, l.selfCtx, "handleOtaStatus")
|
||||
logger.Infow("开始处理OTA升级状态",
|
||||
"来源地址", sourceAddr,
|
||||
"状态码", status.StatusCode,
|
||||
"处理结果", status.StatusCode == 0,
|
||||
"当前版本", status.CurrentFirmwareVersion,
|
||||
)
|
||||
|
||||
// 1. 查找区域主控
|
||||
areaController, err := l.areaControllerRepo.FindByNetworkID(reqCtx, sourceAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("处理OTA状态失败:无法找到区域主控: %w", err)
|
||||
}
|
||||
|
||||
// 2. 更新固件版本号
|
||||
// 我们信任设备上报的版本号,无论成功失败都进行更新
|
||||
if status.CurrentFirmwareVersion != "" {
|
||||
err = l.areaControllerRepo.UpdateFirmwareVersion(reqCtx, areaController.ID, status.CurrentFirmwareVersion)
|
||||
if err != nil {
|
||||
logger.Errorw("更新区域主控固件版本号失败", "主控ID", areaController.ID, "error", err)
|
||||
return fmt.Errorf("更新固件版本号失败: %w", err)
|
||||
}
|
||||
logger.Infow("成功更新区域主控固件版本号", "主控ID", areaController.ID, "新版本", status.CurrentFirmwareVersion)
|
||||
}
|
||||
|
||||
// TODO: 后续可以在这里增加逻辑,比如记录一条操作日志,或者发送一个通知
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user