|
|
@@ -17,6 +17,7 @@ const (
|
|
|
|
|
|
func StartMCUUpgrade() error {
|
|
|
fwPath := filepath.Join(baseapp.VAR_DIR, DefaultSendFileName)
|
|
|
+ defer os.Remove(fwPath)
|
|
|
|
|
|
info, err := os.Stat(fwPath)
|
|
|
if err != nil {
|
|
|
@@ -31,6 +32,7 @@ func StartMCUUpgrade() error {
|
|
|
|
|
|
fwSize := info.Size()
|
|
|
startTime := time.Now()
|
|
|
+ upgradeOK := false
|
|
|
|
|
|
baseapp.Logger.Warnf("====[ MCU UPGRADE PREPARE ]==== [%s] stop MCU communication", MODULE_NAME)
|
|
|
ModuleExit() // 先退出MCU控制板的通信
|
|
|
@@ -43,17 +45,21 @@ func StartMCUUpgrade() error {
|
|
|
|
|
|
bytes := ymodem.Send_file(fwPath) // 使用ymodem发送升级文件
|
|
|
if bytes > 0 && bytes == int(fwSize) {
|
|
|
- baseapp.Logger.Warnf("====[ MCU UPGRADE SUCCESS ]====, %d bytes written", bytes)
|
|
|
- } else {
|
|
|
- baseapp.Logger.Errorf("!!!![ MCU UPGRADE FAILED ]!!!!, written=%dBytes, expect=%dBytes", bytes, fwSize)
|
|
|
+ upgradeOK = true
|
|
|
+ }
|
|
|
+
|
|
|
+ if ok := ModuleInit(Board.ExtInfo); !ok { /// 重新打开串口
|
|
|
+ return errors.New("mcu serial open failed")
|
|
|
}
|
|
|
|
|
|
elapsed := time.Since(startTime)
|
|
|
- baseapp.Logger.Warnf("====[ MCU UPGRADE SUCCESS ]====, 用时: %v", elapsed) // 成功
|
|
|
|
|
|
- if ok := ModuleInit(Board.ExtInfo); !ok {
|
|
|
- return errors.New("mcu serial open failed")
|
|
|
+ if !upgradeOK {
|
|
|
+ baseapp.Logger.Errorf("!!!![ MCU UPGRADE FAILED ]!!!!, written=%dBytes, expect=%dBytes", bytes, fwSize)
|
|
|
+ return fmt.Errorf("MCU firmware upgrade failed, written=%dBytes, expect=%dBytes", bytes, fwSize)
|
|
|
}
|
|
|
|
|
|
+ baseapp.Logger.Warnf("====[ MCU UPGRADE SUCCESS ]====, 用时: %v", elapsed) //成功
|
|
|
+
|
|
|
return nil
|
|
|
}
|