LingxinMeng преди 6 месеца
родител
ревизия
ed9d88100b
променени са 2 файла, в които са добавени 96 реда и са изтрити 31 реда
  1. 26 24
      src/package/service/run_task.go
  2. 70 7
      src/package/util/u_xosc.go

+ 26 - 24
src/package/service/run_task.go

@@ -182,6 +182,26 @@ func RunWaitingCluster() {
 		}
 		infra.GlobalLogger.Infof("偏移量【%v】加一给下个任务使用。", offsetKey)
 
+		// ---------------
+		// ------- 解析 xosc ,从xosc中解析起终点位置&修改 xodr 和 osgb ---------------
+		xoscOssPath := firstTaskCache.Task.Scenario.ScenarioOsc
+		tempDir := "/mnt/disk001/dcl_dispatch_server/temp/"
+		util.CreateDir(tempDir)
+		xoscLocalPath := tempDir + util.NewShortUUID() + ".xosc"
+		if firstTaskCache.Env == "cicv" { // cicv 或 pji
+			err = infra.GlobalOssBucketCicv.GetObjectToFile(firstTaskCache.Task.Scenario.ScenarioOsc, xoscLocalPath)
+		} else {
+			err = infra.GlobalOssBucketPji.GetObjectToFile(firstTaskCache.Task.Scenario.ScenarioOsc, xoscLocalPath)
+		}
+
+		if err != nil {
+			infra.GlobalLogger.Errorf("下载xosc文件【%v】失败,错误信息为:%v", xoscOssPath, err)
+			continue
+		}
+		s1, s2, s3, s4, xodrPath, osgbPath := util.ParseXosc(xoscLocalPath)
+		firstTaskCache.Task.Scenario.ScenarioOdr = xodrPath
+		firstTaskCache.Task.Scenario.ScenarioOsgb = osgbPath
+
 		// --------------- 发送 kafka 消息(获取偏移量和分区) ---------------
 		// 获取任务消息转json
 		// 将摄像头写死一个参数
