|
|
@@ -3,21 +3,21 @@ package mcu_ctrl_board
|
|
|
import (
|
|
|
"fmt"
|
|
|
"os"
|
|
|
- "path/filepath"
|
|
|
"time"
|
|
|
|
|
|
"hnyfkj.com.cn/rtu/linux/baseapp"
|
|
|
"hnyfkj.com.cn/rtu/linux/ymodem"
|
|
|
)
|
|
|
|
|
|
-func StartMCUUpgrade() error {
|
|
|
+func StartMCUUpgrade(filePath string) error {
|
|
|
if !Board.upgradeMu.TryLock() {
|
|
|
return fmt.Errorf("upgrade busy")
|
|
|
}
|
|
|
- defer Board.upgradeMu.Unlock()
|
|
|
|
|
|
- filePath := filepath.Join(baseapp.VAR_DIR, "mcu_firmware.rbl")
|
|
|
- defer os.Remove(filePath) //升级完成后删除升级文件
|
|
|
+ defer func() {
|
|
|
+ os.Remove(filePath) /////// 升级完成后删除
|
|
|
+ Board.upgradeMu.Unlock()
|
|
|
+ }()
|
|
|
|
|
|
info, err := os.Stat(filePath)
|
|
|
if err != nil {
|
|
|
@@ -44,7 +44,7 @@ func StartMCUUpgrade() error {
|
|
|
baseapp.Logger.Warnf("##########################################################")
|
|
|
baseapp.Logger.Warnf("====[ MCU UPGRADE FILE ]====, file=%s, size=%dBytes", filePath, fileSize)
|
|
|
|
|
|
- size := ymodem.Send_file(filePath) // 2-使用ymodem发送升级文件
|
|
|
+ size := ymodem.Send_file(filePath) /// 2-使用ymodem发送升级文件
|
|
|
if size <= 0 || size != int(fileSize) {
|
|
|
baseapp.Logger.Errorf("!!!![ MCU UPGRADE FAILED ]!!!!, written=%dBytes, expect=%dBytes", size, fileSize)
|
|
|
} else {
|