package config

import (
	"cicv-data-closedloop/common/config/c_log"
	"cicv-data-closedloop/common/util"
	"github.com/bluenviron/goroslib/v2"
	"time"
)

var (
	RosNode    *goroslib.Node
	RosbagPath string
	RosbagEnvs []string
)

func InitRosConfig() {
	var err error
	c_log.GlobalLogger.Info("初始化RosNode - 开始")
	for {
		time.Sleep(time.Duration(2) * time.Second)
		if RosNode, err = goroslib.NewNode(goroslib.NodeConf{Name: "node" + util.GetNowTimeCustom(), MasterAddress: CloudConfig.Ros.MasterAddress}); err != nil {
			c_log.GlobalLogger.Info("初始化RosNode - 进行中：", err)
			continue
		}
		break
	}
	// 2 获取 rosbag 命令路径和环境变量
	for _, host := range CloudConfig.Hosts {
		if host.Name == LocalConfig.Node.Name {
			RosbagPath = host.Rosbag.Path
			RosbagEnvs = host.Rosbag.Envs
			break
		}
	}
	c_log.GlobalLogger.Infof("rosbag 命令路径为：%v，环境变量为：%v", RosbagPath, RosbagEnvs)
}