@@ -300,28 +320,10 @@ func RunWaitingCluster() {
 		podString = strings.Replace(podString, "kafka-offset", "\""+util.ToString(offset)+"\"", -1)
 		podString = strings.Replace(podString, "cpu-order", "\""+util.ToString(restParallelism-1)+"\"", -1) // cpu编号是剩余并行度-1
 		podString = strings.Replace(podString, "algorithm-container", algorithmContainer, -1)
-		// 从xosc中解析起终点位置
-		xoscOssPath := firstTaskCache.Task.Scenario.ScenarioOsc
-		tempDir := "/mnt/disk001/dcl_dispatch_server/temp/"
-		util.CreateDir(tempDir)
-		xoscLocalPath := tempDir + util.NewShortUUID() + ".xosc"
-		if firstTaskCache.Env == "cicv" { // cicv 或 pji
-			err = infra.GlobalOssBucketCicv.GetObjectToFile(firstTaskCache.Task.Scenario.ScenarioOsc, xoscLocalPath)
-		} else {
-			err = infra.GlobalOssBucketPji.GetObjectToFile(firstTaskCache.Task.Scenario.ScenarioOsc, xoscLocalPath)
-		}
-
-		if err != nil {
-			infra.GlobalLogger.Errorf("下载xosc文件【%v】失败,错误信息为:%v", xoscOssPath, err)
-			continue
-		}
-		{
-			s1, s2, s3, s4 := util.GetStartAndEnd(xoscLocalPath)
-			podString = strings.Replace(podString, "start-position-x", "\""+s1+"\"", -1)
-			podString = strings.Replace(podString, "start-position-y", "\""+s2+"\"", -1)
-			podString = strings.Replace(podString, "end-position-x", "\""+s3+"\"", -1)
-			podString = strings.Replace(podString, "end-position-y", "\""+s4+"\"", -1)
-		}
+		podString = strings.Replace(podString, "start-position-x", "\""+s1+"\"", -1)
+		podString = strings.Replace(podString, "start-position-y", "\""+s2+"\"", -1)
+		podString = strings.Replace(podString, "end-position-x", "\""+s3+"\"", -1)
+		podString = strings.Replace(podString, "end-position-y", "\""+s4+"\"", -1)
 
 		// --------------- 保存成文件
 		err = util.WriteFile(podString, yamlPath)
@@ -332,12 +334,12 @@ func RunWaitingCluster() {
 		}
 		infra.GlobalLogger.Infof("保存yaml文件到执行路径【%v】和备份路径【%v】", yamlPath, yamlPathBak)
 		// --------------- 启动 pod
-		_, s2, err := util.Execute("kubectl", "apply", "-f", yamlPath)
+		_, sr, err := util.Execute("kubectl", "apply", "-f", yamlPath)
 		if err != nil {
 			infra.GlobalLogger.Errorf("启动pod失败,执行结果为 %v,错误信息为 %v", s2, err)
 			continue
 		}
-		infra.GlobalLogger.Errorf("启动pod成功,执行结果为 %v。", s2)
+		infra.GlobalLogger.Errorf("启动pod成功,执行结果为 %v。", sr)
 		// 收尾
 		{
 			// --------------- 添加到运行队列

+ 70 - 7
src/package/util/u_xosc.go

@@ -5,13 +5,37 @@ import (
 	"github.com/beevik/etree"
 )
 
-// GetStartAndEnd
+var (
+	xodr1Key   = "OpenDRIVE2_add_stop_line_marking_20231229.xodr"
+	xodr1Value = "resource/OpenDRIVE2_add_stop_line_marking_20231229.xodr"
+	xodr2Key   = "thq_1116.xodr"
+	xodr2Value = "resource/thq_1116.xodr"
+	xodr3Key   = "thq_20240706.xodr"
+	xodr3Value = "resource/thq_20240706.xodr"
+	xodr4Key   = "yizhuang.xodr"
+	xodr4Value = "resource/yizhuang.xodr"
+	xodr5Key   = "anqing.xodr"
+	xodr5Value = "resource/anqing.xodr"
+	osgb1Key   = "jinlong_all_addtrafficlight_20240226_5_guazai_2.opt.osgb"
+	osgb1Value = "resource/jinlong_all_addtrafficlight_20240226_5_guazai_2.opt.osgb"
+	osgb2Key   = "thq_1116.opt.osgb"
+	osgb2Value = "resource/thq_1116.opt.osgb"
+	osgb3Key   = "thq_20230710.osgb"
+	osgb3Value = "resource/thq_20230710.osgb"
+	osgb4Key   = "yizhuang.osgb"
+	osgb4Value = "resource/yizhuang.osgb"
+	osgb5Key   = "anqing.osgb"
+	osgb5Value = "resource/anqing.osgb"
+)
+
 // - filepath  文件路径 "D:\\test.xosc"
-func GetStartAndEnd(filepath string) (string, string, string, string) {
+func ParseXosc(filepath string) (string, string, string, string, string, string) {
 	startPositionX := ""
 	startPositionY := ""
 	endPositionX := ""
 	endPositionY := ""
+	xodrPath := ""
+	osgbPath := ""
 	doc := etree.NewDocument()
 	if err := doc.ReadFromFile(filepath); err != nil {
 		panic(err)
@@ -55,9 +79,48 @@ func GetStartAndEnd(filepath string) (string, string, string, string) {
 			}
 		}
 	}
-	fmt.Println(startPositionX)
-	fmt.Println(startPositionY)
-	fmt.Println(endPositionX)
-	fmt.Println(endPositionY)
-	return startPositionX, startPositionY, endPositionX, endPositionY
+
+	logicFile := doc.SelectElement("OpenSCENARIO").SelectElement("RoadNetwork").SelectElement("LogicFile")
+	for _, attr := range logicFile.Attr {
+		if attr.Key == "filepath" {
+			xodrKey := attr.Value
+			xodrPath = getValueByKey(xodrKey)
+		}
+	}
+	sceneGraphFile := doc.SelectElement("OpenSCENARIO").SelectElement("RoadNetwork").SelectElement("SceneGraphFile")
+	for _, attr := range sceneGraphFile.Attr {
+		if attr.Key == "filepath" {
+			osgbKey := attr.Value
+			osgbPath = getValueByKey(osgbKey)
+		}
+	}
+
+	return startPositionX, startPositionY, endPositionX, endPositionY, xodrPath, osgbPath
+}
+
+func getValueByKey(key string) string {
+	switch key {
+	case xodr1Key:
+		return xodr1Value
+	case xodr2Key:
+		return xodr2Value
+	case xodr3Key:
+		return xodr3Value
+	case xodr4Key:
+		return xodr4Value
+	case xodr5Key:
+		return xodr5Value
+	case osgb1Key:
+		return osgb1Value
+	case osgb2Key:
+		return osgb2Value
+	case osgb3Key:
+		return osgb3Value
+	case osgb4Key:
+		return osgb4Value
+	case osgb5Key:
+		return osgb5Value
+	}
+	fmt.Print("错误的xosc")
+	return ""
 }