孟令鑫 1 рік тому
батько
коміт
2fbbedf28f

+ 20 - 20
aarch64/kinglong/common/config/c_cloud.go

@@ -15,10 +15,11 @@ type platform struct {
 	UrlTask       string `yaml:"url-task"`
 }
 
-type host struct {
-	Name   string   `yaml:"name"`
-	Ip     string   `yaml:"ip"`
-	Topics []string `yaml:"topics"`
+type hostStruct struct {
+	Name       string   `yaml:"name"`
+	Ip         string   `yaml:"ip"`
+	Topics     []string `yaml:"topics"`
+	RecordEnvs []string `yaml:"record-envs"`
 }
 type ros struct {
 	MasterAddress string   `yaml:"master-address"`
@@ -34,22 +35,21 @@ type trigger struct {
 	Topics []string `yaml:"topics"`
 }
 type cloudConfig struct {
-	FullCollect           bool      `yaml:"full-collect"`
-	ConfigRefreshInterval int       `yaml:"config-refresh-interval"` // 配置刷新时间间隔
-	BagNumber             int       `yaml:"bag-number"`
-	TimeWindowSendGap     int       `yaml:"time-window-send-gap"` // 主节点向从节点发送窗口的最小时间间隔
-	TimeToLabelJsonPath   string    `yaml:"time-to-label-json-path"`
-	BagDataDir            string    `yaml:"bag-data-dir"`
-	BagCopyDir            string    `yaml:"bag-copy-dir"`
-	TriggersDir           string    `yaml:"triggers-dir"`
-	TcpPort               string    `yaml:"tcp-port"`
-	RpcPort               string    `yaml:"rpc-port"`
-	RecordEnvs            []string  `yaml:"record-envs"`
-	Triggers              []trigger `yaml:"triggers"`
-	Hosts                 []host    `yaml:"hosts"`
-	Ros                   ros       `yaml:"ros"`
-	Platform              platform  `yaml:"platform"`
-	Disk                  disk      `yaml:"disk"`
+	FullCollect           bool         `yaml:"full-collect"`
+	ConfigRefreshInterval int          `yaml:"config-refresh-interval"` // 配置刷新时间间隔
+	BagNumber             int          `yaml:"bag-number"`
+	TimeWindowSendGap     int          `yaml:"time-window-send-gap"` // 主节点向从节点发送窗口的最小时间间隔
+	TimeToLabelJsonPath   string       `yaml:"time-to-label-json-path"`
+	BagDataDir            string       `yaml:"bag-data-dir"`
+	BagCopyDir            string       `yaml:"bag-copy-dir"`
+	TriggersDir           string       `yaml:"triggers-dir"`
+	TcpPort               string       `yaml:"tcp-port"`
+	RpcPort               string       `yaml:"rpc-port"`
+	Triggers              []trigger    `yaml:"triggers"`
+	Hosts                 []hostStruct `yaml:"hosts"`
+	Ros                   ros          `yaml:"ros"`
+	Platform              platform     `yaml:"platform"`
+	Disk                  disk         `yaml:"disk"`
 }
 
 var (

+ 13 - 1
aarch64/kinglong/common/config/c_ros.go

@@ -7,7 +7,10 @@ import (
 	"os"
 )
 
-var RosNode *goroslib.Node
+var (
+	RosNode *goroslib.Node
+	RosEnv  []string
+)
 
 func InitRosConfig() {
 	c_log.GlobalLogger.Info("初始化RosNode - 开始")
@@ -21,4 +24,13 @@ func InitRosConfig() {
 		os.Exit(-1)
 	}
 	c_log.GlobalLogger.Info("初始化RosNode - 成功:", CloudConfig.Ros.MasterAddress)
+	// 获取 record 命令环境变量
+	for _, host := range CloudConfig.Hosts {
+		if host.Name == LocalConfig.Node.Name {
+			RosEnv = host.RecordEnvs
+			break
+		}
+	}
+	c_log.GlobalLogger.Info("ros 环境变量为:", RosEnv)
+
 }

+ 4 - 3
aarch64/kinglong/common/config/yaml/cloud-config-v2253.yaml

@@ -16,8 +16,6 @@ triggers-dir: /mnt/media/sda1/rosbag-handle/triggers/
 time-window-send-gap: 6
 tcp-port: 12340
 rpc-port: 12341
-record-envs:
-  - ""
 ros:
   master-address: 192.168.1.102:11311
   nodes:
@@ -81,6 +79,8 @@ hosts:
       - /AutoModeStatus
       - /heartbeat_info
       - /data_read
+    record-envs:
+      - ""
   - name: node2
     ip: 192.168.1.103
     topics:
@@ -94,7 +94,8 @@ hosts:
       - /points_concat
       - /tpperception
       - /tpperception/hmi
-      -
+    record-envs:
+      - ""
 triggers:
   - label: rapidaccel
     topics:

+ 0 - 2
aarch64/kinglong/common/config/yaml/cloud-config-v2304.yaml

@@ -16,8 +16,6 @@ triggers-dir: /mnt/media/sda1/rosbag-handle/triggers/
 time-window-send-gap: 6
 tcp-port: 12340
 rpc-port: 12341
-record-envs:
-  - ""
 ros:
   master-address: 192.168.1.102:11311
   nodes:

+ 1 - 1
aarch64/kinglong/common/config/yaml/local-config-soc1.yaml

@@ -1,5 +1,5 @@
 node:
-  name: master
+  name: node1
   ip: 192.168.1.102
 # 数据闭环平台参数
 equipment-no: kinglong3

+ 1 - 1
aarch64/kinglong/common/config/yaml/local-config-soc2.yaml

@@ -1,5 +1,5 @@
 node:
-  name: slave
+  name: node2
   ip: 192.168.1.103
 # 数据闭环平台参数
 equipment-no: kinglong3

+ 1 - 2
aarch64/kinglong/common/service/rosbag_record.go

@@ -5,7 +5,6 @@ import (
 	"cicv-data-closedloop/common/config/c_log"
 	"cicv-data-closedloop/common/util"
 	"github.com/bluenviron/goroslib/v2"
-	"os"
 	"time"
 )
 
@@ -37,7 +36,7 @@ func BagRecord(nodeName string) {
 		// 不在此处压缩,因为 rosbag filter 时会报错。在上传到oss之前压缩即可。
 		// 包名格式:2023-11-15-17-35-20_0.bag
 		_ = util.CreateParentDir(config.CloudConfig.BagDataDir)
-		cmd, err := util.ExecuteWithEnvAndDirAsync(os.Environ(), config.CloudConfig.BagDataDir, "rosbag", command...)
+		cmd, err := util.ExecuteWithEnvAndDirAsync(config.RosEnv, config.CloudConfig.BagDataDir, "rosbag", command...)
 		if err != nil {
 			c_log.GlobalLogger.Error("执行record命令", command, "出错:", err)
 			continue

+ 2 - 2
aarch64/kinglong/common/service/rosbag_upload.go

@@ -70,7 +70,7 @@ outLoop:
 				oldName := bag
 				newName := bag + "_filter"
 				filterCommand := []string{"filter", oldName, newName, "\"" + strings.Join(topicsFilterSlice, " or ") + "\""}
-				_, output, err := commonUtil.ExecuteWithEnvSync(os.Environ(), "rosbag", filterCommand...)
+				_, output, err := commonUtil.ExecuteWithEnvSync(commonConfig.RosEnv, "rosbag", filterCommand...)
 				c_log.GlobalLogger.Info("正在过滤中,【FaultTime】=", currentTimeWindow.FaultTime, "【Label】=", currentTimeWindow.Labels, ",进度", i+1, "/", bagNumber, "。")
 				if err != nil {
 					c_log.GlobalLogger.Errorf("filter 命令执行出错【命令】=%v,【输出】=%v,【err】=%v", filterCommand, output, err)
@@ -92,7 +92,7 @@ outLoop:
 			oldName := bag
 			compressCommand := []string{"compress", "--bz2", oldName}
 			c_log.GlobalLogger.Info("正在压缩中,【FaultTime】=", currentTimeWindow.FaultTime, "【Label】=", currentTimeWindow.Labels, ",进度", i+1, "/", bagNumber, "。")
-			if _, output, err := commonUtil.ExecuteWithEnvSync(os.Environ(), "rosbag", compressCommand...); err != nil {
+			if _, output, err := commonUtil.ExecuteWithEnvSync(commonConfig.RosEnv, "rosbag", compressCommand...); err != nil {
 				c_log.GlobalLogger.Errorf("compress 命令执行出错【命令】=%v,【输出】=%v,【err】=%v", compressCommand, output, err)
 				continue
 			}

+ 15 - 15
aarch64/pji/common/config/c_cloud.go

@@ -15,7 +15,7 @@ type platform struct {
 	UrlTask       string `yaml:"url-task"`
 }
 
-type host struct {
+type hostStruct struct {
 	Name   string   `yaml:"name"`
 	Ip     string   `yaml:"ip"`
 	Topics []string `yaml:"topics"`
@@ -35,20 +35,20 @@ type trigger struct {
 }
 
 type cloudConfig struct {
-	FullCollect           bool      `yaml:"full-collect"`
-	ConfigRefreshInterval int       `yaml:"config-refresh-interval"` // 配置刷新时间间隔
-	BagNumber             int       `yaml:"bag-number"`
-	TimeWindowSendGap     int       `yaml:"time-window-send-gap"` // 主节点向从节点发送窗口的最小时间间隔
-	BagDataDir            string    `yaml:"bag-data-dir"`
-	BagCopyDir            string    `yaml:"bag-copy-dir"`
-	TriggersDir           string    `yaml:"triggers-dir"`
-	RpcPort               string    `yaml:"rpc-port"`
-	RecordEnvs            []string  `yaml:"record-envs"`
-	Triggers              []trigger `yaml:"triggers"`
-	Hosts                 []host    `yaml:"hosts"`
-	Ros                   ros       `yaml:"ros"`
-	Platform              platform  `yaml:"platform"`
-	Disk                  disk      `yaml:"disk"`
+	FullCollect           bool         `yaml:"full-collect"`
+	ConfigRefreshInterval int          `yaml:"config-refresh-interval"` // 配置刷新时间间隔
+	BagNumber             int          `yaml:"bag-number"`
+	TimeWindowSendGap     int          `yaml:"time-window-send-gap"` // 主节点向从节点发送窗口的最小时间间隔
+	BagDataDir            string       `yaml:"bag-data-dir"`
+	BagCopyDir            string       `yaml:"bag-copy-dir"`
+	TriggersDir           string       `yaml:"triggers-dir"`
+	RpcPort               string       `yaml:"rpc-port"`
+	RecordEnvs            []string     `yaml:"record-envs"`
+	Triggers              []trigger    `yaml:"triggers"`
+	Hosts                 []hostStruct `yaml:"hosts"`
+	Ros                   ros          `yaml:"ros"`
+	Platform              platform     `yaml:"platform"`
+	Disk                  disk         `yaml:"disk"`
 }
 
 var (

+ 16 - 16
aarch64/pjisuv/common/config/c_cloud.go

@@ -15,7 +15,7 @@ type platform struct {
 	UrlTask       string `yaml:"url-task"`
 }
 
-type host struct {
+type hostStruct struct {
 	Name       string   `yaml:"name"`
 	Ip         string   `yaml:"ip"`
 	Topics     []string `yaml:"topics"`
@@ -36,21 +36,21 @@ type trigger struct {
 }
 
 type cloudConfig struct {
-	FullCollect           bool      `yaml:"full-collect"`
-	ConfigRefreshInterval int       `yaml:"config-refresh-interval"` // 配置刷新时间间隔
-	BagNumber             int       `yaml:"bag-number"`
-	TimeWindowSendGap     int       `yaml:"time-window-send-gap"` // 主节点向从节点发送窗口的最小时间间隔
-	TimeToLabelJsonPath   string    `yaml:"time-to-label-json-path"`
-	BagDataDir            string    `yaml:"bag-data-dir"`
-	BagCopyDir            string    `yaml:"bag-copy-dir"`
-	TriggersDir           string    `yaml:"triggers-dir"`
-	TcpPort               string    `yaml:"tcp-port"`
-	RpcPort               string    `yaml:"rpc-port"`
-	Triggers              []trigger `yaml:"triggers"`
-	Hosts                 []host    `yaml:"hosts"`
-	Ros                   ros       `yaml:"ros"`
-	Platform              platform  `yaml:"platform"`
-	Disk                  disk      `yaml:"disk"`
+	FullCollect           bool         `yaml:"full-collect"`
+	ConfigRefreshInterval int          `yaml:"config-refresh-interval"` // 配置刷新时间间隔
+	BagNumber             int          `yaml:"bag-number"`
+	TimeWindowSendGap     int          `yaml:"time-window-send-gap"` // 主节点向从节点发送窗口的最小时间间隔
+	TimeToLabelJsonPath   string       `yaml:"time-to-label-json-path"`
+	BagDataDir            string       `yaml:"bag-data-dir"`
+	BagCopyDir            string       `yaml:"bag-copy-dir"`
+	TriggersDir           string       `yaml:"triggers-dir"`
+	TcpPort               string       `yaml:"tcp-port"`
+	RpcPort               string       `yaml:"rpc-port"`
+	Triggers              []trigger    `yaml:"triggers"`
+	Hosts                 []hostStruct `yaml:"hosts"`
+	Ros                   ros          `yaml:"ros"`
+	Platform              platform     `yaml:"platform"`
+	Disk                  disk         `yaml:"disk"`
 }
 
 var (

+ 13 - 1
aarch64/pjisuv/common/config/c_ros.go

@@ -7,7 +7,10 @@ import (
 	"os"
 )
 
-var RosNode *goroslib.Node
+var (
+	RosNode *goroslib.Node
+	RosEnv  []string
+)
 
 func InitRosConfig() {
 	c_log.GlobalLogger.Info("初始化RosNode - 开始")
@@ -21,4 +24,13 @@ func InitRosConfig() {
 		os.Exit(-1)
 	}
 	c_log.GlobalLogger.Info("初始化RosNode - 成功:", CloudConfig.Ros.MasterAddress)
+	// 获取 record 命令环境变量
+	for _, host := range CloudConfig.Hosts {
+		if host.Name == LocalConfig.Node.Name {
+			RosEnv = host.RecordEnvs
+			break
+		}
+	}
+	c_log.GlobalLogger.Info("ros 环境变量为:", RosEnv)
+
 }

+ 1 - 10
aarch64/pjisuv/common/service/rosbag_record.go

@@ -39,16 +39,7 @@ func BagRecord(nodeName string) {
 		_ = util.CreateParentDir(config.CloudConfig.BagDataDir)
 		systemEnv := os.Environ()
 		c_log.GlobalLogger.Info("系统环境变量为:", systemEnv)
-		// 获取 record 命令环境变量
-		var recordEnvs []string
-		for _, host := range config.CloudConfig.Hosts {
-			if host.Name == config.LocalConfig.Node.Name {
-				recordEnvs = host.RecordEnvs
-				break
-			}
-		}
-		c_log.GlobalLogger.Info("record 环境变量为:", recordEnvs)
-		cmd, err := util.ExecuteWithEnvAndDirAsync(recordEnvs, config.CloudConfig.BagDataDir, "/opt/ros/melodic/bin/rosbag", command...)
+		cmd, err := util.ExecuteWithEnvAndDirAsync(config.RosEnv, config.CloudConfig.BagDataDir, "/opt/ros/melodic/bin/rosbag", command...)
 		if err != nil {
 			c_log.GlobalLogger.Error("执行record命令", command, "出错:", err)
 			continue

+ 2 - 2
aarch64/pjisuv/common/service/rosbag_upload.go

@@ -70,7 +70,7 @@ outLoop:
 				oldName := bag
 				newName := bag + "_filter"
 				filterCommand := []string{"filter", oldName, newName, "\"" + strings.Join(topicsFilterSlice, " or ") + "\""}
-				_, output, err := commonUtil.ExecuteWithEnvSync(os.Environ(), "rosbag", filterCommand...)
+				_, output, err := commonUtil.ExecuteWithEnvSync(commonConfig.RosEnv, "rosbag", filterCommand...)
 				c_log.GlobalLogger.Info("正在过滤中,【FaultTime】=", currentTimeWindow.FaultTime, "【Label】=", currentTimeWindow.Labels, ",进度", i+1, "/", bagNumber, "。")
 				if err != nil {
 					c_log.GlobalLogger.Errorf("filter 命令执行出错【命令】=%v,【输出】=%v,【err】=%v", filterCommand, output, err)
@@ -92,7 +92,7 @@ outLoop:
 			oldName := bag
 			compressCommand := []string{"compress", "--bz2", oldName}
 			c_log.GlobalLogger.Info("正在压缩中,【FaultTime】=", currentTimeWindow.FaultTime, "【Label】=", currentTimeWindow.Labels, ",进度", i+1, "/", bagNumber, "。")
-			if _, output, err := commonUtil.ExecuteWithEnvSync(os.Environ(), "rosbag", compressCommand...); err != nil {
+			if _, output, err := commonUtil.ExecuteWithEnvSync(commonConfig.RosEnv, "rosbag", compressCommand...); err != nil {
 				c_log.GlobalLogger.Errorf("compress 命令执行出错【命令】=%v,【输出】=%v,【err】=%v", compressCommand, output, err)
 				continue
 			}