|
@@ -0,0 +1,69 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "cicv-data-closedloop/common/config/c_log"
|
|
|
+ "cicv-data-closedloop/common/util"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// 用于执行rosbag命令
|
|
|
+func main() {
|
|
|
+ //// 定义一个字符串切片来存储转换后的结果
|
|
|
+ //envVars := []string{
|
|
|
+ // "C_INCLUDE_PATH=/usr/include/drm:",
|
|
|
+ // "USER=root",
|
|
|
+ // "ROS_PACKAGE_PATH=/opt/ros/melodic/share",
|
|
|
+ // "LD_LIBRARY_PATH=/opt/ros/melodic/lib:/opt/ros/melodic/lib/aarch64-linux-gnu",
|
|
|
+ // "ROS_ETC_DIR=/opt/ros/melodic/etc/ros",
|
|
|
+ // "SHLVL=1",
|
|
|
+ // "HOME=/root",
|
|
|
+ // "ROS_PYTHON_VERSION=2",
|
|
|
+ // "PCMANFM_OUTLINE_MODE=on",
|
|
|
+ // "CPLUS_INCLUDE_PATH=/usr/include/drm:",
|
|
|
+ // "ROS_DISTRO=melodic",
|
|
|
+ // "ROS_VERSION=1",
|
|
|
+ // "PKG_CONFIG_PATH=/opt/ros/melodic/lib/pkgconfig",
|
|
|
+ // "PATH=/opt/ros/melodic/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/root/go/bin",
|
|
|
+ // "ROS_ROOT=/opt/ros/melodic/share/ros",
|
|
|
+ // "ROSLISP_PACKAGE_DIRECTORIES=",
|
|
|
+ // "ROS_MASTER_URI=http://192.168.1.104:11311",
|
|
|
+ // "PYTHONPATH=/opt/ros/melodic/lib/python2.7/dist-packages",
|
|
|
+ // "ROS_HOSTNAME=192.168.1.104",
|
|
|
+ // "CMAKE_PREFIX_PATH=/opt/ros/melodic",
|
|
|
+ //}
|
|
|
+ //// 1 启动父命令
|
|
|
+ //c_log.GlobalLogger.Info("record 环境变量为:", config.RosbagEnvs)
|
|
|
+ //
|
|
|
+ //cmd, _ := util.ExecuteWithEnvAndDirAsync(config.RosbagEnvs, config.CloudConfig.BagDataDir, config.RosbagPath, command...)
|
|
|
+ //recordProcessPid := cmd.Process.Pid
|
|
|
+ //recordSubProcessPid, _ := util.GetSubProcessPid(recordProcessPid)
|
|
|
+ //c_log.GlobalLogger.Info("获取进程 ", recordProcessPid, " 的子进程的pid:", recordSubProcessPid)
|
|
|
+
|
|
|
+ for {
|
|
|
+ time.Sleep(time.Duration(2) * time.Second)
|
|
|
+ snCode, err := getSnCode()
|
|
|
+ if err != nil {
|
|
|
+ c_log.GlobalLogger.Error("获取sn码失败:", err.Error())
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ fmt.Println("SN码为:", snCode)
|
|
|
+ break
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func getSnCode() (string, error) {
|
|
|
+ rosparamPath := "/opt/ros/melodic/bin/rosparam"
|
|
|
+ var command []string
|
|
|
+ command = append(command, "get")
|
|
|
+ command = append(command, "sn")
|
|
|
+ _, snOutput, err := util.ExecuteSync(rosparamPath, command...)
|
|
|
+ if err != nil {
|
|
|
+ return "", errors.New("执行获取sn码命令" + rosparamPath + util.ToString(command) + "出错:" + util.ToString(err))
|
|
|
+ }
|
|
|
+ c_log.GlobalLogger.Info("执行获取sn码命令", command, "成功,结果为:", snOutput)
|
|
|
+ snCode := strings.Replace(strings.Replace(snOutput, " ", "", -1), "\n", "", -1)
|
|
|
+ return snCode, nil
|
|
|
+}
|