HeWang 6 mesi fa
parent
commit
08aa91a347

+ 17 - 0
aarch64/pjibot_guide/common/config/c_platform.go

@@ -66,6 +66,23 @@ func InitPlatformConfig() {
 	c_log.GlobalLogger.Info("获取数据闭环平台配置 - 成功。")
 }
 
+func CheckPlatformConfigStatus(maxRetryCount int) bool {
+	var err error
+	for i := 0; i < maxRetryCount; i++ {
+		time.Sleep(time.Duration(2) * time.Second)
+		// 判断是否有配置,第一次访问状态应该为:CHANGE(一共三种状态 CHANGE|UNCHANGE|NONE)
+		PlatformConfig, err = getConfig()
+		if err != nil {
+			c_log.GlobalLogger.Error("获取配置status失败:", err)
+			continue
+		}
+		if checkPlatformConfig() {
+			return true
+		}
+	}
+	return false
+}
+
 /*
 	{
 	  "data": {

+ 6 - 2
aarch64/pjibot_guide/control/main.go

@@ -29,6 +29,7 @@ var (
 	renewedFlag     = false
 	renewTimer      *time.Timer // 续约定时器
 	RenewDur        = 5         // min, 续约时间
+	maxRetryCount   = 10        // 查询配置最大重试次数
 )
 
 func init() {
@@ -66,8 +67,11 @@ func renew() {
 
 func startMasterNode() {
 	c_log.GlobalLogger.Info("获取数据闭环平台最新配置。")
-	fmt.Println("1")
-	commonConfig.InitPlatformConfig()
+
+	if commonConfig.CheckPlatformConfigStatus(maxRetryCount) {
+		c_log.GlobalLogger.Info("查询到数据闭环平台有配置任务。")
+		commonConfig.InitPlatformConfig()
+	}
 
 	if _, err := util.ExecuteWithPath(commonConfig.LocalConfig.RestartCmd.Dir, commonConfig.LocalConfig.RestartCmd.Name, commonConfig.LocalConfig.RestartCmd.Args...); err != nil {
 		c_log.GlobalLogger.Info("启动新程序失败,【path】=", commonConfig.LocalConfig.RestartCmd.Dir, "【cmd】=", commonConfig.LocalConfig.RestartCmd.Name, commonConfig.LocalConfig.RestartCmd.Args, ":", err)

+ 9 - 4
aarch64/pjibot_guide/control/pkg/judge_cloud.go

@@ -3,10 +3,13 @@ package pkg
 import (
 	commonConfig "cicv-data-closedloop/aarch64/pjibot_guide/common/config"
 	"cicv-data-closedloop/common/config/c_log"
-	"fmt"
 	"time"
 )
 
+var (
+	maxRetryCount = 10
+)
+
 // UN_CHANGE 没有新的任务
 // CHANGE 有新的任务
 // NONE 设备没有配置任务
@@ -31,10 +34,12 @@ func GetCloudStatus(cloudStatus *string, lastCloudStatus *string, turnLength int
 func GetCloudConfig(cloudStatus *string, lastCloudStatus *string, turnLength int) {
 	for {
 		time.Sleep(time.Duration(turnLength) * time.Second)
-		c_log.GlobalLogger.Error("cloudStatus:", cloudStatus)
 		if *cloudStatus == "CHANGE" {
-			fmt.Println("2")
-			commonConfig.InitPlatformConfig()
+			c_log.GlobalLogger.Error("cloudStatus:", *cloudStatus)
+			if commonConfig.CheckPlatformConfigStatus(maxRetryCount) {
+				c_log.GlobalLogger.Info("查询到数据闭环平台有配置任务。")
+				commonConfig.InitPlatformConfig()
+			}
 		}
 	}
 }

+ 0 - 2
aarch64/pjibot_guide/master/main.go

@@ -8,7 +8,6 @@ import (
 	masterService "cicv-data-closedloop/aarch64/pjibot_guide/master/package/service"
 	"cicv-data-closedloop/common/config/c_log"
 	"cicv-data-closedloop/common/util"
-	"fmt"
 	"runtime"
 	"time"
 )
@@ -29,7 +28,6 @@ func init() {
 	_ = util.RemoveSubFiles(commonConfig.CloudConfig.BagCopyDir)
 	go commonConfig.RefreshCloudConfig()
 	// 初始化数据闭环平台的配置(第3处配置,在数据闭环平台接口)
-	fmt.Println("3")
 	commonConfig.InitPlatformConfig()
 	// 初始化ros节点
 	commonConfig.InitRosConfig()