LingxinMeng 10 months ago
parent
commit
827d4ed54d
2 changed files with 11 additions and 8 deletions
  1. 10 7
      aarch64/pjisuv/master/config/master_trigger_config.go
  2. 1 1
      common/util/u_io.go

+ 10 - 7
aarch64/pjisuv/master/config/master_trigger_config.go

@@ -183,7 +183,7 @@ var (
 func InitTriggerConfig() {
 	c_log.GlobalLogger.Info("主节点加载触发器插件 - 开始。")
 	var triggerLocalPaths []string
-	if config.CloudConfig.TriggersOnline {
+	if config.CloudConfig.TriggersOnline { // 在线方案
 		for _, trigger := range config.PlatformConfig.TaskTriggers {
 			triggerLocalPath := config.CloudConfig.TriggersDir + trigger.TriggerScriptPath
 			_ = util.CreateParentDir(triggerLocalPath)
@@ -197,16 +197,19 @@ func InitTriggerConfig() {
 			c_log.GlobalLogger.Info("下载触发器插件从 ", trigger.TriggerScriptPath, " 到 ", triggerLocalPath)
 			triggerLocalPaths = append(triggerLocalPaths, triggerLocalPath)
 		}
-	} else {
+	} else { // 离线方案
 		triggerLocalPaths = util.GetSoFilePaths(config.CloudConfig.TriggersDir)
+		// 绑定 triggerId 和 triggerLabel
 		for _, path := range triggerLocalPaths {
-			LabelMapTriggerId.Store(util.get, strconv.Itoa(trigger.TriggerId))
+			name1 := util.GetFileNameWithoutExtension(path)
+			for _, trigger := range config.PlatformConfig.TaskTriggers {
+				name2 := util.GetFileNameWithoutExtension(config.CloudConfig.TriggersDir + trigger.TriggerScriptPath)
+				if name1 == name2 {
+					LabelMapTriggerId.Store(name1, strconv.Itoa(trigger.TriggerId))
+				}
+			}
 		}
 	}
-	for _, trigger := range config.PlatformConfig.TaskTriggers {
-		LabelMapTriggerId.Store(labelString, strconv.Itoa(trigger.TriggerId))
-		c_log.GlobalLogger.Info("主节点加载触发器插件:【ros topic】=", topic2, ",【触发器label】=", labelString, "【触发器ID】=", trigger.TriggerId)
-	}
 	// 下载所有触发器的文件
 	for _, triggerLocalPath := range triggerLocalPaths {
 		// 载入插件到数组

+ 1 - 1
common/util/u_io.go

@@ -9,7 +9,7 @@ import (
 	"strings"
 )
 
-func getFileNameWithoutExtension(absPath string) string {
+func GetFileNameWithoutExtension(absPath string) string {
 	file := filepath.Base(absPath)
 	ext := filepath.Ext(file)
 	return strings.TrimSuffix(file, ext)