|
|
@@ -16,58 +16,70 @@ func StartMCUUpgrade(filePath string) error {
|
|
|
return fmt.Errorf("upgrade busy")
|
|
|
}
|
|
|
|
|
|
- defer func() {
|
|
|
- os.Remove(filePath) /////// 升级完成后删除
|
|
|
- Board.upgradeMu.Unlock()
|
|
|
- }()
|
|
|
+ go func() {
|
|
|
+ defer func() {
|
|
|
+ os.Remove(filePath) // 升级完成后删除文件
|
|
|
+ Board.upgradeMu.Unlock()
|
|
|
+ }()
|
|
|
|
|
|
- info, err := os.Stat(filePath)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- if !info.Mode().IsRegular() {
|
|
|
- return fmt.Errorf("升级文件无效: %s", filePath)
|
|
|
- }
|
|
|
- if info.Size() <= 0 {
|
|
|
- return fmt.Errorf("升级文件为空: %s", filePath)
|
|
|
- }
|
|
|
+ utils.PlayAudioAsync(filepath.Join(baseapp.EXEC_DIR, "voices",
|
|
|
+ "startupdate.wav")) //// 播报开始升级语音
|
|
|
+
|
|
|
+ startTime := time.Now()
|
|
|
+ baseapp.Logger.Warnf("##########################################################")
|
|
|
+ baseapp.Logger.Warnf("############# MCU FIRMWARE UPGRADE START #############")
|
|
|
+ baseapp.Logger.Warnf("##########################################################")
|
|
|
+
|
|
|
+ info, err := os.Stat(filePath)
|
|
|
+ if err != nil {
|
|
|
+ baseapp.Logger.Errorf("!!!![ MCU UPGRADE FAILED ]!!!!, %v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !info.Mode().IsRegular() {
|
|
|
+ baseapp.Logger.Errorf("!!!![ MCU UPGRADE FAILED ]!!!!, 升级文件无效: %s", filePath)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if info.Size() <= 0 {
|
|
|
+ baseapp.Logger.Errorf("!!!![ MCU UPGRADE FAILED ]!!!!, 升级文件为空: %s", filePath)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- fileSize := info.Size()
|
|
|
- startTime := time.Now()
|
|
|
+ fileSize := info.Size()
|
|
|
+ baseapp.Logger.Warnf("====[ MCU UPGRADE FILE ]====, file=%s, size=%dBytes", filePath, fileSize)
|
|
|
|
|
|
- Board.uartUseMu.Lock()
|
|
|
- defer Board.uartUseMu.Unlock()
|
|
|
+ Board.uartUseMu.Lock()
|
|
|
+ defer Board.uartUseMu.Unlock()
|
|
|
|
|
|
- mcuCtrlBoard_ComExit() /////////////// 1-关闭与控制板的串口通信
|
|
|
- time.Sleep(100 * time.Millisecond)
|
|
|
+ time.Sleep(100 * time.Millisecond)
|
|
|
+ mcuCtrlBoard_ComExit() /////////////// 1-关闭与控制板的串口通信
|
|
|
+ time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
- utils.PlayAudioAsync(filepath.Join(baseapp.EXEC_DIR, "voices",
|
|
|
- "startupdate.wav")) ////// 播报开始升级语音
|
|
|
- baseapp.Logger.Warnf("##########################################################")
|
|
|
- baseapp.Logger.Warnf("############# MCU FIRMWARE UPGRADE START #############")
|
|
|
- baseapp.Logger.Warnf("##########################################################")
|
|
|
- baseapp.Logger.Warnf("====[ MCU UPGRADE FILE ]====, file=%s, size=%dBytes", filePath, fileSize)
|
|
|
+ baseapp.Logger.Warn("====[ MCU UPGRADING... ]====")
|
|
|
+ size := ymodem.Send_file(filePath) /// 2-使用ymodem发送升级文件
|
|
|
+ if size <= 0 || size != int(fileSize) {
|
|
|
+ utils.PlayAudioAsync(filepath.Join(baseapp.EXEC_DIR, "voices",
|
|
|
+ "updatefailed.wav")) /// 播报升级失败语音
|
|
|
+ baseapp.Logger.Errorf("!!!![ MCU UPGRADE FAILED ]!!!!, written=%dBytes, expect=%dBytes", size, fileSize)
|
|
|
+ } else {
|
|
|
+ utils.PlayAudioAsync(filepath.Join(baseapp.EXEC_DIR, "voices",
|
|
|
+ "updatesuccess.wav")) // 播报升级成功语音
|
|
|
+ baseapp.Logger.Warnf("====[ MCU UPGRADE SUCCESS ]====, 用时: %v", time.Since(startTime)) ////////// 成功
|
|
|
+ }
|
|
|
|
|
|
- size := ymodem.Send_file(filePath) /// 2-使用ymodem发送升级文件
|
|
|
- if size <= 0 || size != int(fileSize) {
|
|
|
- utils.PlayAudioAsync(filepath.Join(baseapp.EXEC_DIR, "voices",
|
|
|
- "updatefailed.wav")) /// 播报升级失败语音
|
|
|
- baseapp.Logger.Errorf("!!!![ MCU UPGRADE FAILED ]!!!!, written=%dBytes, expect=%dBytes", size, fileSize)
|
|
|
- } else {
|
|
|
- utils.PlayAudioAsync(filepath.Join(baseapp.EXEC_DIR, "voices",
|
|
|
- "updatesuccess.wav")) // 播报升级成功语音
|
|
|
- baseapp.Logger.Warnf("====[ MCU UPGRADE SUCCESS ]====, 用时: %v", time.Since(startTime)) ////////// 成功
|
|
|
- }
|
|
|
+ for range 3 { ////////// 3-升级结束后,重新打开与控制板的串口通信
|
|
|
+ _, err = mcuCtrlBoard_ComInit()
|
|
|
+ if err == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- for range 3 { ////////// 3-升级结束后,重新打开与控制板的串口通信
|
|
|
- _, err = mcuCtrlBoard_ComInit()
|
|
|
- if err == nil {
|
|
|
- return nil
|
|
|
+ mcuCtrlBoard_ComExit()
|
|
|
+ time.Sleep(time.Second)
|
|
|
}
|
|
|
|
|
|
- mcuCtrlBoard_ComExit()
|
|
|
- time.Sleep(time.Second)
|
|
|
- }
|
|
|
+ baseapp.Logger.Errorf("[%s] 打开与MCU控制板通信的串口失败: %v!!",
|
|
|
+ MODULE_NAME, err)
|
|
|
+ os.Exit(1)
|
|
|
+ }()
|
|
|
|
|
|
- return fmt.Errorf("failed to reopen MCU serial port: %w", err)
|
|
|
+ return nil
|
|
|
}
|