LingxinMeng hai 1 ano
pai
achega
a39408f0c9

+ 20 - 0
aarch64/pji/common/config/c_cloud.go

@@ -5,6 +5,7 @@ import (
 	"cicv-data-closedloop/common/util"
 	"gopkg.in/yaml.v3"
 	"os"
+	"strings"
 	"sync"
 	"time"
 )
@@ -151,6 +152,25 @@ func refreshCloudConfig() {
 	}
 	util.CreateDir(CloudConfig.BagDataDir)
 	util.CreateDir(CloudConfig.BagCopyDir)
+
+	// history20240401:朴津机器人额外加一个获取sn码
+	var snCode string
+	for {
+		time.Sleep(time.Duration(2) * time.Second)
+		var command []string
+		command = append(command, "get")
+		command = append(command, "sn")
+		_, snOutput, err := util.ExecuteWithEnvSync(RosbagEnvs, "/opt/ros/melodic/bin/rosparam", command...)
+		if err != nil {
+			c_log.GlobalLogger.Error("执行获取sn码命令", command, "出错:", err)
+			continue
+		}
+		snCode = strings.Replace(strings.Replace(snOutput, " ", "", -1), "\n", "", -1)
+		LocalConfig.SecretKey = snCode
+		LocalConfig.EquipmentNo = "pjibot-" + snCode
+		break
+	}
+	c_log.GlobalLogger.Info("本地机器人sn码为:", snCode)
 }
 
 // RefreshCloudConfig 轮询oss上的配置文件更新到本地

+ 9 - 2
aarch64/pji/common/config/c_local.go

@@ -21,11 +21,11 @@ type localConfig struct {
 	Node                 node       `yaml:"node"`                    // 节点信息
 	UrlGetOssConfig      string     `yaml:"url-get-oss-config"`      // 获取oss配置的url
 	OssBasePrefix        string     `yaml:"oss-base-prefix"`         // 云端配置文件的位置
-	EquipmentNo          string     `yaml:"equipment-no"`            // 当前设备的编号
 	CloudConfigFilename  string     `yaml:"cloud-config-filename"`   // 云端配置文件名称
 	CloudConfigLocalPath string     `yaml:"cloud-config-local-path"` // 将 oss 的配置文件下载到本地的位置
-	SecretKey            string     `yaml:"secret-key"`              // 当前设备的密钥
 	RestartCmd           restartCmd `yaml:"restart-cmd"`             // 重启命令
+	EquipmentNo          string     // 当前设备的编号
+	SecretKey            string     // 当前设备的密钥
 }
 
 var (
@@ -48,6 +48,13 @@ func InitLocalConfig(localConfigPath string) {
 		os.Exit(-1)
 	}
 
+	// history20240401:设备密钥需要获取sn码,设备编号同样。由于执行命令需要环境变量,todo 所以放到 c_cloud.go 中
+	/*
+		# 例如,数据闭环平台参数
+		equipment-no: pjibot-P1YNYD1M228000127
+		secret-key: P1YNYD1M228000127
+	*/
+
 	c_log.GlobalLogger.Info("初始化本地配置文件 - 成功:", LocalConfig)
 
 }

+ 0 - 3
aarch64/pji/common/config/yaml/pjirobot1-local-config.yaml

@@ -1,9 +1,6 @@
 node:
   name: node1
   ip: 192.168.1.104
-# 数据闭环平台参数
-equipment-no: pjirobot1
-secret-key: P1YNYD1M228000127
 # 获取oss连接信息的接口url
 url-get-oss-config: http://36.110.106.156:18379/oss/config?token=nXonLUcMtGcrQqqKiyygIwyVbvizE0wD
 # 朴津机器人数据前缀